| 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 --nooptimize-constructed-arrays | 29 // Flags: --track-allocation-sites --noalways-opt |
| 30 | 30 |
| 31 // TODO(mvstanton): remove --nooptimize-constructed-arrays and enable | 31 // TODO(mvstanton): remove --nooptimize-constructed-arrays and enable |
| 32 // the constructed array code below when the feature is turned on | 32 // the constructed array code below when the feature is turned on |
| 33 // by default. | 33 // by default. |
| 34 | 34 |
| 35 // Test element kind of objects. | 35 // Test element kind of objects. |
| 36 // Since --smi-only-arrays affects builtins, its default setting at compile | 36 // Since --smi-only-arrays affects builtins, its default setting at compile |
| 37 // time sticks if built with snapshot. If --smi-only-arrays is deactivated | 37 // time sticks if built with snapshot. If --smi-only-arrays is deactivated |
| 38 // by default, only a no-snapshot build actually has smi-only arrays enabled | 38 // by default, only a no-snapshot build actually has smi-only arrays enabled |
| 39 // in this test case. Depending on whether smi-only arrays are actually | 39 // in this test case. Depending on whether smi-only arrays are actually |
| 40 // enabled, this test takes the appropriate code path to check smi-only arrays. | 40 // enabled, this test takes the appropriate code path to check smi-only arrays. |
| 41 | 41 |
| 42 support_smi_only_arrays = %HasFastSmiElements(new Array(1,2,3,4,5,6,7,8)); | 42 // support_smi_only_arrays = %HasFastSmiElements(new Array(1,2,3,4,5,6,7,8)); |
| 43 optimize_constructed_arrays = false; | 43 support_smi_only_arrays = true; |
| 44 optimize_constructed_arrays = true; |
| 44 | 45 |
| 45 if (support_smi_only_arrays) { | 46 if (support_smi_only_arrays) { |
| 46 print("Tests include smi-only arrays."); | 47 print("Tests include smi-only arrays."); |
| 47 } else { | 48 } else { |
| 48 print("Tests do NOT include smi-only arrays."); | 49 print("Tests do NOT include smi-only arrays."); |
| 49 } | 50 } |
| 50 | 51 |
| 51 if (optimize_constructed_arrays) { | 52 if (optimize_constructed_arrays) { |
| 52 print("Tests include constructed array optimizations."); | 53 print("Tests include constructed array optimizations."); |
| 53 } else { | 54 } else { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 | 115 |
| 115 obj = new Array(0); | 116 obj = new Array(0); |
| 116 assertNotHoley(obj); | 117 assertNotHoley(obj); |
| 117 assertKind(elements_kind.fast_smi_only, obj); | 118 assertKind(elements_kind.fast_smi_only, obj); |
| 118 | 119 |
| 119 obj = new Array(2); | 120 obj = new Array(2); |
| 120 assertHoley(obj); | 121 assertHoley(obj); |
| 121 assertKind(elements_kind.fast_smi_only, obj); | 122 assertKind(elements_kind.fast_smi_only, obj); |
| 122 | 123 |
| 123 obj = new Array(1,2,3); | 124 obj = new Array(1,2,3); |
| 125 |
| 124 assertNotHoley(obj); | 126 assertNotHoley(obj); |
| 125 assertKind(elements_kind.fast_smi_only, obj); | 127 assertKind(elements_kind.fast_smi_only, obj); |
| 126 | 128 |
| 127 obj = new Array(1, "hi", 2, undefined); | 129 obj = new Array(1, "hi", 2, undefined); |
| 128 assertNotHoley(obj); | 130 assertNotHoley(obj); |
| 129 assertKind(elements_kind.fast, obj); | 131 assertKind(elements_kind.fast, obj); |
| 130 | 132 |
| 131 function fastliteralcase(literal, value) { | 133 function fastliteralcase(literal, value) { |
| 132 literal[0] = value; | 134 literal[0] = value; |
| 133 return literal; | 135 return literal; |
| 134 } | 136 } |
| 135 | 137 |
| 136 function get_standard_literal() { | 138 function get_standard_literal() { |
| 137 var literal = [1, 2, 3]; | 139 var literal = [1, 2, 3]; |
| 138 return literal; | 140 return literal; |
| 139 } | 141 } |
| 140 | 142 |
| 141 // Case: [1,2,3] as allocation site | 143 // Case: [1,2,3] as allocation site |
| 142 obj = fastliteralcase(get_standard_literal(), 1); | 144 obj = fastliteralcase(get_standard_literal(), 1); |
| 143 assertKind(elements_kind.fast_smi_only, obj); | 145 assertKind(elements_kind.fast_smi_only, obj); |
| 144 obj = fastliteralcase(get_standard_literal(), 1.5); | 146 obj = fastliteralcase(get_standard_literal(), 1.5); |
| 145 assertKind(elements_kind.fast_double, obj); | 147 assertKind(elements_kind.fast_double, obj); |
| 146 obj = fastliteralcase(get_standard_literal(), 2); | 148 obj = fastliteralcase(get_standard_literal(), 2); |
| 147 // TODO(hpayer): bring the following assert back as soon as allocation | 149 // TODO(hpayer): bring the following assert back as soon as allocation |
| 148 // sites work again for fast literals | 150 // sites work again for fast literals |
| 149 //assertKind(elements_kind.fast_double, obj); | 151 //assertKind(elements_kind.fast_double, obj); |
| 150 | 152 |
| 151 obj = fastliteralcase([5, 3, 2], 1.5); | 153 // The test below is in a loop because arrays that live |
| 152 assertKind(elements_kind.fast_double, obj); | 154 // at global scope without the chance of being recreated |
| 153 obj = fastliteralcase([3, 6, 2], 1.5); | 155 // don't have allocation site information attached. |
| 154 assertKind(elements_kind.fast_double, obj); | 156 for(i=0;i<2;i++) { |
| 155 obj = fastliteralcase([2, 6, 3], 2); | 157 obj = fastliteralcase([5, 3, 2], 1.5); |
| 156 assertKind(elements_kind.fast_smi_only, obj); | 158 assertKind(elements_kind.fast_double, obj); |
| 159 obj = fastliteralcase([3, 6, 2], 1.5); |
| 160 assertKind(elements_kind.fast_double, obj); |
| 161 obj = fastliteralcase([2, 6, 3], 2); |
| 162 assertKind(elements_kind.fast_smi_only, obj); |
| 163 } |
| 157 | 164 |
| 158 // Verify that we will not pretransition the double->fast path. | 165 // Verify that we will not pretransition the double->fast path. |
| 159 obj = fastliteralcase(get_standard_literal(), "elliot"); | 166 obj = fastliteralcase(get_standard_literal(), "elliot"); |
| 160 assertKind(elements_kind.fast, obj); | 167 assertKind(elements_kind.fast, obj); |
| 161 // This fails until we turn off optimistic transitions to the | 168 // This fails until we turn off optimistic transitions to the |
| 162 // most general elements kind seen on keyed stores. It's a goal | 169 // most general elements kind seen on keyed stores. It's a goal |
| 163 // to turn it off, but for now we need it. | 170 // to turn it off, but for now we need it. |
| 164 // obj = fastliteralcase(3); | 171 // obj = fastliteralcase(3); |
| 165 // assertKind(elements_kind.fast_double, obj); | 172 // assertKind(elements_kind.fast_double, obj); |
| 166 | 173 |
| 174 // Make sure this works in crankshafted code too. |
| 175 %OptimizeFunctionOnNextCall(get_standard_literal); |
| 176 get_standard_literal(); |
| 177 obj = get_standard_literal(); |
| 178 assertKind(elements_kind.fast_double, obj); |
| 179 |
| 167 function fastliteralcase_smifast(value) { | 180 function fastliteralcase_smifast(value) { |
| 168 var literal = [1, 2, 3, 4]; | 181 var literal = [1, 2, 3, 4]; |
| 169 literal[0] = value; | 182 literal[0] = value; |
| 170 return literal; | 183 return literal; |
| 171 } | 184 } |
| 172 | 185 |
| 173 obj = fastliteralcase_smifast(1); | 186 obj = fastliteralcase_smifast(1); |
| 174 assertKind(elements_kind.fast_smi_only, obj); | 187 assertKind(elements_kind.fast_smi_only, obj); |
| 175 obj = fastliteralcase_smifast("carter"); | 188 obj = fastliteralcase_smifast("carter"); |
| 176 assertKind(elements_kind.fast, obj); | 189 assertKind(elements_kind.fast, obj); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 201 } | 214 } |
| 202 | 215 |
| 203 // Case: new Array() as allocation site, smi->fast | 216 // Case: new Array() as allocation site, smi->fast |
| 204 obj = newarraycase_smiobj(1); | 217 obj = newarraycase_smiobj(1); |
| 205 assertKind(elements_kind.fast_smi_only, obj); | 218 assertKind(elements_kind.fast_smi_only, obj); |
| 206 obj = newarraycase_smiobj("gloria"); | 219 obj = newarraycase_smiobj("gloria"); |
| 207 assertKind(elements_kind.fast, obj); | 220 assertKind(elements_kind.fast, obj); |
| 208 obj = newarraycase_smiobj(2); | 221 obj = newarraycase_smiobj(2); |
| 209 assertKind(elements_kind.fast, obj); | 222 assertKind(elements_kind.fast, obj); |
| 210 | 223 |
| 224 // first death if we optimze ArraySingleArgumentConstructorStub |
| 211 function newarraycase_length_smidouble(value) { | 225 function newarraycase_length_smidouble(value) { |
| 212 var a = new Array(3); | 226 var a = new Array(3); |
| 213 a[0] = value; | 227 a[0] = value; |
| 214 return a; | 228 return a; |
| 215 } | 229 } |
| 216 | 230 |
| 217 // Case: new Array(length) as allocation site | 231 // Case: new Array(length) as allocation site |
| 218 obj = newarraycase_length_smidouble(1); | 232 obj = newarraycase_length_smidouble(1); |
| 219 assertKind(elements_kind.fast_smi_only, obj); | 233 assertKind(elements_kind.fast_smi_only, obj); |
| 220 obj = newarraycase_length_smidouble(1.5); | 234 obj = newarraycase_length_smidouble(1.5); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 } | 281 } |
| 268 | 282 |
| 269 obj = newarraycase_list_smiobj(1); | 283 obj = newarraycase_list_smiobj(1); |
| 270 assertKind(elements_kind.fast_smi_only, obj); | 284 assertKind(elements_kind.fast_smi_only, obj); |
| 271 obj = newarraycase_list_smiobj("coates"); | 285 obj = newarraycase_list_smiobj("coates"); |
| 272 assertKind(elements_kind.fast, obj); | 286 assertKind(elements_kind.fast, obj); |
| 273 obj = newarraycase_list_smiobj(2); | 287 obj = newarraycase_list_smiobj(2); |
| 274 assertKind(elements_kind.fast, obj); | 288 assertKind(elements_kind.fast, obj); |
| 275 } | 289 } |
| 276 } | 290 } |
| OLD | NEW |