An Efficient and Flexible Implementation of Aspect-Oriented
Total Page:16
File Type:pdf, Size:1020Kb
An Efficient and Flexible Implementation of Aspect-Oriented Languages Vom Fachbereich Informatik der Technischen Universit¨at Darmstadt genehmigte Dissertation zur Erlangung des akademischen Grades eines Doktor-Ingenieurs (Dr.-Ing.) vorgelegt von Diplom-Informatiker Christoph-Matthias Bockisch geboren in Bielefeld Referentin: Prof. Dr.-Ing. Mira Mezini Korreferent: Prof. dr. ir. Mehmet Ak¸sit Datum der Einreichung: 14. Mai 2008 Datum der mundlichen¨ Prufung:¨ 1. Juli 2008 Erscheinungsjahr 2009 Darmstadt D17 Abstract Compilers for modern object-oriented programming languages generate code in a platform independent intermediate language [LY99, CLI06] preserv- ing the concepts of the source language; for example, classes, fields, meth- ods, and virtual or static dispatch can be directly identified within the in- termediate code. To execute this intermediate code, state-of-the-art im- plementations of virtual machines perform just-in-time (JIT) compilation [DS84, ACL+99, Ayc03] of the intermediate language; i.e., the virtual in- structions in the intermediate code are compiled to native machine code at runtime. In this step, a declarative representation of source language con- cepts in the intermediate language facilitates highly efficient adaptive and speculative optimization of the running program which may not be possible otherwise. In contrast, constructs of aspect-oriented languages|which improve the separation of concerns|are commonly realized by compiling them to con- ventional intermediate language instructions or by driving transformations of the intermediate code, which is called weaving. This way the aspect-oriented constructs' semantics is not preserved in a declarative manner at the inter- mediate language level. This representational gap between aspect-oriented concepts in the source code and in the intermediate code hinders high perfor- mance optimizations and weakens features of software engineering processes like debugging support or the continuity property of incremental compila- tion: modifying an aspect in the source code potentially requires re-weaving multiple other modules [SDR08, RDHN06]. To leverage language implementation techniques for aspect-oriented lan- guages, this thesis proposes the Aspect-Language Implementation Archi- tecture (ALIA) which prescribes|amongst others|the existence of an in- termediate representation preserving the aspect-oriented constructs of the source program. A central component of this architecture is an extensible and flexible meta-model of aspect-oriented concepts which acts as an inter- face between front-ends (usually a compiler) and back-ends (usually a vir- tual machine) of aspect-oriented language implementations. The architecture iii and the meta-model are embodied for Java-based aspect-oriented languages in the Framework for Implementing Aspect Languages (FIAL) respectively the Language-Independent Aspect Meta-Model (LIAM) which is part of the framework. FIAL generically implements the work flows required from an ex- ecution environment when executing aspects provided in terms of LIAM. In addition to the first-class intermediate representation of aspect-oriented con- cepts, ALIA|and the FIAL framework as its incarnation|treat the points of interaction between aspects and other modules|so-called join points|as being late-bound to an implementation. In analogy to the object-oriented terminology for late-bound methods, the join points are called virtual in ALIA. Together, the first-class representation of aspect-oriented concepts in the intermediate representation as well as treating join points as being virtual facilitate the implementation of new and effective optimizations for aspect- oriented programs. Three different instantiations of the FIAL framework are presented in this thesis, showcasing the feasibility of integrating language back-ends with dif- ferent characteristics with the framework. One integration supports static as- pect deployment and produces results similar to conventional aspect weavers; the woven code is executable on any standard Java virtual machine. Two in- stantiations are fully dynamic, where one is realized as a portable plug-in for standard Java virtual machines and the other one, called SteamloomALIA, is realized as a deep integration into a specific virtual machine, the Jikes Research Virtual Machine [AAB+05]. While the latter instantiation is not portable, it exhibits an outstanding performance. Virtual join point dispatch is a generalization of virtual method dis- patch. Thus, well established and elaborate optimization techniques from the field of virtual method dispatch are re-used with slight adaptations in SteamloomALIA. These optimizations for aspect-oriented concepts go be- yond the generation of optimal bytecode. Especially strikingly, the power of such optimizations is shown in this thesis by the examples of the cflow dynamic property [ACH+05b], which may be necessary to evaluate during virtual join point dispatch, and dynamic aspect deployment [MO03]|i.e., the selective modification of specific join points' dispatch. In order to evaluate the optimization techniques developed in this thesis, a means for benchmarking has been developed in terms of macro-benchmarks; i.e., real-world applications are executed. These benchmarks show that for both concepts the implementation presented here is at least circa twice as fast as state-of-the-art implementations performing static optimizations of the generated bytecode; in many cases this thesis's optimizations even reach a speed-up of two orders of magnitude for the cflow implementation and even four orders of magnitude for the dynamic deployment. iv The intermediate representation in terms of LIAM models is general enough to express the constructs of multiple aspect-oriented languages. There- fore, optimizations of features common to different languages are available to applications written in all of them. To proof that the abstractions provided by LIAM are sufficient to act as intermediate language for multiple aspect- oriented source languages, an automated translation from source code to LIAM models has been realized for three very different and popular aspect- oriented languages: AspectJ [KHH+01], JAsCo [VSV+05] and Compose* [BA01, dRHH+08]. In addition, the feasibility of translating from CaesarJ [AGMO06] to LIAM models is shown by discussion. The use of an exten- sible meta-model as intermediate representation furthermore simplifies the definition of new aspect-oriented language concepts as is shown in terms of a tutorial-style example of designing a domain specific extension to the Java language in this thesis. v Zusammenfassung Compiler fur¨ moderne Objekt-orientierte Programmiersprachen generieren Code in einer Plattform-unabh¨angigen Intermediate-Sprache [LY99, CLI06], die die Konzepte der Quell-Sprache erh¨alt; zum Beispiel k¨onnen Klassen, Felder, Methoden und virtueller oder statischer Methodendispatch direkt im Intermediate-Code identifiziert werden. Um diesen Intermediate-Code auszufuhren,¨ fuhren¨ aktuelle Implementierungen von virtuellen Maschinen sogenannte just-in-time (JIT) Compilierung der Intermediate-Sprache durch [DS84, ACL+99, Ayc03]; das bedeutet, dass die virtuellen Instruktionen im Intermediate-Code zur Laufzeit zu nativem Maschinencode compiliert werden. In diesem Schritt erm¨oglicht eine deklarative Repr¨asentation der Konzepte aus der Quell-Sprache in der Intermediate-Sprache h¨ochst effiziente adaptive und spekulative Optimierungen des laufenden Programms, die sonst nicht m¨oglich w¨aren. Im Gegensatz hierzu werden die Konstrukte von Aspekt-orientierten Pro- grammiersprachen { die zu einer besseren \Separation of Concerns" fuhren¨ { ublicherweise¨ dadurch realisiert, dass sie zu herk¨ommlichen Intermediate- Instruktionen compiliert werden oder dass sie Transformationen im Interme- diate-Code bewirken; dies wird \Weben" genannt. Auf diese Weise bleibt die Semantik Aspekt-orientierter Konstrukte auf der Ebene der Intermediate- Sprache nicht deklarativ erhalten. Durch diese Kluft in der Darstellung Aspekt-orientierter Konzepte im Quell-Code und im Intermediate-Code wer- den hoch-performante Optimierungen behindert und Eigenschaften eines Soft- ware-Entwicklungsprozesses geschw¨acht, wie Unterstutzung¨ beim Debuggen oder die Continuity-Eigenschaft von inkremeteller Compilierung: Eine Mod- ifikation an einem Aspekt im Quell-Code zieht m¨oglicherweise das erneute Weben mehrerer anderer Module nach sich [SDR08, RDHN06]. Um die Sprach-Implementierungstechniken fur¨ Aspekt-orientierte Pro- grammiersprachen zu verbessern, wird in dieser Arbeit die Architektur fur¨ Aspekt-Sprachen-Implementierungen (englisch Aspect-Language Implemen- tation Architecture, ALIA) vorgeschlagen, welche unter anderem vorschreibt, dass eine Intermediate-Repr¨asentation existiert, die die Aspekt-orientierten vii Konstrukte aus dem Quell-Programm erh¨alt. Eine zentrale Komponente dieser Architektur ist das erweiterbare und flexible Meta-Model von Aspekt- orientierten Konzepten, das als Schnittstelle zwischen Front-Ends (ublicher-¨ weise ein Compiler) und Back-Ends (ublicherweise¨ eine virtuelle Maschine) von Aspekt-orientierten Sprachimplementierungen dient. Die Architektur und das Meta-Model sind fur¨ Java-basierte Sprachen in dem Framework zum Implementieren von Aspekt-Sprachen (englisch Framework for Implementing Aspect Languages, FIAL) beziehungsweise dem Sprachunabh¨angigen Aspekt- Meta-Model (englisch Language-Independent Aspect Meta-Model, LIAM), das Teil des Frameworks ist, verk¨orpert. FIAL implementiert