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

Unified Diff: third_party/WebKit/Source/platform/heap/StackFrameDepth.cpp

Issue 2623273007: Fast path for ThreadSpecific for main thread on TLS-slow platforms (Closed)
Patch Set: haraken revieqw Created 3 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/platform/heap/StackFrameDepth.cpp
diff --git a/third_party/WebKit/Source/platform/heap/StackFrameDepth.cpp b/third_party/WebKit/Source/platform/heap/StackFrameDepth.cpp
index 1d164f510a36de4ecb3328e6c80065f4913eca5d..7c609c5bba5ab1b1a181be5121b44acbbaf306b3 100644
--- a/third_party/WebKit/Source/platform/heap/StackFrameDepth.cpp
+++ b/third_party/WebKit/Source/platform/heap/StackFrameDepth.cpp
@@ -5,6 +5,7 @@
#include "platform/heap/StackFrameDepth.h"
#include "public/platform/Platform.h"
+#include "wtf/StackUtil.h"
#if OS(WIN)
#include <stddef.h>
@@ -38,7 +39,7 @@ uintptr_t StackFrameDepth::getFallbackStackLimit() {
void StackFrameDepth::enableStackLimit() {
// All supported platforms will currently return a non-zero estimate,
// except if ASan is enabled.
- size_t stackSize = getUnderestimatedStackSize();
+ size_t stackSize = WTF::getUnderestimatedStackSize();
if (!stackSize) {
m_stackFrameLimit = getFallbackStackLimit();
return;
@@ -46,7 +47,7 @@ void StackFrameDepth::enableStackLimit() {
static const int kStackRoomSize = 1024;
- Address stackBase = reinterpret_cast<Address>(getStackStart());
+ Address stackBase = reinterpret_cast<Address>(WTF::getStackStart());
RELEASE_ASSERT(stackSize > static_cast<const size_t>(kStackRoomSize));
size_t stackRoom = stackSize - kStackRoomSize;
RELEASE_ASSERT(stackBase > reinterpret_cast<Address>(stackRoom));
@@ -58,127 +59,4 @@ void StackFrameDepth::enableStackLimit() {
disableStackLimit();
}
-size_t StackFrameDepth::getUnderestimatedStackSize() {
-// FIXME: ASAN bot uses a fake stack as a thread stack frame,
-// and its size is different from the value which APIs tells us.
-#if defined(ADDRESS_SANITIZER)
- return 0;
-#endif
-
-// FIXME: On Mac OSX and Linux, this method cannot estimate stack size
-// correctly for the main thread.
-
-#if defined(__GLIBC__) || OS(ANDROID) || OS(FREEBSD)
- // pthread_getattr_np() can fail if the thread is not invoked by
- // pthread_create() (e.g., the main thread of webkit_unit_tests).
- // If so, a conservative size estimate is returned.
-
- pthread_attr_t attr;
- int error;
-#if OS(FREEBSD)
- pthread_attr_init(&attr);
- error = pthread_attr_get_np(pthread_self(), &attr);
-#else
- error = pthread_getattr_np(pthread_self(), &attr);
-#endif
- if (!error) {
- void* base;
- size_t size;
- error = pthread_attr_getstack(&attr, &base, &size);
- RELEASE_ASSERT(!error);
- pthread_attr_destroy(&attr);
- return size;
- }
-#if OS(FREEBSD)
- pthread_attr_destroy(&attr);
-#endif
-
- // Return a 512k stack size, (conservatively) assuming the following:
- // - that size is much lower than the pthreads default (x86 pthreads has a 2M
- // default.)
- // - no one is running Blink with an RLIMIT_STACK override, let alone as
- // low as 512k.
- //
- return 512 * 1024;
-#elif OS(MACOSX)
- // pthread_get_stacksize_np() returns too low a value for the main thread on
- // OSX 10.9,
- // http://mail.openjdk.java.net/pipermail/hotspot-dev/2013-October/011369.html
- //
- // Multiple workarounds possible, adopt the one made by
- // https://github.com/robovm/robovm/issues/274
- // (cf.
- // https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Multithreading/CreatingThreads/CreatingThreads.html
- // on why hardcoding sizes is reasonable.)
- if (pthread_main_np()) {
-#if defined(IOS)
- pthread_attr_t attr;
- pthread_attr_init(&attr);
- size_t guardSize = 0;
- pthread_attr_getguardsize(&attr, &guardSize);
- // Stack size for the main thread is 1MB on iOS including the guard page
- // size.
- return (1 * 1024 * 1024 - guardSize);
-#else
- // Stack size for the main thread is 8MB on OSX excluding the guard page
- // size.
- return (8 * 1024 * 1024);
-#endif
- }
- return pthread_get_stacksize_np(pthread_self());
-#elif OS(WIN) && COMPILER(MSVC)
- return ThreadState::current()->threadStackSize();
-#else
-#error "Stack frame size estimation not supported on this platform."
- return 0;
-#endif
-}
-
-void* StackFrameDepth::getStackStart() {
-#if defined(__GLIBC__) || OS(ANDROID) || OS(FREEBSD)
- pthread_attr_t attr;
- int error;
-#if OS(FREEBSD)
- pthread_attr_init(&attr);
- error = pthread_attr_get_np(pthread_self(), &attr);
-#else
- error = pthread_getattr_np(pthread_self(), &attr);
-#endif
- if (!error) {
- void* base;
- size_t size;
- error = pthread_attr_getstack(&attr, &base, &size);
- RELEASE_ASSERT(!error);
- pthread_attr_destroy(&attr);
- return reinterpret_cast<uint8_t*>(base) + size;
- }
-#if OS(FREEBSD)
- pthread_attr_destroy(&attr);
-#endif
-#if defined(__GLIBC__)
- // pthread_getattr_np can fail for the main thread. In this case
- // just like NaCl we rely on the __libc_stack_end to give us
- // the start of the stack.
- // See https://code.google.com/p/nativeclient/issues/detail?id=3431.
- return __libc_stack_end;
-#else
- ASSERT_NOT_REACHED();
- return nullptr;
-#endif
-#elif OS(MACOSX)
- return pthread_get_stackaddr_np(pthread_self());
-#elif OS(WIN) && COMPILER(MSVC)
-// On Windows stack limits for the current thread are available in
-// the thread information block (TIB). Its fields can be accessed through
-// FS segment register on x86 and GS segment register on x86_64.
-#ifdef _WIN64
- return reinterpret_cast<void*>(__readgsqword(offsetof(NT_TIB64, StackBase)));
-#else
- return reinterpret_cast<void*>(__readfsdword(offsetof(NT_TIB, StackBase)));
-#endif
-#else
-#error Unsupported getStackStart on this platform.
-#endif
-}
-
} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/platform/heap/StackFrameDepth.h ('k') | third_party/WebKit/Source/platform/heap/ThreadState.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698