| 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 bool isSafeToRecurse() | 19 inline bool isSafeToRecurse() |
| 20 { | 20 { |
| 21 ASSERT(m_stackFrameLimit); | 21 ASSERT(m_stackFrameLimit); |
| 22 | 22 |
| 23 // Below comparison assumes callstack to glow downward, | 23 // Asssume that the stack grows towards lower addresses, which |
| 24 // which is true for all ABI Blink currently supports. | 24 // all the ABIs currently supported do. |
| 25 // |
| 26 // A unit test checks that the assumption holds for a target |
| 27 // (HeapTest.StackGrowthDirection.) |
| 25 return currentStackFrame() > m_stackFrameLimit; | 28 return currentStackFrame() > m_stackFrameLimit; |
| 26 } | 29 } |
| 27 | 30 |
| 28 static uintptr_t currentStackFrame(const char* dummy = nullptr) | 31 static uintptr_t currentStackFrame(const char* dummy = nullptr) |
| 29 { | 32 { |
| 30 #if COMPILER(GCC) | 33 #if COMPILER(GCC) |
| 31 return reinterpret_cast<uintptr_t>(__builtin_frame_address(0)); | 34 return reinterpret_cast<uintptr_t>(__builtin_frame_address(0)); |
| 32 #elif COMPILER(MSVC) | 35 #elif COMPILER(MSVC) |
| 33 return reinterpret_cast<uintptr_t>(&dummy) - sizeof(void*); | 36 return reinterpret_cast<uintptr_t>(&dummy) - sizeof(void*); |
| 34 #else | 37 #else |
| 35 #error "Stack frame pointer estimation not supported on this platform." | 38 #error "Stack frame pointer estimation not supported on this platform." |
| 36 return 0; | 39 return 0; |
| 37 #endif | 40 #endif |
| 38 } | 41 } |
| 39 | 42 |
| 40 void configureLimit(); | 43 void configureLimit(); |
| 41 | 44 |
| 42 private: | 45 private: |
| 43 // The maximum depth of eager, unrolled trace() calls that is | 46 // The maximum depth of eager, unrolled trace() calls that is |
| 44 // considered safe and allowed. | 47 // considered safe and allowed. |
| 45 static const int kSafeStackFrameSize = 32 * 1024; | 48 static const int kSafeStackFrameSize = 32 * 1024; |
| 46 | 49 |
| 47 uintptr_t m_stackFrameLimit; | 50 uintptr_t m_stackFrameLimit; |
| 48 }; | 51 }; |
| 49 | 52 |
| 50 } // namespace blink | 53 } // namespace blink |
| 51 | 54 |
| 52 #endif // StackFrameDepth_h | 55 #endif // StackFrameDepth_h |
| OLD | NEW |