Chromium Code Reviews| 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 "platform/heap/PagePool.h" | 5 #include "platform/heap/PagePool.h" |
| 6 | 6 |
| 7 #include "platform/heap/Heap.h" | 7 #include "platform/heap/Heap.h" |
| 8 #include "platform/heap/PageMemory.h" | 8 #include "platform/heap/PageMemory.h" |
| 9 #include "wtf/Assertions.h" | 9 #include "wtf/Assertions.h" |
| 10 | 10 |
| 11 namespace blink { | 11 namespace blink { |
| 12 | 12 |
| 13 FreePagePool::~FreePagePool() | 13 FreePagePool::~FreePagePool() |
| 14 { | 14 { |
| 15 for (int index = 0; index < BlinkGC::NumberOfHeaps; ++index) { | 15 for (int index = 0; index < BlinkGC::NumberOfArenas; ++index) { |
| 16 while (PoolEntry* entry = m_pool[index]) { | 16 while (PoolEntry* entry = m_pool[index]) { |
| 17 m_pool[index] = entry->next; | 17 m_pool[index] = entry->next; |
| 18 PageMemory* memory = entry->data; | 18 PageMemory* memory = entry->data; |
| 19 ASSERT(memory); | 19 ASSERT(memory); |
| 20 delete memory; | 20 delete memory; |
| 21 delete entry; | 21 delete entry; |
| 22 } | 22 } |
| 23 } | 23 } |
| 24 } | 24 } |
| 25 | 25 |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 46 return memory; | 46 return memory; |
| 47 | 47 |
| 48 // We got some memory, but failed to commit it, try again. | 48 // We got some memory, but failed to commit it, try again. |
| 49 delete memory; | 49 delete memory; |
| 50 } | 50 } |
| 51 return nullptr; | 51 return nullptr; |
| 52 } | 52 } |
| 53 | 53 |
| 54 OrphanedPagePool::~OrphanedPagePool() | 54 OrphanedPagePool::~OrphanedPagePool() |
| 55 { | 55 { |
| 56 for (int index = 0; index < BlinkGC::NumberOfHeaps; ++index) { | 56 for (int index = 0; index < BlinkGC::NumberOfArenas; ++index) { |
| 57 while (PoolEntry* entry = m_pool[index]) { | 57 while (PoolEntry* entry = m_pool[index]) { |
| 58 m_pool[index] = entry->next; | 58 m_pool[index] = entry->next; |
| 59 BasePage* page = entry->data; | 59 BasePage* page = entry->data; |
| 60 delete entry; | 60 delete entry; |
| 61 PageMemory* memory = page->storage(); | 61 PageMemory* memory = page->storage(); |
| 62 ASSERT(memory); | 62 ASSERT(memory); |
| 63 page->~BasePage(); | 63 page->~BasePage(); |
| 64 delete memory; | 64 delete memory; |
| 65 } | 65 } |
| 66 } | 66 } |
| 67 } | 67 } |
| 68 | 68 |
| 69 void OrphanedPagePool::addOrphanedPage(int index, BasePage* page) | 69 void OrphanedPagePool::addOrphanedPage(int index, BasePage* page) |
| 70 { | 70 { |
| 71 page->markOrphaned(); | 71 page->markOrphaned(); |
| 72 PoolEntry* entry = new PoolEntry(page, m_pool[index]); | 72 PoolEntry* entry = new PoolEntry(page, m_pool[index]); |
| 73 m_pool[index] = entry; | 73 m_pool[index] = entry; |
| 74 } | 74 } |
| 75 | 75 |
| 76 NO_SANITIZE_ADDRESS | 76 NO_SANITIZE_ADDRESS |
| 77 void OrphanedPagePool::decommitOrphanedPages() | 77 void OrphanedPagePool::decommitOrphanedPages() |
| 78 { | 78 { |
| 79 ASSERT(ThreadState::current()->isInGC()); | 79 ASSERT(ThreadState::current()->isInGC()); |
|
haraken
2016/02/29 11:17:45
Add ASSERT(ThreadState::current() == ThreadState::
keishi
2016/03/02 06:01:03
Turned out decommitOrphanedPages() was called from
| |
| 80 | 80 |
| 81 #if ENABLE(ASSERT) | 81 #if ENABLE(ASSERT) |
| 82 // No locking needed as all threads are at safepoints at this point in time. | 82 // No locking needed as all threads are at safepoints at this point in time. |
| 83 for (ThreadState* state : ThreadState::attachedThreads()) | 83 ASSERT(ThreadState::mainThreadState()->heap().isAtSafePoint()); |
| 84 ASSERT(state->isAtSafePoint()); | |
| 85 #endif | 84 #endif |
| 86 | 85 |
| 87 for (int index = 0; index < BlinkGC::NumberOfHeaps; ++index) { | 86 for (int index = 0; index < BlinkGC::NumberOfArenas; ++index) { |
| 88 PoolEntry* entry = m_pool[index]; | 87 PoolEntry* entry = m_pool[index]; |
| 89 PoolEntry** prevNext = &m_pool[index]; | 88 PoolEntry** prevNext = &m_pool[index]; |
| 90 while (entry) { | 89 while (entry) { |
| 91 BasePage* page = entry->data; | 90 BasePage* page = entry->data; |
| 92 // Check if we should reuse the memory or just free it. | 91 // Check if we should reuse the memory or just free it. |
| 93 // Large object memory is not reused but freed, normal blink heap | 92 // Large object memory is not reused but freed, normal blink heap |
| 94 // pages are reused. | 93 // pages are reused. |
| 95 // NOTE: We call the destructor before freeing or adding to the | 94 // NOTE: We call the destructor before freeing or adding to the |
| 96 // free page pool. | 95 // free page pool. |
| 97 PageMemory* memory = page->storage(); | 96 PageMemory* memory = page->storage(); |
| 98 if (page->isLargeObjectPage()) { | 97 if (page->isLargeObjectPage()) { |
| 99 page->~BasePage(); | 98 page->~BasePage(); |
| 100 delete memory; | 99 delete memory; |
| 101 } else { | 100 } else { |
| 102 page->~BasePage(); | 101 page->~BasePage(); |
| 103 clearMemory(memory); | 102 clearMemory(memory); |
| 104 Heap::freePagePool()->addFreePage(index, memory); | 103 ThreadState::current()->heap().freePagePool()->addFreePage(index , memory); |
|
haraken
2016/02/29 11:17:45
ThreadState::current() => ThreadState::mainThreadS
keishi
2016/03/02 06:01:03
Done.
| |
| 105 } | 104 } |
| 106 | 105 |
| 107 PoolEntry* deadEntry = entry; | 106 PoolEntry* deadEntry = entry; |
| 108 entry = entry->next; | 107 entry = entry->next; |
| 109 *prevNext = entry; | 108 *prevNext = entry; |
| 110 delete deadEntry; | 109 delete deadEntry; |
| 111 } | 110 } |
| 112 } | 111 } |
| 113 } | 112 } |
| 114 | 113 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 132 } | 131 } |
| 133 | 132 |
| 134 void OrphanedPagePool::clearMemory(PageMemory* memory) | 133 void OrphanedPagePool::clearMemory(PageMemory* memory) |
| 135 { | 134 { |
| 136 asanDisabledMemset(memory->writableStart(), 0, blinkPagePayloadSize()); | 135 asanDisabledMemset(memory->writableStart(), 0, blinkPagePayloadSize()); |
| 137 } | 136 } |
| 138 | 137 |
| 139 #if ENABLE(ASSERT) | 138 #if ENABLE(ASSERT) |
| 140 bool OrphanedPagePool::contains(void* object) | 139 bool OrphanedPagePool::contains(void* object) |
| 141 { | 140 { |
| 142 for (int index = 0; index < BlinkGC::NumberOfHeaps; ++index) { | 141 for (int index = 0; index < BlinkGC::NumberOfArenas; ++index) { |
| 143 for (PoolEntry* entry = m_pool[index]; entry; entry = entry->next) { | 142 for (PoolEntry* entry = m_pool[index]; entry; entry = entry->next) { |
| 144 BasePage* page = entry->data; | 143 BasePage* page = entry->data; |
| 145 if (page->contains(reinterpret_cast<Address>(object))) | 144 if (page->contains(reinterpret_cast<Address>(object))) |
| 146 return true; | 145 return true; |
| 147 } | 146 } |
| 148 } | 147 } |
| 149 return false; | 148 return false; |
| 150 } | 149 } |
| 151 #endif | 150 #endif |
| 152 | 151 |
| 153 } // namespace blink | 152 } // namespace blink |
| OLD | NEW |