From d7ec9ab06123038d8da9c0b0464d9b407985c102 Mon Sep 17 00:00:00 2001 From: "yurys@chromium.org" Date: Thu, 13 Mar 2014 07:48:42 +0000 Subject: [PATCH] Remove SnapshotFillerInterface There used to be additional pass in the heap profiler that estimated memory required for the snapshot and it used special implementation of the interface. Now that we dropped that step it doesn't makes sense to keep the interface with single implementation. BUG=None LOG=N R=loislo@chromium.org, mstarzinger@chromium.org Review URL: https://codereview.chromium.org/194503002 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@19875 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/heap-snapshot-generator.cc | 126 ++++++++++++++++++++--------------------- src/heap-snapshot-generator.h | 39 +++---------- 2 files changed, 70 insertions(+), 95 deletions(-) diff --git a/src/heap-snapshot-generator.cc b/src/heap-snapshot-generator.cc index aa28d07..a7c1c2e 100644 --- a/src/heap-snapshot-generator.cc +++ b/src/heap-snapshot-generator.cc @@ -927,10 +927,68 @@ HeapEntry* V8HeapExplorer::AddEntry(Address address, } +class SnapshotFiller { + public: + explicit SnapshotFiller(HeapSnapshot* snapshot, HeapEntriesMap* entries) + : snapshot_(snapshot), + names_(snapshot->profiler()->names()), + entries_(entries) { } + HeapEntry* AddEntry(HeapThing ptr, HeapEntriesAllocator* allocator) { + HeapEntry* entry = allocator->AllocateEntry(ptr); + entries_->Pair(ptr, entry->index()); + return entry; + } + HeapEntry* FindEntry(HeapThing ptr) { + int index = entries_->Map(ptr); + return index != HeapEntry::kNoEntry ? &snapshot_->entries()[index] : NULL; + } + HeapEntry* FindOrAddEntry(HeapThing ptr, HeapEntriesAllocator* allocator) { + HeapEntry* entry = FindEntry(ptr); + return entry != NULL ? entry : AddEntry(ptr, allocator); + } + void SetIndexedReference(HeapGraphEdge::Type type, + int parent, + int index, + HeapEntry* child_entry) { + HeapEntry* parent_entry = &snapshot_->entries()[parent]; + parent_entry->SetIndexedReference(type, index, child_entry); + } + void SetIndexedAutoIndexReference(HeapGraphEdge::Type type, + int parent, + HeapEntry* child_entry) { + HeapEntry* parent_entry = &snapshot_->entries()[parent]; + int index = parent_entry->children_count() + 1; + parent_entry->SetIndexedReference(type, index, child_entry); + } + void SetNamedReference(HeapGraphEdge::Type type, + int parent, + const char* reference_name, + HeapEntry* child_entry) { + HeapEntry* parent_entry = &snapshot_->entries()[parent]; + parent_entry->SetNamedReference(type, reference_name, child_entry); + } + void SetNamedAutoIndexReference(HeapGraphEdge::Type type, + int parent, + HeapEntry* child_entry) { + HeapEntry* parent_entry = &snapshot_->entries()[parent]; + int index = parent_entry->children_count() + 1; + parent_entry->SetNamedReference( + type, + names_->GetName(index), + child_entry); + } + + private: + HeapSnapshot* snapshot_; + StringsStorage* names_; + HeapEntriesMap* entries_; +}; + + class GcSubrootsEnumerator : public ObjectVisitor { public: GcSubrootsEnumerator( - SnapshotFillerInterface* filler, V8HeapExplorer* explorer) + SnapshotFiller* filler, V8HeapExplorer* explorer) : filler_(filler), explorer_(explorer), previous_object_count_(0), @@ -947,14 +1005,14 @@ class GcSubrootsEnumerator : public ObjectVisitor { } } private: - SnapshotFillerInterface* filler_; + SnapshotFiller* filler_; V8HeapExplorer* explorer_; intptr_t previous_object_count_; intptr_t object_count_; }; -void V8HeapExplorer::AddRootEntries(SnapshotFillerInterface* filler) { +void V8HeapExplorer::AddRootEntries(SnapshotFiller* filler) { filler->AddEntry(kInternalRootObject, this); filler->AddEntry(kGcRootsObject, this); GcSubrootsEnumerator enumerator(filler, this); @@ -1764,7 +1822,7 @@ class RootsReferencesExtractor : public ObjectVisitor { bool V8HeapExplorer::IterateAndExtractReferences( - SnapshotFillerInterface* filler) { + SnapshotFiller* filler) { filler_ = filler; // Make sure builtin code objects get their builtin tags @@ -2275,7 +2333,7 @@ List* NativeObjectsExplorer::GetListMaybeDisposeInfo( bool NativeObjectsExplorer::IterateAndExtractReferences( - SnapshotFillerInterface* filler) { + SnapshotFiller* filler) { filler_ = filler; FillRetainedObjects(); FillImplicitReferences(); @@ -2402,64 +2460,6 @@ void NativeObjectsExplorer::VisitSubtreeWrapper(Object** p, uint16_t class_id) { } -class SnapshotFiller : public SnapshotFillerInterface { - public: - explicit SnapshotFiller(HeapSnapshot* snapshot, HeapEntriesMap* entries) - : snapshot_(snapshot), - names_(snapshot->profiler()->names()), - entries_(entries) { } - HeapEntry* AddEntry(HeapThing ptr, HeapEntriesAllocator* allocator) { - HeapEntry* entry = allocator->AllocateEntry(ptr); - entries_->Pair(ptr, entry->index()); - return entry; - } - HeapEntry* FindEntry(HeapThing ptr) { - int index = entries_->Map(ptr); - return index != HeapEntry::kNoEntry ? &snapshot_->entries()[index] : NULL; - } - HeapEntry* FindOrAddEntry(HeapThing ptr, HeapEntriesAllocator* allocator) { - HeapEntry* entry = FindEntry(ptr); - return entry != NULL ? entry : AddEntry(ptr, allocator); - } - void SetIndexedReference(HeapGraphEdge::Type type, - int parent, - int index, - HeapEntry* child_entry) { - HeapEntry* parent_entry = &snapshot_->entries()[parent]; - parent_entry->SetIndexedReference(type, index, child_entry); - } - void SetIndexedAutoIndexReference(HeapGraphEdge::Type type, - int parent, - HeapEntry* child_entry) { - HeapEntry* parent_entry = &snapshot_->entries()[parent]; - int index = parent_entry->children_count() + 1; - parent_entry->SetIndexedReference(type, index, child_entry); - } - void SetNamedReference(HeapGraphEdge::Type type, - int parent, - const char* reference_name, - HeapEntry* child_entry) { - HeapEntry* parent_entry = &snapshot_->entries()[parent]; - parent_entry->SetNamedReference(type, reference_name, child_entry); - } - void SetNamedAutoIndexReference(HeapGraphEdge::Type type, - int parent, - HeapEntry* child_entry) { - HeapEntry* parent_entry = &snapshot_->entries()[parent]; - int index = parent_entry->children_count() + 1; - parent_entry->SetNamedReference( - type, - names_->GetName(index), - child_entry); - } - - private: - HeapSnapshot* snapshot_; - StringsStorage* names_; - HeapEntriesMap* entries_; -}; - - HeapSnapshotGenerator::HeapSnapshotGenerator( HeapSnapshot* snapshot, v8::ActivityControl* control, diff --git a/src/heap-snapshot-generator.h b/src/heap-snapshot-generator.h index 87c3909..634ede1 100644 --- a/src/heap-snapshot-generator.h +++ b/src/heap-snapshot-generator.h @@ -37,6 +37,7 @@ class AllocationTracker; class AllocationTraceNode; class HeapEntry; class HeapSnapshot; +class SnapshotFiller; class HeapGraphEdge BASE_EMBEDDED { public: @@ -343,32 +344,6 @@ class HeapObjectsSet { }; -// An interface used to populate a snapshot with nodes and edges. -class SnapshotFillerInterface { - public: - virtual ~SnapshotFillerInterface() { } - virtual HeapEntry* AddEntry(HeapThing ptr, - HeapEntriesAllocator* allocator) = 0; - virtual HeapEntry* FindEntry(HeapThing ptr) = 0; - virtual HeapEntry* FindOrAddEntry(HeapThing ptr, - HeapEntriesAllocator* allocator) = 0; - virtual void SetIndexedReference(HeapGraphEdge::Type type, - int parent_entry, - int index, - HeapEntry* child_entry) = 0; - virtual void SetIndexedAutoIndexReference(HeapGraphEdge::Type type, - int parent_entry, - HeapEntry* child_entry) = 0; - virtual void SetNamedReference(HeapGraphEdge::Type type, - int parent_entry, - const char* reference_name, - HeapEntry* child_entry) = 0; - virtual void SetNamedAutoIndexReference(HeapGraphEdge::Type type, - int parent_entry, - HeapEntry* child_entry) = 0; -}; - - class SnapshottingProgressReportingInterface { public: virtual ~SnapshottingProgressReportingInterface() { } @@ -385,9 +360,9 @@ class V8HeapExplorer : public HeapEntriesAllocator { v8::HeapProfiler::ObjectNameResolver* resolver); virtual ~V8HeapExplorer(); virtual HeapEntry* AllocateEntry(HeapThing ptr); - void AddRootEntries(SnapshotFillerInterface* filler); + void AddRootEntries(SnapshotFiller* filler); int EstimateObjectsCount(HeapIterator* iterator); - bool IterateAndExtractReferences(SnapshotFillerInterface* filler); + bool IterateAndExtractReferences(SnapshotFiller* filler); void TagGlobalObjects(); void TagCodeObject(Code* code); void TagBuiltinCodeObject(Code* code, const char* name); @@ -488,7 +463,7 @@ class V8HeapExplorer : public HeapEntriesAllocator { StringsStorage* names_; HeapObjectsMap* heap_object_map_; SnapshottingProgressReportingInterface* progress_; - SnapshotFillerInterface* filler_; + SnapshotFiller* filler_; HeapObjectsSet objects_tags_; HeapObjectsSet strong_gc_subroot_names_; HeapObjectsSet user_roots_; @@ -515,9 +490,9 @@ class NativeObjectsExplorer { NativeObjectsExplorer(HeapSnapshot* snapshot, SnapshottingProgressReportingInterface* progress); virtual ~NativeObjectsExplorer(); - void AddRootEntries(SnapshotFillerInterface* filler); + void AddRootEntries(SnapshotFiller* filler); int EstimateObjectsCount(); - bool IterateAndExtractReferences(SnapshotFillerInterface* filler); + bool IterateAndExtractReferences(SnapshotFiller* filler); private: void FillRetainedObjects(); @@ -557,7 +532,7 @@ class NativeObjectsExplorer { HeapEntriesAllocator* synthetic_entries_allocator_; HeapEntriesAllocator* native_entries_allocator_; // Used during references extraction. - SnapshotFillerInterface* filler_; + SnapshotFiller* filler_; static HeapThing const kNativesRootObject; -- 2.7.4