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 |
11 // with the distribution. | 11 // with the distribution. |
12 // * Neither the name of Google Inc. nor the names of its | 12 // * Neither the name of Google Inc. nor the names of its |
13 // contributors may be used to endorse or promote products derived | 13 // contributors may be used to endorse or promote products derived |
14 // from this software without specific prior written permission. | 14 // from this software without specific prior written permission. |
15 // | 15 // |
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
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 // Flags: --allow-natives-syntax --smi-only-arrays --expose-gc | 28 // Flags: --allow-natives-syntax --smi-only-arrays --expose-gc |
29 // Flags: --track-allocation-sites --noalways-opt | 29 // Flags: --notrack_allocation_sites |
| 30 |
| 31 // Limit the number of stress runs to reduce polymorphism it defeats some of the |
| 32 // assumptions made about how elements transitions work because transition stubs |
| 33 // end up going generic. |
| 34 // Flags: --stress-runs=2 |
30 | 35 |
31 // Test element kind of objects. | 36 // Test element kind of objects. |
32 // Since --smi-only-arrays affects builtins, its default setting at compile | 37 // Since --smi-only-arrays affects builtins, its default setting at compile |
33 // time sticks if built with snapshot. If --smi-only-arrays is deactivated | 38 // time sticks if built with snapshot. If --smi-only-arrays is deactivated |
34 // by default, only a no-snapshot build actually has smi-only arrays enabled | 39 // by default, only a no-snapshot build actually has smi-only arrays enabled |
35 // in this test case. Depending on whether smi-only arrays are actually | 40 // in this test case. Depending on whether smi-only arrays are actually |
36 // enabled, this test takes the appropriate code path to check smi-only arrays. | 41 // enabled, this test takes the appropriate code path to check smi-only arrays. |
37 | 42 |
38 // support_smi_only_arrays = %HasFastSmiElements(new Array(1,2,3,4,5,6,7,8)); | 43 support_smi_only_arrays = %HasFastSmiElements(new Array(1,2,3,4,5,6,7,8)); |
39 support_smi_only_arrays = true; | |
40 | 44 |
41 if (support_smi_only_arrays) { | 45 if (support_smi_only_arrays) { |
42 print("Tests include smi-only arrays."); | 46 print("Tests include smi-only arrays."); |
43 } else { | 47 } else { |
44 print("Tests do NOT include smi-only arrays."); | 48 print("Tests do NOT include smi-only arrays."); |
45 } | 49 } |
46 | 50 |
47 var elements_kind = { | 51 var elements_kind = { |
48 fast_smi_only : 'fast smi only elements', | 52 fast_smi_only : 'fast smi only elements', |
49 fast : 'fast elements', | 53 fast : 'fast elements', |
50 fast_double : 'fast double elements', | 54 fast_double : 'fast double elements', |
51 dictionary : 'dictionary elements', | 55 dictionary : 'dictionary elements', |
52 external_byte : 'external byte elements', | 56 external_byte : 'external byte elements', |
53 external_unsigned_byte : 'external unsigned byte elements', | 57 external_unsigned_byte : 'external unsigned byte elements', |
54 external_short : 'external short elements', | 58 external_short : 'external short elements', |
55 external_unsigned_short : 'external unsigned short elements', | 59 external_unsigned_short : 'external unsigned short elements', |
56 external_int : 'external int elements', | 60 external_int : 'external int elements', |
57 external_unsigned_int : 'external unsigned int elements', | 61 external_unsigned_int : 'external unsigned int elements', |
58 external_float : 'external float elements', | 62 external_float : 'external float elements', |
59 external_double : 'external double elements', | 63 external_double : 'external double elements', |
60 external_pixel : 'external pixel elements' | 64 external_pixel : 'external pixel elements' |
61 } | 65 } |
62 | 66 |
63 function getKind(obj) { | 67 function getKind(obj) { |
64 if (%HasFastSmiElements(obj)) return elements_kind.fast_smi_only; | 68 if (%HasFastSmiElements(obj)) return elements_kind.fast_smi_only; |
65 if (%HasFastObjectElements(obj)) return elements_kind.fast; | 69 if (%HasFastObjectElements(obj)) return elements_kind.fast; |
66 if (%HasFastDoubleElements(obj)) return elements_kind.fast_double; | 70 if (%HasFastDoubleElements(obj)) return elements_kind.fast_double; |
67 if (%HasDictionaryElements(obj)) return elements_kind.dictionary; | 71 if (%HasDictionaryElements(obj)) return elements_kind.dictionary; |
68 } | 72 // Every external kind is also an external array. |
69 | 73 assertTrue(%HasExternalArrayElements(obj)); |
70 function isHoley(obj) { | 74 if (%HasExternalByteElements(obj)) { |
71 if (%HasFastHoleyElements(obj)) return true; | 75 return elements_kind.external_byte; |
72 return false; | 76 } |
| 77 if (%HasExternalUnsignedByteElements(obj)) { |
| 78 return elements_kind.external_unsigned_byte; |
| 79 } |
| 80 if (%HasExternalShortElements(obj)) { |
| 81 return elements_kind.external_short; |
| 82 } |
| 83 if (%HasExternalUnsignedShortElements(obj)) { |
| 84 return elements_kind.external_unsigned_short; |
| 85 } |
| 86 if (%HasExternalIntElements(obj)) { |
| 87 return elements_kind.external_int; |
| 88 } |
| 89 if (%HasExternalUnsignedIntElements(obj)) { |
| 90 return elements_kind.external_unsigned_int; |
| 91 } |
| 92 if (%HasExternalFloatElements(obj)) { |
| 93 return elements_kind.external_float; |
| 94 } |
| 95 if (%HasExternalDoubleElements(obj)) { |
| 96 return elements_kind.external_double; |
| 97 } |
| 98 if (%HasExternalPixelElements(obj)) { |
| 99 return elements_kind.external_pixel; |
| 100 } |
73 } | 101 } |
74 | 102 |
75 function assertKind(expected, obj, name_opt) { | 103 function assertKind(expected, obj, name_opt) { |
76 if (!support_smi_only_arrays && | 104 if (!support_smi_only_arrays && |
77 expected == elements_kind.fast_smi_only) { | 105 expected == elements_kind.fast_smi_only) { |
78 expected = elements_kind.fast; | 106 expected = elements_kind.fast; |
79 } | 107 } |
80 assertEquals(expected, getKind(obj), name_opt); | 108 assertEquals(expected, getKind(obj), name_opt); |
81 } | 109 } |
82 | 110 |
| 111 // long-running loop forces OSR. |
| 112 for (var i = 0; i < 1000000; i++) { } |
| 113 |
83 if (support_smi_only_arrays) { | 114 if (support_smi_only_arrays) { |
84 function bar0(t) { | 115 function construct_smis() { |
85 return new t(); | 116 try {} catch (e) {} // TODO(titzer): DisableOptimization |
| 117 var a = [0, 0, 0]; |
| 118 a[0] = 0; // Send the COW array map to the steak house. |
| 119 assertKind(elements_kind.fast_smi_only, a); |
| 120 return a; |
| 121 } |
| 122 function construct_doubles() { |
| 123 try {} catch (e) {} // TODO(titzer): DisableOptimization |
| 124 var a = construct_smis(); |
| 125 a[0] = 1.5; |
| 126 assertKind(elements_kind.fast_double, a); |
| 127 return a; |
86 } | 128 } |
87 | 129 |
88 a = bar0(Array); | 130 // Test transition chain SMI->DOUBLE->FAST (crankshafted function will |
89 a[0] = 3.5; | 131 // transition to FAST directly). |
90 b = bar0(Array); | 132 function convert_mixed(array, value, kind) { |
91 assertKind(elements_kind.fast_double, b); | 133 try {} catch (e) {} // TODO(titzer): DisableOptimization |
92 %OptimizeFunctionOnNextCall(bar0); | 134 array[1] = value; |
93 b = bar0(Array); | 135 assertKind(kind, array); |
94 assertKind(elements_kind.fast_double, b); | 136 assertEquals(value, array[1]); |
95 assertTrue(2 != %GetOptimizationStatus(bar0)); | 137 } |
96 // bar0 should deopt | 138 smis = construct_smis(); |
97 b = bar0(Object); | 139 convert_mixed(smis, 1.5, elements_kind.fast_double); |
98 assertTrue(1 != %GetOptimizationStatus(bar0)); | 140 |
| 141 doubles = construct_doubles(); |
| 142 convert_mixed(doubles, "three", elements_kind.fast); |
| 143 |
| 144 convert_mixed(construct_smis(), "three", elements_kind.fast); |
| 145 convert_mixed(construct_doubles(), "three", elements_kind.fast); |
| 146 |
| 147 smis = construct_smis(); |
| 148 doubles = construct_doubles(); |
| 149 convert_mixed(smis, 1, elements_kind.fast); |
| 150 convert_mixed(doubles, 1, elements_kind.fast); |
| 151 assertTrue(%HaveSameMap(smis, doubles)); |
99 } | 152 } |
| 153 |
| 154 // Throw away type information in the ICs for next stress run. |
| 155 gc(); |
OLD | NEW |