OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // Flags: --allow-natives-syntax --noalways-opt |
| 6 |
| 7 var elements_kind = { |
| 8 fast_smi_only : 'fast smi only elements', |
| 9 fast : 'fast elements', |
| 10 fast_double : 'fast double elements', |
| 11 dictionary : 'dictionary elements', |
| 12 } |
| 13 |
| 14 function getKind(obj) { |
| 15 if (%HasFastSmiElements(obj)) return elements_kind.fast_smi_only; |
| 16 if (%HasFastObjectElements(obj)) return elements_kind.fast; |
| 17 if (%HasFastDoubleElements(obj)) return elements_kind.fast_double; |
| 18 if (%HasDictionaryElements(obj)) return elements_kind.dictionary; |
| 19 } |
| 20 |
| 21 function assertKind(expected, obj, name_opt) { |
| 22 assertEquals(expected, getKind(obj), name_opt); |
| 23 } |
| 24 |
| 25 (function() { |
| 26 function make1() { return new Array(); } |
| 27 function make2() { return new Array(); } |
| 28 function make3() { return new Array(); } |
| 29 function foo(a, i) { a[0] = i; } |
| 30 |
| 31 function run_test(maker_function) { |
| 32 var one = maker_function(); |
| 33 assertKind(elements_kind.fast_smi_only, one); |
| 34 // Use memento to pre-transition allocation site to DOUBLE elements. |
| 35 foo(one, 1.5); |
| 36 // Newly created arrays should now have DOUBLE elements right away. |
| 37 var two = maker_function(); |
| 38 assertKind(elements_kind.fast_double, two); |
| 39 } |
| 40 |
| 41 // Initialize the KeyedStoreIC in foo; the actual operation will be done |
| 42 // in the runtime. |
| 43 run_test(make1); |
| 44 // Run again; the IC optimistically assumed to only see the transitioned |
| 45 // (double-elements) map again, so this will make it polymorphic. |
| 46 // The actual operation will again be done in the runtime. |
| 47 run_test(make2); |
| 48 // Finally, check if the initialized IC honors the allocation memento. |
| 49 run_test(make3); |
| 50 })(); |
OLD | NEW |