Memory Management for Real-Time Java Wes Beebee and Martin Rinard Laboratory for Computer Science Massachusetts Institute of Technology Supported by: DARPA.

Slides:



Advertisements
Similar presentations
Dataflow Analysis for Datarace-Free Programs (ESOP 11) Arnab De Joint work with Deepak DSouza and Rupesh Nasre Indian Institute of Science, Bangalore.
Advertisements

Automatic Memory Management Noam Rinetzky Schreiber 123A /seminar/seminar1415a.html.
Compilation 2011 Static Analysis Johnni Winther Michael I. Schwartzbach Aarhus University.
Extensibility, Safety and Performance in the SPIN Operating System Presented by Allen Kerr.
1 Concurrency Specification. 2 Outline 4 Issues in concurrent systems 4 Programming language support for concurrency 4 Concurrency analysis - A specification.
Java How to Program, 9/e CET 3640 Professor: Dr. José M. Reyes Álamo © Copyright by Pearson Education, Inc. All Rights Reserved.
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 18.
Chapter 5 Processes and Threads Copyright © 2008.
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
490dp Synchronous vs. Asynchronous Invocation Robert Grimm.
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Concurrency CS 510: Programming Languages David Walker.
© Andy Wellings, 2004 Roadmap  Introduction  Concurrent Programming  Communication and Synchronization  Completing the Java Model  Overview of the.
Java for High Performance Computing Jordi Garcia Almiñana 14 de Octubre de 1998 de la era post-internet.
Laboratory for Computer Science Massachusetts Institute of Technology Ownership Types for Safe Region-Based Memory Management in Real-Time Java Chandrasekhar.
Language Support for Lightweight transactions Tim Harris & Keir Fraser Presented by Narayanan Sundaram 04/28/2008.
 2004 Deitel & Associates, Inc. All rights reserved. Chapter 4 – Thread Concepts Outline 4.1 Introduction 4.2Definition of Thread 4.3Motivation for Threads.
VB in Context Michael B. Spring Department of Information Science and Telecommunications University of Pittsburgh Pittsburgh, Pa 15260
Role Analysis Victor Kunkac, Patric Lam, Martin Rinard Laboratory for Computer Science, MIT Presentation by George Caragea CMSC631,
November 18, 2004 Embedded System Design Flow Arkadeb Ghosal Alessandro Pinto Daniele Gasperini Alberto Sangiovanni-Vincentelli
Chapter 6 Implementing Processes, Threads, and Resources.
CprE 458/558: Real-Time Systems
0wn3rship Types John Whaley CS343 Stanford University May 19, 2004.
© Andy Wellings, 2004 Roadmap  Introduction  Concurrent Programming  Communication and Synchronization  Completing the Java Model  Overview of the.
Java How to Program, 9/e CET 3640 Professor: Dr. Reyes Álamo © Copyright by Pearson Education, Inc. All Rights Reserved.
Maria-Cristina Marinescu Martin Rinard Laboratory for Computer Science Massachusetts Institute of Technology A Synthesis Algorithm for Modular Design of.
Previous Next 06/18/2000Shanghai Jiaotong Univ. Computer Science & Engineering Dept. C+J Software Architecture Shanghai Jiaotong University Author: Lu,
1 Chapter 5: Names, Bindings and Scopes Lionel Williams Jr. and Victoria Yan CSci 210, Advanced Software Paradigms September 26, 2010.
P ARALLEL P ROCESSING I NSTITUTE · F UDAN U NIVERSITY 1.
Flex Compiler Compiler Case Study By Mee Ka Chang.
An Adaptive, Region-based Allocator for Java Feng Qian, Laurie Hendren {fqian, Sable Research Group School of Computer Science McGill.
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.
Threads in Java. History  Process is a program in execution  Has stack/heap memory  Has a program counter  Multiuser operating systems since the sixties.
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.
Lecture 2 Foundations and Definitions Processes/Threads.
Invitation to Computer Science 5 th Edition Chapter 6 An Introduction to System Software and Virtual Machine s.
Java Threads 11 Threading and Concurrent Programming in Java Introduction and Definitions D.W. Denbo Introduction and Definitions D.W. Denbo.
111 © 2002, Cisco Systems, Inc. All rights reserved.
 2004 Deitel & Associates, Inc. All rights reserved. 1 Chapter 4 – Thread Concepts Outline 4.1 Introduction 4.2Definition of Thread 4.3Motivation for.
Enhancements to Java for Real Time Systems Theresa Dsena CSE Fall 2006 Prof. Ganesan.
COMP 111 Threads and concurrency Sept 28, Tufts University Computer Science2 Who is this guy? I am not Prof. Couch Obvious? Sam Guyer New assistant.
Component Composition for Embedded Systems Using Semantic Aspect-Oriented Programming Martin Rinard Laboratory for Computer Science Massachusetts Institute.
Writing Systems Software in a Functional Language An Experience Report Iavor Diatchki, Thomas Hallgren, Mark Jones, Rebekah Leslie, Andrew Tolmach.
EEL The Real-Time Specification for Java (1)
Lecture 8 Page 1 CS 111 Online Other Important Synchronization Primitives Semaphores Mutexes Monitors.
CSCI1600: Embedded and Real Time Software Lecture 18: Real Time Languages Steven Reiss, Fall 2015.
GARBAGE COLLECTION IN AN UNCOOPERATIVE ENVIRONMENT Hans-Juergen Boehm Computer Science Dept. Rice University, Houston Mark Wieser Xerox Corporation, Palo.
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.
CSE 153 Design of Operating Systems Winter 2015 Midterm Review.
Design-Directed Programming Martin Rinard Daniel Jackson MIT Laboratory for Computer Science.
Pointer and Escape Analysis for (Multithreaded) Programs Martin Rinard MIT Laboratory for Computer Science.
Pointer and Escape Analysis for Multithreaded Programs Alexandru Salcianu Martin Rinard Laboratory for Computer Science Massachusetts Institute of Technology.
Operating Systems Unit 2: – Process Context switch Interrupt Interprocess communication – Thread Thread models Operating Systems.
The Structuring of Systems Using Upcalls By David D. Clark Presented by Samuel Moffatt.
Abstract Interpretation and Future Program Analysis Problems Martin Rinard Alexandru Salcianu Laboratory for Computer Science Massachusetts Institute of.
Sung-Dong Kim, Dept. of Computer Engineering, Hansung University Java - Introduction.
Chapter 4 – Thread Concepts
Compositional Pointer and Escape Analysis for Java programs
Data Types In Text: Chapter 6.
Course Outcomes of Object Oriented Modeling Design (17630,C604)
Compositional Pointer and Escape Analysis for Java Programs
Chapter 4 – Thread Concepts
Seminar in automatic tools for analyzing programs with dynamic memory
Other Important Synchronization Primitives
Introduction Enosis Learning.
Concurrency Specification
Introduction Enosis Learning.
Names, Binding, and Scope
CSCI1600: Embedded and Real Time Software
Foundations and Definitions
Presentation transcript:

Memory Management for Real-Time Java Wes Beebee and Martin Rinard Laboratory for Computer Science Massachusetts Institute of Technology Supported by: DARPA Program Composition for Embedded Systems (PCES) Program

Goal: Enable Use of Java for Real- Time and Embedded Systems

Vision Downloaded Java Applets Standard Java Applications Real-Time Computation In Java Unified Language/Environment Facilitates Interaction

Why Java? Type safe language, no memory corruption Reasonably modern approach Object oriented Garbage collected memory management Popular and supported… Programmers available Tools available Libraries available

Implications and Issues Heterogeneous components with different needs and goals Real-time computation User interface Data management Issues Memory management Scheduling Event management and delivery Processor allocation

Why NOT Java Unpredictable memory usage Dynamic memory allocation Allocation hidden in extensive set of libraries and native methods Allocation hidden in exception model Unpredictable execution times Garbage collection No scheduling guarantees Thread scheduling Event delivery Complex libraries and native methods

Why NOT Java Impoverished set of abstractions Threads, mutex locks, signal and wait No good way express relationship between Events in system Corresponding pieces of computation No good way to express timing expectations Real-Time Java Approach Extend library Native methods for new mechanisms

Real-Time Java Standard Goal: Augment Java to better support real-time systems Augment memory model to enable threads to avoid garbage collection pauses Augment thread scheduling model to add more control over task scheduling Augment synchronization model to include lightweight event delivery mechanism

Our View Real-time Java is a work in progress Many of extensions generate More complex programming model More possibilities for errors Our goal Isolate general principles/concepts we think will last Develop new program analyses and implementation mechanisms That help programmers use real-time extensions safely and effectively

Java Memory Models Java: single garbage-collected heap Real-time Java: multiple kinds of memories Garbage-collected heap memory Immortal memory (live for full computation) Scoped memories (live for specific subcomputations) Linear-time allocation ( LTMemory ) Variable-time allocation ( VTMemory )

Problems/Issues with Memory Model Scoped memory issues Scoped memory reference checks Scoped memory sizes Avoiding garbage collection interaction issues No-heap real-time thread access checks Priority inversions caused by indirect interactions with garbage collector

Scoped Memory Overview Standard Java Computation

Scoped Memory Overview Standard Java Computation Objects in GC Heap

Scoped Memory Overview Standard Java Computation Objects in GC Heap

Objects in GC Heap Scoped Memory Overview New Computation Typically new thread Maybe even real-time thread Standard Java Computation

Objects in GC Heap Scoped Memory Overview New Computation Typically new thread Maybe even real-time thread Standard Java Computation Scoped Memory New Thread Runs In Scoped Memory

Objects in GC Heap Scoped Memory Overview New Computation Typically new thread Maybe even real-time thread Standard Java Computation Scoped Memory Thread’s New Objects Allocated in Scoped Memory Objects

Objects in GC Heap Scoped Memory Overview New Computation Typically new thread Maybe even real-time thread Standard Java Computation Scoped Memory Objects Thread’s New Objects Allocated in Scoped Memory

Objects in GC Heap Scoped Memory Overview New Computation Typically new thread Maybe even real-time thread Standard Java Computation Scoped Memory Objects Thread’s New Objects Allocated in Scoped Memory

Objects in GC Heap Scoped Memory Overview New Computation Typically new thread Maybe even real-time thread Standard Java Computation Scoped Memory Objects Computation Terminates

Objects in GC Heap Scoped Memory Overview New Computation Typically new thread Maybe even real-time thread Standard Java Computation Scoped Memory Objects Objects in Scoped Memory Deallocated as a Unit without GC

Scoped Memory Motivation Dynamic memory allocation without GC Tie object lifetimes to computation lifetimes Eliminate need to dynamically trace out reachable objects Warning: Example illustrates primary intended use Specification allows more behaviors Scoped memories shared by multiple threads Nested scoped memories Scoped memories entered multiple times

Safety Issue for Scoped Memories: Dangling References Lifetimes of objects in scoped memory determined by lifetime of computation Must ensure that no reference goes from long-lived object to short-lived object

Nested Scoped Memories Scoped Memory Object

Referencing Constraints Scoped Memory Object Referencing Down Scopes Is NOT OK Referencing Up Scopes Is OK

Preventing Downward References Dynamic Reference Checks At every write of a reference into an object field or array element Check that written object is allocated in a scope with a lifetime at least as long as that of referred object If not, throw an exception Drawbacks Dynamic checking overhead New class of dynamic errors

Static Analysis Goal Eliminate need for dynamic checks by Statically checking that program does not violate referencing constraints Basic approach: escape analysis

What Escape Analysis Provides void compute(d,e) ———— void multiplyAdd(a,b,c) ————————— void multiply(m) ———— void add(u,v) —————— Control Flow Graph Nodes = methods Edges = invocation relationships

What Escape Analysis Provides void compute(d,e) ———— void multiplyAdd(a,b,c) ————————— void multiply(m) ———— void add(u,v) —————— Allocation Site Control Flow Graph Nodes = methods Edges = invocation relationships

What Escape Analysis Provides void compute(d,e) ———— void multiplyAdd(a,b,c) ————————— void multiply(m) ———— void add(u,v) —————— Allocation Site Object Allocated Here Does Not Escape Computation of multiplyAdd method Control Flow Graph Nodes = methods Edges = invocation relationships

Our Escape Analysis Interprocedural Analyzes interactions between methods Recaptures objects in callers of allocating methods Compositional Analyzes each method once Single analysis result that can be specialized for use in different calling contexts Suitable for multithreaded programs Analyzes interactions between threads Recaptures objects that do not escape a given multithreaded computation

Using Escape Analysis to Verify Correct Use of Scoped Memories For each computation that runs in scoped memory Check that allocated objects do not escape

Implementation FLEX compiler infrastructure ( Full Java compiler Lots of utilities and packages Support for deep program analyses and transformations Implemented scoped memories and checks Implemented escape analysis Used results to eliminate checks In applications, eliminated all checks

Experimental Results Array (Heap) Array (Scope) Tree (Heap) Tree (Scope) Water (Heap) Water (Scope) Barnes (Heap) Barnes (Scope) Benchmarks Time (sec) Scope Checks Application

Scoped Memory Sizes Scoped memory creation and size MemoryArea ma = new LTMemory(10000); “create a new scoped memory with 10,000 bytes” If try to allocate more than 10,000 bytes, implementation throws an exception Problems Java does not specify object sizes Size of given object may change during its lifetime in computation So how big to make scoped memory?

Objects in GC Heap Modularity Problems Scoped Memory Size Determined Here Standard Java Computation Scoped Memory Objects Required Size Determined by Behavior of Code in this Computation

Objects in GC Heap Modularity Problems Scoped Memory Size Determined Here Standard Java Computation Scoped Memory Objects If change program, size may need to change! Amount of allocated memory becomes part of interface!

More Issues Different executions may allocate different amounts of data Lots of hidden allocation in libraries Difficult to find out how much memory is really allocated If change implementation, may need to change scoped memory size in clients

Analysis Solution Analyze program to symbolically compute allocated memory sizes Input variables Object sizes Compiler knows object sizes, can conservatively generate scoped memory sizes

Interaction with Garbage Collector Standard Collector Assumptions Can interrupt computation at any point Can suspend for unbounded time Real-Time Java extension No-Heap Real-Time Threads Can Access Immortal memory Scoped memory Do not interact with GC heap AT ALL Can run asynchronously with GC Immortal Scoped GC Heap

No-Heap Real-Time Thread Checks Dynamically check that no-heap real-time threads never access a location containing a reference into garbage-collected heap At every read, check to make sure result does not point into garbage-collected heap At every write, check to make sure not overwriting reference into GC heap If check fails, throw exception Drawbacks Dynamic checking overhead New class of dynamic errors

Implementation FLEX compiler infrastructure ( Implemented no-heap real-time threads Implemented access checks Measured performance with and without checks

Experimental Results ArrayTreeWater Benchmark Time (sec) Scope Checks Heap Checks Application

Program Analysis for Eliminating Checks Control-flow analysis to identify code that may execute in no-heap real-time thread Global value-flow analysis Tags each value that points to GC heap Identifies all locations into which these values may flow Combine results Look at all no-heap real-time thread code Check statically for access violations

Analysis Issues and Solutions Complicated, whole-program analysis Simple annotations can enable local analysis Annotate each reference with source Scoped memory Immortal memory Heap memory Annotation checker validates annotations Result: Scalable analysis Eliminate checks, eliminate programming errors

Indirect Priority Inversions Standard Java Thread No-heap Thread Lock Acquire Garbage Collector Lock Acquire Interaction Between Resource Sharing and Garbage Collection

Indirect Priority Inversions Standard Java Thread No-heap Thread Lock Acquire Garbage Collector Lock Acquire Interaction Between Resource Sharing and Garbage Collection Blocks

Indirect Priority Inversions Standard Java Thread No-heap Thread Lock Acquire Garbage Collector Lock Acquire No-heap thread must wait for standard Java thread to release lock Standard thread must wait for GC to finish (heap inconsistent until it finishes) No-heap thread must wait for GC!

Using Non-Blocking Synchronization to Eliminate Indirect Priority Inversions Standard Java Thread No-heap Thread Start Atomic Region Garbage Collector Start Atomic Region End Atomic Region Does Not Block! Abort, Retry

Implementation Status Non-blocking synchronization implemented for memory management primitives Useful when threads share scoped memory Uses non-blocking synchronization instructions from processor Software implementation underway for general atomic regions

Goal Dangling references for scoped memories Resource needs of computations Isolating computations from garbage collector Ensure threads with real-time constraints don’t access garbage collected data Eliminate indirect interactions Our view Dynamic checks inadequate Statically verify correct use, eliminate checks Enable safe real-time code to interact successfully with code that accesses GC data Issues and Complications

Broader View of Real-Time Java Java is best suited to express “batch” computations on objects Not so good for control in asynchronous, parallel, distributed, time-aware systems Inadequate for design/requirements Can be part of solution, but only a part

Multiple Perspectives Any system has many desired properties Data structure invariants Flow of data between different components Timing requirements for computations Each property is inherently partial Many properties are best expressed as Declarative constraints NOT translatable into implementation

Design Conformance Object Referencing Relationships Timing Constraints Dataflow Interactions Implementation Check that implementation conforms to design properties

Future Scheduling and event delivery More precise referencing relationship analysis Completely characterize aliasing behavior More flexible memory management algorithms that preserve predictability More flexible regions Immediate deallocation Less restricted memory access constraints for real- time threads Design conformance for more control-oriented properties

Summary Real-time Java code coexists and interacts with standard Java code New complications (overhead + failure modes) Scoped memory checks Scoped memory sizes No-heap real-time threads Indirect priority inversions Attacked with program analysis Future: scheduling and timing