|
AOP
[
avasseur
]
13:08, Saturday, 10 March 2007
Jonas and Eugene from Terracotta - the Naturally Clustered Java provider and maker of OpenTerracotta - have published a very interesting paper on industry use of AOP and point out some limitations present in current AOP frameworks: "Clustering the Java Virtual Machine using Aspect-Oriented Programming". Excerpt: This comes to no surprise to me as AspectJ is born for build time weaving and Eclipse integration and AspectWerkz was born for load time and runtime weaving. As author of both (as we joint forces from AspectWerkz to AspectJ back mhh.. 2 years ago) I was unable to get the best of both world in one engine as we initially focussed on features integration - such as thru the @AspectJ style that is annotation-defined and driven AOP. Since that time my open source bandwith has been drawned due to work engagements. That is unfortunate as I believe there are no technical reasons for this multi-weaving-optimized engine to not happen. Fortunately AspectJ is strong on runtime performance which is something you really have to consider as well. Their paper is available online on AOSD 2007
[
avasseur
]
17:48, Thursday, 29 December 2005
While AOP has reached a decent maturity level in the Java platform, thanks to several iniatives from different players with different priorities and goals (IBM, BEA, JBoss, Spring, and individuals like Bob Lee to name a few), Microsoft seems to be willing to move beyond that. Last year at AOSD they were hosting a session on Phoenix, an interesting building block in the .Net CLR labs to help enable AOP frameworks. The community in .Net around AOP is fairly active as well, and Microsoft did awarded some of the projects, like Alan Cyment' SetPoint hosted on CodeHaus, the home of AspectWerkz. Recently (Nov. 2005) Microsoft has set up a research event to emulate discussions around the best way to have good AOP solutions in the .Net platform. Several key .Net AOP project leads and folks from the AOP research academia were invited for a full day event at Redmond. As far as I know Sun never set up such an event to try to understand AOP from its roots, and most of the discussion on the field has been driven by individual to individual networking and the AOSD annual conference. I am eager to see where .Net ends up in that field in 2 years from now. There are certainly interesting architectures and concepts that we have implemented in Java based AOP that could be ported rightaway to .Net, though .Net luminaries have certainly several new ideas that 'd be worth exploring from Java luminaries point of view - and possibly standardizing on - obviously outside the JCP - unless Sun suddenly cares more about AOP.
[
avasseur
]
11:22, Thursday, 20 October 2005
It's there !
I am very pleased to announce the prototype version of JRockit that includes our AOP API is available. It will drive you far far away from current bytecode instrumentation techniques to a world of plain Java API, complete runtime control for hot deployment and undeployment, agnostic from the programming model you like for your aspects.
If you are involved in the AOP field, bytecode instrumentation field, APM field, and did not heard from us recently, please drop me an email and I 'll consider your participation in evaluating this technology to help us drive it to reality.
You can read the official announcement and some background information in our BEA dev2dev dedicated forum.
[
avasseur
]
13:30, Monday, 10 October 2005
Back in July Jonas suggested some semantics for a synchronized block join point. The discussion was interesting but I am wondering if we actually came up with the right question.
What if we simply think in terms of "is this type listening to locking events ?" instead of trying to come up with a pointcut expression that defines the semantics of a synchronized block - as done in Jonas discusion?
Lets draft some code:
Consider the program: class Bar { synchronized void foo() { .. } static synchronized void statfoo() { .. } void stuff() { .. synchronized(bar) { .. } } }
interface Lockable { void waiting(); void acquired(); void released(); } @Introduce("Bar")
class LockableNOOP implements Lockable {
void waiting() {}
void acquired() {}
void released() {}
}Replace all synchronized blocks like that: Given synchronized(stuff) {
..
}if (stuff instanceof Lockable) { Lockable lockable = (Lockable)stuff; lockable.waiting(); synchronized(stuff) { lockable.acquired(); ..// unchanged body } lockable.released(); } else { synchronized(stuff) { ..// unchanged body } } You can now access the enclosing static join point information if you need - which gives you if you really need it, the rich semantics Jonas was looking for: call(Lockable.waiting()) && withincode(....) && target(t) && cflow(...) .....
// t is the locked object
There are two interesting things to solve now:
[
avasseur
]
12:18, Wednesday, 10 August 2005
These last days I have been prototyping around an interesting idea.
As you know we have been working on an API to add JVM support for AOP in JRockit. The prototype will be available any time soon.
The nice thing about it is that you don't manipulate the bytecode anymore and that you are using only well known java.lang.reflect.* API to tell the JVM if your pointcut is matching or not. This is somehow similar to what ones can do with Spring AOP - as this one is proxy based (see f.e. MethodMatcher API in Spring).
The immediate benefit of it is that first there is no need to have another in-memory representation of classes beeing weaved (before they get loaded) that is backed by some expensive (both memory and CPU) bytecode analysis.
This advantage is detailled in our JVM support for AOP part1 article.
As a consequence it is really easy to query the method annotation, generics properties, and such - something that is extremely complex to achieve with acceptable overhead in regular bytecode based weaver such as AspectJ or AspectWerkz (actually more complex than changing some bytecode instruction). So what is that idea I had ? Having AOP support in JRockit is nice, but it will take some time before that gets mainstream (with eventually a JSR etc). In this transition period, there must be a way to implement a better bytecode based weaver that will perform way better than current weavers (both AspectJ and AspectWerkz), that will be easier to implement, and whose only requirement is Java 5 (well off course, it won't be as good as JRockit JVM support for AOP - so it is still a transition technology). I have thus been sketching on an hybrid system that makes extensive use of the hotswap API, and whose actual weaver relies only on pointcut matching backed by the java.lang.reflect.* API ie does not build any kind of equivalent structure backed by bytecode analysis. As such the memory overhead is zero, and the CPU overhead is way less than current AspectJ and AspectWerkz. The overall idea is quite simple and consists in 2 phases: Phase 1 A first weaver is changing the bytecode in some stable way - such that all classes are transformed (lets say prepared) the same way - while not introducing any dependancies on any kind of AOP, and while not adding any kind of performance overhead (ie no changes in the execution flow such as introduced by wrappers method and such usually used when implementing instrumentation needed for around advice). All classes thus get loaded as expected with a very limited time overhead and no memory overhead at all (thanks to the excellent ASM performance). Phase 2 Then when an actual class gets loaded (as per regular application behavior) I get a small callback invoked when this class has just been loaded and just before anything else happens (ie the class static initializer invoked by the JVM). Current load time weavers do things "just before the class gets loaded" and as such cannot access the java.lang.reflect representation of what they weave. This callback can then perform the actual weaving by relying entirely on the java.lang.reflect.* API to match the pointcuts. It then constructs the instrumented version of the class and hotswap it thanks to the Java 5 API. The JVM eats this one and goes on. The first prepare phase is needed as the hotswap API does forbids change in the schema (ie cannot add or remove methods or fields). A nice extra side effect is that at any point in time any class can be exposed to the AOP layer thru a simple API. This can be handy for some cases where there are some circular references in the dependancies (f.e. the instrumentation needs the java.lang.reflect.Method class to match against the pointcuts so if I want to add aspects to the Method class, I cannot do it until I have a representation of this class ie there 's no way to have it working by simply invoking the callback from the prepared Method class itself). This might seems like gory details, especially when compared to what we do in the JRockit JVM support for AOP, but I am sure there are some concepts worth digging there - as memory usage and weaving overhead as been reported more than once as a major problem (see f.e. use case with AspectJ reported by Ron Bodkin where the system takes 4 minutes to start instead of less than a minute without any weaver here) This makes it also very easy to add aspects even to java.* classes (though it's not generally a good idea unless you know what you are doing). This sample is an actual code snip of the actual AOP transformation (part of phase 2). As you can see it relies on the java.lang.reflect API. public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { if (!filter(access, name)) {//fast filter for f.e. clinit method as we look for method execution join points // see if we get a match for this join point // only java.lang.reflect.* API is used here Member method = ReflectQuery.getMethod(m_klass, name, desc); Class thisClass = m_klass; Class targetClass = null; Member withinCode = null; //do matching if (match(method, thisClass, targetClass, withinCode)) { //change the bytecode but don't change the schema for hotswap purpose } else { return super.visitMethod(access, name, desc, signature, exceptions); } } }
[
avasseur
]
09:34, Tuesday, 2 August 2005
We have plublished a follow-up to our JavaOne 2005 session that describes with some more details the JVM support for AOP that is beeing designed within the BEA JRockit JVM. This first article introduces the problems that usually happen with current weavers (in the Java land) and briefly described the proposed solution. The next part to appear in the following weeks will give more details and code samples. Read the article
We are currently working on making the prototype implementation available for further evaluation. If you could not attend JavaOne 2005, the slides are available from the JavaOne web site, and they are also available here The full webcast of the JavaOne session is also available on dev2dev.
[
avasseur
]
14:48, Monday, 1 August 2005
**** Introduction **** Some background
**** Running AspectJ by using AspectWerkz for load time weavingpackage org.aspectj.ext.ltw13; public class ClassPreProcessorAdapter implements // implements the AspectWerkz core interface org.codehaus.aspectwerkz.hook.ClassPreProcessor { /** * Concrete preprocessor we delegate to * This one sits in org.aspectj.weaver.loadtime.* */ private static ClassPreProcessor s_preProcessor; static { try { s_preProcessor = new Aj(); s_preProcessor.initialize(); } catch (Exception e) { throw new ExceptionInInitializerError("could not initialize preprocessor due to: " + e.toString()); } } public void initialize() { ; } public byte[] preProcess(String className, byte[] bytes, ClassLoader classLoader) { // skip bootCL if (classLoader == null) { return bytes; } // skip AJ weaver well know stuff to avoid circularity if (className != null) { String slashed = className.replace('.', '/'); if (slashed.startsWith("org/aspectj/weaver/") || slashed.startsWith("org/aspectj/bridge/") || slashed.startsWith("org/aspectj/util/") || slashed.startsWith("org/aspectj/apache/bcel") || slashed.startsWith("org/aspectj/lang/") ) { //System.out.println("SKIP " + className); return bytes; } } // do the weaving using AspectJ weaver return s_preProcessor.preProcess(className, bytes, classLoader); } } <java classname="org.codehaus.aspectwerkz.hook.Plug" fork="true" failonerror="true"> <classpath> <pathelement path="${java.home}/../lib/tools.jar"/> <path refid="aw.path"/> </classpath> <arg line="-target _boot/awaj-boot.jar"/> </java> <target name="test" depends="compile.test, compile, prepare"> <java classname="test.ltw13.Sample" fork="true" failonerror="true"> <classpath> ..... </classpath> <jvmarg line=" -Daj5.def=test/aop.xml -Xbootclasspath/p:_boot/awaj-boot.jar -Xbootclasspath/a:D:/aw/cvs_aw/aspectwerkz4/lib/aspectwerkz-core-2.0.jar -Daspectwerkz.classloader.preprocessor=org.aspectj.ext.ltw13.ClassPreProcessorAdapter "/> </java> **** Sample project
[
avasseur
]
13:02, Wednesday, 13 July 2005
There is an interesting option in AspectJ that is named -Xreweavable.
When turned on using any kind of compilation/weaving mode (compiling with ajc, within Eclipse AJDT, doing bynary weaving, or using loadtime weaving), each weaved class keeps track of
Actually, discussions are taking place if this should be the default. An interesting consequence is that it is fairly easy to implement an opt-out AOP engine that simply restores the state prior to weaving, and thus kicks out all the aspects from the application ! There are of course realistic use-cases for it :
This is actually very easy to do when using f.e. AspectWerkz-core as the backend to hook this one in and have it work as well on Java 1.3, and using ASM for the bytecode details. Here is a sample output (I am using AspectJ loadtime weaving to do the weaving first, but that could be done using post compilation with AJC, or compilation from within Eclispe AJDT etc) // in this sample, start the app with AspectJ loadtime weaving (could have been compiled with ajc instead) // and pipe with the UndoAspectJ opt-out engine using the AspectWerkz core // as a backend #java -javaagent:aspectjweaver.jar -Daj5.def=test/aop.xml -javaagent:aspectwerkz-jdk5-2.0.jar -Daspectwerkz.classloader.preprocessor= org.aspectj.ext.undoaspectj.ClassPreProcessor test.undoaspectj.Sample weaveinfo Type 'test.undoaspectj.Sample' (Sample.java:28) advised by around advice from 'test.undoaspectj.Sample$TestAspect' (Sample.java) // here is the opt-out message UndoAspectJ - test/undoaspectj/Sample was affected by test.undoaspectj.Sample$TestAspect // execution without any aspect takes place: Sample.target // without the opt-out we would see the aspect executing: weaveinfo Type 'test.undoaspectj.Sample' (Sample.java:28) advised by around advice from 'test.undoaspectj.Sample$TestAspect' (Sample.java) // execution with aspect takes place: Sample$TestAspect.around Sample.target
[
avasseur
]
13:32, Tuesday, 5 July 2005
I am happy to announce that the @AspectJ support within Eclipse AJDT will appear in the next build snapshots, ie very soon ! That is an important step that brings to the AspectWerkz and AspectJ merger all its meaning, by providing a plain Java syntax (based on annotations) to write AspectJ aspects (aka @AspectJ) while still providing excellent support for it in Eclipse AJDT plugin - just as it exists for the well know AspectJ style (code style). In the list of things to already expect, that will officially ship as of AspectJ 1.5 M3 in the following days:
As a world premiere, here is a snapshot of an @AspectJ aspect in AJDT ! For those of you using AspectWerkz, you may wish to give it a try very soon, as it is already much better that the Eclipse plugin I had written for AspectWerkz, and as it will help you to get started with the @AspectJ syntax in your favorite IDE. Start your download engines to get the next build snapshots and the upcoming AspectJ 1.5 M3 with your fresh Eclipse 3.1 final ! (Many thanks to Andrew and Mik for answering my questions to get that bits working)
[
avasseur
]
11:31, Thursday, 23 June 2005
Following the Backport175 release that Jonas and I have done some days ago, and since AspectJ 1.5 upcoming M3 and especially the @Aspect style is starting to take shape after some month of hard work on my side, I think it is a good timing to also explain that this @Aspect sytle, despite its name tied to these Java 5 annotations, is not at all tied to Java 5, and will bring the plain Java aspect concept to all of you using Java 1.3 and 1.4 (from the real world).
The @Aspect style is also referred as @AJ, or annotation style, or this way to write aspect with annotation that we came up with thru AspectWerkz.
It mainly means that AspectJ allows you to write an aspects using wether the well known code style or the AspectWerkz like annotation style.
// code style public aspect SomeAspect { void before() : execution(* Foo.bar()) { // do some stuff // use thisJoinPoint etc } } // annotation style, here with Java 5 @Aspect public class SomeAspect { @Before("execution(* Foo.bar())") void before(JoinPoint thisJoinPoint) { // do some stuff // use thisJoinPoint etc } } // annotation style, backported to Java 1.3 or 1.4 /** * @Aspect */ public class SomeAspect { /** * @Before("execution(* Foo.bar())") */ void before(JoinPoint thisJoinPoint) { // do some stuff // use thisJoinPoint etc } } @interface Aspect
) backported to Java 1.3 in the form of regular interfaces (ie interface Aspect
) and then make sure you have those classes first when doing the weaving.
Aside, since AJC (the AspectJ compiler) is not yet integrated in the doclet parsing pipeline, you need to follow a binary weaving strategy ie:
aj.root
in the build.properties
to the folder that contains aspectjrt.jar
and aspectjtools.jar
from a recent nightly build (will work for M3, does not for M2, so use a recent one!).
Then run ant clean test
.
Check the build.xml
file to understand how the different build steps are performed.
In the IDE it will also popup pretty well. See for example the little green
@
signs in the margin in this IntelliJ screenshot.
So now we have AspectJ @Aspect straight in IntelliJ.
Off course, you'd better use Eclipse AJDT to benefit from the rich user experience that it provides when dealing with software modularity thru AOP and AspectJ.
Using Backport175 also allows to use custom annotations in the pointcuts under Java 1.3 to define stronger contract between the aspect and the application, as Adrian describes here as the Holy Trinity (when you further add dependency injection)
(the demo don't include that but I let you try it).
In a follow-up post I will also explain how the new AspectJ enhanced load time weaving ala AspectWerkz can work with Java 1.3 and 1.4 as well - since it has been a recurrent question.
[
avasseur
]
18:34, Tuesday, 7 June 2005
JavaOne 2005 will be a good opportunity for you to have an update on the Make sure you attend this technical session on Tuesday June 28 (TS-7659, "Runtime Aspects With JVM Support") and have a You can also visit us at the Eclipse booth where we will show latest Meet you there !
[
avasseur
]
18:32, Monday, 24 January 2005
Three months ago when we wrote the AWBench AOP benchmark suite, I had to hack some little Spring AOP aspect and pointcuts. If you are familiar with Spring and know about AOP (AspectJ, AspectWerkz, JBoss etc), you know that Spring pointcuts are rather ... well sadly un-intuitives. I could not resist and integrating Spring with AspectWerkz pointcut (yes, once again for the third time, after the Spring container Jonas did and the extensible container we shipped.) A Spring pointcut before the wedding with AspectWerkz - almost impossible to combine with other patterns unless you have your "Mastering Spring XML" in the pocket...
Spring pointcut as a real pointcut thanks to the wedding with AspectWerkzPointcutAdvisor
[
avasseur
]
10:09, Wednesday, 19 January 2005
Today we have finally announced that we are joining AspectJ to work on AspectJ 5. We will focus on what has been the success of AspectWerkz The new team is backed by both IBM and BEA and the new project will be delivered in the coming months. One of the priority is to make sure that a smooth migration path exists from AspectWerkz to AspectJ 5. That' s a great day for AspectWerkz and AspectWerkz users.
[
avasseur
]
09:42, Wednesday, 22 December 2004
I am pleased to announce the first release of YAPB AOP. For those who don't like this April Fool like YAPB AOP, please read this post on The Server Side - read
Sample code
Extra features It took 40min to hack (time for a train trip, YAPB AOP are that easy today). If you want to do something usefull, write an email to your favorite AOP framework representative (AspectJ, AspectWerkz, JBoss AOP, Spring AOP, dynAOP, joyAOP [RIP ?], jeetAOP [RIP ?], YAPB AOP [RIP]) and wonder how to Download Now !
Access the source code Write your own ! Here are some ideas : If you have read till there
[
avasseur
]
19:25, Monday, 13 December 2004
Well, we for long have said that plain Java AOP and annotation defined aspects don't needs fancy GUI support, but I have to admit, this makes everyones life easier. So I am pleased to announce the availability of the AspectWerkz Eclipse Plugin based on the 2.x releases. Get it now, see the doc and the screenshots ! The plugin contains two almost disjunct features:
(Each feature is a builder so you can deactivate them on a a per project basis if you don't like them / use them.) Aside since your app will gets weaved, you can just click run and the aspects are in - nothing more to do. Feedback welcome. The plugin ships for Eclipse 3 and Java 1.4. More to come on Java 5 later. Alex Oh forgot to say before others make a story about that: yes we are the last one to write an Eclipse plugin, way (decades?) after AspectJ and some month after JBoss.
[
avasseur
]
11:36, Wednesday, 22 September 2004
I am back from the JAOO conference that is happening this week in Aarhus, a city in the west part of the Denmark. This post won't give you the right view on this conference, since I attented to my own fields related session aka AOP related, but anyway, you will have a minimum. The conferenceThe conference is this year largely sponsored by Microsoft, among others of the .Net or Java ground. Great guys are speaking there, like Rod Johnson (Spring / Interface21 - you know him), Rickard Oberg (former JBoss ejb guy, closed source AOP/CMS lead at Senselogic) , Martin Fowler, Arno Schmidmeier (early AspectJ user, AOSD consultant), Peter Von der Ahé (javac Sun guy), Jonas Bonér and myself to name a few and a bunch of .Net guys. Though the conference location was a bit far from the airport, the accomodation was good, lunches were fine, with DK stuff but not too much for a FR guy, and the monday night social party was pretty good. Day 1 - Keynote by MicrosoftI have attended the monday keynote given by a Microsoft guy. It was a good insight to see what MS is attempting to achieve, thinking ahead the C# things while people are just excited about the upcoming release of a new Visual C# things. it was interesting to hear about how clever is Microsoft when it leads to the latest Java 5 Tiger new features, which are some sort of compiler trick for most of them. Microsoft gave a bunch of other samples, and admitted that it was somehow easier to start a good language desgin from scratch that sketching on an existing one. Day 1 - SessionsI did not attended more on monday morning since I had to prepare some for our own session and I hope to see someone providing feedback on it since it is not fair to write it myself but still... Annotation driven AOP with AspectWerkzJonas and I were giving a talk in the J2SE track on Annotation and AOP. Annotations are also used in AspectWerkz as a matching mechanism, and we went thru a sample where it is perfectely safe to refactor your methods without taking care about the underlying AOP without any whatever IDE plugings. You can check our slides there, but for the impatient, here is how our strongly typed matching aspect looks like for annotation driven AOP. As you can see, there is no string based, wildcard based magic there. // Annotation driven AOP // Sample of strongly typed matching // in AspectWerkz AOP with annotations The session went fine, and the room was pretty much full, with around 400 attendees and after the session we met and chatted some with Rickard Oberg. After that we had a sort of J2SE panel, which turned out to be a BOF since the JAOO crew had not provided us with a moderator. It ended up in discussing some details and pitfalls in the new Tiger features, like generics and static import. Night 1 - All conferences are about social eventsIn the afternoon we met Arno Schmidmeier, an early AspectJ user (meaning late 90's), who is now doing AOSD consulting in Germany (give him a call if you need some AspectJ on-site knowledge), and we then head up to the social event / party with Rod Johnson. Time to share a bunch of beers paid by JAOO sponsors (Microsoft, Borland, Quest, and then I don't really remember) while discussing ideas about Proxy based AOP as in Spring, Geronimo integration, Spring AOP container for AspectWerkz, and some other things. Day 2 - SessionsOn day 2 I had to leave early and get back at work so I could only make it for Arno and Rickard'sessions and missed Rod' session unfortunately. AOP - let the code looks like the designArno Schmidmeier gave a talk in the Domain Driven Development track, where the main point was to explain how AOP could allow you to let the code looks like the design. He went thru some use-cases he had seen during his consultancy jobs, and the most interesting part of the session was when he explained how an expression for a domain requirements like "for every successfull bank account operation the accont balance must be checked after the operation and in case of failure, an error should be triggered by the system and the system notified that it should rollabck etc." could be mapped to an AspectJ after returning aspect and thus making his points that AOP enables you to have the code look like the design while avoiding code tangling issues. Attendees raised questions about code readability, modelling issues and similarities to a predicate language approach. I would have liked to see a running samples in AJDT and alike, and be able to navigate thru the aspects, and may be emphasis more on the domain level pointcuts idea. Rickard experiences on AOPI attended Rickard talk about experiences on AOP. This approach, which seems quite close to quantum AOP concepts, opens for a bunch of interesting things when it comes to GUI update propagation and server to server replication of sub-graph of persistable objects as well as undo/redo management which again should propagate... Rickard introduced the idea of a "property=development|production|whatever" pointcut element, that allows for sort of global on/off on the pointcuts. Something you can achieve with a "if" pointcut in AspectJ - although he probably did implemented it at weave time and not at runtime unlike the AspectJ "if". Rickard then explored the advantages and drawbacks of his "home made" AOP framework, and explained the idea of the abstract schema, where the aspect is abstract and then implements interface of classes where it is actually weaved to, providing sort of natural syntax for accessing the advice target instance methods from within the advice body. He then went thru a small demo wich showed a nice swinguish things, and then went thru some ajdoc equivalent, where generated javadoc for a class/member is exposing which advices are bounded to it and thru which pointcut. The next session was Rod Johnson session on Spring and Spring AOP. Unfortunately Jonas and I had to leave since mh, we are pretty busy these days. Wrap upThose 2 days were a good investement. I enjoyed the talk we gave there, and it was nice to meet and discuss more with people like Rod, Arno and Rickard.
Rickard explaining his Abstract Schema
[
avasseur
]
12:19, Sunday, 19 September 2004
Jonas and I are going to speak at JAOO about Annotation driven AOP in Java (Tiger / J2SE 5). This is a great opportunity to speak there, especially since those ideas have been implemented since the early time of AspectWerkz. Something that some of the other AOP framework are now following.
[
avasseur
]
15:37, Tuesday, 20 July 2004
I have sketeched a BEA WebLogic domain wizard, so that it is now possible to install a WebLogic server with AspectWerkz AOP in a minute.
Requirements: How to: Limitations: Extra bonus:
[
avasseur
]
11:38, Friday, 9 July 2004
Since we released AspectWerkz 1.0 beta 1 some days ago, with a real cool feature we had in our roadmap since the very begining, I have written a small tutorial for you to practice. AspectWerkz now supports the concept of an AOP container. No other AOP framework out there supports this idea in the way we do it : class loader aware and cross platform. The standard way of doing so is to use META-INF/aop.xml files, and for some container like Tomcat it is possible to use WEB-INF/aop.xml as well. You can drop Aspect classes at your system classpath and those will affect all deployed application, AND, you can have Aspect classes within your web application that will only affect this specific deployed application. Read the tutorial here.
[
avasseur
]
10:20, Thursday, 27 May 2004
On several recent ML post AspectWerkz users complained about getting into troubles when hooking in AOP in Tomcat 5. Steve provided good feedback but ... there is off course a damned better way to handle that ! Here is a little hands on that gives the idea for a 5 minutes shot. Pretty much straigthforward based on
I was concerned about this issue and had an hectic face to face burger discussion with Jonas about "my" so called seamless integration of AOP... I needed to sit down on that and hack, too bad for the jet lag in this crazy GMT 9h far from home SF BEA eWorld clock. Since the Codehaus had to migrate some CVS details today, the little qdox.jar fix that is needed cannot be commited, but just do it yourself if you want to go on with those explanations. Or wait tomorrow since Bob the despot is around there as well... He'll fix that for me if he is not too busy on the new Codehaus / BEA BeeHive stuff there. So I took a Tomcat 5 from Apache, unzipped the stuff on my windows box. I checked that it was fine with the bin/startup.bat and shutted it down to spread AOP in. Then I made sure that AW *cvs head* was builded, and ASPECTWERKZ_HOME and JAVA_HOME was set. I decided to give a try to this integration issue and decided to start with a silly tracing aspect that is sitting in AW samples (examples.logging.JavaLoggingAspect). I then builded the samples with a maven target (aspectwerkz:samples:compile)and had a new target/aspectwerkz-samples.jar ready to use. Then I just opened this bin/catalina.bat that is actually starting things and added this just before the comment:
to have AOP seamless integration:
So as you see I go with the bin\aspectwerkz.bat way, which is the easiest kick off stuff we provide, with adaptive behavior regarding Java version detection etc, even if when it comes to production usage I would rather use some JRockit VM. You will have noticed that I just added my silly tracing sample aspect in the CLASSPATH and replaced bin/java call by bin/aspectwerkz.bat - not taking care about the details. From there, Tomcat started up *almost* fine. The AW/lib/qdox-1.3.jar has a strange Manifest.mf file that Tomcat complains about... Just dropped this Manifest.mf from the qdox.jar and we are up and running with AOP online mode / class load time weaving / AOP container from cvs head. Time to bind my system level tracing Aspect to some application. I did a try by writting a 5 lines aop.xml file (actually copy pasted it from AW samples/hotdeployed.xml) and dropping it in Tomcat samples in webapps\servlets-examples\META-INF\aop.xml, since this is what we now provided in cvs head (and not in 0.10). Once that done, nothing happened. I added some tracing stuff (-Daspectwerkz.transform.verbose=true) and figured out (with a bit of pain since toString() on Tomcat classloader is damned too much verbose..) that Tomcat classloader is not taking this META-INF topmost stuff into account. I decided to move that to the WEB-INF/classes path, so ending up in webapps\servlets-examples\WEB-INF\classes\META-INF\aop.xml [file below]. I ll double check that later since this WEB-INF/.../META-INF is a bit strange there. and here it is (once I browsed to http://localhost:8080/servlets-examples/)
aop.xml
Conclusion We are almost there and 1.0 will be damned good don't you think ?
[
avasseur
]
23:15, Wednesday, 25 February 2004
In a recent post Bill Burke describes his preliminary research as regards HotSwap usage for dynamic AOP. He first defines in a few words what is dynamic AOP and what is the HotSwap or class redefinition in Java. Then he briefly describes how JBossAOP handles dynamic AOP thru a "prepare" phase, and gives some measurements about the overhead he obtained when using the -Xdebug mode during a JBoss startup sequence, an option required to activate the HotSwap API under Java 1.4. I would like to give some feedback on his post, since I have been working in the dynamic AOP field for some time now thru my involvment in AspectWerkz and thru a research paper and a runtime weaving prototype I did for the Dynamic Aspect Workshop for AOSD 2004. I think dynamic AOP has to be splitted in two categories:
The first category is fully supported by AspectWerkz. It is possible to rearrange (add/remove/reorder) aspects and advices at runtime providing that the join point(s) where the construct(s) is(are) bounded is(are) already existing as a result of the transformation phase, no matter it is a post compilation phase (ala AspectJ) or a class load time weaving.
The second category is the most interesting one. Redefining join points (thus pointcuts) allows - in theory - to add new AOP construct at new locations (join points) in the running application. This should come with the guarantee that there is
I think that this second category requires runtime weaving capabilities from the AOP framework (as long as the AOP frameworks rely on bytecode instrumentation). A use-case for join point redefinition at runtime is some on-demand profiling tool that needs to activate profiling only when necessary, for a limited time, and without any overhead prior to activation, and without specific knowledge on what will be profiled at application deployment time.
As Bill explains, JBossAOP "addresses" the second category by providing a way to declare pointcuts with nothing bounded. This definition is used at class post compilation / class load time and is what Bill calls the "prepare phase".
So what might be a better solution for true runtime join point redefinition ?
As Bill quotes, HotSwap API allows to change the implementation of method / constructor bodies of a class at runtime, and inject them in the running JVM.
So considering what HotSwap can do, and what bytecode instrumentation oriented AOP frameworks do to enable AOP in Java OOP, especially to enable dynamic AOP constructs of the first category I described previously, HotSwap seems very attractive, but is currently missing key things.
The fact that the java level HotSwap API as described in Java 1.4 JPDA requires a remote JVM attached to the running JVM (or a JPDA LaunchingConnector) can be avoided by implementing a JNI layer on top of the C-level HotSwap API so that HotSwap is available at Java level, without coupling with the JPDA architecture: no need for a remote JVM, and no need for a LaunchingConnector (that would forbid further remote dedbugging ...).
The "in-process HotSwap" - Java level API - is standardized in Java 1.5 thru the JSR-163. Java 1.5 will not requires -Xdebug to enable the HotSwap API. As you might have understood, the HotSwap API is not that coupled to the JVM debugging capabilities, althought the API was part of the same block in Java 1.4.
The schema change support would be interesting for AOP join point redefinition, since as Bill explains, AOP frameworks that allow dynamic AOP (AspectWerkz, JBossAOP) require some structural changes to bring in enough indirection level between the join point (in the weaved classed) and the AOP constructs (handled by the AOP framework internals).
class Foo { public void doAction() { // the bytecode for your code } } can appeared transformed after the weaving as (approximation) class Foo { JoinPointManager __AW_joinPointManager =... public void doAction() { __AW_joinPointManager.proceed(this, "doAction()"); } private void __AW_doAction() { // the bytecode for your code } }
As a consequence, if we would like to be able to redefine (f.e. simply define) the "* Foo.doAction(..)" execution pointcut at runtime, we would need schema change support. The schema change support might not be needed though for caller side constructs.
I think that HotSwap - if largely adopted by JVM implementation - can be a good enabler for dynamic AOP as regards pointcut redefinition at runtime. I don't think that the debate is limited to a -Xdebug option, and Java 1.5 demonstrates it.
I agree that this solution (which I will publish later in my blog) is itself not optimal but I was able to demonstrates the feasability of such an on-demand AOP approach, instead of an invasive pointcut definition, that might itself lead to a globally large overhead. I was able to do the prototype with Java 1.4, and it will be even more easy to do with Java 1.5 and the standardized "in-process" Java level HotSwap.
So far so good, what do we wanted ? Probably not a low level "addPointcut(<pointcut pattern>, Class klass)" API with a controlled and guaranteed minimal (or even zero) global overhead prior activation, but maybe a more usefull system wide control like "addAOPSystem(ClassLoader klassScope, SystemDefinition definition)" to be able to activate AOP constructs as a whole, at runtime, and leaving the internal recipe of it to AOP solutions and JVM implementations ... Right ?
[
avasseur
]
11:51, Tuesday, 6 January 2004
Today I finished my implementation of the new AspectWerkz pointcut expression language. AspectWerkz had already a good usability level as regards pointcut expression. Most of the needed syntax to bind pointcuts with advice or introduction had been implemented by Jonas, based on an algebra backed by Jexl.
/** @Execution com.*.Foo.set(..) */ /** @Execution com.*.Foo.get(..) */ /** @Around pc1 OR pc2 */ } The previous implementation supported the complete AND / OR / NOT algebra: What I found bad with this Jexl based implementation was the following:
After some digging in Jexl extensibility I decided to start my own boolean expression implementation based on a JJTree grammar. In two days I had the complete operator set I needed, and a true Visitor pattern exposure. In other two days I was able to refactor Jonas' work to plug my JJTree implementation in AspectWerkz. It allowed to solve a pending issue we had in the 0.9.RC1 release as regards cflow support for model 2 JSR-175 style Aspects. Now we have many advantages at the hand:
From a user point of view this grammar add a new operator for cflow: the IN and NOT IN (or ! IN etc ...). In the next month, I should have time to add the needed glue to support several level of cflow composition - since this is already supported by our JJTree grammar : This time, the trick will be more at the runtime during the joinpoint evaluation.
[
avasseur
]
20:41, Tuesday, 16 December 2003
Today while having my daily googling time on AOP, I found a 25 pages article about JMangler, a class load time weaving solution I had already bloged about. The paper is here as a PDF. I am rather surprised when I read that and mirror it with the fact that AOP would gain from massive adoption. I will defend my position in a very near future, but i could not avoid this flameware snip. JMangler quotes itself as A Powerful Back-End for Aspect-Oriented Programming. And you might even buy a Prentice Hall book in 2004 to learn that. Just to let you think about by your own while I am writting my flameware:
Is that a joke ? Abusing the AOP hype in the Academic sphere ?
[
avasseur
]
19:37, Friday, 21 November 2003
Samuel has done a viewlet where he demonstrates how to easily debug an application and its aspects with AspectWerkz from within Eclipse. If you did not yet understood how standard and easy it was from my first annoucement, you have to watch it now ! All is explained step by step. This is a definitely a things to work with. |