| 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/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 STATIC_ONLY(StackFrameDepth); | 23 DISALLOW_NEW(); |
| 24 public: | 24 public: |
| 25 inline static bool isSafeToRecurse() | 25 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() > s_stackFrameLimit; | 32 return currentStackFrame() > m_stackFrameLimit; |
| 33 } | 33 } |
| 34 | 34 |
| 35 static void enableStackLimit(); | 35 void enableStackLimit(); |
| 36 static void disableStackLimit() | 36 void disableStackLimit() |
| 37 { | 37 { |
| 38 s_stackFrameLimit = kMinimumStackLimit; | 38 m_stackFrameLimit = kMinimumStackLimit; |
| 39 } | 39 } |
| 40 | 40 |
| 41 #if ENABLE(ASSERT) | 41 bool isEnabled() { return m_stackFrameLimit != kMinimumStackLimit; } |
| 42 inline static bool isEnabled() { return s_stackFrameLimit != kMinimumStackLi
mit; } | 42 bool isAcceptableStackUse() |
| 43 inline static bool isAcceptableStackUse() | |
| 44 { | 43 { |
| 45 #if defined(ADDRESS_SANITIZER) | 44 #if defined(ADDRESS_SANITIZER) |
| 46 // ASan adds extra stack usage leading to too noisy asserts. | 45 // ASan adds extra stack usage leading to too noisy asserts. |
| 47 return true; | 46 return true; |
| 48 #else | 47 #else |
| 49 return !isEnabled() || isSafeToRecurse(); | 48 return !isEnabled() || isSafeToRecurse(); |
| 50 #endif | 49 #endif |
| 51 } | 50 } |
| 52 #endif | |
| 53 | 51 |
| 54 static size_t getUnderestimatedStackSize(); | 52 static size_t getUnderestimatedStackSize(); |
| 55 static void* getStackStart(); | 53 static void* getStackStart(); |
| 56 | 54 |
| 57 #if COMPILER(MSVC) | 55 #if COMPILER(MSVC) |
| 58 // Ignore C4172: returning address of local variable or temporary: dummy. This | 56 // Ignore C4172: returning address of local variable or temporary: dummy. This |
| 59 // warning suppression has to go outside of the function to take effect. | 57 // warning suppression has to go outside of the function to take effect. |
| 60 #pragma warning(push) | 58 #pragma warning(push) |
| 61 #pragma warning(disable: 4172) | 59 #pragma warning(disable: 4172) |
| 62 #endif | 60 #endif |
| (...skipping 19 matching lines...) Expand all Loading... |
| 82 static const int kSafeStackFrameSize = 32 * 1024; | 80 static const int kSafeStackFrameSize = 32 * 1024; |
| 83 | 81 |
| 84 // The stack pointer is assumed to grow towards lower addresses; | 82 // The stack pointer is assumed to grow towards lower addresses; |
| 85 // |kMinimumStackLimit| then being the limit that a stack | 83 // |kMinimumStackLimit| then being the limit that a stack |
| 86 // pointer will always exceed. | 84 // pointer will always exceed. |
| 87 static const uintptr_t kMinimumStackLimit = ~0ul; | 85 static const uintptr_t kMinimumStackLimit = ~0ul; |
| 88 | 86 |
| 89 static uintptr_t getFallbackStackLimit(); | 87 static uintptr_t getFallbackStackLimit(); |
| 90 | 88 |
| 91 // The (pointer-valued) stack limit. | 89 // The (pointer-valued) stack limit. |
| 92 static uintptr_t s_stackFrameLimit; | 90 uintptr_t m_stackFrameLimit; |
| 93 }; | 91 }; |
| 94 | 92 |
| 95 class StackFrameDepthScope { | 93 class StackFrameDepthScope { |
| 96 STACK_ALLOCATED(); | 94 STACK_ALLOCATED(); |
| 97 WTF_MAKE_NONCOPYABLE(StackFrameDepthScope); | 95 WTF_MAKE_NONCOPYABLE(StackFrameDepthScope); |
| 98 public: | 96 public: |
| 99 StackFrameDepthScope() | 97 explicit StackFrameDepthScope(StackFrameDepth* depth): m_depth(depth) |
| 100 { | 98 { |
| 101 StackFrameDepth::enableStackLimit(); | 99 m_depth->enableStackLimit(); |
| 102 // Enabled unless under stack pressure. | 100 // Enabled unless under stack pressure. |
| 103 ASSERT(StackFrameDepth::isSafeToRecurse() || !StackFrameDepth::isEnabled
()); | 101 DCHECK(m_depth->isSafeToRecurse() || !m_depth->isEnabled()); |
| 104 } | 102 } |
| 105 | 103 |
| 106 ~StackFrameDepthScope() | 104 ~StackFrameDepthScope() |
| 107 { | 105 { |
| 108 StackFrameDepth::disableStackLimit(); | 106 m_depth->disableStackLimit(); |
| 109 } | 107 } |
| 108 |
| 109 private: |
| 110 StackFrameDepth* m_depth; |
| 110 }; | 111 }; |
| 111 | 112 |
| 112 } // namespace blink | 113 } // namespace blink |
| 113 | 114 |
| 114 #endif // StackFrameDepth_h | 115 #endif // StackFrameDepth_h |
| OLD | NEW |