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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 return new Array(len); | 143 return new Array(len); |
144 } | 144 } |
145 a = bar(10); | 145 a = bar(10); |
146 a[0] = "a string"; | 146 a[0] = "a string"; |
147 a = bar(10); | 147 a = bar(10); |
148 assertKind(elements_kind.fast, a); | 148 assertKind(elements_kind.fast, a); |
149 %OptimizeFunctionOnNextCall(bar); | 149 %OptimizeFunctionOnNextCall(bar); |
150 a = bar(10); | 150 a = bar(10); |
151 assertKind(elements_kind.fast, a); | 151 assertKind(elements_kind.fast, a); |
152 assertOptimized(bar); | 152 assertOptimized(bar); |
| 153 // bar should deopt because the length is too large. |
| 154 a = bar(100000); |
| 155 assertUnoptimized(bar); |
| 156 assertKind(elements_kind.dictionary, a); |
| 157 // The allocation site now has feedback that means the array constructor |
| 158 // will not be inlined. |
| 159 %OptimizeFunctionOnNextCall(bar); |
153 a = bar(100000); | 160 a = bar(100000); |
154 assertKind(elements_kind.dictionary, a); | 161 assertKind(elements_kind.dictionary, a); |
155 assertOptimized(bar); | 162 assertOptimized(bar); |
156 | 163 |
157 // If the argument isn't a smi, things should still work. | 164 // If the argument isn't a smi, it bails out as well |
158 a = bar("oops"); | 165 a = bar("oops"); |
159 assertOptimized(bar); | 166 assertOptimized(bar); |
160 assertKind(elements_kind.fast, a); | 167 assertKind(elements_kind.fast, a); |
161 | 168 |
162 function barn(one, two, three) { | 169 function barn(one, two, three) { |
163 return new Array(one, two, three); | 170 return new Array(one, two, three); |
164 } | 171 } |
165 | 172 |
166 barn(1, 2, 3); | 173 barn(1, 2, 3); |
167 barn(1, 2, 3); | 174 barn(1, 2, 3); |
168 %OptimizeFunctionOnNextCall(barn); | 175 %OptimizeFunctionOnNextCall(barn); |
169 barn(1, 2, 3); | 176 barn(1, 2, 3); |
170 assertOptimized(barn); | 177 assertOptimized(barn); |
171 a = barn(1, "oops", 3); | 178 a = barn(1, "oops", 3); |
| 179 // The method should deopt, but learn from the failure to avoid inlining |
| 180 // the array. |
| 181 assertKind(elements_kind.fast, a); |
| 182 assertUnoptimized(barn); |
| 183 %OptimizeFunctionOnNextCall(barn); |
| 184 a = barn(1, "oops", 3); |
172 assertOptimized(barn); | 185 assertOptimized(barn); |
173 })(); | 186 })(); |
174 | 187 |
175 | 188 |
176 // Test: When a method with array constructor is crankshafted, the type | 189 // Test: When a method with array constructor is crankshafted, the type |
177 // feedback for elements kind is baked in. Verify that transitions don't | 190 // feedback for elements kind is baked in. Verify that transitions don't |
178 // change it anymore | 191 // change it anymore |
179 (function() { | 192 (function() { |
180 function bar() { | 193 function bar() { |
181 return new Array(); | 194 return new Array(); |
(...skipping 26 matching lines...) Expand all Loading... |
208 | 221 |
209 var contextB = Realm.create(); | 222 var contextB = Realm.create(); |
210 Realm.eval(contextB, "function bar2() { return new Array(); };"); | 223 Realm.eval(contextB, "function bar2() { return new Array(); };"); |
211 Realm.eval(contextB, "bar2(); bar2();"); | 224 Realm.eval(contextB, "bar2(); bar2();"); |
212 Realm.eval(contextB, "%OptimizeFunctionOnNextCall(bar2);"); | 225 Realm.eval(contextB, "%OptimizeFunctionOnNextCall(bar2);"); |
213 Realm.eval(contextB, "bar2();"); | 226 Realm.eval(contextB, "bar2();"); |
214 assertFalse(Realm.eval(contextB, "bar2();") instanceof Array); | 227 assertFalse(Realm.eval(contextB, "bar2();") instanceof Array); |
215 assertTrue(Realm.eval(contextB, "bar2() instanceof Array")); | 228 assertTrue(Realm.eval(contextB, "bar2() instanceof Array")); |
216 })(); | 229 })(); |
217 | 230 |
218 // Test: create array with packed feedback, then optimize function, which | 231 // Test: create array with packed feedback, then optimize/inline |
219 // should deal with arguments that create holey arrays. | 232 // function. Verify that if we ask for a holey array then we deopt. |
| 233 // Reoptimization will proceed with the correct feedback and we |
| 234 // won't deopt anymore. |
220 (function() { | 235 (function() { |
221 function bar(len) { return new Array(len); } | 236 function bar(len) { return new Array(len); } |
222 bar(0); | 237 bar(0); |
223 bar(0); | 238 bar(0); |
224 %OptimizeFunctionOnNextCall(bar); | 239 %OptimizeFunctionOnNextCall(bar); |
225 a = bar(0); | 240 a = bar(0); |
226 assertOptimized(bar); | 241 assertOptimized(bar); |
227 assertFalse(isHoley(a)); | 242 assertFalse(isHoley(a)); |
228 a = bar(1); // ouch! | 243 a = bar(1); // ouch! |
| 244 assertUnoptimized(bar); |
| 245 assertTrue(isHoley(a)); |
| 246 // Try again |
| 247 %OptimizeFunctionOnNextCall(bar); |
| 248 a = bar(100); |
229 assertOptimized(bar); | 249 assertOptimized(bar); |
230 assertTrue(isHoley(a)); | 250 assertTrue(isHoley(a)); |
231 a = bar(100); | |
232 assertTrue(isHoley(a)); | |
233 a = bar(0); | 251 a = bar(0); |
234 assertOptimized(bar); | 252 assertOptimized(bar); |
235 // Crankshafted functions don't use mementos, so feedback still | 253 assertTrue(isHoley(a)); |
236 // indicates a packed array is desired. (unless --nocrankshaft is in use). | |
237 if (4 != %GetOptimizationStatus(bar)) { | |
238 assertFalse(isHoley(a)); | |
239 } | |
240 })(); | 254 })(); |
241 } | 255 } |
OLD | NEW |