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

Side by Side Diff: third_party/WebKit/Source/platform/heap/ThreadState.cpp

Issue 2050123002: Remove OwnPtr from Blink. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments from Kent; merge. Created 4 years, 6 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 unified diff | Download patch
OLDNEW
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
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
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
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 846 matching lines...) Expand 10 before | Expand all | Expand 10 after
1307 ASSERT(slotCount < 1024); 1308 ASSERT(slotCount < 1024);
1308 #endif 1309 #endif
1309 1310
1310 ASSERT(!m_safePointStackCopy.size()); 1311 ASSERT(!m_safePointStackCopy.size());
1311 m_safePointStackCopy.resize(slotCount); 1312 m_safePointStackCopy.resize(slotCount);
1312 for (size_t i = 0; i < slotCount; ++i) { 1313 for (size_t i = 0; i < slotCount; ++i) {
1313 m_safePointStackCopy[i] = from[i]; 1314 m_safePointStackCopy[i] = from[i];
1314 } 1315 }
1315 } 1316 }
1316 1317
1317 void ThreadState::addInterruptor(PassOwnPtr<BlinkGCInterruptor> interruptor) 1318 void ThreadState::addInterruptor(std::unique_ptr<BlinkGCInterruptor> interruptor )
1318 { 1319 {
1319 ASSERT(checkThread()); 1320 ASSERT(checkThread());
1320 SafePointScope scope(BlinkGC::HeapPointersOnStack); 1321 SafePointScope scope(BlinkGC::HeapPointersOnStack);
1321 { 1322 {
1322 MutexLocker locker(m_heap->threadAttachMutex()); 1323 MutexLocker locker(m_heap->threadAttachMutex());
1323 m_interruptors.append(std::move(interruptor)); 1324 m_interruptors.append(std::move(interruptor));
1324 } 1325 }
1325 } 1326 }
1326 1327
1327 void ThreadState::registerStaticPersistentNode(PersistentNode* node, PersistentC learCallback callback) 1328 void ThreadState::registerStaticPersistentNode(PersistentNode* node, PersistentC learCallback callback)
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
1526 threadDump->AddScalar("dead_count", "objects", totalDeadCount); 1527 threadDump->AddScalar("dead_count", "objects", totalDeadCount);
1527 threadDump->AddScalar("live_size", "bytes", totalLiveSize); 1528 threadDump->AddScalar("live_size", "bytes", totalLiveSize);
1528 threadDump->AddScalar("dead_size", "bytes", totalDeadSize); 1529 threadDump->AddScalar("dead_size", "bytes", totalDeadSize);
1529 1530
1530 base::trace_event::MemoryAllocatorDump* heapsDump = BlinkGCMemoryDumpProvide r::instance()->createMemoryAllocatorDumpForCurrentGC(heapsDumpName); 1531 base::trace_event::MemoryAllocatorDump* heapsDump = BlinkGCMemoryDumpProvide r::instance()->createMemoryAllocatorDumpForCurrentGC(heapsDumpName);
1531 base::trace_event::MemoryAllocatorDump* classesDump = BlinkGCMemoryDumpProvi der::instance()->createMemoryAllocatorDumpForCurrentGC(classesDumpName); 1532 base::trace_event::MemoryAllocatorDump* classesDump = BlinkGCMemoryDumpProvi der::instance()->createMemoryAllocatorDumpForCurrentGC(classesDumpName);
1532 BlinkGCMemoryDumpProvider::instance()->currentProcessMemoryDump()->AddOwners hipEdge(classesDump->guid(), heapsDump->guid()); 1533 BlinkGCMemoryDumpProvider::instance()->currentProcessMemoryDump()->AddOwners hipEdge(classesDump->guid(), heapsDump->guid());
1533 } 1534 }
1534 1535
1535 } // namespace blink 1536 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698