250 likes | 402 Views
STARS. Scoped Types and Aspects for Realtime Systems. engineering infrastructure. demands. load. tides. wind. currents. raising/lowering capabilities?. multiple lanes?. features. a tower?. special materials?. engineering infrastructure. system infrastructure. code under pressure
E N D
STARS Scoped Types and Aspects for Realtime Systems
engineering infrastructure demands load tides wind currents raising/loweringcapabilities? multiple lanes? features a tower? special materials?
system infrastructure • code under pressure • needs to be both fast and flexible application-specific demands virtual machines platform-specific features
What happens to structure? • code under pressure • needs to be both fast and flexible application-specific demands virtual machines platform-specific features
Java Virtual Machine application specific demands platform specific features 2
Java Virtual Machine responsibility to structure RT mechanism falls on the application RT RTLinux Can STARS bring structure to RT mechanism to improve manageability of RT applications?
RTSJ memory regions • all scoped memory areas must follow a single parent rule to avoid cyclic parent relationships scope a parent • an outer scope may not hold a reference to an object within a more deeply nested inner scope scope b parent scope c • objects allocated within a scoped memory area can not be discarded until all threads in that area have terminated
RTSJ memory regions • all scoped memory areas must follow a single parent rule to avoid cyclic parent relationships scope a RT mechanisms getting in the way parent • an outer scope may not hold a reference to an object within a more deeply nested inner scope scope b • objects allocated within a scoped memory area can not be discarded until all threads in that area have terminated
Exceptions • AsynchronouslyInterruptedException: Generated when a thread is asynchronously interrupted. • DuplicateFilterException: PhysicalMemoryManager can only accomodate one filter object for each type of memory. It throws this exception if an attempt is made to register more than one filter for a type of memory. • InaccessibleAreaException: Thrown when an attempt is made to execute or allocate from an allocation context that is not accessible on the scope stack of the current thread. • MITViolationException: Thrown by the fire() method of an instance of Async-Event when the bound instance of AsyncEventHandler with a Release-Parameter type of SporadicParameters has mitViolationExcept behavior and the minimum interarrival time gets violated. • MemoryScopeException: Thrown by the wait-free queue implementation when an object is passed that is not compatible with both ends of the queue. • MemoryTypeConflictException: Thrown when the PhysicalMemoryManager is given conflicting specification for memory. The conflict can be between two types in an array of memory type specifiers, or when the specified base address does not fall in the requested memory type. • OffsetOutOfBoundsException: Generated by the physical memory classes when the given offset is out of bounds. • SizeOutOfBoundsException: Generated by the physical memory classes when the given size is out of bounds. • IllegalAssignmentError: Thrown on an attempt to make an illegal assignment. • MemoryAccessError: Thrown by the JVM when a thread attempts to access memory that is not in scope. • ResourceLimitError: Thrown if an attempt is made to exceed a system resource limit, such as the maximum number of locks. • ThrowBoundaryError: A throwable tried to propagate into a scope where it was not accessible. Errors • UnsupportedPhysicalMemoryException: Generated by the physical memory classes when the requested physical memory is unsupported. • MemoryInUseException: Thrown when an attempt is made to allocate a range of physical or virtual memory that is already in use. • ScopedCycleException: Thrown when a user tries to enter a ScopedMemory that is already accessible (ScopedMemory is present on stack) or when a user tries to create ScopedMemory cycle spanning threads (tries to make cycle in the VM ScopedMemory tree structure). • UnknownHappeningException: Thrown when bindTo() is called with an illegal happening. RuntimeExceptions left to developer to decipher…
RTSJ memory regions • all scoped memory areas must follow a single parent rule to avoid cyclic parent relationships scope a the right abstraction can help structure the mechanism… parent • an outer scope may not hold a reference to an object within a more deeply nested inner scope scope b • objects allocated within a scoped memory area can not be discarded until all threads in that area have terminated
heap memory plain java run-loop run condition terminate applicationinstructions
RTSJ run-loop create new memory scope(m) run create new application thread(a) condition terminate a.run in m applicationinstructions terminate inner memory scope outer memory scope
aspect aspect-oriented software development (AOSD)
RTSJ using AOSD… App around(Object o): call(void App.new()) && this (o) { App d = (AppLoop)proceed(o); d.memSpace = new LTMemory( SZ,SZ ); return d; } void around(Detector d): execution(void App.run()) && this (d) { (d.memSpace).enter( new Runnable() { public void run() { proceed(d); } });}
scoped types to clarify policy • provides the abstraction to help structure mechanism • clarifies policy • possible problems: • breaks existing abstractions? • conceals too much mechanism?
imm parent mem parent cdmem scoped types and packages scopea scopea.scopeb scopea.scopeb.scopec
scoped types and gates instance of a gate class scope a parent instance of a gate class scope b parent scope c
scoped types and gates instance of a gate class scope a parent instance of a gate class scope b
applying AOSD to gates Gate around(Object o): call(void Gate+.new()) && this (o) { Gate g = proceed(o); g.memSpace = new LTMemory( SZ,SZ ); return g; } public interface Gate { MemoryArea mem; } void around(final Gate g): execution(void Gate+.run()) && this (g) { (g.memSpace).enter( new Runnable() { public void run() {proceed(g); } });} declare parents: (type1||type2||…) implements Gate
tool supportstatic verification • set of rules established to coincide with RTSJ invariants • assume that a scoped package contains at least one gate class and zero or more scoped classes • statically verify rules • eliminates expensive, error prone dynamic verification
package imm; @scoped class Main { static void main() { new App().start(); } } package imm.mem; @gate final class App extends NoHeapRealtimeThread { void run() { Detector cd = new Detector(); StateTable state = new StateTable(); Aircraft key = new Aircraft(); while ( true ) cd.run( state, key); } } @scoped class StateTable ... @scoped class Aircraft ... @scoped class Position ... package imm.mem.cdmem; @gate final class Detector { void run(StateTable state, Aircraft key){ Frame frame = receiveFrame(); TmpAircraft plane = frame.getAircraft(); plane.update( key); Position pos_in_table = state.get( key); if ( pos_in_table == null ) state.put(plane.copy(), frame.getPosition().copy()); else frame.getPosition(). update(pos_in_table); } } @scoped class TmpAircraft ... @scoped class TmpPosition ... @scoped class Frame ... class App extends NoHeapRealtimeThread { staticvoid main() { imm = ImmortalMemory.instance(); app = (App) imm.newInstance( App.class); app.start(); } void run() { LTMemory mem = new LTMemory( ...); mem.enter( new Runner() ); } } class Runner implements Runnable { void run() { LTMemory cdmem = new LTMemory(...); Detector cd = new Detector( new StateTable() ); while ( true ) cdmem.enter( cd ); } } class Detector implements Runnable { StateTable state; … void run() { Frame frame = receiveFrame(); Position pos_in_table = state.get( frame.getAircraft()); if (pos_in_table == null) { mem = MemoryArea.getMemoryArea(this); Aircraft new plane = mem.newInstance( Aircraft.class); frame.getAircraft().update(new_plane); pos_in_table = mem.newInstance( Position.class); state.put( new_plane, pos_in_table); } pos_in_table.update( frame.getPosition()); } } class App extends NoHeapRealtimeThread { staticvoid main() { app.start(); } class Runner implements Runnable { void run() { Detector cd = new Detector( new StateTable() ); } } class Detector implements Runnable { StateTable state; … void run() { Frame frame = receiveFrame(); Position pos_in_table = state.get( frame.getAircraft()); if (pos_in_table == null) { Aircraft new plane = new Aircraft(); frame.getAircraft().update(new_plane); pos_in_table = new Position(); state.put( new_plane, pos_in_table); } pos_in_table.update( frame.getPosition()); } } void around (Object obj): execution ( void *.run() ) && this (obj) { if ( isGate (obj) ) new LTMemory(..).enter( new Runnable() { public void run() { proceed(); } }); } void around (Object obj): execution ( void *.run() ) && this (obj) { if ( isGate (obj) ) new LTMemory(..).enter( new Runnable() { public void run() { proceed(); } }); } raw RTSJ scoped types aspect summary
class App extends NoHeapRealtimeThread { staticvoid main() { imm = ImmortalMemory.instance(); app = (App) imm.newInstance( App.class); app.start(); } void run() { LTMemory mem = new LTMemory( ...); mem.enter( new Runner() ); } } class Runner implements Runnable { void run() { LTMemory cdmem = new LTMemory(...); Detector cd = new Detector( new StateTable() ); while ( true ) cdmem.enter( cd ); } } class Detector implements Runnable { StateTable state; … void run() { Frame frame = receiveFrame(); Position pos_in_table = state.get( frame.getAircraft()); if (pos_in_table == null) { mem = MemoryArea.getMemoryArea(this); Aircraft new plane = mem.newInstance( Aircraft.class); frame.getAircraft().update(new_plane); pos_in_table = mem.newInstance( Position.class); state.put( new_plane, pos_in_table); } pos_in_table.update( frame.getPosition()); } } class App extends NoHeapRealtimeThread { staticvoid main() { app.start(); } class Runner implements Runnable { void run() { Detector cd = new Detector( new StateTable() ); } } class Detector implements Runnable { StateTable state; … void run() { Frame frame = receiveFrame(); Position pos_in_table = state.get( frame.getAircraft()); if (pos_in_table == null) { Aircraft new plane = new Aircraft(); frame.getAircraft().update(new_plane); pos_in_table = new Position(); state.put( new_plane, pos_in_table); } pos_in_table.update( frame.getPosition()); } } void around (Object obj): execution ( void *.run() ) && this (obj) { if ( isGate (obj) ) new LTMemory(..).enter( new Runnable() { public void run() { proceed(); } }); } void around (Object obj): execution ( void *.run() ) && this (obj) { if ( isGate (obj) ) new LTMemory(..).enter( new Runnable() { public void run() { proceed(); } }); } raw RTSJ aspect summary
conclusions • require sophisticated mechanisms to support complex structure • AOSD provides linguistic support for software engineering principles • separation of concerns • modularity • STARS uses AOSD to achieve • separation of real-time mechanism from application code