Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Inject goto instructuion #645

Open
zly2006 opened this issue Sep 24, 2023 · 0 comments
Open

[Feature Request] Inject goto instructuion #645

zly2006 opened this issue Sep 24, 2023 · 0 comments

Comments

@zly2006
Copy link

zly2006 commented Sep 24, 2023

Can we add a new injection mode that can inject gotos?

For example, original code:

class X {
  int foo(int x) {
    if (x < 0) return -x;
    bar(x)
    return x;
  }
}

then

@Goto(method="foo", at = @At(value = "INVOKE", target = "bar...", shift = BEFORE), to = @At(value = "INVOKE", target = "bar...", shift = AFTER)
boolean condition() {
  return true; // if return true, goto the "to" target, otherwise, do nothing. This is like if statement.
}

Finally, the code is like

class X {
  int foo(int x) {
    if (x < 0) return -x;
    if (condition()) {
      // nothing
    } else {
      bar(x);
    }
    return x;
  }
}

Its definition may be like:

@Target({ ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
public @interface Goto {
    String[] method() default {};
    Desc[] target() default {};
    Slice[] slice() default {};
    At[] at();
    At to();
    boolean remap() default true;
}

I know this may be unnecessary because @Redirect is already here, but @Redirects often cause a lot of conflicts. Many redirects just add a condition, if we provide a compatible method to do that, we can reduce conflicts. What's more, this feature can support break and continue, which is also very useful i think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant