| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 allocation sinking optimization. | 4 // Test allocation sinking optimization. |
| 5 // VMOptions=--optimization-counter-threshold=10 --no-use-osr |
| 5 | 6 |
| 6 import 'package:expect/expect.dart'; | 7 import 'package:expect/expect.dart'; |
| 7 | 8 |
| 8 class Point { | 9 class Point { |
| 9 var x, y; | 10 var x, y; |
| 10 | 11 |
| 11 Point(this.x, this.y); | 12 Point(this.x, this.y); |
| 12 | 13 |
| 13 operator * (other) { | 14 operator * (other) { |
| 14 return x * other.x + y * other.y; | 15 return x * other.x + y * other.y; |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 class WithFinal { | 107 class WithFinal { |
| 107 final _x; | 108 final _x; |
| 108 WithFinal(this._x); | 109 WithFinal(this._x); |
| 109 } | 110 } |
| 110 | 111 |
| 111 testInitialValueForFinalField(x) { | 112 testInitialValueForFinalField(x) { |
| 112 new WithFinal(x); | 113 new WithFinal(x); |
| 113 } | 114 } |
| 114 | 115 |
| 115 testFinalField() { | 116 testFinalField() { |
| 116 for (var i = 0; i < 10000; i++) { | 117 for (var i = 0; i < 100; i++) { |
| 117 testInitialValueForFinalField(1); | 118 testInitialValueForFinalField(1); |
| 118 } | 119 } |
| 119 } | 120 } |
| 120 | 121 |
| 121 class V { | 122 class V { |
| 122 var x = 0; | 123 var x = 0; |
| 123 } | 124 } |
| 124 | 125 |
| 125 test_vm_field() { | 126 test_vm_field() { |
| 126 var obj; | 127 var obj; |
| 127 inner() => obj.x = 42; | 128 inner() => obj.x = 42; |
| 128 var a = new V(); | 129 var a = new V(); |
| 129 obj = a; | 130 obj = a; |
| 130 var t1 = a.x; | 131 var t1 = a.x; |
| 131 var t2 = inner(); | 132 var t2 = inner(); |
| 132 return a.x + t1 + t2; | 133 return a.x + t1 + t2; |
| 133 } | 134 } |
| 134 | 135 |
| 135 testVMField() { | 136 testVMField() { |
| 136 Expect.equals(84, test_vm_field()); | 137 Expect.equals(84, test_vm_field()); |
| 137 for (var i=0; i<15000; i++) test_vm_field(); | 138 for (var i = 0; i < 100; i++) test_vm_field(); |
| 138 Expect.equals(84, test_vm_field()); | 139 Expect.equals(84, test_vm_field()); |
| 139 } | 140 } |
| 140 | 141 |
| 141 main() { | 142 main() { |
| 142 var c = new C(new Point(0.1, 0.2)); | 143 var c = new C(new Point(0.1, 0.2)); |
| 143 | 144 |
| 144 // Compute initial values. | 145 // Compute initial values. |
| 145 final x0 = test1(c, 11.11, 22.22); | 146 final x0 = test1(c, 11.11, 22.22); |
| 146 final y0 = testForwardingThroughEffects(c, 11.11, 22.22); | 147 final y0 = testForwardingThroughEffects(c, 11.11, 22.22); |
| 147 final z0 = testIdentity(c.p); | 148 final z0 = testIdentity(c.p); |
| 148 | 149 |
| 149 // Force optimization. | 150 // Force optimization. |
| 150 for (var i = 0; i < 10000; i++) { | 151 for (var i = 0; i < 100; i++) { |
| 151 test1(c, i.toDouble(), i.toDouble()); | 152 test1(c, i.toDouble(), i.toDouble()); |
| 152 testForwardingThroughEffects(c, i.toDouble(), i.toDouble()); | 153 testForwardingThroughEffects(c, i.toDouble(), i.toDouble()); |
| 153 testIdentity(c.p); | 154 testIdentity(c.p); |
| 154 foo2(); | 155 foo2(); |
| 155 Expect.equals(10, foo3(5)); | 156 Expect.equals(10, foo3(5)); |
| 156 } | 157 } |
| 157 Expect.equals(0.0, foo3(0.5)); | 158 Expect.equals(0.0, foo3(0.5)); |
| 158 | 159 |
| 159 // Test returned value after optimization. | 160 // Test returned value after optimization. |
| 160 final x1 = test1(c, 11.11, 22.22); | 161 final x1 = test1(c, 11.11, 22.22); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 179 // Test that identity of materialized objects is preserved correctly and | 180 // Test that identity of materialized objects is preserved correctly and |
| 180 // no copies are materialized. | 181 // no copies are materialized. |
| 181 final z1 = testIdentity(c.p); | 182 final z1 = testIdentity(c.p); |
| 182 final z2 = testIdentity(new F(c.p)); | 183 final z2 = testIdentity(new F(c.p)); |
| 183 Expect.equals(z0, z1); | 184 Expect.equals(z0, z1); |
| 184 Expect.equals(z0, z2); | 185 Expect.equals(z0, z2); |
| 185 | 186 |
| 186 testFinalField(); | 187 testFinalField(); |
| 187 testVMField(); | 188 testVMField(); |
| 188 } | 189 } |
| OLD | NEW |