harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sian January" <sianjanu...@googlemail.com>
Subject [classlib] Using Aspects for Tracing
Date Tue, 14 Nov 2006 11:57:48 GMT

Following a recent discussion on this list I have been looking into how
aspects could be used for tracing in the Harmony class library code.  I have
been using AspectJ and have written a really simple tracing aspect for the
math module, adapted the build.xml script and written some instructions on
how to apply it.  At the moment the aspect just does entry and exit tracing
and prints to System.out, but this is because it's a first draft - it is
possible to do more targeted tracing and to use frameworks such as
java.util.logging with aspects.

Steps to follow:

1. Download AspectJ from http://www.eclipse.org/aspectj/downloads.php

2. Copy aspectjrt.jar to /depends/jars/aspectj/

3. Copy aspectjtools.jar and aspectjrt.jar to ANT_HOME/lib and if using
Eclipse add both of these to your ant runtime configuration (Window >
Preferences > Ant > Runtime > Add...)

4. Edit build file to use iajc* instead of javac and include aspect class
files (or apply the buildxmlpatch.txt to build.xml in the math module)

5. Write a tracing aspect (or copy the one attached to

6. Re-build the module

7. Make sure to add aspectjrt.jar to the runtime classpath of whatever
program you are running.

* - iajc isn't incremental like javac in ant, it will always do a total
rebuild.  Also if you switch from using iajc back to javac you will need to
do a clean before you do a rebuild.
Please also note that it's not possible to use this kind of tracing for any
classes that are depended on by the AspectJ runtime or there will be errors
initializing the classes because of circular dependencies.  However I think
most modules apart from luni should be safe.  Also it's important to not
trace methods that are called (directly or indirectly) by your tracing
methods otherwise you will end up in an endless loop.

If anyone thinks this information might be useful to have available
somewhere I would be happy to expand it a bit for a web page or a Wiki page.



Sian January

IBM Java Technology Centre, UK

View raw message