Commit 7e6d6285 authored by Ulan Degenbaev's avatar Ulan Degenbaev Committed by Commit Bot

[heap-profiler] Simplify snapshotting of the roots.

This replaces three passes over the roots with a single pass.
This also removes root synchronization logic.

The GC subroot index is computed from the |root| parameter of the visit
method. The new |description| parameter is used as an edge name.

Bug: chromium:811842
Change-Id: I03a9215d56b54b3eb5f7bc8b32d5b22ad091c68b
Reviewed-on: https://chromium-review.googlesource.com/916781Reviewed-by: 's avatarAlexei Filippov <alph@chromium.org>
Commit-Queue: Ulan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#51350}
parent ba37a5f6
...@@ -86,8 +86,9 @@ Builtins::Name Builtins::GetBuiltinFromBailoutId(BailoutId id) { ...@@ -86,8 +86,9 @@ Builtins::Name Builtins::GetBuiltinFromBailoutId(BailoutId id) {
void Builtins::TearDown() { initialized_ = false; } void Builtins::TearDown() { initialized_ = false; }
void Builtins::IterateBuiltins(RootVisitor* v) { void Builtins::IterateBuiltins(RootVisitor* v) {
v->VisitRootPointers(Root::kBuiltins, nullptr, &builtins_[0], for (int i = 0; i < builtin_count; i++) {
&builtins_[0] + builtin_count); v->VisitRootPointer(Root::kBuiltins, name(i), &builtins_[i]);
}
} }
const char* Builtins::Lookup(byte* pc) { const char* Builtins::Lookup(byte* pc) {
......
...@@ -907,6 +907,13 @@ void GlobalHandles::IterateStrongRoots(RootVisitor* v) { ...@@ -907,6 +907,13 @@ void GlobalHandles::IterateStrongRoots(RootVisitor* v) {
} }
} }
void GlobalHandles::IterateWeakRoots(RootVisitor* v) {
for (NodeIterator it(this); !it.done(); it.Advance()) {
if (it.node()->IsWeak()) {
v->VisitRootPointer(Root::kGlobalHandles, nullptr, it.node()->location());
}
}
}
DISABLE_CFI_PERF DISABLE_CFI_PERF
void GlobalHandles::IterateAllRoots(RootVisitor* v) { void GlobalHandles::IterateAllRoots(RootVisitor* v) {
......
...@@ -108,10 +108,10 @@ class GlobalHandles { ...@@ -108,10 +108,10 @@ class GlobalHandles {
int PostGarbageCollectionProcessing( int PostGarbageCollectionProcessing(
GarbageCollector collector, const v8::GCCallbackFlags gc_callback_flags); GarbageCollector collector, const v8::GCCallbackFlags gc_callback_flags);
// Iterates over all strong handles.
void IterateStrongRoots(RootVisitor* v); void IterateStrongRoots(RootVisitor* v);
// Iterates over all handles. void IterateWeakRoots(RootVisitor* v);
void IterateAllRoots(RootVisitor* v); void IterateAllRoots(RootVisitor* v);
void IterateAllNewSpaceRoots(RootVisitor* v); void IterateAllNewSpaceRoots(RootVisitor* v);
......
...@@ -462,30 +462,6 @@ bool Heap::IsRetainingPathTarget(HeapObject* object, ...@@ -462,30 +462,6 @@ bool Heap::IsRetainingPathTarget(HeapObject* object,
return false; return false;
} }
namespace {
const char* RootToString(Root root) {
switch (root) {
#define ROOT_CASE(root_id, ignore, description) \
case Root::root_id: \
return description;
ROOT_ID_LIST(ROOT_CASE)
#undef ROOT_CASE
case Root::kCodeFlusher:
return "(Code flusher)";
case Root::kPartialSnapshotCache:
return "(Partial snapshot cache)";
case Root::kWeakCollections:
return "(Weak collections)";
case Root::kWrapperTracing:
return "(Wrapper tracing)";
case Root::kUnknown:
return "(Unknown)";
}
UNREACHABLE();
return nullptr;
}
} // namespace
void Heap::PrintRetainingPath(HeapObject* target, RetainingPathOption option) { void Heap::PrintRetainingPath(HeapObject* target, RetainingPathOption option) {
PrintF("\n\n\n"); PrintF("\n\n\n");
PrintF("#################################################\n"); PrintF("#################################################\n");
...@@ -528,7 +504,7 @@ void Heap::PrintRetainingPath(HeapObject* target, RetainingPathOption option) { ...@@ -528,7 +504,7 @@ void Heap::PrintRetainingPath(HeapObject* target, RetainingPathOption option) {
} }
PrintF("\n"); PrintF("\n");
PrintF("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n"); PrintF("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
PrintF("Root: %s\n", RootToString(root)); PrintF("Root: %s\n", RootVisitor::RootName(root));
PrintF("-------------------------------------------------\n"); PrintF("-------------------------------------------------\n");
} }
...@@ -5146,6 +5122,9 @@ void Heap::IterateStrongRoots(RootVisitor* v, VisitMode mode) { ...@@ -5146,6 +5122,9 @@ void Heap::IterateStrongRoots(RootVisitor* v, VisitMode mode) {
} }
} }
void Heap::IterateWeakGlobalHandles(RootVisitor* v) {
isolate_->global_handles()->IterateWeakRoots(v);
}
// TODO(1236194): Since the heap size is configurable on the command line // TODO(1236194): Since the heap size is configurable on the command line
// and through the API, we should gracefully handle the case that the heap // and through the API, we should gracefully handle the case that the heap
......
...@@ -1167,15 +1167,15 @@ class Heap { ...@@ -1167,15 +1167,15 @@ class Heap {
// Iterators. ================================================================ // Iterators. ================================================================
// =========================================================================== // ===========================================================================
// Iterates over all roots in the heap.
void IterateRoots(RootVisitor* v, VisitMode mode); void IterateRoots(RootVisitor* v, VisitMode mode);
// Iterates over all strong roots in the heap.
void IterateStrongRoots(RootVisitor* v, VisitMode mode); void IterateStrongRoots(RootVisitor* v, VisitMode mode);
// Iterates over entries in the smi roots list. Only interesting to the // Iterates over entries in the smi roots list. Only interesting to the
// serializer/deserializer, since GC does not care about smis. // serializer/deserializer, since GC does not care about smis.
void IterateSmiRoots(RootVisitor* v); void IterateSmiRoots(RootVisitor* v);
// Iterates over all the other roots in the heap. // Iterates over weak string tables.
void IterateWeakRoots(RootVisitor* v, VisitMode mode); void IterateWeakRoots(RootVisitor* v, VisitMode mode);
// Iterates over weak global handles.
void IterateWeakGlobalHandles(RootVisitor* v);
// =========================================================================== // ===========================================================================
// Store buffer API. ========================================================= // Store buffer API. =========================================================
......
This diff is collapsed.
...@@ -165,8 +165,8 @@ class HeapSnapshot { ...@@ -165,8 +165,8 @@ class HeapSnapshot {
HeapProfiler* profiler() { return profiler_; } HeapProfiler* profiler() { return profiler_; }
HeapEntry* root() { return &entries_[root_index_]; } HeapEntry* root() { return &entries_[root_index_]; }
HeapEntry* gc_roots() { return &entries_[gc_roots_index_]; } HeapEntry* gc_roots() { return &entries_[gc_roots_index_]; }
HeapEntry* gc_subroot(int index) { HeapEntry* gc_subroot(Root root) {
return &entries_[gc_subroot_indexes_[index]]; return &entries_[gc_subroot_indexes_[static_cast<int>(root)]];
} }
std::vector<HeapEntry>& entries() { return entries_; } std::vector<HeapEntry>& entries() { return entries_; }
std::deque<HeapGraphEdge>& edges() { return edges_; } std::deque<HeapGraphEdge>& edges() { return edges_; }
...@@ -191,12 +191,12 @@ class HeapSnapshot { ...@@ -191,12 +191,12 @@ class HeapSnapshot {
private: private:
HeapEntry* AddRootEntry(); HeapEntry* AddRootEntry();
HeapEntry* AddGcRootsEntry(); HeapEntry* AddGcRootsEntry();
HeapEntry* AddGcSubrootEntry(int tag, SnapshotObjectId id); HeapEntry* AddGcSubrootEntry(Root root, SnapshotObjectId id);
HeapProfiler* profiler_; HeapProfiler* profiler_;
int root_index_; int root_index_;
int gc_roots_index_; int gc_roots_index_;
int gc_subroot_indexes_[VisitorSynchronization::kNumberOfSyncTags]; int gc_subroot_indexes_[static_cast<int>(Root::kNumberOfRoots)];
std::vector<HeapEntry> entries_; std::vector<HeapEntry> entries_;
std::deque<HeapGraphEdge> edges_; std::deque<HeapGraphEdge> edges_;
std::deque<HeapGraphEdge*> children_; std::deque<HeapGraphEdge*> children_;
...@@ -445,9 +445,9 @@ class V8HeapExplorer : public HeapEntriesAllocator { ...@@ -445,9 +445,9 @@ class V8HeapExplorer : public HeapEntriesAllocator {
void SetUserGlobalReference(Object* user_global); void SetUserGlobalReference(Object* user_global);
void SetRootGcRootsReference(); void SetRootGcRootsReference();
void SetGcRootsReference(VisitorSynchronization::SyncTag tag); void SetGcRootsReference(Root root);
void SetGcSubrootReference( void SetGcSubrootReference(Root root, const char* description, bool is_weak,
VisitorSynchronization::SyncTag tag, bool is_weak, Object* child); Object* child);
const char* GetStrongGcSubrootName(Object* object); const char* GetStrongGcSubrootName(Object* object);
void TagObject(Object* obj, const char* tag); void TagObject(Object* obj, const char* tag);
void TagFixedArraySubType(const FixedArray* array, void TagFixedArraySubType(const FixedArray* array,
......
...@@ -9,16 +9,19 @@ ...@@ -9,16 +9,19 @@
namespace v8 { namespace v8 {
namespace internal { namespace internal {
#define DECLARE_TAG(ignore1, name, ignore2) name, const char* RootVisitor::RootName(Root root) {
const char* const switch (root) {
VisitorSynchronization::kTags[VisitorSynchronization::kNumberOfSyncTags] = { #define ROOT_CASE(root_id, description) \
ROOT_ID_LIST(DECLARE_TAG)}; case Root::root_id: \
#undef DECLARE_TAG return description;
ROOT_ID_LIST(ROOT_CASE)
#define DECLARE_TAG(ignore1, ignore2, name) name, #undef ROOT_CASE
const char* const VisitorSynchronization::kTagNames case Root::kNumberOfRoots:
[VisitorSynchronization::kNumberOfSyncTags] = {ROOT_ID_LIST(DECLARE_TAG)}; break;
#undef DECLARE_TAG }
UNREACHABLE();
return nullptr;
}
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8
...@@ -13,45 +13,42 @@ namespace internal { ...@@ -13,45 +13,42 @@ namespace internal {
class CodeDataContainer; class CodeDataContainer;
class Object; class Object;
#define ROOT_ID_LIST(V) \ #define ROOT_ID_LIST(V) \
V(kStringTable, "string_table", "(Internalized strings)") \ V(kStringTable, "(Internalized strings)") \
V(kExternalStringsTable, "external_strings_table", "(External strings)") \ V(kExternalStringsTable, "(External strings)") \
V(kStrongRootList, "strong_root_list", "(Strong roots)") \ V(kStrongRootList, "(Strong roots)") \
V(kSmiRootList, "smi_root_list", "(Smi roots)") \ V(kSmiRootList, "(Smi roots)") \
V(kBootstrapper, "bootstrapper", "(Bootstrapper)") \ V(kBootstrapper, "(Bootstrapper)") \
V(kTop, "top", "(Isolate)") \ V(kTop, "(Isolate)") \
V(kRelocatable, "relocatable", "(Relocatable)") \ V(kRelocatable, "(Relocatable)") \
V(kDebug, "debug", "(Debugger)") \ V(kDebug, "(Debugger)") \
V(kCompilationCache, "compilationcache", "(Compilation cache)") \ V(kCompilationCache, "(Compilation cache)") \
V(kHandleScope, "handlescope", "(Handle scope)") \ V(kHandleScope, "(Handle scope)") \
V(kDispatchTable, "dispatchtable", "(Dispatch table)") \ V(kDispatchTable, "(Dispatch table)") \
V(kBuiltins, "builtins", "(Builtins)") \ V(kBuiltins, "(Builtins)") \
V(kGlobalHandles, "globalhandles", "(Global handles)") \ V(kGlobalHandles, "(Global handles)") \
V(kEternalHandles, "eternalhandles", "(Eternal handles)") \ V(kEternalHandles, "(Eternal handles)") \
V(kThreadManager, "threadmanager", "(Thread manager)") \ V(kThreadManager, "(Thread manager)") \
V(kStrongRoots, "strong roots", "(Strong roots)") \ V(kStrongRoots, "(Strong roots)") \
V(kExtensions, "Extensions", "(Extensions)") V(kExtensions, "(Extensions)") \
V(kCodeFlusher, "(Code flusher)") \
V(kPartialSnapshotCache, "(Partial snapshot cache)") \
V(kWeakCollections, "(Weak collections)") \
V(kWrapperTracing, "(Wrapper tracing)") \
V(kUnknown, "(Unknown)")
class VisitorSynchronization : public AllStatic { class VisitorSynchronization : public AllStatic {
public: public:
#define DECLARE_ENUM(enum_item, ignore1, ignore2) enum_item, #define DECLARE_ENUM(enum_item, ignore) enum_item,
enum SyncTag { ROOT_ID_LIST(DECLARE_ENUM) kNumberOfSyncTags }; enum SyncTag { ROOT_ID_LIST(DECLARE_ENUM) kNumberOfSyncTags };
#undef DECLARE_ENUM #undef DECLARE_ENUM
static const char* const kTags[kNumberOfSyncTags];
static const char* const kTagNames[kNumberOfSyncTags];
}; };
enum class Root { enum class Root {
#define DECLARE_ENUM(enum_item, ignore1, ignore2) enum_item, #define DECLARE_ENUM(enum_item, ignore) enum_item,
ROOT_ID_LIST(DECLARE_ENUM) ROOT_ID_LIST(DECLARE_ENUM)
#undef DECLARE_ENUM #undef DECLARE_ENUM
// TODO(ulan): Merge with the ROOT_ID_LIST. kNumberOfRoots
kCodeFlusher,
kPartialSnapshotCache,
kWeakCollections,
kWrapperTracing,
kUnknown
}; };
// Abstract base class for visiting, and optionally modifying, the // Abstract base class for visiting, and optionally modifying, the
...@@ -76,6 +73,8 @@ class RootVisitor BASE_EMBEDDED { ...@@ -76,6 +73,8 @@ class RootVisitor BASE_EMBEDDED {
// Also used for marking up GC roots in heap snapshots. // Also used for marking up GC roots in heap snapshots.
// TODO(ulan): Remove this. // TODO(ulan): Remove this.
virtual void Synchronize(VisitorSynchronization::SyncTag tag) {} virtual void Synchronize(VisitorSynchronization::SyncTag tag) {}
static const char* RootName(Root root);
}; };
// Abstract base class for visiting, and optionally modifying, the // Abstract base class for visiting, and optionally modifying, the
......
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