Chromium Code Reviews| 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 "wtf/Assertions.h" | 8 #include "wtf/Assertions.h" |
| 9 #include "wtf/PageAllocator.h" | 9 #include "wtf/PageAllocator.h" |
| 10 | 10 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 return WTF::setSystemPagesAccessible(m_base, m_size); | 21 return WTF::setSystemPagesAccessible(m_base, m_size); |
| 22 } | 22 } |
| 23 | 23 |
| 24 void MemoryRegion::decommit() | 24 void MemoryRegion::decommit() |
| 25 { | 25 { |
| 26 WTF::decommitSystemPages(m_base, m_size); | 26 WTF::decommitSystemPages(m_base, m_size); |
| 27 WTF::setSystemPagesInaccessible(m_base, m_size); | 27 WTF::setSystemPagesInaccessible(m_base, m_size); |
| 28 } | 28 } |
| 29 | 29 |
| 30 | 30 |
| 31 PageMemoryRegion::PageMemoryRegion(Address base, size_t size, unsigned numPages) | 31 PageMemoryRegion::PageMemoryRegion(Address base, size_t size, unsigned numPages, Heap* heap) |
| 32 : MemoryRegion(base, size) | 32 : MemoryRegion(base, size) |
| 33 , m_isLargePage(numPages == 1) | 33 , m_isLargePage(numPages == 1) |
| 34 , m_numPages(numPages) | 34 , m_numPages(numPages) |
| 35 , m_heap(heap) | |
| 35 { | 36 { |
| 36 Heap::addPageMemoryRegion(this); | 37 m_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; |
| 39 } | 40 } |
| 40 | 41 |
| 41 PageMemoryRegion::~PageMemoryRegion() | 42 PageMemoryRegion::~PageMemoryRegion() |
| 42 { | 43 { |
| 43 Heap::removePageMemoryRegion(this); | 44 m_heap->removePageMemoryRegion(this); |
| 44 release(); | 45 release(); |
| 45 } | 46 } |
| 46 | 47 |
| 47 // TODO(haraken): Like partitionOutOfMemoryWithLotsOfUncommitedPages(), | 48 // TODO(haraken): Like partitionOutOfMemoryWithLotsOfUncommitedPages(), |
| 48 // we should probably have a way to distinguish physical memory OOM from | 49 // we should probably have a way to distinguish physical memory OOM from |
| 49 // virtual address space OOM. | 50 // virtual address space OOM. |
| 50 static NEVER_INLINE void blinkGCOutOfMemory() | 51 static NEVER_INLINE void blinkGCOutOfMemory() |
| 51 { | 52 { |
| 52 IMMEDIATE_CRASH(); | 53 IMMEDIATE_CRASH(); |
| 53 } | 54 } |
| 54 | 55 |
| 55 PageMemoryRegion* PageMemoryRegion::allocate(size_t size, unsigned numPages) | 56 PageMemoryRegion* PageMemoryRegion::allocate(size_t size, unsigned numPages, Hea p* heap) |
| 56 { | 57 { |
| 57 // Round size up to the allocation granularity. | 58 // Round size up to the allocation granularity. |
| 58 size = (size + WTF::kPageAllocationGranularityOffsetMask) & WTF::kPageAlloca tionGranularityBaseMask; | 59 size = (size + WTF::kPageAllocationGranularityOffsetMask) & WTF::kPageAlloca tionGranularityBaseMask; |
| 59 Address base = static_cast<Address>(WTF::allocPages(nullptr, size, blinkPage Size, WTF::PageInaccessible)); | 60 Address base = static_cast<Address>(WTF::allocPages(nullptr, size, blinkPage Size, WTF::PageInaccessible)); |
| 60 if (!base) | 61 if (!base) |
| 61 blinkGCOutOfMemory(); | 62 blinkGCOutOfMemory(); |
| 62 return new PageMemoryRegion(base, size, numPages); | 63 return new PageMemoryRegion(base, size, numPages, heap); |
| 63 } | 64 } |
| 64 | 65 |
| 65 PageMemoryRegion* RegionTree::lookup(Address address) | 66 PageMemoryRegion* RegionTree::lookup(Address address) |
| 66 { | 67 { |
| 67 RegionTree* current = this; | 68 RegionTree* current = this; |
| 68 while (current) { | 69 while (current) { |
| 69 Address base = current->m_region->base(); | 70 Address base = current->m_region->base(); |
| 70 if (address < base) { | 71 if (address < base) { |
| 71 current = current->m_left; | 72 current = current->m_left; |
| 72 continue; | 73 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. | 139 // Setup the payload one guard page into the page memory. |
| 139 Address payloadAddress = region->base() + pageOffset + blinkGuardPageSize; | 140 Address payloadAddress = region->base() + pageOffset + blinkGuardPageSize; |
| 140 return new PageMemory(region, MemoryRegion(payloadAddress, payloadSize)); | 141 return new PageMemory(region, MemoryRegion(payloadAddress, payloadSize)); |
| 141 } | 142 } |
| 142 | 143 |
| 143 static size_t roundToOsPageSize(size_t size) | 144 static size_t roundToOsPageSize(size_t size) |
| 144 { | 145 { |
| 145 return (size + WTF::kSystemPageSize - 1) & ~(WTF::kSystemPageSize - 1); | 146 return (size + WTF::kSystemPageSize - 1) & ~(WTF::kSystemPageSize - 1); |
| 146 } | 147 } |
| 147 | 148 |
| 148 PageMemory* PageMemory::allocate(size_t payloadSize) | 149 PageMemory* PageMemory::allocate(size_t payloadSize, Heap* heap) |
| 149 { | 150 { |
| 150 ASSERT(payloadSize > 0); | 151 ASSERT(payloadSize > 0); |
| 151 | 152 |
| 152 // Virtual memory allocation routines operate in OS page sizes. | 153 // Virtual memory allocation routines operate in OS page sizes. |
| 153 // Round up the requested size to nearest os page size. | 154 // Round up the requested size to nearest os page size. |
| 154 payloadSize = roundToOsPageSize(payloadSize); | 155 payloadSize = roundToOsPageSize(payloadSize); |
| 155 | 156 |
| 156 // Overallocate by 2 times OS page size to have space for a | 157 // Overallocate by 2 times OS page size to have space for a |
| 157 // guard page at the beginning and end of blink heap page. | 158 // guard page at the beginning and end of blink heap page. |
| 158 size_t allocationSize = payloadSize + 2 * blinkGuardPageSize; | 159 size_t allocationSize = payloadSize + 2 * blinkGuardPageSize; |
| 159 PageMemoryRegion* pageMemoryRegion = PageMemoryRegion::allocateLargePage(all ocationSize); | 160 PageMemoryRegion* pageMemoryRegion = PageMemoryRegion::allocateLargePage(all ocationSize, heap); |
|
haraken
2016/02/29 11:17:45
A better fix would be to call heap->addPageMemoryR
keishi
2016/03/02 06:01:03
We need to call removePageMemoryRegion from ~PageM
haraken
2016/03/02 07:21:07
~PageMemoryRegion is called only by 'delete curren
keishi
2016/03/02 10:19:31
Done.
| |
| 160 PageMemory* storage = setupPageMemoryInRegion(pageMemoryRegion, 0, payloadSi ze); | 161 PageMemory* storage = setupPageMemoryInRegion(pageMemoryRegion, 0, payloadSi ze); |
| 161 RELEASE_ASSERT(storage->commit()); | 162 RELEASE_ASSERT(storage->commit()); |
| 162 return storage; | 163 return storage; |
| 163 } | 164 } |
| 164 | 165 |
| 165 } // namespace blink | 166 } // namespace blink |
| OLD | NEW |