real-time java threads insik shin real-time systems group university of pennsylvania

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

Post on 20-Dec-2015

216 views

Category:

Documents


0 download

TRANSCRIPT

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

Real-time Java Threads

Insik Shin

Real-time Systems GroupUniversity of Pennsylvania

Page 2: Real-time Java Threads Insik Shin Real-time Systems Group University of Pennsylvania

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

Page 3: Real-time Java Threads Insik Shin Real-time Systems Group University of Pennsylvania

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

Page 4: Real-time Java Threads Insik Shin Real-time Systems Group University of Pennsylvania

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

Page 5: Real-time Java Threads Insik Shin Real-time Systems Group University of Pennsylvania

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

Page 6: Real-time Java Threads Insik Shin Real-time Systems Group University of Pennsylvania

JAVATHREAD in KVM JAVATHREAD

COMMON_OBJECT_INFOlong priority current priority THREAD VMthread pointer to internal THREADINSTANCE target pointer to the object whose ‘run’

Page 7: Real-time Java Threads Insik Shin Real-time Systems Group University of Pennsylvania

THREAD in KVM THREAD

THREAD nextAliveThread active thread queueTHREAD nextThread all thread queueJAVATHREAD javathread java-level thread informatinSTACK stack execution stackBYTE* ipStore program counterFRAME fpStore frame pointerCell* spStore execution stack pointer

MONITOR monitor thread monitor queueTHREAD nextAlarmThread thread timer queueLong wakeupTime[2] wakeup timeVoid (*wakeupCall)(THREAD) callback when timer expires state thread state

Page 8: Real-time Java Threads Insik Shin Real-time Systems Group University of Pennsylvania

THREAD & JAVATHREAD in KVM THREAD & JAVATHREAD

JAVATHREAD javathread

THREAD VMthread

Page 9: Real-time Java Threads Insik Shin Real-time Systems Group University of Pennsylvania

Thread Queues in KVM

nextThread

nextAliveThread

monitor

nextAlarmThread

Page 10: Real-time Java Threads Insik Shin Real-time Systems Group University of Pennsylvania

Thread Queues in KVM

nextThread

nextAliveThread

monitor

nextAlarmThread

CurrentThread RunnableThreads

Page 11: Real-time Java Threads Insik Shin Real-time Systems Group University of Pennsylvania

Thread Context Switching in KVM

IP, FP, SP

VM RegistersCurrentThread

1. store execution environment

Page 12: Real-time Java Threads Insik Shin Real-time Systems Group University of Pennsylvania

Thread Context Switching in KVM

IP, FP, SP

VM Registers

1. store execution environment

CurrentThread

2. Pick a thread from ‘RunnableThreads’ queue

Page 13: Real-time Java Threads Insik Shin Real-time Systems Group University of Pennsylvania

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

Page 14: Real-time Java Threads Insik Shin Real-time Systems Group University of Pennsylvania

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

Page 15: Real-time Java Threads Insik Shin Real-time Systems Group University of Pennsylvania

Thread Scheduling in KVM Scheduling policy

Round-robin with the following quantum: quantum = 500 * priority

Scheduler data structure THREAD CurrentThread THREAD RunnableThreads

Page 16: Real-time Java Threads Insik Shin Real-time Systems Group University of Pennsylvania

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

Page 17: Real-time Java Threads Insik Shin Real-time Systems Group University of Pennsylvania

Java API & KVMThread.java public native void start();

KVM : nativeCore.c

Java_java_lang_Thread_start() {… startThread();…

}

KVM : thread.c

startThread() { …}

Page 18: Real-time Java Threads Insik Shin Real-time Systems Group University of Pennsylvania

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?

Page 19: Real-time Java Threads Insik Shin Real-time Systems Group University of Pennsylvania

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

Page 20: Real-time Java Threads Insik Shin Real-time Systems Group University of Pennsylvania

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

Page 21: Real-time Java Threads Insik Shin Real-time Systems Group University of Pennsylvania

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’

Page 22: Real-time Java Threads Insik Shin Real-time Systems Group University of Pennsylvania

Real-time Thread Structure RT_JAVATHREAD extends JAVATHREAD

JAVATHREADSchedulingParameter spReleaseParameter rpMemoryParameter mpProcessingGroupParameter pgpScheduler sch

COMMON_OBJECT_INFOlong priorityTHREAD VMthread INSTANCE target

Page 23: Real-time Java Threads Insik Shin Real-time Systems Group University of Pennsylvania

THREAD in KVM

THREAD nextAliveThread active thread queueTHREAD nextThread all thread queueJAVATHREAD javathread java-level thread informatinSTACK stack execution stackBYTE* ipStore program counterFRAME fpStore frame pointerCell* spStore execution stack pointer

MONITOR monitor thread monitor queueTHREAD nextAlarmThread thread timer queueLong wakeupTime[2] wakeup timeVoid (*wakeupCall)(THREAD) callback when timer expires state thread state

Page 24: Real-time Java Threads Insik Shin Real-time Systems Group University of Pennsylvania

THREAD in KVM

THREAD nextAliveThread active thread queueTHREAD nextThread all thread queueJAVATHREAD javathread java-level thread informatinSTACK stack execution stackBYTE* ipStore program counterFRAME fpStore frame pointerCell* spStore execution stack pointer

MONITOR monitor thread monitor queueTHREAD nextAlarmThread thread timer queueLong wakeupTime[2] wakeup timeVoid (*wakeupCall)(THREAD) callback when timer expires state thread state

bool_t realtime

Page 25: Real-time Java Threads Insik Shin Real-time Systems Group University of Pennsylvania

Thread Structures for Real-time Java

realtime = false realtime = true

non-realtime thread realtime thread

Page 26: Real-time Java Threads Insik Shin Real-time Systems Group University of Pennsylvania

Real-time Thread Supports We can use the same mechanisms as in

KVM for the followings: thread queue managements context switching

Page 27: Real-time Java Threads Insik Shin Real-time Systems Group University of Pennsylvania

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

Page 28: Real-time Java Threads Insik Shin Real-time Systems Group University of Pennsylvania

Two-level Scheduling

Meta-level scheduler

Priority scheduler

Round-robinscheduler

EDF scheduler

Page 29: Real-time Java Threads Insik Shin Real-time Systems Group University of Pennsylvania

Thread Scheduling in KVM Scheduling policy

Round-robin with the following quantum: quantum = 500 * priority

Scheduler data structure THREAD CurrentThread THREAD RunnableThreads

Page 30: Real-time Java Threads Insik Shin Real-time Systems Group University of Pennsylvania

Real-time Thread Scheduling Scheduling policy

Meta-level scheduling policy (priority) Scheduler data structure

SCHEDULER

THREAD CurrentThreadTHREAD RunnableThreads

Page 31: Real-time Java Threads Insik Shin Real-time Systems Group University of Pennsylvania

Java API & KVMThread.java public native void start();

KVM : nativeCore.c

Java_java_lang_Thread_start() {… startThread();…

}

KVM : thread.c

startThread() { …}

Page 32: Real-time Java Threads Insik Shin Real-time Systems Group University of Pennsylvania

Real-time Java API & KVMRealtimeThread.java public native void start();

KVM : nativeCore.c

Java_javax_rtgedition_RealtimeThread_start() {… startThread();…

}

KVM : thread.c

startThread() { …}

Page 33: Real-time Java Threads Insik Shin Real-time Systems Group University of Pennsylvania
Page 34: Real-time Java Threads Insik Shin Real-time Systems Group University of Pennsylvania