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

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

Issue 2304023003: StackFrameDepth should be managed per ThreadHeap (Closed)
Patch Set: Created 4 years, 3 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 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 // It is specifically used to control stack usage while tracing 17 // It is specifically used to control stack usage while tracing
18 // the object graph during a GC. 18 // the object graph during a GC.
19 // 19 //
20 // Use isSafeToRecurse() to determine if it is safe to consume 20 // Use isSafeToRecurse() to determine if it is safe to consume
21 // more stack by invoking another recursive call. 21 // more stack by invoking another recursive call.
22 class PLATFORM_EXPORT StackFrameDepth final { 22 class PLATFORM_EXPORT StackFrameDepth final {
haraken 2016/09/02 09:07:57 Add DISALLOW_NEW().
23 STATIC_ONLY(StackFrameDepth);
24 public: 23 public:
25 inline static bool isSafeToRecurse() 24 bool isSafeToRecurse()
26 { 25 {
27 // Asssume that the stack grows towards lower addresses, which 26 // Asssume that the stack grows towards lower addresses, which
28 // all the ABIs currently supported do. 27 // all the ABIs currently supported do.
29 // 28 //
30 // A unit test checks that the assumption holds for a target 29 // A unit test checks that the assumption holds for a target
31 // (HeapTest.StackGrowthDirection.) 30 // (HeapTest.StackGrowthDirection.)
32 return currentStackFrame() > s_stackFrameLimit; 31 return currentStackFrame() > m_stackFrameLimit;
33 } 32 }
34 33
35 static void enableStackLimit(); 34 void enableStackLimit();
36 static void disableStackLimit() 35 void disableStackLimit()
37 { 36 {
38 s_stackFrameLimit = kMinimumStackLimit; 37 m_stackFrameLimit = kMinimumStackLimit;
39 } 38 }
40 39
41 #if ENABLE(ASSERT) 40 #if ENABLE(ASSERT)
42 inline static bool isEnabled() { return s_stackFrameLimit != kMinimumStackLi mit; } 41 bool isEnabled() { return m_stackFrameLimit != kMinimumStackLimit; }
43 inline static bool isAcceptableStackUse() 42 bool isAcceptableStackUse()
44 { 43 {
45 #if defined(ADDRESS_SANITIZER) 44 #if defined(ADDRESS_SANITIZER)
46 // ASan adds extra stack usage leading to too noisy asserts. 45 // ASan adds extra stack usage leading to too noisy asserts.
47 return true; 46 return true;
48 #else 47 #else
49 return !isEnabled() || isSafeToRecurse(); 48 return !isEnabled() || isSafeToRecurse();
50 #endif 49 #endif
51 } 50 }
52 #endif 51 #endif
53 52
(...skipping 28 matching lines...) Expand all
82 static const int kSafeStackFrameSize = 32 * 1024; 81 static const int kSafeStackFrameSize = 32 * 1024;
83 82
84 // The stack pointer is assumed to grow towards lower addresses; 83 // The stack pointer is assumed to grow towards lower addresses;
85 // |kMinimumStackLimit| then being the limit that a stack 84 // |kMinimumStackLimit| then being the limit that a stack
86 // pointer will always exceed. 85 // pointer will always exceed.
87 static const uintptr_t kMinimumStackLimit = ~0ul; 86 static const uintptr_t kMinimumStackLimit = ~0ul;
88 87
89 static uintptr_t getFallbackStackLimit(); 88 static uintptr_t getFallbackStackLimit();
90 89
91 // The (pointer-valued) stack limit. 90 // The (pointer-valued) stack limit.
92 static uintptr_t s_stackFrameLimit; 91 uintptr_t m_stackFrameLimit;
93 }; 92 };
94 93
95 class StackFrameDepthScope { 94 class StackFrameDepthScope {
haraken 2016/09/02 09:07:57 Conceptually StackFrameDepthScope should be equal
keishi 2016/09/06 12:54:22 Done.
96 STACK_ALLOCATED(); 95 STACK_ALLOCATED();
97 WTF_MAKE_NONCOPYABLE(StackFrameDepthScope); 96 WTF_MAKE_NONCOPYABLE(StackFrameDepthScope);
98 public: 97 public:
99 StackFrameDepthScope() 98 StackFrameDepthScope(StackFrameDepth* depth): m_depth(depth)
haraken 2016/09/02 09:07:57 Add explicit.
keishi 2016/09/06 12:54:22 Done.
100 { 99 {
101 StackFrameDepth::enableStackLimit(); 100 m_depth->enableStackLimit();
102 // Enabled unless under stack pressure. 101 // Enabled unless under stack pressure.
103 ASSERT(StackFrameDepth::isSafeToRecurse() || !StackFrameDepth::isEnabled ()); 102 DCHECK(m_depth->isSafeToRecurse() || !m_depth->isEnabled());
104 } 103 }
105 104
106 ~StackFrameDepthScope() 105 ~StackFrameDepthScope()
107 { 106 {
108 StackFrameDepth::disableStackLimit(); 107 m_depth->disableStackLimit();
109 } 108 }
109
110 private:
111 StackFrameDepth* m_depth;
110 }; 112 };
111 113
112 } // namespace blink 114 } // namespace blink
113 115
114 #endif // StackFrameDepth_h 116 #endif // StackFrameDepth_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698