15.1. INTRODUCTIONAOSD improves separation of concerns by enabling the modular expression of crosscutting concerns. Modular implementation of a concern as one aspect[1] requires techniques to "weave" this implementation back into the code of all classes that require the concern. For instance, logging behavior expressed in one aspect must be "woven" into all the classes of a system whose activities should be recorded.
15.1.1. Challenges for Aspect WeavingA general solution for aspect weaving must deal with different times and development contexts. Weaving can be performed before a program starts (compile-time or static weaving), at load-time (load-time weaving), or after a class is loaded (dynamic weaving). Static weaving has the advantage of adding no unnecessary run-time penalty to a program's execution. However, in a dynamic class-loading context, static weaving has the weakness that it cannot enforce aspect application to dynamically loaded classes. With static weaving, we have to trust the programmer to identify the classes that belong to a program. In Java,[2] the only way to be sure of which classes are actually used by a program is by checking during dynamic class loading.
Weaving might be applied in fully controlled contexts or in partly controlled contexts, depending on how the woven entities are created and stored and in which format they are available. A program can be available as source code or in compiled form. Source code and compiled code can be entirely available beforehand, or parts of it can be generated at runtime. Code can be stored locally or on a remote host. Full control means that every part of the program is available as source code, and the code is stored locally and is entirely available beforehand. Otherwise, we have only partial control. These relationships are illustrated in Table 15-1.
Another challenge for weaving is managing variants. Not every incarnation of a system requires every aspect. In general, the number of possible variants grows exponentially with the number of possible adaptations. Depending on its context of use, an application might need to integrate a logging aspect, might apply an observer aspect for monitoring different subsets of the program state [24], might need to apply various security or synchronization exception handling policies [7], and so forth. In their discussion of "jumping aspects," for instance, Brichau, Meuter, and de Volder [7] show that different exception handling policies are required if an application is deployed standalone or as a component of another application. It could be prohibitive to generate all these variants statically and in advance. For these reasons, we need means for instrumenting the code base "on-the-fly," depending on the actual needs of an application in a concrete deployment scenario. 15.1.2. Promises of Load-Time Analysis and Transformation (LAT)Processing binaries at load time makes it possible to address many of the challenges mentioned above. Load-time analysis and transformation of class files (subsequently called LAT) can be used to implement load-time weaving or to insert code that performs run-time weaving. With a tool that can store transformed classes, LAT can also be used for static weaving of binary code. LAT is inherently applicable to black-box components delivered by third parties in binary format and is oblivious of the local or remote origin of binaries and of their static or dynamic creation. LAT processes only classes relevant in a given application context. It can further prevent static version proliferation by taking advantage of dynamic information for selection of relevant transformations and for their specialization to current run-time conditions. 15.1.3. Aspect-Oriented LAT with JManglerThe advantages of load-time transformation have motivated the development of various LAT tools and frameworks for Java class files. JMangler differs from other approaches in four main regards:
JMangler and its relation to other LAT tools are described in [10, 33]. Details of its use and various features that go beyond the scope of this paper are described in the tutorial that is available online and as part of the JMangler distribution [26]. A commercial development tool built with JMangler is presented in [31]. In Section 15.2, we introduce the notion of generic interception and explain how JMangler achieves generic interception. Then we present its open architecture, which enables other frameworks to be used as plug-ins for JMangler (Section 15.3), and we describe the treatment of non-local dependencies (Section 15.4). In Section 15.5, we introduce the concepts behind the weaver included in JMangler as far as necessary to understand its use in different AOSD scenarios. In Section 15.6, we discuss a few typical application scenarios: development of higher-level aspect tools, load-time weaving, run-time weaving, and applications beyond the expressive power of existing high-level AOSD languages. Section 15.7 examines related work. In Section 15.8, we summarize ongoing and future work before concluding. Appendix 15.A illustrates the implementation of a code transformer. |