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