Post on 13-Apr-2018
Real-Time Java on JOP
Martin Schöberl
Real-Time Java on JOP 2
Overview
RTSJ – why notSimple RT profileScheduler implementationUser defined scheduling
Real-Time Java on JOP 3
Real-Time Specification for Java
Real-time extension definitionSun JSR - standardStill not completely finishedImplementations
Timesys RIPurdue OVM
Real-Time Java on JOP 4
RTSJ Issues
Large and complex specificationImplementationVerification
Scoped memory cumbersomeExpensive longs (64 bit) for time valuesJ2SE library
Heap usage not documentedOS functions can cause blocking
Real-Time Java on JOP 5
RTSJ Subset
Ravenscar JavaName from Ravenscar AdaBased in Puschner & Wellings paper
Profile for high integrity applicationsRTSJ compatibleNo dynamic thread creationOnly NHRTTSimplified scoped memoryImplementation?
Real-Time Java on JOP 6
Real-Time Profile
Hard real-time profileSee Puschner paper
Easy to implementLow runtime overheadNo RTSJ compatibility
Real-Time Java on JOP 7
Real-Time Profile
Schedulable objectsPeriodic activitiesAsynchronous sporadic activities
Hardware interrupt or software eventBound to a thread
ApplicationInitializationMission
Real-Time Java on JOP 8
Application Structure
Initialization phaseFixed number of threadsThread creationShared objects in immortal memory
MissionRuns foreverCommunication via shared objectsScoped memory for temporary data
Real-Time Java on JOP 9
Schedulable ObjectsThree types:
RtThread, HwEvent and SwEvent
Fixed priorityPeriod or minimum interarrival timeScoped memory per threadDispatched after mission start
public class RtThread {
public RtThread(int priority, int period)
...
public RtThread(int priority, int period,
int offset, Memory mem)
public void enterMemory()
public void exitMemory()
public void run()
public boolean waitForNextPeriod()
public static void startMission()
}
public class HwEvent extends RtThread {
public HwEvent(int priority, int minTime,
Memory mem, int number)
public void handle()
}
public class SwEvent extends RtThread {
public SwEvent(int priority, int minTime,
Memory mem)
public final void fire()
public void handle()
}
Real-Time Java on JOP 10
Scheduling
Fixed priority with strict monotonic orderPriority ceiling emulation protocol
Top priority for unassigned objects
Interrupts under scheduler controlPriority for device driversNo additional blocking timeIntegration in schedulability analysis
Real-Time Java on JOP 11
Memory
No GC: Heap becomes immortal memoryScoped memory
Bound to one thread at creationConstant allocation time
Cleared on creation and on exit
Simple enter/exit syntax
Real-Time Java on JOP 12
Restrictions of Java
Only WCET analyzable language constructsNo static class initializer
Use a static init() function
No finalizationObjects in immortal memory live foreverFinalization complicates WCET analysis of exit from scoped memory
No dynamic class loading
Real-Time Java on JOP 13
Implementation
Scheduler for a Java real-time profilePeriodic and sporadic threadsPreemptiveFixed priority
MicrocodeJava
Real-Time Java on JOP 14
Low-level Functions
Access to JVM internalsExposed as special bytecodesIn Java declared as native methodsTranslationAvoids non-standard class files
Real-Time Java on JOP 15
Interrupts in JOP
Translation of JVM bytecodes to microcodeInterrupts are special bytecodesInserted in the translation stageCall of JVM internal Java method
Real-Time Java on JOP 16
Dispatching
Scheduler is a Java methodContext of task is on the stackExchange stackSet stack pointerSimple return
private static int newSp;
public static void schedule() {
Native.wr(0, IO_INT_ENA);
RtThread th = tasks[active];
th.sp = Native.getSP();
Native.int2extMem(...);
// find ready thread and
// new timer value
newSp = tasks[ready].sp;
Native.int2extMem(...);
Native.wr(tim, IO_TIMER);
Native.setSP(newSp);
Native.wr(1, IO_INT_ENA);
}
Real-Time Java on JOP 17
Implementation Results
Scheduler and Dispatch in JavaOnly one function in microcodeTest JVM in C
JOP compatible JVMImplements timer with timestamp counterScheduling in JavaNo OS needed, just a 32-bit C compiler
Real-Time Java on JOP 18
User-Defined Scheduler
Java is a safe OO LanguageNo pointersType-safety
No kernel user space distinctionHooks for schedulingScheduler in Java extended to a framework
Class SchedulerClass Task
Real-Time Java on JOP 19
Schedule Events
Timer interruptHW interruptMonitorThread blockingSW Event
Real-Time Java on JOP 20
Interrupts
Hook for HW interruptsTimer interrupt results in scheduler callAccess to timer interruptGenerate interrupt for blockingSW Event is not part of the framework
Real-Time Java on JOP 21
Synchronization
Part of the languageEach object can be a monitorJVM instruction or method declaration
synchronized void foo() {
...
}
synchronized(o) {
...
}
Real-Time Java on JOP 22
Synchronization cont.
Called by framework:monitorEnter(Object o)monitorExit(Object o)
Attach user data to an object:attachData(Object obj, Object data)getAttachedData(Object obj)
Real-Time Java on JOP 23
Services for the Scheduler
DispatchTimeTimerInterrupts
Real-Time Java on JOP 24
Class Scheduler
Extended for a user-defined schedulerUser provides:
schedule()Monitor handling
Framework supplies:Software interrupt for blockingDispatch functionCurrent timeTimer interrupt
Real-Time Java on JOP 25
Class Task
Minimal (not j.l.Thread)Provides list of tasksScoped memoryUsually extended
Real-Time Java on JOP 26
A Simple Exampleclass Work extends Task {
private int c;
Work(int ch) {
c = ch;
}
public void run() {
for (;;) {
Dbg.wr(c); // debug output
int ts = Scheduler.getNow() + 3000;
while (ts-Scheduler.getNow()>0)
;
}
}
}
Real-Time Java on JOP 27
A Simple Example cont.public class RoundRobin extends Scheduler {
public void schedule() {
Task t = getRunningTask().getNext();
if (t==null) t = Task.getFirstTask();
dispatch(t, getNow()+10000);
}
public static void main(String[] args) {
new Work(‚a');
new Work(‚b');
RoundRobin rr = new RoundRobin();
rr.start();
}
}
Task 1 SchedulerTask 2 JVM Hardware
block genInt
set interrupt
interrupt
schedule
dispatch
switch
resume task
Schedulingdecision
Contextswitch
wFNP
interrupt
schedule
dispatch
Schedulingdecision
Contextswitch
timer
User-defined FrameworkApplication
resume task
set timer
set timer
switch
Real-Time Java on JOP 29
Summary
RTSJ is too complexSystem code in Java is possibleNo extra memory protection neededDispatch is 20% slower in frameworkMissing C++ friend in JavaJopVm in C
Real-Time Java on JOP 30
Garbage Collection?
An essential part of JavaWithout GC it is a different computing modelRTSJ does not believe in real-time GCReal-time collectors evolveActive research area
For You?
Real-Time Java on JOP 31
Further ReadingP. Puschner and A. J. Wellings. A Profile for High Integrity Real-Time Java Programs. In 4th IEEE International Symposium on Object-oriented Real-time distributed Computing (ISORC), 2001.M. Schoeberl, Design Rationale of a Processor Architecture for Predictable Real-Time Execution of Java Programs, In Proceedings of the 10th International Conference on Real-Time and Embedded Computing Systems and Applications (RTCSA), 2004.M. Schoeberl, Real-Time Scheduling on a Java Processor, In Proceedings of the 10th International Conference on Real-Time and Embedded Computing Systems and Applications (RTCSA), 2004.