Real-time Java Threads Insik Shin Real-time Systems Group University of Pennsylvania.
-
date post
20-Dec-2015 -
Category
Documents
-
view
213 -
download
0
Transcript of Real-time Java Threads Insik Shin Real-time Systems Group University of Pennsylvania.
![Page 1: Real-time Java Threads Insik Shin Real-time Systems Group University of Pennsylvania.](https://reader030.fdocuments.in/reader030/viewer/2022032800/56649d4b5503460f94a29278/html5/thumbnails/1.jpg)
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.](https://reader030.fdocuments.in/reader030/viewer/2022032800/56649d4b5503460f94a29278/html5/thumbnails/2.jpg)
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.](https://reader030.fdocuments.in/reader030/viewer/2022032800/56649d4b5503460f94a29278/html5/thumbnails/3.jpg)
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.](https://reader030.fdocuments.in/reader030/viewer/2022032800/56649d4b5503460f94a29278/html5/thumbnails/4.jpg)
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.](https://reader030.fdocuments.in/reader030/viewer/2022032800/56649d4b5503460f94a29278/html5/thumbnails/5.jpg)
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.](https://reader030.fdocuments.in/reader030/viewer/2022032800/56649d4b5503460f94a29278/html5/thumbnails/6.jpg)
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.](https://reader030.fdocuments.in/reader030/viewer/2022032800/56649d4b5503460f94a29278/html5/thumbnails/7.jpg)
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.](https://reader030.fdocuments.in/reader030/viewer/2022032800/56649d4b5503460f94a29278/html5/thumbnails/8.jpg)
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.](https://reader030.fdocuments.in/reader030/viewer/2022032800/56649d4b5503460f94a29278/html5/thumbnails/9.jpg)
Thread Queues in KVM
nextThread
nextAliveThread
monitor
nextAlarmThread
![Page 10: Real-time Java Threads Insik Shin Real-time Systems Group University of Pennsylvania.](https://reader030.fdocuments.in/reader030/viewer/2022032800/56649d4b5503460f94a29278/html5/thumbnails/10.jpg)
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.](https://reader030.fdocuments.in/reader030/viewer/2022032800/56649d4b5503460f94a29278/html5/thumbnails/11.jpg)
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.](https://reader030.fdocuments.in/reader030/viewer/2022032800/56649d4b5503460f94a29278/html5/thumbnails/12.jpg)
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.](https://reader030.fdocuments.in/reader030/viewer/2022032800/56649d4b5503460f94a29278/html5/thumbnails/13.jpg)
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.](https://reader030.fdocuments.in/reader030/viewer/2022032800/56649d4b5503460f94a29278/html5/thumbnails/14.jpg)
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.](https://reader030.fdocuments.in/reader030/viewer/2022032800/56649d4b5503460f94a29278/html5/thumbnails/15.jpg)
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.](https://reader030.fdocuments.in/reader030/viewer/2022032800/56649d4b5503460f94a29278/html5/thumbnails/16.jpg)
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.](https://reader030.fdocuments.in/reader030/viewer/2022032800/56649d4b5503460f94a29278/html5/thumbnails/17.jpg)
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.](https://reader030.fdocuments.in/reader030/viewer/2022032800/56649d4b5503460f94a29278/html5/thumbnails/18.jpg)
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.](https://reader030.fdocuments.in/reader030/viewer/2022032800/56649d4b5503460f94a29278/html5/thumbnails/19.jpg)
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.](https://reader030.fdocuments.in/reader030/viewer/2022032800/56649d4b5503460f94a29278/html5/thumbnails/20.jpg)
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.](https://reader030.fdocuments.in/reader030/viewer/2022032800/56649d4b5503460f94a29278/html5/thumbnails/21.jpg)
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.](https://reader030.fdocuments.in/reader030/viewer/2022032800/56649d4b5503460f94a29278/html5/thumbnails/22.jpg)
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.](https://reader030.fdocuments.in/reader030/viewer/2022032800/56649d4b5503460f94a29278/html5/thumbnails/23.jpg)
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.](https://reader030.fdocuments.in/reader030/viewer/2022032800/56649d4b5503460f94a29278/html5/thumbnails/24.jpg)
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.](https://reader030.fdocuments.in/reader030/viewer/2022032800/56649d4b5503460f94a29278/html5/thumbnails/25.jpg)
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.](https://reader030.fdocuments.in/reader030/viewer/2022032800/56649d4b5503460f94a29278/html5/thumbnails/26.jpg)
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.](https://reader030.fdocuments.in/reader030/viewer/2022032800/56649d4b5503460f94a29278/html5/thumbnails/27.jpg)
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.](https://reader030.fdocuments.in/reader030/viewer/2022032800/56649d4b5503460f94a29278/html5/thumbnails/28.jpg)
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.](https://reader030.fdocuments.in/reader030/viewer/2022032800/56649d4b5503460f94a29278/html5/thumbnails/29.jpg)
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.](https://reader030.fdocuments.in/reader030/viewer/2022032800/56649d4b5503460f94a29278/html5/thumbnails/30.jpg)
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.](https://reader030.fdocuments.in/reader030/viewer/2022032800/56649d4b5503460f94a29278/html5/thumbnails/31.jpg)
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.](https://reader030.fdocuments.in/reader030/viewer/2022032800/56649d4b5503460f94a29278/html5/thumbnails/32.jpg)
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.](https://reader030.fdocuments.in/reader030/viewer/2022032800/56649d4b5503460f94a29278/html5/thumbnails/33.jpg)
![Page 34: Real-time Java Threads Insik Shin Real-time Systems Group University of Pennsylvania.](https://reader030.fdocuments.in/reader030/viewer/2022032800/56649d4b5503460f94a29278/html5/thumbnails/34.jpg)