OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are |
| 4 // met: |
| 5 // |
| 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided |
| 11 // with the distribution. |
| 12 // * Neither the name of Google Inc. nor the names of its |
| 13 // contributors may be used to endorse or promote products derived |
| 14 // from this software without specific prior written permission. |
| 15 // |
| 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 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. |
| 27 |
| 28 // Flags: --allow-natives-syntax --compiled_transitions |
| 29 |
| 30 try {} catch (e) {} |
| 31 |
| 32 var iteration_count = 1; |
| 33 |
| 34 function transition1(a, i, v) { |
| 35 a[i] = v; |
| 36 } |
| 37 |
| 38 // |
| 39 // Test PACKED SMI -> PACKED DOUBLE |
| 40 // |
| 41 |
| 42 var a1 = [0, 1, 2, 3, 4]; |
| 43 transition1(a1, 0, 2.5); |
| 44 var a2 = [0, 1, 2, 3, 4]; |
| 45 transition1(a2, 0, 2.5); |
| 46 assertFalse(%HasFastHoleyElements(a2)); |
| 47 %OptimizeFunctionOnNextCall(transition1); |
| 48 |
| 49 var a3 = [0, 1, 2, 3, 4]; |
| 50 assertTrue(%HasFastSmiElements(a3)); |
| 51 transition1(a3, 0, 2.5); |
| 52 assertFalse(%HasFastHoleyElements(a3)); |
| 53 assertEquals(4, a3[4]); |
| 54 assertEquals(2.5, a3[0]); |
| 55 |
| 56 // Test handling of hole. |
| 57 var a4 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; |
| 58 a4.length = 7; |
| 59 assertTrue(%HasFastSmiElements(a4)); |
| 60 transition1(a4, 0, 2.5); |
| 61 assertFalse(%HasFastHoleyElements(a4)); |
| 62 assertEquals(2.5, a4[0]); |
| 63 assertEquals(undefined, a4[8]); |
| 64 |
| 65 // Large array should deopt to runtimea |
| 66 for (j = 0; j < iteration_count; ++j) { |
| 67 a5 = new Array(); |
| 68 for (i = 0; i < 0x40000; ++i) { |
| 69 a5[i] = 0; |
| 70 } |
| 71 assertTrue(%HasFastSmiElements(a5)); |
| 72 transition1(a5, 0, 2.5); |
| 73 assertEquals(2.5, a5[0]); |
| 74 } |
| 75 |
| 76 // |
| 77 // Test HOLEY SMI -> HOLEY DOUBLE |
| 78 // |
| 79 |
| 80 function transition2(a, i, v) { |
| 81 a[i] = v; |
| 82 } |
| 83 |
| 84 var b1 = [0, 1, 2, , 4]; |
| 85 transition2(b1, 0, 2.5); |
| 86 var b2 = [0, 1, 2, , 4]; |
| 87 transition2(b2, 0, 2.5); |
| 88 assertTrue(%HasFastHoleyElements(b2)); |
| 89 %OptimizeFunctionOnNextCall(transition2); |
| 90 |
| 91 var b3 = [0, 1, 2, , 4]; |
| 92 assertTrue(%HasFastSmiElements(b3)); |
| 93 assertTrue(%HasFastHoleyElements(b3)); |
| 94 transition2(b3, 0, 2.5); |
| 95 assertTrue(%HasFastHoleyElements(b3)); |
| 96 assertEquals(4, b3[4]); |
| 97 assertEquals(2.5, b3[0]); |
| 98 |
| 99 // Large array should deopt to runtime |
| 100 for (j = 0; j < iteration_count; ++j) { |
| 101 b4 = [0, ,0]; |
| 102 for (i = 3; i < 0x40000; ++i) { |
| 103 b4[i] = 0; |
| 104 } |
| 105 assertTrue(%HasFastSmiElements(b4)); |
| 106 transition2(b4, 0, 2.5); |
| 107 assertEquals(2.5, b4[0]); |
| 108 } |
| 109 |
| 110 // |
| 111 // Test PACKED DOUBLE -> PACKED OBJECT |
| 112 // |
| 113 |
| 114 function transition3(a, i, v) { |
| 115 a[i] = v; |
| 116 } |
| 117 |
| 118 var c1 = [0, 1, 2, 3.5, 4]; |
| 119 transition3(c1, 0, new Object()); |
| 120 var c2 = [0, 1, 2, 3.5, 4]; |
| 121 transition3(c2, 0, new Object()); |
| 122 assertTrue(%HasFastObjectElements(c2)); |
| 123 assertTrue(!%HasFastHoleyElements(c2)); |
| 124 %OptimizeFunctionOnNextCall(transition3); |
| 125 |
| 126 var c3 = [0, 1, 2, 3.5, 4]; |
| 127 assertTrue(%HasFastDoubleElements(c3)); |
| 128 assertTrue(!%HasFastHoleyElements(c3)); |
| 129 transition3(c3, 0, new Array()); |
| 130 assertTrue(!%HasFastHoleyElements(c3)); |
| 131 assertTrue(%HasFastObjectElements(c3)); |
| 132 assertEquals(4, c3[4]); |
| 133 assertEquals(0, c3[0].length); |
| 134 |
| 135 // Large array under the deopt threshold should be able to trigger GC without |
| 136 // causing crashes. |
| 137 for (j = 0; j < iteration_count; ++j) { |
| 138 c4 = [0, 2.5, 0]; |
| 139 for (i = 3; i < 0xa000; ++i) { |
| 140 c4[i] = 0; |
| 141 } |
| 142 assertTrue(%HasFastDoubleElements(c4)); |
| 143 assertTrue(!%HasFastHoleyElements(c4)); |
| 144 transition3(c4, 0, new Array(5)); |
| 145 assertTrue(!%HasFastHoleyElements(c4)); |
| 146 assertTrue(%HasFastObjectElements(c4)); |
| 147 assertEquals(5, c4[0].length); |
| 148 } |
| 149 |
| 150 // Large array should deopt to runtime |
| 151 for (j = 0; j < iteration_count; ++j) { |
| 152 c5 = [0, 2.5, 0]; |
| 153 for (i = 3; i < 0x40000; ++i) { |
| 154 c5[i] = 0; |
| 155 } |
| 156 assertTrue(%HasFastDoubleElements(c5)); |
| 157 assertTrue(!%HasFastHoleyElements(c5)); |
| 158 transition3(c5, 0, new Array(5)); |
| 159 assertTrue(!%HasFastHoleyElements(c5)); |
| 160 assertTrue(%HasFastObjectElements(c5)); |
| 161 assertEquals(5, c5[0].length); |
| 162 } |
| 163 |
| 164 // |
| 165 // Test HOLEY DOUBLE -> HOLEY OBJECT |
| 166 // |
| 167 |
| 168 function transition4(a, i, v) { |
| 169 a[i] = v; |
| 170 } |
| 171 |
| 172 var d1 = [0, 1, , 3.5, 4]; |
| 173 transition4(d1, 0, new Object()); |
| 174 var d2 = [0, 1, , 3.5, 4]; |
| 175 transition4(d2, 0, new Object()); |
| 176 assertTrue(%HasFastObjectElements(d2)); |
| 177 assertTrue(%HasFastHoleyElements(d2)); |
| 178 %OptimizeFunctionOnNextCall(transition4); |
| 179 |
| 180 var d3 = [0, 1, , 3.5, 4]; |
| 181 assertTrue(%HasFastDoubleElements(d3)); |
| 182 assertTrue(%HasFastHoleyElements(d3)); |
| 183 transition4(d3, 0, new Array()); |
| 184 assertTrue(%HasFastHoleyElements(d3)); |
| 185 assertTrue(%HasFastObjectElements(d3)); |
| 186 assertEquals(4, d3[4]); |
| 187 assertEquals(0, d3[0].length); |
| 188 |
| 189 // Large array under the deopt threshold should be able to trigger GC without |
| 190 // causing crashes. |
| 191 for (j = 0; j < iteration_count; ++j) { |
| 192 d4 = [, 2.5, ,]; |
| 193 for (i = 3; i < 0xa000; ++i) { |
| 194 d4[i] = 0; |
| 195 } |
| 196 assertTrue(%HasFastDoubleElements(d4)); |
| 197 assertTrue(%HasFastHoleyElements(d4)); |
| 198 transition4(d4, 0, new Array(5)); |
| 199 assertTrue(%HasFastHoleyElements(d4)); |
| 200 assertTrue(%HasFastObjectElements(d4)); |
| 201 assertEquals(5, d4[0].length); |
| 202 assertEquals(undefined, d4[2]); |
| 203 } |
| 204 |
| 205 // Large array should deopt to runtime |
| 206 for (j = 0; j < iteration_count; ++j) { |
| 207 d5 = [, 2.5, ,]; |
| 208 for (i = 3; i < 0x40000; ++i) { |
| 209 d5[i] = 0; |
| 210 } |
| 211 assertTrue(%HasFastDoubleElements(d5)); |
| 212 assertTrue(%HasFastHoleyElements(d5)); |
| 213 transition4(d5, 0, new Array(5)); |
| 214 assertTrue(%HasFastHoleyElements(d5)); |
| 215 assertTrue(%HasFastObjectElements(d5)); |
| 216 assertEquals(5, d5[0].length); |
| 217 assertEquals(undefined, d5[2]); |
| 218 } |
OLD | NEW |