Commit 8877f156 authored by adamk's avatar adamk Committed by Commit bot

Create optimized inline versions of Map and Set initialization

Review URL: https://codereview.chromium.org/779173010

Cr-Commit-Position: refs/heads/master@{#25758}
parent 986e7cef
......@@ -30,7 +30,7 @@ function SetConstructor(iterable) {
}
}
%SetInitialize(this);
%_SetInitialize(this);
if (IS_UNDEFINED(iter)) return;
......@@ -170,7 +170,7 @@ function MapConstructor(iterable) {
}
}
%MapInitialize(this);
%_MapInitialize(this);
if (IS_UNDEFINED(iter)) return;
......
......@@ -139,12 +139,12 @@ Handle<ConstantPoolArray> Factory::NewExtendedConstantPoolArray(
Handle<OrderedHashSet> Factory::NewOrderedHashSet() {
return OrderedHashSet::Allocate(isolate(), 4);
return OrderedHashSet::Allocate(isolate(), OrderedHashSet::kMinCapacity);
}
Handle<OrderedHashMap> Factory::NewOrderedHashMap() {
return OrderedHashMap::Allocate(isolate(), 4);
return OrderedHashMap::Allocate(isolate(), OrderedHashMap::kMinCapacity);
}
......
......@@ -6367,6 +6367,22 @@ class HObjectAccess FINAL {
Representation::Smi());
}
template <typename CollectionType>
static HObjectAccess ForOrderedHashTableBucket(int bucket) {
return HObjectAccess(kInobject, CollectionType::kHashTableStartOffset +
(bucket * kPointerSize),
Representation::Smi());
}
// Access into the data table of an OrderedHashTable with a
// known-at-compile-time bucket count.
template <typename CollectionType, int kBucketCount>
static HObjectAccess ForOrderedHashTableDataTableIndex(int index) {
return HObjectAccess(kInobject, CollectionType::kHashTableStartOffset +
(kBucketCount * kPointerSize) +
(index * kPointerSize));
}
inline bool Equals(HObjectAccess that) const {
return value_ == that.value_; // portion and offset must match
}
......
......@@ -12648,6 +12648,85 @@ void HOptimizedGraphBuilder::GenerateMapGetSize(CallRuntime* call) {
}
template <typename CollectionType>
HValue* HOptimizedGraphBuilder::BuildAllocateOrderedHashTable() {
static const int kCapacity = CollectionType::kMinCapacity;
static const int kBucketCount = kCapacity / CollectionType::kLoadFactor;
static const int kFixedArrayLength = CollectionType::kHashTableStartIndex +
kBucketCount +
(kCapacity * CollectionType::kEntrySize);
static const int kSizeInBytes =
FixedArray::kHeaderSize + (kFixedArrayLength * kPointerSize);
// Allocate the table and add the proper map.
HValue* table =
Add<HAllocate>(Add<HConstant>(kSizeInBytes), HType::HeapObject(),
NOT_TENURED, FIXED_ARRAY_TYPE);
AddStoreMapConstant(table, isolate()->factory()->ordered_hash_table_map());
// Initialize the FixedArray...
HValue* length = Add<HConstant>(kFixedArrayLength);
Add<HStoreNamedField>(table, HObjectAccess::ForFixedArrayLength(), length);
// ...and the OrderedHashTable fields.
Add<HStoreNamedField>(
table,
HObjectAccess::ForOrderedHashTableNumberOfBuckets<CollectionType>(),
Add<HConstant>(kBucketCount));
Add<HStoreNamedField>(
table,
HObjectAccess::ForOrderedHashTableNumberOfElements<CollectionType>(),
graph()->GetConstant0());
Add<HStoreNamedField>(
table, HObjectAccess::ForOrderedHashTableNumberOfDeletedElements<
CollectionType>(),
graph()->GetConstant0());
// Fill the buckets with kNotFound.
HValue* not_found = Add<HConstant>(CollectionType::kNotFound);
for (int i = 0; i < kBucketCount; ++i) {
Add<HStoreNamedField>(
table, HObjectAccess::ForOrderedHashTableBucket<CollectionType>(i),
not_found);
}
// Fill the data table with undefined.
HValue* undefined = graph()->GetConstantUndefined();
for (int i = 0; i < (kCapacity * CollectionType::kEntrySize); ++i) {
Add<HStoreNamedField>(table,
HObjectAccess::ForOrderedHashTableDataTableIndex<
CollectionType, kBucketCount>(i),
undefined);
}
return table;
}
void HOptimizedGraphBuilder::GenerateSetInitialize(CallRuntime* call) {
DCHECK(call->arguments()->length() == 1);
CHECK_ALIVE(VisitForValue(call->arguments()->at(0)));
HValue* receiver = Pop();
NoObservableSideEffectsScope no_effects(this);
HValue* table = BuildAllocateOrderedHashTable<OrderedHashSet>();
Add<HStoreNamedField>(receiver, HObjectAccess::ForJSCollectionTable(), table);
return ast_context()->ReturnValue(receiver);
}
void HOptimizedGraphBuilder::GenerateMapInitialize(CallRuntime* call) {
DCHECK(call->arguments()->length() == 1);
CHECK_ALIVE(VisitForValue(call->arguments()->at(0)));
HValue* receiver = Pop();
NoObservableSideEffectsScope no_effects(this);
HValue* table = BuildAllocateOrderedHashTable<OrderedHashMap>();
Add<HStoreNamedField>(receiver, HObjectAccess::ForJSCollectionTable(), table);
return ast_context()->ReturnValue(receiver);
}
void HOptimizedGraphBuilder::GenerateGetCachedArrayIndex(CallRuntime* call) {
DCHECK(call->arguments()->length() == 1);
CHECK_ALIVE(VisitForValue(call->arguments()->at(0)));
......
......@@ -2432,6 +2432,8 @@ class HOptimizedGraphBuilder : public HGraphBuilder, public AstVisitor {
HValue* hash,
HIfContinuation* join_continuation);
template <typename CollectionType>
HValue* BuildAllocateOrderedHashTable();
template <typename CollectionType>
void BuildJSCollectionDelete(CallRuntime* call,
const Runtime::Function* c_function);
template <typename CollectionType>
......
......@@ -3928,6 +3928,8 @@ class OrderedHashTable: public FixedArray {
kHeaderSize + kNumberOfElementsIndex * kPointerSize;
static const int kNumberOfDeletedElementsOffset =
kHeaderSize + kNumberOfDeletedElementsIndex * kPointerSize;
static const int kHashTableStartOffset =
kHeaderSize + kHashTableStartIndex * kPointerSize;
static const int kEntrySize = entrysize + 1;
static const int kChainOffset = entrysize;
......
......@@ -300,7 +300,6 @@ namespace internal {
F(Fix, 1, 1) \
\
/* Harmony sets */ \
F(SetInitialize, 1, 1) \
F(SetClear, 1, 1) \
\
F(SetIteratorInitialize, 3, 1) \
......@@ -309,7 +308,6 @@ namespace internal {
F(SetIteratorDetails, 1, 1) \
\
/* Harmony maps */ \
F(MapInitialize, 1, 1) \
F(MapClear, 1, 1) \
\
F(MapIteratorInitialize, 3, 1) \
......@@ -726,11 +724,13 @@ namespace internal {
F(MapGet, 2, 1) \
F(MapGetSize, 1, 1) \
F(MapHas, 2, 1) \
F(MapInitialize, 1, 1) \
F(MapSet, 3, 1) \
F(SetAdd, 2, 1) \
F(SetDelete, 2, 1) \
F(SetGetSize, 1, 1) \
F(SetHas, 2, 1) \
F(SetInitialize, 1, 1) \
/* Arrays */ \
F(HasFastPackedElements, 1, 1) \
F(GetPrototype, 1, 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