Hard Real-Time Garbage Collection in Java Virtual Machines

Similar documents
Configuring the Heap and Garbage Collector for Real- Time Programming.

JamaicaVM Java for Embedded Realtime Systems

Garbage Collection. Hwansoo Han

Limits of Parallel Marking Garbage Collection....how parallel can a GC become?

Hard Real-Time Garbage Collection in the Jamaica Virtual Machine

Garbage Collection Algorithms. Ganesh Bikshandi

Reference Counting. Reference counting: a way to know whether a record has other users

A High Integrity Distributed Deterministic Java Environment. WORDS 2002 January 7, San Diego CA

Runtime. The optimized program is ready to run What sorts of facilities are available at runtime

Reference Counting. Reference counting: a way to know whether a record has other users

CS577 Modern Language Processors. Spring 2018 Lecture Garbage Collection

Garbage Collection. Vyacheslav Egorov

Lecture 13: Garbage Collection

Garbage Collection (2) Advanced Operating Systems Lecture 9

Acknowledgements These slides are based on Kathryn McKinley s slides on garbage collection as well as E Christopher Lewis s slides

Sustainable Memory Use Allocation & (Implicit) Deallocation (mostly in Java)

Programming Language Implementation

Shenandoah An ultra-low pause time Garbage Collector for OpenJDK. Christine H. Flood Roman Kennke

Managed runtimes & garbage collection. CSE 6341 Some slides by Kathryn McKinley

Garbage Collection. CS 351: Systems Programming Michael Saelee

Managed runtimes & garbage collection

Simple Garbage Collection and Fast Allocation Andrew W. Appel

Implementation Garbage Collection

Eliminating External Fragmentation in a Non-Moving Garbage Collector for Java

Heap Compression for Memory-Constrained Java

Garbage Collection. Weiyuan Li

JVM Memory Model and GC

Run-Time Environments/Garbage Collection

Lecture Notes on Advanced Garbage Collection

Lecture 15 Garbage Collection

Real-Time Garbage Collection Panel JTRES 2007

CS 4120 Lecture 37 Memory Management 28 November 2011 Lecturer: Andrew Myers

Run-time Environments -Part 3

Garbage Collection. Steven R. Bagley

Run-time Environments - 3

A new Mono GC. Paolo Molaro October 25, 2006

Motivation for Dynamic Memory. Dynamic Memory Allocation. Stack Organization. Stack Discussion. Questions answered in this lecture:

Agenda. CSE P 501 Compilers. Java Implementation Overview. JVM Architecture. JVM Runtime Data Areas (1) JVM Data Types. CSE P 501 Su04 T-1

CS 345. Garbage Collection. Vitaly Shmatikov. slide 1

Algorithms for Dynamic Memory Management (236780) Lecture 4. Lecturer: Erez Petrank

6.172 Performance Engineering of Software Systems Spring Lecture 9. P after. Figure 1: A diagram of the stack (Image by MIT OpenCourseWare.

Glacier: A Garbage Collection Simulation System

Memory management has always involved tradeoffs between numerous optimization possibilities: Schemes to manage problem fall into roughly two camps

Automatic Garbage Collection

Attila Szegedi, Software

Garbage Collection. Akim D le, Etienne Renault, Roland Levillain. May 15, CCMP2 Garbage Collection May 15, / 35

CMSC 330: Organization of Programming Languages

A program execution is memory safe so long as memory access errors never occur:

Compilers. 8. Run-time Support. Laszlo Böszörmenyi Compilers Run-time - 1

CSE P 501 Compilers. Memory Management and Garbage Collec<on Hal Perkins Winter UW CSE P 501 Winter 2016 W-1

Automatic Memory Management

Dynamic Storage Allocation

Garbage Collection (1)

G1 Garbage Collector Details and Tuning. Simone Bordet

CS842: Automatic Memory Management and Garbage Collection. Mark and sweep

CS 153 Design of Operating Systems

Concurrent Garbage Collection

Schism: Fragmentation-Tolerant Real-Time Garbage Collection. Fil Pizlo *

CMSC 330: Organization of Programming Languages

Name, Scope, and Binding. Outline [1]

Compiler Construction D7011E

High-Level Language VMs

Memory Allocation. Static Allocation. Dynamic Allocation. Dynamic Storage Allocation. CS 414: Operating Systems Spring 2008

Decoupled Root Scanning in Multi-Processor Systems

Design Issues. Subroutines and Control Abstraction. Subroutines and Control Abstraction. CSC 4101: Programming Languages 1. Textbook, Chapter 8

JAVA PERFORMANCE. PR SW2 S18 Dr. Prähofer DI Leopoldseder

Garbage Collection. Lecture Compilers SS Dr.-Ing. Ina Schaefer. Software Technology Group TU Kaiserslautern. Ina Schaefer Garbage Collection 1

Garbage Collection Techniques

CA341 - Comparative Programming Languages

Exploiting the Behavior of Generational Garbage Collector

Java & Coherence Simon Cook - Sales Consultant, FMW for Financial Services

Hardware-Supported Pointer Detection for common Garbage Collections

CMSC 330: Organization of Programming Languages. Memory Management and Garbage Collection

High Performance Managed Languages. Martin Thompson

Lecture 15 Advanced Garbage Collection

Robust Memory Management Schemes

Lecture Notes on Garbage Collection

The Z Garbage Collector An Introduction

Cooperative Memory Management in Embedded Systems

Reference Object Processing in On-The-Fly Garbage Collection

The Z Garbage Collector Scalable Low-Latency GC in JDK 11

Parallel GC. (Chapter 14) Eleanor Ainy December 16 th 2014

G Programming Languages - Fall 2012

Shenandoah: An ultra-low pause time garbage collector for OpenJDK. Christine Flood Principal Software Engineer Red Hat

Java Internals. Frank Yellin Tim Lindholm JavaSoft

Shenandoah: Theory and Practice. Christine Flood Roman Kennke Principal Software Engineers Red Hat

Contents. 8-1 Copyright (c) N. Afshartous

Java Performance Tuning

Myths and Realities: The Performance Impact of Garbage Collection

Verifying a Concurrent Garbage Collector using a Rely-Guarantee Methodology

Memory Management. Chapter Fourteen Modern Programming Languages, 2nd ed. 1

Memory Management. Didactic Module 14 Programming Languages - EEL670 1

Cycle Tracing. Presented by: Siddharth Tiwary

Memory Management: The Details

The C4 Collector. Or: the Application memory wall will remain until compaction is solved. Gil Tene Balaji Iyengar Michael Wolf

Generation scavenging: A non-disruptive high-performance storage reclamation algorithm By David Ungar

Name: CIS 341 Final Examination 10 December 2008

MC 2 : High-Performance Garbage Collection for Memory-Constrained Environments

Dynamic Memory Allocation

Java Performance Tuning From A Garbage Collection Perspective. Nagendra Nagarajayya MDE

Transcription:

Hard Real-Time Garbage Collection in Java Virtual Machines... towards unrestricted real-time programming in Java Fridtjof Siebert, IPD, University of Karlsruhe 1 Jamaica Systems

Structure Exisiting GC Techniques Definition of Real-Time Garbage Collection Jamaica s Garbage Collector Example Conclusion 2 Jamaica Systems

Garbage Collection Automatic reclamation of unused memory Root Scanning Mark Sweep Compact 3 Jamaica Systems

Why is Real-Time GC so difficult in Java? Allocation is an integral part of Java programming Java is Multi-Threaded Java Objects and Arrays may be of very different sizes 4 Jamaica Systems

Existing Implementations Blocking Generational, Age Based Heap: GCed area old area Age: young old Concurrent GC as separate thread Real-Time -Threads Real-Time code uses subset of Java langage 5 Jamaica Systems

Definition of Real-Time GC Real-Time Garbage Collection means Hard upper bounds for execution time of any operation. Any operation must succeed in desired way Hard upper bound for pre-emption delay For the implementation to be useful Upper bounds for execution time must be short (in the order of µsec/nsec) 6 Jamaica Systems

Definition of Real-Time GC Operations that are affected by GC are Memory reads (accesses to objects, arrays) (read-barrier code?) Memory writes (write-barrier code?) Allocation of objects (recycling work!) 7 Jamaica Systems

Real Time Garbage Collection in the Jamaica Virtual Machine 8 Jamaica Systems

Root Scanning Root scanning typically causes the biggest problems in real-time garbage collection: Need to stop threads for a long time! In the Jamaica Virtual Machine: All life refs are also stored on the heap There is only one single root pointer Root scanning is a real-time operation But, additional overhead of writing 2-3 refs on every call (using write-barrier!) 9 Jamaica Systems

Fragmentation Avoid fragmentation without using handles and moving objects: Heap is array of blocks of the same size At least one such block used for every Java object allocated Larger objects are represented as a graph of these blocks 10 Jamaica Systems

Object Layout Block 1: Block 2: Block 3: Type Field 3 Field 6 Field 1 Field 4 Field 7 Field 2 Field 5 Link Link 11 Jamaica Systems

GC Algorithm Simple incremental mark & sweep garbage collector Does not know about Java objects, just works with blocks Tagging is used to identify references One word per object reserved for colour Root Scanning Mark Sweep Compact 12 Jamaica Systems

Heap Layout Blocks tag bits Colours 13 Jamaica Systems

GC Activation A GC running as a separate thread with no information on the application might not recycle enough memory or use too much CPU time. Couple GC activity with allocation in application threads. Amount of GC work is determined dynamically as function of amount of free memory 14 Jamaica Systems

GC Activiation With this Amount of GC work is adjusted dynamically as needed by application No allocation means no GC work at all GC can guarantee an upper bound of allocation time for any application with limited memory demand Trade off between this upper bound and heap size is possible 15 Jamaica Systems

Example public class HelloWorld { public static void main(string[] args) { int n,s,c; if (args.length > 0) { n = Integer.parseInt(args[0]); } else { n = 30; } s = 0; c = 14; for(int i=0; i<n; i++) { String s1 = " ".substring(s+14); String s2 = " ".substring(s/2+7); System.out.println(s1+"Hello "+s2+"world!"); s = s + c / 4; c = c - s / 4; } } } 16 Jamaica Systems

Example > jamaica -analyse 5 HelloWorld > HelloWorld Hello World! Hello World! Hello World! [...] ### Application used at most 165664 bytes for Java heap ### Non-Java heap memory used: 49808 bytes. ### ### heapsize worst case allocation overhead: ### 373k 7 ### 319k 10 ### 292k 14 ### 280k 16 ### 265k 21 ### 251k 28 ### 239k 40 ### 219k 138 ### 215k 286 > 17 Jamaica Systems

Example Determination of worst-case execution time of new StringBuffer() Determine number of blocks: > numblocks java.lang.stringbuffer 1 Worst-case execution time: wcet = numblocks max gc_unit wcet gc_unit wcet 265k = 1 21 2µs = 42µs wcet 373k = 1 7 2µs = 14µs 18 Jamaica Systems

Conclusion JamaicaVM allows real-time programming using the full Java language Having hard real-time guarantees on all parts of the programming language, including allocation, will ease software development for more complex real-time systems. 19 Jamaica Systems

3-Colour Marking Colours: white: not marked yet grey: known to be reachable, but not scanned yet black: known to be reachable and scanned GC-Invariant during Mark-phase: There is no reference from a black object to a white object. No grey objects left white objects are free 20 Jamaica Systems

Colour Encoding Colour values: black: -1 white: 0 grey: any other value Grey objects form a linked listed, the colour value is used to refer to the next element. constant time addition of grey objects constant time retrieval of a grey object GC cycle completed in O(allocated) 21 Jamaica Systems

Experimental Data Cost of exact root scanning: Average number of references stored on a call for three large applications: 2.73 2.51 2.02 Application: HotJava SwingSet TurboJ 22 Jamaica Systems

Experimental Data Cost for object accesses using handles (scenario 1) and blocks (scenario 2) Scenario 1 2 1 2 1 2 Arrays 67 63 38 49 4.5 4.9 Objects 43 29 11 8.4 2.4 1.3 Application: HotJava (10 6 ) SwingSet (10 7 ) TurboJ (10 9 ) 23 Jamaica Systems

Array Layout Blocks 3-5 (data): data[0] data[1] data[2] Block 1 (header): Block 2 (links): data[3] Array Type Elements 0..3 data[4] Length: 11 Elements 4..7 data[5] Depth: 2 Elements 8..10 data[6] Elements 0..10 data[7] data[8] data[9] data[10] 24 Jamaica Systems