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

Unified Diff: Source/platform/heap/Visitor.cpp

Issue 834673008: Extend locking of GCInfo table to include slot allocation. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Adjust position of slot initialization Created 5 years, 11 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 | « Source/platform/heap/Visitor.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/platform/heap/Visitor.cpp
diff --git a/Source/platform/heap/Visitor.cpp b/Source/platform/heap/Visitor.cpp
index 7183b329e54e5a745bf63448032ab8ad8bafd27d..57c2edbd311d3702ca4b2e4da070bcebcc39db4d 100644
--- a/Source/platform/heap/Visitor.cpp
+++ b/Source/platform/heap/Visitor.cpp
@@ -43,32 +43,32 @@ int GCInfoTable::s_gcInfoIndex = 0;
size_t GCInfoTable::s_gcInfoTableSize = 0;
GCInfo const** s_gcInfoTable = nullptr;
-size_t GCInfoTable::allocateGCInfoSlot()
+void GCInfoTable::ensureGCInfoIndex(const GCInfo* gcInfo, size_t* gcInfoIndexSlot)
{
- // FIXME: if multiple threads attempt to allocate the initial object
- // for a given type, there'll be a write race on updating the 'static'
- // holding its index. Duplicate GCInfo slots might be written for the
- // object, which is benign, but verify that the index update race is
- // acceptable.
- int index = atomicIncrement(&s_gcInfoIndex);
+ ASSERT(gcInfo);
+ ASSERT(gcInfoIndexSlot);
+ // Keep a global GCInfoTable lock while allocating a new slot.
+ AtomicallyInitializedStatic(Mutex&, mutex = *new Mutex);
+ MutexLocker locker(mutex);
+
+ // If more than one thread ends up allocating a slot for
+ // the same GCInfo, have later threads reuse the slot
+ // allocated by the first.
+ if (*gcInfoIndexSlot)
+ return;
+
+ int index = ++s_gcInfoIndex;
size_t gcInfoIndex = static_cast<size_t>(index);
ASSERT(gcInfoIndex < GCInfoTable::maxIndex);
if (gcInfoIndex >= s_gcInfoTableSize)
- resize(gcInfoIndex);
+ resize();
- return gcInfoIndex;
+ s_gcInfoTable[gcInfoIndex] = gcInfo;
+ *gcInfoIndexSlot = gcInfoIndex;
}
-void GCInfoTable::resize(size_t index)
+void GCInfoTable::resize()
{
- AtomicallyInitializedStatic(Mutex&, mutex = *new Mutex);
- MutexLocker locker(mutex);
-
- // Keep a lock while expanding the shared table; check
- // if another thread have already resized.
- if (index < s_gcInfoTableSize)
- return;
-
// (Light) experimentation suggests that Blink doesn't need
// more than this while handling content on popular web properties.
const size_t initialSize = 512;
@@ -84,7 +84,7 @@ void GCInfoTable::resize(size_t index)
void GCInfoTable::init()
{
RELEASE_ASSERT(!s_gcInfoTable);
- resize(0);
+ resize();
}
void GCInfoTable::shutdown()
« no previous file with comments | « Source/platform/heap/Visitor.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698