Reviewers: Dmitry Lomov (chromium),

https://codereview.chromium.org/779173010/diff/1/src/hydrogen.cc
File src/hydrogen.cc (right):

https://codereview.chromium.org/779173010/diff/1/src/hydrogen.cc#newcode12660
src/hydrogen.cc:12660: Add<HAllocate>(size, HType::HeapObject(),
NOT_TENURED, FIXED_ARRAY_TYPE);
One question about HAllocate: do I need to add code here to fill the
rest of this space with undefineds, to mirror what
Heap::AllocateFixedArray() does?

Description:
Create optimized inline versions of Map and Set initialization

Please review this at https://codereview.chromium.org/779173010/

Base URL: https://chromium.googlesource.com/v8/v8.git@master

Affected files (+63, -6 lines):
  M src/collection.js
  M src/factory.cc
  M src/hydrogen.h
  M src/hydrogen.cc
  M src/runtime/runtime.h


Index: src/collection.js
diff --git a/src/collection.js b/src/collection.js
index d1b16beda6772b7c9fa7072d7a5526152a2ab47d..3f6d105447962ff65705fb02e18144336774b579 100644
--- a/src/collection.js
+++ b/src/collection.js
@@ -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;

Index: src/factory.cc
diff --git a/src/factory.cc b/src/factory.cc
index 4680e75204b30bf91770ab04333fa9fcdd7b94d0..c2fa087d0769353fef32deae556719146250335e 100644
--- a/src/factory.cc
+++ b/src/factory.cc
@@ -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);
 }


Index: src/hydrogen.cc
diff --git a/src/hydrogen.cc b/src/hydrogen.cc
index 5947643733d67e6835047cc3eb5f6a3d799a980b..9114100d442cdbdf42801a573467b4d6a5acf236 100644
--- a/src/hydrogen.cc
+++ b/src/hydrogen.cc
@@ -12648,6 +12648,61 @@ void HOptimizedGraphBuilder::GenerateMapGetSize(CallRuntime* call) {
 }


+template <typename CollectionType>
+HValue* HOptimizedGraphBuilder::BuildAllocateOrderedHashTable() {
+  static const int kInitialCapacity = CollectionType::kMinCapacity;
+  static const int kInitialNumBuckets =
+      kInitialCapacity / CollectionType::kLoadFactor;
+  HValue* size = Add<HConstant>(
+      FixedArray::kHeaderSize + CollectionType::kHashTableStartIndex +
+ kInitialNumBuckets + (kInitialCapacity * CollectionType::kEntrySize));
+  HValue* table =
+ Add<HAllocate>(size, HType::HeapObject(), NOT_TENURED, FIXED_ARRAY_TYPE);
+  Add<HStoreNamedField>(
+      table, HObjectAccess::ForMap(),
+      Add<HConstant>(isolate()->factory()->ordered_hash_table_map()));
+  HValue* not_found = Add<HConstant>(CollectionType::kNotFound);
+  for (int i = 0; i < kInitialNumBuckets; ++i) {
+    Add<HStoreKeyed>(table,
+ Add<HConstant>(CollectionType::kHashTableStartIndex + i),
+                     not_found, FAST_ELEMENTS);
+  }
+  Add<HStoreNamedField>(
+      table,
+      HObjectAccess::ForOrderedHashTableNumberOfBuckets<CollectionType>(),
+      Add<HConstant>(kInitialNumBuckets));
+  Add<HStoreNamedField>(
+      table,
+      HObjectAccess::ForOrderedHashTableNumberOfElements<CollectionType>(),
+      graph()->GetConstant0());
+  Add<HStoreNamedField>(
+      table, HObjectAccess::ForOrderedHashTableNumberOfDeletedElements<
+                 CollectionType>(),
+      graph()->GetConstant0());
+  return table;
+}
+
+
+void HOptimizedGraphBuilder::GenerateSetInitialize(CallRuntime* call) {
+  DCHECK(call->arguments()->length() == 1);
+  CHECK_ALIVE(VisitForValue(call->arguments()->at(0)));
+  HValue* receiver = Pop();
+  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();
+  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)));
Index: src/hydrogen.h
diff --git a/src/hydrogen.h b/src/hydrogen.h
index f24f1729e8cdb96ea90bbf077d9503d2cc47ab7b..86c3b6b9fd79eb29eee100caa301f94f2d44c270 100644
--- a/src/hydrogen.h
+++ b/src/hydrogen.h
@@ -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>
Index: src/runtime/runtime.h
diff --git a/src/runtime/runtime.h b/src/runtime/runtime.h
index 8cc2db1c710d0e49bb5b32d7a36bd470fdb50d25..867bd196a8dcbcb13eb961cec2d3f35fcca7dadf 100644
--- a/src/runtime/runtime.h
+++ b/src/runtime/runtime.h
@@ -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)


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to