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

Unified Diff: test/mjsunit/compiler/slice-call-arguments.js

Issue 327173002: Optimize various forms of slice.call(arguments, ...) (Closed) Base URL: https://github.com/v8/v8.git@master
Patch Set: Created 6 years, 6 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/runtime.cc ('k') | test/mjsunit/runtime-gen/disableoptimisticoptimizations.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/compiler/slice-call-arguments.js
diff --git a/test/mjsunit/compiler/slice-call-arguments.js b/test/mjsunit/compiler/slice-call-arguments.js
new file mode 100644
index 0000000000000000000000000000000000000000..ae25909f461f5b4e0b04bb627cf437b553b94dfd
--- /dev/null
+++ b/test/mjsunit/compiler/slice-call-arguments.js
@@ -0,0 +1,203 @@
+// Copyright 2014 the V8 project authors. All rights reserved.
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following
+// disclaimer in the documentation and/or other materials provided
+// with the distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived
+// from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (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 --noalways-opt
+
+// Scope so that slice has no type feedback
+(function() {
+ var slice = [].slice;
+ var not_slice = [].shift;
+
+ function makeCopier(lower, upper) {
+ switch (arguments.length) {
+ case 2:
+ var ret = new Function(
+ "return [].slice.call(arguments, lower, upper);"
+ .replace("lower", lower)
+ .replace("upper", upper));
+ ret.lower = lower;
+ ret.upper = upper;
+ return ret;
+ case 1:
+ var ret = new Function(
+ "return [].slice.call(arguments, lower);"
+ .replace("lower", lower));
+ ret.lower = lower;
+ return ret;
+ }
+ }
+
+ function verify(fn, args) {
+ fn(); fn();
+ %OptimizeFunctionOnNextCall(fn);
+ fn();
+ fn();
+ assertOptimized(fn);
+ assertArrayEquals(fn(), []);
+ var returned_value = fn.apply(void 0, args);
+ assertTrue(Array.isArray(returned_value));
+ var lower = fn.lower;
+ var upper = fn.upper;
+ var expected = args.slice(lower, upper);
+ assertArrayEquals(expected, returned_value);
+ }
+
+ function plainCopy() {
+ return slice.call(arguments);
+ }
+
+ verify(plainCopy, [1,2,3]);
+ verify(plainCopy, []);
+
+ var arr = [1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3];
+ verify(makeCopier(-1), arr);
+ verify(makeCopier(1), arr);
+ verify(makeCopier(-4, -10), arr);
+ verify(makeCopier(3, -2), arr);
+ verify(makeCopier(-5), arr);
+ verify(makeCopier(3, -1), arr);
+ verify(makeCopier(0, 0), arr);
+ verify(makeCopier(1, 0), arr);
+ verify(makeCopier(0, 1), arr);
+ verify(makeCopier(-1, 1), arr);
+ verify(makeCopier(-100), arr);
+ verify(makeCopier(-100, -100), arr);
+ verify(makeCopier(-10, -5), arr);
+ verify(makeCopier(10, -5), arr);
+ verify(makeCopier(-123, 72), arr);
+ verify(makeCopier(-1, -1), arr);
+ verify(makeCopier(3, -1), arr);
+
+ var arr = [1, 2, 3];
+
+ verify(makeCopier(-1), arr);
+ verify(makeCopier(1), arr);
+ verify(makeCopier(-4, -10), arr);
+ verify(makeCopier(3, -2), arr);
+ verify(makeCopier(-5), arr);
+ verify(makeCopier(3, -1), arr);
+ verify(makeCopier(0, 0), arr);
+ verify(makeCopier(1, 0), arr);
+ verify(makeCopier(0, 1), arr);
+ verify(makeCopier(-1, 1), arr);
+ verify(makeCopier(-100), arr);
+ verify(makeCopier(-100, -100), arr);
+ verify(makeCopier(-10, -5), arr);
+ verify(makeCopier(10, -5), arr);
+ verify(makeCopier(-123, 72), arr);
+ verify(makeCopier(-1, -1), arr);
+ verify(makeCopier(3, -1), arr);
+
+ var arr = [];
+
+ verify(makeCopier(-1), arr);
+ verify(makeCopier(1), arr);
+ verify(makeCopier(-4, -10), arr);
+ verify(makeCopier(3, -2), arr);
+ verify(makeCopier(-5), arr);
+ verify(makeCopier(3, -1), arr);
+ verify(makeCopier(0, 0), arr);
+ verify(makeCopier(1, 0), arr);
+ verify(makeCopier(0, 1), arr);
+ verify(makeCopier(-1, 1), arr);
+ verify(makeCopier(-100), arr);
+ verify(makeCopier(-100, -100), arr);
+ verify(makeCopier(-10, -5), arr);
+ verify(makeCopier(10, -5), arr);
+ verify(makeCopier(-123, 72), arr);
+ verify(makeCopier(-1, -1), arr);
+ verify(makeCopier(3, -1), arr);
+
+ function calls_not_slice() {
+ return not_slice.call(arguments);
+ }
+
+ calls_not_slice();
+ calls_not_slice();
+ %OptimizeFunctionOnNextCall(calls_not_slice);
+ calls_not_slice();
+ assertUnoptimized(calls_not_slice);
+ calls_not_slice();
+ calls_not_slice();
+ %OptimizeFunctionOnNextCall(calls_not_slice);
+ calls_not_slice();
+ assertUnoptimized(calls_not_slice);
+
+ function calls_slice_that_changes() {
+ return slice.call(arguments);
+ }
+
+ calls_slice_that_changes();
+ calls_slice_that_changes();
+ %OptimizeFunctionOnNextCall(calls_slice_that_changes);
+ calls_slice_that_changes();
+ assertOptimized(calls_slice_that_changes);
+
+ slice = function(){};
+ calls_slice_that_changes();
+ assertUnoptimized(calls_slice_that_changes);
+ calls_slice_that_changes();
+ calls_slice_that_changes();
+ %OptimizeFunctionOnNextCall(calls_slice_that_changes);
+ calls_slice_that_changes();
+ assertUnoptimized(calls_slice_that_changes);
+
+ slice = [].slice;
+ function lotsOfArguments() {
+ return slice.call(arguments);
+ }
+
+ var arr = new Array(100000);
+ for (var i = 0; i < arr.length; ++i) arr[i] = i;
+
+ assertArrayEquals([1,2,3], lotsOfArguments(1,2,3));
+ assertArrayEquals([1,2,3], lotsOfArguments(1,2,3));
+ %OptimizeFunctionOnNextCall(lotsOfArguments);
+ assertArrayEquals([1,2,3], lotsOfArguments(1,2,3));
+ assertOptimized(lotsOfArguments);
+ var result = lotsOfArguments.apply(void 0, arr);
+ assertArrayEquals(arr, result);
+ assertUnoptimized(lotsOfArguments);
+
+
+ var o = {
+ callsInline: function caller() {
+ return this.toBeInlined(1, 2, 3, 4, 5);
+ },
+ toBeInlined: function callee() {
+ return slice.call(arguments);
+ }
+ };
+
+ assertArrayEquals([1,2,3,4,5], o.callsInline());
+ assertArrayEquals([1,2,3,4,5], o.callsInline());
+ %OptimizeFunctionOnNextCall(o.callsInline);
+ assertArrayEquals([1,2,3,4,5], o.callsInline());
+ assertOptimized(o.callsInline);
+ assertArrayEquals([1,2,3,4,5], o.callsInline());
+
+})();
« no previous file with comments | « src/runtime.cc ('k') | test/mjsunit/runtime-gen/disableoptimisticoptimizations.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698