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

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

Issue 1673543002: Split out fallback stack limit determination. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comment improvements 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
« no previous file with comments | « third_party/WebKit/Source/platform/heap/StackFrameDepth.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/StackFrameDepth.h" 5 #include "platform/heap/StackFrameDepth.h"
6 6
7 #include "public/platform/Platform.h" 7 #include "public/platform/Platform.h"
8 8
9 #if OS(WIN) 9 #if OS(WIN)
10 #include <stddef.h> 10 #include <stddef.h>
(...skipping 14 matching lines...) Expand all
25 #endif 25 #endif
26 26
27 // NEVER_INLINE ensures that |dummy| array on configureLimit() is not optimized away, 27 // NEVER_INLINE ensures that |dummy| array on configureLimit() is not optimized away,
28 // and the stack frame base register is adjusted |kSafeStackFrameSize|. 28 // and the stack frame base register is adjusted |kSafeStackFrameSize|.
29 NEVER_INLINE static uintptr_t currentStackFrameBaseOnCallee(const char* dummy) 29 NEVER_INLINE static uintptr_t currentStackFrameBaseOnCallee(const char* dummy)
30 { 30 {
31 s_avoidOptimization = dummy; 31 s_avoidOptimization = dummy;
32 return StackFrameDepth::currentStackFrame(); 32 return StackFrameDepth::currentStackFrame();
33 } 33 }
34 34
35 uintptr_t StackFrameDepth::getFallbackStackLimit()
36 {
37 // Allocate an |kSafeStackFrameSize|-sized object on stack and query
38 // stack frame base after it.
39 char dummy[kSafeStackFrameSize];
40
41 // Check that the stack frame can be used.
42 dummy[sizeof(dummy) - 1] = 0;
43 #if ENABLE(ASSERT)
44 // Use a larger stack limit for what's acceptable if the platform
45 // thread ends up using the fallback size to decide if switching to
46 // lazy marking is in order.
47 s_isUsingFallbackStackSize = true;
48 #endif
49 return currentStackFrameBaseOnCallee(dummy);
50 }
51
35 void StackFrameDepth::enableStackLimit() 52 void StackFrameDepth::enableStackLimit()
36 { 53 {
37 #if ENABLE(ASSERT) 54 #if ENABLE(ASSERT)
38 s_isEnabled = true; 55 s_isEnabled = true;
39 s_isUsingFallbackStackSize = false; 56 s_isUsingFallbackStackSize = false;
40 #endif 57 #endif
41 58
42 static const int kStackRoomSize = 1024; 59 // Windows and OSX platforms will always return a non-zero estimate.
43
44 size_t stackSize = getUnderestimatedStackSize(); 60 size_t stackSize = getUnderestimatedStackSize();
45 if (stackSize) { 61 if (!stackSize) {
46 Address stackBase = reinterpret_cast<Address>(getStackStart()); 62 s_stackFrameLimit = getFallbackStackLimit();
47 RELEASE_ASSERT(stackSize > static_cast<const size_t>(kStackRoomSize));
48 size_t stackRoom = stackSize - kStackRoomSize;
49 RELEASE_ASSERT(stackBase > reinterpret_cast<Address>(stackRoom));
50 s_stackFrameLimit = reinterpret_cast<uintptr_t>(stackBase - stackRoom);
51 return; 63 return;
52 } 64 }
53 65
54 // Fallback version 66 static const int kStackRoomSize = 1024;
55 // Allocate a 32KB object on stack and query stack frame base after it.
56 char dummy[kSafeStackFrameSize];
57 s_stackFrameLimit = currentStackFrameBaseOnCallee(dummy);
58 67
59 // Assert that the stack frame can be used. 68 Address stackBase = reinterpret_cast<Address>(getStackStart());
60 dummy[sizeof(dummy) - 1] = 0; 69 RELEASE_ASSERT(stackSize > static_cast<const size_t>(kStackRoomSize));
61 #if ENABLE(ASSERT) 70 size_t stackRoom = stackSize - kStackRoomSize;
62 // Use a larger stack limit for what's acceptable if the platform 71 RELEASE_ASSERT(stackBase > reinterpret_cast<Address>(stackRoom));
63 // thread ends up using the fallback size to decide if switching to 72 s_stackFrameLimit = reinterpret_cast<uintptr_t>(stackBase - stackRoom);
64 // lazy marking is in order.
65 s_isUsingFallbackStackSize = true;
66 #endif
67 } 73 }
68 74
69 size_t StackFrameDepth::getUnderestimatedStackSize() 75 size_t StackFrameDepth::getUnderestimatedStackSize()
70 { 76 {
71 // FIXME: ASAN bot uses a fake stack as a thread stack frame, 77 // FIXME: ASAN bot uses a fake stack as a thread stack frame,
72 // and its size is different from the value which APIs tells us. 78 // and its size is different from the value which APIs tells us.
73 #if defined(ADDRESS_SANITIZER) 79 #if defined(ADDRESS_SANITIZER)
74 return 0; 80 return 0;
75 #endif 81 #endif
76 82
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 return reinterpret_cast<void*>(__readgsqword(offsetof(NT_TIB64, StackBase))) ; 180 return reinterpret_cast<void*>(__readgsqword(offsetof(NT_TIB64, StackBase))) ;
175 #else 181 #else
176 return reinterpret_cast<void*>(__readfsdword(offsetof(NT_TIB, StackBase))); 182 return reinterpret_cast<void*>(__readfsdword(offsetof(NT_TIB, StackBase)));
177 #endif 183 #endif
178 #else 184 #else
179 #error Unsupported getStackStart on this platform. 185 #error Unsupported getStackStart on this platform.
180 #endif 186 #endif
181 } 187 }
182 188
183 } // namespace blink 189 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/heap/StackFrameDepth.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698