Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [aspectj-users] LTW Agent Dynamic Attachement with Attach API

A step more but unfortunnaly not the last

I have a little application that is correctly woven when it is launched with the agent myaspectjweaver.jar (myaspectjweaver.jar  aspectjweaver.jar + aspects package+ aop.xml+ aspects configuration) as shown as below :

 

E:\opt\perfStats\scripts>"C:\Program Files\Java\jdk1.6.0_11\bin\java" -javaagent:E:\\opt\\perfStats\\myaspectjweaver.jar  -classpath "C:\Program Files\Java\jdk1.6.0_11\lib\tools.jar";..\exemple1.jar;;. jlp.exemple1.jvm14.Main

[AppClassLoader@df6ccd] info AspectJ Weaver Version DEVELOPMENT built on Thursday Dec 18, 2008 at 18:33:02 GMT

[AppClassLoader@df6ccd] info register classloader sun.misc.Launcher$AppClassLoader@df6ccd

[AppClassLoader@df6ccd] info using configuration file:/E:/opt/perfStats/myaspectjweaver.jar!/META-INF/aop.xml

[AppClassLoader@df6ccd] info define aspect iep.perf.aspects.abstractAspects.AbstractDurationMethodImpl

[AppClassLoader@df6ccd] weaveinfo Join point 'method-call(void jlp.exemple1.jvm14.Main.addNumberCircle(int))' in Type 'jlp.exemple1.jvm14.Main' (Main.java:71) advised by around advice from 'iep.perf.aspects.abstractAspects.AbstractDurationMethodImpl' (AbstractDurationMethod.aj:53)

[AppClassLoader@df6ccd] weaveinfo Join point 'method-call(double jlp.exemple1.jvm14.Circle.perimeter())' in Type 'jlp.exemple1.jvm14.Main' (Main.java:75) advised by around advice from 'iep.perf.aspects.abstractAspects.AbstractDurationMethodImpl' (AbstractDurationMethod.aj:53)

[AppClassLoader@df6ccd] weaveinfo Join point 'method-call(void jlp.exemple1.jvm14.Circle.externalCircle())' in Type 'jlp.exemple1.jvm14.Main' (Main.java:78) advised by around advice from 'iep.perf.aspects.abstractAspects.AbstractDurationMethodImpl' (AbstractDurationMethod.aj:53)

 

The 3 last lines show that aspects are woven, when the agent is launched with the start of application.

 

For test with the Attach API, I launch the application, the first that do the main method is to sleep 1 mn. I can get the PID of the java VM with jps and afterwards I can launch the tool to attach the javaagent myaspectjweaver.jar. The logs below show that the agent is correctly loaded, and the aop.xml correctly read, but threr is no weaving after ;-(

 

E:\opt\perfStats\scripts>"C:\Program Files\Java\jdk1.6.0_11\bin\java"   -classpath "C:\Program Files\Java\jdk1.6.0_11\lib\tools.jar";..\exemple1.jar;;. jlp.exemple1.jvm14.Main 100 60000

[AppClassLoader@11b86e7] info AspectJ Weaver Version DEVELOPMENT built on Thursd

ay Dec 18, 2008 at 18:33:02 GMT

[AppClassLoader@11b86e7] info register classloader sun.misc.Launcher$AppClassLoader@11b86e7

[AppClassLoader@11b86e7] info using configuration file:/E:/opt/perfStats/lib/myaspectjweaver.jar!/META-INF/aop.xml

[AppClassLoader@11b86e7] info define aspect iep.perf.aspects.abstractAspects.AbstractDurationMethodImpl

 External public Call from Circle

 Internal Private  Call from Circle

 External public Call from Circle

 Internal Private  Call from Circle

 External public Call from Circle

 Internal Private  Call from Circle

 External public Call from Circle

 External public Call from Circle

 Internal Private  Call from Circle

 External public Call from Circle

 Internal Private  Call from Circle

 External public Call from Circle

 

 

So it is not a bug of AspectJ1.6.3, because it is not a feature of this release.

I will add this request for the next version ….

 

Cordialement / Best regards

 

Jean-Louis Pasturel

 


De : aspectj-users-bounces@xxxxxxxxxxx [mailto:aspectj-users-bounces@xxxxxxxxxxx] De la part de jeanlouis.pasturel@xxxxxxxxxxxxxxxxxx
Envoyé : mercredi 7 janvier 2009 11:38
À : aspectj-users@xxxxxxxxxxx
Objet : RE: [aspectj-users] LTW Agent Dynamic Attachement with Attach API

 

Hi Andy,

I have progressed, the agent is correctly loaded, I have just add the method agentmain to org.aspectj.weaver.loadtime.Agent . :

 

public static void agentmain(String options, Instrumentation instrumentation)

    {

        if(s_instrumentation != null)

        {

            return;

        } else

        {

            s_instrumentation = instrumentation;

            s_instrumentation.addTransformer(s_transformer);

            return;

        }

    }

 

 The code is the same as the premain existing method.

 

Below the code for loading the agent :

 

package attachapi.launcher;

import java.io.File;

import java.io.IOException;

 

import com.sun.tools.attach.AgentInitializationException;

import com.sun.tools.attach.AgentLoadException;

import com.sun.tools.attach.AttachNotSupportedException;

import com.sun.tools.attach.VirtualMachine;

 

public class PerfStatsLaunch {

      public  VirtualMachine vm =null;

      public int pidVm=-1;

       String agent ="";

      public PerfStatsLaunch(int pidVm, String path) {

            super();

            this.pidVm = pidVm;

            this.agent=path;

             try {

                  vm = VirtualMachine.attach(Integer.toString(pidVm));

            } catch (AttachNotSupportedException e) {

                  // TODO Auto-generated catch block

                  e.printStackTrace();

            } catch (IOException e) {

                  // TODO Auto-generated catch block

                  e.printStackTrace();

            }

      }

 

      public void attachPerfStats()

      {

            try {

                  System.out.println("loading agent : "+agent);

                  vm.loadAgent(agent,null);

            } catch (AgentLoadException e) {

                  // TODO Auto-generated catch block

                  e.printStackTrace();

            } catch (AgentInitializationException e) {

                  // TODO Auto-generated catch block

                  System.out.println("Echec Attach ");

                  e.printStackTrace();

            } catch (IOException e) {

                  // TODO Auto-generated catch block

                  e.printStackTrace();

            }

      }

     

      public void detachPerfStats()

      {

            try {

                  vm.detach();

            } catch (IOException e) {

                  // TODO Auto-generated catch block

                  e.printStackTrace();

            }

      }

  

 

      /**

       * @param args

       */

      public static void main(String[] args) {

            if(args.length!=2)

            {

                  System.out.println("usage :\n"+

                             "java -classpath <path to myaspectjweaver.jar>:<path to tools.jar> attachapi.launcher.PerfStats pidJVM fullpathToAgent\n");

                  System.exit(1);

            }

            PerfStatsLaunch psl=new PerfStatsLaunch(Integer.parseInt(args[0]),args[1]);

            psl.attachPerfStats();

           

                  try {

                        Thread.sleep(30000);

                  } catch (InterruptedException e) {

                        // TODO Auto-generated catch block

                        e.printStackTrace();

                  }

                 

                  psl.detachPerfStats(); 

           

           

 

      }

 

}

 

 

Next step : => obtaining weaving that a more bit difficult ( ClassLoaders must works …)

 

Cordialement / Best regards

 

Jean-Louis Pasturel


De : aspectj-users-bounces@xxxxxxxxxxx [mailto:aspectj-users-bounces@xxxxxxxxxxx] De la part de Andy Clement
Envoyé : mardi 6 janvier 2009 18:02
À : aspectj-users@xxxxxxxxxxx
Objet : Re: [aspectj-users] LTW Agent Dynamic Attachement with Attach API

 

Hi Jean-Louis,

I'd suspect we need the weaver to perhaps implement a new interface or two, so that it can be plugged in via that route - but I haven't looked into it.  I don't think we have an open enhancement request to support this, so you could create one.  And if you discover the magic we need to get it working, please add it to the enhancement - that would be the easiest way to get it done in the 1.6.4 timeframe.  I don't think it will be too complex as the weaver doesn't have any logic in to stop you trying to do this.

The disadvantage of attaching any time later than right up front is simply that things will not have been woven that have already been loaded (unless they are reloaded after the weaver is attached). 

Andy.

2009/1/6 <jeanlouis.pasturel@xxxxxxxxxxxxxxxxxx>

I have yet asked the question, and I made a try.

JDK 1.6 brings Sun Api to dynamically load java Agent http://java.sun.com/javase/6/docs/technotes/guides/attach/index.html

 

I test it with aspectjweaver.jar ( in fact a custom myaspectjweaver.jar that contains aspectjweaver.jar ) but I can't success a run.

 

Does-it possible to attach LTW agent, when an application is already running?

 Or the LTW agent *must* be loaded at starting?

 

 I see that there is some thing similar with the Equinox/Aspects; project in status incubator…

 

I load the Agent but the initialisation failed as shown with this traces:

 

E:\opt\perfStats\scripts>"C:\Program Files\Java\jdk1.6.0_11\bin\java"   -classpath ..\lib\myaspectjweaver.jar;"C:\Program Files\Java\jdk1.6.0_11\lib\tools.jar";

;. attachapi.launcher.PerfStatsLaunch 4668 E:\opt\perfStats\lib\myaspectjweaver.jar

loading agent : E:\opt\perfStats\lib\myaspectjweaver.jar

Echec Attach

com.sun.tools.attach.AgentInitializationException: Agent JAR loaded but agent failed to initialize

        at sun.tools.attach.HotSpotVirtualMachine.loadAgent(HotSpotVirtualMachine.java:103)

        at attachapi.launcher.PerfStatsLaunch.attachPerfStats(PerfStatsLaunch.java:33)

        at attachapi.launcher.PerfStatsLaunch.main(PerfStatsLaunch.java:69)

 

My MANIFEST.MF

Manifest-Version: 1.0

Name: org/aspectj/weaver/

Specification-Title: AspectJ Weaver Classes

Specification-Version: DEVELOPMENT

Specification-Vendor: aspectj.org

Implementation-Title: org.aspectj.weaver

Implementation-Version: DEVELOPMENT

Implementation-Vendor: aspectj.org

Premain-Class: org.aspectj.weaver.loadtime.Agent

Can-Redefine-Classes: true

Agent-Class: org.aspectj.weaver.loadtime.Agent

 

I added the Agent-Class line.

 

 

 

Cordialement / Best regards

Jean-Louis Pasturel

 

*********************************
This message and any attachments (the "message") are confidential and intended solely for the addressees.
Any unauthorised use or dissemination is prohibited.
Messages are susceptible to alteration.
France Telecom Group shall not be liable for the message if altered, changed or falsified.
If you are not the intended addressee of this message, please cancel it immediately and inform the sender.
********************************


_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users

 

*********************************
This message and any attachments (the "message") are confidential and intended solely for the addressees.
Any unauthorised use or dissemination is prohibited.
Messages are susceptible to alteration.
France Telecom Group shall not be liable for the message if altered, changed or falsified.
If you are not the intended addressee of this message, please cancel it immediately and inform the sender.
********************************
*********************************
This message and any attachments (the "message") are confidential and intended solely for the addressees.
Any unauthorised use or dissemination is prohibited.
Messages are susceptible to alteration.
France Telecom Group shall not be liable for the message if altered, changed or falsified.
If you are not the intended addressee of this message, please cancel it immediately and inform the sender.
********************************

Back to the top