diff --git a/src/api/api.cc b/src/api/api.cc index 6285ec1821..88f0475d7f 100644 --- a/src/api/api.cc +++ b/src/api/api.cc @@ -5135,7 +5135,7 @@ MaybeLocal v8::Function::FunctionProtoToString(Local context) { int Name::GetIdentityHash() { auto self = Utils::OpenHandle(this); - return static_cast(self->Hash()); + return static_cast(self->EnsureHash()); } int String::Length() const { diff --git a/src/ast/ast-value-factory.h b/src/ast/ast-value-factory.h index bf7de49d1a..9edbc5f55b 100644 --- a/src/ast/ast-value-factory.h +++ b/src/ast/ast-value-factory.h @@ -77,7 +77,11 @@ class AstRawString final : public ZoneObject { // For storing AstRawStrings in a hash map. uint32_t raw_hash_field() const { return raw_hash_field_; } - uint32_t Hash() const { return raw_hash_field_ >> Name::kHashShift; } + uint32_t Hash() const { + // Hash field must be computed. + DCHECK_EQ(raw_hash_field_ & Name::kHashNotComputedMask, 0); + return raw_hash_field_ >> Name::kHashShift; + } // This function can be called after internalizing. V8_INLINE Handle string() const { diff --git a/src/diagnostics/objects-debug.cc b/src/diagnostics/objects-debug.cc index 7c74bac410..574fd5369f 100644 --- a/src/diagnostics/objects-debug.cc +++ b/src/diagnostics/objects-debug.cc @@ -278,7 +278,7 @@ void HeapObject::VerifyHeapPointer(Isolate* isolate, Object p) { void Symbol::SymbolVerify(Isolate* isolate) { TorqueGeneratedClassVerifiers::SymbolVerify(*this, isolate); CHECK(HasHashCode()); - CHECK_GT(Hash(), 0); + CHECK_GT(hash(), 0); CHECK(description().IsUndefined(isolate) || description().IsString()); CHECK_IMPLIES(IsPrivateName(), IsPrivate()); CHECK_IMPLIES(IsPrivateBrand(), IsPrivateName()); @@ -938,7 +938,13 @@ void Oddball::OddballVerify(Isolate* isolate) { } } -USE_TORQUE_VERIFIER(PropertyCell) +void PropertyCell::PropertyCellVerify(Isolate* isolate) { + // TODO(torque): replace with USE_TORQUE_VERIFIER(PropertyCell) once + // it supports UniqueName type. + TorqueGeneratedClassVerifiers::PropertyCellVerify(*this, isolate); + + CHECK(name().IsUniqueName()); +} void CodeDataContainer::CodeDataContainerVerify(Isolate* isolate) { CHECK(IsCodeDataContainer()); diff --git a/src/heap/setup-heap-internal.cc b/src/heap/setup-heap-internal.cc index a2b77564ef..30bf6fa1cc 100644 --- a/src/heap/setup-heap-internal.cc +++ b/src/heap/setup-heap-internal.cc @@ -1026,8 +1026,8 @@ void Heap::CreateInitialObjects() { AllocationType::kReadOnly)); // Evaluate the hash values which will then be cached in the strings. - isolate()->factory()->zero_string()->Hash(); - isolate()->factory()->one_string()->Hash(); + isolate()->factory()->zero_string()->EnsureHash(); + isolate()->factory()->one_string()->EnsureHash(); // Initialize builtins constants table. set_builtins_constants_table(roots.empty_fixed_array()); diff --git a/src/ic/stub-cache.cc b/src/ic/stub-cache.cc index 2c66d4bee2..cf276ea040 100644 --- a/src/ic/stub-cache.cc +++ b/src/ic/stub-cache.cc @@ -71,7 +71,6 @@ bool CommonStubCacheChecks(StubCache* stub_cache, Name name, Map map, DCHECK(!Heap::InYoungGeneration(name)); DCHECK(!Heap::InYoungGeneration(handler)); DCHECK(name.IsUniqueName()); - DCHECK(name.HasHashCode()); if (handler->ptr() != kNullAddress) DCHECK(IC::IsHandler(handler)); return true; } diff --git a/src/logging/log-utils.cc b/src/logging/log-utils.cc index aaf7a37618..e8493cfa73 100644 --- a/src/logging/log-utils.cc +++ b/src/logging/log-utils.cc @@ -192,7 +192,7 @@ void Log::MessageBuilder::AppendSymbolName(Symbol symbol) { AppendSymbolNameDetails(String::cast(symbol.description()), false); os << "\" "; } - os << "hash " << std::hex << symbol.Hash() << std::dec << ")"; + os << "hash " << std::hex << symbol.hash() << std::dec << ")"; } void Log::MessageBuilder::AppendSymbolNameDetails(String str, diff --git a/src/logging/log.cc b/src/logging/log.cc index 61909ae967..1c0ebb03be 100644 --- a/src/logging/log.cc +++ b/src/logging/log.cc @@ -124,7 +124,7 @@ class CodeEventLogger::NameBuffer { AppendBytes("\" "); } AppendBytes("hash "); - AppendHex(symbol.Hash()); + AppendHex(symbol.hash()); AppendByte(')'); } } @@ -232,7 +232,7 @@ void CodeEventLogger::CodeCreateEvent(LogEventsAndTags tag, name_buffer_->AppendString(String::cast(*script_name)); } else { name_buffer_->AppendBytes("symbol(hash "); - name_buffer_->AppendHex(Name::cast(*script_name).Hash()); + name_buffer_->AppendHex(Name::cast(*script_name).hash()); name_buffer_->AppendByte(')'); } name_buffer_->AppendByte(':'); diff --git a/src/objects/compilation-cache-table-inl.h b/src/objects/compilation-cache-table-inl.h index 473eed496c..496332490e 100644 --- a/src/objects/compilation-cache-table-inl.h +++ b/src/objects/compilation-cache-table-inl.h @@ -27,14 +27,14 @@ NEVER_READ_ONLY_SPACE_IMPL(CompilationCacheTable) CAST_ACCESSOR(CompilationCacheTable) uint32_t CompilationCacheShape::RegExpHash(String string, Smi flags) { - return string.Hash() + flags.value(); + return string.EnsureHash() + flags.value(); } uint32_t CompilationCacheShape::StringSharedHash(String source, SharedFunctionInfo shared, LanguageMode language_mode, int position) { - uint32_t hash = source.Hash(); + uint32_t hash = source.EnsureHash(); if (shared.HasSourceCode()) { // Instead of using the SharedFunctionInfo pointer in the hash // code computation, we use a combination of the hash of the @@ -42,7 +42,7 @@ uint32_t CompilationCacheShape::StringSharedHash(String source, // We do this to ensure that the cache entries can survive garbage // collection. Script script(Script::cast(shared.script())); - hash ^= String::cast(script.source()).Hash(); + hash ^= String::cast(script.source()).EnsureHash(); STATIC_ASSERT(LanguageModeSize == 2); if (is_strict(language_mode)) hash ^= 0x8000; hash += position; diff --git a/src/objects/descriptor-array-inl.h b/src/objects/descriptor-array-inl.h index 21f43d292a..d01e103c66 100644 --- a/src/objects/descriptor-array-inl.h +++ b/src/objects/descriptor-array-inl.h @@ -223,7 +223,7 @@ void DescriptorArray::Append(Descriptor* desc) { set_number_of_descriptors(descriptor_number + 1); Set(InternalIndex(descriptor_number), desc); - uint32_t hash = desc->GetKey()->Hash(); + uint32_t hash = desc->GetKey()->hash(); int insertion; diff --git a/src/objects/dictionary-inl.h b/src/objects/dictionary-inl.h index 0e68a7f774..026c643455 100644 --- a/src/objects/dictionary-inl.h +++ b/src/objects/dictionary-inl.h @@ -279,11 +279,13 @@ bool NameDictionaryShape::IsMatch(Handle key, Object other) { } uint32_t NameDictionaryShape::Hash(ReadOnlyRoots roots, Handle key) { - return key->Hash(); + DCHECK(key->IsUniqueName()); + return key->hash(); } uint32_t NameDictionaryShape::HashForObject(ReadOnlyRoots roots, Object other) { - return Name::cast(other).Hash(); + DCHECK(other.IsUniqueName()); + return Name::cast(other).hash(); } bool GlobalDictionaryShape::IsMatch(Handle key, Object other) { @@ -294,7 +296,7 @@ bool GlobalDictionaryShape::IsMatch(Handle key, Object other) { uint32_t GlobalDictionaryShape::HashForObject(ReadOnlyRoots roots, Object other) { - return PropertyCell::cast(other).name().Hash(); + return PropertyCell::cast(other).name().hash(); } Handle NameDictionaryShape::AsHandle(Isolate* isolate, diff --git a/src/objects/js-objects.cc b/src/objects/js-objects.cc index 8e35787b36..0c8ca1973f 100644 --- a/src/objects/js-objects.cc +++ b/src/objects/js-objects.cc @@ -2389,7 +2389,7 @@ void JSObject::SetNormalizedProperty(Handle object, Handle name, DCHECK(name->IsUniqueName()); Isolate* isolate = object->GetIsolate(); - uint32_t hash = name->Hash(); + uint32_t hash = name->hash(); if (object->IsJSGlobalObject()) { Handle global_obj = Handle::cast(object); diff --git a/src/objects/keys.cc b/src/objects/keys.cc index 04bc9bc64a..fe5f4bef4b 100644 --- a/src/objects/keys.cc +++ b/src/objects/keys.cc @@ -1251,7 +1251,7 @@ Maybe KeyAccumulator::CollectOwnJSProxyKeys(Handle receiver, int unchecked_result_keys_size = 0; for (int i = 0; i < trap_result->length(); ++i) { Handle key(Name::cast(trap_result->get(i)), isolate_); - auto entry = unchecked_result_keys.LookupOrInsert(key, key->Hash()); + auto entry = unchecked_result_keys.LookupOrInsert(key, key->EnsureHash()); if (entry->value != kPresent) { entry->value = kPresent; unchecked_result_keys_size++; @@ -1313,7 +1313,7 @@ Maybe KeyAccumulator::CollectOwnJSProxyKeys(Handle receiver, Handle key(Name::cast(raw_key), isolate_); // 19a. If key is not an element of uncheckedResultKeys, throw a // TypeError exception. - auto found = unchecked_result_keys.Lookup(key, key->Hash()); + auto found = unchecked_result_keys.Lookup(key, key->hash()); if (found == nullptr || found->value == kGone) { isolate_->Throw(*isolate_->factory()->NewTypeError( MessageTemplate::kProxyOwnKeysMissing, key)); @@ -1334,7 +1334,7 @@ Maybe KeyAccumulator::CollectOwnJSProxyKeys(Handle receiver, Handle key(Name::cast(raw_key), isolate_); // 21a. If key is not an element of uncheckedResultKeys, throw a // TypeError exception. - auto found = unchecked_result_keys.Lookup(key, key->Hash()); + auto found = unchecked_result_keys.Lookup(key, key->hash()); if (found == nullptr || found->value == kGone) { isolate_->Throw(*isolate_->factory()->NewTypeError( MessageTemplate::kProxyOwnKeysMissing, key)); diff --git a/src/objects/name-inl.h b/src/objects/name-inl.h index 5c9712552e..f07e1bb9ce 100644 --- a/src/objects/name-inl.h +++ b/src/objects/name-inl.h @@ -5,10 +5,10 @@ #ifndef V8_OBJECTS_NAME_INL_H_ #define V8_OBJECTS_NAME_INL_H_ -#include "src/objects/name.h" - +#include "src/base/logging.h" #include "src/heap/heap-write-barrier-inl.h" #include "src/objects/map-inl.h" +#include "src/objects/name.h" #include "src/objects/primitive-heap-object-inl.h" // Has to be the last include (doesn't have include guards): @@ -60,6 +60,7 @@ DEF_GETTER(Name, IsUniqueName, bool) { bool result = (type & (kIsNotStringMask | kIsNotInternalizedMask)) != (kStringTag | kNotInternalizedTag); SLOW_DCHECK(result == HeapObject::IsUniqueName()); + DCHECK_IMPLIES(result, HasHashCode()); return result; } @@ -82,13 +83,13 @@ bool Name::Equals(Isolate* isolate, Handle one, Handle two) { Handle::cast(two)); } -bool Name::IsHashFieldComputed(uint32_t field) { - return (field & kHashNotComputedMask) == 0; +bool Name::IsHashFieldComputed(uint32_t raw_hash_field) { + return (raw_hash_field & kHashNotComputedMask) == 0; } -bool Name::HasHashCode() { return IsHashFieldComputed(raw_hash_field()); } +bool Name::HasHashCode() const { return IsHashFieldComputed(raw_hash_field()); } -uint32_t Name::Hash() { +uint32_t Name::EnsureHash() { // Fast case: has hash code already been computed? uint32_t field = raw_hash_field(); if (IsHashFieldComputed(field)) return field >> kHashShift; diff --git a/src/objects/name.h b/src/objects/name.h index fc0927083e..49d593372d 100644 --- a/src/objects/name.h +++ b/src/objects/name.h @@ -23,12 +23,11 @@ namespace internal { class Name : public TorqueGeneratedName { public: // Tells whether the hash code has been computed. - inline bool HasHashCode(); + inline bool HasHashCode() const; // Returns a hash value used for the property table. Ensures that the hash // value is computed. - // TODO(ishell): rename to EnsureHash(). - inline uint32_t Hash(); + inline uint32_t EnsureHash(); // Returns a hash value used for the property table (same as Hash()), assumes // the hash is already computed. @@ -139,8 +138,7 @@ class Name : public TorqueGeneratedName { static const int kEmptyHashField = kIsNotIntegerIndexMask | kHashNotComputedMask; - protected: - static inline bool IsHashFieldComputed(uint32_t field); + static inline bool IsHashFieldComputed(uint32_t raw_hash_field); TQ_OBJECT_CONSTRUCTORS(Name) }; diff --git a/src/objects/objects-inl.h b/src/objects/objects-inl.h index 65ac811e44..e394db173e 100644 --- a/src/objects/objects-inl.h +++ b/src/objects/objects-inl.h @@ -1044,11 +1044,11 @@ Object Object::GetSimpleHash(Object object) { return Smi::FromInt(hash & Smi::kMaxValue); } if (object.IsName()) { - uint32_t hash = Name::cast(object).Hash(); + uint32_t hash = Name::cast(object).EnsureHash(); return Smi::FromInt(hash); } if (object.IsOddball()) { - uint32_t hash = Oddball::cast(object).to_string().Hash(); + uint32_t hash = Oddball::cast(object).to_string().EnsureHash(); return Smi::FromInt(hash); } if (object.IsBigInt()) { diff --git a/src/objects/objects.cc b/src/objects/objects.cc index 5b9f647a58..1b039f1e68 100644 --- a/src/objects/objects.cc +++ b/src/objects/objects.cc @@ -2432,7 +2432,7 @@ void HeapObject::RehashBasedOnMap(Isolate* isolate) { case INTERNALIZED_STRING_TYPE: // Rare case, rehash read-only space strings before they are sealed. DCHECK(ReadOnlyHeap::Contains(*this)); - String::cast(*this).Hash(); + String::cast(*this).EnsureHash(); break; default: UNREACHABLE(); diff --git a/src/objects/ordered-hash-table.cc b/src/objects/ordered-hash-table.cc index 0d90a72af4..39db901560 100644 --- a/src/objects/ordered-hash-table.cc +++ b/src/objects/ordered-hash-table.cc @@ -421,7 +421,7 @@ InternalIndex OrderedNameDictionary::FindEntry(LocalIsolate* isolate, return InternalIndex::NotFound(); } - int raw_entry = HashToEntryRaw(raw_key.Hash()); + int raw_entry = HashToEntryRaw(raw_key.hash()); while (raw_entry != kNotFound) { InternalIndex entry(raw_entry); Object candidate_key = KeyAt(entry); @@ -474,6 +474,7 @@ template MaybeHandle OrderedNameDictionary::Add( LocalIsolate* isolate, Handle table, Handle key, Handle value, PropertyDetails details) { + DCHECK(key->IsUniqueName()); DCHECK(table->FindEntry(isolate, *key).is_not_found()); MaybeHandle table_candidate = @@ -482,7 +483,7 @@ MaybeHandle OrderedNameDictionary::Add( return table_candidate; } // Read the existing bucket values. - int hash = key->Hash(); + int hash = key->hash(); int bucket = table->HashToBucket(hash); int previous_entry = table->HashToEntryRaw(hash); int nof = table->NumberOfElements(); @@ -834,7 +835,7 @@ SmallOrderedHashTable::FindEntry(Isolate* isolate, DCHECK(key.IsUniqueName()); Name raw_key = Name::cast(key); - int raw_entry = HashToFirstEntry(raw_key.Hash()); + int raw_entry = HashToFirstEntry(raw_key.hash()); // Walk the chain in the bucket to find the key. while (raw_entry != kNotFound) { @@ -850,6 +851,7 @@ SmallOrderedHashTable::FindEntry(Isolate* isolate, MaybeHandle SmallOrderedNameDictionary::Add( Isolate* isolate, Handle table, Handle key, Handle value, PropertyDetails details) { + DCHECK(key->IsUniqueName()); DCHECK(table->FindEntry(isolate, *key).is_not_found()); if (table->UsedCapacity() >= table->Capacity()) { @@ -863,7 +865,7 @@ MaybeHandle SmallOrderedNameDictionary::Add( int nof = table->NumberOfElements(); // Read the existing bucket values. - int hash = key->Hash(); + int hash = key->hash(); int bucket = table->HashToBucket(hash); int previous_entry = table->HashToFirstEntry(hash); diff --git a/src/objects/source-text-module.cc b/src/objects/source-text-module.cc index 67ed8d9bfb..ca5dd2c2a1 100644 --- a/src/objects/source-text-module.cc +++ b/src/objects/source-text-module.cc @@ -19,7 +19,7 @@ namespace internal { struct StringHandleHash { V8_INLINE size_t operator()(Handle string) const { - return string->Hash(); + return string->EnsureHash(); } }; diff --git a/src/objects/string-set-inl.h b/src/objects/string-set-inl.h index 49e96dd2a6..ff35fe085a 100644 --- a/src/objects/string-set-inl.h +++ b/src/objects/string-set-inl.h @@ -26,11 +26,11 @@ bool StringSetShape::IsMatch(String key, Object value) { } uint32_t StringSetShape::Hash(ReadOnlyRoots roots, String key) { - return key.Hash(); + return key.EnsureHash(); } uint32_t StringSetShape::HashForObject(ReadOnlyRoots roots, Object object) { - return String::cast(object).Hash(); + return String::cast(object).EnsureHash(); } } // namespace internal diff --git a/src/objects/string-table.cc b/src/objects/string-table.cc index 9c129e0d78..0092cc65fb 100644 --- a/src/objects/string-table.cc +++ b/src/objects/string-table.cc @@ -237,7 +237,7 @@ std::unique_ptr StringTable::Data::Resize( Object element = data->Get(isolate, i); if (element == empty_element() || element == deleted_element()) continue; String string = String::cast(element); - uint32_t hash = string.Hash(); + uint32_t hash = string.hash(); InternalIndex insertion_index = new_data->FindInsertionEntry(isolate, hash); new_data->Set(insertion_index, string); } @@ -354,7 +354,7 @@ class InternalizedStringKey final : public StringTableKey { DCHECK(!string->IsInternalizedString()); DCHECK(string->IsFlat()); // Make sure hash_field is computed. - string->Hash(); + string->EnsureHash(); set_raw_hash_field(string->raw_hash_field()); } diff --git a/src/objects/string.cc b/src/objects/string.cc index 445f3cc4ca..a07239e37d 100644 --- a/src/objects/string.cc +++ b/src/objects/string.cc @@ -206,7 +206,8 @@ bool String::MakeExternal(v8::String::ExternalStringResource* resource) { self.AllocateExternalPointerEntries(isolate); self.SetResource(isolate, resource); isolate->heap()->RegisterExternalString(*this); - if (is_internalized) self.Hash(); // Force regeneration of the hash value. + // Force regeneration of the hash value. + if (is_internalized) self.EnsureHash(); return true; } @@ -282,7 +283,8 @@ bool String::MakeExternal(v8::String::ExternalOneByteStringResource* resource) { self.AllocateExternalPointerEntries(isolate); self.SetResource(isolate, resource); isolate->heap()->RegisterExternalString(*this); - if (is_internalized) self.Hash(); // Force regeneration of the hash value. + // Force regeneration of the hash value. + if (is_internalized) self.EnsureHash(); return true; } @@ -515,9 +517,8 @@ Handle String::ToNumber(Isolate* isolate, Handle subject) { // Update the hash field to speed up sequential convertions. uint32_t raw_hash_field = StringHasher::MakeArrayIndexHash(d, len); #ifdef DEBUG - subject->Hash(); // Force hash calculation. - DCHECK_EQ(static_cast(subject->raw_hash_field()), - static_cast(raw_hash_field)); + subject->EnsureHash(); // Force hash calculation. + DCHECK_EQ(subject->raw_hash_field(), raw_hash_field); #endif subject->set_raw_hash_field(raw_hash_field); } @@ -813,7 +814,7 @@ bool String::SlowEquals(String other) { if (HasHashCode() && other.HasHashCode()) { #ifdef ENABLE_SLOW_DCHECKS if (FLAG_enable_slow_asserts) { - if (Hash() != other.Hash()) { + if (hash() != other.hash()) { bool found_difference = false; for (int i = 0; i < len; i++) { if (Get(i) != other.Get(i)) { @@ -825,7 +826,7 @@ bool String::SlowEquals(String other) { } } #endif - if (Hash() != other.Hash()) return false; + if (hash() != other.hash()) return false; } // We know the strings are both non-empty. Compare the first chars @@ -864,7 +865,7 @@ bool String::SlowEquals(Isolate* isolate, Handle one, if (one->HasHashCode() && two->HasHashCode()) { #ifdef ENABLE_SLOW_DCHECKS if (FLAG_enable_slow_asserts) { - if (one->Hash() != two->Hash()) { + if (one->hash() != two->hash()) { bool found_difference = false; for (int i = 0; i < one_length; i++) { if (one->Get(i) != two->Get(i)) { @@ -876,7 +877,7 @@ bool String::SlowEquals(Isolate* isolate, Handle one, } } #endif - if (one->Hash() != two->Hash()) return false; + if (one->hash() != two->hash()) return false; } // We know the strings are both non-empty. Compare the first chars @@ -1417,7 +1418,7 @@ bool String::SlowAsArrayIndex(uint32_t* index) { DisallowHeapAllocation no_gc; int length = this->length(); if (length <= kMaxCachedArrayIndexLength) { - Hash(); // Force computation of hash code. + EnsureHash(); // Force computation of hash code. uint32_t field = raw_hash_field(); if ((field & kIsNotIntegerIndexMask) != 0) return false; *index = ArrayIndexValueBits::decode(field); @@ -1432,7 +1433,7 @@ bool String::SlowAsIntegerIndex(size_t* index) { DisallowHeapAllocation no_gc; int length = this->length(); if (length <= kMaxCachedArrayIndexLength) { - Hash(); // Force computation of hash code. + EnsureHash(); // Force computation of hash code. uint32_t field = raw_hash_field(); if ((field & kIsNotIntegerIndexMask) != 0) return false; *index = ArrayIndexValueBits::decode(field); diff --git a/src/objects/transitions-inl.h b/src/objects/transitions-inl.h index d9d2f83a7f..d337d18cf2 100644 --- a/src/objects/transitions-inl.h +++ b/src/objects/transitions-inl.h @@ -188,9 +188,6 @@ int TransitionArray::SearchSpecial(Symbol symbol, int* out_insertion_index) { int TransitionArray::SearchName(Name name, int* out_insertion_index) { DCHECK(name.IsUniqueName()); - // The name is taken from DescriptorArray, so it must already has a computed - // hash. - DCHECK(name.HasHashCode()); return internal::Search(this, name, number_of_entries(), out_insertion_index); } diff --git a/src/regexp/regexp.cc b/src/regexp/regexp.cc index b62ad1fff8..aea456af04 100644 --- a/src/regexp/regexp.cc +++ b/src/regexp/regexp.cc @@ -1123,7 +1123,7 @@ Object RegExpResultsCache::Lookup(Heap* heap, String key_string, cache = heap->regexp_multiple_cache(); } - uint32_t hash = key_string.Hash(); + uint32_t hash = key_string.hash(); uint32_t index = ((hash & (kRegExpResultsCacheSize - 1)) & ~(kArrayEntriesPerCacheEntry - 1)); if (cache.get(index + kStringOffset) != key_string || @@ -1158,7 +1158,7 @@ void RegExpResultsCache::Enter(Isolate* isolate, Handle key_string, cache = factory->regexp_multiple_cache(); } - uint32_t hash = key_string->Hash(); + uint32_t hash = key_string->hash(); uint32_t index = ((hash & (kRegExpResultsCacheSize - 1)) & ~(kArrayEntriesPerCacheEntry - 1)); if (cache->get(index + kStringOffset) == Smi::zero()) { diff --git a/src/snapshot/deserializer.cc b/src/snapshot/deserializer.cc index 9f390a8e2d..7bd50567be 100644 --- a/src/snapshot/deserializer.cc +++ b/src/snapshot/deserializer.cc @@ -321,7 +321,7 @@ Handle StringTableInsertionKey::AsHandle(Isolate* isolate) { uint32_t StringTableInsertionKey::ComputeRawHashField(String string) { // Make sure raw_hash_field() is computed. - string.Hash(); + string.EnsureHash(); return string.raw_hash_field(); } diff --git a/test/cctest/heap/test-heap.cc b/test/cctest/heap/test-heap.cc index 8abbe3cfca..91f384e706 100644 --- a/test/cctest/heap/test-heap.cc +++ b/test/cctest/heap/test-heap.cc @@ -1011,15 +1011,14 @@ TEST(StringAllocation) { Handle one_byte_sym = factory->InternalizeString(OneByteVector(one_byte, length)); CHECK_EQ(length, one_byte_sym->length()); + CHECK(one_byte_sym->HasHashCode()); Handle non_one_byte_str = factory->NewStringFromUtf8(Vector(non_one_byte, 3 * length)) .ToHandleChecked(); - non_one_byte_str->Hash(); CHECK_EQ(length, non_one_byte_str->length()); Handle one_byte_str = factory->NewStringFromUtf8(Vector(one_byte, length)) .ToHandleChecked(); - one_byte_str->Hash(); CHECK_EQ(length, one_byte_str->length()); DeleteArray(non_one_byte); DeleteArray(one_byte); diff --git a/test/cctest/test-strings.cc b/test/cctest/test-strings.cc index fbd706ef85..eb891a98de 100644 --- a/test/cctest/test-strings.cc +++ b/test/cctest/test-strings.cc @@ -1829,11 +1829,11 @@ void TestString(i::Isolate* isolate, const IndexData& data) { size_t index; CHECK(s->AsIntegerIndex(&index)); CHECK_EQ(data.integer_index, index); - s->Hash(); + s->EnsureHash(); CHECK_EQ(0, s->raw_hash_field() & String::kIsNotIntegerIndexMask); CHECK(s->HasHashCode()); } - if (!s->HasHashCode()) s->Hash(); + if (!s->HasHashCode()) s->EnsureHash(); CHECK(s->HasHashCode()); if (!data.is_integer_index) { CHECK_NE(0, s->raw_hash_field() & String::kIsNotIntegerIndexMask); @@ -1850,11 +1850,11 @@ TEST(HashArrayIndexStrings) { CHECK_EQ(StringHasher::MakeArrayIndexHash(0 /* value */, 1 /* length */) >> Name::kHashShift, - isolate->factory()->zero_string()->Hash()); + isolate->factory()->zero_string()->hash()); CHECK_EQ(StringHasher::MakeArrayIndexHash(1 /* value */, 1 /* length */) >> Name::kHashShift, - isolate->factory()->one_string()->Hash()); + isolate->factory()->one_string()->hash()); IndexData tests[] = { {"", false, 0, false, 0}, diff --git a/test/cctest/test-symbols.cc b/test/cctest/test-symbols.cc index 006bca9f1f..d466f7fe07 100644 --- a/test/cctest/test-symbols.cc +++ b/test/cctest/test-symbols.cc @@ -54,7 +54,8 @@ TEST(Create) { CHECK(symbols[i]->IsName()); CHECK(symbols[i]->IsSymbol()); CHECK(symbols[i]->HasHashCode()); - CHECK_GT(symbols[i]->Hash(), 0u); + CHECK(symbols[i]->IsUniqueName()); + CHECK_GT(symbols[i]->hash(), 0u); os << Brief(*symbols[i]) << "\n"; #if OBJECT_PRINT symbols[i]->Print(os);