Commit 4894bbd4 authored by mlippautz's avatar mlippautz Committed by Commit bot

[profiler] Query retainer infos from embedder instead of using object grouping

BUG=chromium:679724

Review-Url: https://codereview.chromium.org/2627033002
Cr-Commit-Position: refs/heads/master@{#42628}
parent db1de41a
......@@ -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)) {
......
......@@ -496,7 +496,7 @@ class NativeObjectsExplorer {
private:
void FillRetainedObjects();
void FillImplicitReferences();
void FillEdges();
List<HeapObject*>* GetListMaybeDisposeInfo(v8::RetainedObjectInfo* info);
void SetNativeRootReference(v8::RetainedObjectInfo* info);
void SetRootNativeRootsReference();
......@@ -532,6 +532,7 @@ class NativeObjectsExplorer {
HeapEntriesAllocator* native_entries_allocator_;
// Used during references extraction.
SnapshotFiller* filler_;
v8::HeapProfiler::RetainerEdges edges_;
static HeapThing const kNativesRootObject;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment