Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: third_party/WebKit/Source/platform/heap/HeapAllocator.h

Issue 2816033003: Replace ASSERT with DHCECK_op in platform/heap (Closed)
Patch Set: Replace ASSERT with CHECK_op in platform/heap Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 template <typename T> 59 template <typename T>
60 static size_t QuantizedSize(size_t count) { 60 static size_t QuantizedSize(size_t count) {
61 CHECK(count <= MaxElementCountInBackingStore<T>()); 61 CHECK(count <= MaxElementCountInBackingStore<T>());
62 return ThreadHeap::AllocationSizeFromSize(count * sizeof(T)) - 62 return ThreadHeap::AllocationSizeFromSize(count * sizeof(T)) -
63 sizeof(HeapObjectHeader); 63 sizeof(HeapObjectHeader);
64 } 64 }
65 template <typename T> 65 template <typename T>
66 static T* AllocateVectorBacking(size_t size) { 66 static T* AllocateVectorBacking(size_t size) {
67 ThreadState* state = 67 ThreadState* state =
68 ThreadStateFor<ThreadingTrait<T>::kAffinity>::GetState(); 68 ThreadStateFor<ThreadingTrait<T>::kAffinity>::GetState();
69 ASSERT(state->IsAllocationAllowed()); 69 DCHECK(state->IsAllocationAllowed());
70 size_t gc_info_index = GCInfoTrait<HeapVectorBacking<T>>::Index(); 70 size_t gc_info_index = GCInfoTrait<HeapVectorBacking<T>>::Index();
71 NormalPageArena* arena = 71 NormalPageArena* arena =
72 static_cast<NormalPageArena*>(state->VectorBackingArena(gc_info_index)); 72 static_cast<NormalPageArena*>(state->VectorBackingArena(gc_info_index));
73 return reinterpret_cast<T*>(arena->AllocateObject( 73 return reinterpret_cast<T*>(arena->AllocateObject(
74 ThreadHeap::AllocationSizeFromSize(size), gc_info_index)); 74 ThreadHeap::AllocationSizeFromSize(size), gc_info_index));
75 } 75 }
76 template <typename T> 76 template <typename T>
77 static T* AllocateExpandedVectorBacking(size_t size) { 77 static T* AllocateExpandedVectorBacking(size_t size) {
78 ThreadState* state = 78 ThreadState* state =
79 ThreadStateFor<ThreadingTrait<T>::kAffinity>::GetState(); 79 ThreadStateFor<ThreadingTrait<T>::kAffinity>::GetState();
80 ASSERT(state->IsAllocationAllowed()); 80 DCHECK(state->IsAllocationAllowed());
81 size_t gc_info_index = GCInfoTrait<HeapVectorBacking<T>>::Index(); 81 size_t gc_info_index = GCInfoTrait<HeapVectorBacking<T>>::Index();
82 NormalPageArena* arena = static_cast<NormalPageArena*>( 82 NormalPageArena* arena = static_cast<NormalPageArena*>(
83 state->ExpandedVectorBackingArena(gc_info_index)); 83 state->ExpandedVectorBackingArena(gc_info_index));
84 return reinterpret_cast<T*>(arena->AllocateObject( 84 return reinterpret_cast<T*>(arena->AllocateObject(
85 ThreadHeap::AllocationSizeFromSize(size), gc_info_index)); 85 ThreadHeap::AllocationSizeFromSize(size), gc_info_index));
86 } 86 }
87 static void FreeVectorBacking(void*); 87 static void FreeVectorBacking(void*);
88 static bool ExpandVectorBacking(void*, size_t); 88 static bool ExpandVectorBacking(void*, size_t);
89 static bool ShrinkVectorBacking(void* address, 89 static bool ShrinkVectorBacking(void* address,
90 size_t quantized_current_size, 90 size_t quantized_current_size,
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 void HeapVectorBacking<T, Traits>::Finalize(void* pointer) { 316 void HeapVectorBacking<T, Traits>::Finalize(void* pointer) {
317 static_assert(Traits::kNeedsDestruction, 317 static_assert(Traits::kNeedsDestruction,
318 "Only vector buffers with items requiring destruction should " 318 "Only vector buffers with items requiring destruction should "
319 "be finalized"); 319 "be finalized");
320 // See the comment in HeapVectorBacking::trace. 320 // See the comment in HeapVectorBacking::trace.
321 static_assert( 321 static_assert(
322 Traits::kCanClearUnusedSlotsWithMemset || std::is_polymorphic<T>::value, 322 Traits::kCanClearUnusedSlotsWithMemset || std::is_polymorphic<T>::value,
323 "HeapVectorBacking doesn't support objects that cannot be cleared as " 323 "HeapVectorBacking doesn't support objects that cannot be cleared as "
324 "unused with memset or don't have a vtable"); 324 "unused with memset or don't have a vtable");
325 325
326 ASSERT(!WTF::IsTriviallyDestructible<T>::value); 326 DCHECK(!WTF::IsTriviallyDestructible<T>::value);
327 HeapObjectHeader* header = HeapObjectHeader::FromPayload(pointer); 327 HeapObjectHeader* header = HeapObjectHeader::FromPayload(pointer);
328 // Use the payload size as recorded by the heap to determine how many 328 // Use the payload size as recorded by the heap to determine how many
329 // elements to finalize. 329 // elements to finalize.
330 size_t length = header->PayloadSize() / sizeof(T); 330 size_t length = header->PayloadSize() / sizeof(T);
331 T* buffer = reinterpret_cast<T*>(pointer); 331 T* buffer = reinterpret_cast<T*>(pointer);
332 #ifdef ANNOTATE_CONTIGUOUS_CONTAINER 332 #ifdef ANNOTATE_CONTIGUOUS_CONTAINER
333 // As commented above, HeapVectorBacking calls finalizers for unused slots 333 // As commented above, HeapVectorBacking calls finalizers for unused slots
334 // (which are already zeroed out). 334 // (which are already zeroed out).
335 ANNOTATE_CHANGE_SIZE(buffer, length, 0, length); 335 ANNOTATE_CHANGE_SIZE(buffer, length, 0, length);
336 #endif 336 #endif
337 if (std::is_polymorphic<T>::value) { 337 if (std::is_polymorphic<T>::value) {
338 char* pointer = reinterpret_cast<char*>(buffer); 338 char* pointer = reinterpret_cast<char*>(buffer);
339 for (unsigned i = 0; i < length; ++i) { 339 for (unsigned i = 0; i < length; ++i) {
340 char* element = pointer + i * sizeof(T); 340 char* element = pointer + i * sizeof(T);
341 if (blink::VTableInitialized(element)) 341 if (blink::VTableInitialized(element))
342 reinterpret_cast<T*>(element)->~T(); 342 reinterpret_cast<T*>(element)->~T();
343 } 343 }
344 } else { 344 } else {
345 for (unsigned i = 0; i < length; ++i) { 345 for (unsigned i = 0; i < length; ++i) {
346 buffer[i].~T(); 346 buffer[i].~T();
347 } 347 }
348 } 348 }
349 } 349 }
350 350
351 template <typename Table> 351 template <typename Table>
352 void HeapHashTableBacking<Table>::Finalize(void* pointer) { 352 void HeapHashTableBacking<Table>::Finalize(void* pointer) {
353 using Value = typename Table::ValueType; 353 using Value = typename Table::ValueType;
354 ASSERT(!WTF::IsTriviallyDestructible<Value>::value); 354 DCHECK(!WTF::IsTriviallyDestructible<Value>::value);
355 HeapObjectHeader* header = HeapObjectHeader::FromPayload(pointer); 355 HeapObjectHeader* header = HeapObjectHeader::FromPayload(pointer);
356 // Use the payload size as recorded by the heap to determine how many 356 // Use the payload size as recorded by the heap to determine how many
357 // elements to finalize. 357 // elements to finalize.
358 size_t length = header->PayloadSize() / sizeof(Value); 358 size_t length = header->PayloadSize() / sizeof(Value);
359 Value* table = reinterpret_cast<Value*>(pointer); 359 Value* table = reinterpret_cast<Value*>(pointer);
360 for (unsigned i = 0; i < length; ++i) { 360 for (unsigned i = 0; i < length; ++i) {
361 if (!Table::IsEmptyOrDeletedBucket(table[i])) 361 if (!Table::IsEmptyOrDeletedBucket(table[i]))
362 table[i].~Value(); 362 table[i].~Value();
363 } 363 }
364 } 364 }
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
846 const blink::HeapHashCountedSet<Value, HashFunctions, Traits>& set, 846 const blink::HeapHashCountedSet<Value, HashFunctions, Traits>& set,
847 VectorType& vector) { 847 VectorType& vector) {
848 CopyToVector(static_cast<const HashCountedSet<Value, HashFunctions, Traits, 848 CopyToVector(static_cast<const HashCountedSet<Value, HashFunctions, Traits,
849 blink::HeapAllocator>&>(set), 849 blink::HeapAllocator>&>(set),
850 vector); 850 vector);
851 } 851 }
852 852
853 } // namespace WTF 853 } // namespace WTF
854 854
855 #endif 855 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698