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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « src/runtime.cc ('k') | test/mjsunit/runtime-gen/disableoptimisticoptimizations.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28 // Flags: --allow-natives-syntax --noalways-opt
29
30 // Scope so that slice has no type feedback
31 (function() {
32 var slice = [].slice;
33 var not_slice = [].shift;
34
35 function makeCopier(lower, upper) {
36 switch (arguments.length) {
37 case 2:
38 var ret = new Function(
39 "return [].slice.call(arguments, lower, upper);"
40 .replace("lower", lower)
41 .replace("upper", upper));
42 ret.lower = lower;
43 ret.upper = upper;
44 return ret;
45 case 1:
46 var ret = new Function(
47 "return [].slice.call(arguments, lower);"
48 .replace("lower", lower));
49 ret.lower = lower;
50 return ret;
51 }
52 }
53
54 function verify(fn, args) {
55 fn(); fn();
56 %OptimizeFunctionOnNextCall(fn);
57 fn();
58 fn();
59 assertOptimized(fn);
60 assertArrayEquals(fn(), []);
61 var returned_value = fn.apply(void 0, args);
62 assertTrue(Array.isArray(returned_value));
63 var lower = fn.lower;
64 var upper = fn.upper;
65 var expected = args.slice(lower, upper);
66 assertArrayEquals(expected, returned_value);
67 }
68
69 function plainCopy() {
70 return slice.call(arguments);
71 }
72
73 verify(plainCopy, [1,2,3]);
74 verify(plainCopy, []);
75
76 var arr = [1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3];
77 verify(makeCopier(-1), arr);
78 verify(makeCopier(1), arr);
79 verify(makeCopier(-4, -10), arr);
80 verify(makeCopier(3, -2), arr);
81 verify(makeCopier(-5), arr);
82 verify(makeCopier(3, -1), arr);
83 verify(makeCopier(0, 0), arr);
84 verify(makeCopier(1, 0), arr);
85 verify(makeCopier(0, 1), arr);
86 verify(makeCopier(-1, 1), arr);
87 verify(makeCopier(-100), arr);
88 verify(makeCopier(-100, -100), arr);
89 verify(makeCopier(-10, -5), arr);
90 verify(makeCopier(10, -5), arr);
91 verify(makeCopier(-123, 72), arr);
92 verify(makeCopier(-1, -1), arr);
93 verify(makeCopier(3, -1), arr);
94
95 var arr = [1, 2, 3];
96
97 verify(makeCopier(-1), arr);
98 verify(makeCopier(1), arr);
99 verify(makeCopier(-4, -10), arr);
100 verify(makeCopier(3, -2), arr);
101 verify(makeCopier(-5), arr);
102 verify(makeCopier(3, -1), arr);
103 verify(makeCopier(0, 0), arr);
104 verify(makeCopier(1, 0), arr);
105 verify(makeCopier(0, 1), arr);
106 verify(makeCopier(-1, 1), arr);
107 verify(makeCopier(-100), arr);
108 verify(makeCopier(-100, -100), arr);
109 verify(makeCopier(-10, -5), arr);
110 verify(makeCopier(10, -5), arr);
111 verify(makeCopier(-123, 72), arr);
112 verify(makeCopier(-1, -1), arr);
113 verify(makeCopier(3, -1), arr);
114
115 var arr = [];
116
117 verify(makeCopier(-1), arr);
118 verify(makeCopier(1), arr);
119 verify(makeCopier(-4, -10), arr);
120 verify(makeCopier(3, -2), arr);
121 verify(makeCopier(-5), arr);
122 verify(makeCopier(3, -1), arr);
123 verify(makeCopier(0, 0), arr);
124 verify(makeCopier(1, 0), arr);
125 verify(makeCopier(0, 1), arr);
126 verify(makeCopier(-1, 1), arr);
127 verify(makeCopier(-100), arr);
128 verify(makeCopier(-100, -100), arr);
129 verify(makeCopier(-10, -5), arr);
130 verify(makeCopier(10, -5), arr);
131 verify(makeCopier(-123, 72), arr);
132 verify(makeCopier(-1, -1), arr);
133 verify(makeCopier(3, -1), arr);
134
135 function calls_not_slice() {
136 return not_slice.call(arguments);
137 }
138
139 calls_not_slice();
140 calls_not_slice();
141 %OptimizeFunctionOnNextCall(calls_not_slice);
142 calls_not_slice();
143 assertUnoptimized(calls_not_slice);
144 calls_not_slice();
145 calls_not_slice();
146 %OptimizeFunctionOnNextCall(calls_not_slice);
147 calls_not_slice();
148 assertUnoptimized(calls_not_slice);
149
150 function calls_slice_that_changes() {
151 return slice.call(arguments);
152 }
153
154 calls_slice_that_changes();
155 calls_slice_that_changes();
156 %OptimizeFunctionOnNextCall(calls_slice_that_changes);
157 calls_slice_that_changes();
158 assertOptimized(calls_slice_that_changes);
159
160 slice = function(){};
161 calls_slice_that_changes();
162 assertUnoptimized(calls_slice_that_changes);
163 calls_slice_that_changes();
164 calls_slice_that_changes();
165 %OptimizeFunctionOnNextCall(calls_slice_that_changes);
166 calls_slice_that_changes();
167 assertUnoptimized(calls_slice_that_changes);
168
169 slice = [].slice;
170 function lotsOfArguments() {
171 return slice.call(arguments);
172 }
173
174 var arr = new Array(100000);
175 for (var i = 0; i < arr.length; ++i) arr[i] = i;
176
177 assertArrayEquals([1,2,3], lotsOfArguments(1,2,3));
178 assertArrayEquals([1,2,3], lotsOfArguments(1,2,3));
179 %OptimizeFunctionOnNextCall(lotsOfArguments);
180 assertArrayEquals([1,2,3], lotsOfArguments(1,2,3));
181 assertOptimized(lotsOfArguments);
182 var result = lotsOfArguments.apply(void 0, arr);
183 assertArrayEquals(arr, result);
184 assertUnoptimized(lotsOfArguments);
185
186
187 var o = {
188 callsInline: function caller() {
189 return this.toBeInlined(1, 2, 3, 4, 5);
190 },
191 toBeInlined: function callee() {
192 return slice.call(arguments);
193 }
194 };
195
196 assertArrayEquals([1,2,3,4,5], o.callsInline());
197 assertArrayEquals([1,2,3,4,5], o.callsInline());
198 %OptimizeFunctionOnNextCall(o.callsInline);
199 assertArrayEquals([1,2,3,4,5], o.callsInline());
200 assertOptimized(o.callsInline);
201 assertArrayEquals([1,2,3,4,5], o.callsInline());
202
203 })();
OLDNEW
« 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