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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 | 44 |
45 // This is a static-only class used as a trait on collections to make them heap | 45 // This is a static-only class used as a trait on collections to make them heap |
46 // allocated. However see also HeapListHashSetAllocator. | 46 // allocated. However see also HeapListHashSetAllocator. |
47 class PLATFORM_EXPORT HeapAllocator { | 47 class PLATFORM_EXPORT HeapAllocator { |
48 STATIC_ONLY(HeapAllocator); | 48 STATIC_ONLY(HeapAllocator); |
49 | 49 |
50 public: | 50 public: |
51 using Visitor = blink::Visitor; | 51 using Visitor = blink::Visitor; |
52 static const bool isGarbageCollected = true; | 52 static const bool isGarbageCollected = true; |
53 | 53 |
| 54 template<typename T> |
| 55 static size_t maxElementCountInBackingStore() { |
| 56 return maxHeapObjectSize / sizeof(T); |
| 57 } |
| 58 |
54 template <typename T> | 59 template <typename T> |
55 static size_t quantizedSize(size_t count) { | 60 static size_t quantizedSize(size_t count) { |
56 RELEASE_ASSERT(count <= maxHeapObjectSize / sizeof(T)); | 61 CHECK(count <= maxElementCountInBackingStore<T>()); |
57 return ThreadHeap::allocationSizeFromSize(count * sizeof(T)) - | 62 return ThreadHeap::allocationSizeFromSize(count * sizeof(T)) - |
58 sizeof(HeapObjectHeader); | 63 sizeof(HeapObjectHeader); |
59 } | 64 } |
60 template <typename T> | 65 template <typename T> |
61 static T* allocateVectorBacking(size_t size) { | 66 static T* allocateVectorBacking(size_t size) { |
62 ThreadState* state = ThreadStateFor<ThreadingTrait<T>::Affinity>::state(); | 67 ThreadState* state = ThreadStateFor<ThreadingTrait<T>::Affinity>::state(); |
63 ASSERT(state->isAllocationAllowed()); | 68 ASSERT(state->isAllocationAllowed()); |
64 size_t gcInfoIndex = GCInfoTrait<HeapVectorBacking<T>>::index(); | 69 size_t gcInfoIndex = GCInfoTrait<HeapVectorBacking<T>>::index(); |
65 NormalPageArena* arena = | 70 NormalPageArena* arena = |
66 static_cast<NormalPageArena*>(state->vectorBackingArena(gcInfoIndex)); | 71 static_cast<NormalPageArena*>(state->vectorBackingArena(gcInfoIndex)); |
(...skipping 765 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
832 const blink::HeapHashCountedSet<Value, HashFunctions, Traits>& set, | 837 const blink::HeapHashCountedSet<Value, HashFunctions, Traits>& set, |
833 VectorType& vector) { | 838 VectorType& vector) { |
834 copyToVector(static_cast<const HashCountedSet<Value, HashFunctions, Traits, | 839 copyToVector(static_cast<const HashCountedSet<Value, HashFunctions, Traits, |
835 blink::HeapAllocator>&>(set), | 840 blink::HeapAllocator>&>(set), |
836 vector); | 841 vector); |
837 } | 842 } |
838 | 843 |
839 } // namespace WTF | 844 } // namespace WTF |
840 | 845 |
841 #endif | 846 #endif |
OLD | NEW |