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

[hashtable] Move ordered hash table allocation to CSA

.. from BaseCollectionsAssembler

Bug: v8:7569
Change-Id: I87fd35dbd82ad5752c857f35b63403ca348bf305
Reviewed-on: https://chromium-review.googlesource.com/1024700Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
Commit-Queue: Sathya Gunasekaran <gsathya@chromium.org>
Cr-Commit-Position: refs/heads/master@{#52765}
parent 75922ead
......@@ -620,8 +620,6 @@ class CollectionsBuiltinsAssembler : public BaseCollectionsAssembler {
: BaseCollectionsAssembler(state) {}
protected:
template <typename CollectionType>
Node* AllocateOrderedHashTable();
template <typename IteratorType>
Node* AllocateJSCollectionIterator(Node* context, int map_index,
Node* collection);
......@@ -734,58 +732,6 @@ class CollectionsBuiltinsAssembler : public BaseCollectionsAssembler {
Node* const occupancy);
};
template <typename CollectionType>
Node* CollectionsBuiltinsAssembler::AllocateOrderedHashTable() {
static const int kCapacity = CollectionType::kMinCapacity;
static const int kBucketCount = kCapacity / CollectionType::kLoadFactor;
static const int kDataTableLength = kCapacity * CollectionType::kEntrySize;
static const int kFixedArrayLength =
CollectionType::kHashTableStartIndex + kBucketCount + kDataTableLength;
static const int kDataTableStartIndex =
CollectionType::kHashTableStartIndex + kBucketCount;
STATIC_ASSERT(base::bits::IsPowerOfTwo(kCapacity));
STATIC_ASSERT(kCapacity <= CollectionType::kMaxCapacity);
// Allocate the table and add the proper map.
const ElementsKind elements_kind = HOLEY_ELEMENTS;
Node* const length_intptr = IntPtrConstant(kFixedArrayLength);
Node* const fixed_array_map = LoadRoot(
static_cast<Heap::RootListIndex>(CollectionType::GetMapRootIndex()));
Node* const table =
AllocateFixedArray(elements_kind, length_intptr, INTPTR_PARAMETERS,
kAllowLargeObjectAllocation, fixed_array_map);
// Initialize the OrderedHashTable fields.
const WriteBarrierMode barrier_mode = SKIP_WRITE_BARRIER;
StoreFixedArrayElement(table, CollectionType::kNumberOfElementsIndex,
SmiConstant(0), barrier_mode);
StoreFixedArrayElement(table, CollectionType::kNumberOfDeletedElementsIndex,
SmiConstant(0), barrier_mode);
StoreFixedArrayElement(table, CollectionType::kNumberOfBucketsIndex,
SmiConstant(kBucketCount), barrier_mode);
// Fill the buckets with kNotFound.
Node* const not_found = SmiConstant(CollectionType::kNotFound);
STATIC_ASSERT(CollectionType::kHashTableStartIndex ==
CollectionType::kNumberOfBucketsIndex + 1);
STATIC_ASSERT((CollectionType::kHashTableStartIndex + kBucketCount) ==
kDataTableStartIndex);
for (int i = 0; i < kBucketCount; i++) {
StoreFixedArrayElement(table, CollectionType::kHashTableStartIndex + i,
not_found, barrier_mode);
}
// Fill the data table with undefined.
STATIC_ASSERT(kDataTableStartIndex + kDataTableLength == kFixedArrayLength);
for (int i = 0; i < kDataTableLength; i++) {
StoreFixedArrayElement(table, kDataTableStartIndex + i, UndefinedConstant(),
barrier_mode);
}
return table;
}
template <typename IteratorType>
Node* CollectionsBuiltinsAssembler::AllocateJSCollectionIterator(
Node* context, int map_index, Node* collection) {
......
......@@ -2953,6 +2953,61 @@ Node* CodeStubAssembler::CopyNameDictionary(Node* dictionary,
return properties;
}
template <typename CollectionType>
Node* CodeStubAssembler::AllocateOrderedHashTable() {
static const int kCapacity = CollectionType::kMinCapacity;
static const int kBucketCount = kCapacity / CollectionType::kLoadFactor;
static const int kDataTableLength = kCapacity * CollectionType::kEntrySize;
static const int kFixedArrayLength =
CollectionType::kHashTableStartIndex + kBucketCount + kDataTableLength;
static const int kDataTableStartIndex =
CollectionType::kHashTableStartIndex + kBucketCount;
STATIC_ASSERT(base::bits::IsPowerOfTwo(kCapacity));
STATIC_ASSERT(kCapacity <= CollectionType::kMaxCapacity);
// Allocate the table and add the proper map.
const ElementsKind elements_kind = HOLEY_ELEMENTS;
Node* const length_intptr = IntPtrConstant(kFixedArrayLength);
Node* const fixed_array_map = LoadRoot(
static_cast<Heap::RootListIndex>(CollectionType::GetMapRootIndex()));
Node* const table =
AllocateFixedArray(elements_kind, length_intptr, INTPTR_PARAMETERS,
kAllowLargeObjectAllocation, fixed_array_map);
// Initialize the OrderedHashTable fields.
const WriteBarrierMode barrier_mode = SKIP_WRITE_BARRIER;
StoreFixedArrayElement(table, CollectionType::kNumberOfElementsIndex,
SmiConstant(0), barrier_mode);
StoreFixedArrayElement(table, CollectionType::kNumberOfDeletedElementsIndex,
SmiConstant(0), barrier_mode);
StoreFixedArrayElement(table, CollectionType::kNumberOfBucketsIndex,
SmiConstant(kBucketCount), barrier_mode);
// Fill the buckets with kNotFound.
Node* const not_found = SmiConstant(CollectionType::kNotFound);
STATIC_ASSERT(CollectionType::kHashTableStartIndex ==
CollectionType::kNumberOfBucketsIndex + 1);
STATIC_ASSERT((CollectionType::kHashTableStartIndex + kBucketCount) ==
kDataTableStartIndex);
for (int i = 0; i < kBucketCount; i++) {
StoreFixedArrayElement(table, CollectionType::kHashTableStartIndex + i,
not_found, barrier_mode);
}
// Fill the data table with undefined.
STATIC_ASSERT(kDataTableStartIndex + kDataTableLength == kFixedArrayLength);
for (int i = 0; i < kDataTableLength; i++) {
StoreFixedArrayElement(table, kDataTableStartIndex + i, UndefinedConstant(),
barrier_mode);
}
return table;
}
template Node* CodeStubAssembler::AllocateOrderedHashTable<OrderedHashMap>();
template Node* CodeStubAssembler::AllocateOrderedHashTable<OrderedHashSet>();
Node* CodeStubAssembler::AllocateStruct(Node* map, AllocationFlags flags) {
Comment("AllocateStruct");
CSA_ASSERT(this, IsMap(map));
......
......@@ -949,6 +949,9 @@ class V8_EXPORT_PRIVATE CodeStubAssembler : public compiler::CodeAssembler {
Node* AllocateNameDictionaryWithCapacity(Node* capacity);
Node* CopyNameDictionary(Node* dictionary, Label* large_object_fallback);
template <typename CollectionType>
Node* AllocateOrderedHashTable();
Node* AllocateStruct(Node* map, AllocationFlags flags = kNone);
void InitializeStructBody(Node* object, Node* map, Node* size,
int start_offset = Struct::kHeaderSize);
......
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