OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef StackFrameDepth_h | |
6 #define StackFrameDepth_h | |
7 | |
8 #include "platform/PlatformExport.h" | |
9 #include "wtf/Assertions.h" | |
10 #include <stdint.h> | |
11 | |
12 namespace blink { | |
13 | |
14 // StackFrameDepth keeps track of current call stack frame depth. | |
15 // Use isSafeToRecurse() to query if there is a room in current | |
16 // call stack for more recursive call. | |
17 class PLATFORM_EXPORT StackFrameDepth final { | |
18 public: | |
19 inline bool isSafeToRecurse() | |
20 { | |
21 ASSERT(m_safeStackFrame); | |
22 | |
23 // Below comparison assumes callstack to glow downward, | |
24 // which is true for all ABI Blink currently supports. | |
25 return estimateCurrentStackFrame() > m_safeStackFrame; | |
26 } | |
27 | |
28 static uintptr_t estimateCurrentStackFrame(const char* dummy = nullptr) | |
haraken
2015/01/08 01:14:23
estimateCurrentStackFrame => currentStackFrame
kouhei (in TOK)
2015/01/08 03:29:54
Done.
| |
29 { | |
30 #if COMPILER(GCC) | |
31 return reinterpret_cast<uintptr_t>(__builtin_frame_address(0)); | |
32 #elif COMPILER(MSVC) | |
33 return reinterpret_cast<uintptr_t>(&dummy) - sizeof(void*); | |
34 #else | |
35 #error "Stack frame pointer estimation not supported on this platform." | |
36 return 0; | |
37 #endif | |
38 } | |
39 | |
40 void configureLimit(); | |
41 | |
42 private: | |
43 // The maximum depth of eager, unrolled trace() calls that is | |
44 // considered safe and allowed. | |
45 static const int kMaxDepth = 400; | |
haraken
2015/01/08 01:14:23
Keep the number to 100 in this CL. You can increas
kouhei (in TOK)
2015/01/08 03:29:54
Changed this to kSafeStackFrameSize for clarity.
| |
46 | |
47 uintptr_t m_safeStackFrame; | |
haraken
2015/01/08 01:14:23
m_safeStackFrame => m_stackFrameLimit (for consist
kouhei (in TOK)
2015/01/08 03:29:54
Done.
| |
48 }; | |
49 | |
50 } // namespace blink | |
51 | |
52 #endif | |
haraken
2015/01/08 01:14:23
Add // StackFrameDepth_h
kouhei (in TOK)
2015/01/08 03:29:54
Done.
| |
OLD | NEW |