Mark and Split Kostis Sagonas Uppsala Univ., Sweden NTUA, Greece Jesper Wilhelmsson Uppsala Univ., Sweden.

Slides:



Advertisements
Similar presentations
An Implementation of Mostly- Copying GC on Ruby VM Tomoharu Ugawa The University of Electro-Communications, Japan.
Advertisements

Singly linked lists Doubly linked lists
Garbage collection David Walker CS 320. Where are we? Last time: A survey of common garbage collection techniques –Manual memory management –Reference.
Steve Blackburn Department of Computer Science Australian National University Perry Cheng TJ Watson Research Center IBM Research Kathryn McKinley Department.
Introduction to Memory Management. 2 General Structure of Run-Time Memory.
Chapter 4: Trees Part II - AVL Tree
Garbage Collection What is garbage and how can we deal with it?
CSC 213 – Large Scale Programming. Today’s Goals  Consider what new does & how Java works  What are traditional means of managing memory?  Why did.
Garbage Collection  records not reachable  reclaim to allow reuse  performed by runtime system (support programs linked with the compiled code) (support.
Garbage Collection CSCI 2720 Spring Static vs. Dynamic Allocation Early versions of Fortran –All memory was static C –Mix of static and dynamic.
Math 130 Introduction to Computing Sorting Lecture # 17 10/11/04 B Smith: Save until Week 15? B Smith: Save until Week 15? B Smith: Skipped Spring 2005?
An On-the-Fly Mark and Sweep Garbage Collector Based on Sliding Views Hezi Azatchi - IBM Yossi Levanoni - Microsoft Harel Paz – Technion Erez Petrank –
CPSC 388 – Compiler Design and Construction
Chapter 8 Runtime Support. How program structures are implemented in a computer memory? The evolution of programming language design has led to the creation.
ParMarkSplit: A Parallel Mark- Split Garbage Collector Based on a Lock-Free Skip-List Nhan Nguyen Philippas Tsigas Håkan Sundell Distributed Computing.
Memory Management. History Run-time management of dynamic memory is a necessary activity for modern programming languages Lisp of the 1960’s was one of.
1 The Compressor: Concurrent, Incremental and Parallel Compaction. Haim Kermany and Erez Petrank Technion – Israel Institute of Technology.
CS 1114: Data Structures – memory allocation Prof. Graeme Bailey (notes modified from Noah Snavely, Spring 2009)
MOSTLY PARALLEL GARBAGE COLLECTION Authors : Hans J. Boehm Alan J. Demers Scott Shenker XEROX PARC Presented by:REVITAL SHABTAI.
FALL 2004CENG 351 Data Management and File Structures1 External Sorting Reference: Chapter 8.
FALL 2006CENG 351 Data Management and File Structures1 External Sorting.
Garbage collection David Walker CS 320. Where are we? Last time: A survey of common garbage collection techniques –Manual memory management –Reference.
CSE 373 Data Structures Lecture 12
An Adaptive, Region-based Allocator for Java Feng Qian & Laurie Hendren 2002.
B + -Trees (Part 1). Motivation AVL tree with N nodes is an excellent data structure for searching, indexing, etc. –The Big-Oh analysis shows most operations.
B + -Trees (Part 1) COMP171. Slide 2 Main and secondary memories  Secondary storage device is much, much slower than the main RAM  Pages and blocks.
1 Reducing Generational Copy Reserve Overhead with Fallback Compaction Phil McGachey and Antony L. Hosking June 2006.
Linked lists and memory allocation Prof. Noah Snavely CS1114
Reference Counters Associate a counter with each heap item Whenever a heap item is created, such as by a new or malloc instruction, initialize the counter.
1 CSE 326: Data Structures: Sorting Lecture 17: Wednesday, Feb 19, 2003.
Memory Management Last Update: July 31, 2014 Memory Management1.
Memory Allocation CS Introduction to Operating Systems.
Taking Off The Gloves With Reference Counting Immix
ICS 220 – Data Structures and Algorithms Week 7 Dr. Ken Cosh.
Brought to you by Max (ICQ: TEL: ) February 5, 2005 Advanced Data Structures Introduction.
Heaps, Heapsort, Priority Queues. Sorting So Far Heap: Data structure and associated algorithms, Not garbage collection context.
Fast Conservative Garbage Collection Rifat Shahriyar Stephen M. Blackburn Australian National University Kathryn S. M cKinley Microsoft Research.
Chapter 8 – Main Memory (Pgs ). Overview  Everything to do with memory is complicated by the fact that more than 1 program can be in memory.
1 Joe Meehean.  Problem arrange comparable items in list into sorted order  Most sorting algorithms involve comparing item values  We assume items.
Message Analysis-Guided Allocation and Low-Pause Incremental Garbage Collection in a Concurrent Language Konstantinos Sagonas Jesper Wilhelmsson Uppsala.
Runtime Environments. Support of Execution  Activation Tree  Control Stack  Scope  Binding of Names –Data object (values in storage) –Environment.
OOPLs /FEN March 2004 Object-Oriented Languages1 Object-Oriented Languages - Design and Implementation Java: Behind the Scenes Finn E. Nordbjerg,
An experimental study of priority queues By Claus Jensen University of Copenhagen.
Arboles B External Search The algorithms we have seen so far are good when all data are stored in primary storage device (RAM). Its access is fast(er)
CPSC 404, Laks V.S. Lakshmanan1 External Sorting Chapter 13: Ramakrishnan & Gherke and Chapter 2.3: Garcia-Molina et al.
11/26/2015IT 3271 Memory Management (Ch 14) n Dynamic memory allocation Language systems provide an important hidden player: Runtime memory manager – Activation.
Sorting: Implementation Fundamental Data Structures and Algorithms Klaus Sutner February 24, 2004.
Memory Management -Memory allocation -Garbage collection.
Internal and External Sorting External Searching
CS 241 Discussion Section (2/9/2012). MP2 continued Implement malloc, free, calloc and realloc Reuse free memory – Sequential fit – Segregated fit.
CS 241 Discussion Section (12/1/2011). Tradeoffs When do you: – Expand Increase total memory usage – Split Make smaller chunks (avoid internal fragmentation)
Heap Sort Uses a heap, which is a tree-based data type Steps involved: Turn the array into a heap. Delete the root from the heap and insert into the array,
CS412/413 Introduction to Compilers and Translators April 21, 1999 Lecture 30: Garbage collection.
Reference Counting. Reference Counting vs. Tracing Advantages ✔ Immediate ✔ Object-local ✔ Overhead distributed ✔ Very simple Trivial implementation for.
Runtime Environments Chapter 7. Support of Execution  Activation Tree  Control Stack  Scope  Binding of Names –Data object (values in storage) –Environment.
Sorting With Priority Queue In-place Extra O(N) space
Garbage Collection What is garbage and how can we deal with it?
Inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture 7 – More Memory Management Lecturer PSOE Dan Garcia
Concepts of programming languages
Map interface Empty() - return true if the map is empty; else return false Size() - return the number of elements in the map Find(key) - if there is an.
Data Structures and Algorithms
Chapter 12 Memory Management
CENG 351 Data Management and File Structures
CSE 373 Data Structures and Algorithms
Inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture 7 – More Memory Management Lecturer PSOE Dan Garcia
Program-level Adaptive Memory Management
Reference Counting.
Garbage Collection What is garbage and how can we deal with it?
Presentation transcript:

Mark and Split Kostis Sagonas Uppsala Univ., Sweden NTUA, Greece Jesper Wilhelmsson Uppsala Univ., Sweden

Mark and Split2 Copying vs. Mark-Sweep Copying Collection + GC time proportional to the size of the live data set - requires non-negligible additional space moves objects compacts the heap Mark-Sweep Collection - GC time proportional to the size of the collected heap + requires relatively little additional space non-moving collector may require compaction

Mark and Split3 Mark-Sweep Collection Algorithm proc mark_sweep_gc()  foreach root  rootset do mark( * root) sweep() proc mark(object)  if marked(object) = false  marked(object) := true foreach pointer in object do mark( * pointer)

Mark and Split4 Variants of Mark-Sweep Lazy sweeping [Hughes 1982; Boehm 2000] –Defer the sweep phase until allocation time and then perform it on a demand-driven (“pay-as-you-go”) way –Improves paging and/or cache behavior Selective sweeping [Chung, Moon, Ebcioĝlu, Sahlin] –During marking, record the addresses of all marked objects in an array (outside the heap) –Once marking is finished, sort these addresses –Perform the sweep phase selectively guided by the sorted addresses

Mark and Split5 Mark-Split Collection: Idea Rather than (lazily/selectively) sweeping the heap after marking to locate free areas, maintain information about them during marking. More specifically, optimistically assume that the entire heap will be free after collection and let the mark phase “repair” the free list by “rescuing” the memory of live objects.

Mark and Split6 Mark-Split Collection: Illustration Heap to be collected One free interval Marking splits a free interval Two free intervals Marking splits another free interval Three free intervals Marking does not always increase the number of free intervals! Three free intervals Marking can actually decrease the number of free intervals! Two free intervals

Mark and Split7 proc mark_sweep_gc()  foreach root  rootset do mark( * root) sweep() proc mark(object)  if marked(object) = false  marked(object) := true foreach pointer in object do mark( * pointer) proc mark_?????_gc()  foreach root  rootset do mark( * root) proc mark(object)  if marked(object) = false  marked(object) := true foreach pointer in object do mark( * pointer) proc mark_sweep_gc()  foreach root  rootset do mark( * root) sweep() proc mark(object)  if marked(object) = false  marked(object) := true foreach pointer in object do mark( * pointer) proc mark_split_gc()  insert_interval(heap_start, heap_end) foreach root  rootset do mark( * root) proc mark(object)  if marked(object) = false  marked(object) := true split(find_interval(&object), object) foreach pointer in object do mark( * pointer) Mark-Split Collection: Algorithm (1)

Mark and Split8 Mark-Split Collection: Algorithm (2) proc split(interval, object)  objectEnd := &object + size(object) keepLeft := keep_interval(&object – interval.start) keepRight := keep_interval(interval.end – objectEnd) if keepLeft  keepRight  insert_interval(objectEnd, interval.end) // Case 1 interval.end := &object else if keepLeft  interval.end := &object // Case 2 else if keepRight  interval.start := objectEnd// Case 3 else remove_interval(interval.end)// Case 4 funct keep_interval(size)  return size  T // T is a threshold

Mark and Split9 Mark-Split Collection: Data Structure For storing the free intervals we need a data structure that allows for: –Fast location of an interval (find_interval ) –Fast insertion of new intervals (insert_interval ) Data structures with these properties are: –Balanced search trees –Splay trees –Skip lists –… In our implementation we used the AA tree [Andersson 1993]

Mark and Split10 Mark-Split Collection: Best Cases When nothing is live When marking is consecutiveWhen live data set is a small percentage of the heap

Mark and Split11 Mark-Split Collection: Worst Case Note: - the number of free intervals is at most #L this number will start decreasing once L  H/2

Mark and Split12 Time Complexity Copying O(L) Mark-sweep O(L) + O(H) Selective sweeping O(L) + O(L log L) + O(L) Mark-split O(L log I) where: L = size of live data set H = size of heap I = number of free intervals Note: 1.I  L  H 2.I is bounded by #L+1 if L < H/2 H/(2o) if L  H/2 where o = size of smallest object

Mark and Split13 Space Requirements Best Worst Copying L H Mark-sweep M M Selective sweepingM + #L M + #H Mark-split M + kM + k(H/2o) where: L = size of live data set o = size of smallest object H = size of heap k = size of interval node M = size of mark bit area

Mark and Split14 Mark-Split vs. Selective Sweeping Mark-coalesce (the dual of mark-split) –Maintains information about occupied intervals –Can be seen as a variant of selective sweeping that eagerly merges neighboring marked intervals –Requires an extra pass at the end of collection to construct the free intervals list Assume marking is consecutive Mark-split requires significantly less auxiliary space than selective sweeping

Mark and Split15 Mark-Split vs. Lazy Sweeping Lazy sweeping does not affect the complexity of collection But often improves the cache performance of applications run with GC because –It avoids (some) negative caching effects Sweep phase disturbs the cache –Compared with “plain” mark-sweep, it has positive caching effects Memory to allocate to is typically in the cache during object initialization

Mark and Split16 Adaptive Schemes Basic idea is simple: –Optimistically start with mark-split –If it is detected that the cost will be too high, revert to mark-sweep Criteria for switching: –Auxiliary space is exhausted –Number of tree nodes visited is too big –Keep a record of prior history (last N collections) –… Note that no single mark-split collection that reverts to mark-sweep can be faster than a mark-sweep only collection, but a sequence of adaptive collections can!

Mark and Split17 Implementation Done in BEA’s JRockit –Mark-sweep collector has existed for quite long –Sweeps the heap by examining whole words of the bitmap array Mark-split’s code is about 600 lines of C –The threshold T is set at 2KB (because of TLA) Benchmarking environment: –4 processor Intel Xeon 2GHz with hyper-threading –512KB of cache, 8GB of RAM running Linux –SPECjvm98 benchmarks run for 50 iterations

Mark and Split18 Performance Evaluation on SPECjvm98 compress

Mark and Split19 Performance Evaluation on SPECjvm98 jess

Mark and Split20 Performance Evaluation on SPECjvm98 db javac mtrt jack

Mark and Split21 Performance Evaluation on SPECjvm98 compress

Mark and Split22 Performance Evaluation on SPECjvm98 jess

Mark and Split23 Performance Evaluation on SPECjvm98 db javac mtrt jack

Mark and Split24 SPECjvm98 – GC times on a 128MB heap

Mark and Split25 SPECjvm98 – GC times on a 512MB heap

Mark and Split26 SPECjvm98 – GC times on a 2GB heap

Mark and Split27 Other Measurements (on SPECjvm98)

Mark and Split28 Performance Evaluation on SPECjbb

Mark and Split29 Concluding Remarks on Mark-Split New non-moving garbage collection algorithm: –Based on a simple idea: maintaining free intervals during marking, rather than sweeping the heap to find them –Makes GC cost proportional to the size of the live data set, not the size of the heap that is collected –Requires very small additional space –Exploits the fact that in most programs live data tends to form (large) neighborhoods