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

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

Issue 2326523004: Revert of 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 {
23 DISALLOW_NEW(); 23 STATIC_ONLY(StackFrameDepth);
24 public: 24 public:
25 bool isSafeToRecurse() 25 inline static bool isSafeToRecurse()
26 { 26 {
27 // Asssume that the stack grows towards lower addresses, which 27 // Asssume that the stack grows towards lower addresses, which
28 // all the ABIs currently supported do. 28 // all the ABIs currently supported do.
29 // 29 //
30 // A unit test checks that the assumption holds for a target 30 // A unit test checks that the assumption holds for a target
31 // (HeapTest.StackGrowthDirection.) 31 // (HeapTest.StackGrowthDirection.)
32 return currentStackFrame() > m_stackFrameLimit; 32 return currentStackFrame() > s_stackFrameLimit;
33 } 33 }
34 34
35 void enableStackLimit(); 35 static void enableStackLimit();
36 void disableStackLimit() 36 static void disableStackLimit()
37 { 37 {
38 m_stackFrameLimit = kMinimumStackLimit; 38 s_stackFrameLimit = kMinimumStackLimit;
39 } 39 }
40 40
41 bool isEnabled() { return m_stackFrameLimit != kMinimumStackLimit; } 41 #if ENABLE(ASSERT)
42 bool isAcceptableStackUse() 42 inline static bool isEnabled() { return s_stackFrameLimit != kMinimumStackLi mit; }
43 inline static bool isAcceptableStackUse()
43 { 44 {
44 #if defined(ADDRESS_SANITIZER) 45 #if defined(ADDRESS_SANITIZER)
45 // ASan adds extra stack usage leading to too noisy asserts. 46 // ASan adds extra stack usage leading to too noisy asserts.
46 return true; 47 return true;
47 #else 48 #else
48 return !isEnabled() || isSafeToRecurse(); 49 return !isEnabled() || isSafeToRecurse();
49 #endif 50 #endif
50 } 51 }
52 #endif
51 53
52 static size_t getUnderestimatedStackSize(); 54 static size_t getUnderestimatedStackSize();
53 static void* getStackStart(); 55 static void* getStackStart();
54 56
55 #if COMPILER(MSVC) 57 #if COMPILER(MSVC)
56 // Ignore C4172: returning address of local variable or temporary: dummy. This 58 // Ignore C4172: returning address of local variable or temporary: dummy. This
57 // 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.
58 #pragma warning(push) 60 #pragma warning(push)
59 #pragma warning(disable: 4172) 61 #pragma warning(disable: 4172)
60 #endif 62 #endif
(...skipping 19 matching lines...) Expand all
80 static const int kSafeStackFrameSize = 32 * 1024; 82 static const int kSafeStackFrameSize = 32 * 1024;
81 83
82 // The stack pointer is assumed to grow towards lower addresses; 84 // The stack pointer is assumed to grow towards lower addresses;
83 // |kMinimumStackLimit| then being the limit that a stack 85 // |kMinimumStackLimit| then being the limit that a stack
84 // pointer will always exceed. 86 // pointer will always exceed.
85 static const uintptr_t kMinimumStackLimit = ~0ul; 87 static const uintptr_t kMinimumStackLimit = ~0ul;
86 88
87 static uintptr_t getFallbackStackLimit(); 89 static uintptr_t getFallbackStackLimit();
88 90
89 // The (pointer-valued) stack limit. 91 // The (pointer-valued) stack limit.
90 uintptr_t m_stackFrameLimit; 92 static uintptr_t s_stackFrameLimit;
91 }; 93 };
92 94
93 class StackFrameDepthScope { 95 class StackFrameDepthScope {
94 STACK_ALLOCATED(); 96 STACK_ALLOCATED();
95 WTF_MAKE_NONCOPYABLE(StackFrameDepthScope); 97 WTF_MAKE_NONCOPYABLE(StackFrameDepthScope);
96 public: 98 public:
97 explicit StackFrameDepthScope(StackFrameDepth* depth): m_depth(depth) 99 StackFrameDepthScope()
98 { 100 {
99 m_depth->enableStackLimit(); 101 StackFrameDepth::enableStackLimit();
100 // Enabled unless under stack pressure. 102 // Enabled unless under stack pressure.
101 DCHECK(m_depth->isSafeToRecurse() || !m_depth->isEnabled()); 103 ASSERT(StackFrameDepth::isSafeToRecurse() || !StackFrameDepth::isEnabled ());
102 } 104 }
103 105
104 ~StackFrameDepthScope() 106 ~StackFrameDepthScope()
105 { 107 {
106 m_depth->disableStackLimit(); 108 StackFrameDepth::disableStackLimit();
107 } 109 }
108
109 private:
110 StackFrameDepth* m_depth;
111 }; 110 };
112 111
113 } // namespace blink 112 } // namespace blink
114 113
115 #endif // StackFrameDepth_h 114 #endif // StackFrameDepth_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/heap/HeapTest.cpp ('k') | third_party/WebKit/Source/platform/heap/StackFrameDepth.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698