Glacier: A Garbage Collection Simulation System Bruno Dufour Sable Research Group McGill University Glacier: A Garbage Collection Simulation System p.1/19
Outline Introduction Objectives & motivation Requirements Design Testing Demo Related & future work Conclusions Glacier: A Garbage Collection Simulation System p.2/19
Introduction Garbage collection: memory management strategy which automatically reclaims heap-allocated memory Found in most modern languages: Java, Python,... Basic principle: unreachable objects are garbage Can be safely reclaimed Glacier: A Garbage Collection Simulation System p.3/19
Objectives & motivation Understanding how collectors work is hard Complex pointer manipulations Closely tied to architecture Goal: produce a simulator to allow modelling collectors Focus on use as a teaching tool Not necessarily suited to performance metrics Glacier: A Garbage Collection Simulation System p.4/19
Requirements Event-driven simulator Flexible event sources Ease of use model representation default trace format Flexibility ( what-if analyses) Event sources Models Monitoring tools Platform-independence Glacier: A Garbage Collection Simulation System p.5/19
Design Implemented as a set of Python modules 4 major components: Event source Model Simulation engine Simulation monitor Glacier: A Garbage Collection Simulation System p.6/19
Design Event source Event source sends execution events to simulator 6 required event classes are provided (can add more) Allocation Update Enter Exit GC Reset Glacier: A Garbage Collection Simulation System p.7/19
Design Event source Event source reads events from an execution trace Trace is text-based, for manual trace generation Trace contents: Options (header size, threads,... ) Entity definition (types, methods,... ) Events (allocation, update,... ) Glacier: A Garbage Collection Simulation System p.8/19
Design Sample trace # Options OPT HEADER_SIZE 32 # 4 byte headers OPT POINTER_SIZE 32 # 4 byte pointers OPT THREADS # Actions have associated threads # Entity definitions TYPEDEF PTR_PAIR 2 ref L car ref R cdr TYPEDEF INTEGER 1 atom V 16 0 value # 16-bit integer THREAD 0 MAIN GLOBAL ref R1 Root pointer to A # Instantiate objects ALLOC 0 A PTR_PAIR @R1 ALLOC 0 B INTEGER A.L ALLOC 0 C PTR_PAIR A.R ALLOC 0 D INTEGER C.L UPDATE 0 C.R A # Circular reference! UPDATE 0 @R1 NIL GC 0 Glacier: A Garbage Collection Simulation System p.9/19
Design Sample Trace R1 A B C D Glacier: A Garbage Collection Simulation System p.10/19
Design Models All models must extend GarbageCollector Models represent GC-managed heaps with 1 or more heap spaces Heap spaces are subdivisions of the heap Each heap space assumed to be contiguous in memory All heap objects must belong to exactly one heap space at any time Glacier provides a default free-list based heap space class Glacier: A Garbage Collection Simulation System p.11/19
Design Models Models are implemented by providing: getspaces() getextrafields() new(heapobject) delete(heapobject) write(reference, HeapObject) collect(roots) Glacier: A Garbage Collection Simulation System p.12/19
Design Simulation Engine Bridge between event source and model Manages execution stacks Controls GC model Keeps track of time in terms of amount of memory allocated Extensible by subclassing if new events are to be added Finding roots: Event source provides global references Simulation engine provides local references Glacier: A Garbage Collection Simulation System p.13/19
Design Monitors 2 possible types of monitors: Console-based GUI-based (visual) Based on Observer pattern 3 subject kinds Collector Simulation engine Execution stacks Necessary for complete system visualization Glacier: A Garbage Collection Simulation System p.14/19
Testing 2 significantly different collectors: Reference counting Stop & Copy (Semi-space collector) 2 monitors GC metrics (console) Heap watermark monitor (GUI) Traces Manually generated (small) Automatically generated from an expression tree evaluator (11K lines) Glacier: A Garbage Collection Simulation System p.15/19
Demo Glacier: A Garbage Collection Simulation System p.16/19
Related Work gcsim (U. Colorado) Designed to performance comparisons Implementation in Java Low-level details (memory blocks) Java-specific trace Glacier: A Garbage Collection Simulation System p.17/19
Conclusions Glacier... allows quick prototyping of garbage collector models is a flexible and versatile simulation framework is heavily customizable http://www.sable.mcgill.ca/ bdufou1/glacier/ Glacier: A Garbage Collection Simulation System p.18/19
Future Work Implement complete system visualization Add support for program location entities e.g. leak detection Implement support for arrays Support concurrent collectors Extend trace format Add more collector models Glacier: A Garbage Collection Simulation System p.19/19