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

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

Issue 955563002: [Oilpan] Set stack limit using estimated sizes (Re-land) (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Update comments 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 | « no previous file | Source/platform/heap/ThreadState.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 #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)
(...skipping 11 matching lines...) Expand all
22 // NEVER_INLINE ensures that |dummy| array on configureLimit() is not optimized away, 22 // NEVER_INLINE ensures that |dummy| array on configureLimit() is not optimized away,
23 // and the stack frame base register is adjusted |kSafeStackFrameSize|. 23 // and the stack frame base register is adjusted |kSafeStackFrameSize|.
24 NEVER_INLINE static uintptr_t currentStackFrameBaseOnCallee(const char* dummy) 24 NEVER_INLINE static uintptr_t currentStackFrameBaseOnCallee(const char* dummy)
25 { 25 {
26 s_avoidOptimization = dummy; 26 s_avoidOptimization = dummy;
27 return StackFrameDepth::currentStackFrame(); 27 return StackFrameDepth::currentStackFrame();
28 } 28 }
29 29
30 void StackFrameDepth::configureLimit() 30 void StackFrameDepth::configureLimit()
31 { 31 {
32 // Allocate a large object in stack and query stack frame pointer after it. 32 static const int kStackRoomSize = 1024;
33
34 size_t stackSize = getUnderestimatedStackSize();
35 if (stackSize) {
36 size_t stackBase = reinterpret_cast<size_t>(getStackStart());
37 m_stackFrameLimit = stackBase - stackSize + kStackRoomSize;
38 return;
39 }
40
41 // Fallback version
42 // Allocate a 32KB object on stack and query stack frame base after it.
33 char dummy[kSafeStackFrameSize]; 43 char dummy[kSafeStackFrameSize];
34 m_stackFrameLimit = currentStackFrameBaseOnCallee(dummy); 44 m_stackFrameLimit = currentStackFrameBaseOnCallee(dummy);
35 45
36 // Assert that the stack frame can be used. 46 // Assert that the stack frame can be used.
37 dummy[sizeof(dummy) - 1] = 0; 47 dummy[sizeof(dummy) - 1] = 0;
38 } 48 }
39 49
40 size_t StackFrameDepth::getUnderestimatedStackSize() 50 size_t StackFrameDepth::getUnderestimatedStackSize()
41 { 51 {
52 // FIXME: ASAN bot uses a fake stack as a thread stack frame,
53 // and its size is different from the value which APIs tells us.
54 #if defined(ADDRESS_SANITIZER)
55 return 0;
56 #endif
57
58 // FIXME: On Mac OSX and Linux, this method cannot estimate stack size
59 // correctly for the main thread.
60
42 #if defined(__GLIBC__) || OS(ANDROID) || OS(FREEBSD) 61 #if defined(__GLIBC__) || OS(ANDROID) || OS(FREEBSD)
43 // We cannot get the stack size in these platforms because 62 // pthread_getattr_np() can fail if the thread is not invoked by
44 // pthread_getattr_np() can fail for the main thread. 63 // pthread_create() (e.g., the main thread of webkit_unit_tests).
45 // This is OK because ThreadState::current() doesn't use the stack size 64 // In this case, this method returns 0 and the caller must handle it.
46 // in these platforms. 65
66 pthread_attr_t attr;
67 int error;
68 #if OS(FREEBSD)
69 pthread_attr_init(&attr);
70 error = pthread_attr_get_np(pthread_self(), &attr);
71 #else
72 error = pthread_getattr_np(pthread_self(), &attr);
73 #endif
74 if (!error) {
75 void* base;
76 size_t size;
77 error = pthread_attr_getstack(&attr, &base, &size);
78 RELEASE_ASSERT(!error);
79 pthread_attr_destroy(&attr);
80 return size;
81 }
82 #if OS(FREEBSD)
83 pthread_attr_destroy(&attr);
84 #endif
85
47 return 0; 86 return 0;
48 #elif OS(MACOSX) 87 #elif OS(MACOSX)
49 return pthread_get_stacksize_np(pthread_self()); 88 // FIXME: pthread_get_stacksize_np() returns shorter size than actual stack
89 // size for the main thread on Mavericks(10.9).
90 return 0;
50 #elif OS(WIN) && COMPILER(MSVC) 91 #elif OS(WIN) && COMPILER(MSVC)
51 // On Windows stack limits for the current thread are available in 92 // On Windows stack limits for the current thread are available in
52 // the thread information block (TIB). Its fields can be accessed through 93 // the thread information block (TIB). Its fields can be accessed through
53 // FS segment register on x86 and GS segment register on x86_64. 94 // FS segment register on x86 and GS segment register on x86_64.
54 #ifdef _WIN64 95 #ifdef _WIN64
55 return __readgsqword(offsetof(NT_TIB64, StackBase)) - __readgsqword(offsetof (NT_TIB64, StackLimit)); 96 return __readgsqword(offsetof(NT_TIB64, StackBase)) - __readgsqword(offsetof (NT_TIB64, StackLimit));
56 #else 97 #else
57 return __readfsdword(offsetof(NT_TIB, StackBase)) - __readfsdword(offsetof(N T_TIB, StackLimit)); 98 return __readfsdword(offsetof(NT_TIB, StackBase)) - __readfsdword(offsetof(N T_TIB, StackLimit));
58 #endif 99 #endif
59 #else 100 #else
101 #error "Stack frame size estimation not supported on this platform."
60 return 0; 102 return 0;
61 #endif 103 #endif
62 } 104 }
63 105
64 void* StackFrameDepth::getStackStart() 106 void* StackFrameDepth::getStackStart()
65 { 107 {
66 #if defined(__GLIBC__) || OS(ANDROID) || OS(FREEBSD) 108 #if defined(__GLIBC__) || OS(ANDROID) || OS(FREEBSD)
67 pthread_attr_t attr; 109 pthread_attr_t attr;
68 int error; 110 int error;
69 #if OS(FREEBSD) 111 #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))) ; 145 return reinterpret_cast<void*>(__readgsqword(offsetof(NT_TIB64, StackBase))) ;
104 #else 146 #else
105 return reinterpret_cast<void*>(__readfsdword(offsetof(NT_TIB, StackBase))); 147 return reinterpret_cast<void*>(__readfsdword(offsetof(NT_TIB, StackBase)));
106 #endif 148 #endif
107 #else 149 #else
108 #error Unsupported getStackStart on this platform. 150 #error Unsupported getStackStart on this platform.
109 #endif 151 #endif
110 } 152 }
111 153
112 } // namespace blink 154 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | Source/platform/heap/ThreadState.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698