111 G53SRP: RTSJ Memory Areas Chris Greenhalgh School of Computer Science.

Slides:



Advertisements
Similar presentations
Concurrency Important and difficult (Ada slides copied from Ed Schonberg)
Advertisements

Chapter 7: User-Defined Functions II Instructor: Mohammad Mojaddam.
Java How to Program, 9/e CET 3640 Professor: Dr. José M. Reyes Álamo © Copyright by Pearson Education, Inc. All Rights Reserved.
Model for Supporting High Integrity and Fault Tolerance Brian Dobbing, Aonix Europe Ltd Chief Technical Consultant.
RTS - Implementation ITV Real-Time Systems Anders P. Ravn Aalborg University February 2006.
Programming R-T Abstractions TSW November 2009 Anders P. Ravn Aalborg University.
Process Description and Control Module 1.0. Major Requirements of an Operating System Interleave the execution of several processes to maximize processor.
Real-Time Java Real-Time Systems Anders P. Ravn Aalborg University March 2008.
© Andy Wellings, 2004 Roadmap  Introduction  Concurrent Programming  Communication and Synchronization  Completing the Java Model  Overview of the.
© Andy Wellings, 2004 Roadmap  Introduction  Concurrent Programming  Communication and Synchronization  Completing the Java Model  Overview of the.
© Andy Wellings, 2004 Roadmap  Introduction  Concurrent Programming  Communication and Synchronization  Completing the Java Model  Overview of the.
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
© Andy Wellings, 2004 Roadmap  Introduction  Concurrent Programming  Communication and Synchronization  Completing the Java Model  Overview of the.
© Andy Wellings, 2004 Roadmap  Introduction  Concurrent Programming  Communication and Synchronization  Completing the Java Model  Overview of the.
Programming Language Semantics Java Threads and Locks Informal Introduction The Java Specification Language Chapter 17.
© Andy Wellings, 2004 Roadmap  Introduction  Concurrent Programming  Communication and Synchronization  Completing the Java Model  Overview of the.
Run time vs. Compile time
OS Spring’03 Introduction Operating Systems Spring 2003.
© Andy Wellings, 2003 Roadmap  Introduction  Concurrent Programming  Communication and Synchronization  Completing the Java Model  Overview of the.
Low-level Programming TSW November 2009 Anders P. Ravn Aalborg University.
© Andy Wellings, 2004 Roadmap  Introduction  Concurrent Programming  Communication and Synchronization  Completing the Java Model  Overview of the.
1 Run time vs. Compile time The compiler must generate code to handle issues that arise at run time Representation of various data types Procedure linkage.
CprE 458/558: Real-Time Systems
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Processes CS 416: Operating Systems Design, Spring 2001 Department of Computer Science Rutgers University
© Andy Wellings, 2004 Roadmap  Introduction  Concurrent Programming  Communication and Synchronization  Completing the Java Model  Overview of the.
Memory organization and usage A computer’s memory is, at its lowest level, composed of binary digits (bits). The memory is organized into bytes, which.
Operating Systems Concepts 1. A Computer Model An operating system has to deal with the fact that a computer is made up of a CPU, random access memory.
Memory Management for Real-Time Java Wes Beebee and Martin Rinard Laboratory for Computer Science Massachusetts Institute of Technology Supported by: DARPA.
Java How to Program, 9/e CET 3640 Professor: Dr. Reyes Álamo © Copyright by Pearson Education, Inc. All Rights Reserved.
Real-Time Java Martin Schöberl. Real Time Java2 Overview What are real-time systems Real-time specification for Java RTSJ issues, subset Real-time profile.
SPL/2010 StackVsHeap. SPL/2010 Objectives ● Memory management ● central shared resource in multiprocessing RTE ● memory models that are used in Java and.
Compilation Technology © 2007 IBM Corporation CGO Performance Overheads In Real-Time Java Programs Mark Stoodley and Mike Fulton Compilation.
Real-Time Java on JOP Martin Schöberl. Real-Time Java on JOP2 Overview RTSJ – why not Simple RT profile Scheduler implementation User defined scheduling.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition, Fifth Edition Chapter 7: User-Defined Functions II.
Instructore: Tasneem Darwish1 University of Palestine Faculty of Applied Engineering and Urban Planning Software Engineering Department Concurrent and.
Enhancements to Java for Real Time Systems Theresa Dsena CSE Fall 2006 Prof. Ganesan.
XOberon CS Fall 2002 Dr. Abzug Jeremy Bruker Jeremy Carbaugh Jeff Hensley Drew Stockdreher.
EEL The Real-Time Specification for Java (1)
11 G53SRP: Deadline misses and cost over-runs in RTSJ Chris Greenhalgh School of Computer Science.
1 G53SRP: Java Concurrency Control (1) - synchronisation Chris Greenhalgh School of Computer Science.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
EEL Real-time Java part 2. EEL Acknowledgements All the lecture slides were adopted from the slides of Andy Wellings.
Introduction to Threads Session 01 Java Simplified / Session 14 / 2 of 28 Objectives Define a thread Define multithreading List benefits of multithreading.
Processes CS 6560: Operating Systems Design. 2 Von Neuman Model Both text (program) and data reside in memory Execution cycle Fetch instruction Decode.
Introduction to Java Chapter 7 - Classes & Object-oriented Programming1 Chapter 7 Classes and Object-Oriented Programming.
Patterns and Tools for Achieving Predictability and Performance with Real-time Java Presenter: Ehsan Ghaneie.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
CSCI1600: Embedded and Real Time Software Lecture 18: Real Time Languages Steven Reiss, Fall 2015.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 4: Threads.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
Thread basics. A computer process Every time a program is executed a process is created It is managed via a data structure that keeps all things memory.
Thread A thread represents an independent module of an application that can be concurrently execution With other modules of the application. MULTITHREADING.
How to Compile Aspects with Real-Time Java Pengcheng Wu Northeastern University Mar. 14, 2005 FOAL Workshop with AOSD’05.
11 G53SRP: Feasibility analysis Chris Greenhalgh School of Computer Science.
1 G53SRP: Introduction to Real Time Scheduling Chris Greenhalgh School of Computer Science.
1 Threads in Java Jingdi Wang. 2 Introduction A thread is a single sequence of execution within a program Multithreading involves multiple threads of.
Embedded Real-Time Systems Processing interrupts Lecturer Department University.
RealTimeSystems Lab Jong-Koo, Lim
Java Thread Programming
Context-related issues in real-time systems
Chapter 7: User-Defined Functions II
PROCESS MANAGEMENT IN MACH
Multithreaded Programming in Java
G53SRP: Real Time Threads in RTSJ (part I)
G53SRP: Asynchronous Events in RTSJ
G53SRP: Resource Sharing Issues
Real Time Java : Synchronization
Presentation transcript:

111 G53SRP: RTSJ Memory Areas Chris Greenhalgh School of Computer Science

222 Contents IntroductionIntroduction –Heap and garbage collection Memory area classesMemory area classes –HeapMemory, ImmortalMemory, ScopedMemory Estimating sizesEstimating sizes Threads and memory usageThreads and memory usage –Memory Parameters, No heap threads and handlers Physical memory usePhysical memory use –Raw memory access SummarySummary Book: Wellings 7.3, 8 (part), 15.1 & 15.2 (part)Book: Wellings 7.3, 8 (part), 15.1 & 15.2 (part)

33 Introduction In regular JavaIn regular Java –All objects are allocated on the heap A single expandable area of memoryA single expandable area of memory Local variables and parameters are on the thread’s stackLocal variables and parameters are on the thread’s stack –In Java these can only be primitive types and references! –A garbage collection algorithm runs in the background E.g. when heap is full, periodically or incrementallyE.g. when heap is full, periodically or incrementally Releases/recycles objects which are no longer reachableReleases/recycles objects which are no longer reachable

44 Realtime issues Memory may be limited – –May need special management Garbage collection may interfere with processes – –Introducing additional delays – –Causing missed deadlines

55 RTSJ responses Allows objects to be allocated in non-heap “memory areas” – –Avoiding garbage collection for those areas And/or recycling the whole area as one (i.e. scoped memory) – –Allowing more explicit management E.g. monitoring space used and free

66 Memory area classes > javax.realtime. MemoryArea javax.realtime. HeapMemory extends > javax.realtime. ScopedMemory javax.realtime. ImmortalMemory javax.realtime. LTMemory javax.realtime. VTMemory

77 Memory area types HeapMemory – –The regular Java heap ImmortalMemory – –Single area of non-GC memory ScopedMemory – –Block(s) of memory which are reference counted and allocated/freed as a whole – –LTMemory – ScopedMemory with allocation time linearly proportional to size – –VTMemory – ScopedMemory with variable allocation time

88 MemoryArea class [optional detail] package javax.realtime; public abstract class MemoryArea { … public long size(); public long memoryConsumed(); public long memoryRemaining(); … Monitor/manage usage

99 … public void enter(Runnable logic); public void executeInArea(Runnable logic); … public Object newInstance(Class clazz); public Object newArray(Class type, int number); … } Explicit allocation within currently valid memory area Manipulate default memory area used for realtime thread’s memory allocation [optional detail]

10 ImmortalMemory & HeapMemory [optional detail] package javax.realtime; public abstract class ImmortalMemory extends MemoryArea { public static ImmortalMemory instance(); } public abstract class HeapMemory extends MemoryArea { public static HeapMemory instance(); } Singletons

11 Example [optional detail] … ImmortalMemory.instance().executeInArea( new Runnable() { public void run() { int a[] = new int[1000]; … } }); … int a[] = (int[])ImmortalMemory.instance(). newArray(Integer.TYPE, 1000); … In immortal memory: never garbage collected

12 Scoped Memory Block of memory managed as a whole Accessible only to realtime threads (and asynchronous event handlers) Accessible only to a realtime thread that has enter ed it Released (and objects finalised) when all realtime threads leave it – –i.e. “garbage collected” as a single unit – –References to it are not allowed where they might “outlive” it, e.g. on the heap or immortal memory

13 LTMemory & VTMemory [optional detail] package javax.realtime; public abstract class LTMemory extends ScopedMemory { public LTMemory(long size); public LTMemory(long initial, long maximum); … } public abstract class VTMemory extends ScopedMemory { public VTMemory(long size); public VTMemory(long initial, long maximum); … }

14 Example [optional detail] … LTMemory mem = new LTMemory(size); mem.enter( new Runnable() { public void run() { int a[] = new int[1000]; … } }); … In scoped memory ‘mem’ Needs to be big enough! Scoped memory backing store released when method finishes

15 Scoped memory notes [optional detail] References to objects in scoped memory – –Cannot be on heap – –Cannot be in immortal memory – –Cannot be in a scoped memory that is “below” the scoped memory containing the object Each scoped memory has one parent scoped memory = the scoped memory from which it was entered

16 Scoped memory portals [optional detail] Each ScopedMemory can have one “portal” – –An object, typically in the scoped memory, that can be accessed from the ScopedMemory object Note that the ScopedMemory object itself may be on the Heap, in immortal memory, etc.; its backing store is separate from the object – –Allows different threads to find an entry to object(s) in a common ScopedMemory The reference rules make this difficult otherwise – –… public Object getPortal(); public void setPortal(Object o); …

17 Memory area stack RealtimeThread and AsyncEventHandler have a MemoryArea parameter – –Initial memory area in which to execute – –Available via getMemoryArea() Memory areas are also visible as a memory area stack – –See RealtimeThread static methods e.g. getCurrentMemoryArea(), getOuterMemoryArea(int index)

18 Estimating sizes Scoped memory areas need to have a size specifiedScoped memory areas need to have a size specified –Supported by SizeEstimator …

19 SizeEstimator class [optional detail] package javax.realtime; public class SizeEstimator { public SizeEstimator(); // call as required public void reserve(Class c, int number); public void reserve(SizeEstimator s, int number); public void reserveArray(int dimensions, Class type); … public long getEstimate(); } Adds to running total Current estimate (sufficient)

20 Example [optional detail] … SizeEstimator s = new SizeEstimator(); s.reserve(MyClass.class, 10); … long size = s.getEstimate(); … Enough for 10 instances of MyClass (excluding any member reference Values!)

21 Memory ParametersMemory Parameters Parameter to RealtimeThread and AsyncEventHandlerParameter to RealtimeThread and AsyncEventHandler –Control memory use of the task Specifies:Specifies: –maxMemoryArea – maximum amount of memory allocation allowed in the task’s (initial) memory area –maxImmortal – maximum amount of memory allocation allowed in immortal memory –allocationRate – maximum rate at which heap memory can be allocated [optionally enforced] 21

22 MemoryParameters class package javax.realtime; public class MemoryParameters { public static final long NO_MAX; public MemoryParameters( long maxMemoryArea, long maxImmortal, long allocationRate); public long getMaxMemoryArea(); public long SetMaxMemoryAreaIfFeasible(); … }

23 Memory Parameter checking May be used by Scheduler for admission control (feasibility checking) – –E.g. total available memory Checked/enforced by new – –Throws OutOfMemoryError if exceeded E.g. – –too much (immortal or scoped) memory used – –Heap memory allocated too rapidly May impact need for garbage collection Implementation dependent whether this is checkedImplementation dependent whether this is checked

24 No heap threads and handlersNo heap threads and handlers To completely avoid interference from the garbage collector a Schedulable mustTo completely avoid interference from the garbage collector a Schedulable must –Not use heap memory at all Indicated to JVM by using NoHeapRealtimeThread class or AsyncEventHandler with noheap = trueIndicated to JVM by using NoHeapRealtimeThread class or AsyncEventHandler with noheap = true Throws exception at run-time if heap memory usedThrows exception at run-time if heap memory used –Have a higher priority than any heap using thread Garbage collection may occur on behalf of any heap using thread – at its priorityGarbage collection may occur on behalf of any heap using thread – at its priority 24

25 Physical memory access An embedded device may have several different kinds of memory with different characteristics – –Fast volatile DRAM/SRAM – –Fast readonly ROM/EPROM – –Slower non-volatile EEPROM/FLASH – –Removable memory, e.g. SD/MMC/… The program may need to use the right kind for the right things…

26 Example Physical Memory map From Wellings Figure 15.2 © Wellings 2004 IO Memory Shared memory Removable Memory RAM ROM High address Low address

27 Raw Memory Access Can access raw bytes, e.g. – –Interacting with an IO device (see later notes) – –Accessing memory shared with another (esp. non-Java) application Via RawMemoryAccess …

28 RawMemoryAccess class package javax.realtime; public class RawMemoryAccess { public RawMemoryAccess( Object type, long base, long size); … public byte getByte(long offset); public int getInt(long offset); public void setByte(long offset, byte value); public void setInt(long offset, int value); … } Raw memory bytes Byte order platform dependent… Types: ALIGNED BYTESWAP DMA IO_PAGE SHARED … (see PhysicalMemoryManager)

29 Checking byte order package javax.realtime; public class RealtimeSystem { … public static final byte BIG_ENDIAN; public static final byte LITTLE_ENDIAN; public static final byte BYTE_ORDER; … } LITTLE_ENDIAN or BIG_ENDIAN as appropriate i.e. start at the “big” or “little” end of the number

30 Physical memory areas Can also create and use MemoryAreas that are “locked” to particular parts of physical memory – –to ensure correct physical memory is used E.g. EEPROM/FLASH vs RAM vs DMA Extends previous MemoryArea classes… – –Inherits basic characteristics and API – –Needs extra information about physical “backing”

31 Physical Memory classes > javax.realtime. MemoryArea > javax.realtime. ScopedMemory extends javax.realtime. ImmortalPhysicalMemory javax.realtime. LTPhysicalMemory javax.realtime. VTPhysicalMemory

32 E.g. ImmortalPhysicalMemory package javax.realtime; public class ImmortalPhysicalMemory extends MemoryArea { public ImmortalPhysicalMemory( Object type, long base, long size); … } Types: ALIGNED BYTESWAP DMA IO_PAGE SHARED … (see PhysicalMemoryManager)

33 Summary Normal Java object allocated on the heapNormal Java object allocated on the heap –Released when unreachable by garbage collector Realtime and embedded systems mayRealtime and embedded systems may –Need more explicit management of space –Be delayed unpredictably by garbage collection RTSJ allows realtime threads to use different memory areas:RTSJ allows realtime threads to use different memory areas: –HeapMemory – normal heap –ImmortalMemory – non-garbage collected area –ScopedMemory …

34 Summary (2) Scoped memoryScoped memory –LTMemory or VTMemory –memory areas which are released as a whole when no realtime threads are using them –May be nested –Cannot have references to object in scoped memory on heap, immortal memory or parent/ancestor scoped memory Estimating sizes for scoped memory areas – using SizeEstimatorEstimating sizes for scoped memory areas – using SizeEstimator

35 Summary (3) Realtime thread and asycn event handler memory usage limits specified by MemoryParameters : – –Memory area and immortal memory size limites – –Heap allocation rate limit (optionally checked) Can avoid interference from GC using NoHeapRealtimeThread or noheap AsyncEventHandler – –Iff priority > any heap-using thread / handler

36 Summary (4) Access to raw physical memory – –E.g. for device IO or inter-program communication – –via RawMemoryAccess Use of specific areas of physical memory – –E.g. to reflect type(s) of memory present – –via PhysicalImmortalMemory, LTPhysicalMemory & VTPhysicalMemory