Runtime Aspect Weaving Through Metaprogramming

Jason Baker and Wilson Hsieh

University of Utah, School of Computing
50 South Central Campus Drive, Room 3190
Salt Lake City, Utah 84112-9205



We describe an extension to the Java language, Handi-Wrap, that supports weaving aspects into code at runtime. Aspects in Handi-Wrap take the form of method wrappers, which allow aspect code to be inserted around method bodies like advice in AspectJ. Handi-Wrap offers several advantages over static aspect languages such as AspectJ. First, aspects can be woven into binary libraries. Second, a wrapper in Handi-Wrap is a first-class Java value, which allows users to exploit Java mechanisms to define and weave wrappers. For example, wrappers can be passed explicit constructor arguments, and wrapper objects can be composed. Finally, methods in all Java classes, including anonymous classes, can be wrapped. A prototype of Handi-Wrap is implemented in a compile-time metaprogramming system for Java, called Maya; we briefly describe how Maya's features support Handi-Wrap.

A revised version of this paper was published in Proceedings of the 1st International Conference on Aspect-Oriented Software Development (AOSD 2002), Enschede, NL, April 2002. Please read and cite the published AOSD 2002 paper in preference to this report.

Jason Baker <>
Last modified: Mon Feb 25 16:47:56 MST 2002