Reviewers: Michael Starzinger,

Description:
Short-circuit embedded cons strings.

[email protected]
BUG=

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

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

Affected files:
  M src/hydrogen-instructions.cc
  M src/objects-visiting-inl.h
  A + test/mjsunit/regress/regress-embedded-cons-string.js


Index: src/hydrogen-instructions.cc
diff --git a/src/hydrogen-instructions.cc b/src/hydrogen-instructions.cc
index 170f5eda6c51d8eb60b137eb6f8c275b5d7d7a85..78f351ab8ca282ca2450e0937915234c0a1564fa 100644
--- a/src/hydrogen-instructions.cc
+++ b/src/hydrogen-instructions.cc
@@ -3323,7 +3323,7 @@ HInstruction* HStringAdd::New(
     HConstant* c_right = HConstant::cast(right);
     HConstant* c_left = HConstant::cast(left);
     if (c_left->HasStringValue() && c_right->HasStringValue()) {
-      Factory* factory = Isolate::Current()->factory();
+      Factory* factory = zone->isolate()->factory();
return new(zone) HConstant(factory->NewConsString(c_left->StringValue(), c_right->StringValue()),
                                  Representation::Tagged());
Index: src/objects-visiting-inl.h
diff --git a/src/objects-visiting-inl.h b/src/objects-visiting-inl.h
index 6c3c9d44fe318d77c141a68dc6d562d86563aceb..ccd76a0fd63df3623c95fdda89dfc1ee288c890e 100644
--- a/src/objects-visiting-inl.h
+++ b/src/objects-visiting-inl.h
@@ -233,8 +233,12 @@ template<typename StaticVisitor>
 void StaticMarkingVisitor<StaticVisitor>::VisitEmbeddedPointer(
     Heap* heap, RelocInfo* rinfo) {
   ASSERT(rinfo->rmode() == RelocInfo::EMBEDDED_OBJECT);
-  ASSERT(!rinfo->target_object()->IsConsString());
   HeapObject* object = HeapObject::cast(rinfo->target_object());
+  if (object->IsConsString() && ConsString::cast(object)->IsFlat()) {
+    // Short-circuit flattened cons-strings.
+    object = ConsString::cast(object)->first();
+    rinfo->set_target_object(object);
+  }
   if (!FLAG_weak_embedded_maps_in_optimized_code || !FLAG_collect_maps ||
       rinfo->host()->kind() != Code::OPTIMIZED_FUNCTION ||
       !object->IsMap() || !Map::cast(object)->CanTransition()) {
Index: test/mjsunit/regress/regress-embedded-cons-string.js
diff --git a/test/mjsunit/compiler/parallel-proto-change.js b/test/mjsunit/regress/regress-embedded-cons-string.js
similarity index 71%
copy from test/mjsunit/compiler/parallel-proto-change.js
copy to test/mjsunit/regress/regress-embedded-cons-string.js
index aa1ac6de90952c3a0f5e2e3ea28c4f1d1dcdd9f1..5810bf01f3b1f3a93267674e3a37a84ee9d44c94 100644
--- a/test/mjsunit/compiler/parallel-proto-change.js
+++ b/test/mjsunit/regress/regress-embedded-cons-string.js
@@ -25,26 +25,25 @@
 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

-// Flags: --allow-natives-syntax
-// Flags: --parallel-recompilation --parallel-recompilation-delay=50
+// Flags: --fold-constants --nodead-code-elimination
+// Flags: --expose-gc --allow-natives-syntax
+// Flags: --parallel-recompilation --parallel-recompilation-delay=200

-function assertUnoptimized(fun) {
-  assertTrue(%GetOptimizationStatus(fun) != 1);
+function f() {
+ return "abcdefghijklmn" + "123456789"; // Constant-folds to a cons string.
 }

-function f(foo) { return foo.bar(); }
+f();
+f();
+%OptimizeFunctionOnNextCall(f, "parallel");
+f();   // Trigger optimization in the background.
+gc();  // Tenure cons string.
+%CompleteOptimization(f);  // Compilation embeds tenured cons string.

-var o = {};
-o.__proto__ = { __proto__: { bar: function() { return 1; } } };
+gc();  // Visit embedded cons string during mark compact.
+assertEquals("abcdefghijklmn123456789", f());
+%FlattenString(f());
+gc();  // Short circuit flattened cons string during visit.
+assertEquals("abcdefghijklmn123456789", f());

-assertEquals(1, f(o));
-assertEquals(1, f(o));

-%OptimizeFunctionOnNextCall(f, "parallel");
-assertEquals(1, f(o));     // Trigger optimization.
-assertUnoptimized(f);      // Optimization not yet done.
-// Change the prototype chain during optimization to trigger map invalidation.
-o.__proto__.__proto__ = { bar: function() { return 2; } };
-%CompleteOptimization(f);  // Conclude optimization with...
-assertUnoptimized(f);      // ... bailing out due to map dependency.
-assertEquals(2, f(o));


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