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

Unified Diff: test/mjsunit/array-constructor-feedback.js

Issue 702243003: Basic array capacity feedback via allocation sites. Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Update. Created 6 years, 1 month 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/runtime/runtime.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/array-constructor-feedback.js
diff --git a/test/mjsunit/array-constructor-feedback.js b/test/mjsunit/array-constructor-feedback.js
index c2c1a1842f7d580800bbed37b62527f45f1454b1..6878e80bf2f281bcc5e4768c31c1c714d50271a3 100644
--- a/test/mjsunit/array-constructor-feedback.js
+++ b/test/mjsunit/array-constructor-feedback.js
@@ -62,6 +62,7 @@ function assertKind(expected, obj, name_opt) {
assertEquals(expected, getKind(obj), name_opt);
}
+
// Test: If a call site goes megamorphic, it retains the ability to
// use allocation site feedback (if FLAG_allocation_site_pretenuring
// is on).
@@ -217,3 +218,52 @@ function assertKind(expected, obj, name_opt) {
assertFalse(isHoley(a));
}
})();
+
+
+// Test: verify that elements capacity feedback works
+(function() {
+ // It works for optimized functions with a no-argument array call.
+ function foo() { return new Array(); }
+ a = foo();
+ a.push(1, 2, 3, 4, 5, 6);
+ assertEquals(25, %GetElementsCapacity(a));
+ %OptimizeFunctionOnNextCall(foo);
+ b = foo();
+ assertEquals(25, %GetElementsCapacity(b));
+
+ // It works for optimized functions with a constant argument array call.
+ function bar() { return new Array(1); }
+ a = bar();
+ a.push(1, 2, 3, 4, 5, 6);
+ assertEquals(26, %GetElementsCapacity(a));
+ %OptimizeFunctionOnNextCall(bar);
+ b = bar();
+ assertEquals(26, %GetElementsCapacity(b));
+
+ // It doesn't work for functions with a non-constant length for array.
+ function nonconst(l) { return new Array(l); }
+ a = nonconst(1);
+ a.push(1, 2, 3, 4, 5, 6);
+ assertEquals(26, %GetElementsCapacity(a));
+ %OptimizeFunctionOnNextCall(nonconst);
+ b = nonconst(3);
+ assertEquals(3, %GetElementsCapacity(b));
+
+ // It doesn't work for multiple arguments to the array constructor.
+ function some_args() { return new Array(1, 2, 3); }
+ a = some_args();
+ a.push(1, 2, 3, 4, 5, 6);
+ assertEquals(29, %GetElementsCapacity(a));
+ %OptimizeFunctionOnNextCall(some_args);
+ b = some_args();
+ assertEquals(3, %GetElementsCapacity(b));
+
+ // It doesn't work for literals.
+ function with_literal() { var a = [1,2]; return a; }
+ a = with_literal();
+ a.push(1, 2, 3, 4, 5, 6);
+ assertEquals(28, %GetElementsCapacity(a));
+ %OptimizeFunctionOnNextCall(with_literal);
+ b = with_literal();
+ assertEquals(0, %GetElementsCapacity(b));
+})();
« no previous file with comments | « src/runtime/runtime.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698