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( ...@@ -2146,7 +2146,6 @@ NativeObjectsExplorer::NativeObjectsExplorer(
snapshot_(snapshot), snapshot_(snapshot),
names_(snapshot_->profiler()->names()), names_(snapshot_->profiler()->names()),
embedder_queried_(false), embedder_queried_(false),
objects_by_info_(RetainedInfosMatch),
native_groups_(StringsMatch), native_groups_(StringsMatch),
synthetic_entries_allocator_( synthetic_entries_allocator_(
new BasicHeapEntriesAllocator(snapshot, HeapEntry::kSynthetic)), new BasicHeapEntriesAllocator(snapshot, HeapEntry::kSynthetic)),
...@@ -2157,13 +2156,10 @@ NativeObjectsExplorer::NativeObjectsExplorer( ...@@ -2157,13 +2156,10 @@ NativeObjectsExplorer::NativeObjectsExplorer(
filler_(nullptr) {} filler_(nullptr) {}
NativeObjectsExplorer::~NativeObjectsExplorer() { NativeObjectsExplorer::~NativeObjectsExplorer() {
for (base::HashMap::Entry* p = objects_by_info_.Start(); p != nullptr; for (auto map_entry : objects_by_info_) {
p = objects_by_info_.Next(p)) { v8::RetainedObjectInfo* info = map_entry.first;
v8::RetainedObjectInfo* info =
reinterpret_cast<v8::RetainedObjectInfo*>(p->key);
info->Dispose(); info->Dispose();
std::vector<HeapObject*>* objects = std::vector<HeapObject*>* objects = map_entry.second;
reinterpret_cast<std::vector<HeapObject*>*>(p->value);
delete objects; delete objects;
} }
for (base::HashMap::Entry* p = native_groups_.Start(); p != nullptr; for (base::HashMap::Entry* p = native_groups_.Start(); p != nullptr;
...@@ -2177,7 +2173,7 @@ NativeObjectsExplorer::~NativeObjectsExplorer() { ...@@ -2177,7 +2173,7 @@ NativeObjectsExplorer::~NativeObjectsExplorer() {
int NativeObjectsExplorer::EstimateObjectsCount() { int NativeObjectsExplorer::EstimateObjectsCount() {
FillRetainedObjects(); FillRetainedObjects();
return objects_by_info_.occupancy(); return static_cast<int>(objects_by_info_.size());
} }
...@@ -2234,14 +2230,13 @@ void NativeObjectsExplorer::FillEdges() { ...@@ -2234,14 +2230,13 @@ void NativeObjectsExplorer::FillEdges() {
std::vector<HeapObject*>* NativeObjectsExplorer::GetVectorMaybeDisposeInfo( std::vector<HeapObject*>* NativeObjectsExplorer::GetVectorMaybeDisposeInfo(
v8::RetainedObjectInfo* info) { v8::RetainedObjectInfo* info) {
base::HashMap::Entry* entry = auto map_entry = objects_by_info_.find(info);
objects_by_info_.LookupOrInsert(info, InfoHash(info)); if (map_entry != objects_by_info_.end()) {
if (entry->value != nullptr) {
info->Dispose(); info->Dispose();
} else { } 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( HeapEntry* NativeObjectsExplorer::EntryForEmbedderGraphNode(
...@@ -2308,13 +2303,10 @@ bool NativeObjectsExplorer::IterateAndExtractReferences( ...@@ -2308,13 +2303,10 @@ bool NativeObjectsExplorer::IterateAndExtractReferences(
FillRetainedObjects(); FillRetainedObjects();
FillEdges(); FillEdges();
if (EstimateObjectsCount() > 0) { if (EstimateObjectsCount() > 0) {
for (base::HashMap::Entry* p = objects_by_info_.Start(); p != nullptr; for (auto map_entry : objects_by_info_) {
p = objects_by_info_.Next(p)) { v8::RetainedObjectInfo* info = map_entry.first;
v8::RetainedObjectInfo* info =
reinterpret_cast<v8::RetainedObjectInfo*>(p->key);
SetNativeRootReference(info); SetNativeRootReference(info);
std::vector<HeapObject*>* objects = std::vector<HeapObject*>* objects = map_entry.second;
reinterpret_cast<std::vector<HeapObject*>*>(p->value);
for (HeapObject* object : *objects) { for (HeapObject* object : *objects) {
SetWrapperNativeReferences(object, info); SetWrapperNativeReferences(object, info);
} }
......
...@@ -507,14 +507,17 @@ class NativeObjectsExplorer { ...@@ -507,14 +507,17 @@ class NativeObjectsExplorer {
v8::RetainedObjectInfo* info); v8::RetainedObjectInfo* info);
void VisitSubtreeWrapper(Object** p, uint16_t class_id); void VisitSubtreeWrapper(Object** p, uint16_t class_id);
static uint32_t InfoHash(v8::RetainedObjectInfo* info) { struct RetainedInfoHasher {
return ComputeIntegerHash(static_cast<uint32_t>(info->GetHash())); std::size_t operator()(v8::RetainedObjectInfo* info) const {
} return ComputeIntegerHash(static_cast<uint32_t>(info->GetHash()));
static bool RetainedInfosMatch(void* key1, void* key2) { }
return key1 == key2 || };
(reinterpret_cast<v8::RetainedObjectInfo*>(key1))->IsEquivalent( struct RetainedInfoEquals {
reinterpret_cast<v8::RetainedObjectInfo*>(key2)); bool operator()(v8::RetainedObjectInfo* info1,
} v8::RetainedObjectInfo* info2) const {
return info1 == info2 || info1->IsEquivalent(info2);
}
};
INLINE(static bool StringsMatch(void* key1, void* key2)) { INLINE(static bool StringsMatch(void* key1, void* key2)) {
return strcmp(reinterpret_cast<char*>(key1), return strcmp(reinterpret_cast<char*>(key1),
reinterpret_cast<char*>(key2)) == 0; reinterpret_cast<char*>(key2)) == 0;
...@@ -529,8 +532,9 @@ class NativeObjectsExplorer { ...@@ -529,8 +532,9 @@ class NativeObjectsExplorer {
StringsStorage* names_; StringsStorage* names_;
bool embedder_queried_; bool embedder_queried_;
HeapObjectsSet in_groups_; HeapObjectsSet in_groups_;
// RetainedObjectInfo* -> std::vector<HeapObject*>* std::unordered_map<v8::RetainedObjectInfo*, std::vector<HeapObject*>*,
base::CustomMatcherHashMap objects_by_info_; RetainedInfoHasher, RetainedInfoEquals>
objects_by_info_;
base::CustomMatcherHashMap native_groups_; base::CustomMatcherHashMap native_groups_;
std::unique_ptr<HeapEntriesAllocator> synthetic_entries_allocator_; std::unique_ptr<HeapEntriesAllocator> synthetic_entries_allocator_;
std::unique_ptr<HeapEntriesAllocator> native_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