| 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 | 55 |
| 56 function isHoley(obj) { | 56 function isHoley(obj) { |
| 57 if (%HasFastHoleyElements(obj)) return true; | 57 if (%HasFastHoleyElements(obj)) return true; |
| 58 return false; | 58 return false; |
| 59 } | 59 } |
| 60 | 60 |
| 61 function assertKind(expected, obj, name_opt) { | 61 function assertKind(expected, obj, name_opt) { |
| 62 assertEquals(expected, getKind(obj), name_opt); | 62 assertEquals(expected, getKind(obj), name_opt); |
| 63 } | 63 } |
| 64 | 64 |
| 65 |
| 65 // Test: If a call site goes megamorphic, it retains the ability to | 66 // Test: If a call site goes megamorphic, it retains the ability to |
| 66 // use allocation site feedback (if FLAG_allocation_site_pretenuring | 67 // use allocation site feedback (if FLAG_allocation_site_pretenuring |
| 67 // is on). | 68 // is on). |
| 68 (function() { | 69 (function() { |
| 69 function bar(t, len) { | 70 function bar(t, len) { |
| 70 return new t(len); | 71 return new t(len); |
| 71 } | 72 } |
| 72 | 73 |
| 73 a = bar(Array, 10); | 74 a = bar(Array, 10); |
| 74 a[0] = 3.5; | 75 a[0] = 3.5; |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 a = bar(100); | 211 a = bar(100); |
| 211 assertTrue(isHoley(a)); | 212 assertTrue(isHoley(a)); |
| 212 a = bar(0); | 213 a = bar(0); |
| 213 assertOptimized(bar); | 214 assertOptimized(bar); |
| 214 // Crankshafted functions don't use mementos, so feedback still | 215 // Crankshafted functions don't use mementos, so feedback still |
| 215 // indicates a packed array is desired. (unless --nocrankshaft is in use). | 216 // indicates a packed array is desired. (unless --nocrankshaft is in use). |
| 216 if (4 != %GetOptimizationStatus(bar)) { | 217 if (4 != %GetOptimizationStatus(bar)) { |
| 217 assertFalse(isHoley(a)); | 218 assertFalse(isHoley(a)); |
| 218 } | 219 } |
| 219 })(); | 220 })(); |
| 221 |
| 222 |
| 223 // Test: verify that elements capacity feedback works |
| 224 (function() { |
| 225 // It works for optimized functions with a no-argument array call. |
| 226 function foo() { return new Array(); } |
| 227 a = foo(); |
| 228 a.push(1, 2, 3, 4, 5, 6); |
| 229 assertEquals(25, %GetElementsCapacity(a)); |
| 230 %OptimizeFunctionOnNextCall(foo); |
| 231 b = foo(); |
| 232 assertEquals(25, %GetElementsCapacity(b)); |
| 233 |
| 234 // It works for optimized functions with a constant argument array call. |
| 235 function bar() { return new Array(1); } |
| 236 a = bar(); |
| 237 a.push(1, 2, 3, 4, 5, 6); |
| 238 assertEquals(26, %GetElementsCapacity(a)); |
| 239 %OptimizeFunctionOnNextCall(bar); |
| 240 b = bar(); |
| 241 assertEquals(26, %GetElementsCapacity(b)); |
| 242 |
| 243 // It doesn't work for functions with a non-constant length for array. |
| 244 function nonconst(l) { return new Array(l); } |
| 245 a = nonconst(1); |
| 246 a.push(1, 2, 3, 4, 5, 6); |
| 247 assertEquals(26, %GetElementsCapacity(a)); |
| 248 %OptimizeFunctionOnNextCall(nonconst); |
| 249 b = nonconst(3); |
| 250 assertEquals(3, %GetElementsCapacity(b)); |
| 251 |
| 252 // It doesn't work for multiple arguments to the array constructor. |
| 253 function some_args() { return new Array(1, 2, 3); } |
| 254 a = some_args(); |
| 255 a.push(1, 2, 3, 4, 5, 6); |
| 256 assertEquals(29, %GetElementsCapacity(a)); |
| 257 %OptimizeFunctionOnNextCall(some_args); |
| 258 b = some_args(); |
| 259 assertEquals(3, %GetElementsCapacity(b)); |
| 260 |
| 261 // It doesn't work for literals. |
| 262 function with_literal() { var a = [1,2]; return a; } |
| 263 a = with_literal(); |
| 264 a.push(1, 2, 3, 4, 5, 6); |
| 265 assertEquals(28, %GetElementsCapacity(a)); |
| 266 %OptimizeFunctionOnNextCall(with_literal); |
| 267 b = with_literal(); |
| 268 assertEquals(0, %GetElementsCapacity(b)); |
| 269 })(); |
| OLD | NEW |