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

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

Issue 927213002: [Oilpan] Set stack limit using estimated sizes (Re-land) (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Work for 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 | « Source/platform/heap/HeapTest.cpp ('k') | 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: On ChromeOS and Mac OSX, this method cannot estimate stack size
53 // correctly for the main thread.
54
42 #if defined(__GLIBC__) || OS(ANDROID) || OS(FREEBSD) 55 #if defined(__GLIBC__) || OS(ANDROID) || OS(FREEBSD)
43 // We cannot get the stack size in these platforms because 56 // pthread_getattr_np() can fail if the thread is not invoked by
44 // pthread_getattr_np() can fail for the main thread. 57 // pthread_create() (e.g., the main thread of webkit_unit_tests).
45 // This is OK because ThreadState::current() doesn't use the stack size 58 // In this case, this method returns 0 and the caller must handle it.
46 // in these platforms. 59
60 pthread_attr_t attr;
61 int error;
62 #if OS(FREEBSD)
63 pthread_attr_init(&attr);
64 error = pthread_attr_get_np(pthread_self(), &attr);
65 #else
66 error = pthread_getattr_np(pthread_self(), &attr);
67 #endif
68 if (!error) {
69 void* base;
70 size_t size;
71 error = pthread_attr_getstack(&attr, &base, &size);
72 RELEASE_ASSERT(!error);
73 pthread_attr_destroy(&attr);
74 return size;
75 }
76 #if OS(FREEBSD)
77 pthread_attr_destroy(&attr);
78 #endif
79
47 return 0; 80 return 0;
48 #elif OS(MACOSX) 81 #elif OS(MACOSX)
49 return pthread_get_stacksize_np(pthread_self()); 82 // FIXME: pthread_get_stacksize_np() seems to return shorter size than actua l
83 // stack size.
84 return 0;
50 #elif OS(WIN) && COMPILER(MSVC) 85 #elif OS(WIN) && COMPILER(MSVC)
51 // On Windows stack limits for the current thread are available in 86 // On Windows stack limits for the current thread are available in
52 // the thread information block (TIB). Its fields can be accessed through 87 // the thread information block (TIB). Its fields can be accessed through
53 // FS segment register on x86 and GS segment register on x86_64. 88 // FS segment register on x86 and GS segment register on x86_64.
54 #ifdef _WIN64 89 #ifdef _WIN64
55 return __readgsqword(offsetof(NT_TIB64, StackBase)) - __readgsqword(offsetof (NT_TIB64, StackLimit)); 90 return __readgsqword(offsetof(NT_TIB64, StackBase)) - __readgsqword(offsetof (NT_TIB64, StackLimit));
56 #else 91 #else
57 return __readfsdword(offsetof(NT_TIB, StackBase)) - __readfsdword(offsetof(N T_TIB, StackLimit)); 92 return __readfsdword(offsetof(NT_TIB, StackBase)) - __readfsdword(offsetof(N T_TIB, StackLimit));
58 #endif 93 #endif
59 #else 94 #else
95 #error "Stack frame size estimation not supported on this platform."
60 return 0; 96 return 0;
61 #endif 97 #endif
62 } 98 }
63 99
64 void* StackFrameDepth::getStackStart() 100 void* StackFrameDepth::getStackStart()
65 { 101 {
66 #if defined(__GLIBC__) || OS(ANDROID) || OS(FREEBSD) 102 #if defined(__GLIBC__) || OS(ANDROID) || OS(FREEBSD)
67 pthread_attr_t attr; 103 pthread_attr_t attr;
68 int error; 104 int error;
69 #if OS(FREEBSD) 105 #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))) ; 139 return reinterpret_cast<void*>(__readgsqword(offsetof(NT_TIB64, StackBase))) ;
104 #else 140 #else
105 return reinterpret_cast<void*>(__readfsdword(offsetof(NT_TIB, StackBase))); 141 return reinterpret_cast<void*>(__readfsdword(offsetof(NT_TIB, StackBase)));
106 #endif 142 #endif
107 #else 143 #else
108 #error Unsupported getStackStart on this platform. 144 #error Unsupported getStackStart on this platform.
109 #endif 145 #endif
110 } 146 }
111 147
112 } // namespace blink 148 } // namespace blink
OLDNEW
« no previous file with comments | « Source/platform/heap/HeapTest.cpp ('k') | Source/platform/heap/ThreadState.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698