How to Compile Aspects with Real-Time Java Pengcheng Wu Northeastern University
Download
Report
Transcript How to Compile Aspects with Real-Time Java Pengcheng Wu Northeastern University
How to Compile Aspects
with Real-Time Java
Pengcheng Wu
Northeastern University
Mar. 14, 2005
FOAL Workshop with AOSD’05
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.
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
Background – RTSJ (cont.)
RTSJ’s Scoped-memory based memory
model
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.)
T1
×
×
×
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 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
√
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
}
}
cd
cd.run()
m2
m1
Problems of compiling Aspects with RTSJ
Program – An Example(cont.)
Now we want to aspectize it so that it only
does periodical polling.
ILLEGAL!
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
}
}
}
cd
PeriodicPoll
m2
m1
cd.run()
Aspect instantiation
is implicit,
programmers cannot
avoid the problem.
Problems of compiling Aspects with RTSJ
Program – cflow based aspect
instantiation
Similar problems exist for cflow pointcuts
Global
Stack
with variable bindings
Singleton aspect instantiation and reflective
access to thisJoinPoint should be fine.
ILLEGAL!
aspect instance for level 2
aspect instance for level 1
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.
Proposed compilation approaches for
Aspects + RTSJ (cont.)
CFLOW-based aspect instantiation (cont. )
A
portal
portal
B
×
portal
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.)
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
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.
Thank you!
Questions and Discussions