Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(692)

Unified Diff: test/mjsunit/field-type-tracking.js

Issue 238773002: Reland "Track field types.". (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Properly handlified... Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/x64/stub-cache-x64.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/field-type-tracking.js
diff --git a/test/mjsunit/field-type-tracking.js b/test/mjsunit/field-type-tracking.js
new file mode 100644
index 0000000000000000000000000000000000000000..8da4ed56857378065eaaf1b87108ca470c9ac49d
--- /dev/null
+++ b/test/mjsunit/field-type-tracking.js
@@ -0,0 +1,149 @@
+// Copyright 2014 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Flags: --allow-natives-syntax --nostress-opt --track-field-types
+
+(function() {
+ var o = { text: "Hello World!" };
+ function A() {
+ this.a = o;
+ }
+ function readA(x) {
+ return x.a;
+ }
+ var a = new A();
+ assertUnoptimized(readA);
+ readA(a); readA(a); readA(a);
+ %OptimizeFunctionOnNextCall(readA);
+ assertEquals(readA(a), o);
+ assertOptimized(readA);
+
+ var b = new A();
+ b.b = o;
+ assertEquals(readA(b), o);
+ assertUnoptimized(readA);
+ %OptimizeFunctionOnNextCall(readA);
+ assertEquals(readA(a), o);
+ assertOptimized(readA);
+ assertEquals(readA(a), o);
+ assertEquals(readA(b), o);
+ assertOptimized(readA);
+
+ function readAFromB(x) {
+ return x.a;
+ }
+ assertUnoptimized(readAFromB);
+ readAFromB(b); readAFromB(b); readAFromB(b);
+ %OptimizeFunctionOnNextCall(readAFromB);
+ assertEquals(readAFromB(b), o);
+ assertOptimized(readAFromB);
+
+ var c = new A();
+ c.c = o;
+ assertOptimized(readA);
+ assertOptimized(readAFromB);
+ c.a = [1];
+ assertUnoptimized(readA);
+ assertUnoptimized(readAFromB);
+ assertEquals(readA(a), o);
+ assertEquals(readA(b), o);
+ assertEquals(readA(c), [1]);
+ assertEquals(readAFromB(b), o);
+
+ %OptimizeFunctionOnNextCall(readA);
+ assertEquals(readA(a), o);
+ %OptimizeFunctionOnNextCall(readAFromB);
+ assertEquals(readAFromB(b), o);
+ assertOptimized(readA);
+ a.a = [1];
+ assertEquals(readA(a), [1]);
+ assertEquals(readA(b), o);
+ assertEquals(readA(c), [1]);
+ assertOptimized(readA);
+ b.a = [1];
+ assertEquals(readA(a), [1]);
+ assertEquals(readA(b), [1]);
+ assertEquals(readA(c), [1]);
+ assertOptimized(readA);
+ assertOptimized(readAFromB);
+})();
+
+(function() {
+ function A() { this.x = 0; }
+ A.prototype = {y: 20};
+ function B(o) { return o.a.y; }
+ function C() { this.a = new A(); }
+
+ B(new C());
+ B(new C());
+ %OptimizeFunctionOnNextCall(B);
+ var c = new C();
+ assertEquals(20, B(c));
+ assertOptimized(B);
+ c.a.y = 10;
+ assertEquals(10, B(c));
+ assertUnoptimized(B);
+
+ var c = new C();
+ %OptimizeFunctionOnNextCall(B);
+ assertEquals(20, B(c));
+ assertOptimized(B);
+ c.a.y = 30;
+ assertEquals(30, B(c));
+ assertOptimized(B);
+})();
+
+(function() {
+ var x = new Object();
+ x.a = 1 + "Long string that results in a cons string";
+ x = JSON.parse('{"a":"Short"}');
+})();
+
+(function() {
+ var x = {y: {z: 1}};
+ x.y.z = 1.1;
+})();
+
+(function() {
+ function Foo(x) { this.x = x; }
+ var f1 = new Foo({x: 1});
+ var f2 = new Foo({x: 2});
+ var f3 = new Foo({x: 3});
+ function readX(f) { return f.x.x; }
+ assertEquals(readX(f1), 1);
+ assertEquals(readX(f2), 2);
+ assertUnoptimized(readX);
+ %OptimizeFunctionOnNextCall(readX);
+ assertEquals(readX(f3), 3);
+ assertOptimized(readX);
+ function writeX(f, x) { f.x = x; }
+ writeX(f1, {x: 11});
+ writeX(f2, {x: 22});
+ assertUnoptimized(writeX);
+ assertEquals(readX(f1), 11);
+ assertEquals(readX(f2), 22);
+ assertOptimized(readX);
+ %OptimizeFunctionOnNextCall(writeX);
+ writeX(f3, {x: 33});
+ assertEquals(readX(f3), 33);
+ assertOptimized(readX);
+ assertOptimized(writeX);
+ function addY(f, y) { f.y = y; }
+ writeX(f1, {a: "a"});
+ assertUnoptimized(readX);
+ assertUnoptimized(writeX);
+})();
+
+(function() {
+ function Narf(x) { this.x = x; }
+ var f1 = new Narf(1);
+ var f2 = new Narf(2);
+ var f3 = new Narf(3);
+ function baz(f, y) { f.y = y; }
+ baz(f1, {y: 9});
+ baz(f2, {y: 9});
+ %OptimizeFunctionOnNextCall(baz);
+ baz(f3, {a: -1});
+ assertUnoptimized(baz);
+})();
« no previous file with comments | « src/x64/stub-cache-x64.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698