Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1 | // Copyright 2015 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 |
| 6 | |
| 7 | function Migrator(o) { |
| 8 | return o.foo; |
| 9 | } |
| 10 | function Loader(o) { |
| 11 | return o[0]; |
| 12 | } |
| 13 | |
| 14 | var first_smi_array = [1]; |
| 15 | var second_smi_array = [2]; |
| 16 | var first_object_array = ["first"]; |
| 17 | var second_object_array = ["string"]; |
| 18 | |
| 19 | assertTrue(%HasFastSmiElements(first_smi_array)); |
| 20 | assertTrue(%HasFastSmiElements(second_smi_array)); |
| 21 | assertTrue(%HasFastObjectElements(first_object_array)); |
| 22 | assertTrue(%HasFastObjectElements(second_object_array)); |
| 23 | |
| 24 | // Prepare identical transition chains for smi and object arrays. |
| 25 | first_smi_array.foo = 0; |
| 26 | second_smi_array.foo = 0; |
| 27 | first_object_array.foo = 0; |
| 28 | second_object_array.foo = 0; |
| 29 | |
| 30 | // Collect type feedback for not-yet-deprecated original object array map. |
| 31 | for (var i = 0; i < 3; i++) Migrator(second_object_array); |
| 32 | |
| 33 | // Blaze a migration trail for smi array maps. |
| 34 | // This marks the migrated smi array map as a migration target. |
| 35 | first_smi_array.foo = 0.5; |
| 36 | print(second_smi_array.foo); |
| 37 | |
| 38 | // Deprecate original object array map. |
| 39 | // Use TryMigrate from deferred optimized code to migrate second object array. |
| 40 | first_object_array.foo = 0.5; |
| 41 | %OptimizeFunctionOnNextCall(Migrator); |
| 42 | Migrator(second_object_array); |
| 43 | |
| 44 | // |second_object_array| now erroneously has a smi map. |
| 45 | // Optimized code assuming smi elements will expose this. |
| 46 | |
| 47 | for (var i = 0; i < 3; i++) Loader(second_smi_array); |
| 48 | %OptimizeFunctionOnNextCall(Loader); |
| 49 | assertEquals("string", Loader(second_object_array)); |
| 50 | |
| 51 | // Any of the following checks will also fail: |
| 52 | assertTrue(%HasFastObjectElements(second_object_array)); |
| 53 | assertFalse(%HasFastSmiElements(second_object_array)); |
| 54 | assertTrue(%HaveSameMap(first_object_array, second_object_array)); |
| 55 | assertFalse(%HaveSameMap(first_smi_array, second_object_array)); |
| 56 | |
| 57 | %ClearFunctionTypeFeedback(Loader); |
| 58 | %ClearFunctionTypeFeedback(Migrator); |