| 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 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 77 void OrphanedPagePool::decommitOrphanedPages() | 77 void OrphanedPagePool::decommitOrphanedPages() |
| 78 { | 78 { |
| 79 ASSERT(ThreadState::current()->isInGC()); | 79 ASSERT(ThreadState::current()->isInGC()); |
| 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 for (ThreadState* state : ThreadState::attachedThreads()) |
| 84 ASSERT(state->isAtSafePoint()); | 84 ASSERT(state->isAtSafePoint()); |
| 85 #endif | 85 #endif |
| 86 | 86 |
| 87 for (int index = 0; index < BlinkGC::NumberOfHeaps; ++index) { | 87 for (int index = 0; index < BlinkGC::NumberOfArenas; ++index) { |
| 88 PoolEntry* entry = m_pool[index]; | 88 PoolEntry* entry = m_pool[index]; |
| 89 PoolEntry** prevNext = &m_pool[index]; | 89 PoolEntry** prevNext = &m_pool[index]; |
| 90 while (entry) { | 90 while (entry) { |
| 91 BasePage* page = entry->data; | 91 BasePage* page = entry->data; |
| 92 // Check if we should reuse the memory or just free it. | 92 // Check if we should reuse the memory or just free it. |
| 93 // Large object memory is not reused but freed, normal blink heap | 93 // Large object memory is not reused but freed, normal blink heap |
| 94 // pages are reused. | 94 // pages are reused. |
| 95 // NOTE: We call the destructor before freeing or adding to the | 95 // NOTE: We call the destructor before freeing or adding to the |
| 96 // free page pool. | 96 // free page pool. |
| 97 PageMemory* memory = page->storage(); | 97 PageMemory* memory = page->storage(); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 } | 132 } |
| 133 | 133 |
| 134 void OrphanedPagePool::clearMemory(PageMemory* memory) | 134 void OrphanedPagePool::clearMemory(PageMemory* memory) |
| 135 { | 135 { |
| 136 asanDisabledMemset(memory->writableStart(), 0, blinkPagePayloadSize()); | 136 asanDisabledMemset(memory->writableStart(), 0, blinkPagePayloadSize()); |
| 137 } | 137 } |
| 138 | 138 |
| 139 #if ENABLE(ASSERT) | 139 #if ENABLE(ASSERT) |
| 140 bool OrphanedPagePool::contains(void* object) | 140 bool OrphanedPagePool::contains(void* object) |
| 141 { | 141 { |
| 142 for (int index = 0; index < BlinkGC::NumberOfHeaps; ++index) { | 142 for (int index = 0; index < BlinkGC::NumberOfArenas; ++index) { |
| 143 for (PoolEntry* entry = m_pool[index]; entry; entry = entry->next) { | 143 for (PoolEntry* entry = m_pool[index]; entry; entry = entry->next) { |
| 144 BasePage* page = entry->data; | 144 BasePage* page = entry->data; |
| 145 if (page->contains(reinterpret_cast<Address>(object))) | 145 if (page->contains(reinterpret_cast<Address>(object))) |
| 146 return true; | 146 return true; |
| 147 } | 147 } |
| 148 } | 148 } |
| 149 return false; | 149 return false; |
| 150 } | 150 } |
| 151 #endif | 151 #endif |
| 152 | 152 |
| 153 } // namespace blink | 153 } // namespace blink |
| OLD | NEW |