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 #ifndef GCInfo_h | 5 #ifndef GCInfo_h |
6 #define GCInfo_h | 6 #define GCInfo_h |
7 | 7 |
8 #include "platform/heap/Visitor.h" | 8 #include "platform/heap/Visitor.h" |
9 #include "wtf/Allocator.h" | 9 #include "wtf/Allocator.h" |
10 #include "wtf/Assertions.h" | 10 #include "wtf/Assertions.h" |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
149 TraceCallback m_trace; | 149 TraceCallback m_trace; |
150 FinalizationCallback m_finalize; | 150 FinalizationCallback m_finalize; |
151 bool m_nonTrivialFinalizer; | 151 bool m_nonTrivialFinalizer; |
152 bool m_hasVTable; | 152 bool m_hasVTable; |
153 }; | 153 }; |
154 | 154 |
155 // s_gcInfoTable holds the per-class GCInfo descriptors; each heap | 155 // s_gcInfoTable holds the per-class GCInfo descriptors; each heap |
156 // object header keeps its index into this table. | 156 // object header keeps its index into this table. |
157 extern PLATFORM_EXPORT GCInfo const** s_gcInfoTable; | 157 extern PLATFORM_EXPORT GCInfo const** s_gcInfoTable; |
158 | 158 |
159 #if ENABLE(ASSERT) | 159 // The (max + 1) GCInfo index supported. |
160 // We assume that 14 bits is enough to represent all possible types: during | |
161 // telemetry runs, we see about 1000 different types, looking at the output | |
162 // of the oilpan gc clang plugin, there appear to be at most about 6000 | |
163 // types, so 14 bits should be more than twice as many bits as we will ever | |
164 // encounter. | |
165 static const size_t gcInfoMaxIndex = 1 << 14; | |
haraken
2017/01/06 04:18:49
I hit a link error if I put this in GCInfo. I coul
sof
2017/01/08 07:10:46
Do you remember what the link error was?
| |
166 | |
167 #if DCHECK_IS_ON() | |
160 PLATFORM_EXPORT void assertObjectHasGCInfo(const void*, size_t gcInfoIndex); | 168 PLATFORM_EXPORT void assertObjectHasGCInfo(const void*, size_t gcInfoIndex); |
161 #endif | 169 #endif |
162 | 170 |
163 class GCInfoTable { | 171 class GCInfoTable { |
164 STATIC_ONLY(GCInfoTable); | 172 STATIC_ONLY(GCInfoTable); |
165 | 173 |
166 public: | 174 public: |
167 PLATFORM_EXPORT static void ensureGCInfoIndex(const GCInfo*, size_t*); | 175 PLATFORM_EXPORT static void ensureGCInfoIndex(const GCInfo*, size_t*); |
168 | 176 |
169 static void init(); | 177 static void init(); |
170 static void shutdown(); | 178 static void shutdown(); |
171 | 179 |
172 static size_t gcInfoIndex() { return s_gcInfoIndex; } | 180 static size_t gcInfoIndex() { return s_gcInfoIndex; } |
173 | 181 |
174 // The (max + 1) GCInfo index supported. | |
175 // We assume that 14 bits is enough to represent all possible types: during | |
176 // telemetry runs, we see about 1000 different types, looking at the output | |
177 // of the oilpan gc clang plugin, there appear to be at most about 6000 | |
178 // types, so 14 bits should be more than twice as many bits as we will ever | |
179 // encounter. | |
180 static const size_t maxIndex = 1 << 14; | |
181 | |
182 private: | 182 private: |
183 static void resize(); | 183 static void resize(); |
184 | 184 |
185 static int s_gcInfoIndex; | 185 static int s_gcInfoIndex; |
186 static size_t s_gcInfoTableSize; | 186 static size_t s_gcInfoTableSize; |
187 }; | 187 }; |
188 | 188 |
189 // GCInfoAtBaseType should be used when returning a unique 14 bit integer | 189 // GCInfoAtBaseType should be used when returning a unique 14 bit integer |
190 // for a given gcInfo. | 190 // for a given gcInfo. |
191 template <typename T> | 191 template <typename T> |
192 struct GCInfoAtBaseType { | 192 struct GCInfoAtBaseType { |
193 STATIC_ONLY(GCInfoAtBaseType); | 193 STATIC_ONLY(GCInfoAtBaseType); |
194 static size_t index() { | 194 static size_t index() { |
195 static_assert(sizeof(T), "T must be fully defined"); | 195 static_assert(sizeof(T), "T must be fully defined"); |
196 static const GCInfo gcInfo = { | 196 static const GCInfo gcInfo = { |
197 TraceTrait<T>::trace, FinalizerTrait<T>::finalize, | 197 TraceTrait<T>::trace, FinalizerTrait<T>::finalize, |
198 FinalizerTrait<T>::nonTrivialFinalizer, std::is_polymorphic<T>::value, | 198 FinalizerTrait<T>::nonTrivialFinalizer, std::is_polymorphic<T>::value, |
199 }; | 199 }; |
200 | 200 |
201 static size_t gcInfoIndex = 0; | 201 static size_t gcInfoIndex = 0; |
202 ASSERT(s_gcInfoTable); | 202 DCHECK(s_gcInfoTable); |
203 if (!acquireLoad(&gcInfoIndex)) | 203 if (!acquireLoad(&gcInfoIndex)) |
204 GCInfoTable::ensureGCInfoIndex(&gcInfo, &gcInfoIndex); | 204 GCInfoTable::ensureGCInfoIndex(&gcInfo, &gcInfoIndex); |
205 ASSERT(gcInfoIndex >= 1); | 205 DCHECK_GE(gcInfoIndex, 1UL); |
206 ASSERT(gcInfoIndex < GCInfoTable::maxIndex); | 206 DCHECK_LT(gcInfoIndex, gcInfoMaxIndex); |
207 return gcInfoIndex; | 207 return gcInfoIndex; |
208 } | 208 } |
209 }; | 209 }; |
210 | 210 |
211 template <typename T, | 211 template <typename T, |
212 bool = WTF::IsSubclassOfTemplate<typename std::remove_const<T>::type, | 212 bool = WTF::IsSubclassOfTemplate<typename std::remove_const<T>::type, |
213 GarbageCollected>::value> | 213 GarbageCollected>::value> |
214 struct GetGarbageCollectedType; | 214 struct GetGarbageCollectedType; |
215 | 215 |
216 template <typename T> | 216 template <typename T> |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
273 template <typename T, size_t inlineCapacity> | 273 template <typename T, size_t inlineCapacity> |
274 struct GCInfoTrait<HeapDeque<T, inlineCapacity>> | 274 struct GCInfoTrait<HeapDeque<T, inlineCapacity>> |
275 : public GCInfoTrait<Deque<T, inlineCapacity, HeapAllocator>> {}; | 275 : public GCInfoTrait<Deque<T, inlineCapacity, HeapAllocator>> {}; |
276 template <typename T, typename U, typename V> | 276 template <typename T, typename U, typename V> |
277 struct GCInfoTrait<HeapHashCountedSet<T, U, V>> | 277 struct GCInfoTrait<HeapHashCountedSet<T, U, V>> |
278 : public GCInfoTrait<HashCountedSet<T, U, V, HeapAllocator>> {}; | 278 : public GCInfoTrait<HashCountedSet<T, U, V, HeapAllocator>> {}; |
279 | 279 |
280 } // namespace blink | 280 } // namespace blink |
281 | 281 |
282 #endif | 282 #endif |
OLD | NEW |