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 #include "config.h" | 5 #include "config.h" |
6 #include "platform/heap/HeapAllocator.h" | 6 #include "platform/heap/HeapAllocator.h" |
7 | 7 |
8 namespace blink { | 8 namespace blink { |
9 | 9 |
10 void HeapAllocator::backingFree(void* address) | 10 void HeapAllocator::backingFree(void* address) |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 return backingExpand(address, newSize); | 81 return backingExpand(address, newSize); |
82 } | 82 } |
83 | 83 |
84 bool HeapAllocator::expandHashTableBacking(void* address, size_t newSize) | 84 bool HeapAllocator::expandHashTableBacking(void* address, size_t newSize) |
85 { | 85 { |
86 return backingExpand(address, newSize); | 86 return backingExpand(address, newSize); |
87 } | 87 } |
88 | 88 |
89 bool HeapAllocator::backingShrink(void* address, size_t quantizedCurrentSize, si
ze_t quantizedShrunkSize) | 89 bool HeapAllocator::backingShrink(void* address, size_t quantizedCurrentSize, si
ze_t quantizedShrunkSize) |
90 { | 90 { |
91 // We shrink the object only if the shrinking will make a non-small | |
92 // prompt-free block. | |
93 // FIXME: Optimize the threshold size. | |
94 if (quantizedCurrentSize <= quantizedShrunkSize + sizeof(HeapObjectHeader) +
sizeof(void*) * 32) | |
95 return true; | |
96 | |
97 if (!address) | 91 if (!address) |
98 return true; | 92 return true; |
99 | 93 |
100 ThreadState* state = ThreadState::current(); | 94 ThreadState* state = ThreadState::current(); |
101 if (state->sweepForbidden()) | 95 if (state->sweepForbidden()) |
102 return false; | 96 return false; |
103 ASSERT(!state->isInGC()); | 97 ASSERT(!state->isInGC()); |
104 ASSERT(state->isAllocationAllowed()); | 98 ASSERT(state->isAllocationAllowed()); |
105 | 99 |
106 // FIXME: Support shrink for large objects. | 100 // FIXME: Support shrink for large objects. |
107 // Don't shrink backings allocated on other threads. | 101 // Don't shrink backings allocated on other threads. |
108 BasePage* page = pageFromObject(address); | 102 BasePage* page = pageFromObject(address); |
109 if (page->isLargeObjectPage() || page->heap()->threadState() != state) | 103 if (page->isLargeObjectPage() || page->heap()->threadState() != state) |
110 return false; | 104 return false; |
111 | 105 |
112 HeapObjectHeader* header = HeapObjectHeader::fromPayload(address); | 106 HeapObjectHeader* header = HeapObjectHeader::fromPayload(address); |
113 ASSERT(header->checkHeader()); | 107 ASSERT(header->checkHeader()); |
114 NormalPageHeap* heap = static_cast<NormalPage*>(page)->heapForNormalPage(); | 108 NormalPageHeap* heap = static_cast<NormalPage*>(page)->heapForNormalPage(); |
| 109 // We shrink the object only if the shrinking will make a non-small |
| 110 // prompt-free block. |
| 111 // FIXME: Optimize the threshold size. |
| 112 if (quantizedCurrentSize <= quantizedShrunkSize + sizeof(HeapObjectHeader) +
sizeof(void*) * 32 && !heap->isObjectAllocatedLast(header)) |
| 113 return true; |
| 114 |
115 bool succeededAtAllocationPoint = heap->shrinkObject(header, quantizedShrunk
Size); | 115 bool succeededAtAllocationPoint = heap->shrinkObject(header, quantizedShrunk
Size); |
116 if (succeededAtAllocationPoint) | 116 if (succeededAtAllocationPoint) |
117 state->allocationPointAdjusted(heap->heapIndex()); | 117 state->allocationPointAdjusted(heap->heapIndex()); |
118 return true; | 118 return true; |
119 } | 119 } |
120 | 120 |
121 bool HeapAllocator::shrinkVectorBacking(void* address, size_t quantizedCurrentSi
ze, size_t quantizedShrunkSize) | 121 bool HeapAllocator::shrinkVectorBacking(void* address, size_t quantizedCurrentSi
ze, size_t quantizedShrunkSize) |
122 { | 122 { |
123 return backingShrink(address, quantizedCurrentSize, quantizedShrunkSize); | 123 return backingShrink(address, quantizedCurrentSize, quantizedShrunkSize); |
124 } | 124 } |
125 | 125 |
126 bool HeapAllocator::shrinkInlineVectorBacking(void* address, size_t quantizedCur
rentSize, size_t quantizedShrunkSize) | 126 bool HeapAllocator::shrinkInlineVectorBacking(void* address, size_t quantizedCur
rentSize, size_t quantizedShrunkSize) |
127 { | 127 { |
128 return backingShrink(address, quantizedCurrentSize, quantizedShrunkSize); | 128 return backingShrink(address, quantizedCurrentSize, quantizedShrunkSize); |
129 } | 129 } |
130 | 130 |
131 } // namespace blink | 131 } // namespace blink |
OLD | NEW |