Section 15.4. SUPPORT FOR NON-LOCAL TRANSFORMATIONS


15.4. SUPPORT FOR NON-LOCAL TRANSFORMATIONS

The class-loading mechanism of Java is linear: Every class is loaded completely before another class starts loading. Figure 15-3 illustrates the corresponding flow of raw class files from the hook to the active weaver. The weaver creates a higher-level representation and transforms this representation before converting it back to a byte stream for the JVM.

Figure 15-3. Linear loading of class files: Every class gets loaded and transformed completely before another class can be loaded.


This scheme is sufficient for the implementation of local analyses and transformations, which need information about just one class at a time. Examples include the introduction of accessor methods or access counters in a class and simple before, after, and around advice.

However, many analyses and transformations are non-local because they depend on the contents of multiple class files. For instance, the addition of forwarding methods requires information about the interface of the class being forwarded to.

Non-local dependencies impose problems for load-time weaving. On one hand, the instrumentation of one class must be completed before handing the class over to the JVM (as the HotSwap API of JDK 1.4 does not support addition of methods and fields at runtime). On the other hand, instrumentation of a class cannot be completed before further classes on which it depends are loaded and analyzed. This is not possible with the linear class-loading model of Java.

To resolve this problem, JMangler extends the Java class-loading model by providing nested class loading: While loading and transforming a class, it is possible to load, analyze, and transform other classes. As illustrated in Figure 15-4, classes loaded and transformed during the processing of another class are stored and only passed to the JVM after completion of the suspended class loading process. Storage of transformed classes also enables their use for later non-local analyses (without having to repeat the same transformations again).

Figure 15-4. JMangler provides nested class loading: While loading and transforming a class, it is possible to load, analyze, and transform further classes. All transformed classes are stored for later non-local analyses. The numbers in the figure indicate the sequence of steps performed.


Nested loading is implemented in the MemoryClassLoaderHook of JMangler. It is thus available to every plug-in. Linear class loading is supported by the SieveClassLoaderHook to avoid the overhead of nested loading when it is not required. Applications can choose the preferred loading model simply by setting an option in a configuration file.



Aspect-Oriented Software Development
Aspect-Oriented Software Development with Use Cases
ISBN: 0321268881
EAN: 2147483647
Year: 2003
Pages: 307

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net