I am using AspectJ to trace calls to graphics class. So far, I have used a pre-weaved set of javax.swing.* classes and upon loading I tell JVM to use these weaved classes and not the ones from JRE by using -Xbootclasspath/p switch.
I would like to switch to load time weaving mode. Can anyone help me how to weave javax.swing on load time. I have searched the net but still I cannot figure it out how to do it. I know that by default, AspectJ load time weaver will not weave java.* and javax.* classes. Someone suggested using
-Xset:weaveJavaPackages=true,weaveJavaxPackages=true
in aop.xml but none of this helped because javax.swing classes are loaded before the weaver is attached to the classloader. I guess that the weaver does not see these classes at all.
How can I manage to dynamically weave javax.swing classes? Should I implement a custom class loader that first registers a weaver then does the class loading?
Can someone please suggest any solution?
Weaving in AspectJ Classes are defined using Java syntax. The weaving process consists of executing the aspect advice to produce only a set of generated classes that have the aspect implementation code woven into it.
Load-time weaving (LTW) is simply binary weaving defered until the point that a class loader loads a class file and defines the class to the JVM. To support this, one or more "weaving class loaders", either provided explicitly by the run-time environment or enabled through a "weaving agent" are required.
Weaving: linking aspects with other application types or objects to create an advised object. This can be done at compile time (using the AspectJ compiler, for example), load time, or at runtime.
Weaving is a technique of manipulating the byte-code of compiled Java classes. The EclipseLink JPA persistence provider uses weaving to enhance both JPA entities and Plain Old Java Object (POJO) classes for such things as lazy loading, change tracking, fetch groups, and internal optimizations.
The only solution I can suggest if you need to use execution()
pointcuts for javax
packages is to binary-weave the JRE's tools.jar and create your own, woven version. I have done that in the past, it worked nicely. But this is only an option if you have control over the runtime environment running your application.
If you do not want to use such an approach, you will have to resort to call()
pointcuts. This way you can capture calls made by your own application or any 3rd party libraries affected by LTW. Only calls made by JRE classes loaded by the boot classloader will escape your aspect, which should not be too bad.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With