[abc-dev] Invoking ABC on classes programmatically

From: Arjan Seesing <a.c.seesing@gmail.com>
Date: Wed Jul 06 2005 - 16:32:34 BST

I have a question and asking for some general input.
In Java 1.5 it is possible to redefine classes during runtime. My idea was
to use this feature to enable and disable tracing aspects during runtime
when they are very expensive.
>From the overview of the abc compiler I concluded that it needed the source
of the aspects but could work on the bytecode of the java class files.
My idea is then as follows:
 The Java 1.5/5.0 specification and VM add capability for runtime
instrumentation. The normal way is to define a ClassFileTransformer class,
which implements a interface with one method. This method is called
everytime a new class is about to load. This class gets the raw bytes and
can use those to instrument the class. It has to return the new array of
bytes.
Every class transformer class has to be registered to the VM in a special
premain method, which is similar to the main method for applications. The
premain method will be invoked before the main method when the application
is executed with a special argument. The classes for the instrumentation
have to be packaged in a special jar file with a manifest file.
Besides this normal use, one can also use the redefineClasses() method in
the Instrumentation object to change the definition of classes during
runtime. I think it is possible to (ab)use this system to apply and remove
aspects during runtime. The interface will be that the user can specify on
the command line multiple sets of aspects (in a file or on the commandline
directly) (aspects source, not compiled). The first set will be applied
before the program starts, the others can be switched to during runtime by
invoking an method. One can also programmaticaly specify during runtime
which aspects should be applied.
I will use the abc compiler, which can apply aspects on normal java classes
in bytecode form if the aspects themselves are in pure source form. When the
system switches to a new set of aspects, it will suspend all running threads
except his own. Then it will load the newly compiled classes with the new
aspects, when it is done, it resumes all the Threads.
To increase performance I will implement a background thread with a low
priority which will start compiling the other sets of aspects and stores the
result in a cache, so that the compiling doesn't have to be done at the
switch.
 My direct 'problem' now is how to call the abc compiler so that:
- I can give it a bunch of aspects and a set of java class files and that I
receave the class files back, preferrable in byte arrays
- I can compile individual class files with aspects (for the initial
starting of the application, when you get all the class files one by one
just before they are loaded)

Do you think this is actually possible? If so, how do you recommend I
proceed?

Arjan Seesing
Received on Wed Jul 6 16:32:42 2005

This archive was generated by hypermail 2.1.8 : Sun Jul 31 2005 - 23:50:05 BST