|
Lines 78-83
using namespace std;
Source/JavaScriptCore/heap/Heap.cpp_sec1
|
| 78 |
|
78 |
|
| 79 |
namespace JSC { |
79 |
namespace JSC { |
| 80 |
|
80 |
|
|
|
81 |
class Heap::ResumeTheWorldScope { |
| 82 |
public: |
| 83 |
ResumeTheWorldScope(Heap& heap) |
| 84 |
: m_heap(heap) |
| 85 |
{ |
| 86 |
if (!Options::useConcurrentGC()) |
| 87 |
return; |
| 88 |
|
| 89 |
if (Options::logGC()) |
| 90 |
dataLog((MonotonicTime::now() - m_heap.m_stopTime).milliseconds(), " ms...]\n"); |
| 91 |
|
| 92 |
m_heap.resumeTheWorld(); |
| 93 |
} |
| 94 |
|
| 95 |
~ResumeTheWorldScope() |
| 96 |
{ |
| 97 |
if (!Options::useConcurrentGC()) |
| 98 |
return; |
| 99 |
|
| 100 |
if (Options::logGC()) |
| 101 |
m_heap.stopTheWorld(); |
| 102 |
|
| 103 |
dataLog("[Increment: "); |
| 104 |
} |
| 105 |
|
| 106 |
private: |
| 107 |
Heap& m_heap; |
| 108 |
}; |
| 109 |
|
| 81 |
namespace { |
110 |
namespace { |
| 82 |
|
111 |
|
| 83 |
static const size_t largeHeapSize = 32 * MB; // About 1.5X the average webpage. |
112 |
static const size_t largeHeapSize = 32 * MB; // About 1.5X the average webpage. |
|
Lines 244-250
Heap::Heap(VM* vm, HeapType heapType)
Source/JavaScriptCore/heap/Heap.cpp_sec2
|
| 244 |
, m_extraMemorySize(0) |
273 |
, m_extraMemorySize(0) |
| 245 |
, m_deprecatedExtraMemorySize(0) |
274 |
, m_deprecatedExtraMemorySize(0) |
| 246 |
, m_machineThreads(this) |
275 |
, m_machineThreads(this) |
| 247 |
, m_slotVisitor(*this) |
276 |
, m_collectorSlotVisitor(std::make_unique<SlotVisitor>(*this)) |
|
|
277 |
, m_mutatorMarkStack(std::make_unique<MarkStackArray>()) |
| 248 |
, m_handleSet(vm) |
278 |
, m_handleSet(vm) |
| 249 |
, m_codeBlocks(std::make_unique<CodeBlockSet>()) |
279 |
, m_codeBlocks(std::make_unique<CodeBlockSet>()) |
| 250 |
, m_jitStubRoutines(std::make_unique<JITStubRoutineSet>()) |
280 |
, m_jitStubRoutines(std::make_unique<JITStubRoutineSet>()) |
|
Lines 266-271
Heap::Heap(VM* vm, HeapType heapType)
Source/JavaScriptCore/heap/Heap.cpp_sec3
|
| 266 |
#if USE(FOUNDATION) |
296 |
#if USE(FOUNDATION) |
| 267 |
, m_delayedReleaseRecursionCount(0) |
297 |
, m_delayedReleaseRecursionCount(0) |
| 268 |
#endif |
298 |
#endif |
|
|
299 |
, m_sharedCollectorMarkStack(std::make_unique<MarkStackArray>()) |
| 300 |
, m_sharedMutatorMarkStack(std::make_unique<MarkStackArray>()) |
| 269 |
, m_helperClient(&heapHelperPool()) |
301 |
, m_helperClient(&heapHelperPool()) |
| 270 |
, m_threadLock(Box<Lock>::create()) |
302 |
, m_threadLock(Box<Lock>::create()) |
| 271 |
, m_threadCondition(AutomaticThreadCondition::create()) |
303 |
, m_threadCondition(AutomaticThreadCondition::create()) |
|
Lines 416-427
void Heap::addReference(JSCell* cell, Ar
Source/JavaScriptCore/heap/Heap.cpp_sec4
|
| 416 |
|
448 |
|
| 417 |
void Heap::harvestWeakReferences() |
449 |
void Heap::harvestWeakReferences() |
| 418 |
{ |
450 |
{ |
| 419 |
m_slotVisitor.harvestWeakReferences(); |
451 |
m_collectorSlotVisitor->harvestWeakReferences(); |
| 420 |
} |
452 |
} |
| 421 |
|
453 |
|
| 422 |
void Heap::finalizeUnconditionalFinalizers() |
454 |
void Heap::finalizeUnconditionalFinalizers() |
| 423 |
{ |
455 |
{ |
| 424 |
m_slotVisitor.finalizeUnconditionalFinalizers(); |
456 |
m_collectorSlotVisitor->finalizeUnconditionalFinalizers(); |
| 425 |
} |
457 |
} |
| 426 |
|
458 |
|
| 427 |
void Heap::willStartIterating() |
459 |
void Heap::willStartIterating() |
|
Lines 439-554
void Heap::completeAllJITPlans()
Source/JavaScriptCore/heap/Heap.cpp_sec5
|
| 439 |
#if ENABLE(JIT) |
471 |
#if ENABLE(JIT) |
| 440 |
JITWorklist::instance()->completeAllForVM(*m_vm); |
472 |
JITWorklist::instance()->completeAllForVM(*m_vm); |
| 441 |
#endif // ENABLE(JIT) |
473 |
#endif // ENABLE(JIT) |
| 442 |
#if ENABLE(DFG_JIT) |
|
|
| 443 |
DFG::completeAllPlansForVM(*m_vm); |
474 |
DFG::completeAllPlansForVM(*m_vm); |
| 444 |
#endif |
|
|
| 445 |
} |
475 |
} |
| 446 |
|
476 |
|
| 447 |
void Heap::markRoots(double gcStartTime) |
477 |
void Heap::markToFixpoint(double gcStartTime) |
| 448 |
{ |
478 |
{ |
| 449 |
TimingScope markRootsTimingScope(*this, "Heap::markRoots"); |
479 |
TimingScope markToFixpointTimingScope(*this, "Heap::markToFixpoint"); |
| 450 |
|
480 |
|
| 451 |
HeapRootVisitor heapRootVisitor(m_slotVisitor); |
481 |
HeapRootVisitor heapRootVisitor(*m_collectorSlotVisitor); |
| 452 |
|
482 |
|
| 453 |
{ |
483 |
if (m_collectionScope == CollectionScope::Full) { |
| 454 |
TimingScope preConvergenceTimingScope(*this, "Heap::markRoots before convergence"); |
484 |
m_opaqueRoots.clear(); |
|
|
485 |
m_collectorSlotVisitor->clearMarkStacks(); |
| 486 |
m_mutatorMarkStack->clear(); |
| 487 |
} |
| 455 |
|
488 |
|
| 456 |
#if ENABLE(DFG_JIT) |
489 |
beginMarking(); |
| 457 |
DFG::rememberCodeBlocks(*m_vm); |
|
|
| 458 |
#endif |
| 459 |
|
490 |
|
| 460 |
#if ENABLE(SAMPLING_PROFILER) |
491 |
m_parallelMarkersShouldExit = false; |
| 461 |
if (SamplingProfiler* samplingProfiler = m_vm->samplingProfiler()) { |
|
|
| 462 |
// Note that we need to own the lock from now until we're done |
| 463 |
// marking the SamplingProfiler's data because once we verify the |
| 464 |
// SamplingProfiler's stack traces, we don't want it to accumulate |
| 465 |
// more stack traces before we get the chance to mark it. |
| 466 |
// This lock is released inside visitSamplingProfiler(). |
| 467 |
samplingProfiler->getLock().lock(); |
| 468 |
samplingProfiler->processUnverifiedStackTraces(); |
| 469 |
} |
| 470 |
#endif // ENABLE(SAMPLING_PROFILER) |
| 471 |
|
492 |
|
| 472 |
if (m_collectionScope == CollectionScope::Full) { |
493 |
m_helperClient.setFunction( |
| 473 |
m_opaqueRoots.clear(); |
494 |
[this] () { |
| 474 |
m_slotVisitor.clearMarkStack(); |
495 |
SlotVisitor* slotVisitor; |
| 475 |
} |
496 |
{ |
| 476 |
|
497 |
LockHolder locker(m_parallelSlotVisitorLock); |
| 477 |
beginMarking(); |
498 |
if (m_availableParallelSlotVisitors.isEmpty()) { |
| 478 |
|
499 |
std::unique_ptr<SlotVisitor> newVisitor = |
| 479 |
m_parallelMarkersShouldExit = false; |
500 |
std::make_unique<SlotVisitor>(*this); |
| 480 |
|
501 |
slotVisitor = newVisitor.get(); |
| 481 |
m_helperClient.setFunction( |
502 |
m_parallelSlotVisitors.append(WTFMove(newVisitor)); |
| 482 |
[this] () { |
503 |
} else |
| 483 |
SlotVisitor* slotVisitor; |
504 |
slotVisitor = m_availableParallelSlotVisitors.takeLast(); |
| 484 |
{ |
505 |
} |
| 485 |
LockHolder locker(m_parallelSlotVisitorLock); |
|
|
| 486 |
if (m_availableParallelSlotVisitors.isEmpty()) { |
| 487 |
std::unique_ptr<SlotVisitor> newVisitor = |
| 488 |
std::make_unique<SlotVisitor>(*this); |
| 489 |
slotVisitor = newVisitor.get(); |
| 490 |
m_parallelSlotVisitors.append(WTFMove(newVisitor)); |
| 491 |
} else |
| 492 |
slotVisitor = m_availableParallelSlotVisitors.takeLast(); |
| 493 |
} |
| 494 |
|
506 |
|
| 495 |
WTF::registerGCThread(GCThreadType::Helper); |
507 |
WTF::registerGCThread(GCThreadType::Helper); |
| 496 |
|
508 |
|
| 497 |
{ |
509 |
{ |
| 498 |
ParallelModeEnabler parallelModeEnabler(*slotVisitor); |
510 |
ParallelModeEnabler parallelModeEnabler(*slotVisitor); |
| 499 |
slotVisitor->didStartMarking(); |
511 |
slotVisitor->didStartMarking(); |
| 500 |
slotVisitor->drainFromShared(SlotVisitor::SlaveDrain); |
512 |
slotVisitor->drainFromShared(SlotVisitor::SlaveDrain); |
| 501 |
} |
513 |
} |
| 502 |
|
514 |
|
| 503 |
{ |
515 |
{ |
| 504 |
LockHolder locker(m_parallelSlotVisitorLock); |
516 |
LockHolder locker(m_parallelSlotVisitorLock); |
| 505 |
m_availableParallelSlotVisitors.append(slotVisitor); |
517 |
m_availableParallelSlotVisitors.append(slotVisitor); |
| 506 |
} |
518 |
} |
| 507 |
}); |
519 |
}); |
| 508 |
|
520 |
|
| 509 |
m_slotVisitor.didStartMarking(); |
521 |
m_collectorSlotVisitor->didStartMarking(); |
| 510 |
} |
|
|
| 511 |
|
| 512 |
{ |
| 513 |
SuperSamplerScope superSamplerScope(false); |
| 514 |
TimingScope convergenceTimingScope(*this, "Heap::markRoots convergence"); |
| 515 |
ParallelModeEnabler enabler(m_slotVisitor); |
| 516 |
|
| 517 |
m_slotVisitor.donateAndDrain(); |
| 518 |
|
522 |
|
|
|
523 |
Seconds concurrentTime; |
| 524 |
double stoppedOverConcurrentRatio = 0.1; |
| 525 |
const double ratioStep = 1.3; |
| 526 |
MonotonicTime initialTime = MonotonicTime::now(); |
| 527 |
MonotonicTime topOfLoopTime = initialTime; |
| 528 |
while (true) { |
| 529 |
MonotonicTime timeToResume = topOfLoopTime + concurrentTime * stoppedOverConcurrentRatio; |
| 530 |
stoppedOverConcurrentRatio *= ratioStep; |
| 519 |
{ |
531 |
{ |
| 520 |
TimingScope preConvergenceTimingScope(*this, "Heap::markRoots conservative scan"); |
532 |
TimingScope preConvergenceTimingScope(*this, "Heap::markToFixpoint conservative scan"); |
| 521 |
ConservativeRoots conservativeRoots(*this); |
533 |
ConservativeRoots conservativeRoots(*this); |
| 522 |
SuperSamplerScope superSamplerScope(false); |
534 |
SuperSamplerScope superSamplerScope(false); |
| 523 |
gatherStackRoots(conservativeRoots); |
535 |
gatherStackRoots(conservativeRoots); |
| 524 |
gatherJSStackRoots(conservativeRoots); |
536 |
gatherJSStackRoots(conservativeRoots); |
| 525 |
gatherScratchBufferRoots(conservativeRoots); |
537 |
gatherScratchBufferRoots(conservativeRoots); |
| 526 |
visitConservativeRoots(conservativeRoots); |
538 |
visitConservativeRoots(conservativeRoots); |
|
|
539 |
} |
| 540 |
|
| 541 |
// Now we visit roots that don't get barriered, so each fixpoint iteration just revisits |
| 542 |
// all of them. |
| 543 |
#if JSC_OBJC_API_ENABLED |
| 544 |
scanExternalRememberedSet(*m_vm, *m_collectorSlotVisitor); |
| 545 |
#endif |
| 546 |
|
| 547 |
if (m_vm->smallStrings.needsToBeVisited(*m_collectionScope)) |
| 548 |
m_vm->smallStrings.visitStrongReferences(*m_collectorSlotVisitor); |
| 549 |
|
| 550 |
for (auto& pair : m_protectedValues) |
| 551 |
heapRootVisitor.visit(&pair.key); |
| 552 |
|
| 553 |
if (m_markListSet && m_markListSet->size()) |
| 554 |
MarkedArgumentBuffer::markLists(heapRootVisitor, *m_markListSet); |
| 527 |
|
555 |
|
| 528 |
// We want to do this to conservatively ensure that we rescan any code blocks that are |
556 |
if (m_vm->exception()) |
| 529 |
// running right now. However, we need to be sure to do it *after* we mark the code block |
557 |
heapRootVisitor.visit(m_vm->addressOfException()); |
| 530 |
// so that we know for sure if it really needs a barrier. |
558 |
if (m_vm->lastException()) |
| 531 |
m_codeBlocks->writeBarrierCurrentlyExecuting(this); |
559 |
heapRootVisitor.visit(m_vm->addressOfLastException()); |
| 532 |
} |
560 |
|
| 533 |
|
561 |
m_handleSet.visitStrongHandles(heapRootVisitor); |
| 534 |
visitExternalRememberedSet(); |
562 |
m_handleStack.visit(heapRootVisitor); |
| 535 |
visitSmallStrings(); |
563 |
|
| 536 |
visitProtectedObjects(heapRootVisitor); |
564 |
#if ENABLE(SAMPLING_PROFILER) |
| 537 |
visitArgumentBuffers(heapRootVisitor); |
565 |
if (SamplingProfiler* samplingProfiler = m_vm->samplingProfiler()) { |
| 538 |
visitException(heapRootVisitor); |
566 |
LockHolder locker(samplingProfiler->getLock()); |
| 539 |
visitStrongHandles(heapRootVisitor); |
567 |
samplingProfiler->processUnverifiedStackTraces(); |
| 540 |
visitHandleStack(heapRootVisitor); |
568 |
samplingProfiler->visit(*m_collectorSlotVisitor); |
| 541 |
visitSamplingProfiler(); |
569 |
if (Options::logGC() == GCLogging::Verbose) |
| 542 |
visitShadowChicken(); |
570 |
dataLog("Sampling Profiler data:\n", *m_collectorSlotVisitor); |
| 543 |
traceCodeBlocksAndJITStubRoutines(); |
571 |
} |
| 544 |
m_slotVisitor.drainFromShared(SlotVisitor::MasterDrain); |
572 |
#endif // ENABLE(SAMPLING_PROFILER) |
| 545 |
} |
573 |
|
| 546 |
|
574 |
m_vm->shadowChicken().visitChildren(*m_collectorSlotVisitor); |
| 547 |
TimingScope postConvergenceTimingScope(*this, "Heap::markRoots after convergence"); |
575 |
|
| 548 |
|
576 |
m_jitStubRoutines->traceMarkedStubRoutines(*m_collectorSlotVisitor); |
| 549 |
// Weak references must be marked last because their liveness depends on |
577 |
|
| 550 |
// the liveness of the rest of the object graph. |
578 |
m_collectorSlotVisitor->mergeOpaqueRootsIfNecessary(); |
| 551 |
visitWeakHandles(heapRootVisitor); |
579 |
for (auto& parallelVisitor : m_parallelSlotVisitors) |
|
|
580 |
parallelVisitor->mergeOpaqueRootsIfNecessary(); |
| 581 |
|
| 582 |
m_objectSpace.visitWeakSets(heapRootVisitor); |
| 583 |
harvestWeakReferences(); |
| 584 |
visitCompilerWorklistWeakReferences(); |
| 585 |
DFG::markCodeBlocks(*m_vm, *m_collectorSlotVisitor); |
| 586 |
bool shouldTerminate = m_collectorSlotVisitor->isEmpty() && m_mutatorMarkStack->isEmpty(); |
| 587 |
|
| 588 |
// We want to do this to conservatively ensure that we rescan any code blocks that are |
| 589 |
// running right now. However, we need to be sure to do it *after* we mark the code block |
| 590 |
// so that we know for sure if it really needs a barrier. Also, this has to happen after the |
| 591 |
// fixpoint check - otherwise we might loop forever. Incidentally, we also want to do this |
| 592 |
// at the end of GC so that anything at the end of the last GC gets barriered in the next |
| 593 |
// GC. |
| 594 |
m_codeBlocks->writeBarrierCurrentlyExecuting(this); |
| 595 |
DFG::rememberCodeBlocks(*m_vm); |
| 596 |
|
| 597 |
if (shouldTerminate) |
| 598 |
break; |
| 599 |
|
| 600 |
// The SlotVisitor's mark stacks are accessed by the collector thread (i.e. this thread) |
| 601 |
// without locks. That's why we double-buffer. |
| 602 |
m_mutatorMarkStack->transferTo(m_collectorSlotVisitor->mutatorMarkStack()); |
| 603 |
|
| 604 |
if (Options::logGC() == GCLogging::Verbose) |
| 605 |
dataLog("Live Weak Handles:\n", *m_collectorSlotVisitor); |
| 606 |
|
| 607 |
{ |
| 608 |
TimingScope traceTimingScope(*this, "Heap::markToFixpoint tracing"); |
| 609 |
ParallelModeEnabler enabler(*m_collectorSlotVisitor); |
| 610 |
m_collectorSlotVisitor->donateAndDrain(timeToResume); |
| 611 |
SlotVisitor::SharedDrainResult drainResult = |
| 612 |
m_collectorSlotVisitor->drainFromShared(SlotVisitor::MasterDrain, timeToResume); |
| 613 |
if (drainResult != SlotVisitor::SharedDrainResult::Done) { |
| 614 |
ResumeTheWorldScope resumeTheWorldScope(*this); |
| 615 |
m_collectorSlotVisitor->donateAndDrain(); |
| 616 |
m_collectorSlotVisitor->drainFromShared(SlotVisitor::MasterDrain); |
| 617 |
} |
| 618 |
} |
| 619 |
|
| 620 |
MonotonicTime timeOfStop = MonotonicTime::now(); |
| 621 |
concurrentTime = timeOfStop - timeToResume; |
| 622 |
topOfLoopTime = timeOfStop; |
| 623 |
} |
| 552 |
|
624 |
|
| 553 |
{ |
625 |
{ |
| 554 |
std::lock_guard<Lock> lock(m_markingMutex); |
626 |
std::lock_guard<Lock> lock(m_markingMutex); |
|
Lines 562-568
void Heap::markRoots(double gcStartTime)
Source/JavaScriptCore/heap/Heap.cpp_sec6
|
| 562 |
|
634 |
|
| 563 |
void Heap::gatherStackRoots(ConservativeRoots& roots) |
635 |
void Heap::gatherStackRoots(ConservativeRoots& roots) |
| 564 |
{ |
636 |
{ |
| 565 |
m_jitStubRoutines->clearMarks(); |
|
|
| 566 |
m_machineThreads.gatherConservativeRoots(roots, *m_jitStubRoutines, *m_codeBlocks); |
637 |
m_machineThreads.gatherConservativeRoots(roots, *m_jitStubRoutines, *m_codeBlocks); |
| 567 |
} |
638 |
} |
| 568 |
|
639 |
|
|
Lines 589-594
void Heap::beginMarking()
Source/JavaScriptCore/heap/Heap.cpp_sec7
|
| 589 |
TimingScope timingScope(*this, "Heap::beginMarking"); |
660 |
TimingScope timingScope(*this, "Heap::beginMarking"); |
| 590 |
if (m_collectionScope == CollectionScope::Full) |
661 |
if (m_collectionScope == CollectionScope::Full) |
| 591 |
m_codeBlocks->clearMarksForFullCollection(); |
662 |
m_codeBlocks->clearMarksForFullCollection(); |
|
|
663 |
m_jitStubRoutines->clearMarks(); |
| 592 |
|
664 |
|
| 593 |
{ |
665 |
{ |
| 594 |
TimingScope clearMarksTimingScope(*this, "m_objectSpace.beginMarking"); |
666 |
TimingScope clearMarksTimingScope(*this, "m_objectSpace.beginMarking"); |
|
Lines 596-637
void Heap::beginMarking()
Source/JavaScriptCore/heap/Heap.cpp_sec8
|
| 596 |
} |
668 |
} |
| 597 |
} |
669 |
} |
| 598 |
|
670 |
|
| 599 |
void Heap::visitExternalRememberedSet() |
|
|
| 600 |
{ |
| 601 |
#if JSC_OBJC_API_ENABLED |
| 602 |
scanExternalRememberedSet(*m_vm, m_slotVisitor); |
| 603 |
#endif |
| 604 |
} |
| 605 |
|
| 606 |
void Heap::visitSmallStrings() |
| 607 |
{ |
| 608 |
if (!m_vm->smallStrings.needsToBeVisited(*m_collectionScope)) |
| 609 |
return; |
| 610 |
|
| 611 |
m_vm->smallStrings.visitStrongReferences(m_slotVisitor); |
| 612 |
if (Options::logGC() == GCLogging::Verbose) |
| 613 |
dataLog("Small strings:\n", m_slotVisitor); |
| 614 |
m_slotVisitor.donateAndDrain(); |
| 615 |
} |
| 616 |
|
| 617 |
void Heap::visitConservativeRoots(ConservativeRoots& roots) |
671 |
void Heap::visitConservativeRoots(ConservativeRoots& roots) |
| 618 |
{ |
672 |
{ |
| 619 |
m_slotVisitor.append(roots); |
673 |
m_collectorSlotVisitor->append(roots); |
| 620 |
|
674 |
|
| 621 |
if (Options::logGC() == GCLogging::Verbose) |
675 |
if (Options::logGC() == GCLogging::Verbose) |
| 622 |
dataLog("Conservative Roots:\n", m_slotVisitor); |
676 |
dataLog("Conservative Roots:\n", *m_collectorSlotVisitor); |
| 623 |
|
|
|
| 624 |
m_slotVisitor.donateAndDrain(); |
| 625 |
} |
677 |
} |
| 626 |
|
678 |
|
| 627 |
void Heap::visitCompilerWorklistWeakReferences() |
679 |
void Heap::visitCompilerWorklistWeakReferences() |
| 628 |
{ |
680 |
{ |
| 629 |
#if ENABLE(DFG_JIT) |
681 |
#if ENABLE(DFG_JIT) |
| 630 |
for (unsigned i = DFG::numberOfWorklists(); i--;) |
682 |
for (unsigned i = DFG::numberOfWorklists(); i--;) |
| 631 |
DFG::existingWorklistForIndex(i).visitWeakReferences(m_slotVisitor); |
683 |
DFG::existingWorklistForIndex(i).visitWeakReferences(*m_collectorSlotVisitor); |
| 632 |
|
684 |
|
| 633 |
if (Options::logGC() == GCLogging::Verbose) |
685 |
if (Options::logGC() == GCLogging::Verbose) |
| 634 |
dataLog("DFG Worklists:\n", m_slotVisitor); |
686 |
dataLog("DFG Worklists:\n", *m_collectorSlotVisitor); |
| 635 |
#endif |
687 |
#endif |
| 636 |
} |
688 |
} |
| 637 |
|
689 |
|
|
Lines 704-825
void Heap::removeDeadHeapSnapshotNodes(H
Source/JavaScriptCore/heap/Heap.cpp_sec9
|
| 704 |
} |
756 |
} |
| 705 |
} |
757 |
} |
| 706 |
|
758 |
|
| 707 |
void Heap::visitProtectedObjects(HeapRootVisitor& heapRootVisitor) |
|
|
| 708 |
{ |
| 709 |
for (auto& pair : m_protectedValues) |
| 710 |
heapRootVisitor.visit(&pair.key); |
| 711 |
|
| 712 |
if (Options::logGC() == GCLogging::Verbose) |
| 713 |
dataLog("Protected Objects:\n", m_slotVisitor); |
| 714 |
|
| 715 |
m_slotVisitor.donateAndDrain(); |
| 716 |
} |
| 717 |
|
| 718 |
void Heap::visitArgumentBuffers(HeapRootVisitor& visitor) |
| 719 |
{ |
| 720 |
if (!m_markListSet || !m_markListSet->size()) |
| 721 |
return; |
| 722 |
|
| 723 |
MarkedArgumentBuffer::markLists(visitor, *m_markListSet); |
| 724 |
|
| 725 |
if (Options::logGC() == GCLogging::Verbose) |
| 726 |
dataLog("Argument Buffers:\n", m_slotVisitor); |
| 727 |
|
| 728 |
m_slotVisitor.donateAndDrain(); |
| 729 |
} |
| 730 |
|
| 731 |
void Heap::visitException(HeapRootVisitor& visitor) |
| 732 |
{ |
| 733 |
if (!m_vm->exception() && !m_vm->lastException()) |
| 734 |
return; |
| 735 |
|
| 736 |
visitor.visit(m_vm->addressOfException()); |
| 737 |
visitor.visit(m_vm->addressOfLastException()); |
| 738 |
|
| 739 |
if (Options::logGC() == GCLogging::Verbose) |
| 740 |
dataLog("Exceptions:\n", m_slotVisitor); |
| 741 |
|
| 742 |
m_slotVisitor.donateAndDrain(); |
| 743 |
} |
| 744 |
|
| 745 |
void Heap::visitStrongHandles(HeapRootVisitor& visitor) |
| 746 |
{ |
| 747 |
m_handleSet.visitStrongHandles(visitor); |
| 748 |
|
| 749 |
if (Options::logGC() == GCLogging::Verbose) |
| 750 |
dataLog("Strong Handles:\n", m_slotVisitor); |
| 751 |
|
| 752 |
m_slotVisitor.donateAndDrain(); |
| 753 |
} |
| 754 |
|
| 755 |
void Heap::visitHandleStack(HeapRootVisitor& visitor) |
| 756 |
{ |
| 757 |
m_handleStack.visit(visitor); |
| 758 |
|
| 759 |
if (Options::logGC() == GCLogging::Verbose) |
| 760 |
dataLog("Handle Stack:\n", m_slotVisitor); |
| 761 |
|
| 762 |
m_slotVisitor.donateAndDrain(); |
| 763 |
} |
| 764 |
|
| 765 |
void Heap::visitSamplingProfiler() |
| 766 |
{ |
| 767 |
#if ENABLE(SAMPLING_PROFILER) |
| 768 |
if (SamplingProfiler* samplingProfiler = m_vm->samplingProfiler()) { |
| 769 |
ASSERT(samplingProfiler->getLock().isLocked()); |
| 770 |
samplingProfiler->visit(m_slotVisitor); |
| 771 |
if (Options::logGC() == GCLogging::Verbose) |
| 772 |
dataLog("Sampling Profiler data:\n", m_slotVisitor); |
| 773 |
|
| 774 |
m_slotVisitor.donateAndDrain(); |
| 775 |
samplingProfiler->getLock().unlock(); |
| 776 |
} |
| 777 |
#endif // ENABLE(SAMPLING_PROFILER) |
| 778 |
} |
| 779 |
|
| 780 |
void Heap::visitShadowChicken() |
| 781 |
{ |
| 782 |
m_vm->shadowChicken().visitChildren(m_slotVisitor); |
| 783 |
} |
| 784 |
|
| 785 |
void Heap::traceCodeBlocksAndJITStubRoutines() |
| 786 |
{ |
| 787 |
m_jitStubRoutines->traceMarkedStubRoutines(m_slotVisitor); |
| 788 |
|
| 789 |
if (Options::logGC() == GCLogging::Verbose) |
| 790 |
dataLog("Code Blocks and JIT Stub Routines:\n", m_slotVisitor); |
| 791 |
|
| 792 |
m_slotVisitor.donateAndDrain(); |
| 793 |
} |
| 794 |
|
| 795 |
void Heap::visitWeakHandles(HeapRootVisitor& visitor) |
| 796 |
{ |
| 797 |
TimingScope timingScope(*this, "Heap::visitWeakHandles"); |
| 798 |
while (true) { |
| 799 |
{ |
| 800 |
TimingScope timingScope(*this, "m_objectSpace.visitWeakSets"); |
| 801 |
m_objectSpace.visitWeakSets(visitor); |
| 802 |
} |
| 803 |
harvestWeakReferences(); |
| 804 |
visitCompilerWorklistWeakReferences(); |
| 805 |
if (m_slotVisitor.isEmpty()) |
| 806 |
break; |
| 807 |
|
| 808 |
if (Options::logGC() == GCLogging::Verbose) |
| 809 |
dataLog("Live Weak Handles:\n", m_slotVisitor); |
| 810 |
|
| 811 |
{ |
| 812 |
ParallelModeEnabler enabler(m_slotVisitor); |
| 813 |
m_slotVisitor.donateAndDrain(); |
| 814 |
m_slotVisitor.drainFromShared(SlotVisitor::MasterDrain); |
| 815 |
} |
| 816 |
} |
| 817 |
} |
| 818 |
|
| 819 |
void Heap::updateObjectCounts(double gcStartTime) |
759 |
void Heap::updateObjectCounts(double gcStartTime) |
| 820 |
{ |
760 |
{ |
| 821 |
if (Options::logGC() == GCLogging::Verbose) { |
761 |
if (Options::logGC() == GCLogging::Verbose) { |
| 822 |
size_t visitCount = m_slotVisitor.visitCount(); |
762 |
size_t visitCount = m_collectorSlotVisitor->visitCount(); |
| 823 |
visitCount += threadVisitCount(); |
763 |
visitCount += threadVisitCount(); |
| 824 |
dataLogF("\nNumber of live Objects after GC %lu, took %.6f secs\n", static_cast<unsigned long>(visitCount), WTF::monotonicallyIncreasingTime() - gcStartTime); |
764 |
dataLogF("\nNumber of live Objects after GC %lu, took %.6f secs\n", static_cast<unsigned long>(visitCount), WTF::monotonicallyIncreasingTime() - gcStartTime); |
| 825 |
} |
765 |
} |
|
Lines 827-845
void Heap::updateObjectCounts(double gcS
Source/JavaScriptCore/heap/Heap.cpp_sec10
|
| 827 |
if (m_collectionScope == CollectionScope::Full) |
767 |
if (m_collectionScope == CollectionScope::Full) |
| 828 |
m_totalBytesVisited = 0; |
768 |
m_totalBytesVisited = 0; |
| 829 |
|
769 |
|
| 830 |
m_totalBytesVisitedThisCycle = m_slotVisitor.bytesVisited() + threadBytesVisited(); |
770 |
m_totalBytesVisitedThisCycle = |
|
|
771 |
m_collectorSlotVisitor->bytesVisited() + |
| 772 |
threadBytesVisited(); |
| 831 |
|
773 |
|
| 832 |
m_totalBytesVisited += m_totalBytesVisitedThisCycle; |
774 |
m_totalBytesVisited += m_totalBytesVisitedThisCycle; |
| 833 |
} |
775 |
} |
| 834 |
|
776 |
|
| 835 |
void Heap::endMarking() |
777 |
void Heap::endMarking() |
| 836 |
{ |
778 |
{ |
| 837 |
m_slotVisitor.reset(); |
779 |
m_collectorSlotVisitor->reset(); |
| 838 |
|
780 |
|
| 839 |
for (auto& parallelVisitor : m_parallelSlotVisitors) |
781 |
for (auto& parallelVisitor : m_parallelSlotVisitors) |
| 840 |
parallelVisitor->reset(); |
782 |
parallelVisitor->reset(); |
| 841 |
|
783 |
|
| 842 |
ASSERT(m_sharedMarkStack.isEmpty()); |
784 |
RELEASE_ASSERT(m_sharedCollectorMarkStack->isEmpty()); |
|
|
785 |
RELEASE_ASSERT(m_sharedMutatorMarkStack->isEmpty()); |
| 843 |
m_weakReferenceHarvesters.removeAll(); |
786 |
m_weakReferenceHarvesters.removeAll(); |
| 844 |
|
787 |
|
| 845 |
m_objectSpace.endMarking(); |
788 |
m_objectSpace.endMarking(); |
|
Lines 977-990
void Heap::addToRememberedSet(const JSCe
Source/JavaScriptCore/heap/Heap.cpp_sec11
|
| 977 |
{ |
920 |
{ |
| 978 |
ASSERT(cell); |
921 |
ASSERT(cell); |
| 979 |
ASSERT(!Options::useConcurrentJIT() || !isCompilationThread()); |
922 |
ASSERT(!Options::useConcurrentJIT() || !isCompilationThread()); |
| 980 |
ASSERT(cell->cellState() == CellState::AnthraciteOrBlack); |
923 |
if (!Heap::isMarkedConcurrently(cell)) { |
| 981 |
// Indicate that this object is grey and that it's one of the following: |
924 |
// During a full collection a store into an unmarked object that had surivived past |
| 982 |
// - A re-greyed object during a concurrent collection. |
925 |
// collections will manifest as a store to an unmarked black object. If the object gets |
| 983 |
// - An old remembered object. |
926 |
// marked at some time after this then it will go down the normal marking path. We can |
| 984 |
// "OldGrey" doesn't tell us which of these things is true, but we usually treat the two cases the |
927 |
// safely ignore these stores. |
| 985 |
// same. |
928 |
return; |
| 986 |
cell->setCellState(CellState::OldGrey); |
929 |
} |
| 987 |
m_slotVisitor.appendToMarkStack(const_cast<JSCell*>(cell)); |
930 |
// It could be that the object was *just* marked. This means that the collector may set the |
|
|
931 |
// state to Grey and then to AnthraciteOrBlack at any time. It's OK for us to race with the |
| 932 |
// collector here. If we win then this is accurate because the object _will_ get scanned again. |
| 933 |
// If we lose then someone else will barrier the object again. That would be unfortunate but not |
| 934 |
// the end of the world. |
| 935 |
cell->setCellState(CellState::Grey); |
| 936 |
m_mutatorMarkStack->append(cell); |
| 988 |
} |
937 |
} |
| 989 |
|
938 |
|
| 990 |
void Heap::collectAllGarbage() |
939 |
void Heap::collectAllGarbage() |
|
Lines 1083-1111
void Heap::collectInThread()
Source/JavaScriptCore/heap/Heap.cpp_sec12
|
| 1083 |
|
1032 |
|
| 1084 |
stopTheWorld(); |
1033 |
stopTheWorld(); |
| 1085 |
|
1034 |
|
| 1086 |
double before = 0; |
1035 |
MonotonicTime before; |
| 1087 |
if (Options::logGC()) { |
1036 |
if (Options::logGC()) { |
| 1088 |
dataLog("[GC: ", capacity() / 1024, " kb "); |
1037 |
dataLog("[GC: ", capacity() / 1024, " kb "); |
| 1089 |
before = currentTimeMS(); |
1038 |
before = MonotonicTime::now(); |
| 1090 |
} |
1039 |
} |
| 1091 |
|
1040 |
|
| 1092 |
double gcStartTime; |
1041 |
double gcStartTime; |
| 1093 |
|
1042 |
|
| 1094 |
if (vm()->typeProfiler()) { |
|
|
| 1095 |
DeferGCForAWhile awhile(*this); |
| 1096 |
vm()->typeProfilerLog()->processLogEntries(ASCIILiteral("GC")); |
| 1097 |
} |
| 1098 |
|
| 1099 |
#if ENABLE(JIT) |
| 1100 |
{ |
| 1101 |
DeferGCForAWhile awhile(*this); |
| 1102 |
if (JITWorklist::instance()->completeAllForVM(*m_vm)) |
| 1103 |
setGCDidJIT(); |
| 1104 |
} |
| 1105 |
#endif // ENABLE(JIT) |
| 1106 |
|
| 1107 |
vm()->shadowChicken().update(*vm(), vm()->topCallFrame); |
| 1108 |
|
| 1109 |
ASSERT(m_isSafeToCollect); |
1043 |
ASSERT(m_isSafeToCollect); |
| 1110 |
if (m_collectionScope) { |
1044 |
if (m_collectionScope) { |
| 1111 |
dataLog("Collection scope already set during GC: ", m_collectionScope, "\n"); |
1045 |
dataLog("Collection scope already set during GC: ", m_collectionScope, "\n"); |
|
Lines 1125-1139
void Heap::collectInThread()
Source/JavaScriptCore/heap/Heap.cpp_sec13
|
| 1125 |
m_verifier->gatherLiveObjects(HeapVerifier::Phase::BeforeMarking); |
1059 |
m_verifier->gatherLiveObjects(HeapVerifier::Phase::BeforeMarking); |
| 1126 |
} |
1060 |
} |
| 1127 |
|
1061 |
|
| 1128 |
flushOldStructureIDTables(); |
|
|
| 1129 |
stopAllocation(); |
| 1130 |
prepareForMarking(); |
1062 |
prepareForMarking(); |
| 1131 |
flushWriteBarrierBuffer(); |
|
|
| 1132 |
|
1063 |
|
| 1133 |
if (HasOwnPropertyCache* cache = vm()->hasOwnPropertyCache()) |
1064 |
if (HasOwnPropertyCache* cache = vm()->hasOwnPropertyCache()) |
| 1134 |
cache->clear(); |
1065 |
cache->clear(); |
| 1135 |
|
1066 |
|
| 1136 |
markRoots(gcStartTime); |
1067 |
markToFixpoint(gcStartTime); |
| 1137 |
|
1068 |
|
| 1138 |
if (m_verifier) { |
1069 |
if (m_verifier) { |
| 1139 |
m_verifier->gatherLiveObjects(HeapVerifier::Phase::AfterMarking); |
1070 |
m_verifier->gatherLiveObjects(HeapVerifier::Phase::AfterMarking); |
|
Lines 1170-1177
void Heap::collectInThread()
Source/JavaScriptCore/heap/Heap.cpp_sec14
|
| 1170 |
} |
1101 |
} |
| 1171 |
|
1102 |
|
| 1172 |
if (Options::logGC()) { |
1103 |
if (Options::logGC()) { |
| 1173 |
double after = currentTimeMS(); |
1104 |
MonotonicTime after = MonotonicTime::now(); |
| 1174 |
dataLog(after - before, " ms]\n"); |
1105 |
dataLog((after - m_stopTime).milliseconds(), " ms, cycle ", (after - before).milliseconds(), " ms]\n"); |
| 1175 |
} |
1106 |
} |
| 1176 |
|
1107 |
|
| 1177 |
{ |
1108 |
{ |
|
Lines 1193-1202
void Heap::stopTheWorld()
Source/JavaScriptCore/heap/Heap.cpp_sec15
|
| 1193 |
stopTheMutator(); |
1124 |
stopTheMutator(); |
| 1194 |
suspendCompilerThreads(); |
1125 |
suspendCompilerThreads(); |
| 1195 |
m_collectorBelievesThatTheWorldIsStopped = true; |
1126 |
m_collectorBelievesThatTheWorldIsStopped = true; |
|
|
1127 |
|
| 1128 |
if (vm()->typeProfiler()) { |
| 1129 |
DeferGCForAWhile awhile(*this); |
| 1130 |
vm()->typeProfilerLog()->processLogEntries(ASCIILiteral("GC")); |
| 1131 |
} |
| 1132 |
|
| 1133 |
#if ENABLE(JIT) |
| 1134 |
{ |
| 1135 |
DeferGCForAWhile awhile(*this); |
| 1136 |
if (JITWorklist::instance()->completeAllForVM(*m_vm)) |
| 1137 |
setGCDidJIT(); |
| 1138 |
} |
| 1139 |
#endif // ENABLE(JIT) |
| 1140 |
|
| 1141 |
vm()->shadowChicken().update(*vm(), vm()->topCallFrame); |
| 1142 |
|
| 1143 |
flushWriteBarrierBuffer(); |
| 1144 |
m_structureIDTable.flushOldTables(); |
| 1145 |
m_objectSpace.stopAllocating(); |
| 1146 |
|
| 1147 |
m_stopTime = MonotonicTime::now(); |
| 1196 |
} |
1148 |
} |
| 1197 |
|
1149 |
|
| 1198 |
void Heap::resumeTheWorld() |
1150 |
void Heap::resumeTheWorld() |
| 1199 |
{ |
1151 |
{ |
|
|
1152 |
// Calling resumeAllocating does the Right Thing depending on whether this is the end of a |
| 1153 |
// collection cycle or this is just a concurrent phase within a collection cycle: |
| 1154 |
// - At end of collection cycle: it's a no-op because prepareForAllocation already cleared the |
| 1155 |
// last active block. |
| 1156 |
// - During collection cycle: it reinstates the last active block. |
| 1157 |
m_objectSpace.resumeAllocating(); |
| 1158 |
|
| 1200 |
RELEASE_ASSERT(m_collectorBelievesThatTheWorldIsStopped); |
1159 |
RELEASE_ASSERT(m_collectorBelievesThatTheWorldIsStopped); |
| 1201 |
m_collectorBelievesThatTheWorldIsStopped = false; |
1160 |
m_collectorBelievesThatTheWorldIsStopped = false; |
| 1202 |
resumeCompilerThreads(); |
1161 |
resumeCompilerThreads(); |
|
Lines 1466-1475
void Heap::notifyThreadStopping(const Lo
Source/JavaScriptCore/heap/Heap.cpp_sec16
|
| 1466 |
|
1425 |
|
| 1467 |
void Heap::finalize() |
1426 |
void Heap::finalize() |
| 1468 |
{ |
1427 |
{ |
| 1469 |
HelpingGCScope helpingGCScope(*this); |
1428 |
{ |
| 1470 |
deleteUnmarkedCompiledCode(); |
1429 |
HelpingGCScope helpingGCScope(*this); |
| 1471 |
deleteSourceProviderCaches(); |
1430 |
deleteUnmarkedCompiledCode(); |
| 1472 |
sweepLargeAllocations(); |
1431 |
deleteSourceProviderCaches(); |
|
|
1432 |
sweepLargeAllocations(); |
| 1433 |
} |
| 1434 |
|
| 1435 |
if (Options::collectContinuously()) |
| 1436 |
collectAsync(); |
| 1473 |
} |
1437 |
} |
| 1474 |
|
1438 |
|
| 1475 |
Heap::Ticket Heap::requestCollection(Optional<CollectionScope> scope) |
1439 |
Heap::Ticket Heap::requestCollection(Optional<CollectionScope> scope) |
|
Lines 1549-1571
void Heap::willStartCollection(Optional<
Source/JavaScriptCore/heap/Heap.cpp_sec17
|
| 1549 |
observer->willGarbageCollect(); |
1513 |
observer->willGarbageCollect(); |
| 1550 |
} |
1514 |
} |
| 1551 |
|
1515 |
|
| 1552 |
void Heap::flushOldStructureIDTables() |
|
|
| 1553 |
{ |
| 1554 |
m_structureIDTable.flushOldTables(); |
| 1555 |
} |
| 1556 |
|
| 1557 |
void Heap::flushWriteBarrierBuffer() |
1516 |
void Heap::flushWriteBarrierBuffer() |
| 1558 |
{ |
1517 |
{ |
| 1559 |
if (m_collectionScope == CollectionScope::Eden) { |
1518 |
m_writeBarrierBuffer.flush(*this); |
| 1560 |
m_writeBarrierBuffer.flush(*this); |
|
|
| 1561 |
return; |
| 1562 |
} |
| 1563 |
m_writeBarrierBuffer.reset(); |
| 1564 |
} |
| 1565 |
|
| 1566 |
void Heap::stopAllocation() |
| 1567 |
{ |
| 1568 |
m_objectSpace.stopAllocating(); |
| 1569 |
} |
1519 |
} |
| 1570 |
|
1520 |
|
| 1571 |
void Heap::prepareForMarking() |
1521 |
void Heap::prepareForMarking() |
|
Lines 1949-1955
bool Heap::canCollect()
Source/JavaScriptCore/heap/Heap.cpp_sec18
|
| 1949 |
return false; |
1899 |
return false; |
| 1950 |
if (!m_isSafeToCollect) |
1900 |
if (!m_isSafeToCollect) |
| 1951 |
return false; |
1901 |
return false; |
| 1952 |
if (collectionScope() || mutatorState() == MutatorState::HelpingGC) |
1902 |
if (mutatorState() == MutatorState::HelpingGC) |
| 1953 |
return false; |
1903 |
return false; |
| 1954 |
return true; |
1904 |
return true; |
| 1955 |
} |
1905 |
} |
|
Lines 1971-1982
bool Heap::isCurrentThreadBusy()
Source/JavaScriptCore/heap/Heap.cpp_sec19
|
| 1971 |
return mayBeGCThread() || mutatorState() != MutatorState::Running; |
1921 |
return mayBeGCThread() || mutatorState() != MutatorState::Running; |
| 1972 |
} |
1922 |
} |
| 1973 |
|
1923 |
|
| 1974 |
void Heap::reportExtraMemoryVisited(CellState oldState, size_t size) |
1924 |
void Heap::reportExtraMemoryVisited(size_t size) |
| 1975 |
{ |
1925 |
{ |
| 1976 |
// We don't want to double-count the extra memory that was reported in previous collections. |
|
|
| 1977 |
if (collectionScope() == CollectionScope::Eden && oldState == CellState::OldGrey) |
| 1978 |
return; |
| 1979 |
|
| 1980 |
size_t* counter = &m_extraMemorySize; |
1926 |
size_t* counter = &m_extraMemorySize; |
| 1981 |
|
1927 |
|
| 1982 |
for (;;) { |
1928 |
for (;;) { |
|
Lines 1987-1998
void Heap::reportExtraMemoryVisited(Cell
Source/JavaScriptCore/heap/Heap.cpp_sec20
|
| 1987 |
} |
1933 |
} |
| 1988 |
|
1934 |
|
| 1989 |
#if ENABLE(RESOURCE_USAGE) |
1935 |
#if ENABLE(RESOURCE_USAGE) |
| 1990 |
void Heap::reportExternalMemoryVisited(CellState oldState, size_t size) |
1936 |
void Heap::reportExternalMemoryVisited(size_t size) |
| 1991 |
{ |
1937 |
{ |
| 1992 |
// We don't want to double-count the external memory that was reported in previous collections. |
|
|
| 1993 |
if (collectionScope() == CollectionScope::Eden && oldState == CellState::OldGrey) |
| 1994 |
return; |
| 1995 |
|
| 1996 |
size_t* counter = &m_externalMemorySize; |
1938 |
size_t* counter = &m_externalMemorySize; |
| 1997 |
|
1939 |
|
| 1998 |
for (;;) { |
1940 |
for (;;) { |
|
Lines 2086-2089
void Heap::setRunLoop(CFRunLoopRef runLo
Source/JavaScriptCore/heap/Heap.cpp_sec21
|
| 2086 |
} |
2028 |
} |
| 2087 |
#endif // USE(CF) |
2029 |
#endif // USE(CF) |
| 2088 |
|
2030 |
|
|
|
2031 |
void Heap::notifyIsSafeToCollect() |
| 2032 |
{ |
| 2033 |
m_isSafeToCollect = true; |
| 2034 |
if (Options::collectContinuously()) |
| 2035 |
collectAsync(); |
| 2036 |
} |
| 2037 |
|
| 2089 |
} // namespace JSC |
2038 |
} // namespace JSC |