Verifying a Concurrent Garbage Collector Delphine Demange Suresh Jagannathan Gustavo Petri David Pichardie Jan Vitek Yannick Zakowski
Why are high level languages difficult to compile?
Easy to compile in C Obj.f := v What about Java?
A Store in Java if (fivmr_GCHeader_markBits( void FIVMR_CONCAT(FIVMBUILD_GC_NAME,_markSlow)(fivmr_ThreadState *ts, fivmr_GCHeader_fromObject(&ts->vm->settings, fivmr_Object obj) { obj))!=0) { fivmr_SPC_incBarrierSlowPath(); if (ts->gc.tracing && fivmr_GC_isTracing(curPhase)) { if (mutatorMark(ts, if (FIVMR_LOG_GC_MARK_TRAPS) { fivmr_GCHeader_fromObject(&ts->vm->settings, uint64_t stamp=fivmr_readCPUTimestamp(); obj))) { fp_log(ts->id, LOG(3,("Thread %u barrier marked %p (of type %s)", "mark trap at %u:%u on %u",3, ts->id,obj, (uintptr_t)((stamp>>32)&0xffffffff), fivmr_TypeData_forObject(&ts->vm->settings,obj)->name)); (uintptr_t)((stamp>>0)&0xffffffff), } obj); } else if (curPhase==FIVMR_GCP_PRE_INIT || fivmr_GC_isTracing(curPhase)) { } LOG(3,("Thread %u barrier would have marked marked %p (of type %s); " "phase = %d (now %d), status = %" PRIuPTR, fivmr_assert(ts->execStatus==FIVMR_TSES_IN_JAVA || ts->id,obj, ts->execStatus==FIVMR_TSES_IN_JAVA_TO_BLOCK); fivmr_TypeData_forObject(&ts->vm->settings,obj)->name, curPhase,ts->vm->gc.phase,ts->execStatus)); fivmr_assert(obj); } else if (!FIVMR_HFGC_FAIL_FAST_PATHS(&ts->vm->settings)) { LOG(0,("Thread %u barrier incorrectly saw %p (of type %s)", if (FIVMR_ASSERTS_ON || FIVMR_LOG_LEVEL>=2) { ts->id,obj, fivmr_GCPhase curPhase; fivmr_TypeData_forObject(&ts->vm->settings,obj)->name)); curPhase=ts->vm->gc.phase; fivmr_abort("barrier error"); } /* this code is more verbose and careful */ } } else { /* should never see stack-allocated objects */ /* this code is carefully written to ensure performance, but doesn’t if (!FIVMR_HFGC_FAIL_FAST_PATHS(&ts->vm->settings)) { do the same verification as the above. */ fivmr_assert( if (ts->gc.tracing) { fivmr_GCHeader_markBits( fivmr_GCHeader *hdr; fivmr_GCHeader_fromObject(&ts->vm->settings, fivmr_GCHeader oldHdr; obj))!=0); uintptr_t markBits; } uintptr_t curShaded; fivmr_GC *gc; /* we don’t want to mark when we’re idle because during the idle phase at the beginning of GC we may be rotating mark bits. this prevents gc=&ts->vm->gc; races where two threads end up double-marking an object because they hdr = fivmr_GCHeader_fromObject(&ts->vm->settings, see different values of curShaded. obj); oldHdr = *hdr; this is particularly why we query ts->gc.tracing. it’s possible that markBits = fivmr_GCHeader_markBits(&oldHdr); a thread will have used stale shade values in its fast path check. curShaded = gc->curShaded; worse, memory model issues could mean that the value of gc->curShaded we see here could be stale. we don’t want to perform marking with a if (markBits!=0 && stale value of curShaded. checking ts->gc.tracing, which is set by (markBits&curShaded)==0 && safepoints and hence side-steps cache coherence, ensures that we only markUnmarked(gc, proceed when we have the latest shade values. */ &ts->gc.queue,
A Store in Java /* we don’t want to mark when we’re idle because during the idle phase at the beginning of GC we may be rotating mark bits. this prevents races where two threads end up double-marking an object because they see different values of curShaded. this is particularly why we query ts->gc.tracing. it’s possible that a thread will have used stale shade values in its fast path check. worse, memory model issues could mean that the value of gc->curShaded we see here could be stale. we don’t want to perform marking with a stale value of curShaded. checking ts->gc.tracing, which is set by safepoints and hence side-steps cache coherence, ensures that we only proceed when we have the latest shade values. */
This work Challenge: Certify a state-of-the-art Concurrent Garbage Collector Methodology: An IR to Implement and Verify Runtime Services
The set-up
The set-up TSO
The set-up TSO
What do we prove ? This tutorial closely follows Damien Doligez’s phd (1995)
Garbage collection root root root How to automatically reclaim unused memory ? unused Theorem : Reachable memory is never reclaimed
Sequential mark & sweep Periodically stop user code and perform: • Mark: graph traversal from the root marking cells black • Sweep: scan of the whole memory to free non-black cells Color conventions: • Black: marked • White: not marked • Grey: to be marked (pending nodes) • Blue: free cells
Sequential mark & sweep Periodically stop user code and perform: • Mark: graph traversal from the root marking cells black • Sweep: scan of the whole memory to free non-black cells Color conventions: • Black: marked • White: not marked • Grey: to be marked (pending nodes) • Blue: free cells
Sequential mark & sweep Periodically stop user code and perform: • Mark: graph traversal from the root marking cells black • Sweep: scan of the whole memory to free non-black cells Color conventions: • Black: marked • White: not marked • Grey: to be marked (pending nodes) • Blue: free cells
Sequential mark & sweep Periodically stop user code and perform: • Mark: graph traversal from the root marking cells black • Sweep: scan of the whole memory to free non-black cells Color conventions: • Black: marked • White: not marked • Grey: to be marked (pending nodes) • Blue: free cells
Sequential mark & sweep Periodically stop user code and perform: • Mark: graph traversal from the root marking cells black • Sweep: scan of the whole memory to free non-black cells Color conventions: • Black: marked • White: not marked • Grey: to be marked (pending nodes) • Blue: free cells
Sequential mark & sweep Periodically stop user code and perform: • Mark: graph traversal from the root marking cells black • Sweep: scan of the whole memory to free non-black cells Color conventions: • Black: marked • White: not marked • Grey: to be marked (pending nodes) • Blue: free cells
Sequential mark & sweep Periodically stop user code and perform: • Mark: graph traversal from the root marking cells black • Sweep: scan of the whole memory to free non-black cells Color conventions: • Black: marked • White: not marked • Grey: to be marked (pending nodes) • Blue: free cells
Sequential mark & sweep Periodically stop user code and perform: • Mark: graph traversal from the root marking cells black • Sweep: scan of the whole memory to free non-black cells Color conventions: • Black: marked • White: not marked • Grey: to be marked (pending nodes) • Blue: free cells
Sequential mark & sweep Periodically stop user code and perform: • Mark: graph traversal from the root marking cells black • Sweep: scan of the whole memory to free non-black cells Color conventions: • Black: marked • White: not marked • Grey: to be marked (pending nodes) • Blue: free cells
Sequential mark & sweep Periodically stop user code and perform: • Mark: graph traversal from the root marking cells black • Sweep: scan of the whole memory to free non-black cells Color conventions: • Black: marked • White: not marked • Grey: to be marked (pending nodes) • Blue: free cells
Sequential mark & sweep Periodically stop user code and perform: • Mark: graph traversal from the root marking cells black • Sweep: scan of the whole memory to free non-black cells Color conventions: • Black: marked • White: not marked • Grey: to be marked (pending nodes) • Blue: free cells
Sequential mark & sweep Periodically stop user code and perform: • Mark: graph traversal from the root marking cells black • Sweep: scan of the whole memory to free non-black cells Color conventions: • Black: marked • White: not marked • Grey: to be marked (pending nodes) • Blue: free cells
Sequential mark & sweep Periodically stop user code and perform: • Mark: graph traversal from the root marking cells black • Sweep: scan of the whole memory to free non-black cells Color conventions: • Black: marked • White: not marked • Grey: to be marked (pending nodes) • Blue: free cells
Sequential mark & sweep Periodically stop user code and perform: • Mark: graph traversal from the root marking cells black • Sweep: scan of the whole memory to free non-black cells Color conventions: • Black: marked • White: not marked • Grey: to be marked (pending nodes) • Blue: free cells
Sequential mark & sweep Periodically stop user code and perform: • Mark: graph traversal from the root marking cells black • Sweep: scan of the whole memory to free non-black cells Color conventions: • Black: marked • White: not marked • Grey: to be marked (pending nodes) • Blue: free cells
Sequential mark & sweep Periodically stop user code and perform: • Mark: graph traversal from the root marking cells black • Sweep: scan of the whole memory to free non-black cells Color conventions: • Black: marked • White: not marked • Grey: to be marked (pending nodes) • Blue: free cells
Recommend
More recommend