Commit 21356d7f authored by Alexei Filippov's avatar Alexei Filippov Committed by Commit Bot

[heap profiler] Refactor: Replace HeapObjectsSet with std containers

Change-Id: Ib13782a8f5eea793b9a74d6f72c625a050069dc2
Reviewed-on: https://chromium-review.googlesource.com/1227681Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Commit-Queue: Alexei Filippov <alph@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55966}
parent 6df4c377
......@@ -556,45 +556,6 @@ void HeapEntriesMap::Pair(HeapThing thing, int entry) {
cache_entry->value = reinterpret_cast<void*>(static_cast<intptr_t>(entry));
}
HeapObjectsSet::HeapObjectsSet() : entries_() {}
void HeapObjectsSet::Clear() {
entries_.Clear();
}
bool HeapObjectsSet::Contains(Object* obj) {
if (!obj->IsHeapObject()) return false;
HeapObject* object = HeapObject::cast(obj);
return entries_.Lookup(object, HeapEntriesMap::Hash(object)) != nullptr;
}
void HeapObjectsSet::Insert(Object* obj) {
if (!obj->IsHeapObject()) return;
HeapObject* object = HeapObject::cast(obj);
entries_.LookupOrInsert(object, HeapEntriesMap::Hash(object));
}
const char* HeapObjectsSet::GetTag(Object* obj) {
HeapObject* object = HeapObject::cast(obj);
base::HashMap::Entry* cache_entry =
entries_.Lookup(object, HeapEntriesMap::Hash(object));
return cache_entry != nullptr
? reinterpret_cast<const char*>(cache_entry->value)
: nullptr;
}
V8_NOINLINE void HeapObjectsSet::SetTag(Object* obj, const char* tag) {
if (!obj->IsHeapObject()) return;
HeapObject* object = HeapObject::cast(obj);
base::HashMap::Entry* cache_entry =
entries_.LookupOrInsert(object, HeapEntriesMap::Hash(object));
cache_entry->value = const_cast<char*>(tag);
}
V8HeapExplorer::V8HeapExplorer(HeapSnapshot* snapshot,
SnapshottingProgressReportingInterface* progress,
v8::HeapProfiler::ObjectNameResolver* resolver)
......@@ -659,9 +620,9 @@ HeapEntry* V8HeapExplorer::AddEntry(HeapObject* object) {
const char* name = names_->GetName(
GetConstructorName(JSObject::cast(object)));
if (object->IsJSGlobalObject()) {
const char* tag = objects_tags_.GetTag(object);
if (tag != nullptr) {
name = names_->GetFormatted("%s / %s", name, tag);
auto it = objects_tags_.find(JSGlobalObject::cast(object));
if (it != objects_tags_.end()) {
name = names_->GetFormatted("%s / %s", name, it->second);
}
}
return AddEntry(object, HeapEntry::kObject, name);
......@@ -1897,18 +1858,17 @@ void V8HeapExplorer::SetGcSubrootReference(Root root, const char* description,
JSGlobalObject* global = Context::cast(child_obj)->global_object();
if (!global->IsJSGlobalObject()) return;
if (user_roots_.Contains(global)) return;
if (!user_roots_.insert(global).second) return;
user_roots_.Insert(global);
SetUserGlobalReference(global);
}
const char* V8HeapExplorer::GetStrongGcSubrootName(Object* object) {
ReadOnlyRoots roots(heap_);
if (strong_gc_subroot_names_.is_empty()) {
#define NAME_ENTRY(name) strong_gc_subroot_names_.SetTag(heap_->name(), #name);
if (strong_gc_subroot_names_.empty()) {
#define NAME_ENTRY(name) strong_gc_subroot_names_.emplace(heap_->name(), #name);
#define RO_NAME_ENTRY(name) \
strong_gc_subroot_names_.SetTag(roots.name(), #name);
strong_gc_subroot_names_.emplace(roots.name(), #name);
#define ROOT_NAME(type, name, camel_name) NAME_ENTRY(name)
STRONG_MUTABLE_ROOT_LIST(ROOT_NAME)
#undef ROOT_NAME
......@@ -1940,9 +1900,10 @@ const char* V8HeapExplorer::GetStrongGcSubrootName(Object* object) {
#undef ACCESSOR_NAME
#undef NAME_ENTRY
#undef RO_NAME_ENTRY
CHECK(!strong_gc_subroot_names_.is_empty());
CHECK(!strong_gc_subroot_names_.empty());
}
return strong_gc_subroot_names_.GetTag(object);
auto it = strong_gc_subroot_names_.find(object);
return it != strong_gc_subroot_names_.end() ? it->second : nullptr;
}
void V8HeapExplorer::TagObject(Object* obj, const char* tag) {
......@@ -1992,7 +1953,7 @@ void V8HeapExplorer::TagGlobalObjects() {
DisallowHeapAllocation no_allocation;
for (int i = 0, l = enumerator.count(); i < l; ++i) {
objects_tags_.SetTag(*enumerator.at(i), urls[i]);
if (urls[i]) objects_tags_.emplace(*enumerator.at(i), urls[i]);
}
}
......@@ -2230,7 +2191,7 @@ void NativeObjectsExplorer::FillRetainedObjects() {
DCHECK(!object.is_null());
HeapObject* heap_object = HeapObject::cast(*object);
info->push_back(heap_object);
in_groups_.Insert(heap_object);
in_groups_.insert(heap_object);
}
}
......@@ -2268,8 +2229,7 @@ void NativeObjectsExplorer::FillEdges() {
std::vector<HeapObject*>* NativeObjectsExplorer::GetVectorMaybeDisposeInfo(
v8::RetainedObjectInfo* info) {
auto map_entry = objects_by_info_.find(info);
if (map_entry != objects_by_info_.end()) {
if (objects_by_info_.count(info)) {
info->Dispose();
} else {
objects_by_info_[info] = new std::vector<HeapObject*>();
......@@ -2364,8 +2324,7 @@ bool NativeObjectsExplorer::IterateAndExtractReferences(
NativeGroupRetainedObjectInfo* NativeObjectsExplorer::FindOrAddGroupInfo(
const char* label) {
const char* label_copy = names_->GetCopy(label);
auto map_entry = native_groups_.find(label_copy);
if (map_entry == native_groups_.end()) {
if (!native_groups_.count(label_copy)) {
native_groups_[label_copy] = new NativeGroupRetainedObjectInfo(label);
}
return native_groups_[label_copy];
......@@ -2418,17 +2377,14 @@ void NativeObjectsExplorer::SetRootNativeRootsReference() {
}
}
void NativeObjectsExplorer::VisitSubtreeWrapper(Object** p, uint16_t class_id) {
if (in_groups_.Contains(*p)) return;
Isolate* isolate = isolate_;
if (in_groups_.count(*p)) return;
v8::RetainedObjectInfo* info =
isolate->heap_profiler()->ExecuteWrapperClassCallback(class_id, p);
isolate_->heap_profiler()->ExecuteWrapperClassCallback(class_id, p);
if (info == nullptr) return;
GetVectorMaybeDisposeInfo(info)->push_back(HeapObject::cast(*p));
}
HeapSnapshotGenerator::HeapSnapshotGenerator(
HeapSnapshot* snapshot,
v8::ActivityControl* control,
......
......@@ -7,6 +7,7 @@
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include "include/v8-profiler.h"
......@@ -315,29 +316,9 @@ class HeapEntriesMap {
base::HashMap entries_;
friend class HeapObjectsSet;
DISALLOW_COPY_AND_ASSIGN(HeapEntriesMap);
};
class HeapObjectsSet {
public:
HeapObjectsSet();
void Clear();
bool Contains(Object* object);
void Insert(Object* obj);
const char* GetTag(Object* obj);
void SetTag(Object* obj, const char* tag);
bool is_empty() const { return entries_.occupancy() == 0; }
private:
base::HashMap entries_;
DISALLOW_COPY_AND_ASSIGN(HeapObjectsSet);
};
class SnapshottingProgressReportingInterface {
public:
virtual ~SnapshottingProgressReportingInterface() { }
......@@ -345,7 +326,6 @@ class SnapshottingProgressReportingInterface {
virtual bool ProgressReport(bool force) = 0;
};
// An implementation of V8 heap graph extractor.
class V8HeapExplorer : public HeapEntriesAllocator {
public:
......@@ -481,9 +461,9 @@ class V8HeapExplorer : public HeapEntriesAllocator {
HeapObjectsMap* heap_object_map_;
SnapshottingProgressReportingInterface* progress_;
SnapshotFiller* filler_;
HeapObjectsSet objects_tags_;
HeapObjectsSet strong_gc_subroot_names_;
HeapObjectsSet user_roots_;
std::unordered_map<JSGlobalObject*, const char*> objects_tags_;
std::unordered_map<Object*, const char*> strong_gc_subroot_names_;
std::unordered_set<JSGlobalObject*> user_roots_;
v8::HeapProfiler::ObjectNameResolver* global_object_name_resolver_;
std::vector<bool> visited_fields_;
......@@ -538,7 +518,7 @@ class NativeObjectsExplorer {
HeapSnapshot* snapshot_;
StringsStorage* names_;
bool embedder_queried_;
HeapObjectsSet in_groups_;
std::unordered_set<Object*> in_groups_;
std::unordered_map<v8::RetainedObjectInfo*, std::vector<HeapObject*>*,
RetainedInfoHasher, RetainedInfoEquals>
objects_by_info_;
......
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