brixen
August 25, 2016
360

# Papers We Love - Immix mark-region garbage collector

Papers We Love Portland, OR presentation 25 Aug 2016 on the Immix mark-region garbage collector.

August 25, 2016

## Transcript

1. ### Immix: A Mark-Region Garbage Collector Brian Shirai · Portland ·

25 Aug 2016 Portland
2. None
3. ### 1. Introduction to garbage collection 2. Immix mark-region collector 3.

Experience with (Immix) in Rubinius Agenda

5. None

11. ### void fun(Obj a) { Obj m = new Obj(a); work(m);

delete(m); } Manual Automatic void fun(Obj a) { Obj m(a); work(m); } Managing memory is coupled with program meaning Is the object m garbage collected?

13. ### Stack allocation return addr reg N reg M local 0

obj B obj A ... stack pointer (SP) what is the lifetime of A? does it exceed SF lifetime?

15. ### Bump-pointer allocation Obj m = new Obj(a); 0 N M

M+S current pointer = start of free space new start of free space S = size of object T

19. ### Let be an object graph Let A, B, C be

elements of a graph If A ∈ and A → B, then B ∈ If A ∈ and A → B and B → C, then C ∈

unreachable

concurrent

37. ### Space efﬁciency 1. Ratio of space used / space reserved

close to 1 2. Percentage of space used by metadata as small as possible ( < 1-2%) Fragmentation is the biggest opponent
38. ### Fast collection 1. Touch as few objects as possible 2.

Perform as few operations per object as possible
39. ### Mutator performance 1. Allocation must be fast 2. Identiﬁcation must

be fast 3. Reclamation must be fast

45. None
46. ### Two lines deﬁne a point Two points deﬁne a line

Duals Two X deﬁne a Y ^ intersecting ^ dissimilar

49. ### Heap structure Heap divided into blocks Block divided into lines

Objects cannot span blocks Objects can span lines
50. ### Initial allocation 0 N M M+S current pointer = start

of free space new start of free space S = size of object

52. ### Reclamation completely free blocks can be reclaimed completely free lines

can be reclaimed
53. ### Steady-state allocation Block divided into lines previous current free new

objects bump-allocated into holes
54. ### Steady-state allocation X N M M+S a hole is free

range between two pointers (found lazily) Y what happens when an object is too big to ﬁt in the current hole?

56. ### Details and policies 1. When to recycle a block? F

= 1 free object 2. Where to allocate "medium" objects? Overﬂow block 3. Parallelism - multiple allocator and collector threads, but not concurrent collection 4. Allocate into completely free blocks last

58. ### Space efﬁciency 1. Ratio of space reserved / space used

close to 1 2. Percentage of space used by metadata as small as possible ( < 1-2%) Fragmentation is the biggest opponent
59. ### Fast collection 1. Touch as few objects as possible 2.

Perform as few operations per object as possible
60. ### Mutator performance 1. Allocation must be fast 2. Identiﬁcation must

be fast 3. Reclamation must be fast

64. ### Fragmentation 1. Bad: occupancy ~20% 2. No overﬂow allocation and

bigger "medium" object size 3. No defragmentation

67. ### Current work 1. Per-thread Immix region (generational and isolatable heaps)

2. Two tenured regions 3. Large-object region

69. ### 1. Method inline cache region 2. Constant inline cache region

3. Machine code region 4. Symbol region 5. Variable scope region 6. Roots region 7. Object ﬁnalizer region 8. Inﬂated header region
70. ### "Every system with a primary tracing collector has a poorly

specified, buggy, slow, partial implementation of a reference counting collector."
71. ### Reference counting class method table Compiled Code entry Machine Code

InlineCache Constant Cache Memo

74. ### \$ rbx compile -B -e 'Array.new' ============= :__script__ ============== Arguments:

0 required, 0 post, 0 total Arity: 0 Locals: 0 Stack size: 2 Literals: 4: :Array, :new, :allocate, :initialize Lines to IP: 1: 0..22 0000: push_const :Array 0002: dup 0003: check_serial :new, 47 0006: goto_if_false 0018: 0008: allow_private 0009: send_method :allocate 0011: dup 0012: allow_private 0013: send_method :initialize 0015: pop 0016: goto 0020: 0018: send_method :new 0020: pop 0021: push_true 0022: ret ----------------------------------------
75. ### \$ rbx compile -B -e 'Array.new' ============= :__script__ ============== Arguments:

0 required, 0 post, 0 total Arity: 0 Locals: 0 Stack size: 1 Literals: 1: :Array Lines to IP: 1: 0..5 0000: push_const :Array 0002: allocate 0003: pop 0004: push_true 0005: ret ----------------------------------------