Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(79)

Side by Side Diff: third_party/WebKit/Source/platform/heap/CallbackStack.cpp

Issue 1689823003: Revert of Oilpan: Decommit backing storage of CallbackStacks (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/CallbackStack.h" 5 #include "platform/heap/CallbackStack.h"
6 #include "wtf/PageAllocator.h"
7 6
8 namespace blink { 7 namespace blink {
9 8
10 CallbackStack::Block::Block(Block* next) 9 void CallbackStack::Block::clear()
11 { 10 {
12 static_assert((blockSize * sizeof(Item)) % WTF::kPageAllocationGranularity = = 0, "CallbackStack::blockSize * sizeof(Item) must be a multiple of WTF::kPageAl locationGranularity");
13 m_buffer = static_cast<Item*>(WTF::allocPages(nullptr, blockSize * sizeof(It em), WTF::kPageAllocationGranularity, WTF::PageAccessible));
14 RELEASE_ASSERT(m_buffer);
15
16 #if ENABLE(ASSERT)
17 for (size_t i = 0; i < blockSize; i++)
18 m_buffer[i] = Item(0, 0);
19 #endif
20
21 m_limit = &(m_buffer[blockSize]);
22 m_current = &(m_buffer[0]);
23 m_next = next;
24 }
25
26 CallbackStack::Block::~Block()
27 {
28 WTF::freePages(m_buffer, blockSize * sizeof(Item));
29 m_buffer = nullptr;
30 m_limit = nullptr;
31 m_current = nullptr;
32 m_next = nullptr;
33 }
34
35 void CallbackStack::Block::decommit()
36 {
37 #if ENABLE(ASSERT)
38 for (size_t i = 0; i < blockSize; i++)
39 m_buffer[i] = Item(0, 0);
40 #endif
41
42 WTF::discardSystemPages(m_buffer, blockSize * sizeof(Item));
43
44 m_current = &m_buffer[0]; 11 m_current = &m_buffer[0];
45 m_next = nullptr; 12 m_next = nullptr;
13 clearUnused();
46 } 14 }
47 15
48 void CallbackStack::Block::invokeEphemeronCallbacks(Visitor* visitor) 16 void CallbackStack::Block::invokeEphemeronCallbacks(Visitor* visitor)
49 { 17 {
50 // This loop can tolerate entries being added by the callbacks after 18 // This loop can tolerate entries being added by the callbacks after
51 // iteration starts. 19 // iteration starts.
52 for (unsigned i = 0; m_buffer + i < m_current; i++) { 20 for (unsigned i = 0; m_buffer + i < m_current; i++) {
53 Item& item = m_buffer[i]; 21 Item& item = m_buffer[i];
54 item.call(visitor); 22 item.call(visitor);
55 } 23 }
56 } 24 }
57 25
58 #if ENABLE(ASSERT) 26 #if ENABLE(ASSERT)
59 bool CallbackStack::Block::hasCallbackForObject(const void* object) 27 bool CallbackStack::Block::hasCallbackForObject(const void* object)
60 { 28 {
61 for (unsigned i = 0; m_buffer + i < m_current; i++) { 29 for (unsigned i = 0; m_buffer + i < m_current; i++) {
62 Item* item = &m_buffer[i]; 30 Item* item = &m_buffer[i];
63 if (item->object() == object) 31 if (item->object() == object)
64 return true; 32 return true;
65 } 33 }
66 return false; 34 return false;
67 } 35 }
68 #endif 36 #endif
69 37
70 CallbackStack::CallbackStack() 38 void CallbackStack::Block::clearUnused()
71 : m_first(new Block(0)) 39 {
72 , m_last(m_first) 40 #if ENABLE(ASSERT)
41 for (size_t i = 0; i < blockSize; i++)
42 m_buffer[i] = Item(0, 0);
43 #endif
44 }
45
46 CallbackStack::CallbackStack() : m_first(new Block(0)), m_last(m_first)
73 { 47 {
74 } 48 }
75 49
76 CallbackStack::~CallbackStack() 50 CallbackStack::~CallbackStack()
77 { 51 {
78 RELEASE_ASSERT(isEmpty()); 52 clear();
79 delete m_first; 53 delete m_first;
80 m_first = nullptr; 54 m_first = nullptr;
81 m_last = nullptr; 55 m_last = nullptr;
82 } 56 }
83 57
84 void CallbackStack::decommit() 58 void CallbackStack::clear()
85 { 59 {
86 Block* next; 60 Block* next;
87 for (Block* current = m_first->next(); current; current = next) { 61 for (Block* current = m_first->next(); current; current = next) {
88 next = current->next(); 62 next = current->next();
89 delete current; 63 delete current;
90 } 64 }
91 m_first->decommit(); 65 m_first->clear();
92 m_last = m_first; 66 m_last = m_first;
93 } 67 }
94 68
95 bool CallbackStack::isEmpty() const 69 bool CallbackStack::isEmpty() const
96 { 70 {
97 return hasJustOneBlock() && m_first->isEmptyBlock(); 71 return hasJustOneBlock() && m_first->isEmptyBlock();
98 } 72 }
99 73
100 CallbackStack::Item* CallbackStack::allocateEntrySlow() 74 CallbackStack::Item* CallbackStack::allocateEntrySlow()
101 { 75 {
102 ASSERT(!m_first->allocateEntry()); 76 ASSERT(!m_first->allocateEntry());
103 m_first = new Block(m_first); 77 m_first = new Block(m_first);
104 return m_first->allocateEntry(); 78 return m_first->allocateEntry();
105 } 79 }
106 80
107 CallbackStack::Item* CallbackStack::popSlow() 81 CallbackStack::Item* CallbackStack::popSlow()
108 { 82 {
109 ASSERT(m_first->isEmptyBlock()); 83 ASSERT(m_first->isEmptyBlock());
110 84
111 for (;;) { 85 for (;;) {
112 Block* next = m_first->next(); 86 Block* next = m_first->next();
113 if (!next) { 87 if (!next) {
114 #if ENABLE(ASSERT) 88 #if ENABLE(ASSERT)
115 m_first->decommit(); 89 m_first->clear();
116 #endif 90 #endif
117 return nullptr; 91 return nullptr;
118 } 92 }
119 delete m_first; 93 delete m_first;
120 m_first = next; 94 m_first = next;
121 if (Item* item = m_first->pop()) 95 if (Item* item = m_first->pop())
122 return item; 96 return item;
123 } 97 }
124 } 98 }
125 99
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 { 135 {
162 for (Block* current = m_first; current; current = current->next()) { 136 for (Block* current = m_first; current; current = current->next()) {
163 if (current->hasCallbackForObject(object)) 137 if (current->hasCallbackForObject(object))
164 return true; 138 return true;
165 } 139 }
166 return false; 140 return false;
167 } 141 }
168 #endif 142 #endif
169 143
170 } // namespace blink 144 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/heap/CallbackStack.h ('k') | third_party/WebKit/Source/platform/heap/Heap.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698