"He weaves shortcuts into the computer program in a fashion
you wouldn't believe."
- Isaac Asimov, Nemesis
Overview
Wicca v2 transforms .NET applications to enable Aspect-Oriented Programming
(AOP) with the goal of improving modularity and evolution, and reducing
tedious and error-prone programming. Wicca can transform source code
or byte code, at compile-time or runtime (yes, that's right, Wicca
can transform the program while it's running). Wicca can also
transform a program without modifying it via breakpoint weaving.
Wicca is a hybrid weaver that supports 6 weaving scenarios:
Wicca Weaving Scenarios
Weave Time
Weave Strategy*
Weaver
Supported?
Compile time
Byte code
Phx.Morph
Source code
wcs
Load time
Byte code
Phx.Morph
Breakpoint
Phx.Morph
Source code
wcs
Runtime
Byte code
Phx.Morph
Breakpoint
Phx.Morph
Source code
wcs
* "Byte code" refers to Microsoft .NET intermediate language (MSIL) code and
"source code" refers to C#.
Note: We refer to compile-time weaving as "static weaving" and load-time
and runtime weaving as "dynamic weaving".
Static Weaving
The static weaving scenarios are supported by two standalone tools: Phx.Morph
and wcs.
Phx.Morph
Phx.Morph is a static byte-code weaver for .NET applications
built on top of Phoenix, Microsoft's back-end compiler infrastructure. To
run Phx.Morph from the command-line, you specify it as a plugin for the
Microsoft Phoenix pereader.exe assembly rewriting tool. Aspects are specified
as regular assemblies with custom [Advice] attributes. The Phx.Morph
README
file has more information.
wcs
Wcs is a source weaver and compiler. It is similar to AspectJ except
that it supports C# instead of Java. It can be used
standalone via the wcs.exe command-line tool or programmatically via the
Wicca.Wcs API. (Wicca currently does not support dynamic source weaving and so
does not use the API.) Aspects are specified as regular C# source files with
custom [Advice] attributes.
Wcs supports a small extension to C# to enable
statement annotations.
Here's an example:
public SimpleDraw() {
[Log(Sev.Info, "Creating a line")]
Shape s = new Line(new Point(1, 9), new Point(9, 1));
}
Wcs uses the standard C# compiler so before compiling it must "encode" the
statement annotation using a legal C# method annotation:
[Statement(19, "LogAttribute", Sev.Info, "Creating a line")]
public SimpleDraw() {
Shape s = new Line(new Point(1, 9), new Point(9, 1));
}
Wcs and Phx.Morph both recognize this encoding and support advising
annotated statements.
Dynamic Weaving
The Wicca dynamic AOP system is implemented as a plug-in for the Microsoft
Managed Debugger (mdbg). Mdbg takes care of launching the client process,
attaching a debugger to it, managing communication between the debugger
and the process, and providing an interactive command-line shell to the
user.
Dynamic Byte Code Weaving
Phx.Morph exposes an API to support load-time and runtime weaving
("dynamic weaving"). For dynamic byte code weaving, Phx.Morph weaves the
assembly just like in the static weaving case and produces a temporary
assembly. Wicca diffs the woven assembly with the currently running program
using its AssemblyDiff component and updates it as necessary using the
Microsoft Debugger Edit-and-Continue API.
Breakpoint Weaving
For dynamic breakpoint weaving, Phx.Morph weaves the assembly just like in
the static weaving case but instead of injecting advice calls, it calls a
callback function that Wicca implements. When Wicca gets the callback it
sets breakpoints in the running program using the Microsoft Debugger
Breakpoint API. When a breakpoint is hit, Wicca obtains the context
parameters using the Microsoft Debugger API and then executes the advice
method method *in the process space of the running program* using the
Microsoft Debugger Func-Eval API.
Dynamic Software Updating
Wicca's diff-and-update API is called AssemblyDiff. AssemblyDiff exposes
a general-purpose
Dynamic Software Updating (DSU) API that supports (almost) arbitrary updates to the
running program via the Microsoft Debugger Edit-and-Continue (EnC) API.
The diff process produces a byte code delta file and a metadata delta file
which the EnC API consumes. Wicca leverages the API to support three DSU scenarios:
Supported Dynamic Software Update Scenarios
DSU Scenario
Summary
Dynamic AOP
Phx.Morph automatically creates the woven assembly
Assembly Patch
The !patch command is used to supply a new assembly
While the standalone Phx.Morph plugin is fairly mature, the dynamic Wicca
AOP system is only an alpha release. Here are some of the major issues:
Wicca/Phx.Morph chokes when binary weaving some assemblies. In these
cases, use the breakpoint weaver.
Not all of AspectJ's AOP functionality is supported.
Dynamic weaving is inherently slow because it disables JIT
optimizations and enables Edit-and-Continue support. Moreover, binary
weaving is nonoptimized and breakpoint weaving is significantly slower
than byte code weaving (as expected, but could still be optimized).
Weavers are almost but not quite functionally equivalent. The
breakpoint weaver cannot pass some context, including annotation
context. The byte code weaver may succeed when used statically but
fail when used dynamically (probably due to a dynamic update failure).
The source weaver (wcs) has not been fully tested and is very flaky.
The dynamic software updating mechanism has the same limitations as the
Edit-and-Continue API. We can only add private members (fields,
properties, and methods) and replace method bodies.
It's currently not possible to disable aspects at runtime.
A more detailed issue list can be found in the
README
file.
Uses Phx.Morph to weave assemblies (binary weaving)
Uses wcs to weave C# source code (source weaving)
Uses Unmanaged Metadata API for comparing assemblies
Uses Debugger Edit-and-Continue API for dynamically updating assemblies
Uses Debugger Breakpoint API for breakpoint weaving
Uses Debugger Func-Eval API for breakpoint advice invocation
Wicca v1
Wicca v2 is a complete rewrite of v1. It uses the slower out-of-
process Microsoft Debugger API instead of the faster in-process
Microsoft Profiler API. This rewrite was required to support .NET
2.0. However, there are substantial benefits to using the Debugger
API including:
More powerful DSU capabilities - We can now add fields and methods
(although this hasn't been tested)
Breakpoint weaving
Unfortunately, we have not migrated the edit-and-continue, dynamic
source weaving, and woven code debugging features to v2 yet. You
can still download Wicca v1
here.
Marc Eaddy, Alfred Aho, Weiping Hu, Paddy McDonald, and Julian Burger,
"Debugging Aspect-Enabled Programs,"to appear in
International Symposium on Software Composition (SC 2007),
Braga, Portugal, March 25-26, 2007. Note: This paper refers to features only available in Wicca v1,
namely, edit-and-continue and dynamic source weaving.
Download pdf