| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "platform/heap/PageMemory.h" | 5 #include "platform/heap/PageMemory.h" |
| 6 | 6 |
| 7 #include "platform/heap/Heap.h" | 7 #include "platform/heap/Heap.h" |
| 8 #include "platform/heap/ThreadState.h" |
| 8 #include "wtf/Assertions.h" | 9 #include "wtf/Assertions.h" |
| 9 #include "wtf/PageAllocator.h" | 10 #include "wtf/PageAllocator.h" |
| 10 | 11 |
| 11 namespace blink { | 12 namespace blink { |
| 12 | 13 |
| 13 void MemoryRegion::release() | 14 void MemoryRegion::release() |
| 14 { | 15 { |
| 15 WTF::freePages(m_base, m_size); | 16 WTF::freePages(m_base, m_size); |
| 16 } | 17 } |
| 17 | 18 |
| 18 bool MemoryRegion::commit() | 19 bool MemoryRegion::commit() |
| 19 { | 20 { |
| 20 WTF::recommitSystemPages(m_base, m_size); | 21 WTF::recommitSystemPages(m_base, m_size); |
| 21 return WTF::setSystemPagesAccessible(m_base, m_size); | 22 return WTF::setSystemPagesAccessible(m_base, m_size); |
| 22 } | 23 } |
| 23 | 24 |
| 24 void MemoryRegion::decommit() | 25 void MemoryRegion::decommit() |
| 25 { | 26 { |
| 26 WTF::decommitSystemPages(m_base, m_size); | 27 WTF::decommitSystemPages(m_base, m_size); |
| 27 WTF::setSystemPagesInaccessible(m_base, m_size); | 28 WTF::setSystemPagesInaccessible(m_base, m_size); |
| 28 } | 29 } |
| 29 | 30 |
| 30 | 31 |
| 31 PageMemoryRegion::PageMemoryRegion(Address base, size_t size, unsigned numPages) | 32 PageMemoryRegion::PageMemoryRegion(Address base, size_t size, unsigned numPages,
GCGroup* gcGroup) |
| 32 : MemoryRegion(base, size) | 33 : MemoryRegion(base, size) |
| 33 , m_isLargePage(numPages == 1) | 34 , m_isLargePage(numPages == 1) |
| 34 , m_numPages(numPages) | 35 , m_numPages(numPages) |
| 36 , m_gcGroup(gcGroup) |
| 35 { | 37 { |
| 36 Heap::addPageMemoryRegion(this); | |
| 37 for (size_t i = 0; i < blinkPagesPerRegion; ++i) | 38 for (size_t i = 0; i < blinkPagesPerRegion; ++i) |
| 38 m_inUse[i] = false; | 39 m_inUse[i] = false; |
| 40 m_gcGroup->addPageMemoryRegion(this); |
| 39 } | 41 } |
| 40 | 42 |
| 41 PageMemoryRegion::~PageMemoryRegion() | 43 PageMemoryRegion::~PageMemoryRegion() |
| 42 { | 44 { |
| 43 Heap::removePageMemoryRegion(this); | 45 m_gcGroup->removePageMemoryRegion(this); |
| 44 release(); | 46 release(); |
| 45 } | 47 } |
| 46 | 48 |
| 47 // TODO(haraken): Like partitionOutOfMemoryWithLotsOfUncommitedPages(), | 49 // TODO(haraken): Like partitionOutOfMemoryWithLotsOfUncommitedPages(), |
| 48 // we should probably have a way to distinguish physical memory OOM from | 50 // we should probably have a way to distinguish physical memory OOM from |
| 49 // virtual address space OOM. | 51 // virtual address space OOM. |
| 50 static NEVER_INLINE void blinkGCOutOfMemory() | 52 static NEVER_INLINE void blinkGCOutOfMemory() |
| 51 { | 53 { |
| 52 IMMEDIATE_CRASH(); | 54 IMMEDIATE_CRASH(); |
| 53 } | 55 } |
| 54 | 56 |
| 55 PageMemoryRegion* PageMemoryRegion::allocate(size_t size, unsigned numPages) | 57 PageMemoryRegion* PageMemoryRegion::allocate(size_t size, unsigned numPages, GCG
roup* gcGroup) |
| 56 { | 58 { |
| 57 // Round size up to the allocation granularity. | 59 // Round size up to the allocation granularity. |
| 58 size = (size + WTF::kPageAllocationGranularityOffsetMask) & WTF::kPageAlloca
tionGranularityBaseMask; | 60 size = (size + WTF::kPageAllocationGranularityOffsetMask) & WTF::kPageAlloca
tionGranularityBaseMask; |
| 59 Address base = static_cast<Address>(WTF::allocPages(nullptr, size, blinkPage
Size, WTF::PageInaccessible)); | 61 Address base = static_cast<Address>(WTF::allocPages(nullptr, size, blinkPage
Size, WTF::PageInaccessible)); |
| 60 if (!base) | 62 if (!base) |
| 61 blinkGCOutOfMemory(); | 63 blinkGCOutOfMemory(); |
| 62 return new PageMemoryRegion(base, size, numPages); | 64 return new PageMemoryRegion(base, size, numPages, gcGroup); |
| 63 } | 65 } |
| 64 | 66 |
| 65 PageMemoryRegion* RegionTree::lookup(Address address) | 67 PageMemoryRegion* RegionTree::lookup(Address address) |
| 66 { | 68 { |
| 67 RegionTree* current = this; | 69 RegionTree* current = this; |
| 68 while (current) { | 70 while (current) { |
| 69 Address base = current->m_region->base(); | 71 Address base = current->m_region->base(); |
| 70 if (address < base) { | 72 if (address < base) { |
| 71 current = current->m_left; | 73 current = current->m_left; |
| 72 continue; | 74 continue; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 // Setup the payload one guard page into the page memory. | 140 // Setup the payload one guard page into the page memory. |
| 139 Address payloadAddress = region->base() + pageOffset + blinkGuardPageSize; | 141 Address payloadAddress = region->base() + pageOffset + blinkGuardPageSize; |
| 140 return new PageMemory(region, MemoryRegion(payloadAddress, payloadSize)); | 142 return new PageMemory(region, MemoryRegion(payloadAddress, payloadSize)); |
| 141 } | 143 } |
| 142 | 144 |
| 143 static size_t roundToOsPageSize(size_t size) | 145 static size_t roundToOsPageSize(size_t size) |
| 144 { | 146 { |
| 145 return (size + WTF::kSystemPageSize - 1) & ~(WTF::kSystemPageSize - 1); | 147 return (size + WTF::kSystemPageSize - 1) & ~(WTF::kSystemPageSize - 1); |
| 146 } | 148 } |
| 147 | 149 |
| 148 PageMemory* PageMemory::allocate(size_t payloadSize) | 150 PageMemory* PageMemory::allocate(size_t payloadSize, GCGroup* gcGroup) |
| 149 { | 151 { |
| 150 ASSERT(payloadSize > 0); | 152 ASSERT(payloadSize > 0); |
| 151 | 153 |
| 152 // Virtual memory allocation routines operate in OS page sizes. | 154 // Virtual memory allocation routines operate in OS page sizes. |
| 153 // Round up the requested size to nearest os page size. | 155 // Round up the requested size to nearest os page size. |
| 154 payloadSize = roundToOsPageSize(payloadSize); | 156 payloadSize = roundToOsPageSize(payloadSize); |
| 155 | 157 |
| 156 // Overallocate by 2 times OS page size to have space for a | 158 // Overallocate by 2 times OS page size to have space for a |
| 157 // guard page at the beginning and end of blink heap page. | 159 // guard page at the beginning and end of blink heap page. |
| 158 size_t allocationSize = payloadSize + 2 * blinkGuardPageSize; | 160 size_t allocationSize = payloadSize + 2 * blinkGuardPageSize; |
| 159 PageMemoryRegion* pageMemoryRegion = PageMemoryRegion::allocateLargePage(all
ocationSize); | 161 PageMemoryRegion* pageMemoryRegion = PageMemoryRegion::allocateLargePage(all
ocationSize, gcGroup); |
| 160 PageMemory* storage = setupPageMemoryInRegion(pageMemoryRegion, 0, payloadSi
ze); | 162 PageMemory* storage = setupPageMemoryInRegion(pageMemoryRegion, 0, payloadSi
ze); |
| 161 RELEASE_ASSERT(storage->commit()); | 163 RELEASE_ASSERT(storage->commit()); |
| 162 return storage; | 164 return storage; |
| 163 } | 165 } |
| 164 | 166 |
| 165 } // namespace blink | 167 } // namespace blink |
| OLD | NEW |