Aspect weaver
aspects and creates new classes with the aspect code appropriately weaved into the classes. | |
Available in | AspectC++, AspectJ |
---|---|
Type | Aspect-oriented programming |
An aspect weaver is a
Aspect weavers take instructions known as
Motivation
Many programming languages are already widely accepted and understood. However, there is no significant desire to create radically different programming languages to support the aspect-oriented programming paradigm due to business-related risks associated with adopting new technologies.[1] Use of an entirely new language relies on a business's ability to acquire new developers. Additionally, the existing code base of a business would need to be discarded. Finally, a business would need to acquire a new toolchain (suite of tools) for development, which is often expensive in both money and time.[2] Primary concerns about roadmaps for the adoption of new technologies include the need to train new developers and adapt existing processes to the new technology.[3]
To address these business concerns, an aspect weaver enables the use of widely adopted languages like
Implementation
Aspect weavers operate by taking instructions specified by
Through this weaving process, aspect weavers allow for code which otherwise would have been duplicated across classes. By eliminating this duplication, aspect weavers promote modularity of cross-cutting concerns.[8] Aspects define the implementation code which otherwise would have been duplicated and then use pointcuts and join points to define the advice. During weaving, the aspect weaver uses the pointcuts and join points, known as a pointcut designator, to identify the positions in candidate classes at which the implementation should be injected.[9] The implementation is then injected into the classes at the points identified, thus permitting the code to be executed at the appropriate times without relying on manual duplication by the programmer.[10]
aspect Logger {
pointcut method() : execution(* *(..));
before() : method() {
System.out.println("Entering " +
thisJoinPoint.getSignature().toString());
}
after() : method() {
System.out.println("Leaving " +
thisJoinPoint.getSignature().toString());
}
}
public class Foo {
public void bar() {
System.out.println("Executing Foo.bar()");
}
public void baz() {
System.out.println("Executing Foo.baz()");
}
}
|
A sample class defined in the AspectJ programming language
|
public class Foo {
public void bar() {
System.out.println("Entering Foo.bar()");
System.out.println("Executing Foo.bar()");
System.out.println("Leaving Foo.bar()");
}
public void baz() {
System.out.println("Entering Foo.baz()");
System.out.println("Executing Foo.baz()");
System.out.println("Leaving Foo.baz()");
}
}
|
The woven class that results from executing an aspect weaver on the above sample |
Weaving in AspectJ
In the
The example at right shows a potential implementation of an aspect which logs the entry and exit of all
The aspect weaver analyzes the advice specified by the pointcut in the aspect and uses that advice to distribute the implementation code into the defined class. The code differs slightly in each method due to slight variances in requirements for the method (as the method identifier has changed). The aspect weaver determines the appropriate code to generate in each situation as defined by the implementation advice and then injects it into methods matching the specified pointcut.[13]
Weaving to bytecode
Instead of generating a set of woven
It is expected that the performance of aspect weavers which also perform the compilation process will require more computation time due to the weaving process involved. However, the bytecode weaving process produces more efficient runtime code than would usually be achieved through compiled woven source.Run-time weaving
Developments in AspectJ have revealed the potential to incorporate
To accomplish just-in-time weaving, a change to the
Performance
Aspect weavers' performance, as well as the performance of the code that they produce, has been a subject of analysis. It is preferable that the improvement in modularity supplied by aspect weaving does not impact run-time performance. Aspect weavers are able to perform aspect-specific optimizations.thisJoinPoint
, which contains information about this particular instance of woven code, and thisJoinPointStaticPart
, which contains information common to all instances of code relevant to that set of advice. The optimization of replacing thisJoinPoint
with the more efficient and static keyword thisJoinPointStaticPart
can only be done by the aspect weaver. By performing this replacement, the woven program avoids the creation of a join point object on every execution.[14] Studies have shown that the unnecessary creation of join point objects in AspectJ can lead to a performance overhead of 5% at run-time, while performance degradation is only approximately 1% when this object is not created.[22]
Compile-time performance is generally worse in aspect weavers than their traditional compiler counterparts due to the additional work needed for locating methods which match the specified pointcuts. One study showed that the AspectJ compiler ajc is about 34% slower than the
See also
References
- ^ Kiczales (October 2001), p.2
- ^ Kiczales (October 2001), p.7
- ^ Colyer (2003), p.6
- ^ Kiczales (October 2001), p.5
- ^ a b Kiczales (June 2001), p.3
- ^ Spinczyk (2002), p.1
- ^ Wand (2004), p.1
- ^ Wand (2004), p.7
- ^ Viega (November 2000), p.2
- ^ Spinczyk (October 2007), p.21
- ^ Wang (July 2007), p.4
- ^ Avgustinov (2007), p.2
- ^ Hilsdale (2004), pp.5–6
- ^ a b Hilsdale (2004), p.2
- ^ McEachen (2005), p.1
- ^ Popovici (2003), p.1
- ^ a b Sato (September 2003), p.17
- ^ Sato (September 2003), p.2
- ^ a b Papovici (2003), p.3
- ^ Sato (September 2003), p.11
- ^ Gal (2001), p.3
- ^ Colyer (2003), p.2
- ^ Hilsdale (2004), p.7
Bibliography
- Avgustinov, Pavel; Hajiyev, Elnar; Ongkingco, Neil; de More, Oege; Sereni, Damien; Tibble, Julian; Verbaere, Mathieu (2007). "Semantics of static pointcuts in aspectJ". Proceedings of the 34th annual ACM SIGPLAN-SIGACT symposium on Principles of programming languages. S2CID 16484088.
- Colyer, Adrian; Clement, Andy; Bodkin, Ron; Hugunin, Jim (2003). "Using AspectJ for component integration in middleware". Companion of the 18th annual ACM SIGPLAN conference on Object-oriented programming, systems, languages, and applications (PDF). pp. 339–344. ]
- Gal, Andreas; Schröder-Preikschat, Wolfgang; Spinczyk, Olaf (2001). "On Minimal Overhead Operating Systems andAspect-Oriented Programming" (PDF). Proceedings of the 4th Workshop on Object-Orientation and Operating Systems at the 15th European Conference on Object-Oriented Programming (ECOOP-OOOSW). Retrieved 27 January 2010.
- Hilsdale, Erik; Hugunin, Jim (2004). "Advice weaving in AspectJ". Proceedings of the 3rd international conference on Aspect-oriented software development (PDF). S2CID 14674749. Archived from the original(PDF) on 27 July 2011. Retrieved 23 January 2009.
- Kiczales, Gregor; Hilsdale, Erik; Hugunin, Jim; Kersten, Mik; Palm, Jeffrey; Griswold, William (October 2001). "Getting Started with AspectJ". Communications of the ACM. 44 (10): 59–65. S2CID 3025764.
- Kiczales, Gregor; Hilsdale, Erik; Hugunin, Jim; Kersten, Mik; Palm, Jeffery; S2CID 45517610. Archived from the original (PDF) on 2004-07-30. Retrieved 4 January 2010.)
{{cite book}}
:|journal=
ignored (help - McEachen, Nathan; Alexander, Roger (2005). "Distributing classes with woven concerns". Proceedings of the 4th international conference on Aspect-oriented software development. S2CID 15728009.
- Popovici, Andrei; Alonso, Gustavo; Gross, Thomas (2003). "Just-in-time aspects". Proceedings of the 2nd international conference on Aspect-oriented software development. S2CID 1662985.
- Sato, Yoshiki; Chiba, Shigeru; Tatsubori, Michiaki (September 2003). "A Selective, Just-in-Time Aspect Weaver" (PDF). Generative Programming and Component Engineering. Lecture Notes in Computer Science. Vol. 2830. pp. 189–208. ISBN 978-3-540-20102-1. Archived from the original(PDF) on 2010-09-24. Retrieved 4 January 2010.
- Spinczyk, Olaf; Gal, Andreas; Schröder-Preikschat, Wolfgang (2002). "AspectC++: An Aspect-Oriented Extension to the C++ Programming Language" (PDF). Proceedings of the Fortieth International Conference on Tools Pacific. 21: 53–60. Archived from the original (PDF) on 13 October 2009. Retrieved 4 January 2010.
- Spinczyk, Olaf; Lohmann, Daniel (October 2007). "The design and implementation of AspectC++" (PDF). Knowledge-Based Systems. 20 (7): 636–651. . Retrieved 23 January 2010.
- Viega, John; Voas, Jeffrey (November 2000). "Can Aspect-Oriented Programming lead to More Reliable Software?". .
- Wand, Michael; Kiczales, Gregor; Dutchyn, Christopher (2004). "A semantics for advice and dynamic join points in aspect-oriented programming" (PDF). ACM Transactions on Programming Languages and Systems. 26 (5): 890–910. S2CID 12456097. Archived from the original(PDF) on 25 August 2011. Retrieved 23 January 2009.
- Wang, Yi; Zhao, Jianjun (July 2007). "Specifying Pointcuts in AspectJ". 31st Annual International Computer Software and Applications Conference - Vol. 2 - (COMPSAC 2007) (PDF). Vol. 2. pp. 5–10. S2CID 18772035. Archived from the original(PDF) on 20 March 2009. Retrieved 23 January 2010.
Further reading
- Suzuki, Junichi; Yamamoto, Yoshikazu (June 1999). Moreira, A. M.; Demeyer, Moreira (eds.). "Extending UML with Aspects: Aspect Support in the Design Phase" (PDF). Proceedings of the Workshop on Object-Oriented Technology. 1743: 299–300. Archived from the original (PDF) on 22 July 2011. Retrieved 4 January 2010.