Escolar Documentos
Profissional Documentos
Cultura Documentos
RAM Size
CPU
2 4 MB
< 512 MB
16/32 Bit, 25 MHz+
Real-time Java
(A brief intro)
RTSJ Implementations
RTSJ is still under evaluation. Sun has no practical implementation. Some implementations by others: - VisualAge by IBM - Simple RTJ by RTJ Computing Theres another spec by J-consortium backed by Microsoft, HP. Other just sit on the fence.
Asynchrony
Asynchrony
Asynchronous event handling and transfer of control in execution. Not all real-life events are predictable in time and frequency. Ability of real-time systems to react to them correctly requires reliable asynchrony techniques.
Asynchrony (contd.)
Conventional ways of achieving it in Java is by interrupts and exceptions. They are deadlock prone. Can cause data structure corruption.
Asynchrony (contd.)
Leaving exiting techniques intact for conventional codes, RTSJ offers two extended approaches for real-time threads1. Asynchronous Events (AEv). 2. Asynchronously Interrupted Exceptions (AIE).
I. Asynchronous Events
Some internal or external event that happens. System need to respond to the changing environment. Not known in advance about time or frequency.
Class Hierarchy
Object AsyncEvent
AsyncEventHandler behave like Thread. It has run() method. BoundAsynchronousHandler can be used for added timeliness by binding each handler to a dedicated thread.
AsyncEventHandler
BoundAsyncEventHandler
Event3
Handler A
Handler B
AsyncEvent
addHandler()
run() // final
handleAsyncEvent() getAndDecrementPendingFireCount()
AIE (AsynchronouslyInterruptedException)
Object
Throwable
Exception
Interruptible (I) InterruptedException
AsynchronouslyInterruptedException
Timed
AIE (contd.)
In RT Java, ATC is achieved by throwing a special exception AIE. RT threads and methods can choose to receive (or not to) AIE by including it in throws clause. e.g. void run() throws asynchronouslyInterruptedException {} Existing Non-RT implementations are not affected.
AIE (contd.)
AIE can be thrown to cut short a threads execution and take appropriate action. It can be thrown explicitly by firing in program codes, or implicitly by interrupting a real-time thread. e.g. aie.fire() or thread.interrupt() If AIE is fired in a methods it did not declare AIE in throws clause, AIE is put to pending state until control reaches AIE-enabled method.
AIE Handler should invoke the AIE.happened() method to clear it. Otherwise, it will continue to propagate outward.
Sample Implementation
Single Elevator Control system. Separate classes for:
Carriage (floor pos, door open?, moving?) MotorControl (up, down) PanelControl (buttons pressed,next dest)
Elevator (contd.)
Events;
A floor select button is pressed. Elevator request button is pressed. Fire alarm sounded. Hazard (fire, blackout, etc.).
Exceptions;
AsyncEvent classes
class ButtonEvent extends AsyncEvent{ public ButtonEvent(String bindstring){ bindTo(bindstring); } } class FireAlarm extends AsyncEvent{ public FireAlarm(){ super(); bindTo("FireSignal"); } }
AIE exception
class HazardAie extends synchronouslyInterruptedException{ public HazardAie(){super();} } HazardAie myAie= new HazardAie(); Carriage car=new Carriage(fa,myAie); Somebody has to fire it. So pass to Carriage that receive the fire event
AIE handling
public class MotorControl implements Interruptible{ . // action when AIE is fired. public void interruptAction(AsynchronouslyInterruptedException e){ if (carriage.getFloor()>0){ carriage.closeDoor(); godown(); } }
MotorControl (contd.)
// action when interruptible code is run public void run(AsynchronouslyInterruptedException e){ while(true){ try{myrun(e);} catch(AsynchronouslyInterruptedException e1){} }// while } void myrun(AsynchronouslyInterruptedException e) throws AsynchronouslyInterruptedException { // normal control sequence }
Memory Management
Purpose
To allow memory areas of different behavior to be accessed by real-time tasks. Specify memory consumption behavior of RT tasks. RT tasks can enter and exit memory areas and allocate objects as needed.
Heap Memory (normal Java Heap) Scoped Memory (limited lifetime.) Immortal Memory (app lifetime) ImmortalPhysicalMemory (app lifetime, physical)
PhysicalMemoryFactory (Supply physical mem to other mem objects, e.g. DMA, Byte swapping) RawMemoryAccess (Drivers, Memory mapped I/O)
ImmortalPhysicalMemory
Can never be stored in an object in Java Heap. Can never be stored in an object in ImmortalMemory. Can be stored in an object in the same scope or inner scope memory.
ScopeMemory activation
An area of ScopeMemory can become active for a thread by;
ScopeMemory areas can be activated in nested manner. Objects in an inner scope can refer to outer scopes, but not the other way.
Conclusion
Java is trying to become real-time capable. Most systems today are either non real-time or implement only a subset of RTSJ. We expect to see more complete and robust implementations soon with increasingly popular embedded and real-time systems.