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 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 public: | 243 public: |
244 static void finalize(void* pointer); | 244 static void finalize(void* pointer); |
245 void finalizeGarbageCollectedObject() { finalize(this); } | 245 void finalizeGarbageCollectedObject() { finalize(this); } |
246 }; | 246 }; |
247 | 247 |
248 template<typename T, typename Traits> | 248 template<typename T, typename Traits> |
249 void HeapVectorBacking<T, Traits>::finalize(void* pointer) | 249 void HeapVectorBacking<T, Traits>::finalize(void* pointer) |
250 { | 250 { |
251 static_assert(Traits::needsDestruction, "Only vector buffers with items requ
iring destruction should be finalized"); | 251 static_assert(Traits::needsDestruction, "Only vector buffers with items requ
iring destruction should be finalized"); |
252 // See the comment in HeapVectorBacking::trace. | 252 // See the comment in HeapVectorBacking::trace. |
253 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"); | 253 static_assert(Traits::canClearUnusedSlotsWithMemset || std::is_polymorphic<T
>::value, "HeapVectorBacking doesn't support objects that cannot be cleared as u
nused with memset or don't have a vtable"); |
254 | 254 |
255 ASSERT(!WTF::IsTriviallyDestructible<T>::value); | 255 ASSERT(!WTF::IsTriviallyDestructible<T>::value); |
256 HeapObjectHeader* header = HeapObjectHeader::fromPayload(pointer); | 256 HeapObjectHeader* header = HeapObjectHeader::fromPayload(pointer); |
257 ASSERT(header->checkHeader()); | 257 ASSERT(header->checkHeader()); |
258 // Use the payload size as recorded by the heap to determine how many | 258 // Use the payload size as recorded by the heap to determine how many |
259 // elements to finalize. | 259 // elements to finalize. |
260 size_t length = header->payloadSize() / sizeof(T); | 260 size_t length = header->payloadSize() / sizeof(T); |
261 T* buffer = reinterpret_cast<T*>(pointer); | 261 T* buffer = reinterpret_cast<T*>(pointer); |
262 #ifdef ANNOTATE_CONTIGUOUS_CONTAINER | 262 #ifdef ANNOTATE_CONTIGUOUS_CONTAINER |
263 // As commented above, HeapVectorBacking calls finalizers for unused slots | 263 // As commented above, HeapVectorBacking calls finalizers for unused slots |
264 // (which are already zeroed out). | 264 // (which are already zeroed out). |
265 ANNOTATE_CHANGE_SIZE(buffer, length, 0, length); | 265 ANNOTATE_CHANGE_SIZE(buffer, length, 0, length); |
266 #endif | 266 #endif |
267 if (WTF::IsPolymorphic<T>::value) { | 267 if (std::is_polymorphic<T>::value) { |
268 for (unsigned i = 0; i < length; ++i) { | 268 for (unsigned i = 0; i < length; ++i) { |
269 if (blink::vTableInitialized(&buffer[i])) | 269 if (blink::vTableInitialized(&buffer[i])) |
270 buffer[i].~T(); | 270 buffer[i].~T(); |
271 } | 271 } |
272 } else { | 272 } else { |
273 for (unsigned i = 0; i < length; ++i) { | 273 for (unsigned i = 0; i < length; ++i) { |
274 buffer[i].~T(); | 274 buffer[i].~T(); |
275 } | 275 } |
276 } | 276 } |
277 } | 277 } |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 template<size_t otherCapacity> | 387 template<size_t otherCapacity> |
388 HeapDeque(const HeapDeque<T, otherCapacity>& other) | 388 HeapDeque(const HeapDeque<T, otherCapacity>& other) |
389 : Deque<T, inlineCapacity, HeapAllocator>(other) | 389 : Deque<T, inlineCapacity, HeapAllocator>(other) |
390 { | 390 { |
391 } | 391 } |
392 }; | 392 }; |
393 | 393 |
394 } // namespace blink | 394 } // namespace blink |
395 | 395 |
396 #endif | 396 #endif |
OLD | NEW |