Semantics-Based Crosscutting in AspectJ™ Gregor Kiczales, Jim Hugunin, Mik Kersten, John Lamping, ↕ Cristina Lopes and William G. Griswold Introduction A central issue in aspect-oriented programming is the design of mechanisms for specifying the crosscutting. Early systems used explicit enumeration of names of messages or methods[]. Recent versions of AspectJ go beyond this by allowing a crosscut to be described based on semantic properties of the operations involved. We intend for future versions of AspectJ to go even farther in this direction. In this short paper we describe the full range of crosscut specification mechanisms we currently plan. The paper is intended to serve as a foundation for discussion of this important issue. Implementation and detailed rationale are outside the scope of this short paper. Crosscut Definition Mechanisms in AspectJ Crosscuts in AspectJ are defined in terms of key events in the execution of Java programs. 2 These events include invocation of a message 3 from the caller object, reception of a message at the called object, execution of a method, and signaling and handling of exceptions. So, for example, a program can define a crosscut that includes the execution of any int getSize() method in a particular package. AspectJ makes it possible to define actions that should be executed at certain well-defined times in relation to such events. These times are before the event, after the event, and around the event. The after case is further divided into after if the event terminates normally, after if the event throws certain exceptions, or after in all cases. Around the event means that the crosscut action will have explicit control over whether the event should be allowed to proceed and in what dynamic context it does proceed. University of British Columbia (gregor@cs.ubc.ca). Xerox PARC. ↕ Purple Yogi. University of California, San Diego (currently visiting Xerox PARC). This work was partially supported by the Defense Advanced Research Projects Agency under contract number F30602-C-0246. 2 The AspectJ semantics is not defined in terms of a weaver copying code into the beginning and end of methods. A particular implementation of AspectJ might do this a variety of waysit might copy code (as in a pre-processor), it might insert dispatches (as in a fast compiler), it might use other techniques. The work of the aspect weaver component of the language implementation is to coordinate the crosscutting; it was never intended to be so particular as to mean to copy code around. 3 In this paper the term message is used to refer to the combination of a method name, its result type and the types of its parameters. In JVM terminology this is a NameAndType.