| 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 ASSERT(header->checkHeader()); | 316 header->checkHeader(); |
| 317 // Use the payload size as recorded by the heap to determine how many | 317 // Use the payload size as recorded by the heap to determine how many |
| 318 // elements to finalize. | 318 // elements to finalize. |
| 319 size_t length = header->payloadSize() / sizeof(T); | 319 size_t length = header->payloadSize() / sizeof(T); |
| 320 T* buffer = reinterpret_cast<T*>(pointer); | 320 T* buffer = reinterpret_cast<T*>(pointer); |
| 321 #ifdef ANNOTATE_CONTIGUOUS_CONTAINER | 321 #ifdef ANNOTATE_CONTIGUOUS_CONTAINER |
| 322 // As commented above, HeapVectorBacking calls finalizers for unused slots | 322 // As commented above, HeapVectorBacking calls finalizers for unused slots |
| 323 // (which are already zeroed out). | 323 // (which are already zeroed out). |
| 324 ANNOTATE_CHANGE_SIZE(buffer, length, 0, length); | 324 ANNOTATE_CHANGE_SIZE(buffer, length, 0, length); |
| 325 #endif | 325 #endif |
| 326 if (std::is_polymorphic<T>::value) { | 326 if (std::is_polymorphic<T>::value) { |
| 327 char* pointer = reinterpret_cast<char*>(buffer); | 327 char* pointer = reinterpret_cast<char*>(buffer); |
| 328 for (unsigned i = 0; i < length; ++i) { | 328 for (unsigned i = 0; i < length; ++i) { |
| 329 char* element = pointer + i * sizeof(T); | 329 char* element = pointer + i * sizeof(T); |
| 330 if (blink::vTableInitialized(element)) | 330 if (blink::vTableInitialized(element)) |
| 331 reinterpret_cast<T*>(element)->~T(); | 331 reinterpret_cast<T*>(element)->~T(); |
| 332 } | 332 } |
| 333 } else { | 333 } else { |
| 334 for (unsigned i = 0; i < length; ++i) { | 334 for (unsigned i = 0; i < length; ++i) { |
| 335 buffer[i].~T(); | 335 buffer[i].~T(); |
| 336 } | 336 } |
| 337 } | 337 } |
| 338 } | 338 } |
| 339 | 339 |
| 340 template <typename Table> | 340 template <typename Table> |
| 341 void HeapHashTableBacking<Table>::finalize(void* pointer) { | 341 void HeapHashTableBacking<Table>::finalize(void* pointer) { |
| 342 using Value = typename Table::ValueType; | 342 using Value = typename Table::ValueType; |
| 343 ASSERT(!WTF::IsTriviallyDestructible<Value>::value); | 343 ASSERT(!WTF::IsTriviallyDestructible<Value>::value); |
| 344 HeapObjectHeader* header = HeapObjectHeader::fromPayload(pointer); | 344 HeapObjectHeader* header = HeapObjectHeader::fromPayload(pointer); |
| 345 ASSERT(header->checkHeader()); | 345 header->checkHeader(); |
| 346 // Use the payload size as recorded by the heap to determine how many | 346 // Use the payload size as recorded by the heap to determine how many |
| 347 // elements to finalize. | 347 // elements to finalize. |
| 348 size_t length = header->payloadSize() / sizeof(Value); | 348 size_t length = header->payloadSize() / sizeof(Value); |
| 349 Value* table = reinterpret_cast<Value*>(pointer); | 349 Value* table = reinterpret_cast<Value*>(pointer); |
| 350 for (unsigned i = 0; i < length; ++i) { | 350 for (unsigned i = 0; i < length; ++i) { |
| 351 if (!Table::isEmptyOrDeletedBucket(table[i])) | 351 if (!Table::isEmptyOrDeletedBucket(table[i])) |
| 352 table[i].~Value(); | 352 table[i].~Value(); |
| 353 } | 353 } |
| 354 } | 354 } |
| 355 | 355 |
| (...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 836 const blink::HeapHashCountedSet<Value, HashFunctions, Traits>& set, | 836 const blink::HeapHashCountedSet<Value, HashFunctions, Traits>& set, |
| 837 VectorType& vector) { | 837 VectorType& vector) { |
| 838 copyToVector(static_cast<const HashCountedSet<Value, HashFunctions, Traits, | 838 copyToVector(static_cast<const HashCountedSet<Value, HashFunctions, Traits, |
| 839 blink::HeapAllocator>&>(set), | 839 blink::HeapAllocator>&>(set), |
| 840 vector); | 840 vector); |
| 841 } | 841 } |
| 842 | 842 |
| 843 } // namespace WTF | 843 } // namespace WTF |
| 844 | 844 |
| 845 #endif | 845 #endif |
| OLD | NEW |