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

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

Issue 1779243002: Simplify StackFrameDepth's handling of stack limits. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix (un)signed mismatch Created 4 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/platform/heap/StackFrameDepth.cpp » ('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 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 #ifndef StackFrameDepth_h 5 #ifndef StackFrameDepth_h
6 #define StackFrameDepth_h 6 #define StackFrameDepth_h
7 7
8 #include "platform/PlatformExport.h" 8 #include "platform/PlatformExport.h"
9 #include "wtf/Allocator.h" 9 #include "wtf/Allocator.h"
10 #include "wtf/Assertions.h" 10 #include "wtf/Assertions.h"
11 #include <cstddef> 11 #include <cstddef>
12 #include <stdint.h> 12 #include <stdint.h>
13 13
14 namespace blink { 14 namespace blink {
15 15
16 // StackFrameDepth keeps track of current call stack frame depth. 16 // StackFrameDepth keeps track of current call stack frame depth.
17 // Use isSafeToRecurse() to query if there is a room in current 17 // It is specifically used to control stack usage while tracing
18 // call stack for more recursive call. 18 // the object graph during a GC.
19 //
20 // Use isSafeToRecurse() to determine if it is safe to consume
21 // more stack by invoking another recursive call.
19 class PLATFORM_EXPORT StackFrameDepth final { 22 class PLATFORM_EXPORT StackFrameDepth final {
20 STATIC_ONLY(StackFrameDepth); 23 STATIC_ONLY(StackFrameDepth);
21 public: 24 public:
22 inline static bool isSafeToRecurse() 25 inline static bool isSafeToRecurse()
23 { 26 {
24 ASSERT(s_stackFrameLimit || !s_isEnabled);
25
26 // Asssume that the stack grows towards lower addresses, which 27 // Asssume that the stack grows towards lower addresses, which
27 // all the ABIs currently supported do. 28 // all the ABIs currently supported do.
28 // 29 //
29 // A unit test checks that the assumption holds for a target 30 // A unit test checks that the assumption holds for a target
30 // (HeapTest.StackGrowthDirection.) 31 // (HeapTest.StackGrowthDirection.)
31 return currentStackFrame() > s_stackFrameLimit; 32 return currentStackFrame() > s_stackFrameLimit;
32 } 33 }
33 34
34 static void enableStackLimit(); 35 static void enableStackLimit();
35 static void disableStackLimit() 36 static void disableStackLimit()
36 { 37 {
37 s_stackFrameLimit = 0; 38 s_stackFrameLimit = kMinimumStackLimit;
38 #if ENABLE(ASSERT)
39 s_isEnabled = false;
40 #endif
41 } 39 }
42 40
43 #if ENABLE(ASSERT) 41 #if ENABLE(ASSERT)
44 inline static bool isEnabled() { return s_isEnabled; } 42 inline static bool isEnabled() { return s_stackFrameLimit != kMinimumStackLi mit; }
45 inline static bool isAcceptableStackUse() 43 inline static bool isAcceptableStackUse()
46 { 44 {
45 #if defined(ADDRESS_SANITIZER)
47 // ASan adds extra stack usage leading to too noisy asserts. 46 // ASan adds extra stack usage leading to too noisy asserts.
48 #if defined(ADDRESS_SANITIZER)
49 return true; 47 return true;
50 #else 48 #else
51 // If a conservative fallback stack size is in effect, use 49 return !isEnabled() || isSafeToRecurse();
52 // a larger stack limit so as to avoid false positives.
53 if (!s_isEnabled || isSafeToRecurse())
54 return true;
55 if (s_isUsingFallbackStackSize)
56 return (s_stackFrameLimit - currentStackFrame()) < 3 * kSafeStackFra meSize;
57 return false;
58 #endif 50 #endif
59 } 51 }
60 #endif 52 #endif
61 53
62 static size_t getUnderestimatedStackSize(); 54 static size_t getUnderestimatedStackSize();
63 static void* getStackStart(); 55 static void* getStackStart();
64 56
65 #if COMPILER(MSVC) 57 #if COMPILER(MSVC)
66 // Ignore C4172: returning address of local variable or temporary: dummy. This 58 // Ignore C4172: returning address of local variable or temporary: dummy. This
67 // warning suppression has to go outside of the function to take effect. 59 // warning suppression has to go outside of the function to take effect.
(...skipping 10 matching lines...) Expand all
78 #error "Stack frame pointer estimation not supported on this platform." 70 #error "Stack frame pointer estimation not supported on this platform."
79 return 0; 71 return 0;
80 #endif 72 #endif
81 } 73 }
82 #if COMPILER(MSVC) 74 #if COMPILER(MSVC)
83 #pragma warning(pop) 75 #pragma warning(pop)
84 #endif 76 #endif
85 77
86 private: 78 private:
87 // The maximum depth of eager, unrolled trace() calls that is 79 // The maximum depth of eager, unrolled trace() calls that is
88 // considered safe and allowed. 80 // considered safe and allowed for targets with an unknown
81 // thread stack size.
89 static const int kSafeStackFrameSize = 32 * 1024; 82 static const int kSafeStackFrameSize = 32 * 1024;
90 83
84 // The stack pointer is assumed to grow towards lower addresses;
85 // |kMinimumStackLimit| then being the limit that a stack
86 // pointer will always exceed.
87 static const uintptr_t kMinimumStackLimit = ~0ul;
88
91 static uintptr_t getFallbackStackLimit(); 89 static uintptr_t getFallbackStackLimit();
92 90
91 // The (pointer-valued) stack limit.
93 static uintptr_t s_stackFrameLimit; 92 static uintptr_t s_stackFrameLimit;
94 #if ENABLE(ASSERT)
95 static bool s_isEnabled;
96 static bool s_isUsingFallbackStackSize;
97 #endif
98 }; 93 };
99 94
100 class StackFrameDepthScope { 95 class StackFrameDepthScope {
101 STACK_ALLOCATED(); 96 STACK_ALLOCATED();
102 WTF_MAKE_NONCOPYABLE(StackFrameDepthScope); 97 WTF_MAKE_NONCOPYABLE(StackFrameDepthScope);
103 public: 98 public:
104 StackFrameDepthScope() 99 StackFrameDepthScope()
105 { 100 {
106 StackFrameDepth::enableStackLimit(); 101 StackFrameDepth::enableStackLimit();
107 // Enabled unless under stack pressure. 102 // Enabled unless under stack pressure.
108 ASSERT(StackFrameDepth::isSafeToRecurse() || !StackFrameDepth::isEnabled ()); 103 ASSERT(StackFrameDepth::isSafeToRecurse() || !StackFrameDepth::isEnabled ());
109 } 104 }
110 105
111 ~StackFrameDepthScope() 106 ~StackFrameDepthScope()
112 { 107 {
113 StackFrameDepth::disableStackLimit(); 108 StackFrameDepth::disableStackLimit();
114 } 109 }
115 }; 110 };
116 111
117 } // namespace blink 112 } // namespace blink
118 113
119 #endif // StackFrameDepth_h 114 #endif // StackFrameDepth_h
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/platform/heap/StackFrameDepth.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698