Transcript mission

Predictable Java
• Overview
• Implementations
• Next steps
Java Objekt 2, 19 August 2009
Anders P. Ravn and Hans Søndergaard
1
A Real-Time Application
• Periodic Event Handlers
• Aperiodic Event Handlers
collected in a mission
• Mission Handler
Each handler
has a Memory
is Scheduled
2
Periodic handler
class Periodic extends PeriodicEventHandler
{
protected Periodic(.., PeriodicParameters pp,
Scheduler scheduler,
MemoryArea memory);
public void handleEvent() {
// the logic to be executed every period
}
}
3
Aperiodic handler
class Aperiodic extends AperiodicEventHandler
{
protected Aperiodic(.., AperiodicParameters ap,
Scheduler scheduler,
MemoryArea memory);
public void handleEvent() {
// the logic to be executed when an event occurs
}
}
4
A simple mission
public class Basic extends Mission
{
protected Basic(.., AperiodicParameters ap,
Scheduler scheduler,
MemoryArea memoryArea)
{
... // initialization
}
public static void main (String[] args) {
new Basic( null, null,
new CyclicScheduler(),
new LTMemory(10*1024));
}
}
5
…The mission
addToMission(
new Periodic( null, pp, getScheduler(),
new LTMemory(1024)));
addToMission(
new Periodic( null, pp, getScheduler(),
new LTMemory(1024)));
...
add(); // mission to its scheduler
6
Complex mission
private Mission[] mission;
private int active = 0;
static AperiodicEvent event;
public ThreeSequentialMissions(...) {
mission = new Mission[3];
// set up the three missions
mission[0] = new Mission(...);
// add handlers for mission 0
// including the mission termination
...
mission[1] = new Mission();
...
// start the first mission
mission[active].add();
event = new AperiodicEvent(this);
}
7
Changing mission
private Mission[] mission;
private int active = 0;
static AperiodicEvent event;
public ThreeSequentialMissions(...) {
...
}
public void handleEvent() {
mission[active].remove();
active = (active + 1) % mission.length;
mission[active].add();
}
8
Level 0
• only Periodic Event Handlers
• cyclic scheduler
9
Level 1
SO 3 has the
highest priority
• periodic and aperiodic event handlers
• fixed-priority preemptive scheduler
10
Implementations
• On top of RTSJ (adapter)
• Native implementation using
– JamVM
– Xenomai/Linux
– Mechatronic Brick
11
Schedulers
• Cyclic scheduler
– Only one mission, with periodic handlers
– Using cyclic executive model
– The Scheduler: a periodic RT_TASK
• period = gcd of all the handler periods
• Fixed priority pre-emptive scheduler
– Missions with periodic and aperiodic handlers
– Implemented as RT_TASKs
12
Memory
• No GC
• Two types of memory
– Immortal memory = Heap (without GC)
• Lifetime = lifetime of the application
– Scoped memory
• Each handler has its own private memory
• Lifetime = lifetime of the handler
• Object allocation rewritten in JamVM
13
Synchronization
• Java’s locking model (synchronization)
– does not fit to avoid priority inversion
• Xenomai's MUTEX enforce priority inheritance
• Rewritten JamVM
– synchronized methods in classes for shared objects:
• uses MUTEX lock/unlock
14
Next steps: Workbench
15
Next steps
•
•
•
•
•
Eclipse plugins
Homepage for Predictable Java
Different tools for static analysis
Examples
...
16
References
• A predictable Java profile - rationale and implementations
Thomas Bøgholm, René R. Hansen, Anders P. Ravn, Bent Thomsen,
and Hans Søndergaard
JTRES’09. 23-25 September 2009.
• Safety-Critical Java
JSR 302: Safety Critical Java Technology
http://jcp.org/en/jsr/detail?id=302
• Java for Safety-Critical Applications
Thomas Henties, James J. Hunt, Doug Locke, Kelvin Nilsen, Martin
Schoeberl, Jan Vitek.
SafeSert 2009.
• Safety Critical Specification for Java
Version 0.5. August 2008. Draft.
17
Periodic event handler execution
Periodic Rt_task:
for (;;) {
JNI-callback-to-scheduler-dispatch(handlerNo)
rt_task_wait_period(NULL);
}
class PriorityScheduler extends Scheduler {
create Native handlers, start them, etc.
..
void dispatch(int handlerNo) {
EventHandler evh = getEvh(handlerNo);
evh.getMemoryArea().enter(evh);
}
}
public abstract class MemoryArea {
long memSize;
int memID; // a reference to the MEM_AREA
public void enter (Runnable logic) {
Native.enterNativeMemArea (memID);
logic.run();
Native.leaveNativeMemArea (memID);
}
...
}
abstract class PeriodicEventHandler {
..
public final void run() {
handleEvent(); // abstract method
}
}
class MyPeriodicEvH extends PeriodicEventHandler {
..
public void handleEvent() {
// the logic to be executed every period
}
}
18
Xenomai Architecture
 Xenomai runs on top of the Linux kernel and handles all incoming interrupts first, before the Linux kernel
 Adeos (Adaptive Domain Environment for Operating Systems)
 a nanokernel hardware abstraction layer (HAL)
 operates between computer hardware and the operating system
 Xenomai has some skins
 Native, POSIX, etc.
19
Native Xenomai API
• RT services for
– RT_TASKs
•
•
•
•
rt_task_create, rt_task_start, rt_task_set_priority
rt_task_set_periodic, rt_task_wait_period
rt_task_suspend, rt_task_resume
..
– RT_EVENTs
– RT_INTERRUPTs
– RT_MUTEXs
20