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