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 HeapAllocator_h | 5 #ifndef HeapAllocator_h |
6 #define HeapAllocator_h | 6 #define HeapAllocator_h |
7 | 7 |
8 #include "platform/heap/Heap.h" | 8 #include "platform/heap/Heap.h" |
9 #include "platform/heap/TraceTraits.h" | 9 #include "platform/heap/TraceTraits.h" |
10 #include "wtf/Assertions.h" | 10 #include "wtf/Assertions.h" |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 | 276 |
277 template<typename T, typename Traits> | 277 template<typename T, typename Traits> |
278 void HeapVectorBacking<T, Traits>::finalize(void* pointer) | 278 void HeapVectorBacking<T, Traits>::finalize(void* pointer) |
279 { | 279 { |
280 static_assert(Traits::needsDestruction, "Only vector buffers with items requ
iring destruction should be finalized"); | 280 static_assert(Traits::needsDestruction, "Only vector buffers with items requ
iring destruction should be finalized"); |
281 // See the comment in HeapVectorBacking::trace. | 281 // See the comment in HeapVectorBacking::trace. |
282 static_assert(Traits::canClearUnusedSlotsWithMemset || WTF::IsPolymorphic<T>
::value, "HeapVectorBacking doesn't support objects that cannot be cleared as un
used with memset or don't have a vtable"); | 282 static_assert(Traits::canClearUnusedSlotsWithMemset || WTF::IsPolymorphic<T>
::value, "HeapVectorBacking doesn't support objects that cannot be cleared as un
used with memset or don't have a vtable"); |
283 | 283 |
284 ASSERT(!WTF::IsTriviallyDestructible<T>::value); | 284 ASSERT(!WTF::IsTriviallyDestructible<T>::value); |
285 HeapObjectHeader* header = HeapObjectHeader::fromPayload(pointer); | 285 HeapObjectHeader* header = HeapObjectHeader::fromPayload(pointer); |
286 header->checkHeader(); | 286 ASSERT(header->checkHeader()); |
287 // Use the payload size as recorded by the heap to determine how many | 287 // Use the payload size as recorded by the heap to determine how many |
288 // elements to finalize. | 288 // elements to finalize. |
289 size_t length = header->payloadSize() / sizeof(T); | 289 size_t length = header->payloadSize() / sizeof(T); |
290 T* buffer = reinterpret_cast<T*>(pointer); | 290 T* buffer = reinterpret_cast<T*>(pointer); |
291 #ifdef ANNOTATE_CONTIGUOUS_CONTAINER | 291 #ifdef ANNOTATE_CONTIGUOUS_CONTAINER |
292 // As commented above, HeapVectorBacking calls finalizers for unused slots | 292 // As commented above, HeapVectorBacking calls finalizers for unused slots |
293 // (which are already zeroed out). | 293 // (which are already zeroed out). |
294 ANNOTATE_CHANGE_SIZE(buffer, length, 0, length); | 294 ANNOTATE_CHANGE_SIZE(buffer, length, 0, length); |
295 #endif | 295 #endif |
296 if (WTF::IsPolymorphic<T>::value) { | 296 if (WTF::IsPolymorphic<T>::value) { |
(...skipping 13 matching lines...) Expand all Loading... |
310 static void finalize(void* pointer); | 310 static void finalize(void* pointer); |
311 void finalizeGarbageCollectedObject() { finalize(this); } | 311 void finalizeGarbageCollectedObject() { finalize(this); } |
312 }; | 312 }; |
313 | 313 |
314 template<typename Table> | 314 template<typename Table> |
315 void HeapHashTableBacking<Table>::finalize(void* pointer) | 315 void HeapHashTableBacking<Table>::finalize(void* pointer) |
316 { | 316 { |
317 using Value = typename Table::ValueType; | 317 using Value = typename Table::ValueType; |
318 ASSERT(!WTF::IsTriviallyDestructible<Value>::value); | 318 ASSERT(!WTF::IsTriviallyDestructible<Value>::value); |
319 HeapObjectHeader* header = HeapObjectHeader::fromPayload(pointer); | 319 HeapObjectHeader* header = HeapObjectHeader::fromPayload(pointer); |
320 header->checkHeader(); | 320 ASSERT(header->checkHeader()); |
321 // Use the payload size as recorded by the heap to determine how many | 321 // Use the payload size as recorded by the heap to determine how many |
322 // elements to finalize. | 322 // elements to finalize. |
323 size_t length = header->payloadSize() / sizeof(Value); | 323 size_t length = header->payloadSize() / sizeof(Value); |
324 Value* table = reinterpret_cast<Value*>(pointer); | 324 Value* table = reinterpret_cast<Value*>(pointer); |
325 for (unsigned i = 0; i < length; ++i) { | 325 for (unsigned i = 0; i < length; ++i) { |
326 if (!Table::isEmptyOrDeletedBucket(table[i])) | 326 if (!Table::isEmptyOrDeletedBucket(table[i])) |
327 table[i].~Value(); | 327 table[i].~Value(); |
328 } | 328 } |
329 } | 329 } |
330 | 330 |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
457 template<typename T, size_t i, typename U> | 457 template<typename T, size_t i, typename U> |
458 inline void swap(HeapListHashSet<T, i, U>& a, HeapListHashSet<T, i, U>& b) { a.s
wap(b); } | 458 inline void swap(HeapListHashSet<T, i, U>& a, HeapListHashSet<T, i, U>& b) { a.s
wap(b); } |
459 template<typename T, typename U, typename V> | 459 template<typename T, typename U, typename V> |
460 inline void swap(HeapLinkedHashSet<T, U, V>& a, HeapLinkedHashSet<T, U, V>& b) {
a.swap(b); } | 460 inline void swap(HeapLinkedHashSet<T, U, V>& a, HeapLinkedHashSet<T, U, V>& b) {
a.swap(b); } |
461 template<typename T, typename U, typename V> | 461 template<typename T, typename U, typename V> |
462 inline void swap(HeapHashCountedSet<T, U, V>& a, HeapHashCountedSet<T, U, V>& b)
{ a.swap(b); } | 462 inline void swap(HeapHashCountedSet<T, U, V>& a, HeapHashCountedSet<T, U, V>& b)
{ a.swap(b); } |
463 | 463 |
464 } // namespace blink | 464 } // namespace blink |
465 | 465 |
466 #endif | 466 #endif |
OLD | NEW |