| 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/Persistent.h" | 9 #include "platform/heap/Persistent.h" |
| 10 #include "platform/heap/TraceTraits.h" | 10 #include "platform/heap/TraceTraits.h" |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 "Only vector buffers with items requiring destruction should " | 306 "Only vector buffers with items requiring destruction should " |
| 307 "be finalized"); | 307 "be finalized"); |
| 308 // See the comment in HeapVectorBacking::trace. | 308 // See the comment in HeapVectorBacking::trace. |
| 309 static_assert( | 309 static_assert( |
| 310 Traits::canClearUnusedSlotsWithMemset || std::is_polymorphic<T>::value, | 310 Traits::canClearUnusedSlotsWithMemset || std::is_polymorphic<T>::value, |
| 311 "HeapVectorBacking doesn't support objects that cannot be cleared as " | 311 "HeapVectorBacking doesn't support objects that cannot be cleared as " |
| 312 "unused with memset or don't have a vtable"); | 312 "unused with memset or don't have a vtable"); |
| 313 | 313 |
| 314 ASSERT(!WTF::IsTriviallyDestructible<T>::value); | 314 ASSERT(!WTF::IsTriviallyDestructible<T>::value); |
| 315 HeapObjectHeader* header = HeapObjectHeader::fromPayload(pointer); | 315 HeapObjectHeader* header = HeapObjectHeader::fromPayload(pointer); |
| 316 header->checkHeader(); | |
| 317 // Use the payload size as recorded by the heap to determine how many | 316 // Use the payload size as recorded by the heap to determine how many |
| 318 // elements to finalize. | 317 // elements to finalize. |
| 319 size_t length = header->payloadSize() / sizeof(T); | 318 size_t length = header->payloadSize() / sizeof(T); |
| 320 T* buffer = reinterpret_cast<T*>(pointer); | 319 T* buffer = reinterpret_cast<T*>(pointer); |
| 321 #ifdef ANNOTATE_CONTIGUOUS_CONTAINER | 320 #ifdef ANNOTATE_CONTIGUOUS_CONTAINER |
| 322 // As commented above, HeapVectorBacking calls finalizers for unused slots | 321 // As commented above, HeapVectorBacking calls finalizers for unused slots |
| 323 // (which are already zeroed out). | 322 // (which are already zeroed out). |
| 324 ANNOTATE_CHANGE_SIZE(buffer, length, 0, length); | 323 ANNOTATE_CHANGE_SIZE(buffer, length, 0, length); |
| 325 #endif | 324 #endif |
| 326 if (std::is_polymorphic<T>::value) { | 325 if (std::is_polymorphic<T>::value) { |
| 327 char* pointer = reinterpret_cast<char*>(buffer); | 326 char* pointer = reinterpret_cast<char*>(buffer); |
| 328 for (unsigned i = 0; i < length; ++i) { | 327 for (unsigned i = 0; i < length; ++i) { |
| 329 char* element = pointer + i * sizeof(T); | 328 char* element = pointer + i * sizeof(T); |
| 330 if (blink::vTableInitialized(element)) | 329 if (blink::vTableInitialized(element)) |
| 331 reinterpret_cast<T*>(element)->~T(); | 330 reinterpret_cast<T*>(element)->~T(); |
| 332 } | 331 } |
| 333 } else { | 332 } else { |
| 334 for (unsigned i = 0; i < length; ++i) { | 333 for (unsigned i = 0; i < length; ++i) { |
| 335 buffer[i].~T(); | 334 buffer[i].~T(); |
| 336 } | 335 } |
| 337 } | 336 } |
| 338 } | 337 } |
| 339 | 338 |
| 340 template <typename Table> | 339 template <typename Table> |
| 341 void HeapHashTableBacking<Table>::finalize(void* pointer) { | 340 void HeapHashTableBacking<Table>::finalize(void* pointer) { |
| 342 using Value = typename Table::ValueType; | 341 using Value = typename Table::ValueType; |
| 343 ASSERT(!WTF::IsTriviallyDestructible<Value>::value); | 342 ASSERT(!WTF::IsTriviallyDestructible<Value>::value); |
| 344 HeapObjectHeader* header = HeapObjectHeader::fromPayload(pointer); | 343 HeapObjectHeader* header = HeapObjectHeader::fromPayload(pointer); |
| 345 header->checkHeader(); | |
| 346 // Use the payload size as recorded by the heap to determine how many | 344 // Use the payload size as recorded by the heap to determine how many |
| 347 // elements to finalize. | 345 // elements to finalize. |
| 348 size_t length = header->payloadSize() / sizeof(Value); | 346 size_t length = header->payloadSize() / sizeof(Value); |
| 349 Value* table = reinterpret_cast<Value*>(pointer); | 347 Value* table = reinterpret_cast<Value*>(pointer); |
| 350 for (unsigned i = 0; i < length; ++i) { | 348 for (unsigned i = 0; i < length; ++i) { |
| 351 if (!Table::isEmptyOrDeletedBucket(table[i])) | 349 if (!Table::isEmptyOrDeletedBucket(table[i])) |
| 352 table[i].~Value(); | 350 table[i].~Value(); |
| 353 } | 351 } |
| 354 } | 352 } |
| 355 | 353 |
| (...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 836 const blink::HeapHashCountedSet<Value, HashFunctions, Traits>& set, | 834 const blink::HeapHashCountedSet<Value, HashFunctions, Traits>& set, |
| 837 VectorType& vector) { | 835 VectorType& vector) { |
| 838 copyToVector(static_cast<const HashCountedSet<Value, HashFunctions, Traits, | 836 copyToVector(static_cast<const HashCountedSet<Value, HashFunctions, Traits, |
| 839 blink::HeapAllocator>&>(set), | 837 blink::HeapAllocator>&>(set), |
| 840 vector); | 838 vector); |
| 841 } | 839 } |
| 842 | 840 |
| 843 } // namespace WTF | 841 } // namespace WTF |
| 844 | 842 |
| 845 #endif | 843 #endif |
| OLD | NEW |