real-time java martin schöberl. real time java2 overview what are real-time systems real-time...

Download Real-Time Java Martin Schöberl. Real Time Java2 Overview What are real-time systems Real-time specification for Java RTSJ issues, subset Real-time profile

Post on 29-Dec-2015




1 download

Embed Size (px)


  • Real-Time JavaMartin Schberl

  • OverviewWhat are real-time systemsReal-time specification for JavaRTSJ issues, subsetReal-time profileOpen question - GC

  • History of (Real-Time) Java1996 Nilsen: First Paper on Real-Time Java1997 picoJava, PersonalJava1992 Oak for *71995 Java for the Internet1998 EmbeddedJava, RTSJ Start2003 JTime2000 J2EE: Server Applications2002 RTSJ Final Release2000 J2ME: Java for Mobile PhonesJava for Desktop ApplicationsEmbedded Systems?

  • Real-Time SystemsA definition by John A. Stankovic:In real-time computing the correctness of the system depends not only on the logical result of the computation but also on the time at which the result is produced.

  • Real-Time ThreadsIn real-time systems there are:Periodic threadsEvent threads/handlerNo continuous running threadsFixed Priority driven schedulerThreads can starve!

  • PriorityKind of importanceScheduling theory:Shorter periods higher prioritiesRMA: Rate Monotonic AnalysisAssignment is optimalIn (hard) RT forbiddensleep()wait(), notify()

  • Real-Time Specification for JavaRTSJ for shortFirst JSR requestStill not completely finishedImplementationsTimesys RIPurdue OVM

  • RTSJ Guiding PrinciplesBackward compatibility to standard JavaWrite Once, Run AnywhereCurrent real-time practicePredictable executionNo Syntactic extensionAllow implementation flexibility

  • RTSJ OverviewClear definition of schedulerPriority inheritance protocolNoHeapRealtimeThreadScoped memory to avoid GCLow-level access through raw memoryHigh resolution time and timer

  • RTSJ: SchedulingStandard Java offers no guaranteeEven non preemptive JVM possibleFixed priorityFIFO within prioritiesMinimum of 28 unique priority levelsGC priority level not defined

  • RTSJ: Memory AreasGC collected HeapImmortal memoryScoped memoryLTMemoryVTMemoryPhysical memoryDifferent time propertiesAccess to HW devices!

  • RTSJ: Thread TypesExtensions to java.lang.ThreadRealTimeThreadNoHeapRealTimeThreadAsyncEventHandlerScoped and immortal memory for NHRTTStrict assignment rulesNot easy to use

  • RTSJ: SynchronizationUse synchronizedPriority inversion possible in standard JavaPriority inheritance protocolPriority ceiling emulation protocol

  • RTSJ: Scoped MemoryCumbersome programming styleNew class for each code part

    class UseMem implements Runnable {

    public void run() { // inside scoped memory Integer[] = new Integer[100]; ... }}

    // outside of scoped memory// in immortal? at initialization?

    LTMemory mem = new LTMemory(1024, 1024);UseMem um = new UseMem();

    // usagecomputation() {


  • Asynchronous Event HandlerDifference between bound an unboundImplementation hint at application levelNo functional difference for the applicationBetter: only one typeSpecify a minimum latency at creationRuntime system decides about implementation

  • RTSJ IssuesJ2SE library:Heap usage not documentedOS functions can cause blockingOn small systems:Large and complex specificationExpensive longs (64 bit) for time values

  • RTSJ SubsetRavenscar JavaName from Ravenscar AdaBased in Puschner & Wellings paperProfile for high integrity applicationsRTSJ compatibleNo dynamic thread creationOnly NHRTTSimplified scoped memoryImplementation?

  • Real-Time ProfileHard real-time profileSee Puschner paperEasy to implementLow runtime overheadNo RTSJ compatibility

  • Real-Time ProfileSchedulable objects:Periodic activitiesAsynchronous sporadic activitiesHardware interrupt or software eventBound to a threadApplication:InitializationMission

  • Application StructureInitialization phaseFixed number of threadsThread creationShared objects in immortal memoryMissionRuns foreverCommunication via shared objectsScoped memory for temporary data

  • Schedulable ObjectsThree types:RtThread, HwEvent and SwEventFixed priorityPeriod or minimum interarrival timeScoped memory per threadDispatched after mission startpublic 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()}

  • SchedulingFixed priority with strict monotonic orderPriority ceiling emulation protocolTop priority for unassigned objectsInterrupts under scheduler controlPriority for device driversNo additional blocking timeIntegration in schedulability analysis

  • MemoryNo GC: Heap becomes immortal memoryScoped memoryBound to one thread at creationConstant allocation timeCleared on creation and on exitSimple enter/exit syntax

  • Restrictions of JavaOnly WCET analyzable language constructsNo static class initializerUse a static init() functionNo finalizationObjects in immortal memory live foreverFinalization complicates WCET analysis of exit from scoped memoryNo dynamic class loading

  • RtThread Examplepublic class Worker extends RtThread {

    private SwEvent event;

    public Worker(int p, int t, SwEvent ev) {

    super(p, t, // create a scoped // memory area new Memory(10000) ); event = ev; init(); }

    private void init() { // all initialzation stuff // has to be placed here } public void run() {

    for (;;) { work(); // do work; // and fire // an event

    // some work in // scoped memory enterMemory(); workWithMem(); exitMemory();

    // wait for next period if (!waitForNextPeriod()) { missedDeadline(); } } // should never reach // this point }}

  • Application Start // create an Event Handler h = new Handler(3, 1000);

    // create two worker threads with // priorities according to their periods FastWorker fw = new FastWorker(2, 2000); Worker w = new Worker(1, 10000, h);

    // change to mission phase for all // periodic threads and event handler RtThread.startMission();

    // do some non real-time work // and invoke sleep() or yield() for (;;) { watchdogBlink(); Thread.sleep(500); }

  • 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 areaFor You?

  • SummaryReal-time Java is emergingRTSJ defined by SunSubsets: RJ, JOP-RTReal-time GC missing


View more >