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

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

Issue 1115993003: Try reducing and balance GC callback stack sizes. Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: initialize stacks also before doing thread-terminating GCs Created 5 years, 7 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
« no previous file with comments | « Source/platform/heap/CallbackStack.h ('k') | Source/platform/heap/Heap.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "config.h" 5 #include "config.h"
6 #include "platform/heap/CallbackStack.h" 6 #include "platform/heap/CallbackStack.h"
7 7
8 #include "platform/heap/Heap.h" 8 #include "platform/heap/Heap.h"
9 9
10 namespace blink { 10 namespace blink {
11 11
12 CallbackStack::Block::Block(Block* next, unsigned blockSize)
13 {
14 m_buffer = new Item[blockSize];
15 m_limit = &(m_buffer[blockSize]);
16 m_current = &(m_buffer[0]);
17 m_next = next;
18 #if ENABLE(ASSERT)
19 m_blockSize = blockSize;
20 #endif
21 clearUnused();
22 }
23
12 void CallbackStack::Block::clear() 24 void CallbackStack::Block::clear()
13 { 25 {
14 m_current = &m_buffer[0]; 26 m_current = &m_buffer[0];
15 m_next = 0; 27 m_next = 0;
16 clearUnused(); 28 clearUnused();
17 } 29 }
18 30
19 void CallbackStack::Block::invokeEphemeronCallbacks(Visitor* visitor) 31 void CallbackStack::Block::invokeEphemeronCallbacks(Visitor* visitor)
20 { 32 {
21 // This loop can tolerate entries being added by the callbacks after 33 // This loop can tolerate entries being added by the callbacks after
(...skipping 29 matching lines...) Expand all
51 if (item->object() == object) 63 if (item->object() == object)
52 return true; 64 return true;
53 } 65 }
54 return false; 66 return false;
55 } 67 }
56 #endif 68 #endif
57 69
58 void CallbackStack::Block::clearUnused() 70 void CallbackStack::Block::clearUnused()
59 { 71 {
60 #if ENABLE(ASSERT) 72 #if ENABLE(ASSERT)
61 for (size_t i = 0; i < blockSize; i++) 73 for (unsigned i = 0; i < m_blockSize; ++i)
62 m_buffer[i] = Item(0, 0); 74 m_buffer[i] = Item(0, 0);
63 #endif 75 #endif
64 } 76 }
65 77
66 CallbackStack::CallbackStack() : m_first(new Block(0)), m_last(m_first) 78 CallbackStack::CallbackStack(unsigned blockSize)
79 : m_first(new Block(nullptr, blockSize))
80 , m_last(m_first)
81 , m_blockSize(blockSize)
67 { 82 {
68 } 83 }
69 84
70 CallbackStack::~CallbackStack() 85 CallbackStack::~CallbackStack()
71 { 86 {
72 clear(); 87 clear();
73 delete m_first; 88 delete m_first;
74 m_first = 0; 89 m_first = 0;
75 m_last = 0; 90 m_last = 0;
76 } 91 }
(...skipping 10 matching lines...) Expand all
87 } 102 }
88 103
89 bool CallbackStack::isEmpty() const 104 bool CallbackStack::isEmpty() const
90 { 105 {
91 return hasJustOneBlock() && m_first->isEmptyBlock(); 106 return hasJustOneBlock() && m_first->isEmptyBlock();
92 } 107 }
93 108
94 CallbackStack::Item* CallbackStack::allocateEntrySlow() 109 CallbackStack::Item* CallbackStack::allocateEntrySlow()
95 { 110 {
96 ASSERT(!m_first->allocateEntry()); 111 ASSERT(!m_first->allocateEntry());
97 m_first = new Block(m_first); 112 m_first = new Block(m_first, m_blockSize);
98 return m_first->allocateEntry(); 113 return m_first->allocateEntry();
99 } 114 }
100 115
101 CallbackStack::Item* CallbackStack::popSlow() 116 CallbackStack::Item* CallbackStack::popSlow()
102 { 117 {
103 ASSERT(m_first->isEmptyBlock()); 118 ASSERT(m_first->isEmptyBlock());
104 119
105 for (;;) { 120 for (;;) {
106 if (hasJustOneBlock()) { 121 if (hasJustOneBlock()) {
107 #if ENABLE(ASSERT) 122 #if ENABLE(ASSERT)
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 // Recurse first (blockSize at a time) so we get to the newly added entries last. 158 // Recurse first (blockSize at a time) so we get to the newly added entries last.
144 invokeOldestCallbacks(from->next(), upto, visitor); 159 invokeOldestCallbacks(from->next(), upto, visitor);
145 from->invokeEphemeronCallbacks(visitor); 160 from->invokeEphemeronCallbacks(visitor);
146 } 161 }
147 162
148 bool CallbackStack::hasJustOneBlock() const 163 bool CallbackStack::hasJustOneBlock() const
149 { 164 {
150 return !m_first->next(); 165 return !m_first->next();
151 } 166 }
152 167
153 void CallbackStack::swap(CallbackStack* other)
154 {
155 Block* tmp = m_first;
156 m_first = other->m_first;
157 other->m_first = tmp;
158 tmp = m_last;
159 m_last = other->m_last;
160 other->m_last = tmp;
161 }
162
163 #if ENABLE(ASSERT) 168 #if ENABLE(ASSERT)
164 bool CallbackStack::hasCallbackForObject(const void* object) 169 bool CallbackStack::hasCallbackForObject(const void* object)
165 { 170 {
166 for (Block* current = m_first; current; current = current->next()) { 171 for (Block* current = m_first; current; current = current->next()) {
167 if (current->hasCallbackForObject(object)) 172 if (current->hasCallbackForObject(object))
168 return true; 173 return true;
169 } 174 }
170 return false; 175 return false;
171 } 176 }
172 #endif 177 #endif
173 178
174 } 179 }
OLDNEW
« no previous file with comments | « Source/platform/heap/CallbackStack.h ('k') | Source/platform/heap/Heap.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698