Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Load time weaving agent with another java agent

Hi Ali.

Well, according to the manifest in aspectjweaver.jar there is "Can-Redefine-Classes: true", but no "Can-Retransform-Classes: true". So at first I thought you were right with your assumption. But then I was curious and tried anyway, the only difference being that I added a static method to a class via Javassist because its API is more high level than ASM's, thus I did not have to learn so much for my little experiment.

What can I say? It worked nicely, not matter if I intercepted method calls inserted via Javassist or executions of my static method added via Javassist. And yes, I reproduced the chained Java Agent scenario you also used, i.e. my command line was something like:

java -javaagent:agent-0.1-SNAPSHOT.jar -javaagent:aspectjweaver.jar (...) other.Main

BTW, I used AspectJ 1.8.5 and JDK 7 for my test.
-- 
Alexander Kriegisch
http://scrum-master.de


Ali Kheradmand schrieb am 26.03.2015 17:35:

> Thanks for the response Alexander. Yes everything other than inserted method calls get woven. 
> 
> It seems that AspectJ's transformer gets called before my agent on each class regardless of the order of agents. From ClassFileTransformer's javadoc I see that:
> 
> 
> When there are multiple transformers, transformations are composed by chaining the transform calls. That is, the byte array returned by one call to transform becomes the input (via the classfileBuffer parameter) to the next call.
> 
> Transformations are applied in the following order:
> 
> 	Retransformation incapable transformers
> 	Retransformation incapable native transformers
> 	Retransformation capable transformers
> 	Retransformation capable native transformers
> 
> 
> My agent is retransformation capable. I guess aspect weaver's agent is retransformation incapable. 
> 
> Anyway the problem got solved by capturing method "execution" rather than "call". This way, I don't need to care about the order of agents. 
> 
> 
> Regards,
> 
> Ali
> 
> 
> On Thu, Mar 26, 2015 at 4:50 AM, Alexander Kriegisch <Alexander@xxxxxxxxxxxxxx <mailto:Alexander@xxxxxxxxxxxxxx> > wrote:
>> 
>> 
>> Interesting project, Ali.
>> 
>> 
>> Does the combination of agents work with other aspects, i.e. ones unrelated to the ASM-inserted method calls? I mean, does anything get woven at all? If so, my guess would be that the byte code ASM produces is not recognised as valid method calls by AspectJ. Otherwise there is another, more basic problem with mixing those agents. I never tried, actually.
>> 
>> Regards
>> 
>> -- 
>> 
>> Alexander Kriegisch
>> 
>> http://scrum-master.de <http://scrum-master.de> 
>> 
>> 
>> Am 26.03.2015 um 03:58 schrieb Ali Kheradmand <a.i.kheradmand@xxxxxxxxx <mailto:a.i.kheradmand@xxxxxxxxx> >:
>> 
>> 
>>> Hey everybody,
>>> 
>>> 
>>> I need to capture array element access in AspectJ. But it seems that AspectJ does not provide such a pointcut. In order to solve this problem my idea was to insert calls to an specific static method before array accesses and capture those method calls in AspectJ.
>>> 
>>> I wrote a java instrumentation agent (using ASM) that inserts the static method calls before array element accesses. The agent works fine.
>>> 
>>> I also wrote an aspect that captures that method call. I generated a load time weaving agent using that aspect. And that agent works fine too (by that I mean if I manually add the method calls to source code, the agent captures it at runtime)
>>> 
>>> 
>>> Now I try to run both of the agents in order:
>>> 
>>> java -javaagent:myagent.jar -javaagent:asperctjweaver.jar MyClass
>>> 
>>> 
>>> It is said that " Agents are invoked in the same order as specified in options.". and from that I except that myagent would insert method calls before array accesses and asperctjweaver would capture those calls. But it does not work this way: method calls get inserted before array accesses but they do not get captured. However, the method calls that already existed in the source code, get captured. 
>>> 
>>> 
>>> Does anybody have any idea on what the problem might be?
>>> 
>>> 
>>> Regards,
>>> 
>>> Ali
>>> 
>>> 
>>> _______________________________________________
>>> aspectj-users mailing list
>>> aspectj-users@xxxxxxxxxxx <mailto:aspectj-users@xxxxxxxxxxx> 
>>> To change your delivery options, retrieve your password, or unsubscribe from this list, visit
>>> https://dev.eclipse.org/mailman/listinfo/aspectj-users <https://dev.eclipse.org/mailman/listinfo/aspectj-users> 
>> 
>> 
>> _______________________________________________
>> aspectj-users mailing list
>> aspectj-users@xxxxxxxxxxx <mailto:aspectj-users@xxxxxxxxxxx> 
>> To change your delivery options, retrieve your password, or unsubscribe from this list, visit
>> https://dev.eclipse.org/mailman/listinfo/aspectj-users <https://dev.eclipse.org/mailman/listinfo/aspectj-users> 
> 
>


Back to the top