OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 // Test correctness of side effects tracking used by load to load forwarding. | 4 // Test correctness of side effects tracking used by load to load forwarding. |
5 | 5 |
6 import "package:expect/expect.dart"; | 6 import "package:expect/expect.dart"; |
7 | 7 |
8 class A { | 8 class A { |
9 var x, y; | 9 var x, y; |
10 A(this.x, this.y); | 10 A(this.x, this.y); |
(...skipping 17 matching lines...) Expand all Loading... |
28 for (var j = 1; j < 4; j++) { | 28 for (var j = 1; j < 4; j++) { |
29 value1 |= a.x << (j * 8); | 29 value1 |= a.x << (j * 8); |
30 a.y += 1; | 30 a.y += 1; |
31 if (mode) a.x += 1; | 31 if (mode) a.x += 1; |
32 a.x += 1; | 32 a.x += 1; |
33 value2 |= a.y << (j * 8); | 33 value2 |= a.y << (j * 8); |
34 } | 34 } |
35 return [value1, value2]; | 35 return [value1, value2]; |
36 } | 36 } |
37 | 37 |
| 38 // Verify that immutable and mutable VM fields (array length in this case) |
| 39 // are not confused by load forwarding even if the access the same offset |
| 40 // in the object. |
| 41 testImmutableVMFields(arr, immutable) { |
| 42 if (immutable) { |
| 43 return arr.length; // Immutable length load. |
| 44 } |
| 45 |
| 46 if (arr.length < 2) { // Mutable length load, should not be forwarded. |
| 47 arr.add(null); |
| 48 } |
| 49 |
| 50 return arr.length; |
| 51 } |
| 52 |
38 main() { | 53 main() { |
| 54 final fixed = new List(10); |
| 55 final growable = []; |
| 56 testImmutableVMFields(fixed, true); |
| 57 testImmutableVMFields(growable, false); |
| 58 testImmutableVMFields(growable, false); |
| 59 |
39 for (var i = 0; i < 2000; i++) { | 60 for (var i = 0; i < 2000; i++) { |
40 Expect.listEquals([0x02010000, 0x03020100], foo(new A(0, 0))); | 61 Expect.listEquals([0x02010000, 0x03020100], foo(new A(0, 0))); |
41 Expect.listEquals([0x02010000, 0x03020100], bar(new A(0, 0), false)); | 62 Expect.listEquals([0x02010000, 0x03020100], bar(new A(0, 0), false)); |
42 Expect.listEquals([0x04020000, 0x03020100], bar(new A(0, 0), true)); | 63 Expect.listEquals([0x04020000, 0x03020100], bar(new A(0, 0), true)); |
| 64 testImmutableVMFields(fixed, true); |
43 } | 65 } |
| 66 |
| 67 Expect.equals(1, testImmutableVMFields([], false)); |
| 68 Expect.equals(2, testImmutableVMFields([1], false)); |
| 69 Expect.equals(2, testImmutableVMFields([1, 2], false)); |
| 70 Expect.equals(3, testImmutableVMFields([1, 2, 3], false)); |
44 } | 71 } |
OLD | NEW |