Reviewers: mvstanton, Michael Starzinger,

Description:
Clear next map word when folding allocations into js arrays.

BUG=

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

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

Affected files:
  M src/hydrogen-instructions.h
  M src/hydrogen-instructions.cc
  M test/mjsunit/allocation-folding.js


Index: src/hydrogen-instructions.cc
diff --git a/src/hydrogen-instructions.cc b/src/hydrogen-instructions.cc
index b0045b8751b06258f0a241416e54615924ea910f..61eb1a098c58bfe6364a6fbf03c5bbf035e16969 100644
--- a/src/hydrogen-instructions.cc
+++ b/src/hydrogen-instructions.cc
@@ -3209,6 +3209,7 @@ void HAllocate::HandleSideEffectDominator(GVNFlag side_effect,
   // First update the size of the dominator allocate instruction.
   int32_t dominator_size_constant =
       HConstant::cast(dominator_size)->GetInteger32Constant();
+  int32_t object_offset = dominator_size_constant;
   int32_t current_size_constant =
       HConstant::cast(current_size)->GetInteger32Constant();
int32_t new_dominator_size = dominator_size_constant + current_size_constant; @@ -3238,6 +3239,20 @@ void HAllocate::HandleSideEffectDominator(GVNFlag side_effect,
   new_dominator_size_constant->InsertBefore(dominator_allocate_instr);
   dominator_allocate_instr->UpdateSize(new_dominator_size_constant);

+  // TODO(hpayer): This is a short-term hack to make allocation mementos
+  // work again in new space.
+  if (dominator_allocate_instr->type().Equals(HType::JSArray()) &&
+      !dominator_allocate_instr->clear_next_map_word_) {
+    HObjectAccess access =
+        HObjectAccess::ForJSObjectOffset(object_offset);
+    HStoreNamedField* clear_next_map =
+ HStoreNamedField::New(zone, context(), dominator_allocate_instr, access,
+            block->graph()->GetConstantNull());
+    clear_next_map->ClearAllSideEffects();
+    clear_next_map->InsertAfter(dominator_allocate_instr);
+    dominator_allocate_instr->clear_next_map_word_ = true;
+  }
+
 #ifdef VERIFY_HEAP
   if (FLAG_verify_heap) {
     dominator_allocate_instr->MakePrefillWithFiller();
Index: src/hydrogen-instructions.h
diff --git a/src/hydrogen-instructions.h b/src/hydrogen-instructions.h
index 685a5e883cd4085e231cd2d2b2f99c9a8f863dde..d0d5886c8597446cdc698ccc4e970d40caa56805 100644
--- a/src/hydrogen-instructions.h
+++ b/src/hydrogen-instructions.h
@@ -5126,7 +5126,8 @@ class HAllocate V8_FINAL : public HTemplateInstruction<2> {
             HType type,
             PretenureFlag pretenure_flag,
             InstanceType instance_type)
-      : HTemplateInstruction<2>(type) {
+      : HTemplateInstruction<2>(type),
+        clear_next_map_word_(false) {
     SetOperandAt(0, context);
     SetOperandAt(1, size);
     set_representation(Representation::Tagged());
@@ -5145,6 +5146,7 @@ class HAllocate V8_FINAL : public HTemplateInstruction<2> {

   Flags flags_;
   Handle<Map> known_initial_map_;
+  bool clear_next_map_word_;
 };


Index: test/mjsunit/allocation-folding.js
diff --git a/test/mjsunit/allocation-folding.js b/test/mjsunit/allocation-folding.js index fe5fa6d855e5894c2a3f136db2c14a3a865fbe40..f57de11d533f8137ff1ce9e6f8fb98b8af665c39 100644
--- a/test/mjsunit/allocation-folding.js
+++ b/test/mjsunit/allocation-folding.js
@@ -56,7 +56,7 @@ function doubles() {

 doubles(); doubles(); doubles();
 %OptimizeFunctionOnNextCall(doubles);
-var result = doubles();
+result = doubles();

 gc();

@@ -72,8 +72,31 @@ function doubles_int() {

 doubles_int(); doubles_int(); doubles_int();
 %OptimizeFunctionOnNextCall(doubles_int);
-var result = doubles_int();
+result = doubles_int();

 gc();

 assertEquals(result[1], 3.1);
+
+// Test allocation folding of over a branch.
+
+function branch_int(left) {
+  var elem1 = [1, 2];
+  var elem2;
+  if (left) {
+    elem2 = [3, 4];
+  } else {
+    elem2 = [5, 6];
+  }
+  return elem2;
+}
+
+branch_int(1); branch_int(1); branch_int(1);
+%OptimizeFunctionOnNextCall(branch_int);
+result = branch_int(1);
+var result2 = branch_int(0);
+
+gc();
+
+assertEquals(result[1], 4);
+assertEquals(result2[1], 6);


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