OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 12 matching lines...) Expand all Loading... |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 // Flags: --allow-natives-syntax | 28 // Flags: --allow-natives-syntax |
29 | 29 |
30 // IC and Crankshaft support for smi-only elements in dynamic array literals. | 30 // IC and Crankshaft support for smi-only elements in dynamic array literals. |
31 function get(foo) { return foo; } // Used to generate dynamic values. | 31 function get(foo) { return foo; } // Used to generate dynamic values. |
32 | 32 |
33 function array_natives_test() { | 33 function array_natives_test(optimized) { |
34 | 34 |
35 // Ensure small array literals start in specific element kind mode. | 35 // Ensure small array literals start in specific element kind mode. |
36 assertTrue(%HasFastSmiElements([])); | 36 assertTrue(%HasFastSmiElements([])); |
37 assertTrue(%HasFastSmiElements([1])); | 37 assertTrue(%HasFastSmiElements([1])); |
38 assertTrue(%HasFastSmiElements([1,2])); | 38 assertTrue(%HasFastSmiElements([1,2])); |
39 assertTrue(%HasFastDoubleElements([1.1])); | 39 assertTrue(%HasFastDoubleElements([1.1])); |
40 assertTrue(%HasFastDoubleElements([1.1,2])); | 40 assertTrue(%HasFastDoubleElements([1.1,2])); |
41 | 41 |
42 // This code exists to eliminate the learning influence of AllocationSites | 42 // This code exists to eliminate the learning influence of AllocationSites |
43 // on the following tests. | 43 // on the following tests. |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 assertTrue(%HasFastSmiElements(a3r)); | 144 assertTrue(%HasFastSmiElements(a3r)); |
145 assertTrue(%HasFastSmiElements(a3)); | 145 assertTrue(%HasFastSmiElements(a3)); |
146 assertEquals([], a3r); | 146 assertEquals([], a3r); |
147 assertEquals([2, 1, 2, 3], a3); | 147 assertEquals([2, 1, 2, 3], a3); |
148 a3 = [1,2,3]; | 148 a3 = [1,2,3]; |
149 a3r = a3.splice(0, 1, 2); | 149 a3r = a3.splice(0, 1, 2); |
150 assertTrue(%HasFastSmiElements(a3r)); | 150 assertTrue(%HasFastSmiElements(a3r)); |
151 assertTrue(%HasFastSmiElements(a3)); | 151 assertTrue(%HasFastSmiElements(a3)); |
152 assertEquals([1], a3r); | 152 assertEquals([1], a3r); |
153 assertEquals([2, 2, 3], a3); | 153 assertEquals([2, 2, 3], a3); |
154 | |
155 a3 = [1.1,2,3]; | 154 a3 = [1.1,2,3]; |
156 a3r = a3.splice(0, 0); | 155 a3r = a3.splice(0, 0); |
157 assertTrue(%HasFastDoubleElements(a3r)); | 156 assertTrue(%HasFastDoubleElements(a3r)); |
158 assertTrue(%HasFastDoubleElements(a3)); | 157 assertTrue(%HasFastDoubleElements(a3)); |
159 assertEquals([], a3r); | 158 assertEquals([], a3r); |
160 assertEquals([1.1, 2, 3], a3); | 159 assertEquals([1.1, 2, 3], a3); |
161 a3 = [1.1,2,3]; | 160 a3 = [1.1, 2, 3]; |
162 a3r = a3.splice(0, 1); | 161 a3r = a3.splice(0, 1); |
163 assertTrue(%HasFastDoubleElements(a3r)); | 162 assertTrue(%HasFastDoubleElements(a3r)); |
164 assertTrue(%HasFastDoubleElements(a3)); | 163 assertTrue(%HasFastDoubleElements(a3)); |
165 assertEquals([1.1], a3r); | 164 assertEquals([1.1], a3r); |
166 assertEquals([2, 3], a3); | 165 assertEquals([2, 3], a3); |
167 a3 = [1.1,2,3]; | 166 a3 = [1.1, 2, 3]; |
168 a3r = a3.splice(0, 0, 2); | 167 a3r = a3.splice(0, 0, 2); |
169 // Commented out since handled in js, which takes the best fit. | 168 assertTrue(%HasFastDoubleElements(a3r)); |
170 // assertTrue(%HasFastDoubleElements(a3r)); | |
171 assertTrue(%HasFastSmiElements(a3r)); | |
172 assertTrue(%HasFastDoubleElements(a3)); | 169 assertTrue(%HasFastDoubleElements(a3)); |
173 assertEquals([], a3r); | 170 assertEquals([], a3r); |
174 assertEquals([2, 1.1, 2, 3], a3); | 171 assertEquals([2, 1.1, 2, 3], a3); |
175 a3 = [1.1,2,3]; | 172 a3 = [1.1, 2, 3]; |
| 173 assertTrue(%HasFastDoubleElements(a3)); |
176 a3r = a3.splice(0, 1, 2); | 174 a3r = a3.splice(0, 1, 2); |
177 assertTrue(%HasFastDoubleElements(a3r)); | 175 assertTrue(%HasFastDoubleElements(a3r)); |
178 assertTrue(%HasFastDoubleElements(a3)); | 176 assertTrue(%HasFastDoubleElements(a3)); |
179 assertEquals([1.1], a3r); | 177 assertEquals([1.1], a3r); |
180 assertEquals([2, 2, 3], a3); | 178 assertEquals([2, 2, 3], a3); |
181 a3 = [1.1,2,3]; | 179 a3 = [1.1,2,3]; |
182 a3r = a3.splice(0, 0, 2.1); | 180 a3r = a3.splice(0, 0, 2.1); |
183 // Commented out since handled in js, which takes the best fit. | 181 assertTrue(%HasFastDoubleElements(a3r)); |
184 // assertTrue(%HasFastDoubleElements(a3r)); | |
185 assertTrue(%HasFastSmiElements(a3r)); | |
186 assertTrue(%HasFastDoubleElements(a3)); | 182 assertTrue(%HasFastDoubleElements(a3)); |
187 assertEquals([], a3r); | 183 assertEquals([], a3r); |
188 assertEquals([2.1, 1.1, 2, 3], a3); | 184 assertEquals([2.1, 1.1, 2, 3], a3); |
189 a3 = [1.1,2,3]; | 185 a3 = [1.1,2,3]; |
190 a3r = a3.splice(0, 1, 2.2); | 186 a3r = a3.splice(0, 1, 2.2); |
191 assertTrue(%HasFastDoubleElements(a3r)); | 187 assertTrue(%HasFastDoubleElements(a3r)); |
192 assertTrue(%HasFastDoubleElements(a3)); | 188 assertTrue(%HasFastDoubleElements(a3)); |
193 assertEquals([1.1], a3r); | 189 assertEquals([1.1], a3r); |
194 assertEquals([2.2, 2, 3], a3); | 190 assertEquals([2.2, 2, 3], a3); |
195 a3 = [1,2,3]; | 191 a3 = [1,2,3]; |
196 a3r = a3.splice(0, 0, 2.1); | 192 a3r = a3.splice(0, 0, 2.1); |
197 // Commented out since handled in js, which takes the best fit. | 193 assertTrue(%HasFastDoubleElements(a3r)); |
198 // assertTrue(%HasFastDoubleElements(a3r)); | |
199 assertTrue(%HasFastSmiElements(a3r)); | |
200 assertTrue(%HasFastDoubleElements(a3)); | 194 assertTrue(%HasFastDoubleElements(a3)); |
201 assertEquals([], a3r); | 195 assertEquals([], a3r); |
202 assertEquals([2.1, 1, 2, 3], a3); | 196 assertEquals([2.1, 1, 2, 3], a3); |
203 a3 = [1,2,3]; | 197 a3 = [1,2,3]; |
204 a3r = a3.splice(0, 1, 2.2); | 198 a3r = a3.splice(0, 1, 2.2); |
205 assertTrue(%HasFastDoubleElements(a3r)); | 199 assertTrue(%HasFastDoubleElements(a3r)); |
206 assertTrue(%HasFastDoubleElements(a3)); | 200 assertTrue(%HasFastDoubleElements(a3)); |
207 assertEquals([1], a3r); | 201 assertEquals([1], a3r); |
208 assertEquals([2.2, 2, 3], a3); | 202 assertEquals([2.2, 2, 3], a3); |
209 | |
210 a3 = [{},2,3]; | 203 a3 = [{},2,3]; |
211 a3r = a3.splice(0, 0); | 204 a3r = a3.splice(0, 0); |
212 assertTrue(%HasFastObjectElements(a3r)); | 205 assertTrue(%HasFastObjectElements(a3r)); |
213 assertTrue(%HasFastObjectElements(a3)); | 206 assertTrue(%HasFastObjectElements(a3)); |
214 assertEquals([], a3r); | 207 assertEquals([], a3r); |
215 assertEquals([{}, 2, 3], a3); | 208 assertEquals([{}, 2, 3], a3); |
216 a3 = [1,2,{}]; | 209 a3 = [1,2,{}]; |
217 a3r = a3.splice(0, 1); | 210 a3r = a3.splice(0, 1); |
218 assertTrue(%HasFastObjectElements(a3r)); | 211 assertTrue(%HasFastObjectElements(a3r)); |
219 assertTrue(%HasFastObjectElements(a3)); | 212 assertTrue(%HasFastObjectElements(a3)); |
220 assertEquals([1], a3r); | 213 assertEquals([1], a3r); |
221 assertEquals([2, {}], a3); | 214 assertEquals([2, {}], a3); |
222 a3 = [1,2,3]; | 215 a3 = [1,2,3]; |
223 a3r = a3.splice(0, 0, {}); | 216 a3r = a3.splice(0, 0, {}); |
224 assertTrue(%HasFastObjectElements(a3r)); | 217 assertTrue(%HasFastObjectElements(a3r)); |
225 assertTrue(%HasFastObjectElements(a3)); | 218 assertTrue(%HasFastObjectElements(a3)); |
226 assertEquals([], a3r); | 219 assertEquals([], a3r); |
227 assertEquals([{}, 1, 2, 3], a3); | 220 assertEquals([{}, 1, 2, 3], a3); |
228 a3 = [1,2,3]; | 221 a3 = [1,2,3]; |
229 a3r = a3.splice(0, 1, {}); | 222 a3r = a3.splice(0, 1, {}); |
230 assertTrue(%HasFastObjectElements(a3r)); | 223 assertTrue(%HasFastObjectElements(a3r)); |
231 assertTrue(%HasFastObjectElements(a3)); | 224 assertTrue(%HasFastObjectElements(a3)); |
232 assertEquals([1], a3r); | 225 assertEquals([1], a3r); |
233 assertEquals([{}, 2, 3], a3); | 226 assertEquals([{}, 2, 3], a3); |
234 | |
235 a3 = [1.1,2,3]; | 227 a3 = [1.1,2,3]; |
236 a3r = a3.splice(0, 0, {}); | 228 a3r = a3.splice(0, 0, {}); |
237 assertTrue(%HasFastObjectElements(a3r)); | 229 assertTrue(%HasFastObjectElements(a3r)); |
238 assertTrue(%HasFastObjectElements(a3)); | 230 assertTrue(%HasFastObjectElements(a3)); |
239 assertEquals([], a3r); | 231 assertEquals([], a3r); |
240 assertEquals([{}, 1.1, 2, 3], a3); | 232 assertEquals([{}, 1.1, 2, 3], a3); |
241 a3 = [1.1,2,3]; | 233 a3 = [1.1,2,3]; |
242 a3r = a3.splice(0, 1, {}); | 234 a3r = a3.splice(0, 1, {}); |
243 assertTrue(%HasFastObjectElements(a3r)); | 235 assertTrue(%HasFastObjectElements(a3r)); |
244 assertTrue(%HasFastObjectElements(a3)); | 236 assertTrue(%HasFastObjectElements(a3)); |
245 assertEquals([1.1], a3r); | 237 assertEquals([1.1], a3r); |
246 assertEquals([{}, 2, 3], a3); | 238 assertEquals([{}, 2, 3], a3); |
| 239 a3 = [1.1, 2.2, 3.3]; |
| 240 a3r = a3.splice(2, 1); |
| 241 assertTrue(%HasFastDoubleElements(a3r)); |
| 242 assertTrue(%HasFastDoubleElements(a3)); |
| 243 assertEquals([3.3], a3r); |
| 244 //assertTrue(%HasFastDoubleElements(a3r)); |
| 245 assertEquals([1.1, 2.2], a3); |
| 246 //assertTrue(%HasFastDoubleElements(a3r)); |
| 247 a3r = a3.splice(1, 1, 4.4, 5.5); |
| 248 //assertTrue(%HasFastDoubleElements(a3r)); |
| 249 //assertTrue(%HasFastDoubleElements(a3)); |
| 250 assertEquals([2.2], a3r); |
| 251 assertEquals([1.1, 4.4, 5.5], a3); |
247 | 252 |
248 // Pop | 253 // Pop |
249 var a4 = [1,2,3]; | 254 var a4 = [1,2,3]; |
250 assertEquals(3, a4.pop()); | 255 assertEquals(3, a4.pop()); |
251 assertTrue(%HasFastSmiElements(a4)); | 256 assertTrue(%HasFastSmiElements(a4)); |
252 a4 = [1.1,2,3]; | 257 a4 = [1.1,2,3]; |
253 assertEquals(3, a4.pop()); | 258 assertEquals(3, a4.pop()); |
254 assertTrue(%HasFastDoubleElements(a4)); | 259 assertTrue(%HasFastDoubleElements(a4)); |
255 a4 = [{},2,3]; | 260 a4 = [{},2,3]; |
256 assertEquals(3, a4.pop()); | 261 assertEquals(3, a4.pop()); |
(...skipping 27 matching lines...) Expand all Loading... |
284 a4.unshift(1); | 289 a4.unshift(1); |
285 assertTrue(%HasFastObjectElements(a4)); | 290 assertTrue(%HasFastObjectElements(a4)); |
286 assertEquals([1,{},2,3], a4); | 291 assertEquals([1,{},2,3], a4); |
287 a4 = [{},2,3]; | 292 a4 = [{},2,3]; |
288 a4.unshift(1.1); | 293 a4.unshift(1.1); |
289 assertTrue(%HasFastObjectElements(a4)); | 294 assertTrue(%HasFastObjectElements(a4)); |
290 assertEquals([1.1,{},2,3], a4); | 295 assertEquals([1.1,{},2,3], a4); |
291 } | 296 } |
292 | 297 |
293 for (var i = 0; i < 3; i++) { | 298 for (var i = 0; i < 3; i++) { |
294 array_natives_test(); | 299 array_natives_test(false); |
295 } | 300 } |
296 %OptimizeFunctionOnNextCall(array_natives_test); | 301 %OptimizeFunctionOnNextCall(array_natives_test); |
297 array_natives_test(); | 302 array_natives_test(true); |
OLD | NEW |