Language support for AOP - Northeastern University...Problem: context dependencies • Generate...

32
Language support for AOP AspectJ and beyond Mario S ¨ udholt www.emn.fr/sudholt INRIA and ´ Ecole des Mines de Nantes OBASCO project, Nantes, France “Language support for AOP”; Mario S¨ udholt; INRIA/EMN; March 8, 2005 – p.1/28

Transcript of Language support for AOP - Northeastern University...Problem: context dependencies • Generate...

Page 1: Language support for AOP - Northeastern University...Problem: context dependencies • Generate events for scheduleinstructions • Other instructions relevant (e.g., thread state,

Language support for AOPAspectJ and beyond

Mario Sudholt

www.emn.fr/sudholt

INRIA and Ecole des Mines de Nantes

OBASCO project, Nantes, France

“Language support for AOP”; Mario S udholt; INRIA/EMN; March 8, 2005 – p.1/28

Page 2: Language support for AOP - Northeastern University...Problem: context dependencies • Generate events for scheduleinstructions • Other instructions relevant (e.g., thread state,

Plan

• AOP and AspectJ

• AspectJ: end of story?

• Beyond AspectJ

“Language support for AOP”; Mario S udholt; INRIA/EMN; March 8, 2005 – p.2/28

Page 3: Language support for AOP - Northeastern University...Problem: context dependencies • Generate events for scheduleinstructions • Other instructions relevant (e.g., thread state,

I. AOP and AspectJ

“Language support for AOP”; Mario S udholt; INRIA/EMN; March 8, 2005 – p.3/28

Page 4: Language support for AOP - Northeastern University...Problem: context dependencies • Generate events for scheduleinstructions • Other instructions relevant (e.g., thread state,

Defining characteristics of AOP?

• Quantification : modularization of crosscuttingconcerns

• Obliviousness : non-anticipation; incrementaldevelopment

⇒ Tackle crosscutting in large-scale applicationsthroughout the software life cycle

More probably later from Bob . . .

“Language support for AOP”; Mario S udholt; INRIA/EMN; March 8, 2005 – p.4/28

Page 5: Language support for AOP - Northeastern University...Problem: context dependencies • Generate events for scheduleinstructions • Other instructions relevant (e.g., thread state,

What’s new? (1)

• What about computational reflection ?• 3-Lisp, CLOS, Reflex [Tanter et al.,

OOPSLA’03], . . .• General enough reflective system can

“emulate” AOP systems• Difficult to understand• Performance issues• Semantics issues, lack of correctness

guarantees

“Language support for AOP”; Mario S udholt; INRIA/EMN; March 8, 2005 – p.5/28

Page 6: Language support for AOP - Northeastern University...Problem: context dependencies • Generate events for scheduleinstructions • Other instructions relevant (e.g., thread state,

What’s new? (2)

• What about transformation systems ?• General enough transformation system can

“emulate” AOP systems• SOOT, Recoder, CIL, . . .• Difficult to understand• Correctness properties difficult to handle

“Language support for AOP”; Mario S udholt; INRIA/EMN; March 8, 2005 – p.6/28

Page 7: Language support for AOP - Northeastern University...Problem: context dependencies • Generate events for scheduleinstructions • Other instructions relevant (e.g., thread state,

Yes, it is! (in a sense)

Goals for AOP

• Provide abstractions general enough tomodularize (some or all) concerns.

• Be specific enough to make such modularizationunderstandable, tractable and amenable totesting, analysis, verification of properties.

“Language support for AOP”; Mario S udholt; INRIA/EMN; March 8, 2005 – p.7/28

Page 8: Language support for AOP - Northeastern University...Problem: context dependencies • Generate events for scheduleinstructions • Other instructions relevant (e.g., thread state,

AspectJ in one slide

Base program: critical, access

“Language support for AOP”; Mario S udholt; INRIA/EMN; March 8, 2005 – p.8/28

Page 9: Language support for AOP - Northeastern University...Problem: context dependencies • Generate events for scheduleinstructions • Other instructions relevant (e.g., thread state,

AspectJ in one slide

pointcut critAcc(Base r): call(void Base.acc(int)

&& target(r)

&& cflow(call(void Base.crit(int))));

“Language support for AOP”; Mario S udholt; INRIA/EMN; March 8, 2005 – p.8/28

Page 10: Language support for AOP - Northeastern University...Problem: context dependencies • Generate events for scheduleinstructions • Other instructions relevant (e.g., thread state,

AspectJ in one slide

pointcut critAcc(Base r): call(void Base.acc(int)

&& target(r)

&& cflow(call(void Base.crit(int))));

void around(Base r): critAcc(r) {

calls++;

if (ok()) proceed(r);

}

“Language support for AOP”; Mario S udholt; INRIA/EMN; March 8, 2005 – p.8/28

Page 11: Language support for AOP - Northeastern University...Problem: context dependencies • Generate events for scheduleinstructions • Other instructions relevant (e.g., thread state,

AspectJ in one slide

aspect ProfBar pertarget call(void Base.acc(int)) {

int calls = 0;

pointcut critAcc(Base r): call(void Base.acc(int)

&& target(r)

&& cflow(call(void Base.crit(int))));

void around(Base r): critAcc(r) {

calls++;

if (ok()) proceed(r);

}

}

“Language support for AOP”; Mario S udholt; INRIA/EMN; March 8, 2005 – p.8/28

Page 12: Language support for AOP - Northeastern University...Problem: context dependencies • Generate events for scheduleinstructions • Other instructions relevant (e.g., thread state,

AspectJ in one slide

aspect ProfBar pertarget call(void Base.acc(int)) {

int calls = 0;

static int Base.calls = 0;

pointcut critAcc(Base r): call(void Base.acc(int)

&& target(r)

&& cflow(call(void Base.crit(int))));

void around(Base r): critAcc(r) {

calls++;

if (ok()) proceed(r);

}

}

“Language support for AOP”; Mario S udholt; INRIA/EMN; March 8, 2005 – p.8/28

Page 13: Language support for AOP - Northeastern University...Problem: context dependencies • Generate events for scheduleinstructions • Other instructions relevant (e.g., thread state,

Characteristics of AspectJ

+ Join points

+ Pointcuts

+ Advice

+ Aspects

+ Inter-type declarations

+– Aspect instantiation (coarse-grained)

+– Aspect activation (on/off)

+– Aspect composition (dominate)

“Language support for AOP”; Mario S udholt; INRIA/EMN; March 8, 2005 – p.9/28

Page 14: Language support for AOP - Northeastern University...Problem: context dependencies • Generate events for scheduleinstructions • Other instructions relevant (e.g., thread state,

II. AspectJ: end of story?

• Other characteristics of aspect languages

• Other base languages, execution environments

• More expressive pointcut languages

“Language support for AOP”; Mario S udholt; INRIA/EMN; March 8, 2005 – p.10/28

Page 15: Language support for AOP - Northeastern University...Problem: context dependencies • Generate events for scheduleinstructions • Other instructions relevant (e.g., thread state,

Other characteristics of aspectlanguages

• Aspect instantiationE.g., runtime instances, Kevin’s talk

• Aspect activationE.g., enable/disable aspects at runtime

• Aspects of aspectsE.g., layered aspects, Kevin’s talk

• Aspect compositionE.g. for conflict resolution

• Weaver semanticsE.g., no aspects of aspects

“Language support for AOP”; Mario S udholt; INRIA/EMN; March 8, 2005 – p.11/28

Page 16: Language support for AOP - Northeastern University...Problem: context dependencies • Generate events for scheduleinstructions • Other instructions relevant (e.g., thread state,

A world outside Java?

• Crosscutting concerns in large (legacy) Capplications

• Ex.: optimization of web caches without cacheflushes

• New aspect languages for expression of complexcontext conditions

“Language support for AOP”; Mario S udholt; INRIA/EMN; March 8, 2005 – p.12/28

Page 17: Language support for AOP - Northeastern University...Problem: context dependencies • Generate events for scheduleinstructions • Other instructions relevant (e.g., thread state,

Other pointcut languages (1)

• Stateful pointcuts (explicit state in pointcuts)• Sequence pointcuts:

Ex.: protocol translation and bug correction• Temporal logic pointcuts:

Ex.: manipulation of Linux kernel code• Regular expression pointcuts:

Enable interference analysis among aspects

“Language support for AOP”; Mario S udholt; INRIA/EMN; March 8, 2005 – p.13/28

Page 18: Language support for AOP - Northeastern University...Problem: context dependencies • Generate events for scheduleinstructions • Other instructions relevant (e.g., thread state,

Other pointcut languages (2)

• AOP and distributed applications• Often integration/configuration of existing

distribution platforms (see Kevin’s talk)⇒ distribution implicit to aspects

• Remote pointcuts [Nishizawa et al.,AOSD’04]: explicit hosts, advice server

• Trade-off: hide complexity vs. flexibility

• Data-flow pointcuts [Masuhara, Kawauchi;APLAS’03], e.g., for security enforcement.Efficiency realization

“Language support for AOP”; Mario S udholt; INRIA/EMN; March 8, 2005 – p.14/28

Page 19: Language support for AOP - Northeastern University...Problem: context dependencies • Generate events for scheduleinstructions • Other instructions relevant (e.g., thread state,

III. Beyond AspectJ

1. Dynamic aspects for C system-level applications

2. Temporal logic pointcuts for Linux kernel evolution

“Language support for AOP”; Mario S udholt; INRIA/EMN; March 8, 2005 – p.15/28

Page 20: Language support for AOP - Northeastern University...Problem: context dependencies • Generate events for scheduleinstructions • Other instructions relevant (e.g., thread state,

1. Dynamic aspects for Csystem-level applications

• Software evolution frequently to be performed onrunning systems (e.g., high-availability servers)

• Ex. concerns in a web cache• Modification of caching policies• Optimizations (e.g., protocol transformations

TCP→UDP)• Bug corrections

• Some large applications:Open-source web-cache “squid”: 9 MB of source

“Language support for AOP”; Mario S udholt; INRIA/EMN; March 8, 2005 – p.16/28

Page 21: Language support for AOP - Northeastern University...Problem: context dependencies • Generate events for scheduleinstructions • Other instructions relevant (e.g., thread state,

Ex.: explicit sequences for bufferoverflows

• Aspect language with explicit sequences

seq( call(void∗ malloc(size_t))

&& args(allocatedSize) && return(buffer) ;

write(buffer) && size(writtenSize)

&& if(writtenSize> allocatedSize)

then reportOverflow(); ∗

call(void free(void∗)) )

“Language support for AOP”; Mario S udholt; INRIA/EMN; March 8, 2005 – p.17/28

Page 22: Language support for AOP - Northeastern University...Problem: context dependencies • Generate events for scheduleinstructions • Other instructions relevant (e.g., thread state,

Aspect language

• Primitive pointcuts: calls and variables accesses(to global and local variables)

• cflow for nested calls (like AspectJ)

• Sequences with• Conditionals over data

Principally equalities (e.g. over file handles)• Means for ressource handling

Optimize ressource usage (e.g., reuse of filehandles)

“Language support for AOP”; Mario S udholt; INRIA/EMN; March 8, 2005 – p.18/28

Page 23: Language support for AOP - Northeastern University...Problem: context dependencies • Generate events for scheduleinstructions • Other instructions relevant (e.g., thread state,

Realization: the Arachne system

• Dynamic aspect application for C without programinterruptionwww.emn.fr/x-info/arachne

• Rewrite binary code on the fly to weave (anddeweave) aspects

• Current weaving semantics excludes nestedaspectsSimplified implementation, somewhat moreefficient

• [Ségura et al, AOSD’03] [Fritz et al, AOSD’05]

“Language support for AOP”; Mario S udholt; INRIA/EMN; March 8, 2005 – p.19/28

Page 24: Language support for AOP - Northeastern University...Problem: context dependencies • Generate events for scheduleinstructions • Other instructions relevant (e.g., thread state,

2. Temporal logic pointcuts forLinux kernel evolution

• Problem: support extensions of the Linux kernelover a range of kernel versionsE.g., over one major version number

• Ex.: support application-specific schedulersE.g., for multi-media streaming

• Context: integrate an existing system forscheduler development with the kernel

“Language support for AOP”; Mario S udholt; INRIA/EMN; March 8, 2005 – p.20/28

Page 25: Language support for AOP - Northeastern University...Problem: context dependencies • Generate events for scheduleinstructions • Other instructions relevant (e.g., thread state,

Bossa: new schedulers for plainold Linux

• Bossa: system for scheduler developmentwww.emn.fr/x-info/bossa

• DSL: definition of scheduling policies

• Support runtime for hierachical, prioritized, etc.,schedulers

• Runtime overhead < 5%

“Language support for AOP”; Mario S udholt; INRIA/EMN; March 8, 2005 – p.21/28

Page 26: Language support for AOP - Northeastern University...Problem: context dependencies • Generate events for scheduleinstructions • Other instructions relevant (e.g., thread state,

Bossa architecture

• Events mediate between (instrumented) kerneland Bossa runtime, which supports policies

schedulerBossa

Kernel moduleevent

scheduler state

bossa.schedule

elected process

systemrun−time

Bossa

Kernel

events

eventsBossawith

kernelStandard

“Language support for AOP”; Mario S udholt; INRIA/EMN; March 8, 2005 – p.22/28

Page 27: Language support for AOP - Northeastern University...Problem: context dependencies • Generate events for scheduleinstructions • Other instructions relevant (e.g., thread state,

Mediation through eventscrosscuts the kernel

• Instrument kernel code + drivers (˜ 100 MBsource code)

• Instrumentation for Bossa:• ˜ 400 instructions changed in about 150 files

• Previously manually done for Linux kernel 2.4

• Can we do better with aspects?

“Language support for AOP”; Mario S udholt; INRIA/EMN; March 8, 2005 – p.23/28

Page 28: Language support for AOP - Northeastern University...Problem: context dependencies • Generate events for scheduleinstructions • Other instructions relevant (e.g., thread state,

Problem: context dependencies

• Generate events forschedule instructions

• Other instructionsrelevant (e.g., threadstate, yield)

• Problem: threadcontext implicit

• Explicit context depen-dencies vs. efficiency remove_wait_queue();

reg_write();

retval=−EINTR;

run_sub_pcl();

add_wait_queue();

set_current_state(TASK_INTERRUPTIBLE);

schedule();

if(signal_pending(current))

schedule();

true

false

while(...)

n

“Language support for AOP”; Mario S udholt; INRIA/EMN; March 8, 2005 – p.24/28

Page 29: Language support for AOP - Northeastern University...Problem: context dependencies • Generate events for scheduleinstructions • Other instructions relevant (e.g., thread state,

Solution: temporal logic pointcuts

• Use temporal predicates to express control-flowrelationships

n : Rewrite(n,schedule_running)

If n` AX4(A4(¬changeOfState() U changeToRunning()))

“Change current instruction to schedule running iffor all backword pathes starting from the predecessornode, all backward pathes change to running withoutprevious changes to the state.”

“Language support for AOP”; Mario S udholt; INRIA/EMN; March 8, 2005 – p.25/28

Page 30: Language support for AOP - Northeastern University...Problem: context dependencies • Generate events for scheduleinstructions • Other instructions relevant (e.g., thread state,

Results

• Transformational system for Bossa integration: 25rules

• Implementation based on CIL yields exactinstrumentation⇒ no overhead to manual instrumentation

• 6 bugs of manual instrumentation detected

• [Åberg et al., ASE’03]

“Language support for AOP”; Mario S udholt; INRIA/EMN; March 8, 2005 – p.26/28

Page 31: Language support for AOP - Northeastern University...Problem: context dependencies • Generate events for scheduleinstructions • Other instructions relevant (e.g., thread state,

Conclusion

• AOP is relevant to software development

• AOP interesting from theoretical and praticalviewpoint

• AspectJ is an interesting language and toolbut not the end of the story

“Language support for AOP”; Mario S udholt; INRIA/EMN; March 8, 2005 – p.27/28

Page 32: Language support for AOP - Northeastern University...Problem: context dependencies • Generate events for scheduleinstructions • Other instructions relevant (e.g., thread state,

Future work

• (Almost) everything still to be done

• AOP for distributed programming• Remote pointcut: extend language,

implementation, remote aspect calculus

• Aspect interactions• Generalize first results over regular

expressions, use of model checking

• Aspects and components• Aspects over components with explicit

protocols“Language support for AOP”; Mario S udholt; INRIA/EMN; March 8, 2005 – p.28/28