Reviewers: mvstanton, jochen,

Description:
Pretenuring decision of outermost literal is propagated to inner literals.

Literals should stay together to simplify allocation folding. This CL takes the pretenuring information from the outermost literal and applies it to the inner
liberals.

BUG=chromium:514721
LOG=n

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

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

Affected files (+32, -36 lines):
  M src/hydrogen.h
  M src/hydrogen.cc


Index: src/hydrogen.cc
diff --git a/src/hydrogen.cc b/src/hydrogen.cc
index 5e02c32cfb79d273e2f2a8c46c8fa155788f8195..aef7883b08c28439ebf5029a9eaea7df896f46f9 100644
--- a/src/hydrogen.cc
+++ b/src/hydrogen.cc
@@ -5734,7 +5734,7 @@ void HOptimizedGraphBuilder::VisitObjectLiteral(ObjectLiteral* expr) {
       IsFastLiteral(boilerplate, kMaxFastLiteralDepth, &max_properties)) {
     AllocationSiteUsageContext site_context(isolate(), site, false);
     site_context.EnterNewScope();
-    literal = BuildFastLiteral(boilerplate, &site_context);
+    literal = BuildFastLiteral(boilerplate, site, &site_context);
     site_context.ExitScope(site, boilerplate);
   } else {
     NoObservableSideEffectsScope no_effects(this);
@@ -5899,7 +5899,7 @@ void HOptimizedGraphBuilder::VisitArrayLiteral(ArrayLiteral* expr) {
                     &max_properties)) {
     AllocationSiteUsageContext site_context(isolate(), site, false);
     site_context.EnterNewScope();
-    literal = BuildFastLiteral(boilerplate_object, &site_context);
+    literal = BuildFastLiteral(boilerplate_object, site, &site_context);
     site_context.ExitScope(site, boilerplate_object);
   } else {
     NoObservableSideEffectsScope no_effects(this);
@@ -11418,6 +11418,7 @@ HInstruction* HOptimizedGraphBuilder::BuildThisFunction() {

 HInstruction* HOptimizedGraphBuilder::BuildFastLiteral(
     Handle<JSObject> boilerplate_object,
+    Handle<AllocationSite> root_allocation_site,
     AllocationSiteUsageContext* site_context) {
   NoObservableSideEffectsScope no_effects(this);
   Handle<Map> initial_map(boilerplate_object->map());
@@ -11429,16 +11430,16 @@ HInstruction* HOptimizedGraphBuilder::BuildFastLiteral( HValue* object_size_constant = Add<HConstant>(initial_map->instance_size());

   PretenureFlag pretenure_flag = NOT_TENURED;
-  Handle<AllocationSite> current_site(*site_context->current(), isolate());
   if (FLAG_allocation_site_pretenuring) {
-    pretenure_flag = current_site->GetPretenureMode();
-    top_info()->dependencies()->AssumeTenuringDecision(current_site);
+    pretenure_flag = root_allocation_site->GetPretenureMode();
+ top_info()->dependencies()->AssumeTenuringDecision(root_allocation_site);
   }
-
+  Handle<AllocationSite> current_site(*site_context->current(), isolate());
   top_info()->dependencies()->AssumeTransitionStable(current_site);

-  HInstruction* object = Add<HAllocate>(
- object_size_constant, type, pretenure_flag, instance_type, current_site);
+  HInstruction* object =
+ Add<HAllocate>(object_size_constant, type, pretenure_flag, instance_type,
+                     root_allocation_site);

   // If allocation folding reaches Page::kMaxRegularHeapObjectSize the
   // elements array may not get folded into the object. Hence, we set the
@@ -11480,9 +11481,9 @@ HInstruction* HOptimizedGraphBuilder::BuildFastLiteral(
         ? FIXED_DOUBLE_ARRAY_TYPE : FIXED_ARRAY_TYPE;
     object_elements =
         Add<HAllocate>(object_elements_size, HType::HeapObject(),
-                       pretenure_flag, instance_type, current_site);
+ pretenure_flag, instance_type, root_allocation_site);
     BuildEmitElements(boilerplate_object, elements, object_elements,
-                      site_context);
+                      root_allocation_site, site_context);
     Add<HStoreNamedField>(object, HObjectAccess::ForElementsPointer(),
                           object_elements);
   } else {
@@ -11496,8 +11497,8 @@ HInstruction* HOptimizedGraphBuilder::BuildFastLiteral(
   // Copy in-object properties.
   if (initial_map->NumberOfFields() != 0 ||
       initial_map->unused_property_fields() > 0) {
-    BuildEmitInObjectProperties(boilerplate_object, object, site_context,
-                                pretenure_flag);
+    BuildEmitInObjectProperties(boilerplate_object, object,
+                                root_allocation_site, site_context);
   }
   return object;
 }
@@ -11533,10 +11534,9 @@ void HOptimizedGraphBuilder::BuildEmitObjectHeader(


 void HOptimizedGraphBuilder::BuildEmitInObjectProperties(
-    Handle<JSObject> boilerplate_object,
-    HInstruction* object,
-    AllocationSiteUsageContext* site_context,
-    PretenureFlag pretenure_flag) {
+    Handle<JSObject> boilerplate_object, HInstruction* object,
+    Handle<AllocationSite> root_allocation_site,
+    AllocationSiteUsageContext* site_context) {
   Handle<Map> boilerplate_map(boilerplate_object->map());
Handle<DescriptorArray> descriptors(boilerplate_map->instance_descriptors());
   int limit = boilerplate_map->NumberOfOwnDescriptors();
@@ -11571,7 +11571,7 @@ void HOptimizedGraphBuilder::BuildEmitInObjectProperties(
       Handle<JSObject> value_object = Handle<JSObject>::cast(value);
       Handle<AllocationSite> current_site = site_context->EnterNewScope();
       HInstruction* result =
-          BuildFastLiteral(value_object, site_context);
+ BuildFastLiteral(value_object, root_allocation_site, site_context);
       site_context->ExitScope(current_site, value_object);
       Add<HStoreNamedField>(object, access, result);
     } else {
@@ -11581,13 +11581,9 @@ void HOptimizedGraphBuilder::BuildEmitInObjectProperties(
       if (representation.IsDouble()) {
         // Allocate a HeapNumber box and store the value into it.
         HValue* heap_number_constant = Add<HConstant>(HeapNumber::kSize);
-        // This heap number alloc does not have a corresponding
-        // AllocationSite. That is okay because
- // 1) it's a child object of another object with a valid allocation site
-        // 2) we can just use the mode of the parent object for pretenuring
-        HInstruction* double_box =
-            Add<HAllocate>(heap_number_constant, HType::HeapObject(),
-                pretenure_flag, MUTABLE_HEAP_NUMBER_TYPE);
+        HInstruction* double_box = Add<HAllocate>(
+            heap_number_constant, HType::HeapObject(),
+ root_allocation_site->GetPretenureMode(), MUTABLE_HEAP_NUMBER_TYPE);
         AddStoreMapConstant(double_box,
             isolate()->factory()->mutable_heap_number_map());
         // Unwrap the mutable heap number from the boilerplate.
@@ -11624,9 +11620,8 @@ void HOptimizedGraphBuilder::BuildEmitInObjectProperties(


 void HOptimizedGraphBuilder::BuildEmitElements(
-    Handle<JSObject> boilerplate_object,
-    Handle<FixedArrayBase> elements,
-    HValue* object_elements,
+    Handle<JSObject> boilerplate_object, Handle<FixedArrayBase> elements,
+    HValue* object_elements, Handle<AllocationSite> root_allocation_site,
     AllocationSiteUsageContext* site_context) {
   ElementsKind kind = boilerplate_object->map()->elements_kind();
   int elements_length = elements->length();
@@ -11637,7 +11632,7 @@ void HOptimizedGraphBuilder::BuildEmitElements(
   if (elements->IsFixedDoubleArray()) {
     BuildEmitFixedDoubleArray(elements, kind, object_elements);
   } else if (elements->IsFixedArray()) {
-    BuildEmitFixedArray(elements, kind, object_elements,
+ BuildEmitFixedArray(elements, kind, object_elements, root_allocation_site,
                         site_context);
   } else {
     UNREACHABLE();
@@ -11663,9 +11658,8 @@ void HOptimizedGraphBuilder::BuildEmitFixedDoubleArray(


 void HOptimizedGraphBuilder::BuildEmitFixedArray(
-    Handle<FixedArrayBase> elements,
-    ElementsKind kind,
-    HValue* object_elements,
+ Handle<FixedArrayBase> elements, ElementsKind kind, HValue* object_elements,
+    Handle<AllocationSite> root_allocation_site,
     AllocationSiteUsageContext* site_context) {
   HInstruction* boilerplate_elements = Add<HConstant>(elements);
   int elements_length = elements->length();
@@ -11677,7 +11671,7 @@ void HOptimizedGraphBuilder::BuildEmitFixedArray(
       Handle<JSObject> value_object = Handle<JSObject>::cast(value);
       Handle<AllocationSite> current_site = site_context->EnterNewScope();
       HInstruction* result =
-          BuildFastLiteral(value_object, site_context);
+ BuildFastLiteral(value_object, root_allocation_site, site_context);
       site_context->ExitScope(current_site, value_object);
       Add<HStoreKeyed>(object_elements, key_constant, result, kind);
     } else {
Index: src/hydrogen.h
diff --git a/src/hydrogen.h b/src/hydrogen.h
index 33a4912056e16e49bd2cc116a870d03c741e7ce9..6850e45c09ff5c8b0477100483bae143bd948930 100644
--- a/src/hydrogen.h
+++ b/src/hydrogen.h
@@ -2823,6 +2823,7 @@ class HOptimizedGraphBuilder : public HGraphBuilder, public AstVisitor {
   HInstruction* BuildThisFunction();

   HInstruction* BuildFastLiteral(Handle<JSObject> boilerplate_object,
+ Handle<AllocationSite> root_allocation_site,
                                  AllocationSiteUsageContext* site_context);

   void BuildEmitObjectHeader(Handle<JSObject> boilerplate_object,
@@ -2830,21 +2831,22 @@ class HOptimizedGraphBuilder : public HGraphBuilder, public AstVisitor {

   void BuildEmitInObjectProperties(Handle<JSObject> boilerplate_object,
                                    HInstruction* object,
- AllocationSiteUsageContext* site_context,
-                                   PretenureFlag pretenure_flag);
+ Handle<AllocationSite> root_allocation_site, + AllocationSiteUsageContext* site_context);

   void BuildEmitElements(Handle<JSObject> boilerplate_object,
                          Handle<FixedArrayBase> elements,
                          HValue* object_elements,
+                         Handle<AllocationSite> root_allocation_site,
                          AllocationSiteUsageContext* site_context);

   void BuildEmitFixedDoubleArray(Handle<FixedArrayBase> elements,
                                  ElementsKind kind,
                                  HValue* object_elements);

-  void BuildEmitFixedArray(Handle<FixedArrayBase> elements,
-                           ElementsKind kind,
+ void BuildEmitFixedArray(Handle<FixedArrayBase> elements, ElementsKind kind,
                            HValue* object_elements,
+                           Handle<AllocationSite> root_allocation_site,
                            AllocationSiteUsageContext* site_context);

   void AddCheckPrototypeMaps(Handle<JSObject> holder,


--
--
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