| 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 deoptimziation caused by lazy finalization. | 4 // Test deoptimziation caused by lazy finalization. |
| 5 // VMOptions=--optimization-counter-threshold=10 --no-use-osr | 5 // VMOptions=--optimization-counter-threshold=10 --no-use-osr --no-background-co
mpilation |
| 6 | 6 |
| 7 import "package:expect/expect.dart"; | 7 import "package:expect/expect.dart"; |
| 8 | 8 |
| 9 main() { | 9 main() { |
| 10 Expect.equals(20000, part1()); | 10 Expect.equals(20000, part1()); |
| 11 // Trigger lazy finalization of class B, which should invalidate | 11 // Trigger lazy finalization of class B, which should invalidate |
| 12 // optimized code for A.loop. | 12 // optimized code for A.loop. |
| 13 Expect.equals(-20000, part2()); | 13 Expect.equals(-20000, part2()); |
| 14 } | 14 } |
| 15 | 15 |
| 16 part1() { | 16 part1() { |
| 17 var a = new A(); | 17 var a = new A(); |
| 18 a.loop(); | 18 a.loop(); |
| 19 // Second invocation calls optimized code. | 19 // Second invocation calls optimized code. |
| 20 return a.loop(); | 20 return a.loop(); |
| 21 } | 21 } |
| 22 | 22 |
| 23 part2() { | 23 part2() { |
| 24 var b = new B(); | 24 var b = new B(); |
| 25 b.loop(); | 25 b.loop(); |
| 26 // Second invocation calls optimized code. | 26 // Second invocation calls optimized code. |
| 27 return b.loop(); | 27 return b.loop(); |
| 28 } | 28 } |
| 29 | 29 |
| 30 class A { | 30 class A { |
| 31 foo() => 2; | 31 foo() => 2; |
| 32 | 32 |
| 33 loop() { | 33 loop() { |
| 34 var sum = 0; | 34 var sum = 0; |
| 35 for (int i = 0; i < 10000; i++) { | 35 for (int i = 0; i < 10000; i++) { |
| 36 sum += foo(); | 36 sum += foo(); |
| 37 } | 37 } |
| 38 return sum; | 38 return sum; |
| 39 } | 39 } |
| 40 } | 40 } |
| 41 | 41 |
| 42 class Aa extends A { | 42 class Aa extends A { |
| 43 | 43 |
| 44 } | 44 } |
| 45 | 45 |
| 46 class B extends Aa { | 46 class B extends Aa { |
| 47 foo() => -2; | 47 foo() => -2; |
| 48 } | 48 } |
| OLD | NEW |