Simple Garbage Collection and Fast Allocation Andrew W. Appel

Similar documents
Lecture 13: Garbage Collection

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

Garbage Collection. Hwansoo Han

Managed runtimes & garbage collection

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

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

Run-Time Environments/Garbage Collection

Dynamic Storage Allocation

Virtual Memory Primitives for User Programs

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

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

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

Exploiting the Behavior of Generational Garbage Collector

CS 345. Garbage Collection. Vitaly Shmatikov. slide 1

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

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

Hard Real-Time Garbage Collection in Java Virtual Machines

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

Memory Management. Memory Management... Memory Management... Interface to Dynamic allocation

Heap Management. Heap Allocation

Automatic Garbage Collection

Garbage Collection Algorithms. Ganesh Bikshandi

CS577 Modern Language Processors. Spring 2018 Lecture Garbage Collection

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

CS 536 Introduction to Programming Languages and Compilers Charles N. Fischer Lecture 11

The SURE Architecture

Garbage Collection. Steven R. Bagley

Implementation Garbage Collection

CMSC 330: Organization of Programming Languages

High-Level Language VMs

15 Sharing Main Memory Segmentation and Paging

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

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

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

CS 241 Honors Memory

Garbage Collection. Weiyuan Li

Deallocation Mechanisms. User-controlled Deallocation. Automatic Garbage Collection

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

Tick: Concurrent GC in Apache Harmony

16 Sharing Main Memory Segmentation and Paging

CMSC 330: Organization of Programming Languages

CS 553 Compiler Construction Fall 2006 Project #4 Garbage Collection Due November 27, 2005

Heap Compression for Memory-Constrained Java

Automatic Memory Management

JVM Memory Model and GC

Concurrent Garbage Collection

CS4500/5500 Operating Systems File Systems and Implementations

Garbage Collection Basics

Garbage Collection. Vyacheslav Egorov

Run-time Environments -Part 3

Memory Allocation. Copyright : University of Illinois CS 241 Staff 1

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

Freeing memory is a pain. Need to decide on a protocol (who frees what?) Pollutes interfaces Errors hard to track down

Lecture 15 Garbage Collection

Garbage Collection (1)

Garbage Collection Techniques

Intrusion Detection and Malware Analysis

Lecture Conservative Garbage Collection. 3.2 Precise Garbage Collectors. 3.3 Other Garbage Collection Techniques

Write Barrier Removal by Static Analysis

COMPUTER ORGANIZATION & ARCHITECTURE

Java Performance Tuning

HOT-Compilation: Garbage Collection

The Generational Hypothesis

A.Arpaci-Dusseau. Mapping from logical address space to physical address space. CS 537:Operating Systems lecture12.fm.2

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

Older-First Garbage Collection in Practice: Evaluation in a Java Virtual Machine

CSE 120. Translation Lookaside Buffer (TLB) Implemented in Hardware. July 18, Day 5 Memory. Instructor: Neil Rhodes. Software TLB Management

Heap, Variables, References, and Garbage. CS152. Chris Pollett. Oct. 13, 2008.

Reducing the Latency of a Real-time Garbage Collector. in the Appel-Ellis-Li real-time garbage collector be proportional only to the

Operating Systems Memory Management. Mathieu Delalandre University of Tours, Tours city, France

Freeing memory is a pain. Need to decide on a protocol (who frees what?) Pollutes interfaces Errors hard to track down

198:231 Intro to Computer Organization. 198:231 Introduction to Computer Organization Lecture 14

Memory Management! How the hardware and OS give application pgms:" The illusion of a large contiguous address space" Protection against each other"

One-Slide Summary. Lecture Outine. Automatic Memory Management #1. Why Automatic Memory Management? Garbage Collection.

CS 162 Operating Systems and Systems Programming Professor: Anthony D. Joseph Spring Lecture 13: Address Translation

Hardware-Supported Pointer Detection for common Garbage Collections

Garbage Collection. CS 351: Systems Programming Michael Saelee

CS61C : Machine Structures

A new Mono GC. Paolo Molaro October 25, 2006

Harmony GC Source Code

Run-time Environments

Garbage-First Garbage Collection by David Detlefs, Christine Flood, Steve Heller & Tony Printezis. Presented by Edward Raff

Run-time Environments

Garbage Collecting Reactive Real-Time Systems

A Tour to Spur for Non-VM Experts. Guille Polito, Christophe Demarey ESUG 2016, 22/08, Praha

Chapter 8 Virtual Memory

SABLEJIT: A Retargetable Just-In-Time Compiler for a Portable Virtual Machine p. 1

Process size is independent of the main memory present in the system.

How do we mark reachable objects?

Introduction to Computer Systems. Exam 2. April 10, Notes and calculators are permitted, but not computers.

Binding and Storage. COMP 524: Programming Language Concepts Björn B. Brandenburg. The University of North Carolina at Chapel Hill

Buffer overflow background

Dual-Mode Garbage Collection. Patrick M Sansom. University of Glasgow, Glasgow, Scotland. December 1991.

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

CS 31: Intro to Systems Virtual Memory. Kevin Webb Swarthmore College November 15, 2018

MEMORY MANAGEMENT HEAP, STACK AND GARBAGE COLLECTION

CS842: Automatic Memory Management and Garbage Collection. GC basics

THEORY OF COMPILATION

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2017 Lecture 7

Operating Systems and Computer Networks. Memory Management. Dr.-Ing. Pascal A. Klein

Transcription:

Simple Garbage Collection and Fast Allocation Andrew W. Appel Presented by Karthik Iyer

Background Motivation Appel s Technique Terminology Fast Allocation Arranging Generations Invariant GC Working Heuristic Handling Assignments Handling Registers Conclsion Questions Agenda

Background Modern Computers Automatic GC Mark and Sweep Parses and marks the object graph DFS Unmarked objects in free list O(size of mem) Copy Collectors Copies live objects from src to dst regions Src and dst flip O(live object mem)

Background contd Key observations Newer objects point to old ones Young object more likely to become garbage Generational GC Memory divided into regions Objects of similar age same region GC of region x => GC of regions y < x Not suitable for all languages Handling Reverse Pointers Entry Table Lieberman & Hewitt Special VM Hardware, marking pages Moon List of pointers - Ungar Cheney s Algorithm If a root R points in dst, object already copied Else, copy the object, store a forwarding pointer, update NEXT and SCAN

Motivation In a Generational GC Setup, lower bound for reclamation is very low, close to zero Why? All the objects in the collected region are dead Allocation may take more time then collection Technique for fast allocation When to ask memory from OS? Need a way to organize generations Also a Heuristic to aid decisions

Appel s Technique Divide heap into two regions Copy from Newer to Older Older Newer Why only two regions? Two generations maximize space for the allocator Large space reduces GC cycles, avoids unnecessary elevation of objects, reduces copying Other (will visit later)

Appel s Technique contd Uses Cheney s algorithm A technique for fast allocation A way to layout heap Heuristic to aid memory management based on mutator behavior A way to keep track of reverse pointers Unix implementation

Terminology Assignment A modification to the records in the older region such that he record is made to point to a newer region Minor Collection GC of the Newer Region. Appends live objects into Older Region. Major Collection GC of the Older Region. Retains live objects in the Older Region Free Space Pointer (FSP) Pointer to first free byte in the Newer Region Free Space Limit End of the Newer Region Inaccessible Page A dedicated page access to which triggers GC as Newer Region is full

Fast Allocation Unallocated region is continous CONS(A,B) Test FSP below Limit, trigger GC if at limit FSP = FSP -2 Store A, B and return FSP Overhead of CONS Test executed by VM handler. Page Fault if FSP hits inaccessible page On a VAX, auto decrement FSP while store Hence overhead Zero

Variable Sized Records Many techniques to handle Associate tag with object Allocate objects in different regions based on size Type System map in a statically typed language We use tags Issues Allocation is difficult, may span beyond region Two word records not an issue as regions boundaries are even Solution Allocate in reverse order If last word fits, rest is guaranteed to fit Page Fault if last word hits inaccessible page

Arranging Generations Arrange heap such that inaccessible page at one end of heap Unix Memory Layout text bss text heap stack Inaccessible Page Unix Program Break Newer Region Starts mid-heap and grows towards inaccessible page Older Region Starts beginning of heap and grows towards mid-heap point text bss Older text heap Newer stack

Invariant A two region copying collector runs out of space if there is not enough free space in dst region to fit src region live objects Hence M > 2A where M heap size, A mutator requirement If A approaches M/2, GC performance degrades Why? Too many collections For good performance, M >> 2A

Heap Organization GC Working Older Reserve textnewer Free Reserve Free space in Older Region Free Free space in the Newer Region Working Allocation happens in Free area until inaccessible page is hit (Minor Collection - MiC Triggered) MiC copies live data (x) at the end of Older Region Remaining free space beyond x, is divided into equal regions to accommodate Reserve and Free regions

GC Working - Illustration Allocation Older Reserve textnewer Free Older Reserve textnewer Free Minor Collection Triggered Older X text Empty Older X Reservetext Free

GC Working contd. At some point, Older region fills out appending X of a MiC crosses the Older Region Boundary (h) Major Collection (MaC) Triggered How do we ensure enough space for live objects in Older Region (Y)? Copy Y after X Since we crossed h after appending X to Y, Y < M/2 Free Space = M/2, hence Y fits Bring back Y+X to beginning of heap, call it Older Region

GC Working Illustration contd h Older text Free h text Older (Y) Free Older Reservetext Free

When to ask for Memory? Heuristic! Let ϒ be M/A If ϒ < 2, mutator runs out of space If ϒ = 2, GC performance degrades ϒ >> 2 Depending on compiler and language GC performance varies based on ϒ But higher ϒ => better GC performance Let ϒ be required ϒ for required performance

Heuristic contd Allocated some space initially may be based on predicted value of A If A grows ask for more memory from OS How to know A is growing? When to trigger? After MaC, if ϒ < ϒ No space when appending Y to X. ϒ < 2 After an MiC, Free region not enough for a huge object. Most probably A > M/ ϒ Use UNIX brk() for more memory Calculating A, hence ϒ in a multi-generation setup is difficult

Keeping track of Assignments Root Set Globals, Registers, Stack and Reverse Pointers Stack in heap saves tracking stack frames efficient How to keep track of assignments? A linked list or a list of vectors of all Reverse Pointers Compiler adds code to insert Reverse Pointers to the list during assignment Compiler runs checks to see if an assignment is a Reverse Pointer

Assignments contd Multi-generational setup After each MiC, need to maintain pruned lists. Difficult Remember our Two region setup? List will empty after each Mic. Advantage. Root list overhead 8 instructions 4 for list update 4 to examine a record List Traversal overhead to check duplicate?

Handling Registers Registers are part of Root set During Traps and GC, Root set modified But Traps require registers for execution Root Set registers pushed onto stack and modified Can run a check to learn about what registers pushed and the order

Conclusion Fast allocation Simple Algorithm Two regions No entry tables Reverse pointers part of heap. Less overhead to manage these pointers Easy to implement in UNIX

Questions What does fast mean? How many instructions other collectors take to allocate? Compare. Isn t fast too tied to a machine? Assessing A may be skewed due to list of reverse pointers in heap? Why size of Free Space reduced after each MiC?