| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "config.h" |
| 6 #include "platform/heap/HeapAllocator.h" |
| 7 |
| 8 namespace blink { |
| 9 |
| 10 void HeapAllocator::backingFree(void* address) |
| 11 { |
| 12 if (!address) |
| 13 return; |
| 14 |
| 15 ThreadState* state = ThreadState::current(); |
| 16 if (state->sweepForbidden()) |
| 17 return; |
| 18 ASSERT(!state->isInGC()); |
| 19 |
| 20 // Don't promptly free large objects because their page is never reused. |
| 21 // Don't free backings allocated on other threads. |
| 22 BasePage* page = pageFromObject(address); |
| 23 if (page->isLargeObjectPage() || page->heap()->threadState() != state) |
| 24 return; |
| 25 |
| 26 HeapObjectHeader* header = HeapObjectHeader::fromPayload(address); |
| 27 header->checkHeader(); |
| 28 NormalPageHeap* heap = static_cast<NormalPage*>(page)->heapForNormalPage(); |
| 29 state->promptlyFreed(header->gcInfoIndex()); |
| 30 heap->promptlyFreeObject(header); |
| 31 } |
| 32 |
| 33 void HeapAllocator::freeVectorBacking(void* address) |
| 34 { |
| 35 backingFree(address); |
| 36 } |
| 37 |
| 38 void HeapAllocator::freeInlineVectorBacking(void* address) |
| 39 { |
| 40 backingFree(address); |
| 41 } |
| 42 |
| 43 void HeapAllocator::freeHashTableBacking(void* address) |
| 44 { |
| 45 backingFree(address); |
| 46 } |
| 47 |
| 48 bool HeapAllocator::backingExpand(void* address, size_t newSize) |
| 49 { |
| 50 if (!address) |
| 51 return false; |
| 52 |
| 53 ThreadState* state = ThreadState::current(); |
| 54 if (state->sweepForbidden()) |
| 55 return false; |
| 56 ASSERT(!state->isInGC()); |
| 57 ASSERT(state->isAllocationAllowed()); |
| 58 |
| 59 // FIXME: Support expand for large objects. |
| 60 // Don't expand backings allocated on other threads. |
| 61 BasePage* page = pageFromObject(address); |
| 62 if (page->isLargeObjectPage() || page->heap()->threadState() != state) |
| 63 return false; |
| 64 |
| 65 HeapObjectHeader* header = HeapObjectHeader::fromPayload(address); |
| 66 header->checkHeader(); |
| 67 NormalPageHeap* heap = static_cast<NormalPage*>(page)->heapForNormalPage(); |
| 68 bool succeed = heap->expandObject(header, newSize); |
| 69 if (succeed) |
| 70 state->allocationPointAdjusted(heap->heapIndex()); |
| 71 return succeed; |
| 72 } |
| 73 |
| 74 bool HeapAllocator::expandVectorBacking(void* address, size_t newSize) |
| 75 { |
| 76 return backingExpand(address, newSize); |
| 77 } |
| 78 |
| 79 bool HeapAllocator::expandInlineVectorBacking(void* address, size_t newSize) |
| 80 { |
| 81 return backingExpand(address, newSize); |
| 82 } |
| 83 |
| 84 bool HeapAllocator::expandHashTableBacking(void* address, size_t newSize) |
| 85 { |
| 86 return backingExpand(address, newSize); |
| 87 } |
| 88 |
| 89 void HeapAllocator::backingShrink(void* address, size_t quantizedCurrentSize, si
ze_t quantizedShrunkSize) |
| 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; |
| 96 |
| 97 if (!address) |
| 98 return; |
| 99 |
| 100 ThreadState* state = ThreadState::current(); |
| 101 if (state->sweepForbidden()) |
| 102 return; |
| 103 ASSERT(!state->isInGC()); |
| 104 ASSERT(state->isAllocationAllowed()); |
| 105 |
| 106 // FIXME: Support shrink for large objects. |
| 107 // Don't shrink backings allocated on other threads. |
| 108 BasePage* page = pageFromObject(address); |
| 109 if (page->isLargeObjectPage() || page->heap()->threadState() != state) |
| 110 return; |
| 111 |
| 112 HeapObjectHeader* header = HeapObjectHeader::fromPayload(address); |
| 113 header->checkHeader(); |
| 114 NormalPageHeap* heap = static_cast<NormalPage*>(page)->heapForNormalPage(); |
| 115 bool succeed = heap->shrinkObject(header, quantizedShrunkSize); |
| 116 if (succeed) |
| 117 state->allocationPointAdjusted(heap->heapIndex()); |
| 118 } |
| 119 |
| 120 } // namespace blink |
| OLD | NEW |