| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 #ifdef _WIN64 | 103 #ifdef _WIN64 |
| 104 return reinterpret_cast<void*>(__readgsqword(offsetof(NT_TIB64, StackBase)))
; | 104 return reinterpret_cast<void*>(__readgsqword(offsetof(NT_TIB64, StackBase)))
; |
| 105 #else | 105 #else |
| 106 return reinterpret_cast<void*>(__readfsdword(offsetof(NT_TIB, StackBase))); | 106 return reinterpret_cast<void*>(__readfsdword(offsetof(NT_TIB, StackBase))); |
| 107 #endif | 107 #endif |
| 108 #else | 108 #else |
| 109 #error Unsupported getStackStart on this platform. | 109 #error Unsupported getStackStart on this platform. |
| 110 #endif | 110 #endif |
| 111 } | 111 } |
| 112 | 112 |
| 113 static size_t getUnderestimatedStackSize() |
| 114 { |
| 115 #if defined(__GLIBC__) || OS(ANDROID) || OS(FREEBSD) |
| 116 // We cannot get the stack size in these platforms because |
| 117 // pthread_getattr_np() can fail for the main thread. |
| 118 // This is OK because ThreadState::current() doesn't use the stack size |
| 119 // in these platforms. |
| 120 return 0; |
| 121 #elif OS(MACOSX) |
| 122 return pthread_get_stacksize_np(pthread_self()); |
| 123 #elif OS(WIN) && COMPILER(MSVC) |
| 124 // On Windows stack limits for the current thread are available in |
| 125 // the thread information block (TIB). Its fields can be accessed through |
| 126 // FS segment register on x86 and GS segment register on x86_64. |
| 127 #ifdef _WIN64 |
| 128 return __readgsqword(offsetof(NT_TIB64, StackBase)) - __readgsqword(offsetof
(NT_TIB64, StackLimit)); |
| 129 #else |
| 130 return __readfsdword(offsetof(NT_TIB, StackBase)) - __readfsdword(offsetof(N
T_TIB, StackLimit)); |
| 131 #endif |
| 132 #else |
| 133 return 0; |
| 134 #endif |
| 135 } |
| 136 |
| 113 // The maximum number of WrapperPersistentRegions to keep around in the | 137 // The maximum number of WrapperPersistentRegions to keep around in the |
| 114 // m_pooledWrapperPersistentRegions pool. | 138 // m_pooledWrapperPersistentRegions pool. |
| 115 static const size_t MaxPooledWrapperPersistentRegionCount = 2; | 139 static const size_t MaxPooledWrapperPersistentRegionCount = 2; |
| 116 | 140 |
| 117 WTF::ThreadSpecific<ThreadState*>* ThreadState::s_threadSpecific = 0; | 141 WTF::ThreadSpecific<ThreadState*>* ThreadState::s_threadSpecific = 0; |
| 142 uintptr_t ThreadState::s_mainThreadStackStart = 0; |
| 143 uintptr_t ThreadState::s_mainThreadUnderestimatedStackSize = 0; |
| 118 uint8_t ThreadState::s_mainThreadStateStorage[sizeof(ThreadState)]; | 144 uint8_t ThreadState::s_mainThreadStateStorage[sizeof(ThreadState)]; |
| 119 SafePointBarrier* ThreadState::s_safePointBarrier = 0; | 145 SafePointBarrier* ThreadState::s_safePointBarrier = 0; |
| 120 bool ThreadState::s_inGC = false; | 146 bool ThreadState::s_inGC = false; |
| 121 | 147 |
| 122 static Mutex& threadAttachMutex() | 148 static Mutex& threadAttachMutex() |
| 123 { | 149 { |
| 124 AtomicallyInitializedStatic(Mutex&, mutex = *new Mutex); | 150 AtomicallyInitializedStatic(Mutex&, mutex = *new Mutex); |
| 125 return mutex; | 151 return mutex; |
| 126 } | 152 } |
| 127 | 153 |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 , m_shouldFlushHeapDoesNotContainCache(false) | 344 , m_shouldFlushHeapDoesNotContainCache(false) |
| 319 , m_lowCollectionRate(false) | 345 , m_lowCollectionRate(false) |
| 320 , m_numberOfSweeperTasks(0) | 346 , m_numberOfSweeperTasks(0) |
| 321 #if defined(ADDRESS_SANITIZER) | 347 #if defined(ADDRESS_SANITIZER) |
| 322 , m_asanFakeStack(__asan_get_current_fake_stack()) | 348 , m_asanFakeStack(__asan_get_current_fake_stack()) |
| 323 #endif | 349 #endif |
| 324 { | 350 { |
| 325 ASSERT(!**s_threadSpecific); | 351 ASSERT(!**s_threadSpecific); |
| 326 **s_threadSpecific = this; | 352 **s_threadSpecific = this; |
| 327 | 353 |
| 354 if (isMainThread()) { |
| 355 s_mainThreadStackStart = reinterpret_cast<uintptr_t>(m_startOfStack) - s
izeof(void*); |
| 356 s_mainThreadUnderestimatedStackSize = getUnderestimatedStackSize() - siz
eof(void*); |
| 357 } |
| 358 |
| 328 InitializeHeaps<NumberOfHeaps>::init(m_heaps, this); | 359 InitializeHeaps<NumberOfHeaps>::init(m_heaps, this); |
| 329 | 360 |
| 330 m_weakCallbackStack = new CallbackStack(); | 361 m_weakCallbackStack = new CallbackStack(); |
| 331 | 362 |
| 332 if (blink::Platform::current()) | 363 if (blink::Platform::current()) |
| 333 m_sweeperThread = adoptPtr(blink::Platform::current()->createThread("Bli
nk GC Sweeper")); | 364 m_sweeperThread = adoptPtr(blink::Platform::current()->createThread("Bli
nk GC Sweeper")); |
| 334 } | 365 } |
| 335 | 366 |
| 336 ThreadState::~ThreadState() | 367 ThreadState::~ThreadState() |
| 337 { | 368 { |
| 338 checkThread(); | 369 checkThread(); |
| 339 delete m_weakCallbackStack; | 370 delete m_weakCallbackStack; |
| 340 m_weakCallbackStack = 0; | 371 m_weakCallbackStack = 0; |
| 341 for (int i = 0; i < NumberOfHeaps; i++) | 372 for (int i = 0; i < NumberOfHeaps; i++) |
| 342 delete m_heaps[i]; | 373 delete m_heaps[i]; |
| 343 deleteAllValues(m_interruptors); | 374 deleteAllValues(m_interruptors); |
| 344 while (m_liveWrapperPersistents) { | 375 while (m_liveWrapperPersistents) { |
| 345 WrapperPersistentRegion* region = WrapperPersistentRegion::removeHead(&m
_liveWrapperPersistents); | 376 WrapperPersistentRegion* region = WrapperPersistentRegion::removeHead(&m
_liveWrapperPersistents); |
| 346 delete region; | 377 delete region; |
| 347 } | 378 } |
| 348 while (m_pooledWrapperPersistents) { | 379 while (m_pooledWrapperPersistents) { |
| 349 WrapperPersistentRegion* region = WrapperPersistentRegion::removeHead(&m
_pooledWrapperPersistents); | 380 WrapperPersistentRegion* region = WrapperPersistentRegion::removeHead(&m
_pooledWrapperPersistents); |
| 350 delete region; | 381 delete region; |
| 351 } | 382 } |
| 352 **s_threadSpecific = 0; | 383 **s_threadSpecific = 0; |
| 384 s_mainThreadStackStart = 0; |
| 385 s_mainThreadUnderestimatedStackSize = 0; |
| 353 } | 386 } |
| 354 | 387 |
| 355 void ThreadState::init() | 388 void ThreadState::init() |
| 356 { | 389 { |
| 357 s_threadSpecific = new WTF::ThreadSpecific<ThreadState*>(); | 390 s_threadSpecific = new WTF::ThreadSpecific<ThreadState*>(); |
| 358 s_safePointBarrier = new SafePointBarrier; | 391 s_safePointBarrier = new SafePointBarrier; |
| 359 } | 392 } |
| 360 | 393 |
| 361 void ThreadState::shutdown() | 394 void ThreadState::shutdown() |
| 362 { | 395 { |
| (...skipping 919 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1282 return gcInfo; | 1315 return gcInfo; |
| 1283 } | 1316 } |
| 1284 } | 1317 } |
| 1285 if (needLockForIteration) | 1318 if (needLockForIteration) |
| 1286 threadAttachMutex().unlock(); | 1319 threadAttachMutex().unlock(); |
| 1287 return 0; | 1320 return 0; |
| 1288 } | 1321 } |
| 1289 #endif | 1322 #endif |
| 1290 | 1323 |
| 1291 } | 1324 } |
| OLD | NEW |