| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 #include "platform/heap/SafePoint.h" | 42 #include "platform/heap/SafePoint.h" |
| 43 #include "platform/heap/Visitor.h" | 43 #include "platform/heap/Visitor.h" |
| 44 #include "platform/web_memory_allocator_dump.h" | 44 #include "platform/web_memory_allocator_dump.h" |
| 45 #include "platform/web_process_memory_dump.h" | 45 #include "platform/web_process_memory_dump.h" |
| 46 #include "public/platform/Platform.h" | 46 #include "public/platform/Platform.h" |
| 47 #include "public/platform/WebScheduler.h" | 47 #include "public/platform/WebScheduler.h" |
| 48 #include "public/platform/WebThread.h" | 48 #include "public/platform/WebThread.h" |
| 49 #include "public/platform/WebTraceLocation.h" | 49 #include "public/platform/WebTraceLocation.h" |
| 50 #include "wtf/CurrentTime.h" | 50 #include "wtf/CurrentTime.h" |
| 51 #include "wtf/DataLog.h" | 51 #include "wtf/DataLog.h" |
| 52 #include "wtf/PtrUtil.h" |
| 52 #include "wtf/ThreadingPrimitives.h" | 53 #include "wtf/ThreadingPrimitives.h" |
| 53 #include "wtf/allocator/Partitions.h" | 54 #include "wtf/allocator/Partitions.h" |
| 55 #include <memory> |
| 56 #include <v8.h> |
| 54 | 57 |
| 55 #if OS(WIN) | 58 #if OS(WIN) |
| 56 #include <stddef.h> | 59 #include <stddef.h> |
| 57 #include <windows.h> | 60 #include <windows.h> |
| 58 #include <winnt.h> | 61 #include <winnt.h> |
| 59 #endif | 62 #endif |
| 60 | 63 |
| 61 #if defined(MEMORY_SANITIZER) | 64 #if defined(MEMORY_SANITIZER) |
| 62 #include <sanitizer/msan_interface.h> | 65 #include <sanitizer/msan_interface.h> |
| 63 #endif | 66 #endif |
| 64 | 67 |
| 65 #if OS(FREEBSD) | 68 #if OS(FREEBSD) |
| 66 #include <pthread_np.h> | 69 #include <pthread_np.h> |
| 67 #endif | 70 #endif |
| 68 | 71 |
| 69 #include <v8.h> | |
| 70 | |
| 71 namespace blink { | 72 namespace blink { |
| 72 | 73 |
| 73 WTF::ThreadSpecific<ThreadState*>* ThreadState::s_threadSpecific = nullptr; | 74 WTF::ThreadSpecific<ThreadState*>* ThreadState::s_threadSpecific = nullptr; |
| 74 uintptr_t ThreadState::s_mainThreadStackStart = 0; | 75 uintptr_t ThreadState::s_mainThreadStackStart = 0; |
| 75 uintptr_t ThreadState::s_mainThreadUnderestimatedStackSize = 0; | 76 uintptr_t ThreadState::s_mainThreadUnderestimatedStackSize = 0; |
| 76 uint8_t ThreadState::s_mainThreadStateStorage[sizeof(ThreadState)]; | 77 uint8_t ThreadState::s_mainThreadStateStorage[sizeof(ThreadState)]; |
| 77 | 78 |
| 78 ThreadState::ThreadState(bool perThreadHeapEnabled) | 79 ThreadState::ThreadState(bool perThreadHeapEnabled) |
| 79 : m_thread(currentThread()) | 80 : m_thread(currentThread()) |
| 80 , m_persistentRegion(adoptPtr(new PersistentRegion())) | 81 , m_persistentRegion(wrapUnique(new PersistentRegion())) |
| 81 #if OS(WIN) && COMPILER(MSVC) | 82 #if OS(WIN) && COMPILER(MSVC) |
| 82 , m_threadStackSize(0) | 83 , m_threadStackSize(0) |
| 83 #endif | 84 #endif |
| 84 , m_startOfStack(reinterpret_cast<intptr_t*>(StackFrameDepth::getStackStart(
))) | 85 , m_startOfStack(reinterpret_cast<intptr_t*>(StackFrameDepth::getStackStart(
))) |
| 85 , m_endOfStack(reinterpret_cast<intptr_t*>(StackFrameDepth::getStackStart())
) | 86 , m_endOfStack(reinterpret_cast<intptr_t*>(StackFrameDepth::getStackStart())
) |
| 86 , m_safePointScopeMarker(nullptr) | 87 , m_safePointScopeMarker(nullptr) |
| 87 , m_atSafePoint(false) | 88 , m_atSafePoint(false) |
| 88 , m_interruptors() | 89 , m_interruptors() |
| 89 , m_sweepForbidden(false) | 90 , m_sweepForbidden(false) |
| 90 , m_noAllocationCount(0) | 91 , m_noAllocationCount(0) |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 } else { | 126 } else { |
| 126 m_heap = &ThreadState::mainThreadState()->heap(); | 127 m_heap = &ThreadState::mainThreadState()->heap(); |
| 127 } | 128 } |
| 128 ASSERT(m_heap); | 129 ASSERT(m_heap); |
| 129 m_heap->attach(this); | 130 m_heap->attach(this); |
| 130 | 131 |
| 131 for (int arenaIndex = 0; arenaIndex < BlinkGC::LargeObjectArenaIndex; arenaI
ndex++) | 132 for (int arenaIndex = 0; arenaIndex < BlinkGC::LargeObjectArenaIndex; arenaI
ndex++) |
| 132 m_arenas[arenaIndex] = new NormalPageArena(this, arenaIndex); | 133 m_arenas[arenaIndex] = new NormalPageArena(this, arenaIndex); |
| 133 m_arenas[BlinkGC::LargeObjectArenaIndex] = new LargeObjectArena(this, BlinkG
C::LargeObjectArenaIndex); | 134 m_arenas[BlinkGC::LargeObjectArenaIndex] = new LargeObjectArena(this, BlinkG
C::LargeObjectArenaIndex); |
| 134 | 135 |
| 135 m_likelyToBePromptlyFreed = adoptArrayPtr(new int[likelyToBePromptlyFreedArr
aySize]); | 136 m_likelyToBePromptlyFreed = wrapArrayUnique(new int[likelyToBePromptlyFreedA
rraySize]); |
| 136 clearArenaAges(); | 137 clearArenaAges(); |
| 137 | 138 |
| 138 // There is little use of weak references and collections off the main threa
d; | 139 // There is little use of weak references and collections off the main threa
d; |
| 139 // use a much lower initial block reservation. | 140 // use a much lower initial block reservation. |
| 140 size_t initialBlockSize = isMainThread() ? CallbackStack::kDefaultBlockSize
: CallbackStack::kMinimalBlockSize; | 141 size_t initialBlockSize = isMainThread() ? CallbackStack::kDefaultBlockSize
: CallbackStack::kMinimalBlockSize; |
| 141 m_threadLocalWeakCallbackStack = new CallbackStack(initialBlockSize); | 142 m_threadLocalWeakCallbackStack = new CallbackStack(initialBlockSize); |
| 142 } | 143 } |
| 143 | 144 |
| 144 ThreadState::~ThreadState() | 145 ThreadState::~ThreadState() |
| 145 { | 146 { |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 ScriptForbiddenIfMainThreadScope scriptForbiddenScope; | 441 ScriptForbiddenIfMainThreadScope scriptForbiddenScope; |
| 441 | 442 |
| 442 // Disallow allocation during weak processing. | 443 // Disallow allocation during weak processing. |
| 443 // It would be technically safe to allow allocations, but it is unsafe | 444 // It would be technically safe to allow allocations, but it is unsafe |
| 444 // to mutate an object graph in a way in which a dead object gets | 445 // to mutate an object graph in a way in which a dead object gets |
| 445 // resurrected or mutate a HashTable (because HashTable's weak processing | 446 // resurrected or mutate a HashTable (because HashTable's weak processing |
| 446 // assumes that the HashTable hasn't been mutated since the latest marking). | 447 // assumes that the HashTable hasn't been mutated since the latest marking). |
| 447 // Due to the complexity, we just forbid allocations. | 448 // Due to the complexity, we just forbid allocations. |
| 448 NoAllocationScope noAllocationScope(this); | 449 NoAllocationScope noAllocationScope(this); |
| 449 | 450 |
| 450 OwnPtr<Visitor> visitor = Visitor::create(this, BlinkGC::ThreadLocalWeakProc
essing); | 451 std::unique_ptr<Visitor> visitor = Visitor::create(this, BlinkGC::ThreadLoca
lWeakProcessing); |
| 451 | 452 |
| 452 // Perform thread-specific weak processing. | 453 // Perform thread-specific weak processing. |
| 453 while (popAndInvokeThreadLocalWeakCallback(visitor.get())) { } | 454 while (popAndInvokeThreadLocalWeakCallback(visitor.get())) { } |
| 454 | 455 |
| 455 m_threadLocalWeakCallbackStack->decommit(); | 456 m_threadLocalWeakCallbackStack->decommit(); |
| 456 | 457 |
| 457 if (isMainThread()) { | 458 if (isMainThread()) { |
| 458 double timeForThreadLocalWeakProcessing = WTF::currentTimeMS() - startTi
me; | 459 double timeForThreadLocalWeakProcessing = WTF::currentTimeMS() - startTi
me; |
| 459 DEFINE_STATIC_LOCAL(CustomCountHistogram, timeForWeakHistogram, ("BlinkG
C.TimeForThreadLocalWeakProcessing", 1, 10 * 1000, 50)); | 460 DEFINE_STATIC_LOCAL(CustomCountHistogram, timeForWeakHistogram, ("BlinkG
C.TimeForThreadLocalWeakProcessing", 1, 10 * 1000, 50)); |
| 460 timeForWeakHistogram.count(timeForThreadLocalWeakProcessing); | 461 timeForWeakHistogram.count(timeForThreadLocalWeakProcessing); |
| (...skipping 852 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1313 ASSERT(slotCount < 1024); | 1314 ASSERT(slotCount < 1024); |
| 1314 #endif | 1315 #endif |
| 1315 | 1316 |
| 1316 ASSERT(!m_safePointStackCopy.size()); | 1317 ASSERT(!m_safePointStackCopy.size()); |
| 1317 m_safePointStackCopy.resize(slotCount); | 1318 m_safePointStackCopy.resize(slotCount); |
| 1318 for (size_t i = 0; i < slotCount; ++i) { | 1319 for (size_t i = 0; i < slotCount; ++i) { |
| 1319 m_safePointStackCopy[i] = from[i]; | 1320 m_safePointStackCopy[i] = from[i]; |
| 1320 } | 1321 } |
| 1321 } | 1322 } |
| 1322 | 1323 |
| 1323 void ThreadState::addInterruptor(PassOwnPtr<BlinkGCInterruptor> interruptor) | 1324 void ThreadState::addInterruptor(std::unique_ptr<BlinkGCInterruptor> interruptor
) |
| 1324 { | 1325 { |
| 1325 ASSERT(checkThread()); | 1326 ASSERT(checkThread()); |
| 1326 SafePointScope scope(BlinkGC::HeapPointersOnStack); | 1327 SafePointScope scope(BlinkGC::HeapPointersOnStack); |
| 1327 { | 1328 { |
| 1328 MutexLocker locker(m_heap->threadAttachMutex()); | 1329 MutexLocker locker(m_heap->threadAttachMutex()); |
| 1329 m_interruptors.append(std::move(interruptor)); | 1330 m_interruptors.append(std::move(interruptor)); |
| 1330 } | 1331 } |
| 1331 } | 1332 } |
| 1332 | 1333 |
| 1333 void ThreadState::registerStaticPersistentNode(PersistentNode* node, PersistentC
learCallback callback) | 1334 void ThreadState::registerStaticPersistentNode(PersistentNode* node, PersistentC
learCallback callback) |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1532 threadDump->AddScalar("dead_count", "objects", totalDeadCount); | 1533 threadDump->AddScalar("dead_count", "objects", totalDeadCount); |
| 1533 threadDump->AddScalar("live_size", "bytes", totalLiveSize); | 1534 threadDump->AddScalar("live_size", "bytes", totalLiveSize); |
| 1534 threadDump->AddScalar("dead_size", "bytes", totalDeadSize); | 1535 threadDump->AddScalar("dead_size", "bytes", totalDeadSize); |
| 1535 | 1536 |
| 1536 base::trace_event::MemoryAllocatorDump* heapsDump = BlinkGCMemoryDumpProvide
r::instance()->createMemoryAllocatorDumpForCurrentGC(heapsDumpName); | 1537 base::trace_event::MemoryAllocatorDump* heapsDump = BlinkGCMemoryDumpProvide
r::instance()->createMemoryAllocatorDumpForCurrentGC(heapsDumpName); |
| 1537 base::trace_event::MemoryAllocatorDump* classesDump = BlinkGCMemoryDumpProvi
der::instance()->createMemoryAllocatorDumpForCurrentGC(classesDumpName); | 1538 base::trace_event::MemoryAllocatorDump* classesDump = BlinkGCMemoryDumpProvi
der::instance()->createMemoryAllocatorDumpForCurrentGC(classesDumpName); |
| 1538 BlinkGCMemoryDumpProvider::instance()->currentProcessMemoryDump()->AddOwners
hipEdge(classesDump->guid(), heapsDump->guid()); | 1539 BlinkGCMemoryDumpProvider::instance()->currentProcessMemoryDump()->AddOwners
hipEdge(classesDump->guid(), heapsDump->guid()); |
| 1539 } | 1540 } |
| 1540 | 1541 |
| 1541 } // namespace blink | 1542 } // namespace blink |
| OLD | NEW |