• No results found

Realtime Java. Christoph Neijenhuis

N/A
N/A
Protected

Academic year: 2021

Share "Realtime Java. Christoph Neijenhuis"

Copied!
20
0
0

Loading.... (view fulltext now)

Full text

(1)

Realtime Java

(2)

2

Agenda

■ RT Problems in Java

■ Solutions: RTSJ and others

■ Guiding Principles

■ Memory Management

■ Threads

■ Asynchronous Event Handling

■ Scheduling

■ Time

(3)

Realtime Java | Christoph Neijenhuis | 4. Juni 2010

3

Problems in Java

■ Garbage collection can occur at any time

■ VM is optimized for through put

□ Lazy initialization, e.g. for class loading

□ Compilation of code at run-time

■ VM doesn't cooperate with realtime OS

■ Threads can not be scheduled or prioritized reliably

■ APIs are not tailored for real-time scenarios

(4)

4

Solutions

■ Real Time Specification for Java

□ Defined as JSR 1

□ Released in 2002

□ Reference implementation from TimeSys

□ Commercial implementations from Sun and IBM

■ Other proprietary solutions exists

□ Support only a subset of standard Java

□ Tailored for embedded systems with limited memory

□ E.g. PERC Pico from aionix

(5)

Realtime Java | Christoph Neijenhuis | 4. Juni 2010

5

Guiding principles

■ No syntactic extension

■ Backward compatibility

■ Applicability to particular Java environments

■ Current practice and advanced features

(6)

6

Memory Management

■ Additional memory areas that are not garbage collected

■ Immortal memory

□ Objects exist until end of application

■ Scoped memory

□ Exists for a limited lifetime

□ Reference counting, finalization when it reaches 0

□ Scopes can be nested

□ No references into scope from heap or immortal memory

■ Physical memory

(7)

Realtime Java | Christoph Neijenhuis | 4. Juni 2010

7

Memory Management

Reference to Stored In

Heap Immortal Scoped

Heap Permit Permit Forbid

Immortal Permit Permit Forbid

Scoped Permit Permit Permit, if the

reference is from the same scope or an outer scope

(8)

8

Memory Management

■ Garbage collection algorithm must be described

■ “precisely characterize a implemented GC algorithm's effect on the

execution time, preemption, and dispatching of real-time Java threads”

■ Must be preemptable by Threads that do not use heap

(9)

Realtime Java | Christoph Neijenhuis | 4. Juni 2010

9

Memory Management

■ Memory usage of threads can be limited with MemoryParameters

□ Define maximum memory usage for scoped or immortal

memory

□ Define maximum allocation rate (in bytes) for heap

(10)

10

Threads

■ RealtimeThread extends java.lang.Thread

■ Reuses most concepts, but not priority

■ ReleaseParameters, SchedulingParameters and MemoryParameters

may provide information to the scheduler

■ NoHeapRealtimeThread extends RealtimeThread

■ Can only use scoped and immortal memory

(11)

Realtime Java | Christoph Neijenhuis | 4. Juni 2010

11

Examples

PriorityParameters priority = new PriorityParameters(15);

RelativeTime relative = new RelativeTime(20 /* ms */,0 /* ns */); PeriodicParameters period = new PeriodicParameters(relative);

RealtimeThread rt = new RealtimeThread(priority, period); ScopedMemory memory = new LTMemory(1024); // size in bytes NoHeapRealtimeThread nhrt =

(12)

12

Asynchronous Event Handling

■ AsyncEvent class can be:

□ bound to external, implementation specific event

□ fired by application

■ One or more AsyncEventHandlers can be assigned

■ Released when the event occurs

(13)

Realtime Java | Christoph Neijenhuis | 4. Juni 2010

13

Scheduling

■ RealtimeThreads, AsyncEventHandlers, but also standard Java

threads need to be scheduled

■ Specification requires one scheduler (PriorityScheduler)

■ Implementation may define further schedulers

■ PriorityScheduler is fixed-priority, preemptive with at least 28 priorities

■ Subclasses of SchedulingParameters (e.g. PriorityParameters)

provide values for scheduling decisions

■ Subclasses of ReleaseParameters are Periodic-, Aperiodic- and

SporadicParameters

■ Define release time and may define a deadline and cost

(14)

14

Scheduling

■ Scheduler must implement feasibility algorithm

■ IsFeasible() returns true if all known schedulable objects described

by their SchedulingParameters and ReleaseParameters are feasible for the current system

□ Implementation must define feasibility

□ Standard implementation for PriorityScheduler:

– Return true if no AperiodicParameters is set

(15)

Realtime Java | Christoph Neijenhuis | 4. Juni 2010

15

Examples

PriorityParameters priority = new PriorityParameters(15); AperiodicParameters aperiodic = new AperiodicParameters(); aperiodic.setCost(new RelativeTime(2, 500000));

aperiodic.setDeadline(new RelativeTime(5, 0)); aperiodic.setDeadlineMissHandler(missHandler);

AsyncEventHandler handler = new AsyncEventHandler(

priority, aperiodic, null, null, null, false); AsyncEvent externalEvent = getExternalEvent();

(16)

16

Time

■ HighResolutionTime describes time with nanosecond accuracy

□ Actual accuracy depends on underlying system

□ long getMilliseconds()

□ int getNanoseconds() (min: -9999999 max: 999999)

■ Subclass AbsoluteTime defines absolute point in time

(17)

Realtime Java | Christoph Neijenhuis | 4. Juni 2010

17

Synchronization

■ Java provides synchronized keyword for synchronization but no

prevention of priority inversion

■ PriorityInheritance is default synchronization policy

(18)

18

Implementations

■ Reference Implementation from TimeSys (2002)

□ Runs on X86/Linux

□ Not commercially available

■ Sun Java SE Real-time (2005)

□ Runs on Solaris 10, SUSE & RedHat Realtime Linux

□ Based on Java SE 5

□ Min requirements: Dual core or dual CPU system with 512 MB

■ Apogee RTJRE (2006)

□ Runs on Linux, based on IBMs JVM

□ Targets embedded systems, includes version for Java ME

(19)

Realtime Java | Christoph Neijenhuis | 4. Juni 2010

19

Garbage Collection in the Sun VM

(20)

20

References

■ http://jcp.org/en/jsr/detail?id=1 ■ http://java.sun.com/javase/technologies/realtime/index.jsp ■ http://www.rtsj.org ■ http://www.apogee.com/products/rtjre ■ http://www.dcl.hpi.uni-potsdam.de/teaching/EmbeddedOS/Slides/05.2_RT-Java.pdf ■ http://java.sun.com/javase/technologies/realtime/reference/doc_2.2/release/JavaRTSGettingStarted.html

References

Related documents

For example, given that all the tested drugs showed strong evidence for their efficacy (i.e. BF>20), except for bupropion and vilazodone, it could be recommended that

If you are closing your business please submit the Closed or Sold Business Form to the City of Brookhaven if you have closed or sold your business outside of Brookhaven

The requirements set out in section 1.2 are fulfilled by the new methodology thus: Requirement 1 is satisfied by the use of domain specific ontologies distributed to the

The purpose of this Flu Pandemic Contingency Plan is to minimize the health risk posed to The - Group employees from a potential avian flu pandemic and ensure on-going operation of

Tool providers understood that the drivers of different companies using their tools may vary but the general information they needed to improve their sustainable packaging design

Meshes generated for Mod 2a and Mod 2b focused on modifying the baseline volume mesh to use 1 or 2 layers of cells respectively with a height of 0.00117 off the viscous walls,

The empirical results from multinomial logit analysis showed that the choice of CA adopted is positively influenced by farmer’s formal education, access to

Charge Air Cooled Diesel engine Number of cylinders Engine family Turbo Cylinders in In-line con fi guration... Family 914