Commit f08e42e3 authored by Sathya Gunasekaran's avatar Sathya Gunasekaran Committed by Commit Bot

[dict] Remove ordered hash table base

Now we can pass in the prefix size to OrderedHashTable directly from
the Derived class and have it calculate the hash table start offset
based on this.

Bug: v8:6443, v8:7569
Change-Id: I80d54b65116e18f5a0cab18eb51649adad447cce
Reviewed-on: https://chromium-review.googlesource.com/c/1333682
Commit-Queue: Sathya Gunasekaran <gsathya@chromium.org>
Reviewed-by: 's avatarToon Verwaest <verwaest@chromium.org>
Reviewed-by: 's avatarJaroslav Sevcik <jarin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57499}
parent ba5501ed
......@@ -1396,10 +1396,14 @@ TF_BUILTIN(OrderedHashTableHealIndex, CollectionsBuiltinsAssembler) {
GotoIfNot(SmiLessThan(SmiConstant(0), index), &return_zero);
// Check if the {table} was cleared.
STATIC_ASSERT(OrderedHashMap::kNumberOfDeletedElementsOffset ==
OrderedHashSet::kNumberOfDeletedElementsOffset);
Node* number_of_deleted_elements = LoadAndUntagObjectField(
table, OrderedHashTableBase::kNumberOfDeletedElementsOffset);
table, OrderedHashMap::kNumberOfDeletedElementsOffset);
STATIC_ASSERT(OrderedHashMap::kClearedTableSentinel ==
OrderedHashSet::kClearedTableSentinel);
GotoIf(WordEqual(number_of_deleted_elements,
IntPtrConstant(OrderedHashTableBase::kClearedTableSentinel)),
IntPtrConstant(OrderedHashMap::kClearedTableSentinel)),
&return_zero);
VARIABLE(var_i, MachineType::PointerRepresentation(), IntPtrConstant(0));
......@@ -1410,9 +1414,10 @@ TF_BUILTIN(OrderedHashTableHealIndex, CollectionsBuiltinsAssembler) {
{
Node* i = var_i.value();
GotoIfNot(IntPtrLessThan(i, number_of_deleted_elements), &return_index);
STATIC_ASSERT(OrderedHashMap::kRemovedHolesIndex ==
OrderedHashSet::kRemovedHolesIndex);
TNode<Smi> removed_index = CAST(LoadFixedArrayElement(
CAST(table), i,
OrderedHashTableBase::kRemovedHolesIndex * kPointerSize));
CAST(table), i, OrderedHashMap::kRemovedHolesIndex * kPointerSize));
GotoIf(SmiGreaterThanOrEqual(removed_index, index), &return_index);
Decrement(&var_index, 1, SMI_PARAMETERS);
Increment(&var_i);
......
......@@ -1036,11 +1036,13 @@ FieldAccess AccessBuilder::ForHashTableBaseCapacity() {
}
// static
FieldAccess AccessBuilder::ForOrderedHashTableBaseNextTable() {
FieldAccess AccessBuilder::ForOrderedHashMapOrSetNextTable() {
// TODO(turbofan): This will be redundant with the HashTableBase
// methods above once the hash table unification is done.
STATIC_ASSERT(OrderedHashMap::kNextTableOffset ==
OrderedHashSet::kNextTableOffset);
FieldAccess const access = {
kTaggedBase, OrderedHashTableBase::kNextTableOffset,
kTaggedBase, OrderedHashMap::kNextTableOffset,
MaybeHandle<Name>(), MaybeHandle<Map>(),
Type::Any(), MachineType::AnyTagged(),
kFullWriteBarrier};
......@@ -1048,11 +1050,13 @@ FieldAccess AccessBuilder::ForOrderedHashTableBaseNextTable() {
}
// static
FieldAccess AccessBuilder::ForOrderedHashTableBaseNumberOfBuckets() {
FieldAccess AccessBuilder::ForOrderedHashMapOrSetNumberOfBuckets() {
// TODO(turbofan): This will be redundant with the HashTableBase
// methods above once the hash table unification is done.
STATIC_ASSERT(OrderedHashMap::kNumberOfBucketsOffset ==
OrderedHashSet::kNumberOfBucketsOffset);
FieldAccess const access = {kTaggedBase,
OrderedHashTableBase::kNumberOfBucketsOffset,
OrderedHashMap::kNumberOfBucketsOffset,
MaybeHandle<Name>(),
MaybeHandle<Map>(),
TypeCache::Get().kFixedArrayLengthType,
......@@ -1062,12 +1066,13 @@ FieldAccess AccessBuilder::ForOrderedHashTableBaseNumberOfBuckets() {
}
// static
FieldAccess AccessBuilder::ForOrderedHashTableBaseNumberOfDeletedElements() {
FieldAccess AccessBuilder::ForOrderedHashMapOrSetNumberOfDeletedElements() {
// TODO(turbofan): This will be redundant with the HashTableBase
// methods above once the hash table unification is done.
FieldAccess const access = {
kTaggedBase,
OrderedHashTableBase::kNumberOfDeletedElementsOffset,
STATIC_ASSERT(OrderedHashMap::kNumberOfDeletedElementsOffset ==
OrderedHashSet::kNumberOfDeletedElementsOffset);
FieldAccess const access = {kTaggedBase,
OrderedHashMap::kNumberOfDeletedElementsOffset,
MaybeHandle<Name>(),
MaybeHandle<Map>(),
TypeCache::Get().kFixedArrayLengthType,
......@@ -1077,11 +1082,13 @@ FieldAccess AccessBuilder::ForOrderedHashTableBaseNumberOfDeletedElements() {
}
// static
FieldAccess AccessBuilder::ForOrderedHashTableBaseNumberOfElements() {
FieldAccess AccessBuilder::ForOrderedHashMapOrSetNumberOfElements() {
// TODO(turbofan): This will be redundant with the HashTableBase
// methods above once the hash table unification is done.
STATIC_ASSERT(OrderedHashMap::kNumberOfElementsOffset ==
OrderedHashSet::kNumberOfElementsOffset);
FieldAccess const access = {kTaggedBase,
OrderedHashTableBase::kNumberOfElementsOffset,
OrderedHashMap::kNumberOfElementsOffset,
MaybeHandle<Name>(),
MaybeHandle<Map>(),
TypeCache::Get().kFixedArrayLengthType,
......
......@@ -302,11 +302,11 @@ class V8_EXPORT_PRIVATE AccessBuilder final
static FieldAccess ForHashTableBaseNumberOfDeletedElement();
static FieldAccess ForHashTableBaseCapacity();
// Provides access to OrderedHashTableBase fields.
static FieldAccess ForOrderedHashTableBaseNextTable();
static FieldAccess ForOrderedHashTableBaseNumberOfBuckets();
static FieldAccess ForOrderedHashTableBaseNumberOfElements();
static FieldAccess ForOrderedHashTableBaseNumberOfDeletedElements();
// Provides access to OrderedHashMapOrSet fields.
static FieldAccess ForOrderedHashMapOrSetNextTable();
static FieldAccess ForOrderedHashMapOrSetNumberOfBuckets();
static FieldAccess ForOrderedHashMapOrSetNumberOfElements();
static FieldAccess ForOrderedHashMapOrSetNumberOfDeletedElements();
// Provides access to OrderedHashMap elements.
static ElementAccess ForOrderedHashMapEntryValue();
......
......@@ -5225,7 +5225,7 @@ Node* EffectControlLinearizer::LowerFindOrderedHashMapEntryForInt32Key(
Node* hash = ChangeUint32ToUintPtr(ComputeUnseededHash(key));
Node* number_of_buckets = ChangeSmiToIntPtr(__ LoadField(
AccessBuilder::ForOrderedHashTableBaseNumberOfBuckets(), table));
AccessBuilder::ForOrderedHashMapOrSetNumberOfBuckets(), table));
hash = __ WordAnd(hash, __ IntSub(number_of_buckets, __ IntPtrConstant(1)));
Node* first_entry = ChangeSmiToIntPtr(__ Load(
MachineType::TaggedSigned(), table,
......
......@@ -6422,7 +6422,7 @@ Reduction JSCallReducer::ReduceCollectionPrototypeSize(
receiver, effect, control);
Node* value = effect = graph()->NewNode(
simplified()->LoadField(
AccessBuilder::ForOrderedHashTableBaseNumberOfElements()),
AccessBuilder::ForOrderedHashMapOrSetNumberOfElements()),
table, effect, control);
ReplaceWithValue(node, value, effect, control);
return Replace(value);
......@@ -6489,7 +6489,7 @@ Reduction JSCallReducer::ReduceCollectionIteratorPrototypeNext(
receiver, effect, control);
Node* next_table = effect =
graph()->NewNode(simplified()->LoadField(
AccessBuilder::ForOrderedHashTableBaseNextTable()),
AccessBuilder::ForOrderedHashMapOrSetNextTable()),
table, effect, control);
Node* check = graph()->NewNode(simplified()->ObjectIsSmi(), next_table);
control =
......@@ -6558,15 +6558,15 @@ Reduction JSCallReducer::ReduceCollectionIteratorPrototypeNext(
// Compute the currently used capacity.
Node* number_of_buckets = effect = graph()->NewNode(
simplified()->LoadField(
AccessBuilder::ForOrderedHashTableBaseNumberOfBuckets()),
AccessBuilder::ForOrderedHashMapOrSetNumberOfBuckets()),
table, effect, control);
Node* number_of_elements = effect = graph()->NewNode(
simplified()->LoadField(
AccessBuilder::ForOrderedHashTableBaseNumberOfElements()),
AccessBuilder::ForOrderedHashMapOrSetNumberOfElements()),
table, effect, control);
Node* number_of_deleted_elements = effect = graph()->NewNode(
simplified()->LoadField(
AccessBuilder::ForOrderedHashTableBaseNumberOfDeletedElements()),
AccessBuilder::ForOrderedHashMapOrSetNumberOfDeletedElements()),
table, effect, control);
Node* used_capacity =
graph()->NewNode(simplified()->NumberAdd(), number_of_elements,
......@@ -6608,6 +6608,8 @@ Reduction JSCallReducer::ReduceCollectionIteratorPrototypeNext(
Node* etrue0 = effect;
{
// Load the key of the entry.
STATIC_ASSERT(OrderedHashMap::kHashTableStartIndex ==
OrderedHashSet::kHashTableStartIndex);
Node* entry_start_position = graph()->NewNode(
simplified()->NumberAdd(),
graph()->NewNode(
......@@ -6615,7 +6617,7 @@ Reduction JSCallReducer::ReduceCollectionIteratorPrototypeNext(
graph()->NewNode(simplified()->NumberMultiply(), index,
jsgraph()->Constant(entry_size)),
number_of_buckets),
jsgraph()->Constant(OrderedHashTableBase::kHashTableStartIndex));
jsgraph()->Constant(OrderedHashMap::kHashTableStartIndex));
Node* entry_key = etrue0 = graph()->NewNode(
simplified()->LoadElement(AccessBuilder::ForFixedArrayElement()),
table, entry_start_position, etrue0, if_true0);
......
......@@ -87,7 +87,7 @@ void KeyAccumulator::AddKey(Handle<Object> key, AddKeyConversion convert) {
// The keys_ Set is converted directly to a FixedArray in GetKeys which can
// be left-trimmer. Hence the previous Set should not keep a pointer to the
// new one.
keys_->set(OrderedHashTableBase::kNextTableIndex, Smi::kZero);
keys_->set(OrderedHashSet::kNextTableIndex, Smi::kZero);
keys_ = new_set;
}
}
......
......@@ -16,40 +16,6 @@
namespace v8 {
namespace internal {
// Non-templatized base class for {OrderedHashTable}s.
// TODO(hash): Unify this with the HashTableBase above.
class OrderedHashTableBase : public FixedArray {
public:
static const int kNotFound = -1;
static const int kMinCapacity = 4;
static const int kNumberOfElementsIndex = 0;
// The next table is stored at the same index as the nof elements.
static const int kNextTableIndex = kNumberOfElementsIndex;
static const int kNumberOfDeletedElementsIndex = kNumberOfElementsIndex + 1;
static const int kNumberOfBucketsIndex = kNumberOfDeletedElementsIndex + 1;
static const int kHashTableStartIndex = kNumberOfBucketsIndex + 1;
static const int kRemovedHolesIndex = kHashTableStartIndex;
static constexpr const int kNumberOfElementsOffset =
FixedArray::OffsetOfElementAt(kNumberOfElementsIndex);
static constexpr const int kNextTableOffset =
FixedArray::OffsetOfElementAt(kNextTableIndex);
static constexpr const int kNumberOfDeletedElementsOffset =
FixedArray::OffsetOfElementAt(kNumberOfDeletedElementsIndex);
static constexpr const int kNumberOfBucketsOffset =
FixedArray::OffsetOfElementAt(kNumberOfBucketsIndex);
static constexpr const int kHashTableStartOffset =
FixedArray::OffsetOfElementAt(kHashTableStartIndex);
static const int kLoadFactor = 2;
// NumberOfDeletedElements is set to kClearedTableSentinel when
// the table is cleared, which allows iterator transitions to
// optimize that case.
static const int kClearedTableSentinel = -1;
};
// OrderedHashTable is a HashTable with Object keys that preserves
// insertion order. There are Map and Set interfaces (OrderedHashMap
// and OrderedHashTable, below). It is meant to be used by JSMap/JSSet.
......@@ -87,7 +53,7 @@ class OrderedHashTableBase : public FixedArray {
// [3 + NumberOfRemovedHoles()..length]: Not used
//
template <class Derived, int entrysize>
class OrderedHashTable : public OrderedHashTableBase {
class OrderedHashTable : public FixedArray {
public:
// Returns an OrderedHashTable with a capacity of at least |capacity|.
static Handle<Derived> Allocate(Isolate* isolate, int capacity,
......@@ -168,6 +134,34 @@ class OrderedHashTable : public OrderedHashTableBase {
static const int kEntrySize = entrysize + 1;
static const int kChainOffset = entrysize;
static const int kNotFound = -1;
static const int kMinCapacity = 4;
static const int kNumberOfElementsIndex = 0;
// The next table is stored at the same index as the nof elements.
static const int kNextTableIndex = kNumberOfElementsIndex;
static const int kNumberOfDeletedElementsIndex = kNumberOfElementsIndex + 1;
static const int kNumberOfBucketsIndex = kNumberOfDeletedElementsIndex + 1;
static const int kHashTableStartIndex = kNumberOfBucketsIndex + 1;
static const int kRemovedHolesIndex = kHashTableStartIndex;
static constexpr const int kNumberOfElementsOffset =
FixedArray::OffsetOfElementAt(kNumberOfElementsIndex);
static constexpr const int kNextTableOffset =
FixedArray::OffsetOfElementAt(kNextTableIndex);
static constexpr const int kNumberOfDeletedElementsOffset =
FixedArray::OffsetOfElementAt(kNumberOfDeletedElementsIndex);
static constexpr const int kNumberOfBucketsOffset =
FixedArray::OffsetOfElementAt(kNumberOfBucketsIndex);
static constexpr const int kHashTableStartOffset =
FixedArray::OffsetOfElementAt(kHashTableStartIndex);
static const int kLoadFactor = 2;
// NumberOfDeletedElements is set to kClearedTableSentinel when
// the table is cleared, which allows iterator transitions to
// optimize that case.
static const int kClearedTableSentinel = -1;
static const int kMaxCapacity =
(FixedArray::kMaxLength - kHashTableStartIndex) /
(1 + (kEntrySize * kLoadFactor));
......
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