| Index: src/profiler/heap-snapshot-generator.cc
|
| diff --git a/src/profiler/heap-snapshot-generator.cc b/src/profiler/heap-snapshot-generator.cc
|
| index c84892b069d6a7c28b3224136bbf35a6759fee0e..f62129726643d267bdf6fb0c790949c711eeb6a7 100644
|
| --- a/src/profiler/heap-snapshot-generator.cc
|
| +++ b/src/profiler/heap-snapshot-generator.cc
|
| @@ -4,6 +4,8 @@
|
|
|
| #include "src/profiler/heap-snapshot-generator.h"
|
|
|
| +#include <utility>
|
| +
|
| #include "src/code-stubs.h"
|
| #include "src/conversions.h"
|
| #include "src/debug/debug.h"
|
| @@ -2287,55 +2289,52 @@ int NativeObjectsExplorer::EstimateObjectsCount() {
|
|
|
| void NativeObjectsExplorer::FillRetainedObjects() {
|
| if (embedder_queried_) return;
|
| - Isolate* isolate = isolate_;
|
| - const GCType major_gc_type = kGCTypeMarkSweepCompact;
|
| - // Record objects that are joined into ObjectGroups.
|
| - isolate->heap()->CallGCPrologueCallbacks(
|
| - major_gc_type, kGCCallbackFlagConstructRetainedObjectInfos);
|
| - List<ObjectGroup*>* groups = isolate->global_handles()->object_groups();
|
| - for (int i = 0; i < groups->length(); ++i) {
|
| - ObjectGroup* group = groups->at(i);
|
| - if (group->info == NULL) continue;
|
| - List<HeapObject*>* list = GetListMaybeDisposeInfo(group->info);
|
| - for (size_t j = 0; j < group->length; ++j) {
|
| - HeapObject* obj = HeapObject::cast(*group->objects[j]);
|
| - list->Add(obj);
|
| - in_groups_.Insert(obj);
|
| + v8::HandleScope scope(reinterpret_cast<v8::Isolate*>(isolate_));
|
| + v8::HeapProfiler::RetainerInfos infos =
|
| + snapshot_->profiler()->GetRetainerInfos(isolate_);
|
| + for (auto& pair : infos.groups) {
|
| + List<HeapObject*>* list = GetListMaybeDisposeInfo(pair.first);
|
| + for (auto& persistent : pair.second) {
|
| + if (persistent->IsEmpty()) continue;
|
| +
|
| + Handle<Object> object = v8::Utils::OpenHandle(
|
| + *persistent->Get(reinterpret_cast<v8::Isolate*>(isolate_)));
|
| + DCHECK(!object.is_null());
|
| + HeapObject* heap_object = HeapObject::cast(*object);
|
| + list->Add(heap_object);
|
| + in_groups_.Insert(heap_object);
|
| }
|
| - group->info = NULL; // Acquire info object ownership.
|
| }
|
| - isolate->global_handles()->RemoveObjectGroups();
|
| - isolate->heap()->CallGCEpilogueCallbacks(major_gc_type, kNoGCCallbackFlags);
|
| +
|
| // Record objects that are not in ObjectGroups, but have class ID.
|
| GlobalHandlesExtractor extractor(this);
|
| - isolate->global_handles()->IterateAllRootsWithClassIds(&extractor);
|
| + isolate_->global_handles()->IterateAllRootsWithClassIds(&extractor);
|
| +
|
| + edges_ = std::move(infos.edges);
|
| embedder_queried_ = true;
|
| }
|
|
|
| +void NativeObjectsExplorer::FillEdges() {
|
| + v8::HandleScope scope(reinterpret_cast<v8::Isolate*>(isolate_));
|
| + // Fill in actual edges found.
|
| + for (auto& pair : edges_) {
|
| + if (pair.first->IsEmpty() || pair.second->IsEmpty()) continue;
|
|
|
| -void NativeObjectsExplorer::FillImplicitReferences() {
|
| - Isolate* isolate = isolate_;
|
| - List<ImplicitRefGroup*>* groups =
|
| - isolate->global_handles()->implicit_ref_groups();
|
| - for (int i = 0; i < groups->length(); ++i) {
|
| - ImplicitRefGroup* group = groups->at(i);
|
| - HeapObject* parent = *group->parent;
|
| + Handle<Object> parent_object = v8::Utils::OpenHandle(
|
| + *pair.first->Get(reinterpret_cast<v8::Isolate*>(isolate_)));
|
| + HeapObject* parent = HeapObject::cast(*parent_object);
|
| int parent_entry =
|
| filler_->FindOrAddEntry(parent, native_entries_allocator_)->index();
|
| DCHECK(parent_entry != HeapEntry::kNoEntry);
|
| - Object*** children = group->children;
|
| - for (size_t j = 0; j < group->length; ++j) {
|
| - Object* child = *children[j];
|
| - HeapEntry* child_entry =
|
| - filler_->FindOrAddEntry(child, native_entries_allocator_);
|
| - filler_->SetNamedReference(
|
| - HeapGraphEdge::kInternal,
|
| - parent_entry,
|
| - "native",
|
| - child_entry);
|
| - }
|
| + Handle<Object> child_object = v8::Utils::OpenHandle(
|
| + *pair.second->Get(reinterpret_cast<v8::Isolate*>(isolate_)));
|
| + HeapObject* child = HeapObject::cast(*child_object);
|
| + HeapEntry* child_entry =
|
| + filler_->FindOrAddEntry(child, native_entries_allocator_);
|
| + filler_->SetNamedReference(HeapGraphEdge::kInternal, parent_entry, "native",
|
| + child_entry);
|
| }
|
| - isolate->global_handles()->RemoveImplicitRefGroups();
|
| + edges_.clear();
|
| }
|
|
|
| List<HeapObject*>* NativeObjectsExplorer::GetListMaybeDisposeInfo(
|
| @@ -2355,7 +2354,7 @@ bool NativeObjectsExplorer::IterateAndExtractReferences(
|
| SnapshotFiller* filler) {
|
| filler_ = filler;
|
| FillRetainedObjects();
|
| - FillImplicitReferences();
|
| + FillEdges();
|
| if (EstimateObjectsCount() > 0) {
|
| for (base::HashMap::Entry* p = objects_by_info_.Start(); p != NULL;
|
| p = objects_by_info_.Next(p)) {
|
|
|