OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "platform/heap/GCInfo.h" | 5 #include "platform/heap/GCInfo.h" |
6 | 6 |
7 #include "platform/heap/Handle.h" | 7 #include "platform/heap/Handle.h" |
8 #include "platform/heap/Heap.h" | 8 #include "platform/heap/Heap.h" |
9 | 9 |
10 namespace blink { | 10 namespace blink { |
11 | 11 |
12 // GCInfo indices start from 1 for heap objects, with 0 being treated | 12 // GCInfo indices start from 1 for heap objects, with 0 being treated |
13 // specially as the index for freelist entries and large heap objects. | 13 // specially as the index for freelist entries and large heap objects. |
14 int GCInfoTable::s_gcInfoIndex = 0; | 14 int GCInfoTable::s_gcInfoIndex = 0; |
15 | 15 |
16 size_t GCInfoTable::s_gcInfoTableSize = 0; | 16 size_t GCInfoTable::s_gcInfoTableSize = 0; |
17 GCInfo const** s_gcInfoTable = nullptr; | 17 GCInfo const** s_gcInfoTable = nullptr; |
18 | 18 |
19 void GCInfoTable::ensureGCInfoIndex(const GCInfo* gcInfo, | 19 void GCInfoTable::ensureGCInfoIndex(const GCInfo* gcInfo, |
20 size_t* gcInfoIndexSlot) { | 20 size_t* gcInfoIndexSlot) { |
21 ASSERT(gcInfo); | 21 DCHECK(gcInfo); |
22 ASSERT(gcInfoIndexSlot); | 22 DCHECK(gcInfoIndexSlot); |
23 // Keep a global GCInfoTable lock while allocating a new slot. | 23 // Keep a global GCInfoTable lock while allocating a new slot. |
24 DEFINE_THREAD_SAFE_STATIC_LOCAL(Mutex, mutex, new Mutex); | 24 DEFINE_THREAD_SAFE_STATIC_LOCAL(Mutex, mutex, new Mutex); |
25 MutexLocker locker(mutex); | 25 MutexLocker locker(mutex); |
26 | 26 |
27 // If more than one thread ends up allocating a slot for | 27 // If more than one thread ends up allocating a slot for |
28 // the same GCInfo, have later threads reuse the slot | 28 // the same GCInfo, have later threads reuse the slot |
29 // allocated by the first. | 29 // allocated by the first. |
30 if (*gcInfoIndexSlot) | 30 if (*gcInfoIndexSlot) |
31 return; | 31 return; |
32 | 32 |
33 int index = ++s_gcInfoIndex; | 33 int index = ++s_gcInfoIndex; |
34 size_t gcInfoIndex = static_cast<size_t>(index); | 34 size_t gcInfoIndex = static_cast<size_t>(index); |
35 RELEASE_ASSERT(gcInfoIndex < GCInfoTable::maxIndex); | 35 CHECK(gcInfoIndex < gcInfoMaxIndex); |
36 if (gcInfoIndex >= s_gcInfoTableSize) | 36 if (gcInfoIndex >= s_gcInfoTableSize) |
37 resize(); | 37 resize(); |
38 | 38 |
39 s_gcInfoTable[gcInfoIndex] = gcInfo; | 39 s_gcInfoTable[gcInfoIndex] = gcInfo; |
40 releaseStore(reinterpret_cast<int*>(gcInfoIndexSlot), index); | 40 releaseStore(reinterpret_cast<int*>(gcInfoIndexSlot), index); |
41 } | 41 } |
42 | 42 |
43 void GCInfoTable::resize() { | 43 void GCInfoTable::resize() { |
44 static const int gcInfoZapValue = 0x33; | 44 static const int gcInfoZapValue = 0x33; |
45 // (Light) experimentation suggests that Blink doesn't need | 45 // (Light) experimentation suggests that Blink doesn't need |
46 // more than this while handling content on popular web properties. | 46 // more than this while handling content on popular web properties. |
47 const size_t initialSize = 512; | 47 const size_t initialSize = 512; |
48 | 48 |
49 size_t newSize = s_gcInfoTableSize ? 2 * s_gcInfoTableSize : initialSize; | 49 size_t newSize = s_gcInfoTableSize ? 2 * s_gcInfoTableSize : initialSize; |
50 ASSERT(newSize < GCInfoTable::maxIndex); | 50 DCHECK_LT(newSize, gcInfoMaxIndex); |
51 s_gcInfoTable = reinterpret_cast<GCInfo const**>(WTF::Partitions::fastRealloc( | 51 s_gcInfoTable = reinterpret_cast<GCInfo const**>(WTF::Partitions::fastRealloc( |
52 s_gcInfoTable, newSize * sizeof(GCInfo), "GCInfo")); | 52 s_gcInfoTable, newSize * sizeof(GCInfo), "GCInfo")); |
53 ASSERT(s_gcInfoTable); | 53 DCHECK(s_gcInfoTable); |
54 memset(reinterpret_cast<uint8_t*>(s_gcInfoTable) + | 54 memset(reinterpret_cast<uint8_t*>(s_gcInfoTable) + |
55 s_gcInfoTableSize * sizeof(GCInfo), | 55 s_gcInfoTableSize * sizeof(GCInfo), |
56 gcInfoZapValue, (newSize - s_gcInfoTableSize) * sizeof(GCInfo)); | 56 gcInfoZapValue, (newSize - s_gcInfoTableSize) * sizeof(GCInfo)); |
57 s_gcInfoTableSize = newSize; | 57 s_gcInfoTableSize = newSize; |
58 } | 58 } |
59 | 59 |
60 void GCInfoTable::init() { | 60 void GCInfoTable::init() { |
61 RELEASE_ASSERT(!s_gcInfoTable); | 61 CHECK(!s_gcInfoTable); |
62 resize(); | 62 resize(); |
63 } | 63 } |
64 | 64 |
65 void GCInfoTable::shutdown() { | 65 void GCInfoTable::shutdown() { |
66 WTF::Partitions::fastFree(s_gcInfoTable); | 66 WTF::Partitions::fastFree(s_gcInfoTable); |
67 s_gcInfoTable = nullptr; | 67 s_gcInfoTable = nullptr; |
68 } | 68 } |
69 | 69 |
70 #if ENABLE(ASSERT) | 70 #if DCHECK_IS_ON() |
71 void assertObjectHasGCInfo(const void* payload, size_t gcInfoIndex) { | 71 void assertObjectHasGCInfo(const void* payload, size_t gcInfoIndex) { |
72 ASSERT(HeapObjectHeader::fromPayload(payload)->checkHeader()); | 72 DCHECK(HeapObjectHeader::fromPayload(payload)->checkHeader()); |
73 #if !defined(COMPONENT_BUILD) | 73 #if !defined(COMPONENT_BUILD) |
74 // On component builds we cannot compare the gcInfos as they are statically | 74 // On component builds we cannot compare the gcInfos as they are statically |
75 // defined in each of the components and hence will not match. | 75 // defined in each of the components and hence will not match. |
76 BasePage* page = pageFromObject(payload); | 76 BasePage* page = pageFromObject(payload); |
77 ASSERT(!page->orphaned()); | 77 DCHECK(!page->orphaned()); |
78 ASSERT(HeapObjectHeader::fromPayload(payload)->gcInfoIndex() == gcInfoIndex); | 78 DCHECK(HeapObjectHeader::fromPayload(payload)->gcInfoIndex() == gcInfoIndex); |
79 #endif | 79 #endif |
80 } | 80 } |
81 #endif | 81 #endif |
82 | 82 |
83 } // namespace blink | 83 } // namespace blink |
OLD | NEW |