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

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

Issue 1507483002: Simplify prefinalizer processing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: final tidying Created 5 years 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
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 5dade81422fb90875c853471da1f73fa91d9e779..3f25749d8cdadd8a788234cfe1df540abd0ed44b 100644
--- a/third_party/WebKit/Source/platform/heap/ThreadState.cpp
+++ b/third_party/WebKit/Source/platform/heap/ThreadState.cpp
@@ -1338,25 +1338,34 @@ void ThreadState::invokePreFinalizers()
ASSERT(checkThread());
ASSERT(!sweepForbidden());
TRACE_EVENT0("blink_gc", "ThreadState::invokePreFinalizers");
+
double startTime = WTF::currentTimeMS();
+ if (!m_orderedPreFinalizers.isEmpty()) {
+ SweepForbiddenScope forbiddenScope(this);
+ if (isMainThread())
+ ScriptForbiddenScope::enter();
- if (isMainThread())
- ScriptForbiddenScope::enter();
+ // Call the prefinalizers in the opposite order to their registration.
+ //
+ // The prefinalizer callback wrapper returns |true| when its associated
+ // object is unreachable garbage and the prefinalizer callback has run.
+ // The registered prefinalizer entry must then be removed and deleted.
+ //
+ auto it = --m_orderedPreFinalizers.end();
+ bool done;
+ do {
+ auto entry = it;
+ done = it == m_orderedPreFinalizers.begin();
+ if (!done)
+ --it;
+ if ((entry->second)(entry->first))
+ m_orderedPreFinalizers.remove(entry);
+ } while (!done);
- SweepForbiddenScope forbiddenScope(this);
- Vector<PreFinalizer> deadPreFinalizers;
- // Call the pre-finalizers in the reverse order in which they
- // are registered.
- for (auto it = m_orderedPreFinalizers.rbegin(); it != m_orderedPreFinalizers.rend(); ++it) {
- if (!(it->second)(it->first))
- continue;
- deadPreFinalizers.append(*it);
+ if (isMainThread())
+ ScriptForbiddenScope::exit();
}
- // FIXME: removeAll is inefficient. It can shrink repeatedly.
- m_orderedPreFinalizers.removeAll(deadPreFinalizers);
-
if (isMainThread()) {
- ScriptForbiddenScope::exit();
double timeForInvokingPreFinalizers = WTF::currentTimeMS() - startTime;
Platform::current()->histogramCustomCounts("BlinkGC.TimeForInvokingPreFinalizers", timeForInvokingPreFinalizers, 1, 10 * 1000, 50);
}
« no previous file with comments | « third_party/WebKit/Source/platform/heap/ThreadState.h ('k') | third_party/WebKit/Source/platform/heap/TraceTraits.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698