I’m flying home from AOSD 2002, happy and rested, as I write this entry.
I presented CLAW, one of two dynamic aspect weaving systems demonstrated at AOSD 2002. The other system, called PROSE (PROgrammable extenSions of sErvices), was presented by Andrei Popovici, Thomas Grass, and Gustavo Alonso in their short paper titled “Dynamic Weaving for Aspect-Oriented Programming”. Their paper was very interesting; they presented a mechanism for dynamic runtime weaving of aspects in the JVM using the Java Virtual Machine Debugging Interfaces (JVMDI).[1] Their system, like CLAW, lets you weave aspects into arbitrary code at runtime. This includes system code.
Just a few minutes ago, I did some more extensive testing of CLAW; I’m using it to understand the internals of code access security. I just ran across an interesting problem while doing some pretty liberal weaves.[2] Specifically, my aspect code blew up the runtime when the System.AppDomain.SetupDomain() method was executed. Apparently, at this very early stage in the initialization of the runtime, methods such as System.Console.WriteLine() cannot be called.
This raises an interesting complication: if your aspect uses code that depends on the runtime being in a particular state, you will run into problems if it weaves methods that are executed before the runtime reaches the required state. Unfortunately, these types of problems are very difficult to diagnose (aside from dialog boxes that display helpful messages such as “_CorExeMain failed”).
I believe that all byte-code / CIL weavers will suffer from this problem. That includes dynamic runtime weavers such as PROSE and CLAW, as well as link-time weavers such as Hyper/J. I will likely introduce some restrictions into CLAW that will prevent it from weaving methods that are called early during an AppDomain’s initialization sequence. Just what methods must be excluded will be the subject of some future investigations. This will help avoid the weaving problem during initialization of the runtime.
The more general problem of weaving code that depends on the application being in some particular state, however, is an open topic of investigation.
[1] They do much the same type of runtime aspect weaving as CLAW does, although they can only do it while running the JVM in debug mode. This means that all JIT optimizations are disabled, which restricts its utility in production systems.
[2] I was weaving a trace aspect into a Hello World program using a System.* pointcut. Please don’t try this at home. This was done by a professional programmer in an airplane 39,000 feet over the Atlantic Ocean.