Towards a Domain-Specific Aspect Language for Dynamic Program Analysis Position Paper Walter Binder Philippe Moret Danilo Ansaloni Aibek Sarimbekov Akira Yokokawa
Éric Tanter PLEIAD Laboratory Computer Science Department (DCC) University of Chile – Chile
Faculty of Informatics University of Lugano – Switzerland
[email protected]
[email protected] ABSTRACT
inference, and reverse engineering. However, writing dynamic analysis tools requires in-depth expert knowledge of low-level techniques such as program instrumentation, resulting in a tedious, time-consuming, error-prone, and expensive tool development process. Consequently, most software engineers do not write custom dynamic analysis tools but rely on a limited number of tools provided by third parties. Sometimes, the available analysis tools do not exactly meet the requirements of the software engineer, who may want to explore a specific feature of an application. In this position paper, we outline a new approach to developing dynamic program analysis tools with considerably less programming effort, addressing the following research question: Can we raise the abstraction level for writing dynamic analysis tools, allowing software engineers to rapidly develop custom analysis tools, impairing neither expressiveness nor tool performance? The pointcut/advice mechanism used in aspect-oriented programming (AOP) [8] offers a convenient, high-level abstraction for specifying certain program instrumentations. Pointcuts denote join points (i.e. events in the execution of programs) of interest, and advice specify the actions to be performed when execution reaches these points. Unfortunately, existing AOP languages such as AspectJ1 have not been especially designed for the development of dynamic analysis tools. Several limitations severely restrict the applicability of current aspect languages for dynamic analysis: 1. lack of join points at the level of basic blocks of code and at the level of individual bytecodes; 2. lack of support for embedded custom static analysis in the weaving process; 3. access to some context information (e.g., actual method arguments) introduces high overhead; 4. lack of support for passing data between advice in local variables of woven methods; 5. no built-in support for effectively parallelizing small analysis workloads on multicores; 6. composition of separately developed analyses yields unpredictable and misleading results. In order to overcome these limitations, we investigate the design and implementation of a novel domain-specific aspect language (DSAL) that is based on the pointcut/advice mechanism found in AOP, and offers dedicated new features that are essential for the development of a wide range of effi-
Despite the increasing importance of dynamic analysis in modern software engineering, the basic abstractions used to develop dynamic analysis tools have not significantly improved for long time. Developing dynamic analyses with low-level instrumentation techniques is error-prone and time consuming, whereas high-level approaches using aspect-oriented programming limit expressiveness, because the join point model in current general-purpose aspect languages has not been especially designed for dynamic analysis tasks. In this position paper, we promote a new domainspecific aspect language for dynamic program analysis in order to provide new foundations for the productive development of flexible and efficient dynamic analysis tools.
Categories and Subject Descriptors D.3.3 [Programming Languages]: Language Constructs and Features
General Terms Languages
Keywords Domain-specific languages, dynamic program analysis
1.
INTRODUCTION
While the use of polymorphism, reflection, and dynamic code loading limits the applicability of static analysis in modern object-oriented programming languages, dynamic program analysis is becoming increasingly important, as it supports a wide range of software engineering tasks such as profiling, debugging, testing, program comprehension, type
Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. To copy otherwise, to republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. DSAL’11, March 22, 2011, Pernambuco, Brazil. Copyright 2011 ACM 978-1-4503-0648-5/11/03 ...$10.00.
1
9
http://www.eclipse.org/aspectj/
cient dynamic analysis tools. We focus on dynamic analysis for the Java Virtual Machine (JVM) [9], because of its maturity and availability for a wide range of hardware platforms and operating systems. As many modern object-oriented programming languages such as Java, Scala, or JRuby rely on the JVM as execution platform, a wide range of applications and middleware—from application servers to applications on embedded devices—will benefit from the results of our research. We are developing a new join point model that integrates high-level join points found in prevailing AOP languages with customizable low-level join points at the level of basic blocks of code and at the level of individual bytecodes. We introduce the notion of staged advice, where advice executed at weave-time generates runtime advice residues; this mechanism allows custom static analysis at weave-time, as well as the pre-computation of data needed at runtime in the analysis. Also, complete reflective information of join points has to be made efficiently accessible to the advice. We include synthetic local variables [13] for efficiently passing data between advice within the scope of a woven method body. In addition, we provide support for deferred advice [1], a mechanism for effectively parallelizing fine-grained analysis tasks, which helps reduce the overhead of dynamic program analysis on multicore machines. Our design also supports blackbox composition of independently developed dynamic analyses without introducing any unwanted side-effects, thanks to the integration of execution levels for AOP [11, 12].
2.
plex dynamic analysis with low overhead. Despite of the raised abstraction level thanks to using a DSAL, our goal is to outperform prevailing dynamic analysis tools. Typically, optimizations in analysis tools using low-level instrumentation techniques focus on carefully tuned, hand-crafted inserted code. However, in virtual machines with state-of-theart compilers, such optimizations often provide little benefit, while increasing complexity of the tools, because the compiler is able to perform comparable optimizations itself. We avoid replication of optimization functionality, and instead investigate two fundamentally different ways of improving performance: First, we provide dedicated support for executing dynamic analysis tasks on under-utilized CPU cores. As many programs, particularly those written for a shared-memory, multithreaded programming model, cannot effectively use all available cores on modern multicore and emerging manycore machines, under-utilized cores can be exploited for running analysis tasks in parallel with the base program being analyzed. This optimization is exposed to the DSAL programmer through the concept of deferred advice, first presented in [1]. In our DSAL, deferred advice will feature novel autotuning mechanisms to automatically optimize system parameters (e.g., task queue size, number of concurrent analysis threads) at runtime according to the execution platform, the analysis task, and the base program being analyzed. Second, we explore the integration of static analysis to reduce the cost of dynamic analysis. To this end, we introduce the notion of staged advice, where statically evaluated advice yields runtime residues. Staged advice consists of two parts; the first part is evaluated at weaving time, and the second part is executed at runtime. The first part has access to all static reflective join point information. It may perform a local analysis of the method being woven, an analysis of the whole enclosing class, or even whole-program analysis. The results of the static analysis are stored in synthetic local variables, which can be read by the second advice part at runtime.
LANGUAGE DESIGN
We first have derived concrete requirements from a wide spectrum of existing dynamic analyses in the area of profiling, debugging, testing, program comprehension, and reverse engineering. These requirements are guiding the design and specification of the new DSAL. In the following text, we briefly explain (1) how our DSAL helps raise the abstraction level of dynamic program analyses without limiting expressiveness, (2) how it reconciles the higher abstraction level with improved performance of dynamic analyses, and (3) how it supports flexible composition of analyses.
Support for Flexible Composition of Analyses. The DSAL supports black-box composition of analysis tasks. That is, separately developed analyses can be combined without having to change the source code of these analyses. Multiple independent analyses can coexist at runtime and jointly observe the base program, without influencing each other, as long as only platform-independent dynamic metrics [7] are collected. This is achieved with the concept of execution levels for AOP [11], which can be efficiently implemented [12, 10].
Raising the Abstraction Level. One challenge addressed by our research is the design of a DSAL for dynamic program analysis that significantly raises the abstraction level at which dynamic analysis tasks are expressed in comparison to state-of-the-art techniques such as bytecode instrumentation. The higher abstraction level must not compromise expressiveness. While we leverage the pointcut/advice mechanism found in general-purpose AOP languages [8], we design a new join point model where in addition to traditional AOP join points, the execution of any specified sequence of bytecodes and any basic block of code can be exposed as a join point. Furthermore, we include recent concepts, such as synthetic local variables [13] for efficient data passing between woven advice, and provide efficient access to any context information from the bytecode and constant pool, from local variables, and from the operand stack.
3. ONGOING RESEARCH The implementation of the new DSAL requires the development of a compiler and a weaver. We use an intermediate language based on Java annotations in order to decouple the development of the compiler and the weaver, which can proceed in parallel. The intermediate language is an extension of @J [3]. We will validate the DSAL with several case studies, including but not limited to the existing analysis tools identified in the initial requirements analysis phase. We will also implement novel profilers for better understanding performance of multithreaded applications. These profilers will help detect bottlenecks such as lock contention and support
Ensuring High Performance Analysis. Another challenge addressed by our research is the development of new optimization mechanisms that enable com-
10
developers in parallelizing and optimizing applications for modern multicore machines. With thorough empirical analysis we will explore the benefits of our DSAL both in terms of developer productivity and in terms of performance of the analysis tools written in the DSAL. By comparing existing tools implemented with low-level instrumentation techniques with new tools specified with our DSAL, we will be able to answer the research question stated in the introduction.
4.
[2] P. Avgustinov, A. S. Christensen, L. J. Hendren, S. Kuzins, J. Lhot´ ak, O. Lhot´ ak, O. de Moor, D. Sereni, G. Sittampalam, and J. Tibble. abc: An extensible AspectJ compiler. In AOSD ’05: Proceedings of the 4th International Conference on Aspect-Oriented Software Development, pages 87–98, New York, NY, USA, 2005. ACM Press. [3] W. Binder, A. Villaz´ on, D. Ansaloni, and P. Moret. @J Towards Rapid Development of Dynamic Analysis Tools for the Java Virtual Machine. In VMIL ’09: Proceedings of the 3th Workshop on Virtual Machines and Intermediate Languages, pages 1–9, New York, NY, USA, 2009. ACM. [4] C. Bockisch, M. Arnold, T. Dinkelaker, and M. Mezini. Adapting virtual machine techniques for seamless aspect support. In OOPSLA ’06: Proceedings of the 21st annual ACM SIGPLAN conference on Object-oriented programming systems, languages, and applications, pages 109–124, New York, NY, USA, 2006. ACM. [5] E. Bodden and K. Havelund. Racer: Effective Race Detection Using AspectJ. In International Symposium on Software Testing and Analysis (ISSTA), Seattle, WA, July 20-24 2008, pages 155–165, New York, NY, USA, 07 2008. ACM. [6] B. De Fraine, M. S¨ udholt, and V. Jonckers. StrongAspectJ: flexible and safe pointcut/advice bindings. In AOSD ’08: Proceedings of the 7th international conference on Aspect-oriented software development, pages 60–71, New York, NY, USA, 2008. ACM. [7] B. Dufour, K. Driesen, L. Hendren, and C. Verbrugge. Dynamic metrics for Java. ACM SIGPLAN Notices, 38(11):149–168, Nov. 2003. [8] G. Kiczales, J. Lamping, A. Menhdhekar, C. Maeda, C. Lopes, J.-M. Loingtier, and J. Irwin. Aspect-oriented programming. In M. Ak¸sit and S. Matsuoka, editors, ECOOP ’97: Proceedings of the 11th European Conference on Object-Oriented Programming, volume 1241 of Lecture Notes in Computer Science, pages 220–242, Jyv¨ akyl¨ a, Finnland, June 1997. Springer-Verlag. [9] T. Lindholm and F. Yellin. The Java Virtual Machine Specification. Addison-Wesley, Reading, MA, USA, second edition, 1999. ´ Tanter. Polymorphic bytecode [10] P. Moret, W. Binder, and E. instrumentation. In AOSD ’11: Proceedings of the 10th International Conference on Aspect-Oriented Software Development. ACM Press, Mar. 2011. ´ Tanter. Execution levels for aspect-oriented [11] E. programming. In Proceedings of the 9th ACM International Conference on Aspect-Oriented Software Development (AOSD 2010), pages 37–48, Rennes and Saint Malo, France, Mar. 2010. ACM Press. ´ Tanter, P. Moret, W. Binder, and D. Ansaloni. [12] E. Composition of dynamic analysis aspects. In Proceedings of the 9th ACM SIGPLAN International Conference on Generative Programming and Component Engineering (GPCE 2010), pages 113–122, Eindhoven, The Netherlands, Oct. 2010. ACM Press. [13] A. Villaz´ on, W. Binder, D. Ansaloni, and P. Moret. Advanced Runtime Adaptation for Java. In GPCE ’09: Proceedings of the Eighth International Conference on Generative Programming and Component Engineering, pages 85–94. ACM, Oct. 2009. [14] A. Villaz´ on, W. Binder, and P. Moret. Aspect Weaving in Standard Java Class Libraries. In PPPJ ’08: Proceedings of the 6th International Symposium on Principles and Practice of Programming in Java, pages 159–167, New York, NY, USA, Sept. 2008. ACM. [15] A. Villaz´ on, W. Binder, and P. Moret. Flexible Calling Context Reification for Aspect-Oriented Programming. In AOSD ’09: Proceedings of the 8th International Conference on Aspect-oriented Software Development, pages 63–74, Charlottesville, Virginia, USA, Mar. 2009. ACM.
RELATED WORK
The AspectBench Compiler (abc) [2] eases the extension of AspectJ with new pointcuts [5, 6]. In principle, the new join point model for our DSAL could be implemented with abc. However, as our DSAL introduces many other features, such as synthetic local variables, staged advice, and deferred advice, we opted for implementing a lightweight weaver for our DSAL from scratch. Steamloom [4] provides AOP support at the JVM level, which results in efficient runtime weaving. Steamloom enables the dynamic modification and reinstallation of method bytecodes and provides dedicated support for managing aspects. Steamloom uses its own aspect language and provides a parser to support AspectJ-like pointcuts. Steamloom allows the specification of filter objects for fine-grained localization of join point shadows. While Steamloom is based on a customized JVM, we aim at full compatibility with standard JVMs. In prior work [14, 15], we extended the AspectJ weaver with new features by transforming bytecode that has been previously woven with the original, unmodified AspectJ weaver. This approach has the benefit that new versions of the AspectJ weaver can be easily integrated. However, it is not possible to integrate all desired features of our DSAL with AspectJ in that manner.
5.
CONCLUSION
Dynamic program analysis is essential in modern software engineering. Since prevailing approaches to the development of dynamic analysis tools are either too low-level, limited in expressiveness, or introduce high overhead, we are designing a new DSAL in order to establish foundations for the productive development of flexible and efficient dynamic analysis tools. Our goal is to reconcile a high abstraction level, unlimited expressiveness of the DSAL, and high performance of the analysis tools. The key concepts in our DSAL are a new join point model, staged advice for embedding static analyses, deferred advice for parallelizing analysis tasks, and execution levels for flexible black-box composition of analyses.
Acknowledgments. The work presented in this paper has been supported by the Swiss National Science Foundation.
6.
REFERENCES
[1] D. Ansaloni, W. Binder, A. Villaz´ on, and P. Moret. Parallel dynamic analysis on multicores with aspect-oriented programming. In AOSD ’10: Proceedings of the 9th International Conference on Aspect-Oriented Software Development, pages 1–12, Rennes, France, March 2010. ACM Press.
11