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

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

Issue 1149673002: Adding blink gc memory dump infrastructure for thread specific dumps. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Few nits. Created 5 years, 7 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 21 matching lines...) Expand all
32 #include "platform/heap/ThreadState.h" 32 #include "platform/heap/ThreadState.h"
33 33
34 #include "platform/ScriptForbiddenScope.h" 34 #include "platform/ScriptForbiddenScope.h"
35 #include "platform/TraceEvent.h" 35 #include "platform/TraceEvent.h"
36 #include "platform/heap/AddressSanitizer.h" 36 #include "platform/heap/AddressSanitizer.h"
37 #include "platform/heap/CallbackStack.h" 37 #include "platform/heap/CallbackStack.h"
38 #include "platform/heap/Handle.h" 38 #include "platform/heap/Handle.h"
39 #include "platform/heap/Heap.h" 39 #include "platform/heap/Heap.h"
40 #include "platform/heap/SafePoint.h" 40 #include "platform/heap/SafePoint.h"
41 #include "public/platform/Platform.h" 41 #include "public/platform/Platform.h"
42 #include "public/platform/WebMemoryAllocatorDump.h"
43 #include "public/platform/WebProcessMemoryDump.h"
42 #include "public/platform/WebScheduler.h" 44 #include "public/platform/WebScheduler.h"
43 #include "public/platform/WebThread.h" 45 #include "public/platform/WebThread.h"
44 #include "public/platform/WebTraceLocation.h" 46 #include "public/platform/WebTraceLocation.h"
45 #include "wtf/Partitions.h" 47 #include "wtf/Partitions.h"
46 #include "wtf/ThreadingPrimitives.h" 48 #include "wtf/ThreadingPrimitives.h"
47 #if ENABLE(GC_PROFILING) 49 #if ENABLE(GC_PROFILING)
48 #include "platform/TracedValue.h" 50 #include "platform/TracedValue.h"
49 #include "wtf/text/StringHash.h" 51 #include "wtf/text/StringHash.h"
50 #endif 52 #endif
51 53
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 } 122 }
121 123
122 for (int heapIndex = 0; heapIndex < LargeObjectHeapIndex; heapIndex++) 124 for (int heapIndex = 0; heapIndex < LargeObjectHeapIndex; heapIndex++)
123 m_heaps[heapIndex] = new NormalPageHeap(this, heapIndex); 125 m_heaps[heapIndex] = new NormalPageHeap(this, heapIndex);
124 m_heaps[LargeObjectHeapIndex] = new LargeObjectHeap(this, LargeObjectHeapInd ex); 126 m_heaps[LargeObjectHeapIndex] = new LargeObjectHeap(this, LargeObjectHeapInd ex);
125 127
126 m_likelyToBePromptlyFreed = adoptArrayPtr(new int[likelyToBePromptlyFreedArr aySize]); 128 m_likelyToBePromptlyFreed = adoptArrayPtr(new int[likelyToBePromptlyFreedArr aySize]);
127 clearHeapAges(); 129 clearHeapAges();
128 130
129 m_weakCallbackStack = new CallbackStack(); 131 m_weakCallbackStack = new CallbackStack();
132
133 if (Platform::current()->currentThread())
134 Platform::current()->registerMemoryDumpProvider(this);
130 } 135 }
131 136
132 ThreadState::~ThreadState() 137 ThreadState::~ThreadState()
133 { 138 {
134 checkThread(); 139 checkThread();
140
141 if (Platform::current()->currentThread())
142 Platform::current()->unregisterMemoryDumpProvider(this);
143
135 delete m_weakCallbackStack; 144 delete m_weakCallbackStack;
136 m_weakCallbackStack = nullptr; 145 m_weakCallbackStack = nullptr;
137 for (int i = 0; i < NumberOfHeaps; ++i) 146 for (int i = 0; i < NumberOfHeaps; ++i)
138 delete m_heaps[i]; 147 delete m_heaps[i];
139 deleteAllValues(m_interruptors); 148 deleteAllValues(m_interruptors);
140 **s_threadSpecific = nullptr; 149 **s_threadSpecific = nullptr;
141 if (isMainThread()) { 150 if (isMainThread()) {
142 s_mainThreadStackStart = 0; 151 s_mainThreadStackStart = 0;
143 s_mainThreadUnderestimatedStackSize = 0; 152 s_mainThreadUnderestimatedStackSize = 0;
144 } 153 }
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 382
374 void ThreadState::visitPersistents(Visitor* visitor) 383 void ThreadState::visitPersistents(Visitor* visitor)
375 { 384 {
376 m_persistents->trace(visitor); 385 m_persistents->trace(visitor);
377 if (m_traceDOMWrappers) { 386 if (m_traceDOMWrappers) {
378 TRACE_EVENT0("blink_gc", "V8GCController::traceDOMWrappers"); 387 TRACE_EVENT0("blink_gc", "V8GCController::traceDOMWrappers");
379 m_traceDOMWrappers(m_isolate, visitor); 388 m_traceDOMWrappers(m_isolate, visitor);
380 } 389 }
381 } 390 }
382 391
392 void ThreadState::dumpMemoryIfNecessary()
393 {
394 bool enabled;
395 TRACE_EVENT_CATEGORY_GROUP_ENABLED(TRACE_DISABLED_BY_DEFAULT("memory-infra") , &enabled);
396 if (!enabled)
397 return;
398
399 dumpMemory();
400 }
401
402 void ThreadState::dumpMemory()
403 {
404 ASSERT(checkThread());
ssid 2015/05/21 16:55:28 This check is not required here, since method can
405 if (!m_lastProcessMemoryDump.get()) {
406 // TODO(ssid): uncomment the following line once the support is availabl e,
407 // and remove the return statement.
408 // m_lastProcessMemoryDump.reset(Platform::current()->getExtraProcessMem oryDump());
409 return;
410 }
411
412 #define SNAPSHOT_HEAP(HeapType) m_heaps[HeapType##HeapIndex]->dumpMemoryInto(m_l astProcessMemoryDump.get(), #HeapType);
413
414 SNAPSHOT_HEAP(NormalPage1);
415 SNAPSHOT_HEAP(NormalPage2);
416 SNAPSHOT_HEAP(NormalPage3);
417 SNAPSHOT_HEAP(NormalPage4);
418 SNAPSHOT_HEAP(Vector1);
419 SNAPSHOT_HEAP(Vector2);
420 SNAPSHOT_HEAP(Vector3);
421 SNAPSHOT_HEAP(Vector4);
422 SNAPSHOT_HEAP(InlineVector);
423 SNAPSHOT_HEAP(HashTable);
424 SNAPSHOT_HEAP(LargeObject);
425 FOR_EACH_TYPED_HEAP(SNAPSHOT_HEAP);
426
427 #undef SNAPSHOT_HEAP
428
429 // TODO(ssid): Request global dump from blink when support is available.
430 }
431
383 #if ENABLE(GC_PROFILING) 432 #if ENABLE(GC_PROFILING)
384 const GCInfo* ThreadState::findGCInfo(Address address) 433 const GCInfo* ThreadState::findGCInfo(Address address)
385 { 434 {
386 if (BasePage* page = findPageFromAddress(address)) 435 if (BasePage* page = findPageFromAddress(address))
387 return page->findGCInfo(address); 436 return page->findGCInfo(address);
388 return nullptr; 437 return nullptr;
389 } 438 }
390 439
391 size_t ThreadState::SnapshotInfo::getClassTag(const GCInfo* gcInfo) 440 size_t ThreadState::SnapshotInfo::getClassTag(const GCInfo* gcInfo)
392 { 441 {
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after
835 makeConsistentForSweeping(); 884 makeConsistentForSweeping();
836 prepareRegionTree(); 885 prepareRegionTree();
837 flushHeapDoesNotContainCacheIfNeeded(); 886 flushHeapDoesNotContainCacheIfNeeded();
838 clearHeapAges(); 887 clearHeapAges();
839 } 888 }
840 889
841 void ThreadState::postGC(GCType gcType) 890 void ThreadState::postGC(GCType gcType)
842 { 891 {
843 ASSERT(isInGC()); 892 ASSERT(isInGC());
844 893
894 dumpMemoryIfNecessary();
845 #if ENABLE(GC_PROFILING) 895 #if ENABLE(GC_PROFILING)
846 // We snapshot the heap prior to sweeping to get numbers for both resources 896 // We snapshot the heap prior to sweeping to get numbers for both resources
847 // that have been allocated since the last GC and for resources that are 897 // that have been allocated since the last GC and for resources that are
848 // going to be freed. 898 // going to be freed.
849 bool gcTracingEnabled; 899 bool gcTracingEnabled;
850 TRACE_EVENT_CATEGORY_GROUP_ENABLED("blink_gc", &gcTracingEnabled); 900 TRACE_EVENT_CATEGORY_GROUP_ENABLED("blink_gc", &gcTracingEnabled);
851 901
852 if (gcTracingEnabled) { 902 if (gcTracingEnabled) {
853 bool disabledByDefaultGCTracingEnabled; 903 bool disabledByDefaultGCTracingEnabled;
854 TRACE_EVENT_CATEGORY_GROUP_ENABLED(TRACE_DISABLED_BY_DEFAULT("blink_gc") , &disabledByDefaultGCTracingEnabled); 904 TRACE_EVENT_CATEGORY_GROUP_ENABLED(TRACE_DISABLED_BY_DEFAULT("blink_gc") , &disabledByDefaultGCTracingEnabled);
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
1216 m_vectorBackingHeapIndex = heapIndexOfVectorHeapLeastRecentlyExpanded(Ve ctor1HeapIndex, Vector4HeapIndex); 1266 m_vectorBackingHeapIndex = heapIndexOfVectorHeapLeastRecentlyExpanded(Ve ctor1HeapIndex, Vector4HeapIndex);
1217 } 1267 }
1218 1268
1219 void ThreadState::promptlyFreed(size_t gcInfoIndex) 1269 void ThreadState::promptlyFreed(size_t gcInfoIndex)
1220 { 1270 {
1221 size_t entryIndex = gcInfoIndex & likelyToBePromptlyFreedArrayMask; 1271 size_t entryIndex = gcInfoIndex & likelyToBePromptlyFreedArrayMask;
1222 // See the comment in vectorBackingHeap() for why this is +3. 1272 // See the comment in vectorBackingHeap() for why this is +3.
1223 m_likelyToBePromptlyFreed[entryIndex] += 3; 1273 m_likelyToBePromptlyFreed[entryIndex] += 3;
1224 } 1274 }
1225 1275
1276 bool ThreadState::onMemoryDump(WebProcessMemoryDump* memoryDump)
1277 {
1278 // Returns true because it might be able to provide dump in future. On
1279 // returning false, the memory dump manager stops collecting dumps from
1280 // this provider.
1281 if (!m_lastProcessMemoryDump.get())
1282 return true;
1283
1284 // memoryDump->TakeAllDumpsFrom(m_lastProcessMemoryDump.get());
1285 return true;
1286 }
1287
1226 #if ENABLE(GC_PROFILING) 1288 #if ENABLE(GC_PROFILING)
1227 const GCInfo* ThreadState::findGCInfoFromAllThreads(Address address) 1289 const GCInfo* ThreadState::findGCInfoFromAllThreads(Address address)
1228 { 1290 {
1229 bool needLockForIteration = !ThreadState::current()->isInGC(); 1291 bool needLockForIteration = !ThreadState::current()->isInGC();
1230 if (needLockForIteration) 1292 if (needLockForIteration)
1231 threadAttachMutex().lock(); 1293 threadAttachMutex().lock();
1232 1294
1233 for (ThreadState* state : attachedThreads()) { 1295 for (ThreadState* state : attachedThreads()) {
1234 if (const GCInfo* gcInfo = state->findGCInfo(address)) { 1296 if (const GCInfo* gcInfo = state->findGCInfo(address)) {
1235 if (needLockForIteration) 1297 if (needLockForIteration)
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1306 json->beginArray(it->key.ascii().data()); 1368 json->beginArray(it->key.ascii().data());
1307 for (size_t age = 0; age <= maxHeapObjectAge; ++age) 1369 for (size_t age = 0; age <= maxHeapObjectAge; ++age)
1308 json->pushInteger(it->value.ages[age]); 1370 json->pushInteger(it->value.ages[age]);
1309 json->endArray(); 1371 json->endArray();
1310 } 1372 }
1311 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID(TRACE_DISABLED_BY_DEFAULT("blink_gc"), s tatsName, this, json.release()); 1373 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID(TRACE_DISABLED_BY_DEFAULT("blink_gc"), s tatsName, this, json.release());
1312 } 1374 }
1313 #endif 1375 #endif
1314 1376
1315 } // namespace blink 1377 } // namespace blink
OLDNEW
« Source/platform/heap/ThreadState.h ('K') | « Source/platform/heap/ThreadState.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698