Chromium Code Reviews| Index: Source/platform/heap/Visitor.cpp |
| diff --git a/Source/platform/heap/Visitor.cpp b/Source/platform/heap/Visitor.cpp |
| index 7183b329e54e5a745bf63448032ab8ad8bafd27d..4f46be0c22f6cd680a3a9a11082d8822f90f049b 100644 |
| --- a/Source/platform/heap/Visitor.cpp |
| +++ b/Source/platform/heap/Visitor.cpp |
| @@ -43,32 +43,30 @@ int GCInfoTable::s_gcInfoIndex = 0; |
| size_t GCInfoTable::s_gcInfoTableSize = 0; |
| GCInfo const** s_gcInfoTable = nullptr; |
| -size_t GCInfoTable::allocateGCInfoSlot() |
| +bool GCInfoTable::allocateGCInfoSlot(size_t& gcInfoIndexSlot) |
|
haraken
2015/01/10 08:37:24
Nit: I'd slightly prefer a raw pointer for an outp
sof
2015/01/10 08:54:23
Done.
|
| { |
| - // 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); |
| + // 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 false; |
| + |
| + 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; |
| + gcInfoIndexSlot = gcInfoIndex; |
| + return true; |
| } |
| -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 +82,7 @@ void GCInfoTable::resize(size_t index) |
| void GCInfoTable::init() |
| { |
| RELEASE_ASSERT(!s_gcInfoTable); |
| - resize(0); |
| + resize(); |
| } |
| void GCInfoTable::shutdown() |