| 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 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 | 82 |
| 83 if (support_smi_only_arrays) { | 83 if (support_smi_only_arrays) { |
| 84 | 84 |
| 85 // Test: If a call site goes megamorphic, it loses the ability to | 85 // Test: If a call site goes megamorphic, it loses the ability to |
| 86 // use allocation site feedback. | 86 // use allocation site feedback. |
| 87 (function() { | 87 (function() { |
| 88 function bar(t, len) { | 88 function bar(t, len) { |
| 89 return new t(len); | 89 return new t(len); |
| 90 } | 90 } |
| 91 | 91 |
| 92 bar(Array, 10); // Skip premonomorphic state. | |
| 93 a = bar(Array, 10); | 92 a = bar(Array, 10); |
| 94 a[0] = 3.5; | 93 a[0] = 3.5; |
| 95 b = bar(Array, 1); | 94 b = bar(Array, 1); |
| 96 assertKind(elements_kind.fast_double, b); | 95 assertKind(elements_kind.fast_double, b); |
| 97 c = bar(Object, 3); | 96 c = bar(Object, 3); |
| 98 b = bar(Array, 10); | 97 b = bar(Array, 10); |
| 99 assertKind(elements_kind.fast_smi_only, b); | 98 assertKind(elements_kind.fast_smi_only, b); |
| 100 b[0] = 3.5; | 99 b[0] = 3.5; |
| 101 c = bar(Array, 10); | 100 c = bar(Array, 10); |
| 102 assertKind(elements_kind.fast_smi_only, c); | 101 assertKind(elements_kind.fast_smi_only, c); |
| 103 })(); | 102 })(); |
| 104 | 103 |
| 105 | 104 |
| 106 // Test: ensure that crankshafted array constructor sites are deopted | 105 // Test: ensure that crankshafted array constructor sites are deopted |
| 107 // if another function is used. | 106 // if another function is used. |
| 108 (function() { | 107 (function() { |
| 109 function bar0(t) { | 108 function bar0(t) { |
| 110 return new t(); | 109 return new t(); |
| 111 } | 110 } |
| 112 | |
| 113 bar0(Array); // Skip premonomorphic state. | |
| 114 a = bar0(Array); | 111 a = bar0(Array); |
| 115 a[0] = 3.5; | 112 a[0] = 3.5; |
| 116 b = bar0(Array); | 113 b = bar0(Array); |
| 117 assertKind(elements_kind.fast_double, b); | 114 assertKind(elements_kind.fast_double, b); |
| 118 %OptimizeFunctionOnNextCall(bar0); | 115 %OptimizeFunctionOnNextCall(bar0); |
| 119 b = bar0(Array); | 116 b = bar0(Array); |
| 120 assertKind(elements_kind.fast_double, b); | 117 assertKind(elements_kind.fast_double, b); |
| 121 assertOptimized(bar0); | 118 assertOptimized(bar0); |
| 122 // bar0 should deopt | 119 // bar0 should deopt |
| 123 b = bar0(Object); | 120 b = bar0(Object); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 135 assertKind(elements_kind.fast_smi_only, c); | 132 assertKind(elements_kind.fast_smi_only, c); |
| 136 })(); | 133 })(); |
| 137 | 134 |
| 138 | 135 |
| 139 // Test: Ensure that inlined array calls in crankshaft learn from deopts | 136 // Test: Ensure that inlined array calls in crankshaft learn from deopts |
| 140 // based on the move to a dictionary for the array. | 137 // based on the move to a dictionary for the array. |
| 141 (function() { | 138 (function() { |
| 142 function bar(len) { | 139 function bar(len) { |
| 143 return new Array(len); | 140 return new Array(len); |
| 144 } | 141 } |
| 145 | |
| 146 bar(10); // Skip premonomorphic state. | |
| 147 a = bar(10); | 142 a = bar(10); |
| 148 a[0] = "a string"; | 143 a[0] = "a string"; |
| 149 a = bar(10); | 144 a = bar(10); |
| 150 assertKind(elements_kind.fast, a); | 145 assertKind(elements_kind.fast, a); |
| 151 %OptimizeFunctionOnNextCall(bar); | 146 %OptimizeFunctionOnNextCall(bar); |
| 152 a = bar(10); | 147 a = bar(10); |
| 153 assertKind(elements_kind.fast, a); | 148 assertKind(elements_kind.fast, a); |
| 154 assertOptimized(bar); | 149 assertOptimized(bar); |
| 155 // bar should deopt because the length is too large. | 150 // bar should deopt because the length is too large. |
| 156 a = bar(100000); | 151 a = bar(100000); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 })(); | 183 })(); |
| 189 | 184 |
| 190 | 185 |
| 191 // Test: When a method with array constructor is crankshafted, the type | 186 // Test: When a method with array constructor is crankshafted, the type |
| 192 // feedback for elements kind is baked in. Verify that transitions don't | 187 // feedback for elements kind is baked in. Verify that transitions don't |
| 193 // change it anymore | 188 // change it anymore |
| 194 (function() { | 189 (function() { |
| 195 function bar() { | 190 function bar() { |
| 196 return new Array(); | 191 return new Array(); |
| 197 } | 192 } |
| 198 | |
| 199 bar(); // Skip premonomorphic state. | |
| 200 a = bar(); | 193 a = bar(); |
| 201 bar(); | 194 bar(); |
| 202 %OptimizeFunctionOnNextCall(bar); | 195 %OptimizeFunctionOnNextCall(bar); |
| 203 b = bar(); | 196 b = bar(); |
| 204 // This only makes sense to test if we allow crankshafting | 197 // This only makes sense to test if we allow crankshafting |
| 205 if (4 != %GetOptimizationStatus(bar)) { | 198 if (4 != %GetOptimizationStatus(bar)) { |
| 206 assertOptimized(bar); | 199 assertOptimized(bar); |
| 207 %DebugPrint(3); | 200 %DebugPrint(3); |
| 208 b[0] = 3.5; | 201 b[0] = 3.5; |
| 209 c = bar(); | 202 c = bar(); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 // Try again | 243 // Try again |
| 251 %OptimizeFunctionOnNextCall(bar); | 244 %OptimizeFunctionOnNextCall(bar); |
| 252 a = bar(100); | 245 a = bar(100); |
| 253 assertOptimized(bar); | 246 assertOptimized(bar); |
| 254 assertTrue(isHoley(a)); | 247 assertTrue(isHoley(a)); |
| 255 a = bar(0); | 248 a = bar(0); |
| 256 assertOptimized(bar); | 249 assertOptimized(bar); |
| 257 assertTrue(isHoley(a)); | 250 assertTrue(isHoley(a)); |
| 258 })(); | 251 })(); |
| 259 } | 252 } |
| OLD | NEW |