© Andy Wellings, 2004 Roadmap  Introduction  Concurrent Programming  Communication and Synchronization  Completing the Java Model  Overview of the.

Slides:



Advertisements
Similar presentations
Operating Systems Components of OS
Advertisements

© 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.
1 Lecture 11 Interfaces and Exception Handling from Chapters 9 and 10.
Various languages….  Could affect performance  Could affect reliability  Could affect language choice.
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 18.
Chapter 8 Runtime Support. How program structures are implemented in a computer memory? The evolution of programming language design has led to the creation.
Programming R-T Abstractions 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.
ISBN Chapter 11 Abstract Data Types and Encapsulation Concepts.
© 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.
© 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.
© Andy Wellings, 2004 Roadmap  Introduction  Concurrent Programming  Communication and Synchronization  Completing the Java Model  Overview of the.
© Andy Wellings, 2003 Roadmap  Introduction  Concurrent Programming  Communication and Synchronization  Completing the Java Model  Overview of the.
The environment of the computation Declarations introduce names that denote entities. At execution-time, entities are bound to values or to locations:
1 Memory Model of A Program, Methods Overview l Closer Look at Methods l Memory Model of JVM »Method Area »Heap »Stack l Preview: Parameter Passing.
© Andy Wellings, 2004 Roadmap  Introduction  Concurrent Programming  Communication and Synchronization  Completing the Java Model  Overview of the.
Lecture 9 Concepts of Programming Languages
1 Further OO Concepts II – Java Program at run-time Overview l Steps in Executing a Java Program. l Loading l Linking l Initialization l Creation of Objects.
1 Memory Model of A Program, Methods Overview l Memory Model of JVM »Method Area »Heap »Stack.
© 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.
Storage & Linkage: Effects on Scope Rudra Dutta CSC Spring 2007, Section 001.
Chapter TwelveModern Programming Languages1 Memory Locations For Variables.
Object Oriented Programming
220 FINAL TEST REVIEW SESSION Omar Abdelwahab. INHERITANCE AND POLYMORPHISM Suppose you have a class FunClass with public methods show, tell, and smile.
EECE 310: Software Engineering Lecture 2: Understanding Objects in Java and Types.
Instructore: Tasneem Darwish1 University of Palestine Faculty of Applied Engineering and Urban Planning Software Engineering Department Concurrent and.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Exception Handling Unit-6. Introduction An exception is a problem that arises during the execution of a program. An exception can occur for many different.
C# EMILEE KING. HISTORY OF C# In the late 1990’s Microsoft recognized the need to be able to develop applications that can run on multiple operating system.
Instructore: Tasneem Darwish1 University of Palestine Faculty of Applied Engineering and Urban Planning Software Engineering Department Concurrent and.
C++ Memory Overview 4 major memory segments Key differences from Java
EEL The Real-Time Specification for Java (1)
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.
1 5.0 Garbage collector & Threads : Overview Introduction: In this module we discuss the merits and demerits of automated garbage collection over manual.
What is a ‘ thread ’ ? Free Online Dictionary of Computing (FOLDOC) Sharing a single CPU between multiple tasks (or "threads") in a way designed to minimize.
111 G53SRP: RTSJ Memory Areas Chris Greenhalgh School of Computer Science.
Classes. Constructor A constructor is a special method whose purpose is to construct and initialize objects. Constructor name must be the same as the.
Patterns and Tools for Achieving Predictability and Performance with Real-time Java Presenter: Ehsan Ghaneie.
Objects and Variables Local variables – Confined to single context: allocated on stack – Primitive types such as int or object references – Must be initialized.
Multithreaded programming  Java provides built-in support for multithreaded programming. A multithreaded program contains two or more parts that can run.
13-1 Chapter 13 Concurrency Topics Introduction Introduction to Subprogram-Level Concurrency Semaphores Monitors Message Passing Java Threads C# Threads.
CMSC 330: Organization of Programming Languages Threads.
Threads in Java Threads Introduction: After completing this chapter, you will be able to code your own thread, control them efficiently without.
Classes, Interfaces and Packages
How to Compile Aspects with Real-Time Java Pengcheng Wu Northeastern University Mar. 14, 2005 FOAL Workshop with AOSD’05.
Object orientation and Packaging in Java Object Orientation and Packaging Introduction: After completing this chapter, you will be able to identify.
The Execution System1. 2 Introduction Managed code and managed data qualify code or data that executes in cooperation with the execution engine The execution.
CSE 501N Fall ’09 07: Iteration 17 September 2009 Nick Leidenfrost.
Reference Types CSE301 University of Sunderland Harry R Erwin, PhD.
© Andy Wellings, 2004 Thread Priorities I  Although priorities can be given to Java threads, they are only used as a guide to the underlying scheduler.
Internet Computing Module II. Syllabus Creating & Using classes in Java – Methods and Classes – Inheritance – Super Class – Method Overriding – Packages.
Garbage Collection It Is A Way To Destroy The Unused Objects. To do so, we were using free() function in C language and delete() in C++. But, in java it.
Agenda Introduction Errors and Exception Exception Hierarchy Classification of Exceptions Built in Exceptions Exception Handling in Java User defined.
CSE 332: C++ Exceptions Motivation for C++ Exceptions Void Number:: operator/= (const double denom) { if (denom == 0.0) { // what to do here? } m_value.
Java Thread Programming
Design issues for Object-Oriented Languages
EECE 309: Software Engineering
CS 326 Programming Languages, Concepts and Implementation
G53SRP: Real Time Threads in RTSJ (part I)
Java Programming Language
Concurrent programming
Lecture 6: Names (Revised based on the Tucker’s slides) 5/27/2019
Presentation transcript:

© Andy Wellings, 2004 Roadmap  Introduction  Concurrent Programming  Communication and Synchronization  Completing the Java Model  Overview of the RTSJ  Memory Management  An overview of MemoryAreas  An example of Scoped Memory Usage  How to estimating the size of objects  Continued …  Clocks and Time  Scheduling and Schedulable Objects  Asynchronous Events and Handlers  Real-Time Threads  Asynchronous Transfer of Control  Resource Control  Schedulability Analysis  Conclusions

© Andy Wellings, 2004 Memory Management Lecture aims:  To explain the RTSJ assignment Rules  To illustrate the single parent rule  To consider the sharing of memory areas between Schedulable objects

© Andy Wellings, 2004 Memory Assignment Rules  In the RTSJ there are four types of memory  heap memory: collected by the garbage collector  local variables (stack memory): collected automatically when methods exit  immortal memory: never collected  scoped memory: available for collection when the associated reference count equals zero  Given the different collection mechanism, it is necessary to impose some restrictions on assignments between the different types of memory  Otherwise dangling references may occur  A dangling reference is a references to an object that has been collected when scoped memory is reclaimed

© Andy Wellings, 2004 Dangling Reference Example  A, has been created in a scoped memory region  A reference to that object has been stored in object, B, which resides in the heap  The lifetime of a scoped memory is controlled by its reference count

© Andy Wellings, 2004 The Reference Count The reference count of a scoped memory area is the count of the number of active calls (explicit or implicit) to its enter method. It is NOT a count of the number of objects that have references to the objects allocated in the scoped memory. The reference to object, A, from object, B, becoming invalid (dangling) when object A’s memory area is reclaimed. There would be no way to detect this invalid reference, so the safety of the Java program would be compromised.

© Andy Wellings, 2004 Memory Assignment Rules generally allowedallowed Local Variable allowed is to same scope or outer scope forbidden if to an inner scope allowed Scoped Memory forbiddenallowed Immortal Memory forbiddenallowed Heap Memory To Scoped Memory To Immortal Memory To Heap MemoryFrom Memory Area

© Andy Wellings, 2004 Note  If the program violates the assignment rules, the unchecked exception IllegalAssignmentError is thrown  One of the requirements for the RTSJ was that there should be no changes to the Java language and that existing compilers can be used to compile RTSJ programs  These rules must be enforced on every assignment statement at run-time by the real-time JVM  An RTSJ-aware compiler may be able to undertake some static analysis in order to reduce this burden  Alternatively, checks may be performed at class loading time

© Andy Wellings, 2004 Nested Memory Areas  The real-time JVM will need to keep track of the currently active memory areas of each schedulable object  One way this can be achieved is via a stack  Every time a schedulable object enters a memory area, the identity of that area is pushed onto the stack  When it leaves the memory area, the identity is popped off the stack stack grows upwards

© Andy Wellings, 2004 Implementation of Assignment Rules I  The stack can be used to check for invalid memory assignment to and from scoped memory areas  Creating a reference from an object in one scoped memory area to an object in another scoped memory area below the first area in the stack is allowed.  Creating a reference from an object in one scoped memory area to an object in another scoped memory area above the first area in the stack is forbidden

© Andy Wellings, 2004 Implementation of Assignment Rules II  If O1 is in ScopedB and O2 is in ScopedA  O1.O2Ref = O2 is ALLOWED  O2.O1Ref = O1 is DISALLOWED The memory assignment rules by themselves are still inadequate to avoid the dangling reference problem!

© Andy Wellings, 2004 Consider  A schedulable object enters the same memory area twice  Now an object could be created in ScopedA which references an object in ScopedB  However, when the current ScopedA memory is exited, the reference count for that area is still greater than zero and so its objects are not reclaimed  Now when ScopedB is exited, it objects are reclaimed and consequently, the object in ScopedA is left with a dangling reference

© Andy Wellings, 2004 The Single Parent Rule  To avoid this problem, the RTSJ requires that each scoped memory area has a single parent  The parent of an active scoped memory area is  If the memory is the first scoped area on the stack, its parent is termed the primordial scope area  For all other scoped memory areas, the parent is the first scoped area below it on the stack Violates the single parent rule, therefore ScopedCycleException is thrown

© Andy Wellings, 2004 Moving Between Memory Areas  As it is not possible to re-enter an active scoped memory area, it is necessary to provide alternative mechanisms for moving between active memory areas public abstract class MemoryArea {... public void executeInArea(Runnable logic); public Object newArray(Class type, int number) throws various_exceptions; public Object newInstance(Class type) throws various_exceptions; public Object newInstance( java.lang.reflect.Constructor c, Object[] args) throws various_exceptions; }

© Andy Wellings, 2004 Cactus Stack Now Needed heap ScopedA ScopedB current Immortal (a) Initial stack heap ScopedA ScopedB current Immortal (b) During, ScopedA.executeInArea(…) heap ScopedA ScopedB current ImmortalScopedC (c) During, ScopedC.enter(…)

© Andy Wellings, 2004 Important Note  A call to executeInArea with a parameter of the heap (or immortal) memory, results in a new memory stack being created, with the heap (or immortal) memory area at its base.

© Andy Wellings, 2004 Sharing Memory Areas  Multiple schedulable objects can access the same memory areas  Consequently, the cactus stacks for each schedulable objects are linked together  Here, two real-time threads ( ThreadA and ThreadB ) have active scoped memory stacks. ThreadAThreadB

© Andy Wellings, 2004 Sharing Memory Areas  Suppose that ThreadA wishes to enter ScopedE ; it cannot do so directly because ScopedE is already active and has a parent of ScopedD  To gain access to ScopedE, ThreadA must first move to ScopedA (using executeInArea ), then enter ScopedD followed by ScopedE ThreadA ThreadB

© Andy Wellings, 2004 Inheritance of Stack I  When a schedulable object is created, its initial memory area stack can be set; for example, the RealtimeThread class package javax.realtime; public class RealtimeThread extends Thread implements Schedulable { // constructors public RealtimeThread(SchedulingParameters scheduling, ReleaseParameters release, MemoryParameters memory, MemoryArea area, ProcessingGroupParameters group, Runnable logic);... }

© Andy Wellings, 2004 Inheritance of Stack II  The stack of a created schedulable object is determined by the value of the initial memory area (the area parameter) and the currently active memory area  If current area is the heap and  the initial memory area is the heap, the new stack contains only the heap memory area  the initial memory area is not the heap, the new stack contains the heap and the initial memory area  If current area is the immortal memory area and  the initial memory area is the immortal memory area, the new stack contains only the immortal memory area  the initial memory area is not the immortal memory area, the new stack contains the immortal memory area and the initial memory area

© Andy Wellings, 2004 Inheritance of Stack III  If the current area is a scoped memory area and the initial memory area is the currently active memory area (or null)  the new stack is the parent’s stack up to and including the current memory area  If the current area is a scoped memory area and the initial memory area is not the currently active memory area  the new stack is the parent’s stack up to and including the current memory area, plus the initial memory area

© Andy Wellings, 2004 Inheritance of Stack Example I ScopeE ScopeD ScopeC ScopeB ScopeA Heap Immortal Parent Stack current memory area If initial memory area is the heap what is the child’s stack?

© Andy Wellings, 2004 Inheritance of Stack Example II ScopeE ScopeD ScopeC ScopeB ScopeA Heap Immortal Parent Stack current memory area If initial memory area is the heap what is the child’s stack?

© Andy Wellings, 2004 Inheritance of Stack Example III ScopeE ScopeD ScopeC ScopeB ScopeA Heap Immortal Parent Stack current memory area If initial memory area is the ScopeF what is the child’s stack?

© Andy Wellings, 2004 Inheritance of Stack Example IV ScopeE ScopeD ScopeC ScopeB ScopeA Heap Immortal Parent Stack current memory area If initial memory area is the scopeA what is the child’s stack?

© Andy Wellings, 2004 Inheritance of Stack Example V ScopeE ScopeD ScopeC ScopeB ScopeA Heap Immortal Parent Stack current memory area If initial memory area is the heap what is the child’s stack? ScopeG ScopeF

© Andy Wellings, 2004 Entering and Joining Scoped Memory Areas  Scoped memory areas can be used in one of two modes of operation: cooperatively or competitively  In cooperative use, the schedulable objects aim to be active in a scoped memory area simultaneously  they use the area to communicate shared objects  when they leave, the memory is reclaimed  In competitive use, the goal is to make the most efficient use of memory  the schedulable objects are trying to take their memory from the same area but are not using the area for the communication  here, it is usually required for only one schedulable to be active in the memory area at one time  the intention is that the memory can be reclaimed when each of the schedulable objects leave the area

© Andy Wellings, 2004 Competitive Use  To ensure that the area becomes inactive use: package javax.realtime; public abstract class ScopedMemory extends MemoryArea {... public int getReferenceCount(); public void join() throws InterruptedException; public void join(HighResolutionTime time) throws InterruptedException; public void joinAndEnter() throws InterruptedException; public void joinAndEnter(HighResolutionTime time) throws InterruptedException; public void joinAndEnter(java.lang.Runnable logic) throws InterruptedException; public void joinAndEnter(java.lang.Runnable logic, HighResolutionTime time) throws InterruptedException;... }

© Andy Wellings, 2004 Join and Enter Issues  If timeout expires, the memory area is entered  It is difficult to know if the timeout did expire

© Andy Wellings, 2004 Summary  The lack of confidence in real-time garbage collection is one of the main inhibitors to the widespread use of Java in real-time and embedded systems  The RTSJ has introduced an additional memory management facility based on the concept of memory areas  There are two types on non-heap memory areas  immortal memory which is never subject to garbage collection  scoped memory in to which schedulable objects can enter and leave; when there are no schedulable objects active in a scoped memory area, all the objects are destroyed and their memory reclaimed.  Due to the variety of memory areas, the RTSJ has strict assignment rules between them in order to ensure that dangling references do not occur

© Andy Wellings, 2004 Further Reading and Exercises  Do the Accessing Memory Areas Exercise