Presentation is loading. Please wait.

Presentation is loading. Please wait.

How to Compile Aspects with Real-Time Java Pengcheng Wu Northeastern University Mar. 14, 2005 FOAL Workshop with AOSD’05.

Similar presentations


Presentation on theme: "How to Compile Aspects with Real-Time Java Pengcheng Wu Northeastern University Mar. 14, 2005 FOAL Workshop with AOSD’05."— Presentation transcript:

1 How to Compile Aspects with Real-Time Java Pengcheng Wu Northeastern University Mar. 14, 2005 FOAL Workshop with AOSD’05

2 Motivations Real-time systems tend to have a lot of cross-cutting concerns, e.g., thread scheduling, memory management AOP is expected to be helpful to modularize those concerns Real-Time Java Specification (RTSJ) -- an emerging technology to enhance Java with real time features Current AspectJ compilation approaches do not work well with Real-Time Java Specification’s special memory model.

3 Background – Real-Time Java Specification (RTSJ) Java is unsuitable to implement real-time systems  unpredictable garbage collection  unpredictable thread scheduling RTSJ has been proposed to minimize those unpredictability  Official reference implementation by TimeSys Corp. http://www.timesys.com  Open source implementations also available We are particularly interested in RTSJ’s special memory management model

4 Background – RTSJ (cont.) RTSJ’s Scoped-memory based memory model  Scoped memory areas provide guarantee on object allocation time

5 Background – RTSJ (cont.) Objects never reclaimed Objects are just like regular Java heap objects Threads can enter scopes; objects in a scope are freed altogether when all threads left scope

6 Background – RTSJ (cont.) A T1 B × C × × × × ×

7 Background – RTSJ (cont.) A × B C OK ILLEGAL! To avoid dangling pointers, an object reference rule is checked by RTSJ-compliant JVMs. Programmers are responsible for following the rule.

8 Question: How about using AspectJ with RTSJ? How about aspect instantiation? It is implicit and beyond control of programmers. Instance-based aspect instantiation (perthis, pertarget) × CFLOW-based aspect instantiation (percflow) × CFLOW pointcuts with variable bindings × Singleton aspect and reflective access to thisJoinPoint √

9 Problems of compiling Aspects with RTSJ Program – An Example class App extends RealtimeThread { public static void main(String[] args) { MemoryArea mem = ImmortalMemory.instance(); App app = (App) mem.newInstance(App.class); app.start(); } public void run() { ScopedMemory m1 = new LTMemory(... ); m1.enter(new Runner()); } class Runner implements Runnable { public void run() { Detector cd = new Detector(... ); LTMemory m2 = new LTMemory(... ); while(true) m2.enter(cd); } class Detector implements Runnable { public void run() { Frame frame = receiveFrame(); //gets a frame and stores it // into a table //check if any two planes are //going to collide } m1 m2 cd cd.run()

10 Problems of compiling Aspects with RTSJ Program – An Example(cont.) Now we want to aspectize it so that it only does periodical polling. aspect PeriodicPoll perthis(p()) { Time lastTimePolled; pointcut p(): execution(* Detector.run(..)); around(): p() { if(hasn’t yet been 2 seconds) getCurrentThread().yield(); //don't do polling else { //update the time lastTimePolled = System.getCurrentTime(); proceed(); //do polling } m1 m2 cd cd.run() PeriodicPoll ILLEGAL! Aspect instantiation is implicit, programmers cannot avoid the problem.

11 Problems of compiling Aspects with RTSJ Program – cflow based aspect instantiation Global Stack aspect instance for level 1 aspect instance for level 2 ILLEGAL! Similar problems exist for cflow pointcuts with variable bindings Singleton aspect instantiation and reflective access to thisJoinPoint should be fine.

12 Proposed compilation approaches for Aspects + RTSJ Instance-based Aspect Instantiation  Make instantiation explicit?  Allocate aspect instances in ImmortalMemory or HeapMemory?  Allocate aspect instances in the same scoped memories as the host objects. √ CFLOW-based aspect instantiation  Make use of the Portal object of a scoped memory area.

13 Proposed compilation approaches for Aspects + RTSJ (cont.) CFLOW-based aspect instantiation (cont. ) × A B C portal CFLOW-based aspect instantiation looking up – climbing up the memory chain and looking it up in each of the stacks.

14 Proposed compilation approaches for Aspects + RTSJ (cont.) CFLOW-based Aspect Instantiation (cont.)  Problem: portal object may be used by user program for threads communication purpose in RTSJ.  Solution: do automatic adaptation during compile time. An aspect may do the job! CFLOW pointcuts with variable bindings  Similar approach as cflow-based aspect instantiation

15 Future work Implementation of an actual compiler Formal proof that there will be no aspect introduced object reference violations using RTSJ semantics and probably enhanced AspectJ semantics.

16 Thank you! Questions and Discussions


Download ppt "How to Compile Aspects with Real-Time Java Pengcheng Wu Northeastern University Mar. 14, 2005 FOAL Workshop with AOSD’05."

Similar presentations


Ads by Google