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) |
11 { | 11 { |
12 if (!address) | 12 if (!address) |
13 return; | 13 return; |
14 | 14 |
15 ThreadState* state = ThreadState::current(); | 15 ThreadState* state = ThreadState::current(); |
16 if (state->sweepForbidden()) | 16 if (state->sweepForbidden()) |
17 return; | 17 return; |
18 ASSERT(!state->isInGC()); | 18 ASSERT(!state->isInGC()); |
19 | 19 |
20 // Don't promptly free large objects because their page is never reused. | 20 // Don't promptly free large objects because their page is never reused. |
21 // Don't free backings allocated on other threads. | 21 // Don't free backings allocated on other threads. |
22 BasePage* page = pageFromObject(address); | 22 BasePage* page = pageFromObject(address); |
23 if (page->isLargeObjectPage() || page->heap()->threadState() != state) | 23 if (page->isLargeObjectPage() || page->heap()->threadState() != state) |
24 return; | 24 return; |
25 | 25 |
26 HeapObjectHeader* header = HeapObjectHeader::fromPayload(address); | 26 HeapObjectHeader* header = HeapObjectHeader::fromPayload(address); |
27 header->checkHeader(); | 27 ASSERT(header->checkHeader()); |
28 NormalPageHeap* heap = static_cast<NormalPage*>(page)->heapForNormalPage(); | 28 NormalPageHeap* heap = static_cast<NormalPage*>(page)->heapForNormalPage(); |
29 state->promptlyFreed(header->gcInfoIndex()); | 29 state->promptlyFreed(header->gcInfoIndex()); |
30 heap->promptlyFreeObject(header); | 30 heap->promptlyFreeObject(header); |
31 } | 31 } |
32 | 32 |
33 void HeapAllocator::freeVectorBacking(void* address) | 33 void HeapAllocator::freeVectorBacking(void* address) |
34 { | 34 { |
35 backingFree(address); | 35 backingFree(address); |
36 } | 36 } |
37 | 37 |
(...skipping 18 matching lines...) Expand all Loading... |
56 ASSERT(!state->isInGC()); | 56 ASSERT(!state->isInGC()); |
57 ASSERT(state->isAllocationAllowed()); | 57 ASSERT(state->isAllocationAllowed()); |
58 | 58 |
59 // FIXME: Support expand for large objects. | 59 // FIXME: Support expand for large objects. |
60 // Don't expand backings allocated on other threads. | 60 // Don't expand backings allocated on other threads. |
61 BasePage* page = pageFromObject(address); | 61 BasePage* page = pageFromObject(address); |
62 if (page->isLargeObjectPage() || page->heap()->threadState() != state) | 62 if (page->isLargeObjectPage() || page->heap()->threadState() != state) |
63 return false; | 63 return false; |
64 | 64 |
65 HeapObjectHeader* header = HeapObjectHeader::fromPayload(address); | 65 HeapObjectHeader* header = HeapObjectHeader::fromPayload(address); |
66 header->checkHeader(); | 66 ASSERT(header->checkHeader()); |
67 NormalPageHeap* heap = static_cast<NormalPage*>(page)->heapForNormalPage(); | 67 NormalPageHeap* heap = static_cast<NormalPage*>(page)->heapForNormalPage(); |
68 bool succeed = heap->expandObject(header, newSize); | 68 bool succeed = heap->expandObject(header, newSize); |
69 if (succeed) | 69 if (succeed) |
70 state->allocationPointAdjusted(heap->heapIndex()); | 70 state->allocationPointAdjusted(heap->heapIndex()); |
71 return succeed; | 71 return succeed; |
72 } | 72 } |
73 | 73 |
74 bool HeapAllocator::expandVectorBacking(void* address, size_t newSize) | 74 bool HeapAllocator::expandVectorBacking(void* address, size_t newSize) |
75 { | 75 { |
76 return backingExpand(address, newSize); | 76 return backingExpand(address, newSize); |
(...skipping 26 matching lines...) Expand all Loading... |
103 ASSERT(!state->isInGC()); | 103 ASSERT(!state->isInGC()); |
104 ASSERT(state->isAllocationAllowed()); | 104 ASSERT(state->isAllocationAllowed()); |
105 | 105 |
106 // FIXME: Support shrink for large objects. | 106 // FIXME: Support shrink for large objects. |
107 // Don't shrink backings allocated on other threads. | 107 // Don't shrink backings allocated on other threads. |
108 BasePage* page = pageFromObject(address); | 108 BasePage* page = pageFromObject(address); |
109 if (page->isLargeObjectPage() || page->heap()->threadState() != state) | 109 if (page->isLargeObjectPage() || page->heap()->threadState() != state) |
110 return; | 110 return; |
111 | 111 |
112 HeapObjectHeader* header = HeapObjectHeader::fromPayload(address); | 112 HeapObjectHeader* header = HeapObjectHeader::fromPayload(address); |
113 header->checkHeader(); | 113 ASSERT(header->checkHeader()); |
114 NormalPageHeap* heap = static_cast<NormalPage*>(page)->heapForNormalPage(); | 114 NormalPageHeap* heap = static_cast<NormalPage*>(page)->heapForNormalPage(); |
115 bool succeed = heap->shrinkObject(header, quantizedShrunkSize); | 115 bool succeed = heap->shrinkObject(header, quantizedShrunkSize); |
116 if (succeed) | 116 if (succeed) |
117 state->allocationPointAdjusted(heap->heapIndex()); | 117 state->allocationPointAdjusted(heap->heapIndex()); |
118 } | 118 } |
119 | 119 |
120 } // namespace blink | 120 } // namespace blink |
OLD | NEW |