Chromium Code Reviews| Index: Source/platform/heap/StackFrameDepth.h |
| diff --git a/Source/platform/heap/StackFrameDepth.h b/Source/platform/heap/StackFrameDepth.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..86191d1293b7221ebe5b9d7368e1116b6bce60ec |
| --- /dev/null |
| +++ b/Source/platform/heap/StackFrameDepth.h |
| @@ -0,0 +1,52 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef StackFrameDepth_h |
| +#define StackFrameDepth_h |
| + |
| +#include "platform/PlatformExport.h" |
| +#include "wtf/Assertions.h" |
| +#include <stdint.h> |
| + |
| +namespace blink { |
| + |
| +// StackFrameDepth keeps track of current call stack frame depth. |
| +// Use isSafeToRecurse() to query if there is a room in current |
| +// call stack for more recursive call. |
| +class PLATFORM_EXPORT StackFrameDepth final { |
| +public: |
| + inline bool isSafeToRecurse() |
| + { |
| + ASSERT(m_safeStackFrame); |
| + |
| + // Below comparison assumes callstack to glow downward, |
| + // which is true for all ABI Blink currently supports. |
| + return estimateCurrentStackFrame() > m_safeStackFrame; |
| + } |
| + |
| + 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.
|
| + { |
| +#if COMPILER(GCC) |
| + return reinterpret_cast<uintptr_t>(__builtin_frame_address(0)); |
| +#elif COMPILER(MSVC) |
| + return reinterpret_cast<uintptr_t>(&dummy) - sizeof(void*); |
| +#else |
| +#error "Stack frame pointer estimation not supported on this platform." |
| + return 0; |
| +#endif |
| + } |
| + |
| + void configureLimit(); |
| + |
| +private: |
| + // The maximum depth of eager, unrolled trace() calls that is |
| + // considered safe and allowed. |
| + 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.
|
| + |
| + 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.
|
| +}; |
| + |
| +} // namespace blink |
| + |
| +#endif |
|
haraken
2015/01/08 01:14:23
Add // StackFrameDepth_h
kouhei (in TOK)
2015/01/08 03:29:54
Done.
|