Basanta jtr2009
-
Upload
universidad-carlos-iii-de-madrid -
Category
Documents
-
view
145 -
download
2
Transcript of Basanta jtr2009
Este trabajo ha sido publicado en IEEE-ISORC’08 (Orlando-USA)
Simplifying the dualized threading model of RTSJ
Pablo Basanta-ValMarisol García-Valls
Iria Estévez-Ayres
mailto: [email protected]://www.it.uc3m.es/drequiem/
XII Jornadas de Tiempo Real 5-6 de febrero de 2009 (Leganés)
Roadmap
1. Introduction– Motivation
2. RealtimeThread++ extension– Interface changes– Example of use– Low level (VM) changes
3. Taking advantage of the extension– GC interference avoidance– Extended event handlers– Enhanced real-time distributed architectures
4. Empirical results– Absolute and relative penalties
5. Concluding remarks
XII Jornadas de Tiempo Real 5-6 de febrero de 2009 (Leganés)
Introduction
• Java is a successful high-level language– Bytecode portability, garbage collection, clear syntax, a number of
libraries, ….– Productivity may be higher than with other languages (C/C++)
• Java has extended its radius of action to real-time systems– Ideally: real-time portability, real-time automatic memory
management, and real-time libraries– And also: lower development times, and improved maintainability
XII Jornadas de Tiempo Real 5-6 de febrero de 2009 (Leganés)
Current Status of Real-Time Java
• Specifications– Real-Time Specification for Java (RTSJ)
– Distributed Realtime Specification for Java (DRTSJ)
• Compliant virtual machines– Sun’s JRTS, Aicas’s Jamaica, TimeSys’s JTime, IBM Real-Time
Websphere, Purdue’s OVM, …
• Plug-ins for development environments– Netbeans (Sun) and Eclipse (IBM, Aicas)
XII Jornadas de Tiempo Real 5-6 de febrero de 2009 (Leganés)
RealtimeThread++• An extension not identified in JSR-282 (RTSJ 1.1)• RTSJ offers two types of real-time threads:
• RealtimeThread (RtThs) and NoHeapRealtimeThreads (NhRtThs)
• Reducing unnecessarily the language expressiveness– RtThs suffer the garbage collector whereas NhRtThs cannot use
the heap– A general purpose application may require both types of support
• Why don’t a simplification in this model? – One unique type of thread that decides its relationship with the
garbage collector and the heap at runtime– Benefits: a more flexible specification and better synchronization
models.
XII Jornadas de Tiempo Real 5-6 de febrero de 2009 (Leganés)
Real-Time Java
Centralized concurrent entities
RTSJ Thread
RealtimeThread
NoheapRealtimeThread
AsyncEventHandler
BoundAsyncEventHandler
Distributed
concurrent entities
DRTSJ DistributedRealtimeThread
NoHeapDistributedRealtimeThread
DistributedEventHandler
Synchronization RTSJ Synchronized
RealtimeQueues
Signals
XII Jornadas de Tiempo Real 5-6 de febrero de 2009 (Leganés)
Real-Time Java with RealtimeThread++
Centralized concurrent entities
RTSJ Thread
RealtimeThread
NoheapRealtimeThread
AsyncEventHandler
BoundAsyncEventHandler
Distributed
concurrent entities
DRTSJ DistributedRealtimeThread
NoHeapDistributedRealtimeThread
DistributedEventHandler
Synchronization RTSJ synchronized
RealtimeQueues
Signals
XII Jornadas de Tiempo Real 5-6 de febrero de 2009 (Leganés)
RealtimeThread++: changes
• One thread is initially running in either heap or noheap environments– By default, in its instantiation, NhRtThs and NhDRtThs run in
noheap memory whereas RtThs run in heap
• One thread may change at runtime its relationship with the garbage collector– We may change it, temporally, nesting a heap (with enterHeap) or a noheap (with enterNoHeap) runnable object
01: Runnable r1 = new Runnable(){02: public void run(){03: System.out.println(“Running in heap”);04: }05: };06:07: Runnable r2 = new Runnable(){08: public void run(){09: System.out.println(“Running in Noheap”);10: RealtimeThread.enterHeap(r1)11: }12: };13: RealtimeThread.enterNoHeap(r2);
XII Jornadas de Tiempo Real 5-6 de febrero de 2009 (Leganés)
RealtimeThread++: full API
package javax.realtime;public class RealtimeThread extends Thread{
public static void enterHeap(Runnable r){. . .}public static void enterNoHeap(Runnable r){. . .}public static boolean isRunningInHeap(){. . .}
. . .}
01: Runnable r1 = new Runnable(){02: public void run(){03: System.out.println(“Running in heap”);04: }05: };06:07: Runnable r2 = new Runnable(){08: public void run(){09: System.out.println(“Running in Noheap”);10: RealtimeThread.enterHeap(r1)11: }12: };13: RealtimeThread.enterNoHeap(r2);
XII Jornadas de Tiempo Real 5-6 de febrero de 2009 (Leganés)
RealtimeThread++ in action
01: Runnable r1 = new Runnable(){02: public void run(){03: System.out.println(“Running in heap”);04: }05: };06:07: Runnable r2 = new Runnable(){08: public void run(){09: System.out.println(“Running in Noheap”);10: RealtimeThread.enterHeap(r1)11: }12: };13: RealtimeThread.enterNoHeap(r2);
One task printing out two messages: the first in noheapand the second in heap
01: Runnable r1 = new Runnable(){02: public void run(){03: System.out.println(“Running in heap”);04: }05: };06:07: Runnable r2 = new Runnable(){08: public void run(){09: System.out.println(“Running in Noheap”);10: RealtimeThread.enterHeap(r1)11: }12: };13: RealtimeThread.enterNoHeap(r2);
XII Jornadas de Tiempo Real 5-6 de febrero de 2009 (Leganés)
RealtimeThread++ in action
Evolution of the system, the active environment is the one on the top of the environment stack
01: Runnable r1 = new Runnable(){02: public void run(){03: System.out.println(“Running in heap”);04: }05: };06:07: Runnable r2 = new Runnable(){08: public void run(){09: System.out.println(“Running in Noheap”);10: RealtimeThread.enterHeap(r1)11: }12: };13: RealtimeThread.enterNoHeap(r2);
XII Jornadas de Tiempo Real 5-6 de febrero de 2009 (Leganés)
Required underlying support
• Activation and deactivation of reading barrier typically associated with a NhRtThs– Low level interaction with the virtual machine required
• The check of local variables (for NH to H changes)– Easy to obtain in a portable way.
• Modification of the relationship maintained with the garbage collector– Sometimes, NhRtThs have privileges when garbage collector scans their
frame stack
#Turning off the read barrierRTJVM.disableNoHeapReadBarrier();
XII Jornadas de Tiempo Real 5-6 de febrero de 2009 (Leganés)
Runtime checking barriers (examples)
#Checking local variablesif r allocated in HeapMemory throws new IllegalAssignmentException();
#Turnning on the read barrierRTJVM.enableNoHeapReadBarrier();
Runtime barrier that changes the behavior from heap to no-heap.
#Turning off the read barrierRTJVM.disableNoHeapReadBarrier();
Runtime barrier that changes the behavior from o no-heap to heap
#Turning off the read barrierRTJVM.disableNoHeapReadBarrier();
XII Jornadas de Tiempo Real 5-6 de febrero de 2009 (Leganés)
Integration with the garbage collector
NoHeapRealtimeThreadqueue
RealtimeThreadqueue
(i) moving from noheap to heap
(ii) moving from heap to noheap
#Turning off the read barrierRTJVM.disableNoHeapReadBarrier();
XII Jornadas de Tiempo Real 5-6 de febrero de 2009 (Leganés)
Taking advantage of the extension
– Sharing data • Among heap and no-heap entities using enterNoHeap
– Enrichment of the current RTSJ• Giving more flexibility to event-handler programming
– Enrichment of the ongoing DRTSJ• Eases some architecture implementations
XII Jornadas de Tiempo Real 5-6 de febrero de 2009 (Leganés)
Garbage collector priority inversion
01: public class Table {02: private long count=0;03: private Object lock=new Object();04: public void inc(){05: synchronized(lock){ 06: count++; //May cause the GC inversion propagation07: }08: } 09: }
ImmortalMemoryScopedMemoryHeapMemory
rt-threadtable
nhrt-threadinc inc
heap noheap
XII Jornadas de Tiempo Real 5-6 de febrero de 2009 (Leganés)
Garbage collector priority inversion (current RTSJ approach)
00: public class Table{01: private long count=0;02: private Object lock=new Object();03: private WaitFreeReadQueue wfq=04: new WaitFreeReadQueue(5,false);05: public Counter(){06: th.start();07: }08: private NoHeapRealtimeThread th=new 09: NoHeapRealtimeThread(){10: public void run(){11: do{ 12: wfq.waitForData();13: wfq.read();14: count++;15: }while(true);16: }};17: public void inc(){18: wfq.write(lock);//OK 19: }20: } 21: }
ImmortalMemory ScopedMemory
HeapMemory
rt-thread table
nhrt-thread
inc inc
heap noheap
XII Jornadas de Tiempo Real 5-6 de febrero de 2009 (Leganés)
Garbage collector priority inversion (with RealtimeThread++)
ImmortalMemory
ScopedMemoryHeapMemory
rt-threadtable
nhrt-thread
inc inc
heap noheap
01: public class Table{
02: private long count=0;
03: private private Object lock=new Object();
04: private Runnable r=new Runnable(){
05: public void run(){
06: synchronized(lock){ //GC OK
07: count++;
08: }
09: };
10: public void inc(){
11: RealtimeThread.enterNoheap(r); //Ok
12: }
13: }
XII Jornadas de Tiempo Real 5-6 de febrero de 2009 (Leganés)
Enhanced RTSJ event model
ImmortalMemory
ScopedMemory
heap noheap
HeapMemory
Heap
Externalevent
NoHeap
NoHeap
21
NoHeap
enterHeap
Currently event handler decide at creation time itsrelationship with the garbage collector
XII Jornadas de Tiempo Real 5-6 de febrero de 2009 (Leganés)
Session-level isolation for DRTSJ(with real-time thread++ extension)
Remote ObjectStub
enterNoHeapenterNoHeapenterHeap
Programmer space
DistributionMiddleware
heap or noheap
noheap
client server