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 for (int index = 0; index < BlinkGC::NumberOfArenas; ++index) { | 14 for (int index = 0; index < BlinkGC::NumberOfArenas; ++index) { |
15 while (PoolEntry* entry = m_pool[index]) { | 15 while (PoolEntry* entry = m_pool[index]) { |
16 m_pool[index] = entry->next; | 16 m_pool[index] = entry->next; |
17 PageMemory* memory = entry->data; | 17 PageMemory* memory = entry->data; |
18 ASSERT(memory); | 18 DCHECK(memory); |
19 delete memory; | 19 delete memory; |
20 delete entry; | 20 delete entry; |
21 } | 21 } |
22 } | 22 } |
23 } | 23 } |
24 | 24 |
25 void FreePagePool::addFreePage(int index, PageMemory* memory) { | 25 void FreePagePool::addFreePage(int index, PageMemory* memory) { |
26 // When adding a page to the pool we decommit it to ensure it is unused | 26 // When adding a page to the pool we decommit it to ensure it is unused |
27 // while in the pool. This also allows the physical memory, backing the | 27 // while in the pool. This also allows the physical memory, backing the |
28 // page, to be given back to the OS. | 28 // page, to be given back to the OS. |
29 memory->decommit(); | 29 memory->decommit(); |
30 MutexLocker locker(m_mutex[index]); | 30 MutexLocker locker(m_mutex[index]); |
31 PoolEntry* entry = new PoolEntry(memory, m_pool[index]); | 31 PoolEntry* entry = new PoolEntry(memory, m_pool[index]); |
32 m_pool[index] = entry; | 32 m_pool[index] = entry; |
33 } | 33 } |
34 | 34 |
35 PageMemory* FreePagePool::takeFreePage(int index) { | 35 PageMemory* FreePagePool::takeFreePage(int index) { |
36 MutexLocker locker(m_mutex[index]); | 36 MutexLocker locker(m_mutex[index]); |
37 while (PoolEntry* entry = m_pool[index]) { | 37 while (PoolEntry* entry = m_pool[index]) { |
38 m_pool[index] = entry->next; | 38 m_pool[index] = entry->next; |
39 PageMemory* memory = entry->data; | 39 PageMemory* memory = entry->data; |
40 ASSERT(memory); | 40 DCHECK(memory); |
41 delete entry; | 41 delete entry; |
42 if (memory->commit()) | 42 if (memory->commit()) |
43 return memory; | 43 return memory; |
44 | 44 |
45 // We got some memory, but failed to commit it, try again. | 45 // We got some memory, but failed to commit it, try again. |
46 delete memory; | 46 delete memory; |
47 } | 47 } |
48 return nullptr; | 48 return nullptr; |
49 } | 49 } |
50 | 50 |
51 OrphanedPagePool::~OrphanedPagePool() { | 51 OrphanedPagePool::~OrphanedPagePool() { |
52 for (int index = 0; index < BlinkGC::NumberOfArenas; ++index) { | 52 for (int index = 0; index < BlinkGC::NumberOfArenas; ++index) { |
53 while (PoolEntry* entry = m_pool[index]) { | 53 while (PoolEntry* entry = m_pool[index]) { |
54 m_pool[index] = entry->next; | 54 m_pool[index] = entry->next; |
55 BasePage* page = entry->data; | 55 BasePage* page = entry->data; |
56 delete entry; | 56 delete entry; |
57 PageMemory* memory = page->storage(); | 57 PageMemory* memory = page->storage(); |
58 ASSERT(memory); | 58 DCHECK(memory); |
59 page->~BasePage(); | 59 page->~BasePage(); |
60 delete memory; | 60 delete memory; |
61 } | 61 } |
62 } | 62 } |
63 } | 63 } |
64 | 64 |
65 void OrphanedPagePool::addOrphanedPage(int index, BasePage* page) { | 65 void OrphanedPagePool::addOrphanedPage(int index, BasePage* page) { |
66 page->markOrphaned(); | 66 page->markOrphaned(); |
67 PoolEntry* entry = new PoolEntry(page, m_pool[index]); | 67 PoolEntry* entry = new PoolEntry(page, m_pool[index]); |
68 m_pool[index] = entry; | 68 m_pool[index] = entry; |
69 } | 69 } |
70 | 70 |
71 NO_SANITIZE_ADDRESS | 71 NO_SANITIZE_ADDRESS |
72 void OrphanedPagePool::decommitOrphanedPages() { | 72 void OrphanedPagePool::decommitOrphanedPages() { |
73 ASSERT(ThreadState::current()->isInGC()); | 73 DCHECK(ThreadState::current()->isInGC()); |
74 ASSERT(ThreadState::current()->heap().isAtSafePoint()); | 74 DCHECK(ThreadState::current()->heap().isAtSafePoint()); |
75 | 75 |
76 for (int index = 0; index < BlinkGC::NumberOfArenas; ++index) { | 76 for (int index = 0; index < BlinkGC::NumberOfArenas; ++index) { |
77 PoolEntry* entry = m_pool[index]; | 77 PoolEntry* entry = m_pool[index]; |
78 PoolEntry** prevNext = &m_pool[index]; | 78 PoolEntry** prevNext = &m_pool[index]; |
79 while (entry) { | 79 while (entry) { |
80 BasePage* page = entry->data; | 80 BasePage* page = entry->data; |
81 // Check if we should reuse the memory or just free it. | 81 // Check if we should reuse the memory or just free it. |
82 // Large object memory is not reused but freed, normal blink heap | 82 // Large object memory is not reused but freed, normal blink heap |
83 // pages are reused. | 83 // pages are reused. |
84 // NOTE: We call the destructor before freeing or adding to the | 84 // NOTE: We call the destructor before freeing or adding to the |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 for (Address current = address; current < address + size; ++current) { | 119 for (Address current = address; current < address + size; ++current) { |
120 breakOptimization(current); | 120 breakOptimization(current); |
121 *current = value; | 121 *current = value; |
122 } | 122 } |
123 } | 123 } |
124 | 124 |
125 void OrphanedPagePool::clearMemory(PageMemory* memory) { | 125 void OrphanedPagePool::clearMemory(PageMemory* memory) { |
126 asanDisabledMemset(memory->writableStart(), 0, blinkPagePayloadSize()); | 126 asanDisabledMemset(memory->writableStart(), 0, blinkPagePayloadSize()); |
127 } | 127 } |
128 | 128 |
129 #if ENABLE(ASSERT) | 129 #if DCHECK_IS_ON() |
130 bool OrphanedPagePool::contains(void* object) { | 130 bool OrphanedPagePool::contains(void* object) { |
131 for (int index = 0; index < BlinkGC::NumberOfArenas; ++index) { | 131 for (int index = 0; index < BlinkGC::NumberOfArenas; ++index) { |
132 for (PoolEntry* entry = m_pool[index]; entry; entry = entry->next) { | 132 for (PoolEntry* entry = m_pool[index]; entry; entry = entry->next) { |
133 BasePage* page = entry->data; | 133 BasePage* page = entry->data; |
134 if (page->contains(reinterpret_cast<Address>(object))) | 134 if (page->contains(reinterpret_cast<Address>(object))) |
135 return true; | 135 return true; |
136 } | 136 } |
137 } | 137 } |
138 return false; | 138 return false; |
139 } | 139 } |
140 #endif | 140 #endif |
141 | 141 |
142 } // namespace blink | 142 } // namespace blink |
OLD | NEW |