Index: third_party/WebKit/Source/bindings/core/v8/V8GCController.cpp |
diff --git a/third_party/WebKit/Source/bindings/core/v8/V8GCController.cpp b/third_party/WebKit/Source/bindings/core/v8/V8GCController.cpp |
index 6ded783a981de097db3e6563388ac6f197bae47a..f5df87e500e46bd5cb030265d4bc500f4acefb5a 100644 |
--- a/third_party/WebKit/Source/bindings/core/v8/V8GCController.cpp |
+++ b/third_party/WebKit/Source/bindings/core/v8/V8GCController.cpp |
@@ -51,6 +51,7 @@ |
#include "wtf/Vector.h" |
#include "wtf/allocator/Partitions.h" |
#include <algorithm> |
+#include <unordered_set> |
haraken
2017/01/12 16:25:17
Remove this? You're using WTF::HashSet.
Michael Lippautz
2017/01/13 15:08:40
I rewrote now everything using std:: types which c
|
namespace blink { |
@@ -148,6 +149,121 @@ class MinorGCUnmodifiedWrapperVisitor : public v8::PersistentHandleVisitor { |
v8::Isolate* m_isolate; |
}; |
+class HeapSnaphotWrapperVisitor : public ScriptWrappableVisitor { |
+ public: |
+ explicit HeapSnaphotWrapperVisitor(v8::Isolate* isolate) |
+ : ScriptWrappableVisitor(isolate) {} |
+ |
+ // Trace through the blink heap to find all V8 wrappers reachable from |
+ // ActiveScriptWrappables. |
+ v8::HeapProfiler::RetainerChildren findPendingWrappers() { |
+ m_foundV8Wrappers.clear(); |
+ |
+ TracePrologue(); |
+ ActiveScriptWrappableBase::traceActiveScriptWrappables(m_isolate, this); |
+ AdvanceTracing( |
+ 0, |
+ v8::EmbedderHeapTracer::AdvanceTracingActions( |
+ v8::EmbedderHeapTracer::ForceCompletionAction::FORCE_COMPLETION)); |
+ // Abort instead of Epilogue as we want to finish synchronously. |
+ AbortTracing(); |
+ |
+ return std::move(m_foundV8Wrappers); |
+ } |
+ |
+ // Trace through the blink heap to find all V8 wrappers reachable from |
+ // |traceable|. |
+ v8::HeapProfiler::RetainerChildren findV8WrappersReachableFrom( |
+ ScriptWrappable* traceable) { |
+ m_foundV8Wrappers.clear(); |
+ |
+ TracePrologue(); |
+ traceable->wrapperTypeInfo()->traceWrappers(this, traceable); |
+ AdvanceTracing( |
+ 0, |
+ v8::EmbedderHeapTracer::AdvanceTracingActions( |
+ v8::EmbedderHeapTracer::ForceCompletionAction::FORCE_COMPLETION)); |
+ // Abort instead of Epilogue as we want to finish synchronously. |
+ AbortTracing(); |
+ |
+ return std::move(m_foundV8Wrappers); |
+ } |
+ |
+ void markWrapper(const v8::PersistentBase<v8::Value>* value) const override { |
+ if (!m_tracingInProgress) |
+ return; |
+ m_foundV8Wrappers.insert(value); |
+ } |
+ |
+ private: |
+ mutable v8::HeapProfiler::RetainerChildren m_foundV8Wrappers; |
+}; |
+ |
+class HeapSnapshotHandlesVisitor : public v8::PersistentHandleVisitor { |
haraken
2017/01/12 16:25:17
In short term, this is fine, but I'm not sure if i
Michael Lippautz
2017/01/13 15:08:40
See general comment.
|
+ public: |
+ explicit HeapSnapshotHandlesVisitor(v8::Isolate* isolate) |
+ : m_isolate(isolate) {} |
+ |
+ void VisitPersistentHandle(v8::Persistent<v8::Value>* value, |
+ uint16_t classId) override { |
+ if (classId != WrapperTypeInfo::NodeClassId && |
+ classId != WrapperTypeInfo::ObjectClassId) |
haraken
2017/01/12 16:25:17
Remove '&& classId != WrapperTypeInfo::ObjectClass
Michael Lippautz
2017/01/13 15:08:40
Done.
|
+ return; |
+ |
+ if (value->IsIndependent()) |
haraken
2017/01/12 16:25:17
DCHECK(!value->IsIndependent()). Nodes should be d
Michael Lippautz
2017/01/13 15:08:40
Done.
|
+ return; |
+ |
+ if (classId == WrapperTypeInfo::NodeClassId) { |
haraken
2017/01/12 16:25:17
Remove the if statement.
Michael Lippautz
2017/01/13 15:08:40
Done.
|
+ v8::Local<v8::Object> wrapper = v8::Local<v8::Object>::New( |
+ m_isolate, v8::Persistent<v8::Object>::Cast(*value)); |
+ DCHECK(V8Node::hasInstance(wrapper, m_isolate)); |
+ Node* node = V8Node::toImpl(wrapper); |
+ Node* root = V8GCController::opaqueRootForGC(m_isolate, node); |
+ m_nodesRequiringTracing.add(root); |
+ } |
+ } |
+ |
+ WTF::HashSet<UntracedMember<Node>> nodesRequiringTracing() { |
+ return std::move(m_nodesRequiringTracing); |
haraken
2017/01/12 16:25:17
It might be clearer to use std::unique_ptr<WTF::Ha
Michael Lippautz
2017/01/13 15:08:40
Doesn't apply anymore.
|
+ } |
+ |
+ private: |
+ v8::Isolate* m_isolate; |
+ WTF::HashSet<UntracedMember<Node>> m_nodesRequiringTracing; |
+}; |
+ |
+v8::HeapProfiler::RetainerInfos V8GCController::getRetainerInfos( |
+ v8::Isolate* isolate) { |
+ v8::HeapProfiler::RetainerInfos infos; |
+ HeapSnaphotWrapperVisitor tracer(isolate); |
+ V8PerIsolateData::TemporaryScriptWrappableVisitorScope scope(isolate, |
+ &tracer); |
+ |
+ // Find wrappers for pending activities. |
+ { |
+ v8::HeapProfiler::RetainerChildren wrappers = tracer.findPendingWrappers(); |
+ if (!wrappers.empty()) { |
+ infos.push_back(std::make_pair( |
+ new SuspendableObjectsInfo(wrappers.size()), std::move(wrappers))); |
+ } |
+ } |
+ |
+ // Find wrappers for DOM trees. |
+ { |
+ HeapSnapshotHandlesVisitor visitor(isolate); |
+ isolate->VisitHandlesWithClassIds(&visitor); |
haraken
2017/01/12 16:25:17
Why can't we use |&tracer|?
Michael Lippautz
2017/01/13 15:08:40
Rewrote that tracer so that it implements both req
|
+ for (auto root : visitor.nodesRequiringTracing()) { |
+ auto wrappers = tracer.findV8WrappersReachableFrom(root); |
+ if (!wrappers.empty()) { |
+ infos.push_back( |
+ std::make_pair(new RetainedDOMInfo(root), std::move(wrappers))); |
+ } |
+ } |
+ } |
+ |
+ return infos; |
+} |
+ |
class MajorGCWrapperVisitor : public v8::PersistentHandleVisitor { |
public: |
explicit MajorGCWrapperVisitor(v8::Isolate* isolate, |