[runtime] Remove HashTable::UsesSeed. Specialize Hash(ForObject) instead.
Bug: Change-Id: I52bd9573735ac7c28a03e070064fe89b38d479ef Reviewed-on: https://chromium-review.googlesource.com/544957 Reviewed-by: Camillo Bruni <cbruni@chromium.org> Commit-Queue: Toon Verwaest <verwaest@chromium.org> Cr-Commit-Position: refs/heads/master@{#46141}
This commit is contained in:
parent
d1f566c6f1
commit
4d05b04845
@ -5057,12 +5057,9 @@ void CodeStubAssembler::NumberDictionaryLookup(Node* dictionary,
|
||||
Node* capacity = SmiUntag(GetCapacity<Dictionary>(dictionary));
|
||||
Node* mask = IntPtrSub(capacity, IntPtrConstant(1));
|
||||
|
||||
Node* int32_seed;
|
||||
if (Dictionary::ShapeT::UsesSeed) {
|
||||
int32_seed = HashSeed();
|
||||
} else {
|
||||
int32_seed = Int32Constant(kZeroHashSeed);
|
||||
}
|
||||
Node* int32_seed = std::is_same<Dictionary, SeededNumberDictionary>::value
|
||||
? HashSeed()
|
||||
: Int32Constant(kZeroHashSeed);
|
||||
Node* hash = ChangeUint32ToWord(ComputeIntegerHash(intptr_index, int32_seed));
|
||||
Node* key_as_float64 = RoundIntPtrToFloat64(intptr_index);
|
||||
|
||||
|
@ -2603,7 +2603,7 @@ int HashTable<Derived, Shape>::FindEntry(Key key) {
|
||||
|
||||
template <typename Derived, typename Shape>
|
||||
int HashTable<Derived, Shape>::FindEntry(Isolate* isolate, Key key) {
|
||||
return FindEntry(isolate, key, HashTable::Hash(key));
|
||||
return FindEntry(isolate, key, Shape::Hash(isolate, key));
|
||||
}
|
||||
|
||||
// Find entry for key otherwise return kNotFound.
|
||||
@ -2655,9 +2655,11 @@ bool StringSetShape::IsMatch(String* key, Object* value) {
|
||||
return key->Equals(String::cast(value));
|
||||
}
|
||||
|
||||
uint32_t StringSetShape::Hash(String* key) { return key->Hash(); }
|
||||
uint32_t StringSetShape::Hash(Isolate* isolate, String* key) {
|
||||
return key->Hash();
|
||||
}
|
||||
|
||||
uint32_t StringSetShape::HashForObject(Object* object) {
|
||||
uint32_t StringSetShape::HashForObject(Isolate* isolate, Object* object) {
|
||||
return String::cast(object)->Hash();
|
||||
}
|
||||
|
||||
@ -2674,7 +2676,7 @@ Handle<Object> StringTableShape::AsHandle(Isolate* isolate,
|
||||
return key->AsHandle(isolate);
|
||||
}
|
||||
|
||||
uint32_t StringTableShape::HashForObject(Object* object) {
|
||||
uint32_t StringTableShape::HashForObject(Isolate* isolate, Object* object) {
|
||||
return String::cast(object)->Hash();
|
||||
}
|
||||
|
||||
@ -6094,12 +6096,12 @@ bool NumberDictionaryShape::IsMatch(uint32_t key, Object* other) {
|
||||
return key == static_cast<uint32_t>(other->Number());
|
||||
}
|
||||
|
||||
|
||||
uint32_t UnseededNumberDictionaryShape::Hash(uint32_t key) {
|
||||
uint32_t UnseededNumberDictionaryShape::Hash(Isolate* isolate, uint32_t key) {
|
||||
return ComputeIntegerHash(key, 0);
|
||||
}
|
||||
|
||||
uint32_t UnseededNumberDictionaryShape::HashForObject(Object* other) {
|
||||
uint32_t UnseededNumberDictionaryShape::HashForObject(Isolate* isolate,
|
||||
Object* other) {
|
||||
DCHECK(other->IsNumber());
|
||||
return ComputeIntegerHash(static_cast<uint32_t>(other->Number()), 0);
|
||||
}
|
||||
@ -6108,14 +6110,15 @@ Map* UnseededNumberDictionaryShape::GetMap(Isolate* isolate) {
|
||||
return isolate->heap()->unseeded_number_dictionary_map();
|
||||
}
|
||||
|
||||
uint32_t SeededNumberDictionaryShape::SeededHash(uint32_t key, uint32_t seed) {
|
||||
return ComputeIntegerHash(key, seed);
|
||||
uint32_t SeededNumberDictionaryShape::Hash(Isolate* isolate, uint32_t key) {
|
||||
return ComputeIntegerHash(key, isolate->heap()->HashSeed());
|
||||
}
|
||||
|
||||
uint32_t SeededNumberDictionaryShape::SeededHashForObject(uint32_t seed,
|
||||
Object* other) {
|
||||
uint32_t SeededNumberDictionaryShape::HashForObject(Isolate* isolate,
|
||||
Object* other) {
|
||||
DCHECK(other->IsNumber());
|
||||
return ComputeIntegerHash(static_cast<uint32_t>(other->Number()), seed);
|
||||
return ComputeIntegerHash(static_cast<uint32_t>(other->Number()),
|
||||
isolate->heap()->HashSeed());
|
||||
}
|
||||
|
||||
|
||||
@ -6131,12 +6134,11 @@ bool NameDictionaryShape::IsMatch(Handle<Name> key, Object* other) {
|
||||
return *key == other;
|
||||
}
|
||||
|
||||
|
||||
uint32_t NameDictionaryShape::Hash(Handle<Name> key) {
|
||||
uint32_t NameDictionaryShape::Hash(Isolate* isolate, Handle<Name> key) {
|
||||
return key->Hash();
|
||||
}
|
||||
|
||||
uint32_t NameDictionaryShape::HashForObject(Object* other) {
|
||||
uint32_t NameDictionaryShape::HashForObject(Isolate* isolate, Object* other) {
|
||||
return Name::cast(other)->Hash();
|
||||
}
|
||||
|
||||
@ -6185,12 +6187,11 @@ bool ObjectHashTableShape::IsMatch(Handle<Object> key, Object* other) {
|
||||
return key->SameValue(other);
|
||||
}
|
||||
|
||||
|
||||
uint32_t ObjectHashTableShape::Hash(Handle<Object> key) {
|
||||
uint32_t ObjectHashTableShape::Hash(Isolate* isolate, Handle<Object> key) {
|
||||
return Smi::cast(key->GetHash())->value();
|
||||
}
|
||||
|
||||
uint32_t ObjectHashTableShape::HashForObject(Object* other) {
|
||||
uint32_t ObjectHashTableShape::HashForObject(Isolate* isolate, Object* other) {
|
||||
return Smi::cast(other->GetHash())->value();
|
||||
}
|
||||
|
||||
@ -6211,9 +6212,9 @@ bool WeakHashTableShape<entrysize>::IsMatch(Handle<Object> key, Object* other) {
|
||||
: *key == other;
|
||||
}
|
||||
|
||||
|
||||
template <int entrysize>
|
||||
uint32_t WeakHashTableShape<entrysize>::Hash(Handle<Object> key) {
|
||||
uint32_t WeakHashTableShape<entrysize>::Hash(Isolate* isolate,
|
||||
Handle<Object> key) {
|
||||
intptr_t hash =
|
||||
key->IsWeakCell()
|
||||
? reinterpret_cast<intptr_t>(WeakCell::cast(*key)->value())
|
||||
@ -6222,7 +6223,8 @@ uint32_t WeakHashTableShape<entrysize>::Hash(Handle<Object> key) {
|
||||
}
|
||||
|
||||
template <int entrysize>
|
||||
uint32_t WeakHashTableShape<entrysize>::HashForObject(Object* other) {
|
||||
uint32_t WeakHashTableShape<entrysize>::HashForObject(Isolate* isolate,
|
||||
Object* other) {
|
||||
if (other->IsWeakCell()) other = WeakCell::cast(other)->value();
|
||||
intptr_t hash = reinterpret_cast<intptr_t>(other);
|
||||
return (uint32_t)(hash & 0xFFFFFFFF);
|
||||
|
@ -16060,14 +16060,12 @@ void HashTable<Derived, Shape>::Rehash(Derived* new_table) {
|
||||
|
||||
// Rehash the elements.
|
||||
int capacity = this->Capacity();
|
||||
Heap* heap = new_table->GetHeap();
|
||||
Object* the_hole = heap->the_hole_value();
|
||||
Object* undefined = heap->undefined_value();
|
||||
Isolate* isolate = new_table->GetIsolate();
|
||||
for (int i = 0; i < capacity; i++) {
|
||||
uint32_t from_index = EntryToIndex(i);
|
||||
Object* k = this->get(from_index);
|
||||
if (k != the_hole && k != undefined) {
|
||||
uint32_t hash = this->HashForObject(k);
|
||||
if (IsKey(isolate, k)) {
|
||||
uint32_t hash = Shape::HashForObject(isolate, k);
|
||||
uint32_t insertion_index =
|
||||
EntryToIndex(new_table->FindInsertionEntry(hash));
|
||||
for (int j = 0; j < Shape::kEntrySize; j++) {
|
||||
@ -16082,7 +16080,7 @@ void HashTable<Derived, Shape>::Rehash(Derived* new_table) {
|
||||
template <typename Derived, typename Shape>
|
||||
uint32_t HashTable<Derived, Shape>::EntryForProbe(Object* k, int probe,
|
||||
uint32_t expected) {
|
||||
uint32_t hash = this->HashForObject(k);
|
||||
uint32_t hash = Shape::HashForObject(GetIsolate(), k);
|
||||
uint32_t capacity = this->Capacity();
|
||||
uint32_t entry = FirstProbe(hash, capacity);
|
||||
for (int i = 1; i < probe; i++) {
|
||||
@ -17198,7 +17196,7 @@ Handle<StringSet> StringSet::Add(Handle<StringSet> stringset,
|
||||
Handle<String> name) {
|
||||
if (!stringset->Has(name)) {
|
||||
stringset = EnsureCapacity(stringset, 1);
|
||||
uint32_t hash = StringSetShape::Hash(*name);
|
||||
uint32_t hash = ShapeT::Hash(name->GetIsolate(), *name);
|
||||
int entry = stringset->FindInsertionEntry(hash);
|
||||
stringset->set(EntryToIndex(entry), *name);
|
||||
stringset->ElementAdded();
|
||||
@ -17619,7 +17617,7 @@ Handle<Derived> Dictionary<Derived, Shape>::Add(Handle<Derived> dictionary,
|
||||
PropertyDetails details,
|
||||
int* entry_out) {
|
||||
Isolate* isolate = dictionary->GetIsolate();
|
||||
uint32_t hash = dictionary->Hash(key);
|
||||
uint32_t hash = Shape::Hash(isolate, key);
|
||||
// Valdate key is absent.
|
||||
SLOW_DCHECK((dictionary->FindEntry(key) == Dictionary::kNotFound));
|
||||
// Check whether the dictionary should be extended.
|
||||
@ -18066,7 +18064,8 @@ Handle<WeakHashTable> WeakHashTable::Put(Handle<WeakHashTable> table,
|
||||
// Check whether the hash table should be extended.
|
||||
table = EnsureCapacity(table, 1, TENURED);
|
||||
|
||||
table->AddEntry(table->FindInsertionEntry(table->Hash(key)), key_cell, value);
|
||||
uint32_t hash = ShapeT::Hash(isolate, key);
|
||||
table->AddEntry(table->FindInsertionEntry(hash), key_cell, value);
|
||||
return table;
|
||||
}
|
||||
|
||||
|
@ -66,11 +66,11 @@ class CodeCacheHashTableShape : public BaseShape<CodeCacheHashTableKey*> {
|
||||
return key->IsMatch(value);
|
||||
}
|
||||
|
||||
static inline uint32_t Hash(CodeCacheHashTableKey* key) {
|
||||
static inline uint32_t Hash(Isolate* isolate, CodeCacheHashTableKey* key) {
|
||||
return key->Hash();
|
||||
}
|
||||
|
||||
static inline uint32_t HashForObject(Object* object) {
|
||||
static inline uint32_t HashForObject(Isolate* isolate, Object* object) {
|
||||
FixedArray* pair = FixedArray::cast(object);
|
||||
Name* name = Name::cast(pair->get(0));
|
||||
Code* code = Code::cast(pair->get(1));
|
||||
|
@ -39,7 +39,8 @@ uint32_t CompilationCacheShape::StringSharedHash(String* source,
|
||||
return hash;
|
||||
}
|
||||
|
||||
uint32_t CompilationCacheShape::HashForObject(Object* object) {
|
||||
uint32_t CompilationCacheShape::HashForObject(Isolate* isolate,
|
||||
Object* object) {
|
||||
if (object->IsNumber()) return static_cast<uint32_t>(object->Number());
|
||||
|
||||
FixedArray* val = FixedArray::cast(object);
|
||||
|
@ -19,7 +19,9 @@ class CompilationCacheShape : public BaseShape<HashTableKey*> {
|
||||
return key->IsMatch(value);
|
||||
}
|
||||
|
||||
static inline uint32_t Hash(HashTableKey* key) { return key->Hash(); }
|
||||
static inline uint32_t Hash(Isolate* isolate, HashTableKey* key) {
|
||||
return key->Hash();
|
||||
}
|
||||
|
||||
static inline uint32_t RegExpHash(String* string, Smi* flags);
|
||||
|
||||
@ -28,7 +30,7 @@ class CompilationCacheShape : public BaseShape<HashTableKey*> {
|
||||
LanguageMode language_mode,
|
||||
int position);
|
||||
|
||||
static inline uint32_t HashForObject(Object* object);
|
||||
static inline uint32_t HashForObject(Isolate* isolate, Object* object);
|
||||
|
||||
static const int kPrefixSize = 0;
|
||||
static const int kEntrySize = 3;
|
||||
|
@ -122,8 +122,8 @@ class BaseDictionaryShape : public BaseShape<Key> {
|
||||
class NameDictionaryShape : public BaseDictionaryShape<Handle<Name>> {
|
||||
public:
|
||||
static inline bool IsMatch(Handle<Name> key, Object* other);
|
||||
static inline uint32_t Hash(Handle<Name> key);
|
||||
static inline uint32_t HashForObject(Object* object);
|
||||
static inline uint32_t Hash(Isolate* isolate, Handle<Name> key);
|
||||
static inline uint32_t HashForObject(Isolate* isolate, Object* object);
|
||||
static inline Handle<Object> AsHandle(Isolate* isolate, Handle<Name> key);
|
||||
static const int kPrefixSize = 1;
|
||||
static const int kEntrySize = 3;
|
||||
@ -222,12 +222,11 @@ class NumberDictionaryShape : public BaseDictionaryShape<uint32_t> {
|
||||
|
||||
class SeededNumberDictionaryShape : public NumberDictionaryShape {
|
||||
public:
|
||||
static const bool UsesSeed = true;
|
||||
static const int kPrefixSize = 1;
|
||||
static const int kEntrySize = 3;
|
||||
|
||||
static inline uint32_t SeededHash(uint32_t key, uint32_t seed);
|
||||
static inline uint32_t SeededHashForObject(uint32_t seed, Object* object);
|
||||
static inline uint32_t Hash(Isolate* isolate, uint32_t key);
|
||||
static inline uint32_t HashForObject(Isolate* isolate, Object* object);
|
||||
};
|
||||
|
||||
class UnseededNumberDictionaryShape : public NumberDictionaryShape {
|
||||
@ -235,8 +234,8 @@ class UnseededNumberDictionaryShape : public NumberDictionaryShape {
|
||||
static const int kPrefixSize = 0;
|
||||
static const int kEntrySize = 2;
|
||||
|
||||
static inline uint32_t Hash(uint32_t key);
|
||||
static inline uint32_t HashForObject(Object* object);
|
||||
static inline uint32_t Hash(Isolate* isolate, uint32_t key);
|
||||
static inline uint32_t HashForObject(Isolate* isolate, Object* object);
|
||||
|
||||
template <typename Dictionary>
|
||||
static inline PropertyDetails DetailsAt(Dictionary* dict, int entry) {
|
||||
|
@ -10,24 +10,6 @@
|
||||
namespace v8 {
|
||||
namespace internal {
|
||||
|
||||
template <typename Derived, typename Shape>
|
||||
uint32_t HashTable<Derived, Shape>::Hash(Key key) {
|
||||
if (Shape::UsesSeed) {
|
||||
return Shape::SeededHash(key, GetHeap()->HashSeed());
|
||||
} else {
|
||||
return Shape::Hash(key);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Derived, typename Shape>
|
||||
uint32_t HashTable<Derived, Shape>::HashForObject(Object* object) {
|
||||
if (Shape::UsesSeed) {
|
||||
return Shape::SeededHashForObject(GetHeap()->HashSeed(), object);
|
||||
} else {
|
||||
return Shape::HashForObject(object);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
} // namespace v8
|
||||
|
||||
|
@ -34,9 +34,9 @@ namespace internal {
|
||||
// // Tells whether key matches other.
|
||||
// static bool IsMatch(Key key, Object* other);
|
||||
// // Returns the hash value for key.
|
||||
// static uint32_t Hash(Key key);
|
||||
// static uint32_t Hash(Isolate* isolate, Key key);
|
||||
// // Returns the hash value for object.
|
||||
// static uint32_t HashForObject(Object* object);
|
||||
// static uint32_t HashForObject(Isolate* isolate, Object* object);
|
||||
// // Convert key to an object.
|
||||
// static inline Handle<Object> AsHandle(Isolate* isolate, Key key);
|
||||
// // The prefix size indicates number of elements in the beginning
|
||||
@ -56,17 +56,6 @@ template <typename KeyT>
|
||||
class BaseShape {
|
||||
public:
|
||||
typedef KeyT Key;
|
||||
static const bool UsesSeed = false;
|
||||
static uint32_t Hash(Key key) { return 0; }
|
||||
static uint32_t SeededHash(Key key, uint32_t seed) {
|
||||
DCHECK(UsesSeed);
|
||||
return Hash(key);
|
||||
}
|
||||
static uint32_t HashForObject(Object* object) { return 0; }
|
||||
static uint32_t SeededHashForObject(uint32_t seed, Object* object) {
|
||||
DCHECK(UsesSeed);
|
||||
return HashForObject(object);
|
||||
}
|
||||
static inline Map* GetMap(Isolate* isolate);
|
||||
static const bool kNeedsHoleCheck = true;
|
||||
};
|
||||
@ -97,7 +86,7 @@ class V8_EXPORT_PRIVATE HashTableBase : public NON_EXPORTED_BASE(FixedArray) {
|
||||
|
||||
// Tells whether k is a real key. The hole and undefined are not allowed
|
||||
// as keys and can be used to indicate missing or deleted elements.
|
||||
inline bool IsKey(Isolate* isolate, Object* k);
|
||||
static inline bool IsKey(Isolate* isolate, Object* k);
|
||||
|
||||
// Compute the probe offset (quadratic probing).
|
||||
INLINE(static uint32_t GetProbeOffset(uint32_t n)) {
|
||||
@ -144,11 +133,6 @@ class HashTable : public HashTableBase {
|
||||
typedef Shape ShapeT;
|
||||
typedef typename Shape::Key Key;
|
||||
|
||||
// Wrapper methods. Defined in src/objects/hash-table-inl.h
|
||||
// to break a cycle with src/heap/heap.h.
|
||||
inline uint32_t Hash(Key key);
|
||||
inline uint32_t HashForObject(Object* object);
|
||||
|
||||
// Returns a new HashTable object.
|
||||
MUST_USE_RESULT static Handle<Derived> New(
|
||||
Isolate* isolate, int at_least_space_for,
|
||||
@ -271,8 +255,8 @@ class HashTableKey {
|
||||
class ObjectHashTableShape : public BaseShape<Handle<Object>> {
|
||||
public:
|
||||
static inline bool IsMatch(Handle<Object> key, Object* other);
|
||||
static inline uint32_t Hash(Handle<Object> key);
|
||||
static inline uint32_t HashForObject(Object* object);
|
||||
static inline uint32_t Hash(Isolate* isolate, Handle<Object> key);
|
||||
static inline uint32_t HashForObject(Isolate* isolate, Object* object);
|
||||
static inline Handle<Object> AsHandle(Isolate* isolate, Handle<Object> key);
|
||||
static const int kPrefixSize = 0;
|
||||
static const int kEntrySize = 2;
|
||||
@ -573,8 +557,8 @@ template <int entrysize>
|
||||
class WeakHashTableShape : public BaseShape<Handle<Object>> {
|
||||
public:
|
||||
static inline bool IsMatch(Handle<Object> key, Object* other);
|
||||
static inline uint32_t Hash(Handle<Object> key);
|
||||
static inline uint32_t HashForObject(Object* object);
|
||||
static inline uint32_t Hash(Isolate* isolate, Handle<Object> key);
|
||||
static inline uint32_t HashForObject(Isolate* isolate, Object* object);
|
||||
static inline Handle<Object> AsHandle(Isolate* isolate, Handle<Object> key);
|
||||
static const int kPrefixSize = 0;
|
||||
static const int kEntrySize = entrysize;
|
||||
|
@ -36,9 +36,9 @@ class StringTableShape : public BaseShape<StringTableKey*> {
|
||||
return key->IsMatch(value);
|
||||
}
|
||||
|
||||
static inline uint32_t Hash(Key key) { return key->Hash(); }
|
||||
static inline uint32_t Hash(Isolate* isolate, Key key) { return key->Hash(); }
|
||||
|
||||
static inline uint32_t HashForObject(Object* object);
|
||||
static inline uint32_t HashForObject(Isolate* isolate, Object* object);
|
||||
|
||||
static inline Handle<Object> AsHandle(Isolate* isolate, Key key);
|
||||
|
||||
@ -81,8 +81,8 @@ class StringTable : public HashTable<StringTable, StringTableShape> {
|
||||
class StringSetShape : public BaseShape<String*> {
|
||||
public:
|
||||
static inline bool IsMatch(String* key, Object* value);
|
||||
static inline uint32_t Hash(String* key);
|
||||
static inline uint32_t HashForObject(Object* object);
|
||||
static inline uint32_t Hash(Isolate* isolate, String* key);
|
||||
static inline uint32_t HashForObject(Isolate* isolate, Object* object);
|
||||
|
||||
static const int kPrefixSize = 0;
|
||||
static const int kEntrySize = 1;
|
||||
|
Loading…
Reference in New Issue
Block a user