| 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 } | 70 } |
| 71 | 71 |
| 72 // Multiple versions of the test function makes sure that IC/Crankshaft state | 72 // Multiple versions of the test function makes sure that IC/Crankshaft state |
| 73 // doesn't get reused. | 73 // doesn't get reused. |
| 74 function test_various_loads(a, value_5, value_6, value_7) { | 74 function test_various_loads(a, value_5, value_6, value_7) { |
| 75 assertTrue(%HasFastDoubleElements(a)); | 75 assertTrue(%HasFastDoubleElements(a)); |
| 76 assertEquals(value_5, a[5]); | 76 assertEquals(value_5, a[5]); |
| 77 assertEquals(value_6, a[6]); | 77 assertEquals(value_6, a[6]); |
| 78 assertEquals(value_6, a[computed_6()]); // Test non-constant key | 78 assertEquals(value_6, a[computed_6()]); // Test non-constant key |
| 79 assertEquals(value_7, a[7]); | 79 assertEquals(value_7, a[7]); |
| 80 assertEquals(undefined, a[large_array_size-1]); | |
| 81 assertEquals(undefined, a[-1]); | |
| 82 assertEquals(large_array_size, a.length); | 80 assertEquals(large_array_size, a.length); |
| 83 assertTrue(%HasFastDoubleElements(a)); | 81 assertTrue(%HasFastDoubleElements(a)); |
| 84 } | 82 } |
| 85 | 83 |
| 86 function test_various_loads2(a, value_5, value_6, value_7) { | 84 function test_various_loads2(a, value_5, value_6, value_7) { |
| 87 assertTrue(%HasFastDoubleElements(a)); | 85 assertTrue(%HasFastDoubleElements(a)); |
| 88 assertEquals(value_5, a[5]); | 86 assertEquals(value_5, a[5]); |
| 89 assertEquals(value_6, a[6]); | 87 assertEquals(value_6, a[6]); |
| 90 assertEquals(value_6, a[computed_6()]); // Test non-constant key | 88 assertEquals(value_6, a[computed_6()]); // Test non-constant key |
| 91 assertEquals(value_7, a[7]); | 89 assertEquals(value_7, a[7]); |
| 92 assertEquals(undefined, a[large_array_size-1]); | |
| 93 assertEquals(undefined, a[-1]); | |
| 94 assertEquals(large_array_size, a.length); | 90 assertEquals(large_array_size, a.length); |
| 95 assertTrue(%HasFastDoubleElements(a)); | 91 assertTrue(%HasFastDoubleElements(a)); |
| 96 } | 92 } |
| 97 | 93 |
| 98 function test_various_loads3(a, value_5, value_6, value_7) { | 94 function test_various_loads3(a, value_5, value_6, value_7) { |
| 99 assertTrue(%HasFastDoubleElements(a)); | 95 assertTrue(%HasFastDoubleElements(a)); |
| 100 assertEquals(value_5, a[5]); | 96 assertEquals(value_5, a[5]); |
| 101 assertEquals(value_6, a[6]); | 97 assertEquals(value_6, a[6]); |
| 102 assertEquals(value_6, a[computed_6()]); // Test non-constant key | 98 assertEquals(value_6, a[computed_6()]); // Test non-constant key |
| 103 assertEquals(value_7, a[7]); | 99 assertEquals(value_7, a[7]); |
| 104 assertEquals(undefined, a[large_array_size-1]); | |
| 105 assertEquals(undefined, a[-1]); | |
| 106 assertEquals(large_array_size, a.length); | 100 assertEquals(large_array_size, a.length); |
| 107 assertTrue(%HasFastDoubleElements(a)); | 101 assertTrue(%HasFastDoubleElements(a)); |
| 108 } | 102 } |
| 109 | 103 |
| 110 function test_various_loads4(a, value_5, value_6, value_7) { | 104 function test_various_loads4(a, value_5, value_6, value_7) { |
| 111 assertTrue(%HasFastDoubleElements(a)); | 105 assertTrue(%HasFastDoubleElements(a)); |
| 112 assertEquals(value_5, a[5]); | 106 assertEquals(value_5, a[5]); |
| 113 assertEquals(value_6, a[6]); | 107 assertEquals(value_6, a[6]); |
| 114 assertEquals(value_6, a[computed_6()]); // Test non-constant key | 108 assertEquals(value_6, a[computed_6()]); // Test non-constant key |
| 115 assertEquals(value_7, a[7]); | 109 assertEquals(value_7, a[7]); |
| 116 assertEquals(undefined, a[large_array_size-1]); | |
| 117 assertEquals(undefined, a[-1]); | |
| 118 assertEquals(large_array_size, a.length); | 110 assertEquals(large_array_size, a.length); |
| 119 assertTrue(%HasFastDoubleElements(a)); | 111 assertTrue(%HasFastDoubleElements(a)); |
| 120 } | 112 } |
| 121 | 113 |
| 122 function test_various_loads5(a, value_5, value_6, value_7) { | 114 function test_various_loads5(a, value_5, value_6, value_7) { |
| 123 assertTrue(%HasFastDoubleElements(a)); | 115 assertTrue(%HasFastDoubleElements(a)); |
| 124 assertEquals(value_5, a[5]); | 116 if (value_5 != undefined) { |
| 125 assertEquals(value_6, a[6]); | 117 assertEquals(value_5, a[5]); |
| 126 assertEquals(value_6, a[computed_6()]); // Test non-constant key | 118 }; |
| 119 if (value_6 != undefined) { |
| 120 assertEquals(value_6, a[6]); |
| 121 assertEquals(value_6, a[computed_6()]); // Test non-constant key |
| 122 } |
| 127 assertEquals(value_7, a[7]); | 123 assertEquals(value_7, a[7]); |
| 128 assertEquals(undefined, a[large_array_size-1]); | |
| 129 assertEquals(undefined, a[-1]); | |
| 130 assertEquals(large_array_size, a.length); | 124 assertEquals(large_array_size, a.length); |
| 131 assertTrue(%HasFastDoubleElements(a)); | 125 assertTrue(%HasFastDoubleElements(a)); |
| 132 } | 126 } |
| 133 | 127 |
| 134 function test_various_loads6(a, value_5, value_6, value_7) { | 128 function test_various_loads6(a, value_5, value_6, value_7) { |
| 135 assertTrue(%HasFastDoubleElements(a)); | 129 assertTrue(%HasFastDoubleElements(a)); |
| 136 assertEquals(value_5, a[5]); | 130 assertEquals(value_5, a[5]); |
| 137 assertEquals(value_6, a[6]); | 131 assertEquals(value_6, a[6]); |
| 138 assertEquals(value_6, a[computed_6()]); // Test non-constant key | 132 assertEquals(value_6, a[computed_6()]); // Test non-constant key |
| 139 assertEquals(value_7, a[7]); | 133 assertEquals(value_7, a[7]); |
| 140 assertEquals(undefined, a[large_array_size-1]); | |
| 141 assertEquals(undefined, a[-1]); | |
| 142 assertEquals(large_array_size, a.length); | 134 assertEquals(large_array_size, a.length); |
| 143 assertTrue(%HasFastDoubleElements(a)); | 135 assertTrue(%HasFastDoubleElements(a)); |
| 144 } | 136 } |
| 137 |
| 138 function test_various_loads7(a, value_5, value_6, value_7) { |
| 139 assertTrue(%HasFastDoubleElements(a)); |
| 140 assertEquals(value_5, a[5]); |
| 141 assertEquals(value_6, a[6]); |
| 142 assertEquals(value_6, a[computed_6()]); // Test non-constant key |
| 143 assertEquals(value_7, a[7]); |
| 144 assertEquals(large_array_size, a.length); |
| 145 assertTrue(%HasFastDoubleElements(a)); |
| 146 } |
| 145 | 147 |
| 146 function test_various_stores(a, value_5, value_6, value_7) { | 148 function test_various_stores(a, value_5, value_6, value_7) { |
| 147 assertTrue(%HasFastDoubleElements(a)); | 149 assertTrue(%HasFastDoubleElements(a)); |
| 148 a[5] = value_5; | 150 a[5] = value_5; |
| 149 a[computed_6()] = value_6; | 151 a[computed_6()] = value_6; |
| 150 a[7] = value_7; | 152 a[7] = value_7; |
| 151 assertTrue(%HasFastDoubleElements(a)); | 153 assertTrue(%HasFastDoubleElements(a)); |
| 152 } | 154 } |
| 153 | 155 |
| 154 // Test double and integer values | 156 // Test double and integer values |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 test_various_loads5(large_array, | 243 test_various_loads5(large_array, |
| 242 undefined, | 244 undefined, |
| 243 undefined, | 245 undefined, |
| 244 expected_array_value(7)); | 246 expected_array_value(7)); |
| 245 test_various_loads5(large_array, | 247 test_various_loads5(large_array, |
| 246 undefined, | 248 undefined, |
| 247 undefined, | 249 undefined, |
| 248 expected_array_value(7)); | 250 expected_array_value(7)); |
| 249 | 251 |
| 250 // Make sure Crankshaft code handles the hole correctly (bailout) | 252 // Make sure Crankshaft code handles the hole correctly (bailout) |
| 253 var large_array = new allocator(large_array_size); |
| 254 force_to_fast_double_array(large_array); |
| 251 test_various_stores(large_array, | 255 test_various_stores(large_array, |
| 252 expected_array_value(5), | 256 expected_array_value(5), |
| 253 expected_array_value(6), | 257 expected_array_value(6), |
| 254 expected_array_value(7)); | 258 expected_array_value(7)); |
| 255 test_various_loads6(large_array, | 259 test_various_loads6(large_array, |
| 256 expected_array_value(5), | 260 expected_array_value(5), |
| 257 expected_array_value(6), | 261 expected_array_value(6), |
| 258 expected_array_value(7)); | 262 expected_array_value(7)); |
| 259 test_various_loads6(large_array, | 263 test_various_loads6(large_array, |
| 260 expected_array_value(5), | 264 expected_array_value(5), |
| 261 expected_array_value(6), | 265 expected_array_value(6), |
| 262 expected_array_value(7)); | 266 expected_array_value(7)); |
| 263 %OptimizeFunctionOnNextCall(test_various_loads6); | 267 %OptimizeFunctionOnNextCall(test_various_loads6); |
| 264 test_various_loads6(large_array, | 268 test_various_loads6(large_array, |
| 265 expected_array_value(5), | 269 expected_array_value(5), |
| 266 expected_array_value(6), | 270 expected_array_value(6), |
| 267 expected_array_value(7)); | 271 expected_array_value(7)); |
| 268 | 272 |
| 269 delete large_array[5]; | 273 delete large_array[5]; |
| 270 delete large_array[6]; | 274 delete large_array[6]; |
| 271 test_various_loads6(large_array, | 275 test_various_loads6(large_array, |
| 272 undefined, | 276 undefined, |
| 273 undefined, | 277 undefined, |
| 274 expected_array_value(7)); | 278 expected_array_value(7)); |
| 275 | 279 |
| 280 %DeoptimizeFunction(test_various_loads6); |
| 281 gc(); |
| 282 |
| 276 // Test stores for non-NaN. | 283 // Test stores for non-NaN. |
| 284 var large_array = new allocator(large_array_size); |
| 285 force_to_fast_double_array(large_array); |
| 277 %OptimizeFunctionOnNextCall(test_various_stores); | 286 %OptimizeFunctionOnNextCall(test_various_stores); |
| 278 test_various_stores(large_array, | 287 test_various_stores(large_array, |
| 279 expected_array_value(5), | 288 expected_array_value(5), |
| 280 expected_array_value(6), | 289 expected_array_value(6), |
| 281 expected_array_value(7)); | 290 expected_array_value(7)); |
| 282 | 291 |
| 283 test_various_stores(large_array, | 292 test_various_stores(large_array, |
| 284 expected_array_value(5), | 293 expected_array_value(5), |
| 285 expected_array_value(6), | 294 expected_array_value(6), |
| 286 expected_array_value(7)); | 295 expected_array_value(7)); |
| 287 | 296 |
| 288 test_various_loads6(large_array, | 297 test_various_loads7(large_array, |
| 289 expected_array_value(5), | 298 expected_array_value(5), |
| 290 expected_array_value(6), | 299 expected_array_value(6), |
| 291 expected_array_value(7)); | 300 expected_array_value(7)); |
| 301 |
| 302 test_various_loads7(large_array, |
| 303 expected_array_value(5), |
| 304 expected_array_value(6), |
| 305 expected_array_value(7)); |
| 306 |
| 307 %OptimizeFunctionOnNextCall(test_various_loads7); |
| 308 |
| 309 test_various_loads7(large_array, |
| 310 expected_array_value(5), |
| 311 expected_array_value(6), |
| 312 expected_array_value(7)); |
| 292 | 313 |
| 293 // Test NaN behavior for stores. | 314 // Test NaN behavior for stores. |
| 294 test_various_stores(large_array, | 315 test_various_stores(large_array, |
| 295 NaN, | 316 NaN, |
| 296 -NaN, | 317 -NaN, |
| 297 expected_array_value(7)); | 318 expected_array_value(7)); |
| 298 | 319 |
| 299 test_various_stores(large_array, | 320 test_various_stores(large_array, |
| 300 NaN, | 321 NaN, |
| 301 -NaN, | 322 -NaN, |
| 302 expected_array_value(7)); | 323 expected_array_value(7)); |
| 303 | 324 |
| 304 test_various_loads6(large_array, | 325 test_various_loads7(large_array, |
| 305 NaN, | 326 NaN, |
| 306 -NaN, | 327 -NaN, |
| 307 expected_array_value(7)); | 328 expected_array_value(7)); |
| 308 | 329 |
| 309 // Test Infinity behavior for stores. | 330 // Test Infinity behavior for stores. |
| 310 test_various_stores(large_array, | 331 test_various_stores(large_array, |
| 311 Infinity, | 332 Infinity, |
| 312 -Infinity, | 333 -Infinity, |
| 313 expected_array_value(7)); | 334 expected_array_value(7)); |
| 314 | 335 |
| 315 test_various_stores(large_array, | 336 test_various_stores(large_array, |
| 316 Infinity, | 337 Infinity, |
| 317 -Infinity, | 338 -Infinity, |
| 318 expected_array_value(7)); | 339 expected_array_value(7)); |
| 319 | 340 |
| 320 test_various_loads6(large_array, | 341 test_various_loads7(large_array, |
| 321 Infinity, | 342 Infinity, |
| 322 -Infinity, | 343 -Infinity, |
| 323 expected_array_value(7)); | 344 expected_array_value(7)); |
| 324 | 345 |
| 325 assertTrue(%GetOptimizationStatus(test_various_stores) != 2); | 346 assertTrue(%GetOptimizationStatus(test_various_stores) != 2); |
| 326 | 347 |
| 327 // Make sure that we haven't converted from fast double. | 348 // Make sure that we haven't converted from fast double. |
| 328 assertTrue(%HasFastDoubleElements(large_array)); | 349 assertTrue(%HasFastDoubleElements(large_array)); |
| 329 } | 350 } |
| 330 | 351 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 assertEquals(-Infinity, arg4); | 448 assertEquals(-Infinity, arg4); |
| 428 assertEquals(expected_array_value(5), arg5); | 449 assertEquals(expected_array_value(5), arg5); |
| 429 } | 450 } |
| 430 | 451 |
| 431 large_array3[1] = NaN; | 452 large_array3[1] = NaN; |
| 432 large_array3[2] = -NaN; | 453 large_array3[2] = -NaN; |
| 433 large_array3[3] = Infinity; | 454 large_array3[3] = Infinity; |
| 434 large_array3[4] = -Infinity; | 455 large_array3[4] = -Infinity; |
| 435 | 456 |
| 436 function call_apply() { | 457 function call_apply() { |
| 437 assertTrue(%HasFastDoubleElements(large_array3)); | |
| 438 called_by_apply.apply({}, large_array3); | 458 called_by_apply.apply({}, large_array3); |
| 439 } | 459 } |
| 440 | 460 |
| 441 call_apply(); | 461 call_apply(); |
| 442 call_apply(); | 462 call_apply(); |
| 443 call_apply(); | 463 call_apply(); |
| 444 %OptimizeFunctionOnNextCall(call_apply); | 464 %OptimizeFunctionOnNextCall(call_apply); |
| 445 call_apply(); | 465 call_apply(); |
| 446 call_apply(); | 466 call_apply(); |
| 447 call_apply(); | 467 call_apply(); |
| 448 | 468 |
| 449 function test_for_in() { | 469 function test_for_in() { |
| 450 // Due to previous tests, keys 0..25 and 95 should be present. | 470 // Due to previous tests, keys 0..25 and 95 should be present. |
| 451 next_expected = 0; | 471 next_expected = 0; |
| 452 assertTrue(%HasFastDoubleElements(large_array3)); | |
| 453 for (x in large_array3) { | 472 for (x in large_array3) { |
| 454 assertTrue(next_expected++ == x); | 473 assertTrue(next_expected++ == x); |
| 455 if (next_expected == 25) { | 474 if (next_expected == 25) { |
| 456 next_expected = 95; | 475 next_expected = 95; |
| 457 } | 476 } |
| 458 } | 477 } |
| 459 assertTrue(next_expected == 96); | 478 assertTrue(next_expected == 96); |
| 460 } | 479 } |
| 461 | 480 |
| 462 test_for_in(); | 481 test_for_in(); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 assertEquals(expected_array_value(2), large_array4[2]); | 537 assertEquals(expected_array_value(2), large_array4[2]); |
| 519 } | 538 } |
| 520 | 539 |
| 521 test_setter(); | 540 test_setter(); |
| 522 test_setter(); | 541 test_setter(); |
| 523 test_setter(); | 542 test_setter(); |
| 524 %OptimizeFunctionOnNextCall(test_setter); | 543 %OptimizeFunctionOnNextCall(test_setter); |
| 525 test_setter(); | 544 test_setter(); |
| 526 test_setter(); | 545 test_setter(); |
| 527 test_setter(); | 546 test_setter(); |
| OLD | NEW |