| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | |
| 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. | |
| 4 | |
| 5 // This is a test for deoptimization infrastructure and to reproduce the | |
| 6 // failure from bug 5442338. | |
| 7 | |
| 8 main() { | |
| 9 warmup(); | |
| 10 runTest(); | |
| 11 } | |
| 12 | |
| 13 // Create a situation where method 'call' is optimized for using class A | |
| 14 // when calling foo. | |
| 15 warmup() { | |
| 16 List a = [ new A(), new A(), new A(), new A()]; | |
| 17 var res = 0; | |
| 18 for (int i = 0; i < 2000; i++) { | |
| 19 res = call(a, 0); | |
| 20 } | |
| 21 Expect.equals(10, res); | |
| 22 } | |
| 23 | |
| 24 | |
| 25 // Create a situation where several optimized frames of 'call' are on stack | |
| 26 // when deoptimization occurs because B.foo is called. After the first | |
| 27 // deoptimization, several optimized frames of 'call' are still on stack and | |
| 28 // some of them will be deoptimized. | |
| 29 runTest() { | |
| 30 List a = [ new A(), new A(), new B(), new A(), new B(), new B()]; | |
| 31 var res = call(a, 0); | |
| 32 Expect.equals(35, res); | |
| 33 } | |
| 34 | |
| 35 // This method will be optimized for using class A when calling 'foo' and | |
| 36 // later will be deoptimized because B.foo is required. | |
| 37 call(List a, int n) { | |
| 38 if (n < a.length) { | |
| 39 var sum = call(a, n + 1); | |
| 40 for (int i = n; i < a.length; i++) { | |
| 41 sum += a[i].foo(); | |
| 42 } | |
| 43 return sum; | |
| 44 } | |
| 45 return 0; | |
| 46 } | |
| 47 | |
| 48 | |
| 49 class A { | |
| 50 foo() { return 1; } | |
| 51 } | |
| 52 | |
| 53 | |
| 54 class B { | |
| 55 foo() { return 2; } | |
| 56 } | |
| OLD | NEW |