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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 // We also lost our ability to record kind feedback, as the site | 131 // We also lost our ability to record kind feedback, as the site |
132 // is megamorphic now. | 132 // is megamorphic now. |
133 assertKind(elements_kind.fast_smi_only, b); | 133 assertKind(elements_kind.fast_smi_only, b); |
134 assertOptimized(bar0); | 134 assertOptimized(bar0); |
135 b[0] = 3.5; | 135 b[0] = 3.5; |
136 c = bar0(Array); | 136 c = bar0(Array); |
137 assertKind(elements_kind.fast_smi_only, c); | 137 assertKind(elements_kind.fast_smi_only, c); |
138 })(); | 138 })(); |
139 | 139 |
140 | 140 |
141 // Test: Ensure that bailouts from the stub don't deopt a crankshafted | 141 // Test: Ensure that inlined array calls in crankshaft learn from deopts |
142 // method with a call to that stub. | 142 // based on the move to a dictionary for the array. |
143 (function() { | 143 (function() { |
144 function bar(len) { | 144 function bar(len) { |
145 return new Array(len); | 145 return new Array(len); |
146 } | 146 } |
147 a = bar(10); | 147 a = bar(10); |
148 a[0] = "a string"; | 148 a[0] = "a string"; |
149 a = bar(10); | 149 a = bar(10); |
150 assertKind(elements_kind.fast, a); | 150 assertKind(elements_kind.fast, a); |
151 %OptimizeFunctionOnNextCall(bar); | 151 %OptimizeFunctionOnNextCall(bar); |
152 a = bar(10); | 152 a = bar(10); |
153 assertKind(elements_kind.fast, a); | 153 assertKind(elements_kind.fast, a); |
154 assertOptimized(bar); | 154 assertOptimized(bar); |
155 // The stub bails out, but the method call should be fine. | 155 // bar should deopt because the length is too large. |
156 a = bar(100000); | 156 a = bar(100000); |
| 157 assertUnoptimized(bar); |
| 158 assertKind(elements_kind.dictionary, a); |
| 159 // The allocation site now has feedback that means the array constructor |
| 160 // will not be inlined. |
| 161 %OptimizeFunctionOnNextCall(bar); |
| 162 a = bar(100000); |
| 163 assertKind(elements_kind.dictionary, a); |
157 assertOptimized(bar); | 164 assertOptimized(bar); |
158 assertKind(elements_kind.dictionary, a); | |
159 | 165 |
160 // If the argument isn't a smi, it bails out as well | 166 // If the argument isn't a smi, it bails out as well |
161 a = bar("oops"); | 167 a = bar("oops"); |
162 assertOptimized(bar); | 168 assertOptimized(bar); |
163 assertKind(elements_kind.fast, a); | 169 assertKind(elements_kind.fast, a); |
164 | 170 |
165 function barn(one, two, three) { | 171 function barn(one, two, three) { |
166 return new Array(one, two, three); | 172 return new Array(one, two, three); |
167 } | 173 } |
168 | 174 |
169 barn(1, 2, 3); | 175 barn(1, 2, 3); |
170 barn(1, 2, 3); | 176 barn(1, 2, 3); |
171 %OptimizeFunctionOnNextCall(barn); | 177 %OptimizeFunctionOnNextCall(barn); |
172 barn(1, 2, 3); | 178 barn(1, 2, 3); |
173 assertOptimized(barn); | 179 assertOptimized(barn); |
174 a = barn(1, "oops", 3); | 180 a = barn(1, "oops", 3); |
175 // The stub should bail out but the method should remain optimized. | 181 // The method should deopt, but learn from the failure to avoid inlining |
| 182 // the array. |
176 assertKind(elements_kind.fast, a); | 183 assertKind(elements_kind.fast, a); |
| 184 assertUnoptimized(barn); |
| 185 %OptimizeFunctionOnNextCall(barn); |
| 186 a = barn(1, "oops", 3); |
177 assertOptimized(barn); | 187 assertOptimized(barn); |
178 })(); | 188 })(); |
179 | 189 |
180 | 190 |
181 // Test: When a method with array constructor is crankshafted, the type | 191 // Test: When a method with array constructor is crankshafted, the type |
182 // feedback for elements kind is baked in. Verify that transitions don't | 192 // feedback for elements kind is baked in. Verify that transitions don't |
183 // change it anymore | 193 // change it anymore |
184 (function() { | 194 (function() { |
185 function bar() { | 195 function bar() { |
186 return new Array(); | 196 return new Array(); |
(...skipping 26 matching lines...) Expand all Loading... |
213 | 223 |
214 var contextB = Realm.create(); | 224 var contextB = Realm.create(); |
215 Realm.eval(contextB, "function bar2() { return new Array(); };"); | 225 Realm.eval(contextB, "function bar2() { return new Array(); };"); |
216 Realm.eval(contextB, "bar2(); bar2();"); | 226 Realm.eval(contextB, "bar2(); bar2();"); |
217 Realm.eval(contextB, "%OptimizeFunctionOnNextCall(bar2);"); | 227 Realm.eval(contextB, "%OptimizeFunctionOnNextCall(bar2);"); |
218 Realm.eval(contextB, "bar2();"); | 228 Realm.eval(contextB, "bar2();"); |
219 assertFalse(Realm.eval(contextB, "bar2();") instanceof Array); | 229 assertFalse(Realm.eval(contextB, "bar2();") instanceof Array); |
220 assertTrue(Realm.eval(contextB, "bar2() instanceof Array")); | 230 assertTrue(Realm.eval(contextB, "bar2() instanceof Array")); |
221 })(); | 231 })(); |
222 } | 232 } |
OLD | NEW |