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


This is what actually happens. The byte-code for class C is loaded and passed to the weaver. Before attempting to match any pointcuts references to all super-types (classes, interfaces and aspects) are resolved. Therefore the weaver may actually have the byte-code for classes B and A _before_ the JVM. This process is the same whenever weaving takes place (compile, binary, load) which is very important.The reference to the JVM specification is not quite correct:

        "Before a class is initialized, its direct superclass must be initialized, ..."

There is documentation for using the AspectJ language, tools and APIs. There is also some documentation to allow the extension of the compiler. However we do not have detailed documentation on its design and implementation.

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 AspectJ developer discussions <aspectj-dev@xxxxxxxxxxx>

Sent by:        aspectj-dev-bounces@xxxxxxxxxxx

To:        "'murvaja'" <murvaja@xxxxxxxxxxx>, "'AspectJ developer discussions'" <aspectj-dev@xxxxxxxxxxx>
Subject:        RE: [aspectj-dev] How does AspectJ implement load-time weaving?

Murali, the Java “language” specification guarantees that the VM will always load the superclass of a class before it loads the class itself. So this situation can never arise.
See step 7 at http://java.sun.com/docs/books/jls/third_edition/html/execution.html#12.4.2 for the details of how this is guaranteed.

From: aspectj-dev-bounces@xxxxxxxxxxx [mailto:aspectj-dev-bounces@xxxxxxxxxxx] On Behalf Of murvaja (sent by Nabble.com)
Thursday, January 05, 2006 9:31 PM
[aspectj-dev] How does AspectJ implement load-time weaving?

I've been trying to understand how AspectJ manages to match the '+' pointcut construct at runtime for load-time weaving. The example I have in mind is for the Hotspot JVM 1.5, with load-time weaving enabled through the -javaagent option, and goes as follows.

Say I have a class hierarchy like this:

public class A
  public void foo(){}

public class B extends A

public class C extends B
   public void foo(){}

And I write a pointcut and advice as follows:

pointcut pc() : execution (* A+.foo() )

before() : pc() {
//weaving code here

According to the pointcut definition, all subclasses of A will match the pointcut, so the load-time weaving should insert the weaving code at the beginning of both A.foo and C.foo. This will happen at their respective class-load times, that is, A.foo will be weaved when A is loaded and C.foo will be weaved when C is loaded.

My question is, how does the weaver do this if C is loaded before A and B, like in the following code (assume none of A, B or C can be loaded by the system class loader) ?

public static void main (String args[])
  ClassLoader loader = new MyClassLoader();

At the time C is loaded, the weaver will have C's bytes at hand and will have to decide whether to weave them or not. According to the pointcut definition, the bytecodes should be weaved because C is of type A. However, the weaver cannot know that at this time, because the C bytecode only contains a reference to its direct superclass B (not A), and the bytes for B are not yet available because B is not yet loaded.

Any leads? I've been trying to find documentation on this but to no avail. Thanks in advance,


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