OLD | NEW |
---|---|
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/Assertions.h" | 9 #include "wtf/Assertions.h" |
10 #include <stdint.h> | 10 #include <stdint.h> |
11 | 11 |
12 namespace blink { | 12 namespace blink { |
13 | 13 |
14 // StackFrameDepth keeps track of current call stack frame depth. | 14 // StackFrameDepth keeps track of current call stack frame depth. |
15 // Use isSafeToRecurse() to query if there is a room in current | 15 // Use isSafeToRecurse() to query if there is a room in current |
16 // call stack for more recursive call. | 16 // call stack for more recursive call. |
17 class PLATFORM_EXPORT StackFrameDepth final { | 17 class PLATFORM_EXPORT StackFrameDepth final { |
18 public: | 18 public: |
19 inline static bool isSafeToRecurse() | 19 inline static bool isSafeToRecurse() |
20 { | 20 { |
21 ASSERT(s_stackFrameLimit); | 21 ASSERT(s_stackFrameLimit || !s_isActive); |
22 | 22 |
23 // Asssume that the stack grows towards lower addresses, which | 23 // Asssume that the stack grows towards lower addresses, which |
24 // all the ABIs currently supported do. | 24 // all the ABIs currently supported do. |
25 // | 25 // |
26 // A unit test checks that the assumption holds for a target | 26 // A unit test checks that the assumption holds for a target |
27 // (HeapTest.StackGrowthDirection.) | 27 // (HeapTest.StackGrowthDirection.) |
28 return currentStackFrame() > s_stackFrameLimit; | 28 return currentStackFrame() > s_stackFrameLimit; |
29 } | 29 } |
30 static void configureStackLimit(); | 30 static void configureStackLimit(); |
31 static size_t getUnderestimatedStackSize(); | 31 static size_t getUnderestimatedStackSize(); |
32 static void* getStackStart(); | 32 static void* getStackStart(); |
33 | 33 |
34 static void clearStackLimit() | |
haraken
2015/05/04 23:11:32
configureStackLimit => enableStackLimit
clearStack
sof
2015/05/06 10:39:57
Renamed so.
| |
35 { | |
36 s_stackFrameLimit = 0; | |
37 #if ENABLE(ASSERT) | |
38 s_isActive = false; | |
39 #endif | |
40 } | |
41 | |
42 #if ENABLE(ASSERT) | |
43 inline static bool isActive() { return s_isActive; } | |
44 #endif | |
45 | |
34 #if COMPILER(MSVC) | 46 #if COMPILER(MSVC) |
35 // Ignore C4172: returning address of local variable or temporary: dummy. This | 47 // Ignore C4172: returning address of local variable or temporary: dummy. This |
36 // warning suppression has to go outside of the function to take effect. | 48 // warning suppression has to go outside of the function to take effect. |
37 #pragma warning(push) | 49 #pragma warning(push) |
38 #pragma warning(disable: 4172) | 50 #pragma warning(disable: 4172) |
39 #endif | 51 #endif |
40 static uintptr_t currentStackFrame(const char* dummy = nullptr) | 52 static uintptr_t currentStackFrame(const char* dummy = nullptr) |
41 { | 53 { |
42 #if COMPILER(GCC) | 54 #if COMPILER(GCC) |
43 return reinterpret_cast<uintptr_t>(__builtin_frame_address(0)); | 55 return reinterpret_cast<uintptr_t>(__builtin_frame_address(0)); |
44 #elif COMPILER(MSVC) | 56 #elif COMPILER(MSVC) |
45 return reinterpret_cast<uintptr_t>(&dummy) - sizeof(void*); | 57 return reinterpret_cast<uintptr_t>(&dummy) - sizeof(void*); |
46 #else | 58 #else |
47 #error "Stack frame pointer estimation not supported on this platform." | 59 #error "Stack frame pointer estimation not supported on this platform." |
48 return 0; | 60 return 0; |
49 #endif | 61 #endif |
50 } | 62 } |
51 #if COMPILER(MSVC) | 63 #if COMPILER(MSVC) |
52 #pragma warning(pop) | 64 #pragma warning(pop) |
53 #endif | 65 #endif |
54 | 66 |
55 private: | 67 private: |
56 // The maximum depth of eager, unrolled trace() calls that is | 68 // The maximum depth of eager, unrolled trace() calls that is |
57 // considered safe and allowed. | 69 // considered safe and allowed. |
58 static const int kSafeStackFrameSize = 32 * 1024; | 70 static const int kSafeStackFrameSize = 32 * 1024; |
59 | 71 |
60 static uintptr_t s_stackFrameLimit; | 72 static uintptr_t s_stackFrameLimit; |
73 #if ENABLE(ASSERT) | |
74 static bool s_isActive; | |
75 #endif | |
76 }; | |
77 | |
78 class StackFrameDepthScope { | |
haraken
2015/05/04 23:11:32
Add STACK_ALLOCATED.
sof
2015/05/06 10:39:57
Not done, that would be an unnecessary restriction
| |
79 public: | |
80 StackFrameDepthScope() | |
81 { | |
82 StackFrameDepth::configureStackLimit(); | |
83 ASSERT(StackFrameDepth::isSafeToRecurse()); | |
84 } | |
85 | |
86 ~StackFrameDepthScope() | |
87 { | |
88 StackFrameDepth::clearStackLimit(); | |
89 } | |
61 }; | 90 }; |
62 | 91 |
63 } // namespace blink | 92 } // namespace blink |
64 | 93 |
65 #endif // StackFrameDepth_h | 94 #endif // StackFrameDepth_h |
OLD | NEW |