Presentation is loading. Please wait.

Presentation is loading. Please wait.

Real-time Java Threads Insik Shin Real-time Systems Group University of Pennsylvania.

Similar presentations


Presentation on theme: "Real-time Java Threads Insik Shin Real-time Systems Group University of Pennsylvania."— Presentation transcript:

1 Real-time Java Threads Insik Shin Real-time Systems Group University of Pennsylvania

2 KVM Threading System  What kind of information for a thread? data structures  How to maintain such information?  How to support multi-threading? scheduling policy context switching mechanism  Additional features for supporting threads? timer, monitor

3 Thread Information  pointer to ‘run’ method  priority  virtual machine execution stack  virtual machine registers (ip, fp, sp)  timer & monitor  state (active | wait)  thread queues: active, wait, timer, monitor

4 Thread Information in KVM  pointer to ‘run’ method  priority  virtual machine execution stack  virtual machine registers (ip, fp, sp)  timer & monitor  state (active | wait)  thread queues: active, wait, timer, monitor Java-level thread information implementation-level thread information

5 Data Structures in KVM  Two separate structures THREAD  internal (VM-level) structure  information for implementing threading system JAVATHREAD  information defined in Java class ‘Thread.java’ Advantages  JAVATHREAD needs to be subclassed  Implementation independent of the Java language for portability & extension reasons

6 JAVATHREAD in KVM  JAVATHREAD COMMON_OBJECT_INFO long priority current priority THREAD VMthread pointer to internal THREAD INSTANCE target pointer to the object whose ‘run’

7 THREAD in KVM  THREAD THREAD nextAliveThread active thread queue THREAD nextThread all thread queue JAVATHREAD javathread java-level thread informatin STACK stack execution stack BYTE* ipStore program counter FRAME fpStore frame pointer Cell* spStore execution stack pointer MONITOR monitor thread monitor queue THREAD nextAlarmThread thread timer queue Long wakeupTime[2] wakeup time Void (*wakeupCall)(THREAD) callback when timer expires state thread state

8 THREAD & JAVATHREAD in KVM  THREAD & JAVATHREAD JAVATHREAD javathreadTHREAD VMthread

9 Thread Queues in KVM nextThread nextAliveThread monitor nextAlarmThread

10 Thread Queues in KVM nextThread nextAliveThread monitor nextAlarmThread CurrentThread RunnableThreads

11 Thread Context Switching in KVM IP, FP, SP VM Registers CurrentThread 1.store execution environment

12 Thread Context Switching in KVM IP, FP, SP VM Registers 1.store execution environment CurrentThread 2. Pick a thread from ‘RunnableThreads’ queue

13 Thread Context Switching in KVM IP, FP, SP VM Registers 1.store execution environment CurrentThread 2. Pick a thread from ‘RunnableThreads’ queue 3. Put the old thread into ‘RunnableThreads’ queue

14 Thread Context Switching in KVM IP, FP, SP VM Registers 1.store execution environment CurrentThread 2. Pick a thread from ‘RunnableThreads’ queue 4. load execution environment 3. Put the old thread into ‘RunnableThreads’ queue

15 Thread Scheduling in KVM  Scheduling policy Round-robin with the following quantum: quantum = 500 * priority  Scheduler data structure THREAD CurrentThread THREAD RunnableThreads

16 Thread operations in KVM  Constructors & deconstructors BuildThread, DismantleThread  Thread activation & deactivation initThreadBehavior, startThread, stopThread, suspendThread, resumeThread, removeFirstRunnableThread  Multitasking operations switchThread storeExecutionEnvironment, loadExecutionEnvironment  Timer, Queue, Monitor operations

17 Java API & KVM Thread.java public native void start(); KVM : nativeCore.c Java_java_lang_Thread_start() { … startThread(); … } KVM : thread.c startThread() { … }

18 Real-time Thread Scheduling  What kind of features to be added? Real-time thread information Real-time (priority) scheduler Synchronization (monitor) Timer, Asynchrony  How to extend KVM for real-time threads?

19 Real-time Thread Information  Scheduling parameters priority, importance  Release parameters cost, deadline, overrunHandler, missHandler start, period, minInterarrival  Memory parameters maxMemoryArea, maxImmortal  Processing group parameters  Scheduler

20 Data Structures in KVM  Two separate structures THREAD  internal (VM-level) structure  information for implementing threading system JAVATHREAD  information defined in Java class ‘Thread.java’ Advantages  JAVATHREAD needs to be subclassed  Implementation independent of the Java language for portability & extension reasons

21 Real-time Thread Structure  Two separate structures THREAD  internal (VM-level) structure  information for implementing threading system JAVATHREAD  information defined in Java class ‘Thread.java’ RT_JAVATHREAD  information defined in Java class ‘RealtimeThread.java’

22 Real-time Thread Structure  RT_JAVATHREAD extends JAVATHREAD JAVATHREAD SchedulingParameter sp ReleaseParameter rp MemoryParameter mp ProcessingGroupParameter pgp Scheduler sch COMMON_OBJECT_INFO long priority THREAD VMthread INSTANCE target

23 THREAD in KVM THREAD nextAliveThread active thread queue THREAD nextThread all thread queue JAVATHREAD javathread java-level thread informatin STACK stack execution stack BYTE* ipStore program counter FRAME fpStore frame pointer Cell* spStore execution stack pointer MONITOR monitor thread monitor queue THREAD nextAlarmThread thread timer queue Long wakeupTime[2] wakeup time Void (*wakeupCall)(THREAD) callback when timer expires state thread state

24 THREAD in KVM THREAD nextAliveThread active thread queue THREAD nextThread all thread queue JAVATHREAD javathread java-level thread informatin STACK stack execution stack BYTE* ipStore program counter FRAME fpStore frame pointer Cell* spStore execution stack pointer MONITOR monitor thread monitor queue THREAD nextAlarmThread thread timer queue Long wakeupTime[2] wakeup time Void (*wakeupCall)(THREAD) callback when timer expires state thread state bool_t realtime

25 Thread Structures for Real-time Java realtime = falserealtime = true non-realtime thread realtime thread

26 Real-time Thread Supports  We can use the same mechanisms as in KVM for the followings: thread queue managements context switching

27 Real-time Thread Scheduler  RTSJ suggests PriorityScheduler for RTJ  Each RT thread can be associated with any scheduler multiple schedulers at the same time Two-level scheduling

28 Two-level Scheduling Meta-level scheduler Priority scheduler Round-robin scheduler EDF scheduler

29 Thread Scheduling in KVM  Scheduling policy Round-robin with the following quantum: quantum = 500 * priority  Scheduler data structure THREAD CurrentThread THREAD RunnableThreads

30 Real-time Thread Scheduling  Scheduling policy Meta-level scheduling policy (priority)  Scheduler data structure SCHEDULER THREAD CurrentThread THREAD RunnableThreads

31 Java API & KVM Thread.java public native void start(); KVM : nativeCore.c Java_java_lang_Thread_start() { … startThread(); … } KVM : thread.c startThread() { … }

32 Real-time Java API & KVM RealtimeThread.java public native void start(); KVM : nativeCore.c Java_javax_rtgedition_RealtimeThread_start() { … startThread(); … } KVM : thread.c startThread() { … }

33

34


Download ppt "Real-time Java Threads Insik Shin Real-time Systems Group University of Pennsylvania."

Similar presentations


Ads by Google