Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(167)

Unified Diff: third_party/WebKit/Source/platform/heap/ThreadState.cpp

Issue 2690943009: Move postGC out of CrossThreadPersistentRegion::LockScope (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/platform/heap/ThreadState.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/platform/heap/ThreadState.cpp
diff --git a/third_party/WebKit/Source/platform/heap/ThreadState.cpp b/third_party/WebKit/Source/platform/heap/ThreadState.cpp
index d9cf18fc6c2df33ef752494f5c274cc5c43534a2..b781c6c11781548d8f6ea5a5008b70cab23a9f67 100644
--- a/third_party/WebKit/Source/platform/heap/ThreadState.cpp
+++ b/third_party/WebKit/Source/platform/heap/ThreadState.cpp
@@ -1040,7 +1040,11 @@ void ThreadState::postGC(BlinkGC::GCType gcType) {
ASSERT(checkThread());
threadLocalWeakProcessing();
+}
+void ThreadState::preSweep(BlinkGC::GCType gcType) {
+ if (gcState() == NoGCScheduled)
+ return;
// We have to set the GCState to Sweeping before calling pre-finalizers
// to disallow a GC during the pre-finalizers.
setGCState(Sweeping);
@@ -1612,128 +1616,129 @@ void ThreadState::collectGarbage(BlinkGC::StackState stackState,
RELEASE_ASSERT(!isGCForbidden());
completeSweep();
- // Access to the CrossThreadPersistentRegion has to be prevented while
- // in the stop-the-world phase. If not, threads not attached to Oilpan
- // and participating in this GC are able to allocate & free PersistentNodes,
- // something the marking phase isn't capable of handling.
- CrossThreadPersistentRegion::LockScope persistentLock(
- ProcessHeap::crossThreadPersistentRegion());
-
GCForbiddenScope gcForbiddenScope(this);
{
- SafePointScope safePointScope(stackState, this);
+ // Access to the CrossThreadPersistentRegion has to be prevented while in
+ // the marking phase because otherwise other threads may allocate or free
+ // PersistentNodes and we can't handle that.
+ CrossThreadPersistentRegion::LockScope persistentLock(
+ ProcessHeap::crossThreadPersistentRegion());
+ {
+ SafePointScope safePointScope(stackState, this);
- // Resume all parked threads upon leaving this scope.
- ParkThreadsScope parkThreadsScope(this);
+ // Resume all parked threads upon leaving this scope.
+ ParkThreadsScope parkThreadsScope(this);
- // Try to park the other threads. If we're unable to, bail out of the GC.
- if (!parkThreadsScope.parkThreads())
- return;
+ // Try to park the other threads. If we're unable to, bail out of the GC.
+ if (!parkThreadsScope.parkThreads())
+ return;
- std::unique_ptr<Visitor> visitor;
- if (gcType == BlinkGC::TakeSnapshot) {
- visitor = Visitor::create(this, VisitorMarkingMode::SnapshotMarking);
- } else {
- DCHECK(gcType == BlinkGC::GCWithSweep ||
- gcType == BlinkGC::GCWithoutSweep);
- if (heap().compaction()->shouldCompact(this, gcType, reason)) {
- heap().compaction()->initialize(this);
- visitor = Visitor::create(
- this, VisitorMarkingMode::GlobalMarkingWithCompaction);
+ std::unique_ptr<Visitor> visitor;
+ if (gcType == BlinkGC::TakeSnapshot) {
+ visitor = Visitor::create(this, VisitorMarkingMode::SnapshotMarking);
} else {
- visitor = Visitor::create(this, VisitorMarkingMode::GlobalMarking);
+ DCHECK(gcType == BlinkGC::GCWithSweep ||
+ gcType == BlinkGC::GCWithoutSweep);
+ if (heap().compaction()->shouldCompact(this, gcType, reason)) {
+ heap().compaction()->initialize(this);
+ visitor = Visitor::create(
+ this, VisitorMarkingMode::GlobalMarkingWithCompaction);
+ } else {
+ visitor = Visitor::create(this, VisitorMarkingMode::GlobalMarking);
+ }
}
- }
- ScriptForbiddenIfMainThreadScope scriptForbidden;
+ ScriptForbiddenIfMainThreadScope scriptForbidden;
- TRACE_EVENT2("blink_gc,devtools.timeline", "BlinkGCMarking", "lazySweeping",
- gcType == BlinkGC::GCWithoutSweep, "gcReason",
- gcReasonString(reason));
- double startTime = WTF::currentTimeMS();
+ TRACE_EVENT2("blink_gc,devtools.timeline", "BlinkGCMarking",
+ "lazySweeping", gcType == BlinkGC::GCWithoutSweep,
+ "gcReason", gcReasonString(reason));
+ double startTime = WTF::currentTimeMS();
- if (gcType == BlinkGC::TakeSnapshot)
- BlinkGCMemoryDumpProvider::instance()->clearProcessDumpForCurrentGC();
+ if (gcType == BlinkGC::TakeSnapshot)
+ BlinkGCMemoryDumpProvider::instance()->clearProcessDumpForCurrentGC();
- // Disallow allocation during garbage collection (but not during the
- // finalization that happens when the visitorScope is torn down).
- NoAllocationScope noAllocationScope(this);
+ // Disallow allocation during garbage collection (but not during the
+ // finalization that happens when the visitorScope is torn down).
+ NoAllocationScope noAllocationScope(this);
- heap().commitCallbackStacks();
- heap().preGC();
+ heap().commitCallbackStacks();
+ heap().preGC();
- StackFrameDepthScope stackDepthScope(&heap().stackFrameDepth());
+ StackFrameDepthScope stackDepthScope(&heap().stackFrameDepth());
- size_t totalObjectSize = heap().heapStats().allocatedObjectSize() +
- heap().heapStats().markedObjectSize();
- if (gcType != BlinkGC::TakeSnapshot)
- heap().resetHeapCounters();
+ size_t totalObjectSize = heap().heapStats().allocatedObjectSize() +
+ heap().heapStats().markedObjectSize();
+ if (gcType != BlinkGC::TakeSnapshot)
+ heap().resetHeapCounters();
- {
- // 1. Trace persistent roots.
- heap().visitPersistentRoots(visitor.get());
+ {
+ // 1. Trace persistent roots.
+ heap().visitPersistentRoots(visitor.get());
- // 2. Trace objects reachable from the stack. We do this independent of
- // the
- // given stackState since other threads might have a different stack
- // state.
- heap().visitStackRoots(visitor.get());
+ // 2. Trace objects reachable from the stack. We do this independent of
+ // the
+ // given stackState since other threads might have a different stack
+ // state.
+ heap().visitStackRoots(visitor.get());
- // 3. Transitive closure to trace objects including ephemerons.
- heap().processMarkingStack(visitor.get());
+ // 3. Transitive closure to trace objects including ephemerons.
+ heap().processMarkingStack(visitor.get());
- heap().postMarkingProcessing(visitor.get());
- heap().globalWeakProcessing(visitor.get());
- }
+ heap().postMarkingProcessing(visitor.get());
+ heap().globalWeakProcessing(visitor.get());
+ }
- // Now we can delete all orphaned pages because there are no dangling
- // pointers to the orphaned pages. (If we have such dangling pointers,
- // we should have crashed during marking before getting here.)
- heap().getOrphanedPagePool()->decommitOrphanedPages();
+ // Now we can delete all orphaned pages because there are no dangling
+ // pointers to the orphaned pages. (If we have such dangling pointers,
+ // we should have crashed during marking before getting here.)
+ heap().getOrphanedPagePool()->decommitOrphanedPages();
- double markingTimeInMilliseconds = WTF::currentTimeMS() - startTime;
- heap().heapStats().setEstimatedMarkingTimePerByte(
- totalObjectSize ? (markingTimeInMilliseconds / 1000 / totalObjectSize)
- : 0);
+ double markingTimeInMilliseconds = WTF::currentTimeMS() - startTime;
+ heap().heapStats().setEstimatedMarkingTimePerByte(
+ totalObjectSize ? (markingTimeInMilliseconds / 1000 / totalObjectSize)
+ : 0);
#if PRINT_HEAP_STATS
- dataLogF(
- "ThreadHeap::collectGarbage (gcReason=%s, lazySweeping=%d, "
- "time=%.1lfms)\n",
- gcReasonString(reason), gcType == BlinkGC::GCWithoutSweep,
- markingTimeInMilliseconds);
+ dataLogF(
+ "ThreadHeap::collectGarbage (gcReason=%s, lazySweeping=%d, "
+ "time=%.1lfms)\n",
+ gcReasonString(reason), gcType == BlinkGC::GCWithoutSweep,
+ markingTimeInMilliseconds);
#endif
- DEFINE_THREAD_SAFE_STATIC_LOCAL(
- CustomCountHistogram, markingTimeHistogram,
- new CustomCountHistogram("BlinkGC.CollectGarbage", 0, 10 * 1000, 50));
- markingTimeHistogram.count(markingTimeInMilliseconds);
- DEFINE_THREAD_SAFE_STATIC_LOCAL(
- CustomCountHistogram, totalObjectSpaceHistogram,
- new CustomCountHistogram("BlinkGC.TotalObjectSpace", 0, 4 * 1024 * 1024,
- 50));
- totalObjectSpaceHistogram.count(ProcessHeap::totalAllocatedObjectSize() /
- 1024);
- DEFINE_THREAD_SAFE_STATIC_LOCAL(
- CustomCountHistogram, totalAllocatedSpaceHistogram,
- new CustomCountHistogram("BlinkGC.TotalAllocatedSpace", 0,
- 4 * 1024 * 1024, 50));
- totalAllocatedSpaceHistogram.count(ProcessHeap::totalAllocatedSpace() /
- 1024);
- DEFINE_THREAD_SAFE_STATIC_LOCAL(
- EnumerationHistogram, gcReasonHistogram,
- new EnumerationHistogram("BlinkGC.GCReason",
- BlinkGC::NumberOfGCReason));
- gcReasonHistogram.count(reason);
-
- heap().m_lastGCReason = reason;
-
- ThreadHeap::reportMemoryUsageHistogram();
- WTF::Partitions::reportMemoryUsageHistogram();
+ DEFINE_THREAD_SAFE_STATIC_LOCAL(
+ CustomCountHistogram, markingTimeHistogram,
+ new CustomCountHistogram("BlinkGC.CollectGarbage", 0, 10 * 1000, 50));
+ markingTimeHistogram.count(markingTimeInMilliseconds);
+ DEFINE_THREAD_SAFE_STATIC_LOCAL(
+ CustomCountHistogram, totalObjectSpaceHistogram,
+ new CustomCountHistogram("BlinkGC.TotalObjectSpace", 0, 4 * 1024 * 1024,
+ 50));
+ totalObjectSpaceHistogram.count(ProcessHeap::totalAllocatedObjectSize() /
+ 1024);
+ DEFINE_THREAD_SAFE_STATIC_LOCAL(
+ CustomCountHistogram, totalAllocatedSpaceHistogram,
+ new CustomCountHistogram("BlinkGC.TotalAllocatedSpace", 0,
+ 4 * 1024 * 1024, 50));
+ totalAllocatedSpaceHistogram.count(ProcessHeap::totalAllocatedSpace() /
+ 1024);
+ DEFINE_THREAD_SAFE_STATIC_LOCAL(
+ EnumerationHistogram, gcReasonHistogram,
+ new EnumerationHistogram("BlinkGC.GCReason",
+ BlinkGC::NumberOfGCReason));
+ gcReasonHistogram.count(reason);
+
+ heap().m_lastGCReason = reason;
+
+ ThreadHeap::reportMemoryUsageHistogram();
+ WTF::Partitions::reportMemoryUsageHistogram();
+ }
+ heap().postGC(gcType);
}
- heap().postGC(gcType);
+ heap().preSweep(gcType);
heap().decommitCallbackStacks();
}
@@ -1774,6 +1779,7 @@ void ThreadState::collectGarbageForTerminatingThread() {
}
postGC(BlinkGC::GCWithSweep);
+ preSweep(BlinkGC::GCWithSweep);
heap().decommitCallbackStacks();
}
« no previous file with comments | « third_party/WebKit/Source/platform/heap/ThreadState.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698