Lecture11 - Memory Management and Garbage Collection...

Info iconThis preview shows pages 1–12. Sign up to view the full content.

View Full Document Right Arrow Icon
Memory Management and Garbage Collection Lecture 11 CS 501 May 6, 2009 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Preliminaries Critiques Uniprocessor Garbage Collection Techniques Wilson Garbage Collection in an Uncooperative Environment Boehm HW 2 due Monday 2
Background image of page 2
Program memory Typically divided into 3 regions: Global : fxed-size region det. at compile time (global/static vars) Stack variable-size region temporally allocated per method invocation (local vars) Heap : variable-size region explicitly allocated by the programmer (malloc / new / cons) 3
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Memory management Must balance dynamic requirements of program with limited resources of the runtime / machine. Global memory is Fxed ahead of time Stack memory is reclaimed on method return Heap is more complex: want to return to runtime when no longer in use explicitly: free / delete automatically: garbage collection 4
Background image of page 4
Garbage collection Automatically reclaim memory that is no longer in use by the program. Frees programmer from burden Enhances modularity Simpli±es concurrency Prevents dangling pointer errors Near requirement for type-safety 5
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Challenges GC is not free: some performance overhead Greater non-determinism Noticeable pauses in program execution Less Fne-grain control of memory Conservative Does not prevent memory leaks 6
Background image of page 6
What is garbage? An object is live if it is still in use We err on the conservative side Okay to keep memory no longer in use Not okay to reclaim memory still in use An object is garbage if it is not live 7
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Reachability Root set : the set of global and local (stack/register) variables visible to active procedures Heap objects are reachable if: they are directly accessible from the root set they are accessible from another reachable heap object (i.e., via pointers / references) Liveness implies reachability Not reachable implies garbage 8
Background image of page 8
Reachability stack globals registers heap A B C { .... r0 = obj PC -> p.f = obj .... • Compiler produces a stack-map at GC safe-points and Type Information Blocks GC safe points : new(), method entry, method exit, & back-edges (thread switch points) Stack-map: enumerate global variables, stack variables, live registers -- This code is hard to get right! Why? Type Information Blocks: identify reference fields in objects 9
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Reachability stack globals registers heap A B C { .... r0 = obj PC -> p.f = obj .... • Compiler produces a stack-map at GC safe-points and Type Information Blocks Type Information Blocks: identify reference fields in objects for each type i (class) in the program, a map 3 0 2 TIB i 10
Background image of page 10
Reachability • Tracing collector (semispace, marksweep) – Marks the objects reachable from the roots live, and then performs a transitive closure over them stack globals registers heap A B C { ....
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 12
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/09/2012 for the course CSE 403 taught by Professor Staff during the Spring '08 term at University of Washington.

Page1 / 62

Lecture11 - Memory Management and Garbage Collection...

This preview shows document pages 1 - 12. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online