diff --git a/src/asmjs/asm-typer.cc b/src/asmjs/asm-typer.cc index 20b8d96053..7ed54de675 100644 --- a/src/asmjs/asm-typer.cc +++ b/src/asmjs/asm-typer.cc @@ -361,8 +361,8 @@ bool AsmTyper::AddGlobal(Variable* variable, VariableInfo* info) { return false; } - ZoneHashMap::Entry* entry = global_scope_.LookupOrInsert( - variable, ComputePointerHash(variable), ZoneAllocationPolicy(zone_)); + ZoneHashMap::Entry* entry = + global_scope_.LookupOrInsert(variable, ComputePointerHash(variable)); if (entry->value != nullptr) { return false; @@ -378,8 +378,8 @@ bool AsmTyper::AddLocal(Variable* variable, VariableInfo* info) { DCHECK(!info->IsGlobal()); DCHECK(ValidAsmIdentifier(variable->name())); - ZoneHashMap::Entry* entry = local_scope_.LookupOrInsert( - variable, ComputePointerHash(variable), ZoneAllocationPolicy(zone_)); + ZoneHashMap::Entry* entry = + local_scope_.LookupOrInsert(variable, ComputePointerHash(variable)); if (entry->value != nullptr) { return false; diff --git a/src/asmjs/asm-wasm-builder.cc b/src/asmjs/asm-wasm-builder.cc index ac2585e6ea..5f8233391e 100644 --- a/src/asmjs/asm-wasm-builder.cc +++ b/src/asmjs/asm-wasm-builder.cc @@ -664,8 +664,8 @@ class AsmWasmBuilderImpl final : public AstVisitor { FunctionTableIndices* container = new (zone()) FunctionTableIndices(); container->start_index = start_index; container->signature_index = signature_index; - ZoneHashMap::Entry* entry = function_tables_.LookupOrInsert( - v, ComputePointerHash(v), ZoneAllocationPolicy(zone())); + ZoneHashMap::Entry* entry = + function_tables_.LookupOrInsert(v, ComputePointerHash(v)); entry->value = container; } @@ -700,8 +700,8 @@ class AsmWasmBuilderImpl final : public AstVisitor { void AddImport(Variable* v, const char* name, int name_length) { ImportedFunctionIndices* indices = new (builder_->zone()) ImportedFunctionIndices(name, name_length, builder_->zone()); - ZoneHashMap::Entry* entry = table_.LookupOrInsert( - v, ComputePointerHash(v), ZoneAllocationPolicy(builder_->zone())); + ZoneHashMap::Entry* entry = + table_.LookupOrInsert(v, ComputePointerHash(v)); entry->value = indices; } @@ -1694,8 +1694,7 @@ class AsmWasmBuilderImpl final : public AstVisitor { index = current_function_builder_->AddLocal(type); IndexContainer* container = new (zone()) IndexContainer(); container->index = index; - entry = local_variables_.LookupOrInsert(v, ComputePointerHash(v), - ZoneAllocationPolicy(zone())); + entry = local_variables_.LookupOrInsert(v, ComputePointerHash(v)); entry->value = container; } return (reinterpret_cast(entry->value))->index; @@ -1709,8 +1708,7 @@ class AsmWasmBuilderImpl final : public AstVisitor { DCHECK_NULL(entry); IndexContainer* container = new (zone()) IndexContainer(); container->index = index; - entry = local_variables_.LookupOrInsert(v, ComputePointerHash(v), - ZoneAllocationPolicy(zone())); + entry = local_variables_.LookupOrInsert(v, ComputePointerHash(v)); entry->value = container; } @@ -1721,8 +1719,7 @@ class AsmWasmBuilderImpl final : public AstVisitor { uint32_t index = builder_->AddGlobal(type, 0); IndexContainer* container = new (zone()) IndexContainer(); container->index = index; - entry = global_variables_.LookupOrInsert(v, ComputePointerHash(v), - ZoneAllocationPolicy(zone())); + entry = global_variables_.LookupOrInsert(v, ComputePointerHash(v)); entry->value = container; } return (reinterpret_cast(entry->value))->index; @@ -1735,8 +1732,7 @@ class AsmWasmBuilderImpl final : public AstVisitor { uint32_t index = builder_->AddFunction(); IndexContainer* container = new (zone()) IndexContainer(); container->index = index; - entry = functions_.LookupOrInsert(v, ComputePointerHash(v), - ZoneAllocationPolicy(zone())); + entry = functions_.LookupOrInsert(v, ComputePointerHash(v)); entry->value = container; } return (reinterpret_cast(entry->value))->index; diff --git a/src/ast/ast.cc b/src/ast/ast.cc index f8cc2459bf..8d50b7c1c4 100644 --- a/src/ast/ast.cc +++ b/src/ast/ast.cc @@ -472,7 +472,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.LookupOrInsert(literal, hash, allocator); + ZoneHashMap::Entry* entry = table.LookupOrInsert(literal, hash); if (entry->value != NULL) { auto previous_kind = static_cast(entry->value)->kind(); diff --git a/src/ast/ast.h b/src/ast/ast.h index e5cb23f623..9acea70985 100644 --- a/src/ast/ast.h +++ b/src/ast/ast.h @@ -134,14 +134,13 @@ typedef ZoneList> ZoneObjectList; class FeedbackVectorSlotCache { public: explicit FeedbackVectorSlotCache(Zone* zone) - : zone_(zone), - hash_map_(base::HashMap::PointersMatch, + : hash_map_(base::HashMap::PointersMatch, ZoneHashMap::kDefaultHashMapCapacity, ZoneAllocationPolicy(zone)) {} void Put(Variable* variable, FeedbackVectorSlot slot) { - ZoneHashMap::Entry* entry = hash_map_.LookupOrInsert( - variable, ComputePointerHash(variable), ZoneAllocationPolicy(zone_)); + ZoneHashMap::Entry* entry = + hash_map_.LookupOrInsert(variable, ComputePointerHash(variable)); entry->value = reinterpret_cast(slot.ToInt()); } @@ -150,7 +149,6 @@ class FeedbackVectorSlotCache { } private: - Zone* zone_; ZoneHashMap hash_map_; }; @@ -1530,7 +1528,7 @@ class AccessorTable zone_(zone) {} Iterator lookup(Literal* literal) { - Iterator it = find(literal, true, ZoneAllocationPolicy(zone_)); + Iterator it = find(literal, true); if (it->second == NULL) it->second = new (zone_) ObjectLiteral::Accessors(); return it; } diff --git a/src/ast/scopes.cc b/src/ast/scopes.cc index 86f87b15f2..f61e43073c 100644 --- a/src/ast/scopes.cc +++ b/src/ast/scopes.cc @@ -36,9 +36,8 @@ Variable* VariableMap::Declare(Zone* zone, Scope* scope, // 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::LookupOrInsert(const_cast(name), name->hash(), - ZoneAllocationPolicy(zone)); + Entry* p = ZoneHashMap::LookupOrInsert(const_cast(name), + name->hash()); if (added) *added = p->value == nullptr; if (p->value == nullptr) { // The variable has not been declared yet -> insert it. @@ -54,11 +53,10 @@ void VariableMap::Remove(Variable* var) { ZoneHashMap::Remove(const_cast(name), name->hash()); } -void VariableMap::Add(Zone* zone, Variable* var) { +void VariableMap::Add(Variable* var) { const AstRawString* name = var->raw_name(); - Entry* p = - ZoneHashMap::LookupOrInsert(const_cast(name), name->hash(), - ZoneAllocationPolicy(zone)); + Entry* p = ZoneHashMap::LookupOrInsert(const_cast(name), + name->hash()); DCHECK_NULL(p->value); DCHECK_EQ(name, p->key); p->value = var; @@ -77,13 +75,12 @@ Variable* VariableMap::Lookup(const AstRawString* name) { SloppyBlockFunctionMap::SloppyBlockFunctionMap(Zone* zone) : ZoneHashMap(ZoneHashMap::PointersMatch, 8, ZoneAllocationPolicy(zone)) {} -void SloppyBlockFunctionMap::Declare(Zone* zone, const AstRawString* name, +void SloppyBlockFunctionMap::Declare(const AstRawString* name, SloppyBlockFunctionStatement* stmt) { // AstRawStrings are unambiguous, i.e., the same string is always represented // by the same AstRawString*. - Entry* p = - ZoneHashMap::LookupOrInsert(const_cast(name), name->hash(), - ZoneAllocationPolicy(zone)); + Entry* p = ZoneHashMap::LookupOrInsert(const_cast(name), + name->hash()); stmt->set_next(static_cast(p->value)); p->value = stmt; } @@ -697,7 +694,7 @@ void Scope::Snapshot::Reparent(DeclarationScope* new_parent) const { new_parent->AddLocal(local); if (local->mode() == VAR) { outer_closure->variables_.Remove(local); - new_parent->variables_.Add(new_parent->zone(), local); + new_parent->variables_.Add(local); } } outer_closure->locals_.Rewind(top_local_); diff --git a/src/ast/scopes.h b/src/ast/scopes.h index 44797525ca..a3de1e29b8 100644 --- a/src/ast/scopes.h +++ b/src/ast/scopes.h @@ -35,7 +35,7 @@ class VariableMap: public ZoneHashMap { Variable* Lookup(const AstRawString* name); void Remove(Variable* var); - void Add(Zone* zone, Variable* var); + void Add(Variable* var); }; @@ -43,7 +43,7 @@ class VariableMap: public ZoneHashMap { class SloppyBlockFunctionMap : public ZoneHashMap { public: explicit SloppyBlockFunctionMap(Zone* zone); - void Declare(Zone* zone, const AstRawString* name, + void Declare(const AstRawString* name, SloppyBlockFunctionStatement* statement); }; @@ -752,7 +752,7 @@ class DeclarationScope : public Scope { void DeclareSloppyBlockFunction(const AstRawString* name, SloppyBlockFunctionStatement* statement) { - sloppy_block_function_map_.Declare(zone(), name, statement); + sloppy_block_function_map_.Declare(name, statement); } // Go through sloppy_block_function_map_ and hoist those (into this scope) diff --git a/src/base/hashmap.h b/src/base/hashmap.h index 852d7d125c..619108a0a7 100644 --- a/src/base/hashmap.h +++ b/src/base/hashmap.h @@ -55,11 +55,9 @@ class TemplateHashMapImpl { // 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 default initialized value. - Entry* LookupOrInsert(const Key& key, uint32_t hash, - AllocationPolicy allocator = AllocationPolicy()); + Entry* LookupOrInsert(const Key& key, uint32_t hash); - Entry* InsertNew(const Key& key, uint32_t hash, - AllocationPolicy allocator = AllocationPolicy()); + Entry* InsertNew(const Key& key, uint32_t hash); // Removes the entry with matching key. // It returns the value of the deleted entry @@ -102,11 +100,12 @@ class TemplateHashMapImpl { Entry* map_; uint32_t capacity_; uint32_t occupancy_; + AllocationPolicy allocator_; Entry* map_end() const { return map_ + capacity_; } Entry* Probe(const Key& key, uint32_t hash) const; - void Initialize(uint32_t capacity, AllocationPolicy allocator); - void Resize(AllocationPolicy allocator); + void Initialize(uint32_t capacity); + void Resize(); }; template @@ -125,14 +124,15 @@ typedef TemplateHashMapImpl HashMap; template TemplateHashMapImpl::TemplateHashMapImpl( - MatchFun match, uint32_t initial_capacity, AllocationPolicy allocator) { + MatchFun match, uint32_t initial_capacity, AllocationPolicy allocator) + : allocator_(allocator) { match_ = match; - Initialize(initial_capacity, allocator); + Initialize(initial_capacity); } template TemplateHashMapImpl::~TemplateHashMapImpl() { - AllocationPolicy::Delete(map_); + allocator_.Delete(map_); } template @@ -146,20 +146,20 @@ TemplateHashMapImpl::Lookup(const Key& key, template typename TemplateHashMapImpl::Entry* TemplateHashMapImpl::LookupOrInsert( - const Key& key, uint32_t hash, AllocationPolicy allocator) { + const Key& key, uint32_t hash) { // Find a matching entry. Entry* p = Probe(key, hash); if (p->exists()) { return p; } - return InsertNew(key, hash, allocator); + return InsertNew(key, hash); } template typename TemplateHashMapImpl::Entry* -TemplateHashMapImpl::InsertNew( - const Key& key, uint32_t hash, AllocationPolicy allocator) { +TemplateHashMapImpl::InsertNew(const Key& key, + uint32_t hash) { // Find a matching entry. Entry* p = Probe(key, hash); DCHECK(!p->exists()); @@ -171,7 +171,7 @@ TemplateHashMapImpl::InsertNew( // Grow the map if we reached >= 80% occupancy. if (occupancy_ + occupancy_ / 4 >= capacity_) { - Resize(allocator); + Resize(); p = Probe(key, hash); } @@ -290,9 +290,9 @@ TemplateHashMapImpl::Probe(const Key& key, template void TemplateHashMapImpl::Initialize( - uint32_t capacity, AllocationPolicy allocator) { + uint32_t capacity) { DCHECK(base::bits::IsPowerOfTwo32(capacity)); - map_ = reinterpret_cast(allocator.New(capacity * sizeof(Entry))); + map_ = reinterpret_cast(allocator_.New(capacity * sizeof(Entry))); if (map_ == nullptr) { FATAL("Out of memory: HashMap::Initialize"); return; @@ -302,25 +302,24 @@ void TemplateHashMapImpl::Initialize( } template -void TemplateHashMapImpl::Resize( - AllocationPolicy allocator) { +void TemplateHashMapImpl::Resize() { Entry* map = map_; uint32_t n = occupancy_; // Allocate larger map. - Initialize(capacity_ * 2, allocator); + Initialize(capacity_ * 2); // Rehash all current entries. for (Entry* p = map; n > 0; p++) { if (p->exists()) { - Entry* entry = LookupOrInsert(p->key, p->hash, allocator); + Entry* entry = LookupOrInsert(p->key, p->hash); entry->value = p->value; n--; } } // Delete old map. - AllocationPolicy::Delete(map); + allocator_.Delete(map); } // A hash map for pointer keys and values with an STL-like interface. @@ -368,10 +367,9 @@ class TemplateHashMap Iterator begin() const { return Iterator(this, this->Start()); } Iterator end() const { return Iterator(this, nullptr); } - Iterator find(Key* key, bool insert = false, - AllocationPolicy allocator = AllocationPolicy()) { + Iterator find(Key* key, bool insert = false) { if (insert) { - return Iterator(this, this->LookupOrInsert(key, key->Hash(), allocator)); + return Iterator(this, this->LookupOrInsert(key, key->Hash())); } return Iterator(this, this->Lookup(key, key->Hash())); } diff --git a/src/compiler/state-values-utils.cc b/src/compiler/state-values-utils.cc index 77cc227038..a13bb3832e 100644 --- a/src/compiler/state-values-utils.cc +++ b/src/compiler/state-values-utils.cc @@ -104,8 +104,7 @@ int StateValuesHashKey(Node** nodes, size_t count) { Node* StateValuesCache::GetValuesNodeFromCache(Node** nodes, size_t count) { StateValuesKey key(count, nodes); int hash = StateValuesHashKey(nodes, count); - ZoneHashMap::Entry* lookup = - hash_map_.LookupOrInsert(&key, hash, ZoneAllocationPolicy(zone())); + ZoneHashMap::Entry* lookup = hash_map_.LookupOrInsert(&key, hash); DCHECK_NOT_NULL(lookup); Node* node; if (lookup->value == nullptr) { diff --git a/src/crankshaft/hydrogen-bce.cc b/src/crankshaft/hydrogen-bce.cc index d00d8ce25c..3b5940dc9f 100644 --- a/src/crankshaft/hydrogen-bce.cc +++ b/src/crankshaft/hydrogen-bce.cc @@ -316,16 +316,14 @@ BoundsCheckTable::BoundsCheckTable(Zone* zone) BoundsCheckBbData** BoundsCheckTable::LookupOrInsert(BoundsCheckKey* key, Zone* zone) { return reinterpret_cast( - &(ZoneHashMap::LookupOrInsert(key, key->Hash(), - ZoneAllocationPolicy(zone))->value)); + &(ZoneHashMap::LookupOrInsert(key, key->Hash())->value)); } void BoundsCheckTable::Insert(BoundsCheckKey* key, BoundsCheckBbData* data, Zone* zone) { - ZoneHashMap::LookupOrInsert(key, key->Hash(), ZoneAllocationPolicy(zone)) - ->value = data; + ZoneHashMap::LookupOrInsert(key, key->Hash())->value = data; }