Sharing Advice.Locals across multiple Advices
@raphw is already working on this.
Since Feb 13, 2019.
- Dominant language
- Java
- Stars
- 6.9k
- Forks
- 855
- PR merge metrics
- No merged PRs in 30d
Description
In our project we are currently writing a Java agent and use ByteBuddy to perform some configurable instrumentation. Based on the configuration we apply one or multiple Advices to methods. The problem is now that these Advices would like to share some method local data.
Whenever we decide to instrument a method, we first apply an Advice which looks like this:
public class MyContextAdvice {
@Advice.OnMethodEnter
public static void onEnter(@Advice.Local("context") bootstrap.MyContext context) {
context = bootstrap.MyContext.enterNewContext();
}
@Advice.OnMethodExit
public static void onExit(@Advice.Local("context") bootstrap.MyContex context) {
context.close();
}
}
The other Advices which are then applied to the same method would like to access the "context" generated by MyContextAdvice . As I see it this is currently not possible using Advice.Local as all Advices are translated to individual ASMVisitorWrappers which have no knowledge of each other.
Is there any other way of realizing this behaviour or do we have to fallback to using ASM?
As the code is performance critical I would like to avoid "hacks" such as maintaining a custom stack using ThreadLocals.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.