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

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

Issue 910663002: [Oilpan] Set stack limit using estimated sizes (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fallback if stach size is not estimated Created 5 years, 10 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
« no previous file with comments | « Source/platform/heap/StackFrameDepth.h ('k') | no next file » | 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 #include "config.h" 5 #include "config.h"
6 #include "platform/heap/StackFrameDepth.h" 6 #include "platform/heap/StackFrameDepth.h"
7 7
8 #include "public/platform/Platform.h" 8 #include "public/platform/Platform.h"
9 9
10 #if OS(WIN) 10 #if OS(WIN)
11 #include <stddef.h> 11 #include <stddef.h>
12 #include <windows.h> 12 #include <windows.h>
13 #include <winnt.h> 13 #include <winnt.h>
14 #elif defined(__GLIBC__) 14 #elif defined(__GLIBC__)
15 extern "C" void* __libc_stack_end; // NOLINT 15 extern "C" void* __libc_stack_end; // NOLINT
16 #endif 16 #endif
17 17
18 namespace blink { 18 namespace blink {
19 19
20 const int StackFrameDepth::kStackRoomSize = 1024;
20 static const char* s_avoidOptimization = nullptr; 21 static const char* s_avoidOptimization = nullptr;
21 22
22 // NEVER_INLINE ensures that |dummy| array on configureLimit() is not optimized away, 23 // NEVER_INLINE ensures that |dummy| array on configureLimit() is not optimized away,
23 // and the stack frame base register is adjusted |kSafeStackFrameSize|. 24 // and the stack frame base register is adjusted |kSafeStackFrameSize|.
24 NEVER_INLINE static uintptr_t currentStackFrameBaseOnCallee(const char* dummy) 25 NEVER_INLINE static uintptr_t currentStackFrameBaseOnCallee(const char* dummy)
25 { 26 {
26 s_avoidOptimization = dummy; 27 s_avoidOptimization = dummy;
27 return StackFrameDepth::currentStackFrame(); 28 return StackFrameDepth::currentStackFrame();
28 } 29 }
29 30
30 void StackFrameDepth::configureLimit() 31 void StackFrameDepth::configureLimit()
haraken 2015/02/10 08:53:22 Can we avoid calling getUnderestimatedStackSize()
peria 2015/02/10 12:05:29 The instance of StackFrameDepth is globally unique
31 { 32 {
33 size_t stackSize = getUnderestimatedStackSize();
haraken 2015/02/10 08:53:22 Note: You can add RELEASE_ASSERT(stackSize >= 128
peria 2015/02/10 12:05:28 Acknowledged.
haraken 2015/02/10 12:15:09 Would you try this before landing this CL? We migh
peria 2015/02/12 02:31:58 Trying in https://codereview.chromium.org/91888300
34 if (stackSize) {
35 m_stackFrameLimit = reinterpret_cast<uintptr_t>(getStackStart()) - stack Size + kStackRoomSize;
36 return;
37 }
38
39 // Fallback version
32 // Allocate a large object in stack and query stack frame pointer after it. 40 // Allocate a large object in stack and query stack frame pointer after it.
33 char dummy[kSafeStackFrameSize]; 41 char dummy[kSafeStackFrameSize];
34 m_stackFrameLimit = currentStackFrameBaseOnCallee(dummy); 42 m_stackFrameLimit = currentStackFrameBaseOnCallee(dummy);
35 43
36 // Assert that the stack frame can be used. 44 // Assert that the stack frame can be used.
37 dummy[sizeof(dummy) - 1] = 0; 45 dummy[sizeof(dummy) - 1] = 0;
38 } 46 }
39 47
40 size_t StackFrameDepth::getUnderestimatedStackSize() 48 size_t StackFrameDepth::getUnderestimatedStackSize()
41 { 49 {
42 #if defined(__GLIBC__) || OS(ANDROID) || OS(FREEBSD) 50 #if defined(__GLIBC__) || OS(ANDROID) || OS(FREEBSD)
43 // We cannot get the stack size in these platforms because 51 pthread_attr_t attr;
44 // pthread_getattr_np() can fail for the main thread. 52 int error;
45 // This is OK because ThreadState::current() doesn't use the stack size 53 #if OS(FREEBSD)
46 // in these platforms. 54 pthread_attr_init(&attr);
haraken 2015/02/10 08:53:22 Update this comment instead of removing.
peria 2015/02/10 12:05:28 Done.
55 error = pthread_attr_get_np(pthread_self(), &attr);
56 #else
57 error = pthread_getattr_np(pthread_self(), &attr);
58 #endif
59 if (!error) {
60 void* base;
61 size_t size;
62 error = pthread_attr_getstack(&attr, &base, &size);
63 RELEASE_ASSERT(!error);
64 pthread_attr_destroy(&attr);
65 return size;
66 }
67 #if OS(FREEBSD)
68 pthread_attr_destroy(&attr);
69 #endif
70
47 return 0; 71 return 0;
48 #elif OS(MACOSX) 72 #elif OS(MACOSX)
49 return pthread_get_stacksize_np(pthread_self()); 73 return pthread_get_stacksize_np(pthread_self());
50 #elif OS(WIN) && COMPILER(MSVC) 74 #elif OS(WIN) && COMPILER(MSVC)
51 // On Windows stack limits for the current thread are available in 75 // On Windows stack limits for the current thread are available in
52 // the thread information block (TIB). Its fields can be accessed through 76 // the thread information block (TIB). Its fields can be accessed through
53 // FS segment register on x86 and GS segment register on x86_64. 77 // FS segment register on x86 and GS segment register on x86_64.
54 #ifdef _WIN64 78 #ifdef _WIN64
55 return __readgsqword(offsetof(NT_TIB64, StackBase)) - __readgsqword(offsetof (NT_TIB64, StackLimit)); 79 return __readgsqword(offsetof(NT_TIB64, StackBase)) - __readgsqword(offsetof (NT_TIB64, StackLimit));
56 #else 80 #else
57 return __readfsdword(offsetof(NT_TIB, StackBase)) - __readfsdword(offsetof(N T_TIB, StackLimit)); 81 return __readfsdword(offsetof(NT_TIB, StackBase)) - __readfsdword(offsetof(N T_TIB, StackLimit));
58 #endif 82 #endif
59 #else 83 #else
84 #error "Stack frame size estimation not supported on this platform."
60 return 0; 85 return 0;
61 #endif 86 #endif
62 } 87 }
63 88
64 void* StackFrameDepth::getStackStart() 89 void* StackFrameDepth::getStackStart()
65 { 90 {
66 #if defined(__GLIBC__) || OS(ANDROID) || OS(FREEBSD) 91 #if defined(__GLIBC__) || OS(ANDROID) || OS(FREEBSD)
67 pthread_attr_t attr; 92 pthread_attr_t attr;
68 int error; 93 int error;
69 #if OS(FREEBSD) 94 #if OS(FREEBSD)
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 return reinterpret_cast<void*>(__readgsqword(offsetof(NT_TIB64, StackBase))) ; 128 return reinterpret_cast<void*>(__readgsqword(offsetof(NT_TIB64, StackBase))) ;
104 #else 129 #else
105 return reinterpret_cast<void*>(__readfsdword(offsetof(NT_TIB, StackBase))); 130 return reinterpret_cast<void*>(__readfsdword(offsetof(NT_TIB, StackBase)));
106 #endif 131 #endif
107 #else 132 #else
108 #error Unsupported getStackStart on this platform. 133 #error Unsupported getStackStart on this platform.
109 #endif 134 #endif
110 } 135 }
111 136
112 } // namespace blink 137 } // namespace blink
OLDNEW
« no previous file with comments | « Source/platform/heap/StackFrameDepth.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698