Commit 70e49b17 authored by Frank Emrich's avatar Frank Emrich Committed by Commit Bot

[dict-proto] C++ implementation of SwissNameDictionary, pt. 1

This CL is part of a series that adds the C++ implementation of
SwissNameDictionary, a deterministic property backing store based on
Swiss Tables.

This CL contains most of the boilerplate code for introducing a new
instance type.

Bug: v8:11388
Change-Id: Id263b8138a8ce4b465fb28d968223d2e1aaf05a4
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2672030Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Reviewed-by: 's avatarNico Hartmann <nicohartmann@chromium.org>
Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
Reviewed-by: 's avatarMarja Hölttä <marja@chromium.org>
Commit-Queue: Frank Emrich <emrich@google.com>
Cr-Commit-Position: refs/heads/master@{#72582}
parent 811d73aa
...@@ -1412,6 +1412,7 @@ torque_files = [ ...@@ -1412,6 +1412,7 @@ torque_files = [
"src/objects/stack-frame-info.tq", "src/objects/stack-frame-info.tq",
"src/objects/string.tq", "src/objects/string.tq",
"src/objects/struct.tq", "src/objects/struct.tq",
"src/objects/swiss-name-dictionary.tq",
"src/objects/synthetic-module.tq", "src/objects/synthetic-module.tq",
"src/objects/template-objects.tq", "src/objects/template-objects.tq",
"src/objects/templates.tq", "src/objects/templates.tq",
...@@ -3255,6 +3256,9 @@ v8_source_set("v8_base_without_compiler") { ...@@ -3255,6 +3256,9 @@ v8_source_set("v8_base_without_compiler") {
"src/objects/string.h", "src/objects/string.h",
"src/objects/struct-inl.h", "src/objects/struct-inl.h",
"src/objects/struct.h", "src/objects/struct.h",
"src/objects/swiss-name-dictionary-inl.h",
"src/objects/swiss-name-dictionary.cc",
"src/objects/swiss-name-dictionary.h",
"src/objects/synthetic-module-inl.h", "src/objects/synthetic-module-inl.h",
"src/objects/synthetic-module.cc", "src/objects/synthetic-module.cc",
"src/objects/synthetic-module.h", "src/objects/synthetic-module.h",
......
...@@ -430,6 +430,8 @@ const kNameDictionaryInitialCapacity: ...@@ -430,6 +430,8 @@ const kNameDictionaryInitialCapacity:
constexpr int32 generates 'NameDictionary::kInitialCapacity'; constexpr int32 generates 'NameDictionary::kInitialCapacity';
const kOrderedNameDictionaryInitialCapacity: const kOrderedNameDictionaryInitialCapacity:
constexpr int32 generates 'OrderedNameDictionary::kInitialCapacity'; constexpr int32 generates 'OrderedNameDictionary::kInitialCapacity';
const kSwissNameDictionaryGroupWidth:
constexpr int32 generates 'SwissNameDictionary::kGroupWidth';
const kWasmArrayHeaderSize: const kWasmArrayHeaderSize:
constexpr int32 generates 'WasmArray::kHeaderSize'; constexpr int32 generates 'WasmArray::kHeaderSize';
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "src/objects/promise.h" #include "src/objects/promise.h"
#include "src/objects/shared-function-info.h" #include "src/objects/shared-function-info.h"
#include "src/objects/smi.h" #include "src/objects/smi.h"
#include "src/objects/swiss-name-dictionary.h"
#include "src/objects/tagged-index.h" #include "src/objects/tagged-index.h"
#include "src/roots/roots.h" #include "src/roots/roots.h"
#include "torque-generated/exported-macros-assembler.h" #include "torque-generated/exported-macros-assembler.h"
......
...@@ -1698,6 +1698,8 @@ enum class StubCallMode { ...@@ -1698,6 +1698,8 @@ enum class StubCallMode {
constexpr int kFunctionLiteralIdInvalid = -1; constexpr int kFunctionLiteralIdInvalid = -1;
constexpr int kFunctionLiteralIdTopLevel = 0; constexpr int kFunctionLiteralIdTopLevel = 0;
constexpr int kSwissNameDictionaryInitialCapacity = 4;
constexpr int kSmallOrderedHashSetMinCapacity = 4; constexpr int kSmallOrderedHashSetMinCapacity = 4;
constexpr int kSmallOrderedHashMapMinCapacity = 4; constexpr int kSmallOrderedHashMapMinCapacity = 4;
......
...@@ -69,6 +69,7 @@ ...@@ -69,6 +69,7 @@
#include "src/objects/property-descriptor-object-inl.h" #include "src/objects/property-descriptor-object-inl.h"
#include "src/objects/stack-frame-info-inl.h" #include "src/objects/stack-frame-info-inl.h"
#include "src/objects/struct-inl.h" #include "src/objects/struct-inl.h"
#include "src/objects/swiss-name-dictionary-inl.h"
#include "src/objects/synthetic-module-inl.h" #include "src/objects/synthetic-module-inl.h"
#include "src/objects/template-objects-inl.h" #include "src/objects/template-objects-inl.h"
#include "src/objects/torque-defined-classes-inl.h" #include "src/objects/torque-defined-classes-inl.h"
...@@ -1255,6 +1256,11 @@ void SmallOrderedNameDictionary::SmallOrderedNameDictionaryVerify( ...@@ -1255,6 +1256,11 @@ void SmallOrderedNameDictionary::SmallOrderedNameDictionaryVerify(
} }
} }
void SwissNameDictionary::SwissNameDictionaryVerify(Isolate* isolate) {
// TODO(v8:11388) Here to satisfy compiler, implemented in follow-up CL.
UNREACHABLE();
}
void JSRegExp::JSRegExpVerify(Isolate* isolate) { void JSRegExp::JSRegExpVerify(Isolate* isolate) {
TorqueGeneratedClassVerifiers::JSRegExpVerify(*this, isolate); TorqueGeneratedClassVerifiers::JSRegExpVerify(*this, isolate);
switch (TypeTag()) { switch (TypeTag()) {
......
...@@ -945,6 +945,11 @@ void OrderedNameDictionary::OrderedNameDictionaryPrint(std::ostream& os) { ...@@ -945,6 +945,11 @@ void OrderedNameDictionary::OrderedNameDictionaryPrint(std::ostream& os) {
PrintDictionaryContentsFull(os, *this); PrintDictionaryContentsFull(os, *this);
} }
void SwissNameDictionary::SwissNameDictionaryPrint(std::ostream& os) {
// Here to satisfy compiler, implemented in follow-up CL.
UNREACHABLE();
}
void PropertyArray::PropertyArrayPrint(std::ostream& os) { // NOLINT void PropertyArray::PropertyArrayPrint(std::ostream& os) { // NOLINT
PrintHeader(os, "PropertyArray"); PrintHeader(os, "PropertyArray");
os << "\n - length: " << length(); os << "\n - length: " << length();
......
...@@ -32,6 +32,7 @@ class RootVisitor; ...@@ -32,6 +32,7 @@ class RootVisitor;
class SmallOrderedHashMap; class SmallOrderedHashMap;
class SmallOrderedHashSet; class SmallOrderedHashSet;
class SmallOrderedNameDictionary; class SmallOrderedNameDictionary;
class SwissNameDictionary;
class WasmExportedFunctionData; class WasmExportedFunctionData;
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
......
...@@ -47,6 +47,7 @@ namespace internal { ...@@ -47,6 +47,7 @@ namespace internal {
V(SmallOrderedHashSet) \ V(SmallOrderedHashSet) \
V(SmallOrderedNameDictionary) \ V(SmallOrderedNameDictionary) \
V(SourceTextModule) \ V(SourceTextModule) \
V(SwissNameDictionary) \
V(Symbol) \ V(Symbol) \
V(SyntheticModule) \ V(SyntheticModule) \
V(TransitionArray) \ V(TransitionArray) \
......
...@@ -470,6 +470,7 @@ bool Heap::CreateInitialMaps() { ...@@ -470,6 +470,7 @@ bool Heap::CreateInitialMaps() {
ALLOCATE_VARSIZE_MAP(ORDERED_HASH_SET_TYPE, ordered_hash_set) ALLOCATE_VARSIZE_MAP(ORDERED_HASH_SET_TYPE, ordered_hash_set)
ALLOCATE_VARSIZE_MAP(ORDERED_NAME_DICTIONARY_TYPE, ordered_name_dictionary) ALLOCATE_VARSIZE_MAP(ORDERED_NAME_DICTIONARY_TYPE, ordered_name_dictionary)
ALLOCATE_VARSIZE_MAP(NAME_DICTIONARY_TYPE, name_dictionary) ALLOCATE_VARSIZE_MAP(NAME_DICTIONARY_TYPE, name_dictionary)
ALLOCATE_VARSIZE_MAP(SWISS_NAME_DICTIONARY_TYPE, swiss_name_dictionary)
ALLOCATE_VARSIZE_MAP(GLOBAL_DICTIONARY_TYPE, global_dictionary) ALLOCATE_VARSIZE_MAP(GLOBAL_DICTIONARY_TYPE, global_dictionary)
ALLOCATE_VARSIZE_MAP(NUMBER_DICTIONARY_TYPE, number_dictionary) ALLOCATE_VARSIZE_MAP(NUMBER_DICTIONARY_TYPE, number_dictionary)
ALLOCATE_VARSIZE_MAP(SIMPLE_NUMBER_DICTIONARY_TYPE, ALLOCATE_VARSIZE_MAP(SIMPLE_NUMBER_DICTIONARY_TYPE,
......
...@@ -78,6 +78,7 @@ ...@@ -78,6 +78,7 @@
#include "src/objects/string-set-inl.h" #include "src/objects/string-set-inl.h"
#include "src/objects/string-table-inl.h" #include "src/objects/string-table-inl.h"
#include "src/objects/struct-inl.h" #include "src/objects/struct-inl.h"
#include "src/objects/swiss-name-dictionary-inl.h"
#include "src/objects/synthetic-module-inl.h" #include "src/objects/synthetic-module-inl.h"
#include "src/objects/tagged-field-inl.h" #include "src/objects/tagged-field-inl.h"
#include "src/objects/tagged-impl-inl.h" #include "src/objects/tagged-impl-inl.h"
......
...@@ -238,40 +238,41 @@ TYPED_ARRAYS(TYPED_ARRAY_IS_TYPE_FUNCTION_DECL) ...@@ -238,40 +238,41 @@ TYPED_ARRAYS(TYPED_ARRAY_IS_TYPE_FUNCTION_DECL)
// This list must contain only maps that are shared by all objects of their // This list must contain only maps that are shared by all objects of their
// instance type. // instance type.
#define UNIQUE_INSTANCE_TYPE_MAP_LIST_GENERATOR(V, _) \ #define UNIQUE_INSTANCE_TYPE_MAP_LIST_GENERATOR(V, _) \
V(_, AccessorInfoMap, accessor_info_map, AccessorInfo) \ V(_, AccessorInfoMap, accessor_info_map, AccessorInfo) \
V(_, AccessorPairMap, accessor_pair_map, AccessorPair) \ V(_, AccessorPairMap, accessor_pair_map, AccessorPair) \
V(_, AllocationMementoMap, allocation_memento_map, AllocationMemento) \ V(_, AllocationMementoMap, allocation_memento_map, AllocationMemento) \
V(_, ArrayBoilerplateDescriptionMap, array_boilerplate_description_map, \ V(_, ArrayBoilerplateDescriptionMap, array_boilerplate_description_map, \
ArrayBoilerplateDescription) \ ArrayBoilerplateDescription) \
V(_, BreakPointMap, break_point_map, BreakPoint) \ V(_, BreakPointMap, break_point_map, BreakPoint) \
V(_, BreakPointInfoMap, break_point_info_map, BreakPointInfo) \ V(_, BreakPointInfoMap, break_point_info_map, BreakPointInfo) \
V(_, CachedTemplateObjectMap, cached_template_object_map, \ V(_, CachedTemplateObjectMap, cached_template_object_map, \
CachedTemplateObject) \ CachedTemplateObject) \
V(_, CellMap, cell_map, Cell) \ V(_, CellMap, cell_map, Cell) \
V(_, WeakCellMap, weak_cell_map, WeakCell) \ V(_, WeakCellMap, weak_cell_map, WeakCell) \
V(_, CodeMap, code_map, Code) \ V(_, CodeMap, code_map, Code) \
V(_, CoverageInfoMap, coverage_info_map, CoverageInfo) \ V(_, CoverageInfoMap, coverage_info_map, CoverageInfo) \
V(_, DebugInfoMap, debug_info_map, DebugInfo) \ V(_, DebugInfoMap, debug_info_map, DebugInfo) \
V(_, FeedbackVectorMap, feedback_vector_map, FeedbackVector) \ V(_, FeedbackVectorMap, feedback_vector_map, FeedbackVector) \
V(_, FixedDoubleArrayMap, fixed_double_array_map, FixedDoubleArray) \ V(_, FixedDoubleArrayMap, fixed_double_array_map, FixedDoubleArray) \
V(_, FunctionTemplateInfoMap, function_template_info_map, \ V(_, FunctionTemplateInfoMap, function_template_info_map, \
FunctionTemplateInfo) \ FunctionTemplateInfo) \
V(_, HeapNumberMap, heap_number_map, HeapNumber) \ V(_, HeapNumberMap, heap_number_map, HeapNumber) \
V(_, MetaMap, meta_map, Map) \ V(_, MetaMap, meta_map, Map) \
V(_, PreparseDataMap, preparse_data_map, PreparseData) \ V(_, PreparseDataMap, preparse_data_map, PreparseData) \
V(_, PrototypeInfoMap, prototype_info_map, PrototypeInfo) \ V(_, PrototypeInfoMap, prototype_info_map, PrototypeInfo) \
V(_, SharedFunctionInfoMap, shared_function_info_map, SharedFunctionInfo) \ V(_, SharedFunctionInfoMap, shared_function_info_map, SharedFunctionInfo) \
V(_, SmallOrderedHashSetMap, small_ordered_hash_set_map, \ V(_, SmallOrderedHashSetMap, small_ordered_hash_set_map, \
SmallOrderedHashSet) \ SmallOrderedHashSet) \
V(_, SmallOrderedHashMapMap, small_ordered_hash_map_map, \ V(_, SmallOrderedHashMapMap, small_ordered_hash_map_map, \
SmallOrderedHashMap) \ SmallOrderedHashMap) \
V(_, SmallOrderedNameDictionaryMap, small_ordered_name_dictionary_map, \ V(_, SmallOrderedNameDictionaryMap, small_ordered_name_dictionary_map, \
SmallOrderedNameDictionary) \ SmallOrderedNameDictionary) \
V(_, SymbolMap, symbol_map, Symbol) \ V(_, SwissNameDictionaryMap, swiss_name_dictionary_map, SwissNameDictionary) \
V(_, TransitionArrayMap, transition_array_map, TransitionArray) \ V(_, SymbolMap, symbol_map, Symbol) \
V(_, Tuple2Map, tuple2_map, Tuple2) \ V(_, TransitionArrayMap, transition_array_map, TransitionArray) \
V(_, WeakFixedArrayMap, weak_fixed_array_map, WeakFixedArray) \ V(_, Tuple2Map, tuple2_map, Tuple2) \
V(_, WeakFixedArrayMap, weak_fixed_array_map, WeakFixedArray) \
TORQUE_DEFINED_MAP_CSA_LIST_GENERATOR(V, _) TORQUE_DEFINED_MAP_CSA_LIST_GENERATOR(V, _)
} // namespace internal } // namespace internal
......
...@@ -242,6 +242,9 @@ VisitorId Map::GetVisitorId(Map map) { ...@@ -242,6 +242,9 @@ VisitorId Map::GetVisitorId(Map map) {
case SMALL_ORDERED_NAME_DICTIONARY_TYPE: case SMALL_ORDERED_NAME_DICTIONARY_TYPE:
return kVisitSmallOrderedNameDictionary; return kVisitSmallOrderedNameDictionary;
case SWISS_NAME_DICTIONARY_TYPE:
return kVisitSwissNameDictionary;
case CODE_DATA_CONTAINER_TYPE: case CODE_DATA_CONTAINER_TYPE:
return kVisitCodeDataContainer; return kVisitCodeDataContainer;
......
...@@ -64,6 +64,7 @@ enum InstanceType : uint16_t; ...@@ -64,6 +64,7 @@ enum InstanceType : uint16_t;
V(SmallOrderedNameDictionary) \ V(SmallOrderedNameDictionary) \
V(SourceTextModule) \ V(SourceTextModule) \
V(Struct) \ V(Struct) \
V(SwissNameDictionary) \
V(Symbol) \ V(Symbol) \
V(SyntheticModule) \ V(SyntheticModule) \
V(TransitionArray) \ V(TransitionArray) \
......
...@@ -207,6 +207,7 @@ class ZoneForwardList; ...@@ -207,6 +207,7 @@ class ZoneForwardList;
V(StringSet) \ V(StringSet) \
V(StringWrapper) \ V(StringWrapper) \
V(Struct) \ V(Struct) \
V(SwissNameDictionary) \
V(Symbol) \ V(Symbol) \
V(SymbolWrapper) \ V(SymbolWrapper) \
V(SyntheticModule) \ V(SyntheticModule) \
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "src/objects/oddball.h" #include "src/objects/oddball.h"
#include "src/objects/ordered-hash-table-inl.h" #include "src/objects/ordered-hash-table-inl.h"
#include "src/objects/source-text-module.h" #include "src/objects/source-text-module.h"
#include "src/objects/swiss-name-dictionary-inl.h"
#include "src/objects/synthetic-module.h" #include "src/objects/synthetic-module.h"
#include "src/objects/torque-defined-classes-inl.h" #include "src/objects/torque-defined-classes-inl.h"
#include "src/objects/transitions.h" #include "src/objects/transitions.h"
...@@ -403,6 +404,38 @@ class V8_EXPORT_PRIVATE SmallOrderedHashTable<Derived>::BodyDescriptor final ...@@ -403,6 +404,38 @@ class V8_EXPORT_PRIVATE SmallOrderedHashTable<Derived>::BodyDescriptor final
} }
}; };
class V8_EXPORT_PRIVATE SwissNameDictionary::BodyDescriptor final
: public BodyDescriptorBase {
public:
static bool IsValidSlot(Map map, HeapObject obj, int offset) {
// Using |unchecked_cast| here and elsewhere in this class because the
// Scavenger may be calling us while the map word contains the forwarding
// address (a Smi) rather than a map.
SwissNameDictionary table = SwissNameDictionary::unchecked_cast(obj);
STATIC_ASSERT(MetaTablePointerOffset() + kTaggedSize ==
DataTableStartOffset());
return offset >= MetaTablePointerOffset() &&
(offset < table.DataTableEndOffset(table.Capacity()));
}
template <typename ObjectVisitor>
static inline void IterateBody(Map map, HeapObject obj, int object_size,
ObjectVisitor* v) {
SwissNameDictionary table = SwissNameDictionary::unchecked_cast(obj);
STATIC_ASSERT(MetaTablePointerOffset() + kTaggedSize ==
DataTableStartOffset());
int start_offset = MetaTablePointerOffset();
int end_offset = table.DataTableEndOffset(table.Capacity());
IteratePointers(obj, start_offset, end_offset, v);
}
static inline int SizeOf(Map map, HeapObject obj) {
SwissNameDictionary table = SwissNameDictionary::unchecked_cast(obj);
return SwissNameDictionary::SizeFor(table.Capacity());
}
};
class ByteArray::BodyDescriptor final : public BodyDescriptorBase { class ByteArray::BodyDescriptor final : public BodyDescriptorBase {
public: public:
static bool IsValidSlot(Map map, HeapObject obj, int offset) { return false; } static bool IsValidSlot(Map map, HeapObject obj, int offset) { return false; }
...@@ -1050,6 +1083,11 @@ ReturnType BodyDescriptorApply(InstanceType type, T1 p1, T2 p2, T3 p3, T4 p4) { ...@@ -1050,6 +1083,11 @@ ReturnType BodyDescriptorApply(InstanceType type, T1 p1, T2 p2, T3 p3, T4 p4) {
return Op::template apply< return Op::template apply<
SmallOrderedHashTable<SmallOrderedNameDictionary>::BodyDescriptor>( SmallOrderedHashTable<SmallOrderedNameDictionary>::BodyDescriptor>(
p1, p2, p3, p4); p1, p2, p3, p4);
case SWISS_NAME_DICTIONARY_TYPE:
return Op::template apply<SwissNameDictionary::BodyDescriptor>(p1, p2, p3,
p4);
case CODE_DATA_CONTAINER_TYPE: case CODE_DATA_CONTAINER_TYPE:
return Op::template apply<CodeDataContainer::BodyDescriptor>(p1, p2, p3, return Op::template apply<CodeDataContainer::BodyDescriptor>(p1, p2, p3,
p4); p4);
......
...@@ -2285,6 +2285,10 @@ int HeapObject::SizeFromMap(Map map) const { ...@@ -2285,6 +2285,10 @@ int HeapObject::SizeFromMap(Map map) const {
return SmallOrderedNameDictionary::SizeFor( return SmallOrderedNameDictionary::SizeFor(
SmallOrderedNameDictionary::unchecked_cast(*this).Capacity()); SmallOrderedNameDictionary::unchecked_cast(*this).Capacity());
} }
if (instance_type == SWISS_NAME_DICTIONARY_TYPE) {
return SwissNameDictionary::SizeFor(
SwissNameDictionary::unchecked_cast(*this).Capacity());
}
if (instance_type == PROPERTY_ARRAY_TYPE) { if (instance_type == PROPERTY_ARRAY_TYPE) {
return PropertyArray::SizeFor( return PropertyArray::SizeFor(
PropertyArray::cast(*this).synchronized_length()); PropertyArray::cast(*this).synchronized_length());
......
...@@ -188,6 +188,7 @@ ...@@ -188,6 +188,7 @@
// - UncompiledData // - UncompiledData
// - UncompiledDataWithoutPreparseData // - UncompiledDataWithoutPreparseData
// - UncompiledDataWithPreparseData // - UncompiledDataWithPreparseData
// - SwissNameDictionary
// //
// Formats of Object::ptr_: // Formats of Object::ptr_:
// Smi: [31 bit signed int] 0 // Smi: [31 bit signed int] 0
......
// Copyright 2021 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.
#ifndef V8_OBJECTS_SWISS_NAME_DICTIONARY_INL_H_
#define V8_OBJECTS_SWISS_NAME_DICTIONARY_INL_H_
#include "src/base/macros.h"
#include "src/execution/isolate-utils-inl.h"
#include "src/heap/heap.h"
#include "src/objects/fixed-array-inl.h"
#include "src/objects/instance-type-inl.h"
#include "src/objects/js-collection-iterator.h"
#include "src/objects/objects-inl.h"
#include "src/objects/smi.h"
#include "src/objects/swiss-name-dictionary.h"
// Has to be the last include (doesn't have include guards):
#include "src/objects/object-macros.h"
namespace v8 {
namespace internal {
#include "torque-generated/src/objects/swiss-name-dictionary-tq-inl.inc"
CAST_ACCESSOR(SwissNameDictionary)
OBJECT_CONSTRUCTORS_IMPL(SwissNameDictionary, HeapObject)
int SwissNameDictionary::Capacity() {
return ReadField<int32_t>(CapacityOffset());
}
// static
bool SwissNameDictionary::IsValidCapacity(int capacity) {
return capacity == 0 || (capacity >= kInitialCapacity &&
// Must be power of 2.
((capacity & (capacity - 1)) == 0));
}
// static
constexpr int SwissNameDictionary::DataTableSize(int capacity) {
return capacity * kTaggedSize * kDataTableEntryCount;
}
// static
constexpr int SwissNameDictionary::CtrlTableSize(int capacity) {
// Doing + |kGroupWidth| due to the copy of first group at the end of control
// table.
return (capacity + kGroupWidth) * kOneByteSize;
}
// static
constexpr int SwissNameDictionary::SizeFor(int capacity) {
DCHECK(IsValidCapacity(capacity));
return PropertyDetailsTableStartOffset(capacity) + capacity;
}
// static
constexpr int SwissNameDictionary::PrefixOffset() {
return HeapObject::kHeaderSize;
}
// static
constexpr int SwissNameDictionary::CapacityOffset() {
return PrefixOffset() + sizeof(uint32_t);
}
// static
constexpr int SwissNameDictionary::MetaTablePointerOffset() {
return CapacityOffset() + sizeof(int32_t);
}
// static
constexpr int SwissNameDictionary::DataTableStartOffset() {
return MetaTablePointerOffset() + kTaggedSize;
}
// static
constexpr int SwissNameDictionary::DataTableEndOffset(int capacity) {
return CtrlTableStartOffset(capacity);
}
// static
constexpr int SwissNameDictionary::CtrlTableStartOffset(int capacity) {
return DataTableStartOffset() + DataTableSize(capacity);
}
// static
constexpr int SwissNameDictionary::PropertyDetailsTableStartOffset(
int capacity) {
return CtrlTableStartOffset(capacity) + CtrlTableSize(capacity);
}
} // namespace internal
} // namespace v8
#endif // V8_OBJECTS_SWISS_NAME_DICTIONARY_INL_H_
// Copyright 2021 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.
// Only including the -inl.h file directly makes the linter complain.
#include "src/objects/swiss-name-dictionary.h"
#include "src/objects/swiss-name-dictionary-inl.h"
namespace v8 {
namespace internal {} // namespace internal
} // namespace v8
// Copyright 2021 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.
#ifndef V8_OBJECTS_SWISS_NAME_DICTIONARY_H_
#define V8_OBJECTS_SWISS_NAME_DICTIONARY_H_
#include "src/base/export-template.h"
#include "src/common/globals.h"
#include "src/objects/fixed-array.h"
#include "src/objects/internal-index.h"
#include "src/objects/js-objects.h"
#include "src/roots/roots.h"
// Has to be the last include (doesn't have include guards):
#include "src/objects/object-macros.h"
namespace v8 {
namespace internal {
// A property backing store based on Swiss Tables/Abseil's flat_hash_map. The
// implementation is heavily based on Abseil's raw_hash_set.h.
//
// Memory layout (see below for detailed description of parts):
// Prefix: [table type dependent part, can have 0 size]
// Capacity: 4 bytes, raw int32_t
// Meta table pointer: kTaggedSize bytes
// Data table: 2 * |capacity| * |kTaggedSize| bytes
// Ctrl table: |capacity| + |kGroupWidth| uint8_t entries
// PropertyDetails table: |capacity| uint_8 entries
//
// Note that because of |kInitialCapacity| == 4 there is no need for padding.
//
// Description of parts directly contained in SwissNameDictionary allocation:
// Prefix:
// In case of SwissNameDictionary:
// identity hash: 4 bytes, raw int32_t
// Meta table pointer: kTaggedSize bytes.
// See below for explanation of the meta table.
// For capacity 0, this contains the Smi |kNoMetaTableSentinel| instead.
// Data table:
// For each logical bucket of the hash table, contains the corresponding key
// and value.
// Ctrl table:
// The control table is used to implement a Swiss Table: Each byte is either
// Ctrl::kEmpty, Ctrl::kDeleted, or in case of a bucket denoting a present
// entry in the hash table, the 7 lowest bits of the key's hash. The first
// |capacity| entries are the actual control table. The additional
// |kGroupWidth| bytes contain a copy of the first min(capacity,
// kGroupWidth) bytes of the table.
// PropertyDetails table:
// Each byte contains the PropertyDetails for the corresponding bucket of
// the ctrl table. Entries may contain unitialized data if the corresponding
// bucket hasn't been used before.
//
// Meta table:
// The meta table (not to be confused with the control table used in any
// Swiss Table design!) is a separate ByteArray. Here, the "X" in "uintX_t"
// depends on the capacity of the swiss table. For capacities <= 256 we have X
// = 8, for 256 < |capacity| <= 2^16 we have X = 16, and otherwise X = 32 (see
// MetaTableSizePerEntryFor). It contais the following data:
// Number of Entries: uintX_t.
// Number of Deleted Entries: uintX_t.
// Enumeration table: max_load_factor * Capacity() entries of type uintX_t:
// The i-th entry in the enumeration table
// contains the number of the bucket representing the i-th entry of the
// table in enumeration order. Entries may contain unitialized data if the
// corresponding bucket hasn't been used before.
class SwissNameDictionary : public HeapObject {
public:
inline int Capacity();
inline static bool IsValidCapacity(int capacity);
// Returns total size in bytes required for a table of given capacity.
inline static constexpr int SizeFor(int capacity);
// TODO(v8:11388) This is a temporary placeholder for the actual value, which
// is added here in a follow-up CL.
static const int kGroupWidth = 8;
class BodyDescriptor;
// Note that 0 is also a valid capacity. Changing this value to a smaller one
// may make some padding necessary in the data layout.
static constexpr int kInitialCapacity = kSwissNameDictionaryInitialCapacity;
// Defines how many kTaggedSize sized values are associcated which each entry
// in the data table.
static constexpr int kDataTableEntryCount = 2;
inline static constexpr int DataTableSize(int capacity);
inline static constexpr int CtrlTableSize(int capacity);
// TODO(v8:11388) We would like to use Torque-generated constants here, but
// those are currently incorrect.
// Offset into the overall table, starting at HeapObject standard fields,
// in bytes. This means that the map is stored at offset 0.
using Offset = int;
inline static constexpr Offset PrefixOffset();
inline static constexpr Offset CapacityOffset();
inline static constexpr Offset MetaTablePointerOffset();
inline static constexpr Offset DataTableStartOffset();
inline static constexpr Offset DataTableEndOffset(int capacity);
inline static constexpr Offset CtrlTableStartOffset(int capacity);
inline static constexpr Offset PropertyDetailsTableStartOffset(int capacity);
DECL_VERIFIER(SwissNameDictionary)
DECL_PRINTER(SwissNameDictionary)
DECL_CAST(SwissNameDictionary)
OBJECT_CONSTRUCTORS(SwissNameDictionary, HeapObject);
};
} // namespace internal
} // namespace v8
#endif // V8_OBJECTS_SWISS_NAME_DICTIONARY_H_
// Copyright 2021 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/swiss-name-dictionary.h'
@noVerifier
extern class SwissNameDictionary extends HeapObject {
hash: uint32;
const capacity: int32;
meta_table: ByteArray;
data_table[Convert<intptr>(capacity) * 2]: JSAny|TheHole;
ctrl_table[Convert<intptr>(capacity) + kSwissNameDictionaryGroupWidth]: uint8;
property_details_table[Convert<intptr>(capacity)]: uint8;
}
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "src/objects/scope-info.h" #include "src/objects/scope-info.h"
#include "src/objects/slots.h" #include "src/objects/slots.h"
#include "src/objects/string.h" #include "src/objects/string.h"
#include "src/objects/swiss-name-dictionary.h"
#include "src/roots/roots.h" #include "src/roots/roots.h"
namespace v8 { namespace v8 {
......
...@@ -108,6 +108,7 @@ class Symbol; ...@@ -108,6 +108,7 @@ class Symbol;
V(Map, small_ordered_hash_set_map, SmallOrderedHashSetMap) \ V(Map, small_ordered_hash_set_map, SmallOrderedHashSetMap) \
V(Map, small_ordered_name_dictionary_map, SmallOrderedNameDictionaryMap) \ V(Map, small_ordered_name_dictionary_map, SmallOrderedNameDictionaryMap) \
V(Map, source_text_module_map, SourceTextModuleMap) \ V(Map, source_text_module_map, SourceTextModuleMap) \
V(Map, swiss_name_dictionary_map, SwissNameDictionaryMap) \
V(Map, synthetic_module_map, SyntheticModuleMap) \ V(Map, synthetic_module_map, SyntheticModuleMap) \
V(Map, wasm_type_info_map, WasmTypeInfoMap) \ V(Map, wasm_type_info_map, WasmTypeInfoMap) \
V(Map, weak_fixed_array_map, WeakFixedArrayMap) \ V(Map, weak_fixed_array_map, WeakFixedArrayMap) \
......
...@@ -4911,6 +4911,7 @@ void ImplementationVisitor::GenerateExportedMacrosAssembler( ...@@ -4911,6 +4911,7 @@ void ImplementationVisitor::GenerateExportedMacrosAssembler(
cc_contents << "#include \"src/objects/js-regexp-string-iterator.h\"\n"; cc_contents << "#include \"src/objects/js-regexp-string-iterator.h\"\n";
cc_contents << "#include \"src/objects/ordered-hash-table.h\"\n"; cc_contents << "#include \"src/objects/ordered-hash-table.h\"\n";
cc_contents << "#include \"src/objects/property-descriptor-object.h\"\n"; cc_contents << "#include \"src/objects/property-descriptor-object.h\"\n";
cc_contents << "#include \"src/objects/swiss-name-dictionary.h\"\n";
cc_contents << "#include \"src/objects/synthetic-module.h\"\n"; cc_contents << "#include \"src/objects/synthetic-module.h\"\n";
cc_contents << "#include \"src/objects/template-objects.h\"\n"; cc_contents << "#include \"src/objects/template-objects.h\"\n";
{ {
......
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