Accurate Garbage Collection
in
Uncooperative Environments
with
Lazy Pointer Stacks
Jason Baker, Antonio Cunei, Filip Pizlo, Jan Vitek Purdue University
Accurate Garbage Collection in Uncooperative Environments with - - PowerPoint PPT Presentation
Accurate Garbage Collection in Uncooperative Environments with Lazy Pointer Stacks Jason Baker, Antonio Cunei, Filip Pizlo , Jan Vitek Purdue University New Programming Language Translate Compile Hard! Old Programming Language d l O
Jason Baker, Antonio Cunei, Filip Pizlo, Jan Vitek Purdue University
p i l e r
void foo(void) { void *ptr = alloc(); if (ptr == 0) error(); bar(ptr); } _foo: mflr r0 stmw r30,-8(r1) stw r0,8(r1) stwu r1,-80(r1) bl L_alloc$stub
bne+ cr0,L2 bl L_error$stub L2: mr r3,r30 bl L_bar$stub lwz r0,88(r1) addi r1,r1,80 mtlr r0 lmw r30,-8(r1) blr
Bootstrap Frame App Frame App Frame App Frame App Frame Context Switch stackBase stackCur (a) Switch to a thread that needs stack walking.
Bootstrap Frame App Frame App Frame App Frame App Frame Context Switch stackBase stackCur App Frame App Frame App Frame App Frame Context Switch Stack Copy (b) Copy the portion of the stack that will be unwound.
Bootstrap Frame stackBase, stackCur App Frame App Frame App Frame App Frame Context Switch Stack Copy (c) Stack is unwound, but we still have a copy.
Bootstrap Frame App Frame App Frame App Frame App Frame Context Switch stackBase stackCur App Frame App Frame App Frame App Frame Context Switch Stack Copy (d) Restore the stack with a second copy, use context switch to restore registers. Thread is now back to where it was in (a).
placed pointers!
replacement in the context of the affected frame.
this time:
actually returns following GC,
void *ptr; try { functionCall(); } catch (const StackScanException&) { if (saving) { lazyPtrStack->pushPtr(ptr); throw; } else if (restoring) { ptr = lazyPtrStack->popPtr(); if (returned normally) { restore return value; } else { throw app exception; } } }
Direction of stack growth
Return PC Return PC Caller Caller
(a) Ordinary callstack for C or C++ code.
and proceed with GC.
The Thunk
Direction of stack growth
Thunk PC Thunk PC Caller Caller
(b) "Thunkified" callstack.
Thunk PC Caller
and proceed with GC.
The Thunk
Direction of stack growth
Thunk PC Caller
(c) If a function completes (either by return or throw), the thunk runs.
Thunk Runs!
c
p r e s s j e s s d b j a v a c m p e g a u d i
t r t j a c k G e
M e a n
0% 2.5% 5.0% 7.5% 10.0% 12.5% 15.0% 17.5% 20.0%
Ptr Stack Thunking Henderson Counter
Overhead relative to Conservative
c
p r e s s j e s s d b j a v a c m p e g a u d i
t r t j a c k G e
M e a n
0% 5% 10% 15% 20% 25% 30%
Ptr Stack Thunking Henderson Counter
Overhead relative to Conservative