Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(24)

Side by Side Diff: Source/platform/heap/StackFrameDepth.h

Issue 1125613002: Oilpan: handle thread-local weak tracing slightly better. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: rename some methods Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/platform/heap/HeapTest.cpp ('k') | Source/platform/heap/StackFrameDepth.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_isEnabled);
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
31 static void enableStackLimit();
32 static void disableStackLimit()
33 {
34 s_stackFrameLimit = 0;
35 #if ENABLE(ASSERT)
36 s_isEnabled = false;
37 #endif
38 }
39
40 #if ENABLE(ASSERT)
41 inline static bool isEnabled() { return s_isEnabled; }
42 #endif
43
31 static size_t getUnderestimatedStackSize(); 44 static size_t getUnderestimatedStackSize();
32 static void* getStackStart(); 45 static void* getStackStart();
33 46
34 #if COMPILER(MSVC) 47 #if COMPILER(MSVC)
35 // Ignore C4172: returning address of local variable or temporary: dummy. This 48 // Ignore C4172: returning address of local variable or temporary: dummy. This
36 // warning suppression has to go outside of the function to take effect. 49 // warning suppression has to go outside of the function to take effect.
37 #pragma warning(push) 50 #pragma warning(push)
38 #pragma warning(disable: 4172) 51 #pragma warning(disable: 4172)
39 #endif 52 #endif
40 static uintptr_t currentStackFrame(const char* dummy = nullptr) 53 static uintptr_t currentStackFrame(const char* dummy = nullptr)
(...skipping 10 matching lines...) Expand all
51 #if COMPILER(MSVC) 64 #if COMPILER(MSVC)
52 #pragma warning(pop) 65 #pragma warning(pop)
53 #endif 66 #endif
54 67
55 private: 68 private:
56 // The maximum depth of eager, unrolled trace() calls that is 69 // The maximum depth of eager, unrolled trace() calls that is
57 // considered safe and allowed. 70 // considered safe and allowed.
58 static const int kSafeStackFrameSize = 32 * 1024; 71 static const int kSafeStackFrameSize = 32 * 1024;
59 72
60 static uintptr_t s_stackFrameLimit; 73 static uintptr_t s_stackFrameLimit;
74 #if ENABLE(ASSERT)
75 static bool s_isEnabled;
76 #endif
77 };
78
79 class StackFrameDepthScope {
80 public:
81 StackFrameDepthScope()
82 {
83 StackFrameDepth::enableStackLimit();
84 ASSERT(StackFrameDepth::isSafeToRecurse());
85 }
86
87 ~StackFrameDepthScope()
88 {
89 StackFrameDepth::disableStackLimit();
90 }
61 }; 91 };
62 92
63 } // namespace blink 93 } // namespace blink
64 94
65 #endif // StackFrameDepth_h 95 #endif // StackFrameDepth_h
OLDNEW
« no previous file with comments | « Source/platform/heap/HeapTest.cpp ('k') | Source/platform/heap/StackFrameDepth.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698