Commit 49ecce8a authored by Sathya Gunasekaran's avatar Sathya Gunasekaran Committed by Commit Bot

[collections] Port AllocateOrderedHashTable to CSA

Bug: v8:5717, v8:6354
Change-Id: I4ae2a0b629ca8fe03fb8f645aa5f22cf7f2e4a20
Reviewed-on: https://chromium-review.googlesource.com/515024Reviewed-by: 's avatarCamillo Bruni <cbruni@chromium.org>
Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Commit-Queue: Sathya Gunasekaran <gsathya@chromium.org>
Cr-Commit-Position: refs/heads/master@{#45872}
parent ec69ad72
......@@ -6,6 +6,7 @@
#include "src/builtins/builtins-iterator-gen.h"
#include "src/builtins/builtins-utils-gen.h"
#include "src/code-stub-assembler.h"
#include "src/objects/hash-table.h"
namespace v8 {
namespace internal {
......@@ -18,12 +19,72 @@ class CollectionsBuiltinsAssembler : public CodeStubAssembler {
: CodeStubAssembler(state) {}
protected:
Node* AllocateJSMap(Node* js_map_function);
template <typename CollectionType>
Node* AllocateOrderedHashTable();
Node* AllocateJSCollection(Node* js_map_function);
Node* CallGetRaw(Node* const table, Node* const key);
template <typename CollectionType, int entrysize>
Node* CallHasRaw(Node* const table, Node* const key);
};
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::IsPowerOfTwo32(kCapacity));
STATIC_ASSERT(kCapacity <= CollectionType::kMaxCapacity);
// Allocate the table and add the proper map.
const ElementsKind elements_kind = FAST_HOLEY_ELEMENTS;
Node* const length_intptr = IntPtrConstant(kFixedArrayLength);
Node* const table = AllocateFixedArray(elements_kind, length_intptr);
CSA_ASSERT(this,
IntPtrLessThanOrEqual(
length_intptr, IntPtrConstant(FixedArray::kMaxRegularLength)));
Heap::RootListIndex map_index = Heap::kOrderedHashTableMapRootIndex;
// TODO(gsathya): Directly store correct in AllocateFixedArray,
// instead of overwriting here.
StoreMapNoWriteBarrier(table, map_index);
// 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;
}
Node* CollectionsBuiltinsAssembler::AllocateJSCollection(
Node* js_map_function) {
CSA_ASSERT(this, IsConstructorMap(LoadMap(js_map_function)));
......@@ -80,8 +141,8 @@ TF_BUILTIN(MapConstructor, CollectionsBuiltinsAssembler) {
}
BIND(&init);
// TODO(gsathya): Remove runtime call once OrderedHashTable is ported.
CallRuntime(Runtime::kMapInitialize, context, var_result.value());
Node* table = AllocateOrderedHashTable<OrderedHashMap>();
StoreObjectField(var_result.value(), JSMap::kTableOffset, table);
GotoIf(Word32Or(IsUndefined(iterable), IsNull(iterable)), &exit);
......@@ -207,8 +268,8 @@ TF_BUILTIN(SetConstructor, CollectionsBuiltinsAssembler) {
}
BIND(&init);
// TODO(gsathya): Remove runtime call once OrderedHashTable is ported.
CallRuntime(Runtime::kSetInitialize, context, var_result.value());
Node* table = AllocateOrderedHashTable<OrderedHashSet>();
StoreObjectField(var_result.value(), JSSet::kTableOffset, table);
GotoIf(Word32Or(IsUndefined(iterable), IsNull(iterable)), &exit);
......
......@@ -495,6 +495,10 @@ class OrderedHashTable : public FixedArray {
// optimize that case.
static const int kClearedTableSentinel = -1;
static const int kMaxCapacity =
(FixedArray::kMaxLength - kHashTableStartIndex) /
(1 + (kEntrySize * kLoadFactor));
protected:
static Handle<Derived> Rehash(Handle<Derived> table, int new_capacity);
......@@ -520,10 +524,6 @@ class OrderedHashTable : public FixedArray {
}
static const int kRemovedHolesIndex = kHashTableStartIndex;
static const int kMaxCapacity =
(FixedArray::kMaxLength - kHashTableStartIndex) /
(1 + (kEntrySize * kLoadFactor));
};
class OrderedHashSet : public OrderedHashTable<OrderedHashSet, 1> {
......
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