Formal AOP: Opportunity Abounds James Riely http://www.depaul.edu/ - - PowerPoint PPT Presentation

formal aop opportunity abounds
SMART_READER_LITE
LIVE PREVIEW

Formal AOP: Opportunity Abounds James Riely http://www.depaul.edu/ - - PowerPoint PPT Presentation

Formal AOP: Opportunity Abounds James Riely http://www.depaul.edu/ jriely DePaul CTI, Chicago, USA Much of this talk reports on joint work with Glen Bruns Radha Jagadeesan Alan Jeffrey < > - + FOAL 04 p.1/68 Thanks for


slide-1
SLIDE 1

< > - +

Formal AOP: Opportunity Abounds

James Riely

http://www.depaul.edu/∼jriely

DePaul CTI, Chicago, USA

Much of this talk reports on joint work with Glen Bruns Radha Jagadeesan Alan Jeffrey

FOAL ’04 – p.1/68

slide-2
SLIDE 2

< > - +

Thanks for Inviting Me

I will try to say something interesting.

FOAL ’04 – p.2/68

slide-3
SLIDE 3

< > - +

Thanks for Inviting Me

I will try to say something interesting. Waffle. Limiting the power of AOP — Equational Reasoning

FOAL ’04 – p.2/68

slide-4
SLIDE 4

< > - +

Thanks for Inviting Me

I will try to say something interesting. Waffle. Limiting the power of AOP — Equational Reasoning Cheese and Ham. Class-based AOP and Weaving (with types) “Pure” AOP

FOAL ’04 – p.2/68

slide-5
SLIDE 5

< > - +

Thanks for Inviting Me

I will try to say something interesting. Waffle. Limiting the power of AOP — Equational Reasoning Cheese and Ham. Class-based AOP and Weaving (with types) “Pure” AOP Waffle. Increasing the power of AOP — Temporal Logics Focus of attention: aspects as method/function call interceptors.

FOAL ’04 – p.2/68

slide-6
SLIDE 6

< > - +

Opening Waffle

FOAL ’04 – p.3/68

slide-7
SLIDE 7

< > - +

The “Right” Abstractions

More complex programs require more expressive abstractions (ie, better tools). FORTRAN/ALGOL: expressions/recursive functions Structured Programming: first order control structures Labelled Break Statements/Exceptions: finally eliminate goto Higher-Order Programming: programmable control structures Modules/OO Programming: encapsulation of data and control Patterns: popularize higher-order OO AO Programming: encapsulation of “concerns” (Flavors)

FOAL ’04 – p.4/68

slide-8
SLIDE 8

< > - +

Concerns

So what are we concerned about? Primary functionality (in its many aspects) Synchronization Persistence/Distribution User Interfaces Caching Security ... How do we code using OOP/FP?

FOAL ’04 – p.5/68

slide-9
SLIDE 9

< > - +

OOP/FP Solutions

Hooks (Publish/Subscribe, Visitors) — must be placed ahead Wrappers (Decorators) — can be circumvented

FOAL ’04 – p.6/68

slide-10
SLIDE 10

< > - +

OOP/FP Solutions

Hooks (Publish/Subscribe, Visitors) — must be placed ahead Wrappers (Decorators) — can be circumvented

AOP to the Rescue

Obliviousness — no need to plan ahead Quantification — no way to circumvent

FOAL ’04 – p.6/68

slide-11
SLIDE 11

< > - +

Why Aren’t We All Programming in Prolog?

Programming with quantification is a pain.

FOAL ’04 – p.7/68

slide-12
SLIDE 12

< > - +

Why Aren’t We All Programming in Prolog?

Programming with quantification is a pain.

Why Aren’t We All Programming in Assembly Language?

Programming without equational reasoning is a pain.

FOAL ’04 – p.7/68

slide-13
SLIDE 13

< > - +

Why Aren’t We All Programming in Prolog?

Programming with quantification is a pain.

Why Aren’t We All Programming in Assembly Language?

Programming without equational reasoning is a pain.

Why Aren’t We All Programming in the Pi Calculus?

Same question. Abstractions of the language need to support the way we work.

FOAL ’04 – p.7/68

slide-14
SLIDE 14

< > - +

AOP: The Declarative Imperative

Fillman and Friedman: The cleverness of classical AOP is augmenting conventional sequentiality with quantification, rather than supplanting it wholesale.

FOAL ’04 – p.8/68

slide-15
SLIDE 15

< > - +

AOP: The Declarative Imperative

Fillman and Friedman: The cleverness of classical AOP is augmenting conventional sequentiality with quantification, rather than supplanting it wholesale. How can we reasonably quantify over programs? How can we reason about programs over which we quantify?

FOAL ’04 – p.8/68

slide-16
SLIDE 16

< > - +

AOP: The Declarative Imperative

Fillman and Friedman: The cleverness of classical AOP is augmenting conventional sequentiality with quantification, rather than supplanting it wholesale. How can we reasonably quantify over programs? How can we reason about programs over which we quantify? Obliviousness is a two edged sword: Code providers should be oblivious to aspects — attach them where you like Code clients should be oblivious to aspects — assure that contracts will be validated In both cases equational reasoning is essential.

FOAL ’04 – p.8/68

slide-17
SLIDE 17

< > - +

Aspects Break Equational Reasoning: I

class C { void foo() { } } class D1 extends C { } class D2 extends C { void foo() { super.foo(); } } aspect Diff { void around(): execution(D.foo()) { System.out.println("aspect in action"); } }

D1.foo() = D2.foo().

FOAL ’04 – p.9/68

slide-18
SLIDE 18

< > - +

Aspects Break Equational Reasoning: II

class E1 { void f() { f(); } void g() { g(); } } class E2 { void f() { g(); } void g() { f(); } } aspect Diff { void around(): execution(E.f()) { System.out.println("aspect in action"); } }

E1.f() = E2.f(). Also consider “jumping” and “vanishing” aspects.

(example from Mitch Wand)

FOAL ’04 – p.10/68

slide-19
SLIDE 19

< > - +

Aspects Interfere with Each Other

Alice calls Bob using a Server A S B send(B,M)

accept(M)

✲ ✛ ack ✛ ack

Bob Forwards to Charlie Bob blocks calls from Alice A S B C send(B,M)

accept(M) × accept(M)

✲ ✛

ack

✛ ack

A S B send(B,M)

accept(M) ×

blocked

FOAL ’04 – p.11/68

slide-20
SLIDE 20

< > - +

WWDD?

Are aspects the new goto?

FOAL ’04 – p.12/68

slide-21
SLIDE 21

< > - +

WWDD?

Are aspects the new goto? goto problem “solved” by finding sufficiently expressive abstractions for control. Sanity of Hoare Logic mostly restored. Aspects will inevitably follow the same path. (Much work done in this direction, eg [Aldrich, thirty minutes ago].) [Wand ICFP 2003]: Need general support for domain-specific aspect languages. Need specification-level joint-point ontologies (AspectJ is implementation level.) Connections with behavioral types, behavioral subtyping. Contextual equivalence [Gordon’s applicative bisimulation] as useful tool. What are the observable events?

FOAL ’04 – p.12/68

slide-22
SLIDE 22

< > - +

A Continuum of Approaches

Meta-Object Protocols/Full-blown Introspection with Intercession Compile-time Load-time Run-time Clearbox AOP (a lá AspectJ [Kiczales, et al]) Blackbox AOP (a lá Composition Filters [Aksit, et al]) Domain-Specific AOP Traditional OO/FP What is the sweet spot?

FOAL ’04 – p.13/68

slide-23
SLIDE 23

< > - +

AOP in the Wild Wild West

AOP is exploring its power. Wither formal aspects of aspects?

FOAL ’04 – p.14/68

slide-24
SLIDE 24

< > - +

AOP in the Wild Wild West

AOP is exploring its power. Wither formal aspects of aspects? Local sheriff — calls it like it is

FOAL ’04 – p.14/68

slide-25
SLIDE 25

< > - +

AOP in the Wild Wild West

AOP is exploring its power. Wither formal aspects of aspects? Local sheriff — calls it like it is School marm — drawing in the reigns

FOAL ’04 – p.14/68

slide-26
SLIDE 26

< > - +

AOP in the Wild Wild West

AOP is exploring its power. Wither formal aspects of aspects? Local sheriff — calls it like it is School marm — drawing in the reigns Stranger without name — enabling new conquests

FOAL ’04 – p.14/68

slide-27
SLIDE 27

< > - +

AOP in the Wild Wild West

AOP is exploring its power. Wither formal aspects of aspects? Local sheriff — calls it like it is School marm — drawing in the reigns Stranger without name — enabling new conquests Hooker with heart of gold, if you prefer

FOAL ’04 – p.14/68

slide-28
SLIDE 28

< > - +

Some Examples (Quickly)

FOAL ’04 – p.15/68

slide-29
SLIDE 29

< > - +

Lopes Example: Bounded Buffer

FOAL ’04 – p.16/68

slide-30
SLIDE 30

< > - +

Lopes Example: Distributed Book Locator

FOAL ’04 – p.17/68

slide-31
SLIDE 31

< > - +

Walker Example: Composable Security

FOAL ’04 – p.18/68

slide-32
SLIDE 32

< > - +

Aldrich Example: Dynamic Programming

FOAL ’04 – p.19/68

slide-33
SLIDE 33

< > - +

Clifton/Leavens Example: Visitors are Painful

FOAL ’04 – p.20/68

slide-34
SLIDE 34

< > - +

Flatt/Krishnamurthi/Felleisen Example: Mixins as Wrappers

FOAL ’04 – p.21/68

slide-35
SLIDE 35

< > - +

Semantics

FOAL ’04 – p.22/68

slide-36
SLIDE 36

< > - +

Understanding Pointcuts and Advice

Much work has been done. Connections with other things: Predicate Dispatching, Multimethods, MOPs, Reflection, Dynamically Scoped Functions, Subject Oriented Programming, Coordination Languages?, Logic and constraint programming?

FOAL ’04 – p.23/68

slide-37
SLIDE 37

< > - +

Understanding Pointcuts and Advice

Much work has been done. Connections with other things: Predicate Dispatching, Multimethods, MOPs, Reflection, Dynamically Scoped Functions, Subject Oriented Programming, Coordination Languages?, Logic and constraint programming? Semantics: Denotational, Big-step operational, Small-step

  • perational, Haskell, Scheme, Common Lisp. Eg, [de Meuter],

[Andrews], [Douence Motelet Sudholt], [Lämmel], [Wand Kiczales Dutchyn], [Masuhara Kiczales Dutchyn], [Walker Zdancewic Ligatti]

FOAL ’04 – p.23/68

slide-38
SLIDE 38

< > - +

Understanding Pointcuts and Advice

Much work has been done. Connections with other things: Predicate Dispatching, Multimethods, MOPs, Reflection, Dynamically Scoped Functions, Subject Oriented Programming, Coordination Languages?, Logic and constraint programming? Semantics: Denotational, Big-step operational, Small-step

  • perational, Haskell, Scheme, Common Lisp. Eg, [de Meuter],

[Andrews], [Douence Motelet Sudholt], [Lämmel], [Wand Kiczales Dutchyn], [Masuhara Kiczales Dutchyn], [Walker Zdancewic Ligatti] Emphasis on understanding context-dependent pointcuts (cflow). Eg, [Wand Kiczales Dutchyn 2002].

FOAL ’04 – p.23/68

slide-39
SLIDE 39

< > - +

Understanding Pointcuts and Advice

Much work has been done. Connections with other things: Predicate Dispatching, Multimethods, MOPs, Reflection, Dynamically Scoped Functions, Subject Oriented Programming, Coordination Languages?, Logic and constraint programming? Semantics: Denotational, Big-step operational, Small-step

  • perational, Haskell, Scheme, Common Lisp. Eg, [de Meuter],

[Andrews], [Douence Motelet Sudholt], [Lämmel], [Wand Kiczales Dutchyn], [Masuhara Kiczales Dutchyn], [Walker Zdancewic Ligatti] Emphasis on understanding context-dependent pointcuts (cflow). Eg, [Wand Kiczales Dutchyn 2002]. Our work: Emphasis on difference between pointcuts that fire before and after a call. Closest related work is [Lämmel 2002].

FOAL ’04 – p.23/68

slide-40
SLIDE 40

< > - +

A Calculus of AO Programs (ECOOP 2003)

Direct semantics of class-based and aspect-based languages. Small core of orthogonal primitives in ABL. Only around advice — encode before and after No method bodies — only advice bodies Only call/execution pointcuts — and boolean connectives Concurrency and nested declarations are easy. Punted advice ordering: assume a global order on names. Specification of weaving and proof of correctness (in absence of dynamically arriving advice).

FOAL ’04 – p.24/68

slide-41
SLIDE 41

< > - +

Specification of Weaving

No reductions are lost:

complete PABL = = = weave ⇒ PCBL P′

ABL

  • as

PABL = = = weave ⇒ PCBL P′

ABL

  • =

= = weave ⇒ P′

CBL

❄ No reductions are gained:

complete PABL = = = weave ⇒ PCBL P′

CBL

as PABL = = = weave ⇒ PCBL P′

ABL

  • =

= = weave ⇒ P′

CBL

( ✲ is OO reduction; ⊲ is AO reduction)

FOAL ’04 – p.25/68

slide-42
SLIDE 42

< > - +

Example: s delegates to t

class S { void print() { out.print("I am a S"); } void foo(T t) { t.bar(); } } class T { void print() { out.print("I am a T"); } void bar() { } } advice A at call(T.bar()) {

  • ut.print("Aspect invoked");

proceed(); }

foo(t) ✲ s:S bar()

intercept

✲ A bar()

proceed

✲ t:T A intercepts the message.

FOAL ’04 – p.26/68

slide-43
SLIDE 43

< > - +

Call Advice

class S { void print() { out.print("I am a S"); } void foo(T t) { t.bar(); } } class T { void print() { out.print("I am a T"); } void bar() { } } protected S advice A at call(T.bar()) { this.print(); target.print(); proceed(); }

s.foo(t) prints “I am S; I am T”. Call advice executed in the controlling context of the caller

FOAL ’04 – p.27/68

slide-44
SLIDE 44

< > - +

Exec Advice

class S { void print() { out.print("I am a S"); } void foo(T t) { t.bar(); } } class T { void print() { out.print("I am a T"); } void bar() { } } protected T advice A at exec(T.bar()) { this.print(); target.print(); proceed(); }

s.foo(t) prints “I am T; I am T”. Exec advice executed in the controlling context of the callee

FOAL ’04 – p.28/68

slide-45
SLIDE 45

< > - +

The Class Calculus: Some Reductions

Field get

  • bject o:c {...f =v...}

thread {let x=o.f; C} ✲

  • bject o:c {...f =v...}

thread {let x=v; C} Field set

  • bject o:c {...f =u...}

thread {seto.f =v; C} ✲

  • bject o:c {...f =v...}

thread { C} New declarations thread {new class c< :d {...};

  • bject o:c {...};

C} ✲ class c< :d {...}

  • bject o:c {...}

thread { C}

FOAL ’04 – p.29/68

slide-46
SLIDE 46

< > - +

The Class Calculus: Method call

class d< :Object {...m(x) { B}...} class c< :d {...}

  • bject o:c {...}

thread {o.m(v); C} ✲ class d< :Object {...m(x) { B}...} class c< :d {...}

  • bject o:c {...}

thread { B[o /

this, v

/

x];

C}

FOAL ’04 – p.30/68

slide-47
SLIDE 47

< > - +

The Aspect Calculus

A pointcut φ is an element of the boolean algebra with atoms: call(c: :m) exec(c: :m) An advice declaration D binds message arguments x as well as this and target. advice a(

  • x) at φ {

C} A class declaration D list the methods of the class (no code) class c< :d {m1,m2...} New commands C are: let x=o[¯ a; ¯ b](

  • v); process call advice ¯

a and exec advice ¯ b. let x=proceed(

  • v); proceed to next advice

FOAL ’04 – p.31/68

slide-48
SLIDE 48

< > - +

Supporting Call advice

To implement call advice a lá AspectJ, record the static type of

  • bject references on method calls:

let x=o:c.m(

  • v);

To bind this in call advice, record the controlling object of a thread: thread p {S} These changes are required to implement the dynamic semantics.

FOAL ’04 – p.32/68

slide-49
SLIDE 49

< > - +

Aspect Reduction: Context

advice a0(x):call(c: :m) { C0 } advice a3(x):call(d: :m) { C3 } advice b1(x):exec(c: :m) { C1 } advice b2(x):exec(d: :m) { C2 }

  • bject o:d {...}

class d< :c {...} thread p{let x=o:c.m(v);} Actual type of o is d. Declared type of o in thread is c.

FOAL ’04 – p.33/68

slide-50
SLIDE 50

< > - +

Aspect Reduction: Fetching Advice

advice a0(x):call(c: :m) { C0 } advice a3(x):call(d: :m) { C3 } advice b1(x):exec(c: :m) { C1 } advice b2(x):exec(d: :m) { C2 }

  • bject o:d {...}

class d< :c {...} thread p{let x=o:c.m(v);} ⊲ thread p{let x=o.[a0 ;b1,b2](v);}

FOAL ’04 – p.34/68

slide-51
SLIDE 51

< > - +

Aspect Reduction: Call Advice

advice a0(x):call(c: :m) { C0 } advice a3(x):call(d: :m) { C3 } advice b1(x):exec(c: :m) { C1 } advice b2(x):exec(d: :m) { C2 }

  • bject o:d {...}

class d< :c {...} thread p{let x=o.[a0 ;b1,b2](v);} ⊲ thread p{let x=p{ C0[v /

x, p

/

this, o

/

target, o.[/

0;b1,b2]

/

proceed]};}

Controlling context is p.

FOAL ’04 – p.35/68

slide-52
SLIDE 52

< > - +

Aspect Reduction: Exec Advice

advice a0(x):call(c: :m) { C0 } advice a3(x):call(d: :m) { C3 } advice b1(x):exec(c: :m) { C1 } advice b2(x):exec(d: :m) { C2 }

  • bject o:d {...}

class d< :c {...} thread p{let x=o.[/ 0;b1,b2](v);} ⊲ thread p{let x=o{ C1[v /

x, o

/

this, o

/

target, o.[/

0;b2]

/

proceed]};}

Controlling context is o.

FOAL ’04 – p.36/68

slide-53
SLIDE 53

< > - +

Encoding the CBL into the ABL

Given a class: class c< :Object {...m(

  • x) {

C0 }...} class d< :c {...m(

  • x) {

C1 }...} Create exec advice for each body: advice cbl_c_m(

  • x):exec(d:

:m) { C0[proceed /

super.m]}

advice cbl_d_m(

  • x):exec(d:

:m) { C1[proceed /

super.m]}

Ensure that cbl_d_m has higher priority than cbl_c_m. More robust encoding of super uses static dispatch directly.

FOAL ’04 – p.37/68

slide-54
SLIDE 54

< > - +

Weaving

Programs that dynamically load advice affecting existing classes cannot be woven statically. For static advice, weaving is something like macro expansion: class c< :d {m[/ 0;b1,b2]} advice b1(

  • x):exec(d:

:m) { C1 } advice b2(

  • x):exec(d:

:m) { C2 } is woven recursively as class c< :... {m(

  • x) {

C1[this /

target, this.[/

0;b2]

/

proceed]}}

advice b2(

  • x):exec(d:

:m) { C2 } The terminating version of this idea is now standard.

FOAL ’04 – p.38/68

slide-55
SLIDE 55

< > - +

Weaving: Subtleties

Extra parameter on call advice (for target object) Knowledge of controlling object required for call advice Must annotate advised method calls with method name (required for switch from call to exec advice) Introduce skip step to match advice lookups (required so that reductions match one-to-one) Theorem works modulo an equivalence on names (weaving must use actual method name, but aspect code uses name based on advice list)

complete PABL = = = weave ⇒ PCBL P′

ABL

  • as

PABL = = = = = = weave ⇒ PCBL P′

ABL

  • =

= = weave ⇒ ≃ P′

CBL

FOAL ’04 – p.39/68

slide-56
SLIDE 56

< > - +

The Full Untyped AOL

a,..,z Name P,Q ::= ( ¯ D ⊢ ¯ H) Program D,E ::= Declaration class c< :d { ¯ M} Class advice a(

  • x):φ {

C} Advice M ::= m[¯ a ; ¯ b] Method H,G ::= Heap Element

  • bject o:c { ¯

F} Object thread o{S} Thread F ::= f =v Field S,T ::= Call Stack

  • C

Current Frame let x=o{S}; C Pushed Frame C,B ::= Command new ¯ D ¯ H; New Declaration return v; Return let x=v; Value let x=o.f ; Get Field seto.f =v; Set Field let x=o.c: :m(

  • v);

Static Message let x=o:c.m(

  • v);

Dynamic Message let x=o.m[¯ a ; ¯ b](

  • v);

Advised Message let x=proceed(

  • v);

Proceed φ,ψ ::= Pointcut false False ¬φ Negation φ∨ψ Disjunction call(c: :m) Call exec(c: :m) Execution

FOAL ’04 – p.40/68

slide-57
SLIDE 57

< > - +

Types (Unpublished)

FOAL ’04 – p.41/68

slide-58
SLIDE 58

< > - +

Typing is Problematic

A symptom: the following code compiles in AspectJ1.1.

class D { public String m() { return "D"; } } aspect A { Object around(): call(* D.m()) { return new Integer(1); } }

This looks like a bug. Real issues: modular typechecking, variance, genericity. We address only the first issue. if ⊢ P and ⊢ Q then ⊢ P | Q

FOAL ’04 – p.42/68

slide-59
SLIDE 59

< > - +

A Difference with AspectJ

The set of call advice does not depend upon the type of the caller. To avoid locking entire heap on every method call, the declaration set is closed to precompute advice lists: class c< :... {m[¯ a; ¯ b],...} To allow modular typechecking and the use of this in call advice, must constrain the type of the caller. Method declarations have the form: class c< :... {protected s method m(

  • t):r [¯

a; ¯ b]...} protected is “protected c”; public is “protected Object′′.

FOAL ’04 – p.43/68

slide-60
SLIDE 60

< > - +

Another Difference

In AspectJ, each advice list terminates in a call to a plain class, which cannot proceed. To capture this, we must distinguish two types of advice: ρ ::= Placement around Around replace Replace D,E ::= ... Declaration ρ advice a(

  • x:
  • t):r at φ {

C} Advice

FOAL ’04 – p.44/68

slide-61
SLIDE 61

< > - +

Results for the Typed Calculus

The development is fairly standard Weaving still correct Weaving preserves types Reduction preserves types around advice no longer enough (before and after not encodable) Lays the groundwork for Covariant return / Contravariant arguments Genericity Row polymorphism

FOAL ’04 – p.45/68

slide-62
SLIDE 62

< > - +

The Full Typed AOL

a,..,z Name (& Type) X,Y,Z ::= n:t Typed Name P,Q ::= ( ¯ D ⊢ ¯ H) Program ρ ::= Placement around Around replace Replace D,E ::= Declaration class c< :d { ¯ F ¯ M } Class ρ advice a( X):r at φ { C} Advice M ::= protected s method m(

  • t):r [¯

a; ¯ b] Method F ::= protected s field f :t; Field Type V ::= f =v; Field Value H,G ::= Heap Element

  • bject o:c { ¯

V } Object thread o {S} Thread S,T ::= Call Stack

  • C

Current Frame let X =o{S}; C Pushed Frame C,B ::= Command new ¯ D ¯ H; New return v; Return let X =v; Value let X =o.f ; Get Field seto.f =v; Set Field let X =o.c: :m(

  • v);

Static Message let X =o:c.m(

  • v);

Dynamic Msg let X =o:c.m[¯ a; ¯ b](

  • v);

Advised Msg let X =proceed(

  • v);

Proceed φ,ψ ::= Pointcut call(c: :m) Call exec(c: :m) Execution ¬call(c: :m) Not Call ¬exec(c: :m) Not Execution true True false False φ∧ψ Conjunction φ∨ψ Disjunction

FOAL ’04 – p.46/68

slide-63
SLIDE 63

< > - +

µABC

P,Q,R ::= Program letx=pq: m;P Message returnv Return rolep<q;P New Role advice a[φ]=σx.τy.πb.Q;P New Advice

FOAL ’04 – p.47/68

slide-64
SLIDE 64

< > - +

A Minimal Aspect-Based Calculus

FOAL ’04 – p.48/68

slide-65
SLIDE 65

< > - +

Design Choices

Goals Really really small. Straightforward compositional translation of class-based language.

FOAL ’04 – p.49/68

slide-66
SLIDE 66

< > - +

Design Choices

Goals Really really small. Straightforward compositional translation of class-based language. Decisions Start with Abadi and Cardelli’s object calculus (σ).

FOAL ’04 – p.49/68

slide-67
SLIDE 67

< > - +

Design Choices

Goals Really really small. Straightforward compositional translation of class-based language. Decisions Start with Abadi and Cardelli’s object calculus (σ). Add object hierarchy (each object beneath its creator).

FOAL ’04 – p.49/68

slide-68
SLIDE 68

< > - +

Design Choices

Goals Really really small. Straightforward compositional translation of class-based language. Decisions Start with Abadi and Cardelli’s object calculus (σ). Add object hierarchy (each object beneath its creator). Remove everything else. Call objects roles.

FOAL ’04 – p.49/68

slide-69
SLIDE 69

< > - +

Design Choices

Goals Really really small. Straightforward compositional translation of class-based language. Decisions Start with Abadi and Cardelli’s object calculus (σ). Add object hierarchy (each object beneath its creator). Remove everything else. Call objects roles. Remove asymmetry of OO. Message send has the form: pq: m send messages m from p to q

FOAL ’04 – p.49/68

slide-70
SLIDE 70

< > - +

Refactored Syntax

f,...,ℓ,p,...,z Label or Role a,...,e Advice name m,n ::= ℓ a Message P,Q ::= B;returnv Program B,C ::= letx=pq: m D Command D,E ::= Declaration rolep<q Role advice a[φ]=σx.τy.πb.Q Advice Advice names are not first class.

FOAL ’04 – p.50/68

slide-71
SLIDE 71

< > - +

Pointcuts

Syntax φ,ψ ::= Pointcut pq:ℓ Call ¬pq:ℓ Not Call φ∧ψ true Conjunction φ∨ψ false Disjunction ∀x ≤ p.φ Universal ∃x ≤ p.φ Existential Semantics

  • D ⊢ p ≤ q
  • D ⊢ pq:ℓ sat φ

FOAL ’04 – p.51/68

slide-72
SLIDE 72

< > - +

Dynamic Semantics

  • D;letz=pq:

m,ℓ;P D;letz=pq: m, a;P where

  • a = a|

D ∋ advicea[φ]··· and D ⊢ pq:ℓ sat φ

  • D;letz=pq:

m,a;P D; B[p /x, q /y,

m

/b];P[v /z] where D ∋ advice a[···]=σx.τy.πb. B;returnv Pick the rightmost message (for consistency with declaration order). Renaming required in second rule — dom( B) and fn(P) disjoint.

FOAL ’04 – p.52/68

slide-73
SLIDE 73

< > - +

Dynamic Semantics

  • D;letz=pq:

m,ℓ;P D;letz=pq: m, a;P where

  • a = a|

D ∋ advicea[φ]··· and D ⊢ pq:ℓ sat φ

  • D;letz=pq:

m,a;P D; B[p /x, q /y,

m

/b];P[v /z] where D ∋ advice a[···]=σx.τy.πb. B;returnv Pick the rightmost message (for consistency with declaration order). Renaming required in second rule — dom( B) and fn(P) disjoint. Garbage collection P

gc

P′ removes unused roles, advice, messages.

FOAL ’04 – p.52/68

slide-74
SLIDE 74

< > - +

Sugar

Sugar on programs: x

  • returnx

pq: m

  • letx=pq:

m;returnx rolep

  • rolep<top

Sugar on pointcuts: p.ℓ ∃x ≤ top.∃y ≤ p.xy:ℓ “p.ℓ” fires when p or one of its subroles receives message ℓ.

FOAL ’04 – p.53/68

slide-75
SLIDE 75

< > - +

Call-by-value Lambda Calculus

  • D

= rolef; advice a[f .call]=τy.letx=yy:arg;P; roleg<f; advice b[g.arg]=Q; (λx.P)Q

  • D;gg:call
  • D;gg:a
  • D;letx=gg:arg;P
  • D;letx=gg:b;P
  • D;letx=Q;P

gc

  • letx=Q;P
  • Cf. [Milner Functions as Processes]

FOAL ’04 – p.54/68

slide-76
SLIDE 76

< > - +

Conditional

if p ≤ q then R1 else R2 roler; advice [∃x ≤ top.xr :if]=R2; advice [∃x ≤ q.xr :if]=R1; pr :if R1 does not use its proceed variable. If R1 fires, R2 cannot fire.

  • D;if p ≤ q then R1 else R2 ∗ gc

  R1 if D ⊢ p ≤ q R2

  • therwise

FOAL ’04 – p.55/68

slide-77
SLIDE 77

< > - +

Lambda Calculus with Advice

We encode primitives from core MinAML [Walker Zdancewic Ligatti 2003]. See also [Tucker Krishnamurthi 2003]. new p;P creates a new name p which acts as a hook. {p.zQ}> >P attaches after advice λz.Q to hook p. {p.zQ}< <P attaches before advice λz.Q to hook p. pP evaluates P then runs advice hooked on p. Not a full-blown translation. Eg, advice is first class in MinAML.

FOAL ’04 – p.56/68

slide-78
SLIDE 78

< > - +

Core MinAML Reduction

P new p;{p.x1 x1+1}< <{p.x2 x2∗2}> >p3

  • D rolep;

advice a[p.hook]=λx0 .x0; advice b[p.hook]=τz.πd .λx1 .lety1 =x1+1;(zz:d)(y1); advice c[p.hook]=τz.πd .λy2 .letx2 =(zz:d)(y2);x2∗2; P = D;(pp:hook)3 D;(pp:a,b,c)3 ∗ gc D;letx2 =(pp:a,b)(3);x2∗2 ∗ gc D;letx2 =(lety1 =3+1;(pp:a)(y1));x2∗2 ∗ gc D;letx2 =(pp:a)(4);x2∗2 ∗ gc D;letx2 =4;x2∗2 ∗ gc 8

FOAL ’04 – p.57/68

slide-79
SLIDE 79

< > - +

Translating the CBL

advice a[φ](

  • x){Q} = advice a[φ]=σthis.τtarget.πproceed.λ
  • x.thisQ

class t< :u{ M} = role t<u; t M tmethodℓ(

  • x){Q} = advice [t .ℓ]=τthis.πsuper.λ
  • x.thisQ
  • bjectp : t{

F} = rolep<t; p F pfieldf =v = advice a[false]=returnv; advice [p.f]=σx.τy.πb.xy:a,b pletx=q.ℓ(

  • v);P = letx=(pq:ℓ)

v;pP Advice on fields; No call/exec distinction; No global advice order. One step in CBL = Several steps in µABC (including garbage collection).

FOAL ’04 – p.58/68

slide-80
SLIDE 80

< > - +

Insight from µABC

Advice + Names + Name Substitution = Enough! Not much more complicated than λ, π or σ. Paper includes spaghetti CPS translation of µABC into π. Essence of class-based AOP: role hierarchy + advice binding source, target, and proceed. Are pure aspects efficiently implementable?

FOAL ’04 – p.59/68

slide-81
SLIDE 81

< > - +

Closing Waffle

FOAL ’04 – p.60/68

slide-82
SLIDE 82

< > - +

Motivating Example: Resource Access Control

Access Matrix Model [Lampson 1974]. Policy : Subject×Object → 2Rights Stack Inspection [Wallach et al 1997]. Stack : − − − − − → Subject Policy : Stack×Object → 2Rights History-Based Access Control [Abadi Fournet 2003]. Event : Subject×Object×Value×{call,return} History : − − − → Event Policy : History×Object → 2Rights

FOAL ’04 – p.61/68

slide-83
SLIDE 83

< > - +

Abadi/Fournet Example: Bad Plugin

// Trusted : static permissions contain all permissions. public class NaiveProgram { public static void main() { String s = BadPlugIn.tempFile(); new File(s).delete(); } } // Mostly untrusted : static permissions don’t // contain any FilePermission. class BadPlugin { public static String tempFile() { return "..\\password"; } }

FOAL ’04 – p.62/68

slide-84
SLIDE 84

< > - +

Aspects for Resource Access Control

Access Matrix Model: call Stack Inspection: call + cflow History-Based: ?

FOAL ’04 – p.63/68

slide-85
SLIDE 85

< > - +

A More General Notion of Past

Connection between cflow and past-time eventuality operator - ⋄ has been noted by many. cflow’s limitations are accepted on grounds of implementability. How can we implement a more general notion of past?

FOAL ’04 – p.64/68

slide-86
SLIDE 86

< > - +

A More General Notion of Past

Connection between cflow and past-time eventuality operator - ⋄ has been noted by many. cflow’s limitations are accepted on grounds of implementability. How can we implement a more general notion of past? Required in Firewalls and Intrusion Detection Systems. An elegant solution: Security Automata [Schneider 2000]. Idea: automaton maintains an abstraction of the history.

FOAL ’04 – p.64/68

slide-87
SLIDE 87

< > - +

Sketching a Logic of Temporal Pointcuts

A logic based on regular expressions and process algebraic operators: ε empty. φ;ψ sequential composition of two traces. φ∗ closure of sequential composition — ε∨(φ;φ∗). φψ parallel composition of two traces. φ! closure of parallel composition — ε∨(φφ!). Some encodings: balanced = (call;return)! semi·balanced = (balanced;call∗)∗ cflowφ = (φ∧call∗)balanced

FOAL ’04 – p.65/68

slide-88
SLIDE 88

< > - +

Challenges for Temporal Pointcuts

Whose past? thread? caller object? callee object? stack? How does one handle partially completed methods and advice? At what point, exactly, does a call begin or end? What logics are implementable? Compile-time weaving no longer an option. Dynamically loaded aspects attractive – requires rebuilding the automaton (a new kind of weaving). What if new aspects require information that has not been saved?

FOAL ’04 – p.66/68

slide-89
SLIDE 89

< > - +

Putting the Waffles Together

Logics should be powerful enough to capture join points that are not recorded in the stack. Join points are themselves resources, whose access must be managed. Interference between aspect policies an important issue. Work on Feature Interaction is relevant.

FOAL ’04 – p.67/68

slide-90
SLIDE 90

< > - +

Thank You!

FOAL ’04 – p.68/68