| OLD | NEW |
| 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 "platform/heap/StackFrameDepth.h" | 5 #include "platform/heap/StackFrameDepth.h" |
| 6 | 6 |
| 7 #include "public/platform/Platform.h" | 7 #include "public/platform/Platform.h" |
| 8 | 8 |
| 9 #if OS(WIN) | 9 #if OS(WIN) |
| 10 #include <stddef.h> | 10 #include <stddef.h> |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 | 51 |
| 52 // Fallback version | 52 // Fallback version |
| 53 // Allocate a 32KB object on stack and query stack frame base after it. | 53 // Allocate a 32KB object on stack and query stack frame base after it. |
| 54 char dummy[kSafeStackFrameSize]; | 54 char dummy[kSafeStackFrameSize]; |
| 55 s_stackFrameLimit = currentStackFrameBaseOnCallee(dummy); | 55 s_stackFrameLimit = currentStackFrameBaseOnCallee(dummy); |
| 56 | 56 |
| 57 // Assert that the stack frame can be used. | 57 // Assert that the stack frame can be used. |
| 58 dummy[sizeof(dummy) - 1] = 0; | 58 dummy[sizeof(dummy) - 1] = 0; |
| 59 } | 59 } |
| 60 | 60 |
| 61 bool StackFrameDepth::hasInsufficientStackForGC() |
| 62 { |
| 63 size_t stackSize = getUnderestimatedStackSize(); |
| 64 if (!stackSize) |
| 65 return false; |
| 66 |
| 67 Address stackBase = reinterpret_cast<Address>(getStackStart()); |
| 68 RELEASE_ASSERT(stackBase > reinterpret_cast<Address>(stackSize)); |
| 69 uintptr_t stackLimit = reinterpret_cast<uintptr_t>(stackBase - stackSize); |
| 70 |
| 71 // If less than 8k of stack space is left, better not run a GC. |
| 72 char dummy[2]; |
| 73 return (currentStackFrameBaseOnCallee(dummy) - stackLimit) < 8 * 1024; |
| 74 } |
| 75 |
| 61 size_t StackFrameDepth::getUnderestimatedStackSize() | 76 size_t StackFrameDepth::getUnderestimatedStackSize() |
| 62 { | 77 { |
| 63 // FIXME: ASAN bot uses a fake stack as a thread stack frame, | 78 // FIXME: ASAN bot uses a fake stack as a thread stack frame, |
| 64 // and its size is different from the value which APIs tells us. | 79 // and its size is different from the value which APIs tells us. |
| 65 #if defined(ADDRESS_SANITIZER) | 80 #if defined(ADDRESS_SANITIZER) |
| 66 return 0; | 81 return 0; |
| 67 #endif | 82 #endif |
| 68 | 83 |
| 69 // FIXME: On Mac OSX and Linux, this method cannot estimate stack size | 84 // FIXME: On Mac OSX and Linux, this method cannot estimate stack size |
| 70 // correctly for the main thread. | 85 // correctly for the main thread. |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 return reinterpret_cast<void*>(__readgsqword(offsetof(NT_TIB64, StackBase)))
; | 181 return reinterpret_cast<void*>(__readgsqword(offsetof(NT_TIB64, StackBase)))
; |
| 167 #else | 182 #else |
| 168 return reinterpret_cast<void*>(__readfsdword(offsetof(NT_TIB, StackBase))); | 183 return reinterpret_cast<void*>(__readfsdword(offsetof(NT_TIB, StackBase))); |
| 169 #endif | 184 #endif |
| 170 #else | 185 #else |
| 171 #error Unsupported getStackStart on this platform. | 186 #error Unsupported getStackStart on this platform. |
| 172 #endif | 187 #endif |
| 173 } | 188 } |
| 174 | 189 |
| 175 } // namespace blink | 190 } // namespace blink |
| OLD | NEW |