Commit f8597b25 authored by Peter Marshall's avatar Peter Marshall Committed by Commit Bot

[cleanup] Change objects_by_info_ to use unordered map.

Trying to reduce use of our self-baked data structures.

Bug: v8:7570
Change-Id: I3c8598ece74b6434c8baa69810a384b5209dd107
Reviewed-on: https://chromium-review.googlesource.com/1032442Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Commit-Queue: Peter Marshall <petermarshall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#52842}
parent 0a01b620
......@@ -2146,7 +2146,6 @@ NativeObjectsExplorer::NativeObjectsExplorer(
snapshot_(snapshot),
names_(snapshot_->profiler()->names()),
embedder_queried_(false),
objects_by_info_(RetainedInfosMatch),
native_groups_(StringsMatch),
synthetic_entries_allocator_(
new BasicHeapEntriesAllocator(snapshot, HeapEntry::kSynthetic)),
......@@ -2157,13 +2156,10 @@ NativeObjectsExplorer::NativeObjectsExplorer(
filler_(nullptr) {}
NativeObjectsExplorer::~NativeObjectsExplorer() {
for (base::HashMap::Entry* p = objects_by_info_.Start(); p != nullptr;
p = objects_by_info_.Next(p)) {
v8::RetainedObjectInfo* info =
reinterpret_cast<v8::RetainedObjectInfo*>(p->key);
for (auto map_entry : objects_by_info_) {
v8::RetainedObjectInfo* info = map_entry.first;
info->Dispose();
std::vector<HeapObject*>* objects =
reinterpret_cast<std::vector<HeapObject*>*>(p->value);
std::vector<HeapObject*>* objects = map_entry.second;
delete objects;
}
for (base::HashMap::Entry* p = native_groups_.Start(); p != nullptr;
......@@ -2177,7 +2173,7 @@ NativeObjectsExplorer::~NativeObjectsExplorer() {
int NativeObjectsExplorer::EstimateObjectsCount() {
FillRetainedObjects();
return objects_by_info_.occupancy();
return static_cast<int>(objects_by_info_.size());
}
......@@ -2234,14 +2230,13 @@ void NativeObjectsExplorer::FillEdges() {
std::vector<HeapObject*>* NativeObjectsExplorer::GetVectorMaybeDisposeInfo(
v8::RetainedObjectInfo* info) {
base::HashMap::Entry* entry =
objects_by_info_.LookupOrInsert(info, InfoHash(info));
if (entry->value != nullptr) {
auto map_entry = objects_by_info_.find(info);
if (map_entry != objects_by_info_.end()) {
info->Dispose();
} else {
entry->value = new std::vector<HeapObject*>();
objects_by_info_[info] = new std::vector<HeapObject*>();
}
return reinterpret_cast<std::vector<HeapObject*>*>(entry->value);
return objects_by_info_[info];
}
HeapEntry* NativeObjectsExplorer::EntryForEmbedderGraphNode(
......@@ -2308,13 +2303,10 @@ bool NativeObjectsExplorer::IterateAndExtractReferences(
FillRetainedObjects();
FillEdges();
if (EstimateObjectsCount() > 0) {
for (base::HashMap::Entry* p = objects_by_info_.Start(); p != nullptr;
p = objects_by_info_.Next(p)) {
v8::RetainedObjectInfo* info =
reinterpret_cast<v8::RetainedObjectInfo*>(p->key);
for (auto map_entry : objects_by_info_) {
v8::RetainedObjectInfo* info = map_entry.first;
SetNativeRootReference(info);
std::vector<HeapObject*>* objects =
reinterpret_cast<std::vector<HeapObject*>*>(p->value);
std::vector<HeapObject*>* objects = map_entry.second;
for (HeapObject* object : *objects) {
SetWrapperNativeReferences(object, info);
}
......
......@@ -507,14 +507,17 @@ class NativeObjectsExplorer {
v8::RetainedObjectInfo* info);
void VisitSubtreeWrapper(Object** p, uint16_t class_id);
static uint32_t InfoHash(v8::RetainedObjectInfo* info) {
return ComputeIntegerHash(static_cast<uint32_t>(info->GetHash()));
}
static bool RetainedInfosMatch(void* key1, void* key2) {
return key1 == key2 ||
(reinterpret_cast<v8::RetainedObjectInfo*>(key1))->IsEquivalent(
reinterpret_cast<v8::RetainedObjectInfo*>(key2));
}
struct RetainedInfoHasher {
std::size_t operator()(v8::RetainedObjectInfo* info) const {
return ComputeIntegerHash(static_cast<uint32_t>(info->GetHash()));
}
};
struct RetainedInfoEquals {
bool operator()(v8::RetainedObjectInfo* info1,
v8::RetainedObjectInfo* info2) const {
return info1 == info2 || info1->IsEquivalent(info2);
}
};
INLINE(static bool StringsMatch(void* key1, void* key2)) {
return strcmp(reinterpret_cast<char*>(key1),
reinterpret_cast<char*>(key2)) == 0;
......@@ -529,8 +532,9 @@ class NativeObjectsExplorer {
StringsStorage* names_;
bool embedder_queried_;
HeapObjectsSet in_groups_;
// RetainedObjectInfo* -> std::vector<HeapObject*>*
base::CustomMatcherHashMap objects_by_info_;
std::unordered_map<v8::RetainedObjectInfo*, std::vector<HeapObject*>*,
RetainedInfoHasher, RetainedInfoEquals>
objects_by_info_;
base::CustomMatcherHashMap native_groups_;
std::unique_ptr<HeapEntriesAllocator> synthetic_entries_allocator_;
std::unique_ptr<HeapEntriesAllocator> native_entries_allocator_;
......
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