Spoon-AOP: Template-Based AOP in pure Java

Spoon-AOP is an AOP weaver written with Spoon and that allows the programmer to define aspects in pure Java. It uses pure Java templates, which are applied at compile-time, with a mechanism that is comparable to macro expansion (parametrized code inlining). Spoon-AOP is geared toward using pure Java 5 (including annotations) to specify your aspects in a well-typed and efficient way.


Table of content

  1. Warning
  2. Introduction
  3. Getting Started
  4. Quick Reference Guide
  5. Discussion and Execution Times (comparison with AspectJ)

Warning

Spoon-AOP is an experiment that is under development to illustrate the use of Spoon. Also, it aims to prove that efficient and well-typed AOP can be achieved in pure Java. However, the Spoon-AOP weaver is not complete nor stable, and will probably be subject to major changes yet.

Introduction

Spoon-AOP is an AOP weaver written with Spoon and that allows the programmer to define aspects in pure Java. It uses pure Java templates, which are applied at compile-time, with a mechanism that is comparable to macro expansion. As a result, the woven code is directly inlined into the base program an there is very few infrastructural code needed to run the aspects. Indeed, the woven code mostly looks exactly like a programmer would have written it by hand. Here are some properties of Spoon-AOP.

  • Aspects (pointcuts, advices, etc) are expressed directly in Java.
  • Aspects are annotation aware and it is straightforward to write annotation-driven aspects.
  • Since an aspect in Spoon-AOP is a pure Java template (can be seen as a macro object), it allows for statically parametrized aspect code (in the advice and the introductions). Hence, aspects in Spoon-AOP are more generic and reusable.
  • Despite written in pure Java, Spoon is well typed and more efficient than most of the classical AOP approaches since it relies on the Spoon program transformation framework. In particular:
    • The aspect code is directly inlined in the target code, which implies good execution performances when accessing the target's local context.
    • The weaver has statically access to useful information on the joinpoint (as Spoon template parameters), such as the method names or the argument count. After macro expansion, Spoon-AOP uses a partial evaluation engine provided by Spoon, and the woven code can then be simplified and optimized: it is more efficient than classical AOP approaches such as AspectJ.


Author and Contact Information

  • Renaud Pawlak (renaud_dot_pawlak_at_inria_dot_fr)
  • Carlos Noguera (noguera_at_lifl_dot_fr)