Commit 82614978 authored by jameslahm's avatar jameslahm Committed by V8 LUCI CQ

[symbol table] use plain hash table to implement symbol table in isolate

The per-Isolate Symbol tables are implemented using NameDictionary
before, which has additional property details overhead
And NameDictionary is limited to 2^23, which limits the Symbol
tables to be a maximum of 2^23.

- replace NameDictionary with SymbolTable in isolate

Bug: v8:12575
Change-Id: Ica4f05aac3494f7dfa3a074c240d4ba25df814e9
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3476897Reviewed-by: 's avatarShu-yu Guo <syg@chromium.org>
Reviewed-by: 's avatarDominik Inführ <dinfuehr@chromium.org>
Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
Commit-Queue: Igor Sheludko <ishell@chromium.org>
Cr-Commit-Position: refs/heads/main@{#79285}
parent c5ce66b1
......@@ -1751,6 +1751,7 @@ filegroup(
"src/objects/string-set.h",
"src/objects/string-table-inl.h",
"src/objects/string-table.cc",
"src/objects/symbol-table.cc",
"src/objects/string-table.h",
"src/objects/string.cc",
"src/objects/string.h",
......
......@@ -4348,6 +4348,7 @@ v8_source_set("v8_base_without_compiler") {
"src/objects/string-table.cc",
"src/objects/string.cc",
"src/objects/swiss-name-dictionary.cc",
"src/objects/symbol-table.cc",
"src/objects/synthetic-module.cc",
"src/objects/tagged-impl.cc",
"src/objects/template-objects.cc",
......
......@@ -214,6 +214,7 @@ extern class OrderedHashMap extends HashTable;
extern class OrderedHashSet extends HashTable;
extern class OrderedNameDictionary extends HashTable;
extern class NameToIndexHashTable extends HashTable;
extern class RegisteredSymbolTable extends HashTable;
extern class NameDictionary extends HashTable;
extern class GlobalDictionary extends HashTable;
extern class SimpleNumberDictionary extends HashTable;
......
......@@ -205,6 +205,7 @@ void HeapObject::HeapObjectVerify(Isolate* isolate) {
case ORDERED_HASH_SET_TYPE:
case ORDERED_NAME_DICTIONARY_TYPE:
case NAME_TO_INDEX_HASH_TABLE_TYPE:
case REGISTERED_SYMBOL_TABLE_TYPE:
case NAME_DICTIONARY_TYPE:
case GLOBAL_DICTIONARY_TYPE:
case NUMBER_DICTIONARY_TYPE:
......
......@@ -141,6 +141,9 @@ void HeapObject::HeapObjectPrint(std::ostream& os) {
case NAME_TO_INDEX_HASH_TABLE_TYPE:
NameToIndexHashTable::cast(*this).NameToIndexHashTablePrint(os);
break;
case REGISTERED_SYMBOL_TABLE_TYPE:
RegisteredSymbolTable::cast(*this).RegisteredSymbolTablePrint(os);
break;
case ORDERED_HASH_MAP_TYPE:
OrderedHashMap::cast(*this).OrderedHashMapPrint(os);
break;
......@@ -969,6 +972,11 @@ void NameToIndexHashTable::NameToIndexHashTablePrint(std::ostream& os) {
PrintHashMapContentsFull(os, *this);
}
void RegisteredSymbolTable::RegisteredSymbolTablePrint(std::ostream& os) {
PrintHashTableHeader(os, *this, "RegisteredSymbolTable");
PrintHashMapContentsFull(os, *this);
}
void NumberDictionary::NumberDictionaryPrint(std::ostream& os) {
PrintHashTableHeader(os, *this, "NumberDictionary");
PrintDictionaryContentsFull(os, *this);
......
......@@ -4477,16 +4477,16 @@ ISOLATE_INIT_ARRAY_LIST(ISOLATE_FIELD_OFFSET)
Handle<Symbol> Isolate::SymbolFor(RootIndex dictionary_index,
Handle<String> name, bool private_symbol) {
Handle<String> key = factory()->InternalizeString(name);
Handle<NameDictionary> dictionary =
Handle<NameDictionary>::cast(root_handle(dictionary_index));
Handle<RegisteredSymbolTable> dictionary =
Handle<RegisteredSymbolTable>::cast(root_handle(dictionary_index));
InternalIndex entry = dictionary->FindEntry(this, key);
Handle<Symbol> symbol;
if (entry.is_not_found()) {
symbol =
private_symbol ? factory()->NewPrivateSymbol() : factory()->NewSymbol();
symbol->set_description(*key);
dictionary = NameDictionary::Add(this, dictionary, key, symbol,
PropertyDetails::Empty(), &entry);
dictionary = RegisteredSymbolTable::Add(this, dictionary, key, symbol);
switch (dictionary_index) {
case RootIndex::kPublicSymbolTable:
symbol->set_is_in_public_symbol_table(true);
......
......@@ -477,6 +477,7 @@ bool Heap::CreateInitialMaps() {
simple_number_dictionary)
ALLOCATE_VARSIZE_MAP(NAME_TO_INDEX_HASH_TABLE_TYPE,
name_to_index_hash_table)
ALLOCATE_VARSIZE_MAP(REGISTERED_SYMBOL_TABLE_TYPE, registered_symbol_table)
ALLOCATE_VARSIZE_MAP(EMBEDDER_DATA_ARRAY_TYPE, embedder_data_array)
ALLOCATE_VARSIZE_MAP(EPHEMERON_HASH_TABLE_TYPE, ephemeron_hash_table)
......@@ -796,9 +797,12 @@ void Heap::CreateInitialObjects() {
set_empty_property_dictionary(*empty_property_dictionary);
set_public_symbol_table(*empty_property_dictionary);
set_api_symbol_table(*empty_property_dictionary);
set_api_private_symbol_table(*empty_property_dictionary);
Handle<RegisteredSymbolTable> empty_symbol_table = RegisteredSymbolTable::New(
isolate(), 1, AllocationType::kReadOnly, USE_CUSTOM_MINIMUM_CAPACITY);
DCHECK(!empty_symbol_table->HasSufficientCapacityToAdd(1));
set_public_symbol_table(*empty_symbol_table);
set_api_symbol_table(*empty_symbol_table);
set_api_private_symbol_table(*empty_symbol_table);
set_number_string_cache(*factory->NewFixedArray(
kInitialNumberStringCacheSize * 2, AllocationType::kOld));
......
......@@ -35,6 +35,11 @@ ObjectHashTable::ObjectHashTable(Address ptr)
SLOW_DCHECK(IsObjectHashTable());
}
RegisteredSymbolTable::RegisteredSymbolTable(Address ptr)
: HashTable<RegisteredSymbolTable, RegisteredSymbolTableShape>(ptr) {
SLOW_DCHECK(IsRegisteredSymbolTable());
}
EphemeronHashTable::EphemeronHashTable(Address ptr)
: ObjectHashTableBase<EphemeronHashTable, ObjectHashTableShape>(ptr) {
SLOW_DCHECK(IsEphemeronHashTable());
......@@ -51,6 +56,7 @@ NameToIndexHashTable::NameToIndexHashTable(Address ptr)
}
CAST_ACCESSOR(ObjectHashTable)
CAST_ACCESSOR(RegisteredSymbolTable)
CAST_ACCESSOR(EphemeronHashTable)
CAST_ACCESSOR(ObjectHashSet)
CAST_ACCESSOR(NameToIndexHashTable)
......@@ -135,6 +141,11 @@ Handle<Map> NameToIndexHashTable::GetMap(ReadOnlyRoots roots) {
return roots.name_to_index_hash_table_map_handle();
}
// static
Handle<Map> RegisteredSymbolTable::GetMap(ReadOnlyRoots roots) {
return roots.registered_symbol_table_map_handle();
}
// static
Handle<Map> EphemeronHashTable::GetMap(ReadOnlyRoots roots) {
return roots.ephemeron_hash_table_map_handle();
......@@ -265,6 +276,21 @@ bool ObjectHashTableShape::IsMatch(Handle<Object> key, Object other) {
return key->SameValue(other);
}
bool RegisteredSymbolTableShape::IsMatch(Handle<String> key, Object value) {
DCHECK(value.IsString());
return key->Equals(String::cast(value));
}
uint32_t RegisteredSymbolTableShape::Hash(ReadOnlyRoots roots,
Handle<String> key) {
return key->EnsureHash();
}
uint32_t RegisteredSymbolTableShape::HashForObject(ReadOnlyRoots roots,
Object object) {
return String::cast(object).EnsureHash();
}
bool NameToIndexShape::IsMatch(Handle<Name> key, Object other) {
return *key == other;
}
......
......@@ -479,6 +479,43 @@ class V8_EXPORT_PRIVATE NameToIndexHashTable
}
};
class RegisteredSymbolTableShape : public BaseShape<Handle<String>> {
public:
static inline bool IsMatch(Handle<String> key, Object other);
static inline uint32_t Hash(ReadOnlyRoots roots, Handle<String> key);
static inline uint32_t HashForObject(ReadOnlyRoots roots, Object object);
static const int kPrefixSize = 0;
static const int kEntryValueIndex = 1;
static const int kEntrySize = 2;
static const bool kMatchNeedsHoleCheck = false;
};
class RegisteredSymbolTable
: public HashTable<RegisteredSymbolTable, RegisteredSymbolTableShape> {
public:
Object SlowReverseLookup(Object value);
// Returns the value at entry.
Object ValueAt(InternalIndex entry);
inline static Handle<Map> GetMap(ReadOnlyRoots roots);
static Handle<RegisteredSymbolTable> Add(Isolate* isolate,
Handle<RegisteredSymbolTable> table,
Handle<String> key, Handle<Symbol>);
DECL_CAST(RegisteredSymbolTable)
DECL_PRINTER(RegisteredSymbolTable)
OBJECT_CONSTRUCTORS(
RegisteredSymbolTable,
HashTable<RegisteredSymbolTable, RegisteredSymbolTableShape>);
private:
static inline int EntryToValueIndex(InternalIndex entry) {
return EntryToIndex(entry) + RegisteredSymbolTableShape::kEntryValueIndex;
}
};
} // namespace internal
} // namespace v8
......
......@@ -130,6 +130,7 @@ VisitorId Map::GetVisitorId(Map map) {
case OBJECT_BOILERPLATE_DESCRIPTION_TYPE:
case NAME_TO_INDEX_HASH_TABLE_TYPE:
case REGISTERED_SYMBOL_TABLE_TYPE:
case CLOSURE_FEEDBACK_CELL_ARRAY_TYPE:
case HASH_TABLE_TYPE:
case ORDERED_HASH_MAP_TYPE:
......
......@@ -220,6 +220,7 @@ class ZoneForwardList;
V(StoreHandler) \
V(String) \
V(StringSet) \
V(RegisteredSymbolTable) \
V(StringWrapper) \
V(Struct) \
V(SwissNameDictionary) \
......
......@@ -1070,6 +1070,7 @@ auto BodyDescriptorApply(InstanceType type, Args&&... args) {
case NUMBER_DICTIONARY_TYPE:
case SIMPLE_NUMBER_DICTIONARY_TYPE:
case NAME_TO_INDEX_HASH_TABLE_TYPE:
case REGISTERED_SYMBOL_TABLE_TYPE:
case SCRIPT_CONTEXT_TABLE_TYPE:
return CALL_APPLY(FixedArray);
case EPHEMERON_HASH_TABLE_TYPE:
......
......@@ -2330,6 +2330,7 @@ bool HeapObject::NeedsRehashing(InstanceType instance_type) const {
return false; // We'll rehash from the JSMap or JSSet referencing them.
case NAME_DICTIONARY_TYPE:
case NAME_TO_INDEX_HASH_TABLE_TYPE:
case REGISTERED_SYMBOL_TABLE_TYPE:
case GLOBAL_DICTIONARY_TYPE:
case NUMBER_DICTIONARY_TYPE:
case SIMPLE_NUMBER_DICTIONARY_TYPE:
......@@ -2359,6 +2360,7 @@ bool HeapObject::CanBeRehashed(PtrComprCageBase cage_base) const {
return false;
case NAME_DICTIONARY_TYPE:
case NAME_TO_INDEX_HASH_TABLE_TYPE:
case REGISTERED_SYMBOL_TABLE_TYPE:
case GLOBAL_DICTIONARY_TYPE:
case NUMBER_DICTIONARY_TYPE:
case SIMPLE_NUMBER_DICTIONARY_TYPE:
......@@ -2391,6 +2393,9 @@ void HeapObject::RehashBasedOnMap(IsolateT* isolate) {
case NAME_TO_INDEX_HASH_TABLE_TYPE:
NameToIndexHashTable::cast(*this).Rehash(isolate);
break;
case REGISTERED_SYMBOL_TABLE_TYPE:
RegisteredSymbolTable::cast(*this).Rehash(isolate);
break;
case SWISS_NAME_DICTIONARY_TYPE:
SwissNameDictionary::cast(*this).Rehash(isolate);
break;
......@@ -5993,6 +5998,21 @@ bool StringSet::Has(Isolate* isolate, Handle<String> name) {
return FindEntry(isolate, *name).is_found();
}
Handle<RegisteredSymbolTable> RegisteredSymbolTable::Add(
Isolate* isolate, Handle<RegisteredSymbolTable> table, Handle<String> key,
Handle<Symbol> symbol) {
// Validate that the key is absent.
SLOW_DCHECK(table->FindEntry(isolate, key).is_not_found());
table = EnsureCapacity(isolate, table);
uint32_t hash = ShapeT::Hash(ReadOnlyRoots(isolate), key);
InternalIndex entry = table->FindInsertionEntry(isolate, hash);
table->set(EntryToIndex(entry), *key);
table->set(EntryToValueIndex(entry), *symbol);
table->ElementAdded();
return table;
}
Handle<ObjectHashSet> ObjectHashSet::Add(Isolate* isolate,
Handle<ObjectHashSet> set,
Handle<Object> key) {
......@@ -6322,6 +6342,10 @@ Object ObjectHashTableBase<Derived, Shape>::ValueAt(InternalIndex entry) {
return this->get(EntryToValueIndex(entry));
}
Object RegisteredSymbolTable::ValueAt(InternalIndex entry) {
return this->get(EntryToValueIndex(entry));
}
Object NameToIndexHashTable::ValueAt(InternalIndex entry) {
return this->get(EntryToValueIndex(entry));
}
......@@ -6911,6 +6935,7 @@ EXTERN_DEFINE_HASH_TABLE(StringSet, StringSetShape)
EXTERN_DEFINE_HASH_TABLE(CompilationCacheTable, CompilationCacheShape)
EXTERN_DEFINE_HASH_TABLE(ObjectHashSet, ObjectHashSetShape)
EXTERN_DEFINE_HASH_TABLE(NameToIndexHashTable, NameToIndexShape)
EXTERN_DEFINE_HASH_TABLE(RegisteredSymbolTable, RegisteredSymbolTableShape)
EXTERN_DEFINE_OBJECT_BASE_HASH_TABLE(ObjectHashTable, ObjectHashTableShape)
EXTERN_DEFINE_OBJECT_BASE_HASH_TABLE(EphemeronHashTable, ObjectHashTableShape)
......
// Copyright 2022 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/objects/hash-table-inl.h"
namespace v8 {
namespace internal {
Object RegisteredSymbolTable::SlowReverseLookup(Object value) {
ReadOnlyRoots roots = this->GetReadOnlyRoots();
for (InternalIndex i : this->IterateEntries()) {
Object k;
if (!this->ToKey(roots, i, &k)) continue;
Object e = this->ValueAt(i);
if (e == value) return k;
}
return roots.undefined_value();
}
} // namespace internal
} // namespace v8
......@@ -97,6 +97,7 @@ class Symbol;
V(Map, ordered_hash_map_map, OrderedHashMapMap) \
V(Map, ordered_hash_set_map, OrderedHashSetMap) \
V(Map, name_to_index_hash_table_map, NameToIndexHashTableMap) \
V(Map, registered_symbol_table_map, RegisteredSymbolTableMap) \
V(Map, ordered_name_dictionary_map, OrderedNameDictionaryMap) \
V(Map, preparse_data_map, PreparseDataMap) \
V(Map, property_array_map, PropertyArrayMap) \
......@@ -294,34 +295,34 @@ class Symbol;
V(SharedFunctionInfo, proxy_revoke_shared_fun, ProxyRevokeSharedFun)
// These root references can be updated by the mutator.
#define STRONG_MUTABLE_MOVABLE_ROOT_LIST(V) \
/* Caches */ \
V(FixedArray, number_string_cache, NumberStringCache) \
/* Lists and dictionaries */ \
V(NameDictionary, public_symbol_table, PublicSymbolTable) \
V(NameDictionary, api_symbol_table, ApiSymbolTable) \
V(NameDictionary, api_private_symbol_table, ApiPrivateSymbolTable) \
V(WeakArrayList, script_list, ScriptList) \
V(FixedArray, materialized_objects, MaterializedObjects) \
V(WeakArrayList, detached_contexts, DetachedContexts) \
V(WeakArrayList, retaining_path_targets, RetainingPathTargets) \
/* Feedback vectors that we need for code coverage or type profile */ \
V(Object, feedback_vectors_for_profiling_tools, \
FeedbackVectorsForProfilingTools) \
V(FixedArray, serialized_objects, SerializedObjects) \
V(FixedArray, serialized_global_proxy_sizes, SerializedGlobalProxySizes) \
V(TemplateList, message_listeners, MessageListeners) \
/* Support for async stack traces */ \
V(HeapObject, current_microtask, CurrentMicrotask) \
/* KeepDuringJob set for JS WeakRefs */ \
V(HeapObject, weak_refs_keep_during_job, WeakRefsKeepDuringJob) \
V(HeapObject, interpreter_entry_trampoline_for_profiling, \
InterpreterEntryTrampolineForProfiling) \
V(Object, pending_optimize_for_test_bytecode, \
PendingOptimizeForTestBytecode) \
V(ArrayList, basic_block_profiling_data, BasicBlockProfilingData) \
V(WeakArrayList, shared_wasm_memories, SharedWasmMemories) \
IF_WASM(V, HeapObject, active_continuation, ActiveContinuation) \
#define STRONG_MUTABLE_MOVABLE_ROOT_LIST(V) \
/* Caches */ \
V(FixedArray, number_string_cache, NumberStringCache) \
/* Lists and dictionaries */ \
V(RegisteredSymbolTable, public_symbol_table, PublicSymbolTable) \
V(RegisteredSymbolTable, api_symbol_table, ApiSymbolTable) \
V(RegisteredSymbolTable, api_private_symbol_table, ApiPrivateSymbolTable) \
V(WeakArrayList, script_list, ScriptList) \
V(FixedArray, materialized_objects, MaterializedObjects) \
V(WeakArrayList, detached_contexts, DetachedContexts) \
V(WeakArrayList, retaining_path_targets, RetainingPathTargets) \
/* Feedback vectors that we need for code coverage or type profile */ \
V(Object, feedback_vectors_for_profiling_tools, \
FeedbackVectorsForProfilingTools) \
V(FixedArray, serialized_objects, SerializedObjects) \
V(FixedArray, serialized_global_proxy_sizes, SerializedGlobalProxySizes) \
V(TemplateList, message_listeners, MessageListeners) \
/* Support for async stack traces */ \
V(HeapObject, current_microtask, CurrentMicrotask) \
/* KeepDuringJob set for JS WeakRefs */ \
V(HeapObject, weak_refs_keep_during_job, WeakRefsKeepDuringJob) \
V(HeapObject, interpreter_entry_trampoline_for_profiling, \
InterpreterEntryTrampolineForProfiling) \
V(Object, pending_optimize_for_test_bytecode, \
PendingOptimizeForTestBytecode) \
V(ArrayList, basic_block_profiling_data, BasicBlockProfilingData) \
V(WeakArrayList, shared_wasm_memories, SharedWasmMemories) \
IF_WASM(V, HeapObject, active_continuation, ActiveContinuation) \
IF_WASM(V, HeapObject, active_suspender, ActiveSuspender)
// Entries in this list are limited to Smis and are not visited during GC.
......
This diff is collapsed.
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