Reviewers: Michael Starzinger,

Message:
Hi Michael, here is the CL we discussed earlier in the week, PTAL. thx!

Description:
Allow FastCloneShallowObjectStub to use AllocationMementos.
(currently turned off)

BUG=

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

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files (+69, -19 lines):
  M src/arm/full-codegen-arm.cc
  M src/code-stubs-hydrogen.cc
  M src/code-stubs.h
  M src/hydrogen.cc
  M src/ia32/full-codegen-ia32.cc
  M src/runtime.cc
  M src/x64/full-codegen-x64.cc


Index: src/arm/full-codegen-arm.cc
diff --git a/src/arm/full-codegen-arm.cc b/src/arm/full-codegen-arm.cc
index 3becc96d262513378f31b3d5ebc7fcf5d62e3f54..eaa662d7a144299cfe9399fcebbd630f5f831f3d 100644
--- a/src/arm/full-codegen-arm.cc
+++ b/src/arm/full-codegen-arm.cc
@@ -1657,7 +1657,8 @@ void FullCodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) {
     __ Push(r3, r2, r1, r0);
     __ CallRuntime(Runtime::kCreateObjectLiteral, 4);
   } else {
-    FastCloneShallowObjectStub stub(properties_count);
+    FastCloneShallowObjectStub stub(DONT_TRACK_ALLOCATION_SITE,
+                                    properties_count);
     __ CallStub(&stub);
   }

Index: src/code-stubs-hydrogen.cc
diff --git a/src/code-stubs-hydrogen.cc b/src/code-stubs-hydrogen.cc
index dcf9e5b67e50565c3ac4599975914544c4c977b7..9b77ce4281eecc99db6c83c8421224692c3d0ffe 100644
--- a/src/code-stubs-hydrogen.cc
+++ b/src/code-stubs-hydrogen.cc
@@ -436,22 +436,32 @@ template <>
 HValue* CodeStubGraphBuilder<FastCloneShallowObjectStub>::BuildCodeStub() {
   HValue* undefined = graph()->GetConstantUndefined();

-  HInstruction* boilerplate = Add<HLoadKeyed>(GetParameter(0),
-                                              GetParameter(1),
-                                              static_cast<HValue*>(NULL),
-                                              FAST_ELEMENTS);
+  HInstruction* allocation_site = Add<HLoadKeyed>(GetParameter(0),
+                                                  GetParameter(1),
+ static_cast<HValue*>(NULL),
+                                                  FAST_ELEMENTS);

   IfBuilder checker(this);
-  checker.IfNot<HCompareObjectEqAndBranch, HValue*>(boilerplate,
+  checker.IfNot<HCompareObjectEqAndBranch, HValue*>(allocation_site,
                                                     undefined);
   checker.And();

+  HObjectAccess access = HObjectAccess::ForAllocationSiteTransitionInfo();
+ HInstruction* boilerplate = Add<HLoadNamedField>(allocation_site, access);
+
int size = JSObject::kHeaderSize + casted_stub()->length() * kPointerSize;
+  int object_size = size;
+  bool track_allocation_site =
+      (casted_stub()->allocation_site_mode() == TRACK_ALLOCATION_SITE);
+  if (track_allocation_site) {
+    size += AllocationMemento::kSize;
+  }
+
   HValue* boilerplate_map = Add<HLoadNamedField>(
       boilerplate, HObjectAccess::ForMap());
   HValue* boilerplate_size = Add<HLoadNamedField>(
       boilerplate_map, HObjectAccess::ForMapInstanceSize());
-  HValue* size_in_words = Add<HConstant>(size >> kPointerSizeLog2);
+  HValue* size_in_words = Add<HConstant>(object_size >> kPointerSizeLog2);
   checker.If<HCompareNumericAndBranch>(boilerplate_size,
                                        size_in_words, Token::EQ);
   checker.Then();
@@ -461,12 +471,17 @@ HValue* CodeStubGraphBuilder<FastCloneShallowObjectStub>::BuildCodeStub() {
   HInstruction* object = Add<HAllocate>(size_in_bytes, HType::JSObject(),
       isolate()->heap()->GetPretenureMode(), JS_OBJECT_TYPE);

-  for (int i = 0; i < size; i += kPointerSize) {
+  for (int i = 0; i < object_size; i += kPointerSize) {
     HObjectAccess access = HObjectAccess::ForJSObjectOffset(i);
     Add<HStoreNamedField>(object, access,
                           Add<HLoadNamedField>(boilerplate, access));
   }

+  ASSERT(track_allocation_site || (size == object_size));
+  if (track_allocation_site) {
+    BuildCreateAllocationMemento(object, object_size, allocation_site);
+  }
+
   environment()->Push(object);
   checker.ElseDeopt("Uninitialized boilerplate in fast clone");
   checker.End();
Index: src/code-stubs.h
diff --git a/src/code-stubs.h b/src/code-stubs.h
index d2101ae293b6cee60ef3ca597bc483ab9b4d18ba..2fadce35a0561d6d427689cc716f85bd62c59713 100644
--- a/src/code-stubs.h
+++ b/src/code-stubs.h
@@ -673,13 +673,18 @@ class FastCloneShallowObjectStub : public HydrogenCodeStub {
   // Maximum number of properties in copied object.
   static const int kMaximumClonedProperties = 6;

-  explicit FastCloneShallowObjectStub(int length)
-      : length_(length) {
+  FastCloneShallowObjectStub(AllocationSiteMode allocation_site_mode,
+                             int length)
+      : allocation_site_mode_(allocation_site_mode),
+        length_(length) {
     ASSERT_GE(length_, 0);
     ASSERT_LE(length_, kMaximumClonedProperties);
   }

   int length() const { return length_; }
+  AllocationSiteMode allocation_site_mode() const {
+    return allocation_site_mode_;
+  }

   virtual Handle<Code> GenerateCode(Isolate* isolate);

@@ -688,10 +693,20 @@ class FastCloneShallowObjectStub : public HydrogenCodeStub {
       CodeStubInterfaceDescriptor* descriptor);

  private:
+  AllocationSiteMode allocation_site_mode_;
   int length_;

+ class AllocationSiteModeBits: public BitField<AllocationSiteMode, 0, 1> {};
+  class LengthBits: public BitField<int, 1, 4> {};
+  // Ensure data fits within available bits.
+  STATIC_ASSERT(LAST_ALLOCATION_SITE_MODE == 1);
+  STATIC_ASSERT(kMaximumClonedProperties < 16);
+
   Major MajorKey() { return FastCloneShallowObject; }
-  int NotMissMinorKey() { return length_; }
+  int NotMissMinorKey() {
+    return AllocationSiteModeBits::encode(allocation_site_mode_)
+        | LengthBits::encode(length_);
+  }

   DISALLOW_COPY_AND_ASSIGN(FastCloneShallowObjectStub);
 };
Index: src/hydrogen.cc
diff --git a/src/hydrogen.cc b/src/hydrogen.cc
index 99687caf91e9963727301762e6ce2d2f61af1974..1d129d5e245d1f3145f1b74df5363c5bf7be82c3 100644
--- a/src/hydrogen.cc
+++ b/src/hydrogen.cc
@@ -4335,9 +4335,18 @@ void HOptimizedGraphBuilder::VisitObjectLiteral(ObjectLiteral* expr) {

   // Check whether to use fast or slow deep-copying for boilerplate.
   int max_properties = kMaxFastLiteralProperties;
-  Handle<Object> boilerplate(closure->literals()->get(
-      expr->literal_index()), isolate());
-  if (boilerplate->IsJSObject() &&
+ Handle<Object> literals_cell(closure->literals()->get(expr->literal_index()),
+                               isolate());
+  Handle<AllocationSite> site;
+  Handle<Object> boilerplate;
+  if (!literals_cell->IsUndefined()) {
+    // Retrieve the boilerplate
+    ASSERT(literals_cell->IsAllocationSite());
+    site = Handle<AllocationSite>::cast(literals_cell);
+    boilerplate = Handle<Object>(site->transition_info(), isolate());
+  }
+
+  if (!boilerplate.is_null() &&
       IsFastLiteral(Handle<JSObject>::cast(boilerplate),
                     kMaxFastLiteralDepth,
                     &max_properties)) {
Index: src/ia32/full-codegen-ia32.cc
diff --git a/src/ia32/full-codegen-ia32.cc b/src/ia32/full-codegen-ia32.cc
index d284f53ed603bbb696bdb0be0537b8f796c1b5ca..aba5c575a6ca62f9eff0036c633123bd07a124f4 100644
--- a/src/ia32/full-codegen-ia32.cc
+++ b/src/ia32/full-codegen-ia32.cc
@@ -1601,7 +1601,8 @@ void FullCodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) {
     __ mov(ebx, Immediate(Smi::FromInt(expr->literal_index())));
     __ mov(ecx, Immediate(constant_properties));
     __ mov(edx, Immediate(Smi::FromInt(flags)));
-    FastCloneShallowObjectStub stub(properties_count);
+    FastCloneShallowObjectStub stub(DONT_TRACK_ALLOCATION_SITE,
+                                    properties_count);
     __ CallStub(&stub);
   }

Index: src/runtime.cc
diff --git a/src/runtime.cc b/src/runtime.cc
index 26dc36d5300fc44e3ca094389a9d05b2a2f20913..f88b1980d362a56b14e3d613d106154a7d8b3733 100644
--- a/src/runtime.cc
+++ b/src/runtime.cc
@@ -486,16 +486,24 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateObjectLiteral) {
   bool has_function_literal = (flags & ObjectLiteral::kHasFunction) != 0;

   // Check if boilerplate exists. If not, create it first.
-  Handle<Object> boilerplate(literals->get(literals_index), isolate);
-  if (*boilerplate == isolate->heap()->undefined_value()) {
+  Handle<Object> literal_site(literals->get(literals_index), isolate);
+  Handle<AllocationSite> site;
+  Handle<Object> boilerplate;
+  if (*literal_site == isolate->heap()->undefined_value()) {
     boilerplate = CreateObjectLiteralBoilerplate(isolate,
                                                  literals,
                                                  constant_properties,
                                                  should_have_fast_elements,
                                                  has_function_literal);
     RETURN_IF_EMPTY_HANDLE(isolate, boilerplate);
+    site = isolate->factory()->NewAllocationSite();
+    site->set_transition_info(*boilerplate);
+
     // Update the functions literal and return the boilerplate.
-    literals->set(literals_index, *boilerplate);
+    literals->set(literals_index, *site);
+  } else {
+    site = Handle<AllocationSite>::cast(literal_site);
+ boilerplate = Handle<JSObject>(JSObject::cast(site->transition_info()));
   }

Handle<Object> copy = JSObject::DeepCopy(Handle<JSObject>::cast(boilerplate));
Index: src/x64/full-codegen-x64.cc
diff --git a/src/x64/full-codegen-x64.cc b/src/x64/full-codegen-x64.cc
index 20c56226e8cca27078e518d32fb357ecd1e5b49b..1795bd76a68025bf6fb71f67fe9a936db08ba3a8 100644
--- a/src/x64/full-codegen-x64.cc
+++ b/src/x64/full-codegen-x64.cc
@@ -1624,7 +1624,8 @@ void FullCodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) {
     __ Move(rbx, Smi::FromInt(expr->literal_index()));
     __ Move(rcx, constant_properties);
     __ Move(rdx, Smi::FromInt(flags));
-    FastCloneShallowObjectStub stub(properties_count);
+    FastCloneShallowObjectStub stub(DONT_TRACK_ALLOCATION_SITE,
+                                    properties_count);
     __ CallStub(&stub);
   }



--
--
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/groups/opt_out.

Reply via email to