390 likes | 601 Views
Wicca v2 demo. Dynamic weaving using the .NET 2.0 Debugging APIs. Marc Eaddy Columbia University. Wicca: A research platform. Experimenting with techniques for modularizing crosscutting concerns. Advanced separation of concerns (ASOC) First dynamic weaver based on .NET 2.0 Debugging APIs
E N D
Wicca v2 demo Dynamic weaving using the.NET 2.0 Debugging APIs Marc Eaddy Columbia University
Wicca: A research platform Experimenting with techniques for modularizing crosscutting concerns • Advanced separation of concerns (ASOC) • First dynamic weaver based on .NET 2.0 Debugging APIs • New breakpoint weaving technique • New metrics for measuring crosscutting • Novel language mechanisms • Statement annotations • Side classes • Dynamic software updating AOSD 2007
Wicca: A research platform Experimenting with techniques for modularizing crosscutting concerns • Advanced separation of concerns (ASOC) • First dynamic weaver based on .NET 2.0 Debugging APIs • New breakpoint weaving technique • New metrics for measuring crosscutting • Novel language mechanisms • Statement annotations • Side classes • Dynamic software updating AOSD 2007
Wicca transformation pipeline Aspect Assemblies Deltas Source Files Post-Link Weaver Compiled Program WovenProgram Compiler Break Points Backend Frontend AOSD 2007
Phx.Morph • Wicca’s backend • .NET byte code and breakpoint weaver • Built using Microsoft Phoenix • Supports .NET 1.0, 1.1, and 2.0 • Demoed at AOSD 2006 • New: Dynamic weaving, breakpoint weaving, statement annotation support AOSD 2007
Demo setup: Simple Draw • SimpleDraw draws Shapes on a Display • Naïve implementation couples Shape and Display concerns SimpleDraw.cs Point.cs public void moveBy(intdx, intdy) { x += dx; y += dy; Display.instance().update(); public init() { s = new Shape[3]; s[0] = new Point(10, 10); s[1] = new Point(5, 5); s[2] = new Line(new Point(1, 9), new Point(9, 1)); for (inti = 0; i < s.Length; i++) Display.instance().addShape(s[i]); Display.instance().update(); Line.cs public void moveBy(intdx, intdy) { a.moveBy(dx, dy); b.moveBy(dx, dy); Display.instance().update(); AOSD 2007
Demo setup: Simple Draw • SimpleDraw draws Shapes on a Display • Naïve implementation couples Shape and Display concerns SimpleDraw.cs Point.cs public void moveBy(intdx, intdy) { x += dx; y += dy; Display.instance().update(); Crosscutting public init() { s = new Shape[3]; s[0] = new Point(10, 10); s[1] = new Point(5, 5); s[2] = new Line(new Point(1, 9), new Point(9, 1)); for (inti = 0; i < s.Length; i++) Display.instance().addShape(s[i]); Display.instance().update(); Line.cs public void moveBy(intdx, intdy) { a.moveBy(dx, dy); b.moveBy(dx, dy); Display.instance().update(); AOSD 2007
Demo 1: Static byte code weaving Aspect Assemblies Deltas C# Files C# Compiler Phx.Morph Compiled Program WovenProgram Break Points AOSD 2007
Dynamic weaving • .NET 2.0 Debugging APIs • Edit-and-Continue API • Replaces the .NET 1.1 Profiler API • Dynamic AOP • Edit-and-Continue • Patching • Breakpoint API – Noninvasive advising • FuncEval API – In-process advice execution • Intended for debugging, not dynamic AOP • Microsoft Managed Debugger • Hosts Wicca plug-in • Hosts client program in separate process • Command-line shell for weaving commands AOSD 2007
Demo 2: Dynamic byte code weaving Aspect Assemblies Deltas C# Files C# Compiler Phx.Morph Compiled Program Woven Program Break Points Using .NET 2.0 Edit-and-Continue API AOSD 2007
Demo 3: Dynamic bp weaving Aspect Assemblies Deltas C# Files C# Compiler Phx.Morph Compiled Program Woven Program Break Points Noninvasive advising via Breakpoint API In-process advice execution via FuncEval API AOSD 2007
Wicca# language • Wicca’s frontend • Wicca# compiler • Extends C# to support • Statement annotations • Side classes • Goal • Actually “modularize” crosscutting concerns (without sacrificing other modularity properties) AOSD 2007
Statement annotations Allows any program statement to be annotated //[Concern("Input")] inputMapper.Update(elapsedTime); • Fine-grained advising • Statement-level advising (more elegant than dummy methods) • Declarative instance-level advising • Other possibilities • Optimization and parallelization hints • Contracts • Avoiding reweaving • Fault isolation • Oblivious debugging • “Statement Annotations for Fine-Grained Advising”, RAM-SE 2006 AOSD 2007
Quantifying crosscutting 0.92 • “Identifying, Assigning, and Quantifying Crosscutting Concerns”, ACOM 2007 • Display updating in SimpleDraw • Degree of scattering: • Scattering visualization (ala SeeSoft): AOSD 2007
Demo 4: Concern profiling Aspect Assemblies Deltas Wicca# Source Files Phx.Morph Compiled Program Wicca# Compiler WovenProgram Break Points Statement annotation-based advising AOSD 2007
Side classes Powerful and disciplined class extension AOSD 2007
Expression problem revisited • Need to parse simple expression language • e.g., 3 + 4 • Expressions: Literal, Add • Operations: eval • Extensibility goals • Easily add new expressions • Easily add new operations • Cannot do both easily Easy in FP Easy in OO P. Tarr, H. Ossher, W. Harrison, and S. Sutton Jr., "N Degrees of Separation: Multi-Dimensional Separation of Concerns," ICSE 1999 M. Torgersen, "The Expression Problem Revisited," ECOOP 2004 AOSD 2007
Parser implementation in OO • Concern: Add printing • Operations are crosscutting! abstract class Expression { abstract inteval(); } class Add : Expression { public Expression left, right; public Add(Expression left, Expression right) { this.left = left; this.right = right; } public inteval() { return left.eval() + right.eval(); } } AOSD 2007
Add printing using subclassing • Invasive • Inflexible abstract class PrintingExpr : Expression { abstract void print(); } class PrintingAdd : Add { public void print() { Console.WriteLine(left + “+” + right); } } AOSD 2007
Printing the side class way Side class composition operator • Modularizes the printing concern • Side class implicitly extends base class • Clients (or other sub/side classess) oblivious abstract class PrintingExpr+ Expression { abstract void print(); } class PrintingAdd+ Add { public void print() { Console.WriteLine(left + “+” + right); } } AOSD 2007
Caching Concern: Cache expression evaluation Invalidate cache when expression changes AOSD 2007
Side class: Caching eval interface IObserver { void onChange(); } class CachableExpr + Expression : IObserver { protected IObserver observer = null; protected int cache;protected boolisCacheValid = false; void onChanged() { isCacheValid = false; if (observer != null) observer.onChanged(); } } AOSD 2007
Side class: Caching eval Interface intertype declaration Member intertype declarations interface IObserver { void onChange(); } class CachableExpr + Expression : IObserver { protected IObserver observer = null; protected int cache;protected boolisCacheValid = false; void onChanged() { isCacheValid = false; if (observer != null) observer.onChanged(); } } AOSD 2007
Side class: Caching eval (2) class CachableAdd + Add { public Add(Expression left, Expression right) { base(left, right); this.left.observer = this; this.right.observer = this; } override public inteval() { if (!isCacheValid) { cache = base.eval(); isCacheValid = true; } return cache; } AOSD 2007
Side class: Caching eval (2) Call ‘next’ delegate (i.e., proceed) class CachableAdd + Add { public Add(Expression left, Expression right) { base(left, right); this.left.observer = this; this.right.observer = this; } override public inteval() { if (!isCacheValid) { cache = base.eval(); isCacheValid = true; } return cache; } AOSD 2007
Side class: Caching eval (3) override Expression left { set { base.left = value; this.left.observer = this; this.onChange(); } } override Expression right { set { base.right = value; this.right.observer = this; this.onChange(); } } } AOSD 2007
Side class: Caching eval (3) Override virtual field override Expression left { set { base.left = value; this.left.observer = this; this.onChange(); } } override Expression right { set { base.right = value; this.right.observer = this; this.onChange(); } } } AOSD 2007
Side class: Caching eval (4) Metavariable Limited quantification override Expression [$which = left | right] { set { base.$which = value; this.$which.observer = this; this.onChange(); } } AOSD 2007
Base class must allow extension class Add : Expression { public virtual Expression left, right; public Add(Expression left, Expression right) { this.left = left; this.right = right; } public virtualinteval() {return left.eval() + right.eval();} } AOSD 2007
Addresses needs of existing mechanisms • Subclasses • Inflexible composition • Only extend one base class • Only extend instance methods • Requires invasive changes in clients • Open classes/refinements/mixins • Need for composition ordering • Need for constructor and static member overriding • Aspects • Lack of modular reasoning • Poor integration with existing OO semantics and notation • Need for symmetric model • Matching wrong join points AOSD 2007
Conclusions sideClasses Wicca# @Statement AOSD 2007
Acknowledgements • Microsoft Phoenix Team • Wicca developers • BorianaDitcheva • Rajesh Ramakrishnan • Adam Vartanian AOSD 2007
Thank you! AOSD 2007
Phx.Morph architecture Phx.Morph Morph Plugin PEREW Assembly Re-Writer Editors Open Classes, binary and breakpoint weaving Phoenix-specific AOP Attribute Handlers Phx.Aop Phoenix AOP Joinpoints, pointcuts, … Attributes Custom AOP annotations .NET AOSD 2007
Wicca architecture AOSD 2007
Wicca architecture Phx.Morph Wicca# Compiler Wicca # Compiler AOSD 2007
Legalizing statement annotations public OnDraw() { //[Note("Creating a line")] line = new Line(); AOSD 2007
Legalizing statement annotations Legalize public OnDraw() { //[Note("Creating a line")] line = new Line(); [Statement(9, "Note", "Creating a line")] public OnDraw() { line = new Line(); AOSD 2007