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

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: rebased 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 // Fallback version.
38 // Allocate a 32KB object on stack and query stack frame base after it.
haraken 2016/02/05 09:05:57 If we take this approach, I think we can increase
sof 2016/02/05 09:13:01 On Windows this method will never be executed, so
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;
43
44 size_t stackSize = getUnderestimatedStackSize(); 59 size_t stackSize = getUnderestimatedStackSize();
45 if (stackSize) { 60 if (!stackSize) {
haraken 2016/02/05 09:19:02 It would be worth having a comment and mention on
sof 2016/02/05 10:09:34 Yes, added. Having a non-zero default estimate fo
46 Address stackBase = reinterpret_cast<Address>(getStackStart()); 61 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; 62 return;
52 } 63 }
53 64
54 // Fallback version 65 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 66
59 // Assert that the stack frame can be used. 67 Address stackBase = reinterpret_cast<Address>(getStackStart());
60 dummy[sizeof(dummy) - 1] = 0; 68 RELEASE_ASSERT(stackSize > static_cast<const size_t>(kStackRoomSize));
61 #if ENABLE(ASSERT) 69 size_t stackRoom = stackSize - kStackRoomSize;
62 // Use a larger stack limit for what's acceptable if the platform 70 RELEASE_ASSERT(stackBase > reinterpret_cast<Address>(stackRoom));
63 // thread ends up using the fallback size to decide if switching to 71 s_stackFrameLimit = reinterpret_cast<uintptr_t>(stackBase - stackRoom);
64 // lazy marking is in order.
65 s_isUsingFallbackStackSize = true;
66 #endif
67 } 72 }
68 73
69 size_t StackFrameDepth::getUnderestimatedStackSize() 74 size_t StackFrameDepth::getUnderestimatedStackSize()
70 { 75 {
71 // FIXME: ASAN bot uses a fake stack as a thread stack frame, 76 // 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. 77 // and its size is different from the value which APIs tells us.
73 #if defined(ADDRESS_SANITIZER) 78 #if defined(ADDRESS_SANITIZER)
74 return 0; 79 return 0;
75 #endif 80 #endif
76 81
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 return reinterpret_cast<void*>(__readgsqword(offsetof(NT_TIB64, StackBase))) ; 179 return reinterpret_cast<void*>(__readgsqword(offsetof(NT_TIB64, StackBase))) ;
175 #else 180 #else
176 return reinterpret_cast<void*>(__readfsdword(offsetof(NT_TIB, StackBase))); 181 return reinterpret_cast<void*>(__readfsdword(offsetof(NT_TIB, StackBase)));
177 #endif 182 #endif
178 #else 183 #else
179 #error Unsupported getStackStart on this platform. 184 #error Unsupported getStackStart on this platform.
180 #endif 185 #endif
181 } 186 }
182 187
183 } // namespace blink 188 } // 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