[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-dev] RE: How does AspectJ implement load-time weaving?


There is a simpler way to determine the order of class loading. Either use the JVM option "-verbose:class" or use the AspectJ LTW option "-verbose" which will show the order in which classes are woven. May I ask why you need this information; are you just curious?

Matthew Webster
AOSD Project
Java Technology Centre, MP146
IBM Hursley Park, Winchester,  SO21 2JN, England
Telephone: +44 196 2816139 (external) 246139 (internal)
Email: Matthew Webster/UK/IBM @ IBMGB, matthew_webster@xxxxxxxxxx


Please respond to murvaja <murvaja@xxxxxxxxxxx>; Please respond to AspectJ developer discussions <aspectj-dev@xxxxxxxxxxx>

Sent by:        aspectj-dev-bounces@xxxxxxxxxxx

To:        aspectj-dev@xxxxxxxxxxx
Subject:        [aspectj-dev] RE: How does AspectJ implement load-time weaving?

The 12-step process explained in your link refers to class initialization (done after linking) and not loading. From what I know, ClassLoader.loadClass("C") does not initialize C, it only loads it - that is, it finds the source bytecode and creates a java.lang.Class. Initialization of the class only occurs after the class is actually used in execution code, as explained below.  


I know that the JVM specification guarantees the initialization of all superclasses before the initialization of the class. However, by the time a class is initialized it is already too late to change the bytecode. Hence, the JVM 1.5 provides a hook at class *load* time, at a time when the superclass might not have been loaded yet.
In order to uncover the order in which loading and bytecode transformation is done, I implemented my own Java agent and attached it to a JVM running the "main" code above. That, along with inspection of the JVM source code implementation, suggested to me that things happen in the following order (shown in pseudocode - I used curly braces to indicate a code block executing within the body of the previous line):

     loader.defineClass(byte[] C_bytes); //these are the bytes in class C's bytecode
        transformer.transform(C_bytes);    // transformer is a ClassFileTransformer in my agent

This code flow indicates that loading C will indeed result in the loading of B and A. However, the JVM class-load hook into C (that is, the transform method) occurs before B or A are loaded. Thus, when inspecting C_bytes to determine whether it extends A, I find that I have neither B_bytes nor A_bytes available.

What am I missing here? I assume something must be wrong somewhere in my reasoning, otherwise AspectJ 5 wouldn't be able to provide its LTW capabilities :-)


View this message in context: RE: How does AspectJ implement load-time weaving?
Sent from the
AspectJ - dev forum at Nabble.com. _______________________________________________
aspectj-dev mailing list