Split TemplateHashMapImpl::Lookup into two methods
This avoids both a mysterious boolean argument ("insert") and lets non-mutating lookups skip passing an allocator (in one such case, we were passing a scary-looking ZoneAllocationPolicy(NULL)!). Review URL: https://codereview.chromium.org/1074943002 Cr-Commit-Position: refs/heads/master@{#27799}
This commit is contained in:
parent
186dd69b3a
commit
5277c41044
@ -262,8 +262,8 @@ static uint32_t SnapshotObjectIdHash(SnapshotObjectId id) {
|
||||
|
||||
unsigned AllocationTracker::AddFunctionInfo(SharedFunctionInfo* shared,
|
||||
SnapshotObjectId id) {
|
||||
HashMap::Entry* entry = id_to_function_info_index_.Lookup(
|
||||
reinterpret_cast<void*>(id), SnapshotObjectIdHash(id), true);
|
||||
HashMap::Entry* entry = id_to_function_info_index_.LookupOrInsert(
|
||||
reinterpret_cast<void*>(id), SnapshotObjectIdHash(id));
|
||||
if (entry->value == NULL) {
|
||||
FunctionInfo* info = new FunctionInfo();
|
||||
info->name = names_->GetFunctionName(shared->DebugName());
|
||||
|
@ -657,9 +657,8 @@ void Simulator::FlushICache(v8::internal::HashMap* i_cache,
|
||||
|
||||
|
||||
CachePage* Simulator::GetCachePage(v8::internal::HashMap* i_cache, void* page) {
|
||||
v8::internal::HashMap::Entry* entry = i_cache->Lookup(page,
|
||||
ICacheHash(page),
|
||||
true);
|
||||
v8::internal::HashMap::Entry* entry =
|
||||
i_cache->LookupOrInsert(page, ICacheHash(page));
|
||||
if (entry->value == NULL) {
|
||||
CachePage* new_page = new CachePage();
|
||||
entry->value = new_page;
|
||||
|
@ -350,7 +350,7 @@ AstRawString* AstValueFactory::GetString(uint32_t hash, bool is_one_byte,
|
||||
// against the AstRawStrings which are in the string_table_. We should not
|
||||
// return this AstRawString.
|
||||
AstRawString key(is_one_byte, literal_bytes, hash);
|
||||
HashMap::Entry* entry = string_table_.Lookup(&key, hash, true);
|
||||
HashMap::Entry* entry = string_table_.LookupOrInsert(&key, hash);
|
||||
if (entry->value == NULL) {
|
||||
// Copy literal contents for later comparison.
|
||||
int length = literal_bytes.length();
|
||||
|
@ -271,7 +271,7 @@ void ObjectLiteral::CalculateEmitStore(Zone* zone) {
|
||||
// If there is an existing entry do not emit a store unless the previous
|
||||
// entry was also an accessor.
|
||||
uint32_t hash = literal->Hash();
|
||||
ZoneHashMap::Entry* entry = table.Lookup(literal, hash, true, allocator);
|
||||
ZoneHashMap::Entry* entry = table.LookupOrInsert(literal, hash, allocator);
|
||||
if (entry->value != NULL) {
|
||||
auto previous_kind =
|
||||
static_cast<ObjectLiteral::Property*>(entry->value)->kind();
|
||||
|
@ -2498,7 +2498,7 @@ Genesis::ExtensionStates::ExtensionStates() : map_(HashMap::PointersMatch, 8) {}
|
||||
|
||||
Genesis::ExtensionTraversalState Genesis::ExtensionStates::get_state(
|
||||
RegisteredExtension* extension) {
|
||||
i::HashMap::Entry* entry = map_.Lookup(extension, Hash(extension), false);
|
||||
i::HashMap::Entry* entry = map_.Lookup(extension, Hash(extension));
|
||||
if (entry == NULL) {
|
||||
return UNVISITED;
|
||||
}
|
||||
@ -2508,7 +2508,7 @@ Genesis::ExtensionTraversalState Genesis::ExtensionStates::get_state(
|
||||
|
||||
void Genesis::ExtensionStates::set_state(RegisteredExtension* extension,
|
||||
ExtensionTraversalState state) {
|
||||
map_.Lookup(extension, Hash(extension), true)->value =
|
||||
map_.LookupOrInsert(extension, Hash(extension))->value =
|
||||
reinterpret_cast<void*>(static_cast<intptr_t>(state));
|
||||
}
|
||||
|
||||
|
@ -105,7 +105,7 @@ Node* StateValuesCache::GetValuesNodeFromCache(Node** nodes, size_t count) {
|
||||
StateValuesKey key(count, nodes);
|
||||
int hash = StateValuesHashKey(nodes, count);
|
||||
ZoneHashMap::Entry* lookup =
|
||||
hash_map_.Lookup(&key, hash, true, ZoneAllocationPolicy(zone()));
|
||||
hash_map_.LookupOrInsert(&key, hash, ZoneAllocationPolicy(zone()));
|
||||
DCHECK_NOT_NULL(lookup);
|
||||
Node* node;
|
||||
if (lookup->value == nullptr) {
|
||||
|
12
src/d8.h
12
src/d8.h
@ -58,18 +58,14 @@ class CounterMap {
|
||||
public:
|
||||
CounterMap(): hash_map_(Match) { }
|
||||
Counter* Lookup(const char* name) {
|
||||
i::HashMap::Entry* answer = hash_map_.Lookup(
|
||||
const_cast<char*>(name),
|
||||
Hash(name),
|
||||
false);
|
||||
i::HashMap::Entry* answer =
|
||||
hash_map_.Lookup(const_cast<char*>(name), Hash(name));
|
||||
if (!answer) return NULL;
|
||||
return reinterpret_cast<Counter*>(answer->value);
|
||||
}
|
||||
void Set(const char* name, Counter* value) {
|
||||
i::HashMap::Entry* answer = hash_map_.Lookup(
|
||||
const_cast<char*>(name),
|
||||
Hash(name),
|
||||
true);
|
||||
i::HashMap::Entry* answer =
|
||||
hash_map_.LookupOrInsert(const_cast<char*>(name), Hash(name));
|
||||
DCHECK(answer != NULL);
|
||||
answer->value = value;
|
||||
}
|
||||
|
@ -519,7 +519,7 @@ void ScriptCache::Add(Handle<Script> script) {
|
||||
// Create an entry in the hash map for the script.
|
||||
int id = script->id()->value();
|
||||
HashMap::Entry* entry =
|
||||
HashMap::Lookup(reinterpret_cast<void*>(id), Hash(id), true);
|
||||
HashMap::LookupOrInsert(reinterpret_cast<void*>(id), Hash(id));
|
||||
if (entry->value != NULL) {
|
||||
#ifdef DEBUG
|
||||
// The code deserializer may introduce duplicate Script objects.
|
||||
@ -582,7 +582,8 @@ void ScriptCache::HandleWeakScript(
|
||||
// Remove the corresponding entry from the cache.
|
||||
ScriptCache* script_cache =
|
||||
reinterpret_cast<ScriptCache*>(data.GetParameter());
|
||||
HashMap::Entry* entry = script_cache->Lookup(key, hash, false);
|
||||
HashMap::Entry* entry = script_cache->Lookup(key, hash);
|
||||
DCHECK_NOT_NULL(entry);
|
||||
Object** location = reinterpret_cast<Object**>(entry->value);
|
||||
script_cache->Remove(key, hash);
|
||||
|
||||
|
@ -1972,7 +1972,7 @@ static HashMap* GetLineMap() {
|
||||
|
||||
static void PutLineInfo(Address addr, LineInfo* info) {
|
||||
HashMap* line_map = GetLineMap();
|
||||
HashMap::Entry* e = line_map->Lookup(addr, HashCodeAddress(addr), true);
|
||||
HashMap::Entry* e = line_map->LookupOrInsert(addr, HashCodeAddress(addr));
|
||||
if (e->value != NULL) delete static_cast<LineInfo*>(e->value);
|
||||
e->value = info;
|
||||
}
|
||||
|
@ -41,13 +41,15 @@ class TemplateHashMapImpl {
|
||||
int order; // If you never remove entries this is the insertion order.
|
||||
};
|
||||
|
||||
// If an entry with matching key is found, Lookup()
|
||||
// returns that entry. If no matching entry is found,
|
||||
// but insert is set, a new entry is inserted with
|
||||
// corresponding key, key hash, and NULL value.
|
||||
// If an entry with matching key is found, returns that entry.
|
||||
// Otherwise, NULL is returned.
|
||||
Entry* Lookup(void* key, uint32_t hash, bool insert,
|
||||
AllocationPolicy allocator = AllocationPolicy());
|
||||
Entry* Lookup(void* key, uint32_t hash);
|
||||
|
||||
// If an entry with matching key is found, returns that entry.
|
||||
// If no matching entry is found, a new entry is inserted with
|
||||
// corresponding key, key hash, and NULL value.
|
||||
Entry* LookupOrInsert(void* key, uint32_t hash,
|
||||
AllocationPolicy allocator = AllocationPolicy());
|
||||
|
||||
// Removes the entry with matching key.
|
||||
// It returns the value of the deleted entry
|
||||
@ -109,35 +111,38 @@ TemplateHashMapImpl<AllocationPolicy>::~TemplateHashMapImpl() {
|
||||
}
|
||||
|
||||
|
||||
template<class AllocationPolicy>
|
||||
template <class AllocationPolicy>
|
||||
typename TemplateHashMapImpl<AllocationPolicy>::Entry*
|
||||
TemplateHashMapImpl<AllocationPolicy>::Lookup(
|
||||
void* key, uint32_t hash, bool insert, AllocationPolicy allocator) {
|
||||
TemplateHashMapImpl<AllocationPolicy>::Lookup(void* key, uint32_t hash) {
|
||||
Entry* p = Probe(key, hash);
|
||||
return p->key != NULL ? p : NULL;
|
||||
}
|
||||
|
||||
|
||||
template <class AllocationPolicy>
|
||||
typename TemplateHashMapImpl<AllocationPolicy>::Entry*
|
||||
TemplateHashMapImpl<AllocationPolicy>::LookupOrInsert(
|
||||
void* key, uint32_t hash, AllocationPolicy allocator) {
|
||||
// Find a matching entry.
|
||||
Entry* p = Probe(key, hash);
|
||||
if (p->key != NULL) {
|
||||
return p;
|
||||
}
|
||||
|
||||
// No entry found; insert one if necessary.
|
||||
if (insert) {
|
||||
p->key = key;
|
||||
p->value = NULL;
|
||||
p->hash = hash;
|
||||
p->order = occupancy_;
|
||||
occupancy_++;
|
||||
// No entry found; insert one.
|
||||
p->key = key;
|
||||
p->value = NULL;
|
||||
p->hash = hash;
|
||||
p->order = occupancy_;
|
||||
occupancy_++;
|
||||
|
||||
// Grow the map if we reached >= 80% occupancy.
|
||||
if (occupancy_ + occupancy_/4 >= capacity_) {
|
||||
Resize(allocator);
|
||||
p = Probe(key, hash);
|
||||
}
|
||||
|
||||
return p;
|
||||
// Grow the map if we reached >= 80% occupancy.
|
||||
if (occupancy_ + occupancy_ / 4 >= capacity_) {
|
||||
Resize(allocator);
|
||||
p = Probe(key, hash);
|
||||
}
|
||||
|
||||
// No entry found and none inserted.
|
||||
return NULL;
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
@ -235,9 +240,9 @@ typename TemplateHashMapImpl<AllocationPolicy>::Entry*
|
||||
}
|
||||
|
||||
|
||||
template<class AllocationPolicy>
|
||||
template <class AllocationPolicy>
|
||||
typename TemplateHashMapImpl<AllocationPolicy>::Entry*
|
||||
TemplateHashMapImpl<AllocationPolicy>::Probe(void* key, uint32_t hash) {
|
||||
TemplateHashMapImpl<AllocationPolicy>::Probe(void* key, uint32_t hash) {
|
||||
DCHECK(key != NULL);
|
||||
|
||||
DCHECK(base::bits::IsPowerOfTwo32(capacity_));
|
||||
@ -282,7 +287,7 @@ void TemplateHashMapImpl<AllocationPolicy>::Resize(AllocationPolicy allocator) {
|
||||
// Rehash all current entries.
|
||||
for (Entry* p = map; n > 0; p++) {
|
||||
if (p->key != NULL) {
|
||||
Entry* entry = Lookup(p->key, p->hash, true, allocator);
|
||||
Entry* entry = LookupOrInsert(p->key, p->hash, allocator);
|
||||
entry->value = p->value;
|
||||
entry->order = p->order;
|
||||
n--;
|
||||
@ -338,7 +343,10 @@ class TemplateHashMap: private TemplateHashMapImpl<AllocationPolicy> {
|
||||
Iterator end() const { return Iterator(this, NULL); }
|
||||
Iterator find(Key* key, bool insert = false,
|
||||
AllocationPolicy allocator = AllocationPolicy()) {
|
||||
return Iterator(this, this->Lookup(key, key->Hash(), insert, allocator));
|
||||
if (insert) {
|
||||
return Iterator(this, this->LookupOrInsert(key, key->Hash(), allocator));
|
||||
}
|
||||
return Iterator(this, this->Lookup(key, key->Hash()));
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -391,8 +391,8 @@ bool HeapObjectsMap::MoveObject(Address from, Address to, int object_size) {
|
||||
entries_.at(to_entry_info_index).addr = NULL;
|
||||
}
|
||||
} else {
|
||||
HashMap::Entry* to_entry = entries_map_.Lookup(to, ComputePointerHash(to),
|
||||
true);
|
||||
HashMap::Entry* to_entry =
|
||||
entries_map_.LookupOrInsert(to, ComputePointerHash(to));
|
||||
if (to_entry->value != NULL) {
|
||||
// We found the existing entry with to address for an old object.
|
||||
// Without this operation we will have two EntryInfo's with the same
|
||||
@ -429,8 +429,7 @@ void HeapObjectsMap::UpdateObjectSize(Address addr, int size) {
|
||||
|
||||
|
||||
SnapshotObjectId HeapObjectsMap::FindEntry(Address addr) {
|
||||
HashMap::Entry* entry = entries_map_.Lookup(addr, ComputePointerHash(addr),
|
||||
false);
|
||||
HashMap::Entry* entry = entries_map_.Lookup(addr, ComputePointerHash(addr));
|
||||
if (entry == NULL) return 0;
|
||||
int entry_index = static_cast<int>(reinterpret_cast<intptr_t>(entry->value));
|
||||
EntryInfo& entry_info = entries_.at(entry_index);
|
||||
@ -443,8 +442,8 @@ SnapshotObjectId HeapObjectsMap::FindOrAddEntry(Address addr,
|
||||
unsigned int size,
|
||||
bool accessed) {
|
||||
DCHECK(static_cast<uint32_t>(entries_.length()) > entries_map_.occupancy());
|
||||
HashMap::Entry* entry = entries_map_.Lookup(addr, ComputePointerHash(addr),
|
||||
true);
|
||||
HashMap::Entry* entry =
|
||||
entries_map_.LookupOrInsert(addr, ComputePointerHash(addr));
|
||||
if (entry->value != NULL) {
|
||||
int entry_index =
|
||||
static_cast<int>(reinterpret_cast<intptr_t>(entry->value));
|
||||
@ -554,8 +553,8 @@ int HeapObjectsMap::FindUntrackedObjects() {
|
||||
for (HeapObject* obj = iterator.next();
|
||||
obj != NULL;
|
||||
obj = iterator.next()) {
|
||||
HashMap::Entry* entry = entries_map_.Lookup(
|
||||
obj->address(), ComputePointerHash(obj->address()), false);
|
||||
HashMap::Entry* entry =
|
||||
entries_map_.Lookup(obj->address(), ComputePointerHash(obj->address()));
|
||||
if (entry == NULL) {
|
||||
++untracked;
|
||||
if (FLAG_heap_profiler_trace_objects) {
|
||||
@ -675,7 +674,7 @@ void HeapObjectsMap::RemoveDeadEntries() {
|
||||
}
|
||||
entries_.at(first_free_entry).accessed = false;
|
||||
HashMap::Entry* entry = entries_map_.Lookup(
|
||||
entry_info.addr, ComputePointerHash(entry_info.addr), false);
|
||||
entry_info.addr, ComputePointerHash(entry_info.addr));
|
||||
DCHECK(entry);
|
||||
entry->value = reinterpret_cast<void*>(first_free_entry);
|
||||
++first_free_entry;
|
||||
@ -721,14 +720,14 @@ HeapEntriesMap::HeapEntriesMap()
|
||||
|
||||
|
||||
int HeapEntriesMap::Map(HeapThing thing) {
|
||||
HashMap::Entry* cache_entry = entries_.Lookup(thing, Hash(thing), false);
|
||||
HashMap::Entry* cache_entry = entries_.Lookup(thing, Hash(thing));
|
||||
if (cache_entry == NULL) return HeapEntry::kNoEntry;
|
||||
return static_cast<int>(reinterpret_cast<intptr_t>(cache_entry->value));
|
||||
}
|
||||
|
||||
|
||||
void HeapEntriesMap::Pair(HeapThing thing, int entry) {
|
||||
HashMap::Entry* cache_entry = entries_.Lookup(thing, Hash(thing), true);
|
||||
HashMap::Entry* cache_entry = entries_.LookupOrInsert(thing, Hash(thing));
|
||||
DCHECK(cache_entry->value == NULL);
|
||||
cache_entry->value = reinterpret_cast<void*>(static_cast<intptr_t>(entry));
|
||||
}
|
||||
@ -747,21 +746,21 @@ void HeapObjectsSet::Clear() {
|
||||
bool HeapObjectsSet::Contains(Object* obj) {
|
||||
if (!obj->IsHeapObject()) return false;
|
||||
HeapObject* object = HeapObject::cast(obj);
|
||||
return entries_.Lookup(object, HeapEntriesMap::Hash(object), false) != NULL;
|
||||
return entries_.Lookup(object, HeapEntriesMap::Hash(object)) != NULL;
|
||||
}
|
||||
|
||||
|
||||
void HeapObjectsSet::Insert(Object* obj) {
|
||||
if (!obj->IsHeapObject()) return;
|
||||
HeapObject* object = HeapObject::cast(obj);
|
||||
entries_.Lookup(object, HeapEntriesMap::Hash(object), true);
|
||||
entries_.LookupOrInsert(object, HeapEntriesMap::Hash(object));
|
||||
}
|
||||
|
||||
|
||||
const char* HeapObjectsSet::GetTag(Object* obj) {
|
||||
HeapObject* object = HeapObject::cast(obj);
|
||||
HashMap::Entry* cache_entry =
|
||||
entries_.Lookup(object, HeapEntriesMap::Hash(object), false);
|
||||
entries_.Lookup(object, HeapEntriesMap::Hash(object));
|
||||
return cache_entry != NULL
|
||||
? reinterpret_cast<const char*>(cache_entry->value)
|
||||
: NULL;
|
||||
@ -772,7 +771,7 @@ void HeapObjectsSet::SetTag(Object* obj, const char* tag) {
|
||||
if (!obj->IsHeapObject()) return;
|
||||
HeapObject* object = HeapObject::cast(obj);
|
||||
HashMap::Entry* cache_entry =
|
||||
entries_.Lookup(object, HeapEntriesMap::Hash(object), true);
|
||||
entries_.LookupOrInsert(object, HeapEntriesMap::Hash(object));
|
||||
cache_entry->value = const_cast<char*>(tag);
|
||||
}
|
||||
|
||||
@ -2390,8 +2389,7 @@ void NativeObjectsExplorer::FillImplicitReferences() {
|
||||
|
||||
List<HeapObject*>* NativeObjectsExplorer::GetListMaybeDisposeInfo(
|
||||
v8::RetainedObjectInfo* info) {
|
||||
HashMap::Entry* entry =
|
||||
objects_by_info_.Lookup(info, InfoHash(info), true);
|
||||
HashMap::Entry* entry = objects_by_info_.LookupOrInsert(info, InfoHash(info));
|
||||
if (entry->value != NULL) {
|
||||
info->Dispose();
|
||||
} else {
|
||||
@ -2460,8 +2458,8 @@ NativeGroupRetainedObjectInfo* NativeObjectsExplorer::FindOrAddGroupInfo(
|
||||
label_copy,
|
||||
static_cast<int>(strlen(label_copy)),
|
||||
isolate_->heap()->HashSeed());
|
||||
HashMap::Entry* entry = native_groups_.Lookup(const_cast<char*>(label_copy),
|
||||
hash, true);
|
||||
HashMap::Entry* entry =
|
||||
native_groups_.LookupOrInsert(const_cast<char*>(label_copy), hash);
|
||||
if (entry->value == NULL) {
|
||||
entry->value = new NativeGroupRetainedObjectInfo(label);
|
||||
}
|
||||
@ -2772,8 +2770,8 @@ void HeapSnapshotJSONSerializer::SerializeImpl() {
|
||||
|
||||
|
||||
int HeapSnapshotJSONSerializer::GetStringId(const char* s) {
|
||||
HashMap::Entry* cache_entry = strings_.Lookup(
|
||||
const_cast<char*>(s), StringHash(s), true);
|
||||
HashMap::Entry* cache_entry =
|
||||
strings_.LookupOrInsert(const_cast<char*>(s), StringHash(s));
|
||||
if (cache_entry->value == NULL) {
|
||||
cache_entry->value = reinterpret_cast<void*>(next_string_id_++);
|
||||
}
|
||||
|
@ -2890,8 +2890,8 @@ AllocationResult LargeObjectSpace::AllocateRaw(int object_size,
|
||||
uintptr_t base = reinterpret_cast<uintptr_t>(page) / MemoryChunk::kAlignment;
|
||||
uintptr_t limit = base + (page->size() - 1) / MemoryChunk::kAlignment;
|
||||
for (uintptr_t key = base; key <= limit; key++) {
|
||||
HashMap::Entry* entry = chunk_map_.Lookup(reinterpret_cast<void*>(key),
|
||||
static_cast<uint32_t>(key), true);
|
||||
HashMap::Entry* entry = chunk_map_.LookupOrInsert(
|
||||
reinterpret_cast<void*>(key), static_cast<uint32_t>(key));
|
||||
DCHECK(entry != NULL);
|
||||
entry->value = page;
|
||||
}
|
||||
@ -2938,7 +2938,7 @@ Object* LargeObjectSpace::FindObject(Address a) {
|
||||
LargePage* LargeObjectSpace::FindPage(Address a) {
|
||||
uintptr_t key = reinterpret_cast<uintptr_t>(a) / MemoryChunk::kAlignment;
|
||||
HashMap::Entry* e = chunk_map_.Lookup(reinterpret_cast<void*>(key),
|
||||
static_cast<uint32_t>(key), false);
|
||||
static_cast<uint32_t>(key));
|
||||
if (e != NULL) {
|
||||
DCHECK(e->value != NULL);
|
||||
LargePage* page = reinterpret_cast<LargePage*>(e->value);
|
||||
|
@ -308,14 +308,16 @@ BoundsCheckTable::BoundsCheckTable(Zone* zone)
|
||||
BoundsCheckBbData** BoundsCheckTable::LookupOrInsert(BoundsCheckKey* key,
|
||||
Zone* zone) {
|
||||
return reinterpret_cast<BoundsCheckBbData**>(
|
||||
&(Lookup(key, key->Hash(), true, ZoneAllocationPolicy(zone))->value));
|
||||
&(ZoneHashMap::LookupOrInsert(key, key->Hash(),
|
||||
ZoneAllocationPolicy(zone))->value));
|
||||
}
|
||||
|
||||
|
||||
void BoundsCheckTable::Insert(BoundsCheckKey* key,
|
||||
BoundsCheckBbData* data,
|
||||
Zone* zone) {
|
||||
Lookup(key, key->Hash(), true, ZoneAllocationPolicy(zone))->value = data;
|
||||
ZoneHashMap::LookupOrInsert(key, key->Hash(), ZoneAllocationPolicy(zone))
|
||||
->value = data;
|
||||
}
|
||||
|
||||
|
||||
|
@ -15,6 +15,7 @@ namespace internal {
|
||||
void ModuleDescriptor::AddLocalExport(const AstRawString* export_name,
|
||||
const AstRawString* local_name,
|
||||
Zone* zone, bool* ok) {
|
||||
DCHECK(!IsFrozen());
|
||||
void* key = const_cast<AstRawString*>(export_name);
|
||||
|
||||
ZoneAllocationPolicy allocator(zone);
|
||||
@ -26,9 +27,12 @@ void ModuleDescriptor::AddLocalExport(const AstRawString* export_name,
|
||||
}
|
||||
|
||||
ZoneHashMap::Entry* p =
|
||||
exports_->Lookup(key, export_name->hash(), !IsFrozen(), allocator);
|
||||
if (p == nullptr || p->value != nullptr) {
|
||||
exports_->LookupOrInsert(key, export_name->hash(), allocator);
|
||||
DCHECK_NOT_NULL(p);
|
||||
if (p->value != nullptr) {
|
||||
// Duplicate export.
|
||||
*ok = false;
|
||||
return;
|
||||
}
|
||||
|
||||
p->value = const_cast<AstRawString*>(local_name);
|
||||
@ -47,10 +51,8 @@ void ModuleDescriptor::AddModuleRequest(const AstRawString* module_specifier,
|
||||
const AstRawString* ModuleDescriptor::LookupLocalExport(
|
||||
const AstRawString* export_name, Zone* zone) {
|
||||
if (exports_ == nullptr) return nullptr;
|
||||
ZoneAllocationPolicy allocator(zone);
|
||||
ZoneHashMap::Entry* entry =
|
||||
exports_->Lookup(const_cast<AstRawString*>(export_name),
|
||||
export_name->hash(), false, allocator);
|
||||
ZoneHashMap::Entry* entry = exports_->Lookup(
|
||||
const_cast<AstRawString*>(export_name), export_name->hash());
|
||||
if (entry == nullptr) return nullptr;
|
||||
DCHECK_NOT_NULL(entry->value);
|
||||
return static_cast<const AstRawString*>(entry->value);
|
||||
|
@ -729,7 +729,7 @@ void Simulator::FlushICache(v8::internal::HashMap* i_cache, void* start_addr,
|
||||
|
||||
CachePage* Simulator::GetCachePage(v8::internal::HashMap* i_cache, void* page) {
|
||||
v8::internal::HashMap::Entry* entry =
|
||||
i_cache->Lookup(page, ICacheHash(page), true);
|
||||
i_cache->LookupOrInsert(page, ICacheHash(page));
|
||||
if (entry->value == NULL) {
|
||||
CachePage* new_page = new CachePage();
|
||||
entry->value = new_page;
|
||||
|
@ -152,8 +152,7 @@ void ProfileNode::CollectDeoptInfo(CodeEntry* entry) {
|
||||
|
||||
|
||||
ProfileNode* ProfileNode::FindChild(CodeEntry* entry) {
|
||||
HashMap::Entry* map_entry =
|
||||
children_.Lookup(entry, CodeEntryHash(entry), false);
|
||||
HashMap::Entry* map_entry = children_.Lookup(entry, CodeEntryHash(entry));
|
||||
return map_entry != NULL ?
|
||||
reinterpret_cast<ProfileNode*>(map_entry->value) : NULL;
|
||||
}
|
||||
@ -161,7 +160,7 @@ ProfileNode* ProfileNode::FindChild(CodeEntry* entry) {
|
||||
|
||||
ProfileNode* ProfileNode::FindOrAddChild(CodeEntry* entry) {
|
||||
HashMap::Entry* map_entry =
|
||||
children_.Lookup(entry, CodeEntryHash(entry), true);
|
||||
children_.LookupOrInsert(entry, CodeEntryHash(entry));
|
||||
ProfileNode* node = reinterpret_cast<ProfileNode*>(map_entry->value);
|
||||
if (node == NULL) {
|
||||
// New node added.
|
||||
@ -178,7 +177,7 @@ void ProfileNode::IncrementLineTicks(int src_line) {
|
||||
// Increment a hit counter of a certain source line.
|
||||
// Add a new source line if not found.
|
||||
HashMap::Entry* e =
|
||||
line_ticks_.Lookup(reinterpret_cast<void*>(src_line), src_line, true);
|
||||
line_ticks_.LookupOrInsert(reinterpret_cast<void*>(src_line), src_line);
|
||||
DCHECK(e);
|
||||
e->value = reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(e->value) + 1);
|
||||
}
|
||||
@ -269,7 +268,7 @@ ProfileTree::~ProfileTree() {
|
||||
unsigned ProfileTree::GetFunctionId(const ProfileNode* node) {
|
||||
CodeEntry* code_entry = node->entry();
|
||||
HashMap::Entry* entry =
|
||||
function_ids_.Lookup(code_entry, code_entry->GetHash(), true);
|
||||
function_ids_.LookupOrInsert(code_entry, code_entry->GetHash());
|
||||
if (!entry->value) {
|
||||
entry->value = reinterpret_cast<void*>(next_function_id_++);
|
||||
}
|
||||
|
@ -1441,7 +1441,7 @@ int DuplicateFinder::AddSymbol(Vector<const uint8_t> key,
|
||||
int value) {
|
||||
uint32_t hash = Hash(key, is_one_byte);
|
||||
byte* encoding = BackupKey(key, is_one_byte);
|
||||
HashMap::Entry* entry = map_.Lookup(encoding, hash, true);
|
||||
HashMap::Entry* entry = map_.LookupOrInsert(encoding, hash);
|
||||
int old_value = static_cast<int>(reinterpret_cast<intptr_t>(entry->value));
|
||||
entry->value =
|
||||
reinterpret_cast<void*>(static_cast<intptr_t>(value | old_value));
|
||||
|
@ -36,8 +36,9 @@ Variable* VariableMap::Declare(Scope* scope, const AstRawString* name,
|
||||
// AstRawStrings are unambiguous, i.e., the same string is always represented
|
||||
// by the same AstRawString*.
|
||||
// FIXME(marja): fix the type of Lookup.
|
||||
Entry* p = ZoneHashMap::Lookup(const_cast<AstRawString*>(name), name->hash(),
|
||||
true, ZoneAllocationPolicy(zone()));
|
||||
Entry* p =
|
||||
ZoneHashMap::LookupOrInsert(const_cast<AstRawString*>(name), name->hash(),
|
||||
ZoneAllocationPolicy(zone()));
|
||||
if (p->value == NULL) {
|
||||
// The variable has not been declared yet -> insert it.
|
||||
DCHECK(p->key == name);
|
||||
@ -49,8 +50,7 @@ Variable* VariableMap::Declare(Scope* scope, const AstRawString* name,
|
||||
|
||||
|
||||
Variable* VariableMap::Lookup(const AstRawString* name) {
|
||||
Entry* p = ZoneHashMap::Lookup(const_cast<AstRawString*>(name), name->hash(),
|
||||
false, ZoneAllocationPolicy(NULL));
|
||||
Entry* p = ZoneHashMap::Lookup(const_cast<AstRawString*>(name), name->hash());
|
||||
if (p != NULL) {
|
||||
DCHECK(reinterpret_cast<const AstRawString*>(p->key) == name);
|
||||
DCHECK(p->value != NULL);
|
||||
|
@ -339,8 +339,8 @@ ExternalReferenceEncoder::ExternalReferenceEncoder(Isolate* isolate) {
|
||||
Address addr = table->address(i);
|
||||
if (addr == ExternalReferenceTable::NotAvailable()) continue;
|
||||
// We expect no duplicate external references entries in the table.
|
||||
DCHECK_NULL(map_->Lookup(addr, Hash(addr), false));
|
||||
map_->Lookup(addr, Hash(addr), true)->value = reinterpret_cast<void*>(i);
|
||||
DCHECK_NULL(map_->Lookup(addr, Hash(addr)));
|
||||
map_->LookupOrInsert(addr, Hash(addr))->value = reinterpret_cast<void*>(i);
|
||||
}
|
||||
isolate->set_external_reference_map(map_);
|
||||
}
|
||||
@ -349,7 +349,7 @@ ExternalReferenceEncoder::ExternalReferenceEncoder(Isolate* isolate) {
|
||||
uint32_t ExternalReferenceEncoder::Encode(Address address) const {
|
||||
DCHECK_NOT_NULL(address);
|
||||
HashMap::Entry* entry =
|
||||
const_cast<HashMap*>(map_)->Lookup(address, Hash(address), false);
|
||||
const_cast<HashMap*>(map_)->Lookup(address, Hash(address));
|
||||
DCHECK_NOT_NULL(entry);
|
||||
return static_cast<uint32_t>(reinterpret_cast<intptr_t>(entry->value));
|
||||
}
|
||||
@ -358,7 +358,7 @@ uint32_t ExternalReferenceEncoder::Encode(Address address) const {
|
||||
const char* ExternalReferenceEncoder::NameOfAddress(Isolate* isolate,
|
||||
Address address) const {
|
||||
HashMap::Entry* entry =
|
||||
const_cast<HashMap*>(map_)->Lookup(address, Hash(address), false);
|
||||
const_cast<HashMap*>(map_)->Lookup(address, Hash(address));
|
||||
if (entry == NULL) return "<unknown>";
|
||||
uint32_t i = static_cast<uint32_t>(reinterpret_cast<intptr_t>(entry->value));
|
||||
return ExternalReferenceTable::instance(isolate)->name(i);
|
||||
@ -472,13 +472,12 @@ class CodeAddressMap: public CodeEventLogger {
|
||||
}
|
||||
|
||||
HashMap::Entry* FindOrCreateEntry(Address code_address) {
|
||||
return impl_.Lookup(code_address, ComputePointerHash(code_address), true);
|
||||
return impl_.LookupOrInsert(code_address,
|
||||
ComputePointerHash(code_address));
|
||||
}
|
||||
|
||||
HashMap::Entry* FindEntry(Address code_address) {
|
||||
return impl_.Lookup(code_address,
|
||||
ComputePointerHash(code_address),
|
||||
false);
|
||||
return impl_.Lookup(code_address, ComputePointerHash(code_address));
|
||||
}
|
||||
|
||||
void RemoveEntry(HashMap::Entry* entry) {
|
||||
|
@ -81,7 +81,10 @@ class AddressMapBase {
|
||||
|
||||
inline static HashMap::Entry* LookupEntry(HashMap* map, HeapObject* obj,
|
||||
bool insert) {
|
||||
return map->Lookup(Key(obj), Hash(obj), insert);
|
||||
if (insert) {
|
||||
map->LookupOrInsert(Key(obj), Hash(obj));
|
||||
}
|
||||
return map->Lookup(Key(obj), Hash(obj));
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -117,7 +117,7 @@ size_t StringsStorage::GetUsedMemorySize() const {
|
||||
|
||||
HashMap::Entry* StringsStorage::GetEntry(const char* str, int len) {
|
||||
uint32_t hash = StringHasher::HashSequentialString(str, len, hash_seed_);
|
||||
return names_.Lookup(const_cast<char*>(str), hash, true);
|
||||
return names_.LookupOrInsert(const_cast<char*>(str), hash);
|
||||
}
|
||||
}
|
||||
} // namespace v8::internal
|
||||
|
@ -12347,10 +12347,8 @@ static void event_handler(const v8::JitCodeEvent* event) {
|
||||
CHECK(event->code_start != NULL);
|
||||
CHECK_NE(0, static_cast<int>(event->code_len));
|
||||
CHECK(event->name.str != NULL);
|
||||
i::HashMap::Entry* entry =
|
||||
code_map->Lookup(event->code_start,
|
||||
i::ComputePointerHash(event->code_start),
|
||||
true);
|
||||
i::HashMap::Entry* entry = code_map->LookupOrInsert(
|
||||
event->code_start, i::ComputePointerHash(event->code_start));
|
||||
entry->value = reinterpret_cast<void*>(event->code_len);
|
||||
|
||||
if (FunctionNameIs("bar", event)) {
|
||||
@ -12368,18 +12366,16 @@ static void event_handler(const v8::JitCodeEvent* event) {
|
||||
// Compiler::RecordFunctionCompilation) and the line endings
|
||||
// calculations can cause a GC, which can move the newly created code
|
||||
// before its existence can be logged.
|
||||
i::HashMap::Entry* entry =
|
||||
code_map->Lookup(event->code_start, hash, false);
|
||||
i::HashMap::Entry* entry = code_map->Lookup(event->code_start, hash);
|
||||
if (entry != NULL) {
|
||||
++move_events;
|
||||
|
||||
CHECK_EQ(reinterpret_cast<void*>(event->code_len), entry->value);
|
||||
code_map->Remove(event->code_start, hash);
|
||||
|
||||
entry = code_map->Lookup(event->new_code_start,
|
||||
i::ComputePointerHash(event->new_code_start),
|
||||
true);
|
||||
CHECK(entry != NULL);
|
||||
entry = code_map->LookupOrInsert(
|
||||
event->new_code_start,
|
||||
i::ComputePointerHash(event->new_code_start));
|
||||
entry->value = reinterpret_cast<void*>(event->code_len);
|
||||
}
|
||||
}
|
||||
@ -12397,10 +12393,8 @@ static void event_handler(const v8::JitCodeEvent* event) {
|
||||
DummyJitCodeLineInfo* line_info = new DummyJitCodeLineInfo();
|
||||
v8::JitCodeEvent* temp_event = const_cast<v8::JitCodeEvent*>(event);
|
||||
temp_event->user_data = line_info;
|
||||
i::HashMap::Entry* entry =
|
||||
jitcode_line_info->Lookup(line_info,
|
||||
i::ComputePointerHash(line_info),
|
||||
true);
|
||||
i::HashMap::Entry* entry = jitcode_line_info->LookupOrInsert(
|
||||
line_info, i::ComputePointerHash(line_info));
|
||||
entry->value = reinterpret_cast<void*>(line_info);
|
||||
}
|
||||
break;
|
||||
@ -12411,7 +12405,7 @@ static void event_handler(const v8::JitCodeEvent* event) {
|
||||
CHECK(event->user_data != NULL);
|
||||
uint32_t hash = i::ComputePointerHash(event->user_data);
|
||||
i::HashMap::Entry* entry =
|
||||
jitcode_line_info->Lookup(event->user_data, hash, false);
|
||||
jitcode_line_info->Lookup(event->user_data, hash);
|
||||
CHECK(entry != NULL);
|
||||
delete reinterpret_cast<DummyJitCodeLineInfo*>(event->user_data);
|
||||
}
|
||||
@ -12421,7 +12415,7 @@ static void event_handler(const v8::JitCodeEvent* event) {
|
||||
CHECK(event->user_data != NULL);
|
||||
uint32_t hash = i::ComputePointerHash(event->user_data);
|
||||
i::HashMap::Entry* entry =
|
||||
jitcode_line_info->Lookup(event->user_data, hash, false);
|
||||
jitcode_line_info->Lookup(event->user_data, hash);
|
||||
CHECK(entry != NULL);
|
||||
}
|
||||
break;
|
||||
|
@ -48,7 +48,8 @@ class IntSet {
|
||||
|
||||
void Insert(int x) {
|
||||
CHECK_NE(0, x); // 0 corresponds to (void*)NULL - illegal key value
|
||||
HashMap::Entry* p = map_.Lookup(reinterpret_cast<void*>(x), hash_(x), true);
|
||||
HashMap::Entry* p =
|
||||
map_.LookupOrInsert(reinterpret_cast<void*>(x), hash_(x));
|
||||
CHECK(p != NULL); // insert is set!
|
||||
CHECK_EQ(reinterpret_cast<void*>(x), p->key);
|
||||
// we don't care about p->value
|
||||
@ -60,8 +61,7 @@ class IntSet {
|
||||
}
|
||||
|
||||
bool Present(int x) {
|
||||
HashMap::Entry* p =
|
||||
map_.Lookup(reinterpret_cast<void*>(x), hash_(x), false);
|
||||
HashMap::Entry* p = map_.Lookup(reinterpret_cast<void*>(x), hash_(x));
|
||||
if (p != NULL) {
|
||||
CHECK_EQ(reinterpret_cast<void*>(x), p->key);
|
||||
}
|
||||
|
@ -74,10 +74,9 @@ class NamedEntriesDetector {
|
||||
for (int i = 0; i < children.length(); ++i) {
|
||||
if (children[i]->type() == i::HeapGraphEdge::kShortcut) continue;
|
||||
i::HeapEntry* child = children[i]->to();
|
||||
i::HashMap::Entry* entry = visited.Lookup(
|
||||
i::HashMap::Entry* entry = visited.LookupOrInsert(
|
||||
reinterpret_cast<void*>(child),
|
||||
static_cast<uint32_t>(reinterpret_cast<uintptr_t>(child)),
|
||||
true);
|
||||
static_cast<uint32_t>(reinterpret_cast<uintptr_t>(child)));
|
||||
if (entry->value)
|
||||
continue;
|
||||
entry->value = reinterpret_cast<void*>(1);
|
||||
@ -146,10 +145,9 @@ static bool ValidateSnapshot(const v8::HeapSnapshot* snapshot, int depth = 3) {
|
||||
i::HashMap visited(AddressesMatch);
|
||||
i::List<i::HeapGraphEdge>& edges = heap_snapshot->edges();
|
||||
for (int i = 0; i < edges.length(); ++i) {
|
||||
i::HashMap::Entry* entry = visited.Lookup(
|
||||
i::HashMap::Entry* entry = visited.LookupOrInsert(
|
||||
reinterpret_cast<void*>(edges[i].to()),
|
||||
static_cast<uint32_t>(reinterpret_cast<uintptr_t>(edges[i].to())),
|
||||
true);
|
||||
static_cast<uint32_t>(reinterpret_cast<uintptr_t>(edges[i].to())));
|
||||
uint32_t ref_count = static_cast<uint32_t>(
|
||||
reinterpret_cast<uintptr_t>(entry->value));
|
||||
entry->value = reinterpret_cast<void*>(ref_count + 1);
|
||||
@ -159,8 +157,7 @@ static bool ValidateSnapshot(const v8::HeapSnapshot* snapshot, int depth = 3) {
|
||||
for (int i = 0; i < entries.length(); ++i) {
|
||||
i::HashMap::Entry* entry = visited.Lookup(
|
||||
reinterpret_cast<void*>(&entries[i]),
|
||||
static_cast<uint32_t>(reinterpret_cast<uintptr_t>(&entries[i])),
|
||||
false);
|
||||
static_cast<uint32_t>(reinterpret_cast<uintptr_t>(&entries[i])));
|
||||
if (!entry && entries[i].id() != 1) {
|
||||
entries[i].Print("entry with no retainer", "", depth, 0);
|
||||
++unretained_entries_count;
|
||||
|
Loading…
Reference in New Issue
Block a user