MCPcopy Create free account
hub / github.com/ReadyTalk/avian / doCollect

Function doCollect

src/machine.cpp:3441–3506  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3439};
3440
3441void doCollect(Thread* t, Heap::CollectionType type, int pendingAllocation)
3442{
3443 expect(t, not t->m->collecting);
3444
3445 t->m->collecting = true;
3446 THREAD_RESOURCE0(t, t->m->collecting = false);
3447
3448#ifdef VM_STRESS
3449 bool stress = (t->getFlags() & Thread::StressFlag) != 0;
3450 if (not stress)
3451 t->setFlag(Thread::StressFlag);
3452#endif
3453
3454 Machine* m = t->m;
3455
3456 m->unsafe = true;
3457 m->heap->collect(
3458 type,
3459 footprint(m->rootThread),
3460 pendingAllocation - (t->m->heapPoolIndex * ThreadHeapSizeInWords));
3461 m->unsafe = false;
3462
3463 postCollect(m->rootThread);
3464
3465 killZombies(t, m->rootThread);
3466
3467 for (unsigned i = 0; i < m->heapPoolIndex; ++i) {
3468 m->heap->free(m->heapPool[i], ThreadHeapSizeInBytes);
3469 }
3470 m->heapPoolIndex = 0;
3471
3472 if (m->heap->limitExceeded()) {
3473 // if we're out of memory, disallow further allocations of fixed
3474 // objects:
3475 m->fixedFootprint = FixedFootprintThresholdInBytes;
3476 } else {
3477 m->fixedFootprint = 0;
3478 }
3479
3480#ifdef VM_STRESS
3481 if (not stress)
3482 t->clearFlag(Thread::StressFlag);
3483#endif
3484
3485 GcFinalizer* finalizeQueue = t->m->finalizeQueue;
3486 t->m->finalizeQueue = 0;
3487 for (; finalizeQueue;
3488 finalizeQueue = cast<GcFinalizer>(t, finalizeQueue->next())) {
3489 void (*function)(Thread*, object);
3490 memcpy(&function, &finalizeQueue->finalize(), BytesPerWord);
3491 function(t, finalizeQueue->target());
3492 }
3493
3494 if ((roots(t)->objectsToFinalize() or roots(t)->objectsToClean())
3495 and m->finalizeThread == 0 and t->state != Thread::ExitState) {
3496 m->finalizeThread = m->processor->makeThread(
3497 m, roots(t)->finalizerThread(), m->rootThread);
3498

Callers 1

collectFunction · 0.85

Calls 15

expectFunction · 0.85
footprintFunction · 0.85
postCollectFunction · 0.85
killZombiesFunction · 0.85
rootsFunction · 0.85
addThreadFunction · 0.85
startThreadFunction · 0.85
removeThreadFunction · 0.85
getFlagsMethod · 0.80
setFlagMethod · 0.80
limitExceededMethod · 0.80
clearFlagMethod · 0.80

Tested by

no test coverage detected