| Index: Source/platform/heap/ThreadState.cpp
|
| diff --git a/Source/platform/heap/ThreadState.cpp b/Source/platform/heap/ThreadState.cpp
|
| index 4464337e0a7ab72205a1541375f3a0e3c127b320..07a905dc1152e580865ab2d55050877702a58f8d 100644
|
| --- a/Source/platform/heap/ThreadState.cpp
|
| +++ b/Source/platform/heap/ThreadState.cpp
|
| @@ -39,6 +39,10 @@
|
| #include "public/platform/Platform.h"
|
| #include "wtf/ThreadingPrimitives.h"
|
|
|
| +#if GC_PROFILE_HEAP
|
| +#include "platform/TracedValue.h"
|
| +#endif
|
| +
|
| #if OS(WIN)
|
| #include <stddef.h>
|
| #include <windows.h>
|
| @@ -531,7 +535,7 @@ bool ThreadState::checkAndMarkPointer(Visitor* visitor, Address address)
|
| return false;
|
| }
|
|
|
| -#if ENABLE(GC_TRACING)
|
| +#if GC_PROFILE_MARKING
|
| const GCInfo* ThreadState::findGCInfo(Address address)
|
| {
|
| BaseHeapPage* page = heapPageFromAddress(address);
|
| @@ -542,6 +546,67 @@ const GCInfo* ThreadState::findGCInfo(Address address)
|
| }
|
| #endif
|
|
|
| +#if GC_PROFILE_HEAP
|
| +size_t ThreadState::SnapshotInfo::getClassTag(const GCInfo* gcinfo)
|
| +{
|
| + HashMap<const GCInfo*, size_t>::AddResult result = classTags.add(gcinfo, classTags.size());
|
| + if (result.isNewEntry) {
|
| + liveCount.append(0);
|
| + deadCount.append(0);
|
| + generations.append(Vector<int, 8>());
|
| + generations.last().fill(0, 8);
|
| + }
|
| + return result.storedValue->value;
|
| +}
|
| +
|
| +void ThreadState::snapshot()
|
| +{
|
| + SnapshotInfo info(this);
|
| + TracedValue json;
|
| +
|
| +#define SNAPSHOT_HEAP(HeapType) \
|
| + { \
|
| + TracedDictionaryBase& jsonHeap = heaps.beginDictionary(); \
|
| + jsonHeap.setString("name", #HeapType); \
|
| + m_heaps[HeapType##Heap]->snapshot(&jsonHeap, &info); \
|
| + jsonHeap.endDictionary(); \
|
| + }
|
| + TracedArrayBase& heaps = json.beginArray("heaps");
|
| + SNAPSHOT_HEAP(General);
|
| + FOR_EACH_TYPED_HEAP(SNAPSHOT_HEAP);
|
| + heaps.endArray();
|
| +#undef SNAPSHOT_HEAP
|
| +
|
| + json.setInteger("allocatedSpace", m_stats.totalAllocatedSpace())
|
| + .setInteger("objectSpace", m_stats.totalObjectSpace())
|
| + .setInteger("liveSize", info.liveSize)
|
| + .setInteger("deadSize", info.deadSize)
|
| + .setInteger("freeSize", info.freeSize)
|
| + .setInteger("pageCount", info.freeSize);
|
| +
|
| + Vector<String> classNameVector(info.classTags.size());
|
| + for (HashMap<const GCInfo*, size_t>::iterator it = info.classTags.begin(); it != info.classTags.end(); ++it)
|
| + classNameVector[it->value] = it->key->m_className;
|
| +
|
| + TracedArrayBase& jsonClasses = json.beginArray("classes");
|
| + for (size_t i = 0; i < classNameVector.size(); ++i) {
|
| + TracedDictionaryBase& jsonClass = jsonClasses.beginDictionary();
|
| + jsonClass
|
| + .setString("name", classNameVector[i])
|
| + .setInteger("liveCount", info.liveCount[i])
|
| + .setInteger("deadCount", info.deadCount[i]);
|
| + TracedArrayBase& jsonGens = jsonClass.beginArray("generations");
|
| + for (size_t j = 0; j < heapObjectGenerations; ++j)
|
| + jsonGens.pushInteger(info.generations[i][j]);
|
| + jsonGens.endArray();
|
| + jsonClass.endDictionary();
|
| + }
|
| + jsonClasses.endArray();
|
| +
|
| + TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID(GC_PROFILE_GROUP, "ThreadState", this, json.finish());
|
| +}
|
| +#endif
|
| +
|
| void ThreadState::pushWeakObjectPointerCallback(void* object, WeakPointerCallback callback)
|
| {
|
| CallbackStack::Item* slot = m_weakCallbackStack->allocateEntry(&m_weakCallbackStack);
|
| @@ -837,6 +902,16 @@ void ThreadState::performPendingSweep()
|
| if (!sweepRequested())
|
| return;
|
|
|
| +#if GC_PROFILE_HEAP
|
| + // We snapshot the heap prior to sweeping to get numbers for both resources
|
| + // that have been allocated since the last GC and for resources that are
|
| + // going to be freed.
|
| + bool gcTracingEnabled;
|
| + TRACE_EVENT_CATEGORY_GROUP_ENABLED(GC_PROFILE_GROUP, &gcTracingEnabled);
|
| + if (gcTracingEnabled && m_stats.totalObjectSpace() > 0)
|
| + snapshot();
|
| +#endif
|
| +
|
| TRACE_EVENT0("blink", "ThreadState::performPendingSweep");
|
| ScriptForbiddenScope forbiddenScope;
|
|
|
| @@ -904,7 +979,7 @@ ThreadState::AttachedThreadStateSet& ThreadState::attachedThreads()
|
| return threads;
|
| }
|
|
|
| -#if ENABLE(GC_TRACING)
|
| +#if GC_PROFILE_MARKING
|
| const GCInfo* ThreadState::findGCInfoFromAllThreads(Address address)
|
| {
|
| bool needLockForIteration = !isAnyThreadInGC();
|
| @@ -924,4 +999,5 @@ const GCInfo* ThreadState::findGCInfoFromAllThreads(Address address)
|
| return 0;
|
| }
|
| #endif
|
| +
|
| }
|
|
|