Bug 415266 - LTW not working when JMX is enabled
Summary: LTW not working when JMX is enabled
Status: RESOLVED FIXED
Alias: None
Product: AspectJ
Classification: Tools
Component: LTWeaving (show other bugs)
Version: 1.7.4   Edit
Hardware: PC Linux
: P3 critical (vote)
Target Milestone: 1.7.4   Edit
Assignee: aspectj inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-08-16 17:51 EDT by Micron Gust CLA
Modified: 2013-10-24 12:30 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Micron Gust CLA 2013-08-16 17:51:29 EDT
When I enable JMX remote management on a JVM along with AspectJ load-time weaving (LTW), our Aspect doesn't appear to get woven in.

This are the JVM arguments:

-Dvisualvm.display.name=JdbcTimingAspectTest -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.port=1024 -javaagent:/jars/aspectjweaver.jar -Dorg.aspectj.weaver.loadtime.configuration=com/trgr/cobalt/infrastructure/instrumentation/aspects/timing/jdbc/jdbcmonitor.xml

Note that if I don't enable JMX remote management (by remove the -Dcom.sun.management.jmxremote.* JVM arguments), the Aspect works fine.
Comment 1 Micron Gust CLA 2013-08-16 19:19:42 EDT
Note that according to this post on StackOverflow.com:

http://stackoverflow.com/questions/17784939/aspectj-ltw-not-working-with-jmx-remote

A workaround is to add the following to the java arguments:

-Xbootclasspath/p:libs/aspectjweaver-1.7.3.jar

This workaround seems like it could lead to other issues. Could someone comment on whether or not this would be the recommended workaround until a bug fix is available?
Comment 2 Sebastien Richard CLA 2013-08-21 09:59:47 EDT
The bug seems to be coming from this modification:

https://github.com/eclipse/org.aspectj/commit/8a6608f4d5d1a2aa8aa49a0a38da66a54d53c917#L0R265

When JMX is enabled, the first classloader is not the same as the "myClassLoader" (AppClassLoader). Therefore this conditions does not have the proper adaptor:

if(loader.equals(myClassLoader)){
    adaptor = myClassLoaderAdpator;
} 

Adding the condition "loader.equals(myClassLoader)" would probably work.

I didn't have time to test this solution.
Comment 3 Andrew Clement CLA 2013-08-26 15:33:53 EDT
In theory running with the weaver on the bootclasspath should be ok.  The weaver may have access to weaving more types but as long as your aspects are carefully targeting what they need to weave you shouldn't weave anything else by accident.
Comment 4 Andrew Clement CLA 2013-08-27 11:22:36 EDT
Sebastien, I'm interested in trying your proposed solution - but what is it?

> if(loader.equals(myClassLoader)){
>    adaptor = myClassLoaderAdpator;
> } 
>
> Adding the condition "loader.equals(myClassLoader)" would probably work.

Did you mean add that condition? It is the same as the condition already there?
Comment 5 Sebastien Richard CLA 2013-08-27 22:46:34 EDT
(In reply to comment #4)
> Sebastien, I'm interested in trying your proposed solution - but what is it?
> 
> > if(loader.equals(myClassLoader)){
> >    adaptor = myClassLoaderAdpator;
> > } 
> >
> > Adding the condition "loader.equals(myClassLoader)" would probably work.
> 
> Did you mean add that condition? It is the same as the condition already
> there?

Hi Andrew,
    I'm suggesting updating the condition:

if(myClassLoaderAdpator == null){
    myClassLoaderAdpator = adaptor;
}

to:
if(myClassLoaderAdpator == null && loader.equals(myClassLoader)){
    myClassLoaderAdpator = adaptor;
}

Basically, the code keeps a reference of its own classloader (myClassLoader) in order to keep a reference of its own adaptor. However it keeps the wrong reference if the first loaded class loader in this class is not its own (which seems to happen when JMX is activated).
Comment 6 Sebastien Richard CLA 2013-08-27 23:01:18 EDT
 
> However it keeps the wrong
> reference if the first loaded class loader in this class is not its own
> (which seems to happen when JMX is activated).

I mean it keeps the wrong adaptor reference. When it's time to weave the classloader that is kept in reference (myClassLoader) it uses the adaptor from this condition:
if(loader.equals(myClassLoader)){
    adaptor = myClassLoaderAdpator;
} 

which is not the right one. Therefore the class loader is never weaved.
Comment 7 Andrew Clement CLA 2013-08-28 18:33:48 EDT
A dev build is available with Sebastiens proposed change in:

http://www.eclipse.org/downloads/download.php?file=/tools/aspectj/dev/aspectj-DEVELOPMENT-20130828153000.jar
Comment 8 Micron Gust CLA 2013-09-04 19:16:20 EDT
(In reply to Andrew Clement from comment #7)
> A dev build is available with Sebastiens proposed change in:
> 
> http://www.eclipse.org/downloads/download.php?file=/tools/aspectj/dev/
> aspectj-DEVELOPMENT-20130828153000.jar

Andy, I just verified that this build fixes the issue. With the new JAR, my Aspect gets weaved in even when remote JMX management is enabled.

Thanks Andy and Sebastien for helping to fix this. What are the next steps to get this into an official AspectJ build?
Comment 9 Andrew Clement CLA 2013-10-01 13:08:49 EDT
changes are now committed.
Comment 10 Andrew Clement CLA 2013-10-24 12:30:18 EDT
in 1.7.4