u niversity of m assachusetts, a mherst department of computer science 1 mc 2 –copying gc for...
TRANSCRIPT
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science
1
MC2–Copying GC for Memory Constrained Environments
Narendran Sachindran J. Eliot B. MossEmery Berger
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 2
Motivation Handheld Devices: PDAs, cell phones
Constrained memory, limited power Run applications with diverse
requirements Multimedia, scaled down desktop apps.
Java becoming popular on handhelds Safety, portability Garbage collection
Require good throughput & low pauses, in constrained memory
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 3
Mark-Sweep Collection
Free list allocation First-fit, best-fit, segregated free lists… Does not copy data
Space overhead not very high Fragmentation: lowers space
utilization Locality effects
Different sizes are segregated New objects may be interspersed with old
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 4
Mark-(Sweep)-Compact Collection
Low space overhead Bump pointer allocation Good throughput in constrained
memory Preserves object allocation order
Good locality Long pause times
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 5
(Generational) Copying Collection
Bump pointer allocation Copies data, avoids fragmentation Reorders objects: can improve
locality Min. space required = 2X live data
size
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 6
Mark-Copy Collection: Goal
Manages space in old generation Overcome 2X space overhead Better space utilization
Generational copying
Mark-Copy
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 7
Mark-Copy Space Usage Divides space into equal size windows Reserves one window for copying Collects in two phases: Mark and Copy
Generational copying
Mark-Copy
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 8
Mark-Copy In Action
Nursery
Old Generation
Un
map
ped
Un
map
ped
Un
map
ped
Un
map
ped
Un
map
ped
Un
map
ped
Un
map
ped
Un
map
ped
Nursery
Old Generation
A
B
C
D
E
F
R1 R2
Un
map
ped
Un
map
ped
Un
map
ped
Un
map
ped
Un
map
ped
Nursery
Old Generation
Un
map
ped
Un
map
ped
Un
map
ped
Un
map
ped
Un
map
pedA
B
C
D
E
F
R1 R2
G
R3
Nursery
Old Generation
Un
map
ped
Un
map
ped
Un
map
ped
Un
map
ped
Un
map
pedA
B
C
D
E
F
R1 R2
G
H
R3
Nursery
Old Generation
Un
map
ped
Un
map
ped
Un
map
ped
Un
map
ped
Un
map
pedA
B
C
D
E
F
R1 R2
G
H
R3
Nursery
Old Generation
Un
map
ped
Un
map
ped
Un
map
ped
Un
map
ped
Un
map
pedA
B
C
D
E
F
R1 R2
G
H
R3
Nursery
Old Generation
Un
map
ped
Un
map
ped
Un
map
ped
Un
map
ped
Un
map
pedA
B
C
D
E
F
R1
G
H
R3
Nursery
Old Generation
Un
map
ped
Un
map
ped
Un
map
ped
Un
map
pedA
B
C
D
E
F
R1
G
H
R3
Nursery
Old Generation
Un
map
ped
Un
map
ped
Un
map
ped
Un
map
pedA
B
C
D
E
F
R1
G
H
R3
Nursery
Old Generation
Un
map
ped
Un
map
ped
Un
map
ped
Un
map
pedA
B
C
D
E
F
R1
G
H
R3
Nursery
Old Generation
Un
map
ped
Un
map
ped
Un
map
ped
Un
map
pedA
B
C
D
E
F
R1
G
H
R3
Nursery
Old Generation
Un
map
ped
Un
map
ped
Un
map
ped
Un
map
pedA
B
C
D
E
F
R1
G
H
R3
Nursery
Old Generation
Un
map
ped
Un
map
ped
Un
map
ped
Un
map
pedA
B
C
D
E
F
R1
G
H
R3
Nursery
Old Generation
Un
map
ped
Un
map
ped
Un
map
pedA
B
C
D
E
F
R1
G
H
R3
B
Nursery
Old Generation
Un
map
ped
Un
map
ped
Un
map
pedA
B
C
D
E
F
R1
G
H
R3
B
Nursery
Old Generation
Un
map
ped
Un
map
ped
Un
map
pedA
B
C
D
E
F
R1
G
H
R3
B
Nursery
Old Generation
Un
map
ped
Un
map
ped
Un
map
pedA
B
C
D
E
F
R1
G
H
R3
B
Nursery
Old Generation
Un
map
ped
Un
map
ped
Un
map
pedA
B
C
D
E
F
R1
G
H
R3
B
Nursery
Old Generation
Un
map
ped
Un
map
ped
Un
map
pedC
D
E
F
R1
G
H
R3
B
Un
map
ped
Nursery
Old Generation
Un
map
ped
Un
map
pedC
D
E
F
R1
G
H
R3
B
Un
map
ped
Un
map
ped
Nursery
Old Generation
Un
map
ped
Un
map
pedC
D
E
F
R1
G
H
R3
B
Un
map
ped
Nursery
Old Generation
Un
map
ped
Un
map
pedC
D
E
F
R1
G
H
R3
B
C
D
G
Un
map
ped
Nursery
Old Generation
Un
map
ped
Un
map
ped
R1 R3
B
C
D
G
Un
map
ped
Nursery
Old Generation
Un
map
ped
Un
map
ped
R1 R3
B
C
D
G
Un
map
ped
Un
map
ped
Un
map
ped
Un
map
ped
Nursery
Old Generation
Un
map
ped
Un
map
ped
R1 R3
B
C
D
G
Un
map
ped
Un
map
ped
Un
map
ped
Un
map
ped
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 9
Experimental Results
Implemented in Jikes RVM (2.2.2)/JMTk
Macintosh PPC (533 MHz), 640MB memory, Linux 2.4.10
Collectors evaluated Mark-Copy vs. Gen. copy (Appel
style) Mark-Copy vs. Mark-Sweep Mark-Copy vs. Gen. Mark-Sweep
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science
10
Mark-Copy vs. Gen. Copy
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 11
_213_javac Mark/Cons
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 12
_213_javac GC Time
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 13
_213_javac Execution Time
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science
14
Mark-Copy vs. Gen. Mark-Sweep
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 15
_213_javac GC Time
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 16
_213_javac Execution Time
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 17
Mark-Copy Summary
Mark-Copy vs. Gen. copy Runs in less space Outperforms in small and moderate
heaps Mark-Copy vs. Mark-Sweep
Outperforms non-generational collector in small and moderate size heaps
Improves exec. time for some programs when compared with gen. collector
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 18
Mark-Copy Limitations
Requires virtual memory support Always copies all live data Potentially large remembered sets
Could grow as large as heap Long pauses
Non-incremental marking and copying
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 19
MC2–Memory Constrained Copying
Overcomes mark-copy limitations Removes virtual memory
requirement Incremental mark and copy
phases Bounded space for remembering
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 20
Removing Use of Memory Mapping
Use ‘logical’ instead of object address Every window has a logical address Logical address implies collection
order Remset insert requires logical
address lookup High occupancy windows moved
logically
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 21
Handling Large Remembered Sets
Set a limit on the total remset size We use 5% of total heap space
Check size regularly, on allocation ‘slow path’
Coarsen large remsets when space close to limit
Replace large remsets with card table
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 22
Making Collection Incremental
Interleave marking & copying with program (mutator) activity
Problem: Mutator could modify object graph between collection increments Could cause reclamation of live objects
Solution: Track mutations using write barrier Record mutated slots in remsets at GC
time
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 23
Making Collection Incremental
Popular objects Popular = Highly referenced Cause long pauses when copied
MC2 identifies popular objects while coarsening remset
Isolates these objects at high end of heap
May cause long pause once, but does not recur
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 24
Incremental Copying Example
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 25
Incremental Copying Example
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 26
Incremental Copying Example
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 27
Incremental Copying Example
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 28
Incremental Copying Example
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 29
Experimental Results
Implemented in Jikes RVM (2.2.3)/JMTk
Pentium 4 1.7 GHz, 512MB memory, RedHat Linux 2.4.7-10
Collectors evaluated Generational Mark-Sweep (MS) Generational Mark-Compact (MSC) MC2
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science
30
Non-incremental Collector Improvements
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 31
JMTk Heap Layout
BootImage
Imm.ObjectSpace
LargeObjectSpace
Old Generation Nursery
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 32
JMTk Generational Collection Write barrier records pointers into the
nursery from objects outside the nursery Fast–only two comparisons Nursery collections efficient Full collections scan entire boot image to
locate live objects on heap Inefficient for small heaps Scan ~2 million pointers, only 0.4%
relevant
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 33
Old write barrier
BootImage
Imm.ObjectSpace
LargeObjectSpace
Old Generation Nursery
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 34
New Write Barrier
Records pointers into nursery Also records mutated boot image objects Full collections avoid boot image scan Scan only mutated boot image objects Reduces full GC time (4x for small
programs) Efficient for small heaps (reduction in
GC time > cost of new write barrier)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 35
New Write Barrier
BootImage
Imm.ObjectSpace
LargeObjectSpace
Old Generation Nursery
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 36
JMTk Heap
Data and code allocated in same region
Poor code locality high ITLB miss rate
Maintaining separate data and code regions improves locality for copying collectors
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 37
_213_javac (MSC GC Time)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 38
_213_javac (MSC Execution Time)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science
39
MC2 vs. MS and MSC
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 40
jess Execution Time
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 41
javac Execution Time
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 42
Bounded Mutator Utilization (jess)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 43
Bounded Mutator Utilization (javac)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 44
MC2 Summary
Runs with low space overhead Throughput comparable to MS and MSC Average pause times factor of 4 lower
than MS , factor of 7 lower than MSC Suitable for handheld devices with soft
real time requirements: Low space overhead Good throughput Short pause times
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 45
The Papers
Mark-Copy: OOPSLA 2003 MC2: OOPSLA 2004 Naren Sachindran PhD
forthcoming