| 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 15 matching lines...) Expand all Loading... |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 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/BlinkGCMemoryDumpProvider.h" |
| 36 #include "platform/heap/CallbackStack.h" | 37 #include "platform/heap/CallbackStack.h" |
| 37 #include "platform/heap/Handle.h" | 38 #include "platform/heap/Handle.h" |
| 38 #include "platform/heap/Heap.h" | 39 #include "platform/heap/Heap.h" |
| 39 #include "platform/heap/MarkingVisitor.h" | 40 #include "platform/heap/MarkingVisitor.h" |
| 40 #include "platform/heap/SafePoint.h" | 41 #include "platform/heap/SafePoint.h" |
| 41 #include "public/platform/Platform.h" | 42 #include "public/platform/Platform.h" |
| 43 #include "public/platform/WebMemoryAllocatorDump.h" |
| 44 #include "public/platform/WebProcessMemoryDump.h" |
| 42 #include "public/platform/WebScheduler.h" | 45 #include "public/platform/WebScheduler.h" |
| 43 #include "public/platform/WebThread.h" | 46 #include "public/platform/WebThread.h" |
| 44 #include "public/platform/WebTraceLocation.h" | 47 #include "public/platform/WebTraceLocation.h" |
| 45 #include "wtf/Partitions.h" | 48 #include "wtf/Partitions.h" |
| 46 #include "wtf/ThreadingPrimitives.h" | 49 #include "wtf/ThreadingPrimitives.h" |
| 47 #if ENABLE(GC_PROFILING) | 50 #if ENABLE(GC_PROFILING) |
| 48 #include "platform/TracedValue.h" | 51 #include "platform/TracedValue.h" |
| 49 #include "wtf/text/StringHash.h" | 52 #include "wtf/text/StringHash.h" |
| 50 #endif | 53 #endif |
| 51 | 54 |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 | 373 |
| 371 void ThreadState::visitPersistents(Visitor* visitor) | 374 void ThreadState::visitPersistents(Visitor* visitor) |
| 372 { | 375 { |
| 373 m_persistentRegion->tracePersistentNodes(visitor); | 376 m_persistentRegion->tracePersistentNodes(visitor); |
| 374 if (m_traceDOMWrappers) { | 377 if (m_traceDOMWrappers) { |
| 375 TRACE_EVENT0("blink_gc", "V8GCController::traceDOMWrappers"); | 378 TRACE_EVENT0("blink_gc", "V8GCController::traceDOMWrappers"); |
| 376 m_traceDOMWrappers(m_isolate, visitor); | 379 m_traceDOMWrappers(m_isolate, visitor); |
| 377 } | 380 } |
| 378 } | 381 } |
| 379 | 382 |
| 383 ThreadState::GCSnapshotInfo::GCSnapshotInfo(size_t numObjectTypes) |
| 384 : liveCount(Vector<int>(numObjectTypes)) |
| 385 , deadCount(Vector<int>(numObjectTypes)) |
| 386 , liveSize(Vector<size_t>(numObjectTypes)) |
| 387 , deadSize(Vector<size_t>(numObjectTypes)) |
| 388 { |
| 389 } |
| 390 |
| 380 #if ENABLE(GC_PROFILING) | 391 #if ENABLE(GC_PROFILING) |
| 381 const GCInfo* ThreadState::findGCInfo(Address address) | 392 const GCInfo* ThreadState::findGCInfo(Address address) |
| 382 { | 393 { |
| 383 if (BasePage* page = findPageFromAddress(address)) | 394 if (BasePage* page = findPageFromAddress(address)) |
| 384 return page->findGCInfo(address); | 395 return page->findGCInfo(address); |
| 385 return nullptr; | 396 return nullptr; |
| 386 } | 397 } |
| 387 | 398 |
| 388 size_t ThreadState::SnapshotInfo::getClassTag(const GCInfo* gcInfo) | 399 size_t ThreadState::SnapshotInfo::getClassTag(const GCInfo* gcInfo) |
| 389 { | 400 { |
| (...skipping 1012 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1402 ASSERT(checkThread()); | 1413 ASSERT(checkThread()); |
| 1403 size_t entryIndex = gcInfoIndex & likelyToBePromptlyFreedArrayMask; | 1414 size_t entryIndex = gcInfoIndex & likelyToBePromptlyFreedArrayMask; |
| 1404 // See the comment in vectorBackingHeap() for why this is +3. | 1415 // See the comment in vectorBackingHeap() for why this is +3. |
| 1405 m_likelyToBePromptlyFreed[entryIndex] += 3; | 1416 m_likelyToBePromptlyFreed[entryIndex] += 3; |
| 1406 } | 1417 } |
| 1407 | 1418 |
| 1408 void ThreadState::takeSnapshot(SnapshotType type) | 1419 void ThreadState::takeSnapshot(SnapshotType type) |
| 1409 { | 1420 { |
| 1410 ASSERT(isInGC()); | 1421 ASSERT(isInGC()); |
| 1411 | 1422 |
| 1423 // 0 is used as index for freelist entries. Objects are indexed 1 to |
| 1424 // gcInfoIndex. |
| 1425 GCSnapshotInfo info(GCInfoTable::gcInfoIndex() + 1); |
| 1426 String threadDumpName = String::format("blink_gc/thread_%lu", static_cast<un
signed long>(m_thread)); |
| 1427 const String heapsDumpName = threadDumpName + "/heaps"; |
| 1428 const String classesDumpName = threadDumpName + "/classes"; |
| 1429 |
| 1412 int numberOfHeapsReported = 0; | 1430 int numberOfHeapsReported = 0; |
| 1413 #define SNAPSHOT_HEAP(HeapType)
\ | 1431 #define SNAPSHOT_HEAP(HeapType)
\ |
| 1414 {
\ | 1432 {
\ |
| 1415 numberOfHeapsReported++;
\ | 1433 numberOfHeapsReported++;
\ |
| 1416 String allocatorBaseName;
\ | 1434 switch (type) {
\ |
| 1417 allocatorBaseName = String::format("blink_gc/thread_%lu/heaps/" #HeapTyp
e, (unsigned long)(m_thread)); \ | 1435 case SnapshotType::HeapSnapshot:
\ |
| 1418 switch (type) {
\ | 1436 m_heaps[HeapType##HeapIndex]->takeSnapshot(heapsDumpName + "/" #Heap
Type, info); \ |
| 1419 case SnapshotType::HeapSnapshot:
\ | 1437 break;
\ |
| 1420 m_heaps[HeapType##HeapIndex]->takeSnapshot(allocatorBaseName);
\ | 1438 case SnapshotType::FreelistSnapshot:
\ |
| 1421 break;
\ | 1439 m_heaps[HeapType##HeapIndex]->takeFreelistSnapshot(heapsDumpName + "
/" #HeapType); \ |
| 1422 case SnapshotType::FreelistSnapshot:
\ | 1440 break;
\ |
| 1423 m_heaps[HeapType##HeapIndex]->takeFreelistSnapshot(allocatorBaseName
); \ | 1441 default:
\ |
| 1424 break;
\ | 1442 ASSERT_NOT_REACHED();
\ |
| 1425 default:
\ | 1443 }
\ |
| 1426 ASSERT_NOT_REACHED();
\ | |
| 1427 }
\ | |
| 1428 } | 1444 } |
| 1429 | 1445 |
| 1430 SNAPSHOT_HEAP(NormalPage1); | 1446 SNAPSHOT_HEAP(NormalPage1); |
| 1431 SNAPSHOT_HEAP(NormalPage2); | 1447 SNAPSHOT_HEAP(NormalPage2); |
| 1432 SNAPSHOT_HEAP(NormalPage3); | 1448 SNAPSHOT_HEAP(NormalPage3); |
| 1433 SNAPSHOT_HEAP(NormalPage4); | 1449 SNAPSHOT_HEAP(NormalPage4); |
| 1434 SNAPSHOT_HEAP(EagerSweep); | 1450 SNAPSHOT_HEAP(EagerSweep); |
| 1435 SNAPSHOT_HEAP(Vector1); | 1451 SNAPSHOT_HEAP(Vector1); |
| 1436 SNAPSHOT_HEAP(Vector2); | 1452 SNAPSHOT_HEAP(Vector2); |
| 1437 SNAPSHOT_HEAP(Vector3); | 1453 SNAPSHOT_HEAP(Vector3); |
| 1438 SNAPSHOT_HEAP(Vector4); | 1454 SNAPSHOT_HEAP(Vector4); |
| 1439 SNAPSHOT_HEAP(InlineVector); | 1455 SNAPSHOT_HEAP(InlineVector); |
| 1440 SNAPSHOT_HEAP(HashTable); | 1456 SNAPSHOT_HEAP(HashTable); |
| 1441 SNAPSHOT_HEAP(LargeObject); | 1457 SNAPSHOT_HEAP(LargeObject); |
| 1442 FOR_EACH_TYPED_HEAP(SNAPSHOT_HEAP); | 1458 FOR_EACH_TYPED_HEAP(SNAPSHOT_HEAP); |
| 1443 | 1459 |
| 1444 ASSERT(numberOfHeapsReported == NumberOfHeaps); | 1460 ASSERT(numberOfHeapsReported == NumberOfHeaps); |
| 1445 | 1461 |
| 1446 #undef SNAPSHOT_HEAP | 1462 #undef SNAPSHOT_HEAP |
| 1463 |
| 1464 if (type == SnapshotType::FreelistSnapshot) |
| 1465 return; |
| 1466 |
| 1467 size_t totalLiveCount = 0; |
| 1468 size_t totalDeadCount = 0; |
| 1469 size_t totalLiveSize = 0; |
| 1470 size_t totalDeadSize = 0; |
| 1471 for (size_t i = 1; i <= GCInfoTable::gcInfoIndex(); ++i) { |
| 1472 String dumpName = classesDumpName + "/" + Heap::gcInfo(i)->className(); |
| 1473 WebMemoryAllocatorDump* classDump = BlinkGCMemoryDumpProvider::instance(
)->createMemoryAllocatorDumpForCurrentGC(dumpName); |
| 1474 classDump->AddScalar("live_count", "objects", info.liveCount[i]); |
| 1475 classDump->AddScalar("dead_count", "objects", info.deadCount[i]); |
| 1476 classDump->AddScalar("live_size", "bytes", info.liveSize[i]); |
| 1477 classDump->AddScalar("dead_size", "bytes", info.deadSize[i]); |
| 1478 |
| 1479 totalLiveCount += info.liveCount[i]; |
| 1480 totalDeadCount += info.deadCount[i]; |
| 1481 totalLiveSize += info.liveSize[i]; |
| 1482 totalDeadSize += info.deadSize[i]; |
| 1483 } |
| 1484 |
| 1485 WebMemoryAllocatorDump* threadDump = BlinkGCMemoryDumpProvider::instance()->
createMemoryAllocatorDumpForCurrentGC(threadDumpName); |
| 1486 threadDump->AddScalar("live_count", "objects", totalLiveCount); |
| 1487 threadDump->AddScalar("dead_count", "objects", totalDeadCount); |
| 1488 threadDump->AddScalar("live_size", "bytes", totalLiveSize); |
| 1489 threadDump->AddScalar("dead_size", "bytes", totalDeadSize); |
| 1490 |
| 1491 WebMemoryAllocatorDump* heapsDump = BlinkGCMemoryDumpProvider::instance()->c
reateMemoryAllocatorDumpForCurrentGC(heapsDumpName); |
| 1492 WebMemoryAllocatorDump* classesDump = BlinkGCMemoryDumpProvider::instance()-
>createMemoryAllocatorDumpForCurrentGC(classesDumpName); |
| 1493 BlinkGCMemoryDumpProvider::instance()->currentProcessMemoryDump()->AddOwners
hipEdge(classesDump->guid(), heapsDump->guid()); |
| 1447 } | 1494 } |
| 1448 | 1495 |
| 1449 #if ENABLE(GC_PROFILING) | 1496 #if ENABLE(GC_PROFILING) |
| 1450 const GCInfo* ThreadState::findGCInfoFromAllThreads(Address address) | 1497 const GCInfo* ThreadState::findGCInfoFromAllThreads(Address address) |
| 1451 { | 1498 { |
| 1452 bool needLockForIteration = !ThreadState::current()->isInGC(); | 1499 bool needLockForIteration = !ThreadState::current()->isInGC(); |
| 1453 if (needLockForIteration) | 1500 if (needLockForIteration) |
| 1454 threadAttachMutex().lock(); | 1501 threadAttachMutex().lock(); |
| 1455 | 1502 |
| 1456 for (ThreadState* state : attachedThreads()) { | 1503 for (ThreadState* state : attachedThreads()) { |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1536 json->beginArray(it->key.ascii().data()); | 1583 json->beginArray(it->key.ascii().data()); |
| 1537 for (size_t age = 0; age <= maxHeapObjectAge; ++age) | 1584 for (size_t age = 0; age <= maxHeapObjectAge; ++age) |
| 1538 json->pushInteger(it->value.ages[age]); | 1585 json->pushInteger(it->value.ages[age]); |
| 1539 json->endArray(); | 1586 json->endArray(); |
| 1540 } | 1587 } |
| 1541 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID(TRACE_DISABLED_BY_DEFAULT("blink_gc"), s
tatsName, this, json.release()); | 1588 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID(TRACE_DISABLED_BY_DEFAULT("blink_gc"), s
tatsName, this, json.release()); |
| 1542 } | 1589 } |
| 1543 #endif | 1590 #endif |
| 1544 | 1591 |
| 1545 } // namespace blink | 1592 } // namespace blink |
| OLD | NEW |