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

Side by Side Diff: third_party/WebKit/Source/wtf/StackUtil.cpp

Issue 2728453006: WTF: Initialize main-thread stack estimates when WTF starts up. (Closed)
Patch Set: comment about why currentThread works this way Created 3 years, 9 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 "wtf/StackUtil.h" 5 #include "wtf/StackUtil.h"
6 6
7 #include "wtf/Assertions.h" 7 #include "wtf/Assertions.h"
8 #include "wtf/Threading.h" 8 #include "wtf/Threading.h"
9 #include "wtf/WTFThreadData.h" 9 #include "wtf/WTFThreadData.h"
10 10
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 #else 136 #else
137 return reinterpret_cast<void*>(__readfsdword(offsetof(NT_TIB, StackBase))); 137 return reinterpret_cast<void*>(__readfsdword(offsetof(NT_TIB, StackBase)));
138 #endif 138 #endif
139 #else 139 #else
140 #error Unsupported getStackStart on this platform. 140 #error Unsupported getStackStart on this platform.
141 #endif 141 #endif
142 } 142 }
143 143
144 namespace internal { 144 namespace internal {
145 145
146 uintptr_t mainThreadUnderestimatedStackSize() { 146 uintptr_t s_mainThreadStackStart = 0;
147 uintptr_t s_mainThreadUnderestimatedStackSize = 0;
148
149 void initializeMainThreadStackEstimate() {
150 // getStackStart is exclusive, not inclusive (i.e. it points past the last
151 // page of the stack in linear order). So, to ensure an inclusive comparison,
152 // subtract here and below.
153 s_mainThreadStackStart =
154 reinterpret_cast<uintptr_t>(getStackStart()) - sizeof(void*);
155
147 size_t underestimatedStackSize = getUnderestimatedStackSize(); 156 size_t underestimatedStackSize = getUnderestimatedStackSize();
148 // See comment in mayNotBeMainThread as to why we subtract here.
149 if (underestimatedStackSize > sizeof(void*)) { 157 if (underestimatedStackSize > sizeof(void*)) {
150 underestimatedStackSize = underestimatedStackSize - sizeof(void*); 158 underestimatedStackSize = underestimatedStackSize - sizeof(void*);
151 } 159 }
152 return underestimatedStackSize; 160 s_mainThreadUnderestimatedStackSize = underestimatedStackSize;
153 } 161 }
154 162
155 #if OS(WIN) && COMPILER(MSVC) 163 #if OS(WIN) && COMPILER(MSVC)
156 size_t threadStackSize() { 164 size_t threadStackSize() {
157 // Notice that we cannot use the TIB's StackLimit for the stack end, as i 165 // Notice that we cannot use the TIB's StackLimit for the stack end, as i
158 // tracks the end of the committed range. We're after the end of the reserved 166 // tracks the end of the committed range. We're after the end of the reserved
159 // stack area (most of which will be uncommitted, most times.) 167 // stack area (most of which will be uncommitted, most times.)
160 MEMORY_BASIC_INFORMATION stackInfo; 168 MEMORY_BASIC_INFORMATION stackInfo;
161 memset(&stackInfo, 0, sizeof(MEMORY_BASIC_INFORMATION)); 169 memset(&stackInfo, 0, sizeof(MEMORY_BASIC_INFORMATION));
162 size_t resultSize = 170 size_t resultSize =
(...skipping 17 matching lines...) Expand all
180 // explains the details. 188 // explains the details.
181 RELEASE_ASSERT(s_threadStackSize > 4 * 0x1000); 189 RELEASE_ASSERT(s_threadStackSize > 4 * 0x1000);
182 s_threadStackSize -= 4 * 0x1000; 190 s_threadStackSize -= 4 * 0x1000;
183 return s_threadStackSize; 191 return s_threadStackSize;
184 } 192 }
185 #endif 193 #endif
186 194
187 } // namespace internal 195 } // namespace internal
188 196
189 } // namespace WTF 197 } // namespace WTF
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/wtf/StackUtil.h ('k') | third_party/WebKit/Source/wtf/ThreadSpecific.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698