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 // VMOptions=--optimization-counter-threshold=10 --no-use-osr |
6 | 6 |
7 import 'dart:typed_data'; | 7 import 'dart:typed_data'; |
8 import 'package:expect/expect.dart'; | 8 import 'package:expect/expect.dart'; |
9 | 9 |
10 class Point { | 10 class Point { |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 var t2 = inner(); | 156 var t2 = inner(); |
157 return a.x + t1 + t2; | 157 return a.x + t1 + t2; |
158 } | 158 } |
159 | 159 |
160 testVMField() { | 160 testVMField() { |
161 Expect.equals(84, test_vm_field()); | 161 Expect.equals(84, test_vm_field()); |
162 for (var i = 0; i < 100; i++) test_vm_field(); | 162 for (var i = 0; i < 100; i++) test_vm_field(); |
163 Expect.equals(84, test_vm_field()); | 163 Expect.equals(84, test_vm_field()); |
164 } | 164 } |
165 | 165 |
| 166 class CompoundA { |
| 167 var b; |
| 168 CompoundA(this.b); |
| 169 } |
| 170 |
| 171 class CompoundB { |
| 172 var c; |
| 173 CompoundB(this.c); |
| 174 } |
| 175 |
| 176 class CompoundC { |
| 177 var d; |
| 178 var root; |
| 179 CompoundC(this.d); |
| 180 } |
| 181 |
| 182 class NoopSink { |
| 183 const NoopSink(); |
| 184 call(val) { } |
| 185 } |
| 186 |
| 187 testCompound1() { |
| 188 f(d, [sink = const NoopSink()]) { |
| 189 var c = new CompoundC(d); |
| 190 var a = new CompoundA(new CompoundB(c)); |
| 191 sink(a); |
| 192 return c.d; |
| 193 } |
| 194 |
| 195 Expect.equals(0.1, f(0.1)); |
| 196 for (var i = 0; i < 100; i++) f(0.1); |
| 197 Expect.equals(0.1, f(0.1)); |
| 198 Expect.equals(0.1, f(0.1, (val) { |
| 199 Expect.isTrue(val is CompoundA); |
| 200 Expect.isTrue(val.b is CompoundB); |
| 201 Expect.isTrue(val.b.c is CompoundC); |
| 202 Expect.isNull(val.b.c.root); |
| 203 Expect.equals(0.1, val.b.c.d); |
| 204 })); |
| 205 } |
| 206 |
| 207 |
| 208 testCompound2() { |
| 209 f(d, [sink = const NoopSink()]) { |
| 210 var c = new CompoundC(d); |
| 211 var a = new CompoundA(new CompoundB(c)); |
| 212 c.root = a; |
| 213 sink(a); |
| 214 return c.d; |
| 215 } |
| 216 |
| 217 Expect.equals(0.1, f(0.1)); |
| 218 for (var i = 0; i < 100; i++) f(0.1); |
| 219 Expect.equals(0.1, f(0.1)); |
| 220 Expect.equals(0.1, f(0.1, (val) { |
| 221 Expect.isTrue(val is CompoundA); |
| 222 Expect.isTrue(val.b is CompoundB); |
| 223 Expect.isTrue(val.b.c is CompoundC); |
| 224 Expect.equals(val, val.b.c.root); |
| 225 Expect.equals(0.1, val.b.c.d); |
| 226 })); |
| 227 } |
| 228 |
| 229 |
| 230 testCompound3() { |
| 231 f(d, [sink = const NoopSink()]) { |
| 232 var c = new CompoundC(d); |
| 233 c.root = c; |
| 234 sink(c); |
| 235 return c.d; |
| 236 } |
| 237 |
| 238 Expect.equals(0.1, f(0.1)); |
| 239 for (var i = 0; i < 100; i++) f(0.1); |
| 240 Expect.equals(0.1, f(0.1)); |
| 241 Expect.equals(0.1, f(0.1, (val) { |
| 242 Expect.isTrue(val is CompoundC); |
| 243 Expect.equals(val, val.root); |
| 244 Expect.equals(0.1, val.d); |
| 245 })); |
| 246 } |
| 247 |
| 248 |
| 249 testCompound4() { |
| 250 f(d, [sink = const NoopSink()]) { |
| 251 var c = new CompoundC(d); |
| 252 c.root = c; |
| 253 for (var i = 0; i < 10; i++) { |
| 254 c.d += 1.0; |
| 255 } |
| 256 sink(c); |
| 257 return c.d - 1.0 * 10; |
| 258 } |
| 259 |
| 260 Expect.equals(1.0, f(1.0)); |
| 261 for (var i = 0; i < 100; i++) f(1.0); |
| 262 Expect.equals(1.0, f(1.0)); |
| 263 Expect.equals(1.0, f(1.0, (val) { |
| 264 Expect.isTrue(val is CompoundC); |
| 265 Expect.equals(val, val.root); |
| 266 Expect.equals(11.0, val.d); |
| 267 })); |
| 268 } |
| 269 |
| 270 |
166 main() { | 271 main() { |
167 var c = new C(new Point(0.1, 0.2)); | 272 var c = new C(new Point(0.1, 0.2)); |
168 | 273 |
169 // Compute initial values. | 274 // Compute initial values. |
170 final x0 = test1(c, 11.11, 22.22); | 275 final x0 = test1(c, 11.11, 22.22); |
171 var fc = new Cx4(new Pointx4(new Float32x4(1.0, 1.0, 1.0, 1.0), | 276 var fc = new Cx4(new Pointx4(new Float32x4(1.0, 1.0, 1.0, 1.0), |
172 new Float32x4(1.0, 1.0, 1.0, 1.0))); | 277 new Float32x4(1.0, 1.0, 1.0, 1.0))); |
173 final fx0 = test1x4(fc, new Float32x4(1.0, 1.0, 1.0, 1.0), | 278 final fx0 = test1x4(fc, new Float32x4(1.0, 1.0, 1.0, 1.0), |
174 new Float32x4(1.0, 1.0, 1.0, 1.0), | 279 new Float32x4(1.0, 1.0, 1.0, 1.0), |
175 new Float32x4(1.0, 1.0, 1.0, 1.0), | 280 new Float32x4(1.0, 1.0, 1.0, 1.0), |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 | 318 |
214 // Test that identity of materialized objects is preserved correctly and | 319 // Test that identity of materialized objects is preserved correctly and |
215 // no copies are materialized. | 320 // no copies are materialized. |
216 final z1 = testIdentity(c.p); | 321 final z1 = testIdentity(c.p); |
217 final z2 = testIdentity(new F(c.p)); | 322 final z2 = testIdentity(new F(c.p)); |
218 Expect.equals(z0, z1); | 323 Expect.equals(z0, z1); |
219 Expect.equals(z0, z2); | 324 Expect.equals(z0, z2); |
220 | 325 |
221 testFinalField(); | 326 testFinalField(); |
222 testVMField(); | 327 testVMField(); |
| 328 testCompound1(); |
| 329 testCompound2(); |
| 330 testCompound3(); |
| 331 testCompound4(); |
223 } | 332 } |
OLD | NEW |