Chromium Code Reviews| Index: Source/platform/heap/ThreadState.cpp |
| diff --git a/Source/platform/heap/ThreadState.cpp b/Source/platform/heap/ThreadState.cpp |
| index 1b20f981cf9b388edb60b2582881add495171f4b..784924a3fe46444620742bb0ef4e973b6234c2bb 100644 |
| --- a/Source/platform/heap/ThreadState.cpp |
| +++ b/Source/platform/heap/ThreadState.cpp |
| @@ -39,6 +39,8 @@ |
| #include "platform/heap/Heap.h" |
| #include "platform/heap/SafePoint.h" |
| #include "public/platform/Platform.h" |
| +#include "public/platform/WebMemoryAllocatorDump.h" |
| +#include "public/platform/WebProcessMemoryDump.h" |
| #include "public/platform/WebScheduler.h" |
| #include "public/platform/WebThread.h" |
| #include "public/platform/WebTraceLocation.h" |
| @@ -127,10 +129,16 @@ ThreadState::ThreadState() |
| clearHeapAges(); |
| m_weakCallbackStack = new CallbackStack(); |
| + |
| + if (Platform::current()->currentThread()) |
| + Platform::current()->registerMemoryDumpProvider(this); |
| } |
| ThreadState::~ThreadState() |
| { |
| + if (Platform::current()->currentThread()) |
| + Platform::current()->unregisterMemoryDumpProvider(this); |
| + |
| 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.
|
| delete m_weakCallbackStack; |
| m_weakCallbackStack = nullptr; |
| @@ -380,6 +388,44 @@ void ThreadState::visitPersistents(Visitor* visitor) |
| } |
| } |
| +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.
|
| +{ |
| + bool enabled; |
| + 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?
|
| + if (!enabled) |
| + return; |
| + |
| + snapshotMemory(); |
| +} |
| + |
| +void ThreadState::snapshotMemory() |
| +{ |
| + // TODO(ssid): uncomment the following line once the support is available, |
| + // and remove the check for dump being null. |
| + // m_lastProcessMemoryDump.reset(Platform::current()->getExtraProcessMemoryDump()); |
|
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
|
| + if (!m_lastProcessMemoryDump.get()) |
| + return; |
| + |
| +#define SNAPSHOT_HEAP(HeapType) m_heaps[HeapType##HeapIndex]->snapshotMemory(m_lastProcessMemoryDump.get(), #HeapType); |
| + |
| + SNAPSHOT_HEAP(NormalPage1); |
| + SNAPSHOT_HEAP(NormalPage2); |
| + SNAPSHOT_HEAP(NormalPage3); |
| + SNAPSHOT_HEAP(NormalPage4); |
| + SNAPSHOT_HEAP(Vector1); |
| + SNAPSHOT_HEAP(Vector2); |
| + SNAPSHOT_HEAP(Vector3); |
| + SNAPSHOT_HEAP(Vector4); |
| + SNAPSHOT_HEAP(InlineVector); |
| + SNAPSHOT_HEAP(HashTable); |
| + SNAPSHOT_HEAP(LargeObject); |
| + FOR_EACH_TYPED_HEAP(SNAPSHOT_HEAP); |
| + |
| +#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.
|
| + |
| + // TODO(ssid): Request global dump from blink when support is available. |
| +} |
| + |
| #if ENABLE(GC_PROFILING) |
| const GCInfo* ThreadState::findGCInfo(Address address) |
| { |
| @@ -842,6 +888,7 @@ void ThreadState::postGC(GCType gcType) |
| { |
| ASSERT(isInGC()); |
| + snapshotMemoryIfNecessary(); |
| #if ENABLE(GC_PROFILING) |
| // 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 |
| @@ -1223,6 +1270,19 @@ void ThreadState::promptlyFreed(size_t gcInfoIndex) |
| m_likelyToBePromptlyFreed[entryIndex] += 3; |
| } |
| +bool ThreadState::onMemoryDump(WebProcessMemoryDump* memoryDump) |
| +{ |
| + // Returns true because it might be able to provide dump in future. On |
| + // returning false, the memory dump manager stops collecting dumps from |
| + // this provider. |
| + if (!m_lastProcessMemoryDump.get()) |
| + return true; |
| + |
| + // TODO(ssid): Swap the memory dumps once the support is available. |
| + // 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.
|
| + return true; |
| +} |
| + |
| #if ENABLE(GC_PROFILING) |
| const GCInfo* ThreadState::findGCInfoFromAllThreads(Address address) |
| { |