Index: Source/platform/heap/Heap.cpp |
diff --git a/Source/platform/heap/Heap.cpp b/Source/platform/heap/Heap.cpp |
index 07121670b6793aedaf07b52f4f173d29bc178aea..b643e27ce4039ab4d4705198daf80a5f352b1ab4 100644 |
--- a/Source/platform/heap/Heap.cpp |
+++ b/Source/platform/heap/Heap.cpp |
@@ -49,7 +49,7 @@ |
#include <stdio.h> |
#include <utility> |
#endif |
-#if ENABLE(GC_PROFILE_HEAP) |
+#if ENABLE(GC_PROFILE_HEAP) || ENABLE(GC_PROFILE_FREE_LIST) || ENABLE(GC_PROFILE_MARKING) |
#include "platform/TracedValue.h" |
#endif |
@@ -62,6 +62,36 @@ |
namespace blink { |
+struct AgeHistogram { |
+ int data[8]; |
+}; |
+ |
+typedef HashMap<String, AgeHistogram> ObjectAgeMap; |
+ |
+static ObjectAgeMap& uom() |
+{ |
+ static ObjectAgeMap uomap; |
+ return uomap; |
+} |
+ |
+static Mutex& uomMutex() |
+{ |
+ AtomicallyInitializedStatic(Mutex&, mutex = *new Mutex); |
+ return mutex; |
+} |
+ |
+static ObjectAgeMap& mom() |
+{ |
+ static ObjectAgeMap momap; |
+ return momap; |
+} |
+ |
+static Mutex& momMutex() |
+{ |
+ AtomicallyInitializedStatic(Mutex&, mutex = *new Mutex); |
+ return mutex; |
+} |
+ |
#if ENABLE(GC_PROFILE_MARKING) |
static String classOf(const void* object) |
{ |
@@ -641,6 +671,11 @@ ThreadHeap<Header>::ThreadHeap(ThreadState* state, int index) |
: m_currentAllocationPoint(0) |
, m_remainingAllocationSize(0) |
, m_lastRemainingAllocationSize(0) |
+#if ENABLE(GC_PROFILE_FREE_LIST) |
+ , m_totalAllocationSize(0.0) |
+ , m_allocationCount(0) |
+ , m_inlineAllocationCount(0) |
+#endif |
, m_firstPage(0) |
, m_firstLargeObject(0) |
, m_firstPageAllocatedDuringSweeping(0) |
@@ -700,6 +735,9 @@ void ThreadHeap<Header>::updateRemainingAllocationSize() |
template<typename Header> |
Address ThreadHeap<Header>::outOfLineAllocate(size_t payloadSize, size_t allocationSize, const GCInfo* gcInfo) |
{ |
+#if ENABLE(GC_PROFILE_FREE_LIST) |
+ m_threadState->snapshotFreeListIfNecessary(); |
+#endif |
ASSERT(allocationSize > remainingAllocationSize()); |
if (allocationSize > blinkPageSize / 2) |
return allocateLargeObject(allocationSize, gcInfo); |
@@ -799,6 +837,45 @@ const GCInfo* ThreadHeap<Header>::findGCInfoOfLargeObject(Address address) |
} |
#endif |
+#if ENABLE(GC_PROFILE_FREE_LIST) |
+template<typename Header> |
+void ThreadHeap<Header>::snapshotFreeList(TracedValue* json) |
+{ |
+ json->setDouble("totalAllocationSize", m_totalAllocationSize); |
+ json->setDouble("inlineAllocationRate", static_cast<double>(m_inlineAllocationCount) / m_allocationCount); |
+ json->setInteger("inlineAllocationCount", m_inlineAllocationCount); |
+ json->setInteger("allocationCount", m_allocationCount); |
+ if (m_setAllocationPointCount > 0) { |
+ json->setDouble("averageAllocationPointSize", static_cast<double>(m_allocationPointSizeSum) / m_setAllocationPointCount); |
+ } |
+ m_allocationPointSizeSum = 0; |
+ m_setAllocationPointCount = 0; |
+ size_t pageCount = 0; |
+ size_t totalPageSize = 0; |
+ for (HeapPage<Header>* page = m_firstPage; page; page = page->next()) { |
+ ++pageCount; |
+ totalPageSize += page->payloadSize(); |
+ } |
+ json->setInteger("pageCount", pageCount); |
+ json->setInteger("totalPageSize", totalPageSize); |
+ size_t bucketSizes[blinkPageSizeLog2]; |
+ size_t bucketTotalSizes[blinkPageSizeLog2]; |
+ size_t freeSize = 0; |
+ m_freeList.countBucketSizes(bucketSizes, bucketTotalSizes, &freeSize); |
+ json->setInteger("freeSize", freeSize); |
+ json->beginArray("bucketSizes"); |
+ for (size_t i = 0; i < blinkPageSizeLog2; ++i) { |
+ json->pushInteger(bucketSizes[i]); |
+ } |
+ json->endArray(); |
+ json->beginArray("bucketTotalSizes"); |
+ for (size_t i = 0; i < blinkPageSizeLog2; ++i) { |
+ json->pushInteger(bucketTotalSizes[i]); |
+ } |
+ json->endArray(); |
+} |
+#endif |
+ |
#if ENABLE(GC_PROFILE_HEAP) |
#define GC_PROFILE_HEAP_PAGE_SNAPSHOT_THRESHOLD 0 |
template<typename Header> |
@@ -866,6 +943,25 @@ void FreeList<Header>::addToFreeList(Address address, size_t size) |
m_biggestFreeListIndex = index; |
} |
+#if ENABLE(GC_PROFILE_FREE_LIST) |
+template<typename Header> |
+void FreeList<Header>::countBucketSizes(size_t sizes[], size_t totalSizes[], size_t* freeSize) const |
+{ |
+ *freeSize = 0; |
+ for (size_t i = 0; i < blinkPageSizeLog2; i++) { |
+ sizes[i] = 0; |
+ totalSizes[i] = 0; |
+ FreeListEntry* entry = m_freeLists[i]; |
+ while (entry) { |
+ ++sizes[i]; |
+ *freeSize += entry->size(); |
+ totalSizes[i] += entry->size(); |
+ entry = entry->next(); |
+ } |
+ } |
+} |
+#endif |
+ |
template<typename Header> |
bool ThreadHeap<Header>::expandObject(Header* header, size_t newSize) |
{ |
@@ -1444,6 +1540,9 @@ void ThreadHeap<Header>::sweepLargePages() |
template<typename Header> |
void ThreadHeap<Header>::sweep() |
{ |
+ for (HeapPage<Header>* page = m_firstPage; page; page = page->next()) { |
+ page->countUnmarkedObjects(); |
+ } |
ASSERT(isConsistentForSweeping()); |
#if defined(ADDRESS_SANITIZER) && STRICT_ASAN_FINALIZATION_CHECKING |
// When using ASan do a pre-sweep where all unmarked objects are |
@@ -1835,6 +1934,23 @@ void HeapPage<Header>::poisonUnmarkedObjects() |
} |
#endif |
+template<typename Header> |
+void HeapPage<Header>::countUnmarkedObjects() |
+{ |
+ MutexLocker locker(uomMutex()); |
+ for (Address headerAddress = payload(); headerAddress < end(); ) { |
+ Header* header = reinterpret_cast<Header*>(headerAddress); |
+ ASSERT(header->size() < blinkPagePayloadSize()); |
+ |
+ if (!header->isFree() && !header->isMarked()) { |
+ String className(classOf(header->payload())); |
+ ObjectAgeMap::AddResult result = uom().add(className, AgeHistogram()); |
+ result.storedValue->value.data[header->age()]++; |
+ } |
+ headerAddress += header->size(); |
+ } |
+} |
+ |
template<> |
inline void HeapPage<FinalizedHeapObjectHeader>::finalize(FinalizedHeapObjectHeader* header) |
{ |
@@ -1996,12 +2112,19 @@ public: |
return; |
header->mark(); |
#if ENABLE(GC_PROFILE_MARKING) |
+ header->incAge(); |
+ |
MutexLocker locker(objectGraphMutex()); |
String className(classOf(objectPointer)); |
{ |
LiveObjectMap::AddResult result = currentlyLive().add(className, LiveObjectSet()); |
result.storedValue->value.add(reinterpret_cast<uintptr_t>(objectPointer)); |
} |
+ { |
+ MutexLocker locker(momMutex()); |
+ ObjectAgeMap::AddResult result = mom().add(className, AgeHistogram()); |
+ result.storedValue->value.data[header->age()]++; |
+ } |
ObjectGraph::AddResult result = objectGraph().add(reinterpret_cast<uintptr_t>(objectPointer), std::make_pair(reinterpret_cast<uintptr_t>(m_hostObject), m_hostName)); |
ASSERT(result.isNewEntry); |
// fprintf(stderr, "%s[%p] -> %s[%p]\n", m_hostName.ascii().data(), m_hostObject, className.ascii().data(), objectPointer); |
@@ -2098,6 +2221,21 @@ public: |
} |
} |
+ void reportMarkingStats() |
+ { |
+ MutexLocker locker(momMutex()); |
+ RefPtr<TracedValue> json = TracedValue::create(); |
+ for (ObjectAgeMap::iterator it = mom().begin(), end = mom().end(); it != end; ++it) { |
+ json->beginArray(it->key.ascii().data()); |
+ for (size_t i = 0; i < 8; ++i) { |
+ json->pushInteger(it->value.data[i]); |
+ } |
+ json->endArray(); |
+ } |
+ TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID("blink_gc", "MarkingStats", (unsigned long long)0, json.release()); |
+ mom().clear(); |
+ } |
+ |
static void reportStillAlive(LiveObjectSet current, LiveObjectSet previous) |
{ |
int count = 0; |
@@ -2455,11 +2593,30 @@ void Heap::prepareForGC() |
(*it)->prepareForGC(); |
} |
+void Heap::reportSweepingStats() |
+{ |
+ MutexLocker locker(uomMutex()); |
+ RefPtr<TracedValue> json = TracedValue::create(); |
+ for (ObjectAgeMap::iterator it = uom().begin(), end = uom().end(); it != end; ++it) { |
+ json->beginArray(it->key.ascii().data()); |
+ for (size_t i = 0; i < 8; ++i) { |
+ json->pushInteger(it->value.data[i]); |
+ } |
+ json->endArray(); |
+ } |
+ TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID("blink_gc", "SweepingStats", (unsigned long long)0, json.release()); |
+ uom().clear(); |
+} |
+ |
void Heap::collectGarbage(ThreadState::StackState stackState, ThreadState::CauseOfGC cause) |
{ |
ThreadState* state = ThreadState::current(); |
state->clearGCRequested(); |
+#if ENABLE(GC_PROFILE_FREE_LIST) |
+ state->snapshotFreeListIfNecessary(); |
+#endif |
+ |
GCScope gcScope(stackState); |
// Check if we successfully parked the other threads. If not we bail out of the GC. |
if (!gcScope.allThreadsParked()) { |
@@ -2517,7 +2674,8 @@ void Heap::collectGarbage(ThreadState::StackState stackState, ThreadState::Cause |
orphanedPagePool()->decommitOrphanedPages(); |
#if ENABLE(GC_PROFILE_MARKING) |
- static_cast<MarkingVisitor*>(s_markingVisitor)->reportStats(); |
+ //static_cast<MarkingVisitor*>(s_markingVisitor)->reportStats(); |
+ static_cast<MarkingVisitor*>(s_markingVisitor)->reportMarkingStats(); |
#endif |
if (Platform::current()) { |