Chromium Code Reviews| Index: test/mjsunit/opt-elements-kind.js |
| diff --git a/test/mjsunit/array-constructor-feedback.js b/test/mjsunit/opt-elements-kind.js |
| similarity index 56% |
| copy from test/mjsunit/array-constructor-feedback.js |
| copy to test/mjsunit/opt-elements-kind.js |
| index 302239b79c173c9987fb0a2127278c6a57caa6c9..3df1d9ba2b06c77eeb618901141409fe3ad24be4 100644 |
| --- a/test/mjsunit/array-constructor-feedback.js |
| +++ b/test/mjsunit/opt-elements-kind.js |
| @@ -1,4 +1,4 @@ |
| -// Copyright 2012 the V8 project authors. All rights reserved. |
| +// Copyright 2013 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: |
| @@ -26,7 +26,12 @@ |
| // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| // Flags: --allow-natives-syntax --smi-only-arrays --expose-gc |
| -// Flags: --track-allocation-sites --noalways-opt |
| +// Flags: --notrack_allocation_sites |
|
mvstanton
2013/06/26 13:21:43
In these new tests, why do you have to turn off tr
titzer
2013/06/26 17:53:59
It was turned off in the test from which I extract
|
| + |
| +// Limit the number of stress runs to reduce polymorphism it defeats some of the |
| +// assumptions made about how elements transitions work because transition stubs |
| +// end up going generic. |
| +// Flags: --stress-runs=2 |
| // Test element kind of objects. |
| // Since --smi-only-arrays affects builtins, its default setting at compile |
| @@ -35,8 +40,7 @@ |
| // in this test case. Depending on whether smi-only arrays are actually |
| // enabled, this test takes the appropriate code path to check smi-only arrays. |
| -// support_smi_only_arrays = %HasFastSmiElements(new Array(1,2,3,4,5,6,7,8)); |
| -support_smi_only_arrays = true; |
| +support_smi_only_arrays = %HasFastSmiElements(new Array(1,2,3,4,5,6,7,8)); |
| if (support_smi_only_arrays) { |
| print("Tests include smi-only arrays."); |
| @@ -65,11 +69,35 @@ function getKind(obj) { |
| if (%HasFastObjectElements(obj)) return elements_kind.fast; |
| if (%HasFastDoubleElements(obj)) return elements_kind.fast_double; |
| if (%HasDictionaryElements(obj)) return elements_kind.dictionary; |
| -} |
| - |
| -function isHoley(obj) { |
| - if (%HasFastHoleyElements(obj)) return true; |
| - return false; |
| + // Every external kind is also an external array. |
| + assertTrue(%HasExternalArrayElements(obj)); |
| + if (%HasExternalByteElements(obj)) { |
| + return elements_kind.external_byte; |
| + } |
| + if (%HasExternalUnsignedByteElements(obj)) { |
| + return elements_kind.external_unsigned_byte; |
| + } |
| + if (%HasExternalShortElements(obj)) { |
| + return elements_kind.external_short; |
| + } |
| + if (%HasExternalUnsignedShortElements(obj)) { |
| + return elements_kind.external_unsigned_short; |
| + } |
| + if (%HasExternalIntElements(obj)) { |
| + return elements_kind.external_int; |
| + } |
| + if (%HasExternalUnsignedIntElements(obj)) { |
| + return elements_kind.external_unsigned_int; |
| + } |
| + if (%HasExternalFloatElements(obj)) { |
| + return elements_kind.external_float; |
| + } |
| + if (%HasExternalDoubleElements(obj)) { |
| + return elements_kind.external_double; |
| + } |
| + if (%HasExternalPixelElements(obj)) { |
| + return elements_kind.external_pixel; |
| + } |
| } |
| function assertKind(expected, obj, name_opt) { |
| @@ -80,20 +108,54 @@ function assertKind(expected, obj, name_opt) { |
| assertEquals(expected, getKind(obj), name_opt); |
| } |
| -if (support_smi_only_arrays) { |
| - function bar0(t) { |
| - return new t(); |
| - } |
| +function construct_smis() { |
| + try {} catch (e) {} // TODO(titzer): DisableOptimization |
| + var a = [0, 0, 0]; |
| + a[0] = 0; // Send the COW array map to the steak house. |
| + assertKind(elements_kind.fast_smi_only, a); |
| + return a; |
| +} |
| + |
| +function construct_doubles() { |
| + try {} catch (e) {} // TODO(titzer): DisableOptimization |
| + var a = construct_smis(); |
| + a[0] = 1.5; |
| + assertKind(elements_kind.fast_double, a); |
| + return a; |
| +} |
| + |
| +function convert_mixed(array, value, kind) { |
| + try {} catch (e) {} // TODO(titzer): DisableOptimization |
| + array[1] = value; |
| + assertKind(kind, array); |
| + assertEquals(value, array[1]); |
| +} |
| + |
| +function test1() { |
| + if (!support_smi_only_arrays) return; |
| + |
| + // Test transition chain SMI->DOUBLE->FAST (crankshafted function will |
| + // transition to FAST directly). |
| + var smis = construct_smis(); |
| + convert_mixed(smis, 1.5, elements_kind.fast_double); |
| - a = bar0(Array); |
| - a[0] = 3.5; |
| - b = bar0(Array); |
| - assertKind(elements_kind.fast_double, b); |
| - %OptimizeFunctionOnNextCall(bar0); |
| - b = bar0(Array); |
| - assertKind(elements_kind.fast_double, b); |
| - assertTrue(2 != %GetOptimizationStatus(bar0)); |
| - // bar0 should deopt |
| - b = bar0(Object); |
| - assertTrue(1 != %GetOptimizationStatus(bar0)); |
| + var doubles = construct_doubles(); |
| + convert_mixed(doubles, "three", elements_kind.fast); |
| + |
| + convert_mixed(construct_smis(), "three", elements_kind.fast); |
| + convert_mixed(construct_doubles(), "three", elements_kind.fast); |
| + |
| + smis = construct_smis(); |
| + doubles = construct_doubles(); |
| + convert_mixed(smis, 1, elements_kind.fast); |
| + convert_mixed(doubles, 1, elements_kind.fast); |
| + assertTrue(%HaveSameMap(smis, doubles)); |
| } |
| + |
| +test1(); |
| +gc(); // clear IC state |
| +test1(); |
| +gc(); // clear IC state |
| +%OptimizeFunctionOnNextCall(test1); |
| +test1(); |
| +gc(); // clear IC state |