How to Compile Aspects with RealTime Java Pengcheng
















- Slides: 16

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

Motivations n n 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 Aspect. J compilation approaches do not work well with Real-Time Java Specification’s special memory model.

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

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

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

Background – RTSJ (cont. ) T 1 × × × A × × B C ×

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

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

Problems of compiling Aspects with RTSJ Program – An Example class App extends Realtime. Thread { public static void main(String[] args) { Memory. Area mem = Immortal. Memory. instance(); App app = (App) mem. new. Instance(App. class); app. start(); } public void run() { Scoped. Memory m 1 = new LTMemory(. . . ); m 1. enter(new Runner()); } } class Runner implements Runnable { public void run() { Detector cd = new Detector(. . . ); LTMemory m 2 = new LTMemory(. . . ); while(true) m 2. enter(cd); } } class Detector implements Runnable { public void run() { Frame frame = receive. Frame(); //gets a frame and stores it // into a table //check if any two planes are //going to collide } } cd cd. run() m 2 m 1

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

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

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

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

Proposed compilation approaches for Aspects + RTSJ (cont. ) n CFLOW-based Aspect Instantiation (cont. ) q q n 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 q Similar approach as cflow-based aspect instantiation

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

Thank you! Questions and Discussions