OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 10 matching lines...) Expand all Loading... |
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
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 // Test dictionary -> double elements -> dictionary elements round trip | 28 // Test dictionary -> double elements -> dictionary elements round trip |
29 | 29 |
30 // Flags: --allow-natives-syntax --unbox-double-arrays --expose-gc | 30 // Flags: --allow-natives-syntax --unbox-double-arrays --expose-gc |
31 var large_array_size = 500000; | 31 var large_array_size = 100000; |
32 var approx_dict_to_elements_threshold = 69000; | 32 var approx_dict_to_elements_threshold = 75000; |
33 | 33 |
34 var name = 0; | 34 var name = 0; |
35 | 35 |
36 function expected_array_value(i) { | 36 function expected_array_value(i) { |
37 if ((i % 2) == 0) { | 37 if ((i % 2) == 0) { |
38 return i; | 38 return i; |
39 } else { | 39 } else { |
40 return i + 0.5; | 40 return i + 0.5; |
41 } | 41 } |
42 } | 42 } |
43 | 43 |
44 function force_to_fast_double_array(a) { | 44 function force_to_fast_double_array(a) { |
| 45 a[large_array_size - 2] = 1; |
45 for (var i= 0; i < approx_dict_to_elements_threshold; ++i ) { | 46 for (var i= 0; i < approx_dict_to_elements_threshold; ++i ) { |
46 a[i] = expected_array_value(i); | 47 a[i] = expected_array_value(i); |
47 } | 48 } |
48 assertTrue(%HasFastDoubleElements(a)); | 49 assertTrue(%HasFastDoubleElements(a)); |
49 } | 50 } |
50 | 51 |
| 52 function make_object_like_array(size) { |
| 53 obj = new Object(); |
| 54 obj.length = size; |
| 55 return obj; |
| 56 } |
| 57 |
51 function testOneArrayType(allocator) { | 58 function testOneArrayType(allocator) { |
52 var large_array = new allocator(500000); | 59 var large_array = new allocator(large_array_size); |
53 force_to_fast_double_array(large_array); | 60 force_to_fast_double_array(large_array); |
54 var six = 6; | 61 var six = 6; |
55 | 62 |
56 for (var i= 0; i < approx_dict_to_elements_threshold; i += 501 ) { | 63 for (var i= 0; i < approx_dict_to_elements_threshold; i += 501 ) { |
57 assertEquals(expected_array_value(i), large_array[i]); | 64 assertEquals(expected_array_value(i), large_array[i]); |
58 } | 65 } |
59 | 66 |
60 // This function has a constant and won't get inlined. | 67 // This function has a constant and won't get inlined. |
61 function computed_6() { | 68 function computed_6() { |
62 return six; | 69 return six; |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 | 319 |
313 test_various_loads6(large_array, | 320 test_various_loads6(large_array, |
314 Infinity, | 321 Infinity, |
315 -Infinity, | 322 -Infinity, |
316 expected_array_value(7)); | 323 expected_array_value(7)); |
317 | 324 |
318 assertTrue(%GetOptimizationStatus(test_various_stores) != 2); | 325 assertTrue(%GetOptimizationStatus(test_various_stores) != 2); |
319 | 326 |
320 // Make sure that we haven't converted from fast double. | 327 // Make sure that we haven't converted from fast double. |
321 assertTrue(%HasFastDoubleElements(large_array)); | 328 assertTrue(%HasFastDoubleElements(large_array)); |
322 // Cause the array to grow beyond it's JSArray length. This will double the | |
323 // size of the capacity and force the array into "slow" dictionary case. | |
324 large_array[large_array_size+1] = 50; | |
325 assertTrue(%HasDictionaryElements(large_array)); | |
326 assertEquals(50, large_array[large_array_size+1]); | |
327 assertEquals(large_array_size+2, large_array.length); | |
328 assertEquals(Infinity, large_array[5]); | |
329 assertEquals(undefined, large_array[large_array_size-1]); | |
330 assertEquals(undefined, large_array[-1]); | |
331 assertEquals(large_array_size+2, large_array.length); | |
332 | |
333 // Test dictionary -> double elements -> fast elements. | |
334 var large_array2 = new allocator(large_array_size); | |
335 force_to_fast_double_array(large_array2); | |
336 delete large_array2[5]; | |
337 | |
338 // Convert back to fast elements and make sure the contents of the array are | |
339 // unchanged. | |
340 large_array2[25] = new Object(); | |
341 assertTrue(%HasFastElements(large_array2)); | |
342 for (var i= 0; i < approx_dict_to_elements_threshold; i += 500 ) { | |
343 if (i != 25 && i != 5) { | |
344 assertEquals(expected_array_value(i), large_array2[i]); | |
345 } | |
346 } | |
347 assertEquals(undefined, large_array2[5]) | |
348 assertEquals(undefined, large_array2[large_array_size-1]) | |
349 assertEquals(undefined, large_array2[-1]) | |
350 assertEquals(large_array_size, large_array2.length); | |
351 } | 329 } |
352 | 330 |
| 331 testOneArrayType(make_object_like_array); |
353 testOneArrayType(Array); | 332 testOneArrayType(Array); |
| 333 |
| 334 var large_array = new Array(large_array_size); |
| 335 force_to_fast_double_array(large_array); |
| 336 assertTrue(%HasFastDoubleElements(large_array)); |
| 337 |
| 338 // Cause the array to grow beyond it's JSArray length. This will double the |
| 339 // size of the capacity and force the array into "slow" dictionary case. |
| 340 large_array[5] = Infinity; |
| 341 large_array[large_array_size+10001] = 50; |
| 342 assertTrue(%HasDictionaryElements(large_array)); |
| 343 assertEquals(50, large_array[large_array_size+10001]); |
| 344 assertEquals(large_array_size+10002, large_array.length); |
| 345 assertEquals(Infinity, large_array[5]); |
| 346 assertEquals(undefined, large_array[large_array_size-1]); |
| 347 assertEquals(undefined, large_array[-1]); |
| 348 assertEquals(large_array_size+10002, large_array.length); |
| 349 |
| 350 // Test dictionary -> double elements -> fast elements. |
| 351 var large_array2 = new Array(large_array_size); |
| 352 force_to_fast_double_array(large_array2); |
| 353 delete large_array2[5]; |
| 354 |
| 355 // Convert back to fast elements and make sure the contents of the array are |
| 356 // unchanged. |
| 357 large_array2[25] = new Object(); |
| 358 assertTrue(%HasFastElements(large_array2)); |
| 359 for (var i= 0; i < approx_dict_to_elements_threshold; i += 500 ) { |
| 360 if (i != 25 && i != 5) { |
| 361 assertEquals(expected_array_value(i), large_array2[i]); |
| 362 } |
| 363 } |
| 364 assertEquals(undefined, large_array2[5]); |
| 365 assertEquals(undefined, large_array2[large_array_size-1]); |
| 366 assertEquals(undefined, large_array2[-1]); |
| 367 assertEquals(large_array_size, large_array2.length); |
| 368 |
| 369 // Make sure it's possible to change the array's length and that array is still |
| 370 // intact after the resize. |
| 371 var large_array3 = new Array(large_array_size); |
| 372 force_to_fast_double_array(large_array3); |
| 373 large_array3.length = 60000; |
| 374 assertEquals(60000, large_array3.length); |
| 375 assertEquals(undefined, large_array3[60000]); |
| 376 assertTrue(%HasFastDoubleElements(large_array3)); |
| 377 assertEquals(expected_array_value(5), large_array3[5]); |
| 378 assertEquals(expected_array_value(6), large_array3[6]); |
| 379 assertEquals(expected_array_value(7), large_array3[7]); |
| 380 assertEquals(expected_array_value(large_array3.length-1), |
| 381 large_array3[large_array3.length-1]); |
| 382 assertEquals(undefined, large_array3[large_array_size-1]); |
| 383 assertEquals(undefined, large_array3[-1]); |
| 384 gc(); |
| 385 |
| 386 for (var i= 0; i < large_array3.length; i += 501 ) { |
| 387 assertEquals(expected_array_value(i), large_array3[i]); |
| 388 } |
| 389 |
| 390 large_array3.length = 25; |
| 391 assertEquals(25, large_array3.length); |
| 392 assertTrue(%HasFastDoubleElements(large_array3)); |
| 393 assertEquals(undefined, large_array3[25]); |
| 394 assertEquals(expected_array_value(5), large_array3[5]); |
| 395 assertEquals(expected_array_value(6), large_array3[6]); |
| 396 assertEquals(expected_array_value(7), large_array3[7]); |
| 397 assertEquals(expected_array_value(large_array3.length-1), |
| 398 large_array3[large_array3.length-1]); |
| 399 assertEquals(undefined, large_array3[large_array_size-1]); |
| 400 assertEquals(undefined, large_array3[-1]); |
| 401 gc(); |
| 402 |
| 403 for (var i= 0; i < large_array3.length; ++i) { |
| 404 assertEquals(expected_array_value(i), large_array3[i]); |
| 405 } |
| 406 |
| 407 large_array3.length = 100; |
| 408 assertEquals(100, large_array3.length); |
| 409 large_array3[95] = 95; |
| 410 assertTrue(%HasFastDoubleElements(large_array3)); |
| 411 assertEquals(undefined, large_array3[100]); |
| 412 assertEquals(95, large_array3[95]); |
| 413 assertEquals(expected_array_value(5), large_array3[5]); |
| 414 assertEquals(expected_array_value(6), large_array3[6]); |
| 415 assertEquals(expected_array_value(7), large_array3[7]); |
| 416 assertEquals(undefined, large_array3[large_array3.length-1]); |
| 417 assertEquals(undefined, large_array3[large_array_size-1]); |
| 418 assertEquals(undefined, large_array3[-1]); |
| 419 gc(); |
OLD | NEW |