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

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: Fixing dump name. 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 {
139 if (Platform::current()->currentThread())
140 Platform::current()->unregisterMemoryDumpProvider(this);
141
134 checkThread(); 142 checkThread();
Primiano Tucci (use gerrit) 2015/05/21 09:56:34 keep checkThread on the top, if this ends up in th
ssid 2015/05/21 11:38:55 Done.
135 delete m_weakCallbackStack; 143 delete m_weakCallbackStack;
136 m_weakCallbackStack = nullptr; 144 m_weakCallbackStack = nullptr;
137 for (int i = 0; i < NumberOfHeaps; ++i) 145 for (int i = 0; i < NumberOfHeaps; ++i)
138 delete m_heaps[i]; 146 delete m_heaps[i];
139 deleteAllValues(m_interruptors); 147 deleteAllValues(m_interruptors);
140 **s_threadSpecific = nullptr; 148 **s_threadSpecific = nullptr;
141 if (isMainThread()) { 149 if (isMainThread()) {
142 s_mainThreadStackStart = 0; 150 s_mainThreadStackStart = 0;
143 s_mainThreadUnderestimatedStackSize = 0; 151 s_mainThreadUnderestimatedStackSize = 0;
144 } 152 }
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 381
374 void ThreadState::visitPersistents(Visitor* visitor) 382 void ThreadState::visitPersistents(Visitor* visitor)
375 { 383 {
376 m_persistents->trace(visitor); 384 m_persistents->trace(visitor);
377 if (m_traceDOMWrappers) { 385 if (m_traceDOMWrappers) {
378 TRACE_EVENT0("blink_gc", "V8GCController::traceDOMWrappers"); 386 TRACE_EVENT0("blink_gc", "V8GCController::traceDOMWrappers");
379 m_traceDOMWrappers(m_isolate, visitor); 387 m_traceDOMWrappers(m_isolate, visitor);
380 } 388 }
381 } 389 }
382 390
391 void ThreadState::snapshotMemoryIfNecessary()
Primiano Tucci (use gerrit) 2015/05/21 09:56:34 This is a good name. I wonder though if we really
ssid 2015/05/21 11:38:55 Not sure, your call.
392 {
393 bool enabled;
394 TRACE_EVENT_CATEGORY_GROUP_ENABLED(TRACE_DISABLED_BY_DEFAULT("memory-infra") , &enabled);
Primiano Tucci (use gerrit) 2015/05/21 09:56:33 I see why you did it (it's the only way to tell to
ssid 2015/05/21 11:38:55 Not sure if i should add a TODO here?
395 if (!enabled)
396 return;
397
398 snapshotMemory();
399 }
400
401 void ThreadState::snapshotMemory()
402 {
403 // TODO(ssid): uncomment the following line once the support is available,
404 // and remove the check for dump being null.
405 // m_lastProcessMemoryDump.reset(Platform::current()->getExtraProcessMemoryD ump());
Primiano Tucci (use gerrit) 2015/05/21 09:56:34 I think we need to do some kind of dual buffering
ssid 2015/05/21 11:38:55 Yes this check is for the case that it isn't avail
406 if (!m_lastProcessMemoryDump.get())
407 return;
408
409 #define SNAPSHOT_HEAP(HeapType) m_heaps[HeapType##HeapIndex]->snapshotMemory(m_l astProcessMemoryDump.get(), #HeapType);
410
411 SNAPSHOT_HEAP(NormalPage1);
412 SNAPSHOT_HEAP(NormalPage2);
413 SNAPSHOT_HEAP(NormalPage3);
414 SNAPSHOT_HEAP(NormalPage4);
415 SNAPSHOT_HEAP(Vector1);
416 SNAPSHOT_HEAP(Vector2);
417 SNAPSHOT_HEAP(Vector3);
418 SNAPSHOT_HEAP(Vector4);
419 SNAPSHOT_HEAP(InlineVector);
420 SNAPSHOT_HEAP(HashTable);
421 SNAPSHOT_HEAP(LargeObject);
422 FOR_EACH_TYPED_HEAP(SNAPSHOT_HEAP);
423
424 #undef SNAPSHOT_FREE_LIST
Primiano Tucci (use gerrit) 2015/05/21 09:56:33 I think you meant to undef SNAPSHOT_HEAP here :)
ssid 2015/05/21 11:38:55 Done.
425
426 // TODO(ssid): Request global dump from blink when support is available.
427 }
428
383 #if ENABLE(GC_PROFILING) 429 #if ENABLE(GC_PROFILING)
384 const GCInfo* ThreadState::findGCInfo(Address address) 430 const GCInfo* ThreadState::findGCInfo(Address address)
385 { 431 {
386 if (BasePage* page = findPageFromAddress(address)) 432 if (BasePage* page = findPageFromAddress(address))
387 return page->findGCInfo(address); 433 return page->findGCInfo(address);
388 return nullptr; 434 return nullptr;
389 } 435 }
390 436
391 size_t ThreadState::SnapshotInfo::getClassTag(const GCInfo* gcInfo) 437 size_t ThreadState::SnapshotInfo::getClassTag(const GCInfo* gcInfo)
392 { 438 {
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after
835 makeConsistentForSweeping(); 881 makeConsistentForSweeping();
836 prepareRegionTree(); 882 prepareRegionTree();
837 flushHeapDoesNotContainCacheIfNeeded(); 883 flushHeapDoesNotContainCacheIfNeeded();
838 clearHeapAges(); 884 clearHeapAges();
839 } 885 }
840 886
841 void ThreadState::postGC(GCType gcType) 887 void ThreadState::postGC(GCType gcType)
842 { 888 {
843 ASSERT(isInGC()); 889 ASSERT(isInGC());
844 890
891 snapshotMemoryIfNecessary();
845 #if ENABLE(GC_PROFILING) 892 #if ENABLE(GC_PROFILING)
846 // We snapshot the heap prior to sweeping to get numbers for both resources 893 // 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 894 // that have been allocated since the last GC and for resources that are
848 // going to be freed. 895 // going to be freed.
849 bool gcTracingEnabled; 896 bool gcTracingEnabled;
850 TRACE_EVENT_CATEGORY_GROUP_ENABLED("blink_gc", &gcTracingEnabled); 897 TRACE_EVENT_CATEGORY_GROUP_ENABLED("blink_gc", &gcTracingEnabled);
851 898
852 if (gcTracingEnabled) { 899 if (gcTracingEnabled) {
853 bool disabledByDefaultGCTracingEnabled; 900 bool disabledByDefaultGCTracingEnabled;
854 TRACE_EVENT_CATEGORY_GROUP_ENABLED(TRACE_DISABLED_BY_DEFAULT("blink_gc") , &disabledByDefaultGCTracingEnabled); 901 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); 1263 m_vectorBackingHeapIndex = heapIndexOfVectorHeapLeastRecentlyExpanded(Ve ctor1HeapIndex, Vector4HeapIndex);
1217 } 1264 }
1218 1265
1219 void ThreadState::promptlyFreed(size_t gcInfoIndex) 1266 void ThreadState::promptlyFreed(size_t gcInfoIndex)
1220 { 1267 {
1221 size_t entryIndex = gcInfoIndex & likelyToBePromptlyFreedArrayMask; 1268 size_t entryIndex = gcInfoIndex & likelyToBePromptlyFreedArrayMask;
1222 // See the comment in vectorBackingHeap() for why this is +3. 1269 // See the comment in vectorBackingHeap() for why this is +3.
1223 m_likelyToBePromptlyFreed[entryIndex] += 3; 1270 m_likelyToBePromptlyFreed[entryIndex] += 3;
1224 } 1271 }
1225 1272
1273 bool ThreadState::onMemoryDump(WebProcessMemoryDump* memoryDump)
1274 {
1275 // Returns true because it might be able to provide dump in future. On
1276 // returning false, the memory dump manager stops collecting dumps from
1277 // this provider.
1278 if (!m_lastProcessMemoryDump.get())
1279 return true;
1280
1281 // TODO(ssid): Swap the memory dumps once the support is available.
1282 // memoryDump->swap(m_lastProcessMemoryDump.get());
Primiano Tucci (use gerrit) 2015/05/21 09:56:33 The code is not fully there yet, but the final nam
ssid 2015/05/21 11:38:55 Done.
1283 return true;
1284 }
1285
1226 #if ENABLE(GC_PROFILING) 1286 #if ENABLE(GC_PROFILING)
1227 const GCInfo* ThreadState::findGCInfoFromAllThreads(Address address) 1287 const GCInfo* ThreadState::findGCInfoFromAllThreads(Address address)
1228 { 1288 {
1229 bool needLockForIteration = !ThreadState::current()->isInGC(); 1289 bool needLockForIteration = !ThreadState::current()->isInGC();
1230 if (needLockForIteration) 1290 if (needLockForIteration)
1231 threadAttachMutex().lock(); 1291 threadAttachMutex().lock();
1232 1292
1233 for (ThreadState* state : attachedThreads()) { 1293 for (ThreadState* state : attachedThreads()) {
1234 if (const GCInfo* gcInfo = state->findGCInfo(address)) { 1294 if (const GCInfo* gcInfo = state->findGCInfo(address)) {
1235 if (needLockForIteration) 1295 if (needLockForIteration)
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1306 json->beginArray(it->key.ascii().data()); 1366 json->beginArray(it->key.ascii().data());
1307 for (size_t age = 0; age <= maxHeapObjectAge; ++age) 1367 for (size_t age = 0; age <= maxHeapObjectAge; ++age)
1308 json->pushInteger(it->value.ages[age]); 1368 json->pushInteger(it->value.ages[age]);
1309 json->endArray(); 1369 json->endArray();
1310 } 1370 }
1311 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID(TRACE_DISABLED_BY_DEFAULT("blink_gc"), s tatsName, this, json.release()); 1371 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID(TRACE_DISABLED_BY_DEFAULT("blink_gc"), s tatsName, this, json.release());
1312 } 1372 }
1313 #endif 1373 #endif
1314 1374
1315 } // namespace blink 1375 } // namespace blink
OLDNEW
« Source/platform/heap/Heap.cpp ('K') | « Source/platform/heap/ThreadState.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698