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 | 4 |
5 // VMOptions=--optimization_counter_threshold=10 --no-background-compilation | 5 // VMOptions=--optimization_counter_threshold=10 --no-background-compilation |
6 | 6 |
7 import "package:expect/expect.dart"; | |
8 | |
9 // This test tries to verify that we produce the correct stack trace when | 7 // This test tries to verify that we produce the correct stack trace when |
10 // throwing exceptions even when functions are inlined. | 8 // throwing exceptions even when functions are inlined. |
11 // The test invokes a bunch of functions and then does a throw. There is a | 9 // The test invokes a bunch of functions and then does a throw. There is a |
12 // catch at the outer function which uses the stack trace produced to return | 10 // catch at the outer function which uses the stack trace produced to return |
13 // a string. The test then verifies that the stack trace contains each | 11 // a string. The test then verifies that the stack trace contains each |
14 // method in the invocation chain. The test is run during warmup to ensure | 12 // method in the invocation chain. The test is run during warmup to ensure |
15 // unoptimized code produces the correct result and is then run | 13 // unoptimized code produces the correct result and is then run |
16 // in a loop to ensure optimization kicks in and some inlining is done. | 14 // in a loop to ensure optimization kicks in and some inlining is done. |
17 // Note: it appears that functions which have a throw are not inlined (func4) | 15 // Note: it appears that functions which have a throw are not inlined (func4) |
18 // and functions that have try/catch in them are not optimized (func1). | 16 // and functions that have try/catch in them are not optimized (func1). |
19 // func2 is not inlined as func1 has not been optimized. | 17 // func2 is not inlined as func1 has not been optimized. |
20 | 18 |
21 class Test { | 19 class Test { |
22 String func1(var k) { | 20 String func1(var k) { |
23 try { | 21 try { |
24 for (var i = 0; i <= 50; i++) { | 22 for (var i = 0; i <= 50; i++) { |
25 func2(i * k); | 23 func2(i * k); |
26 } | 24 } |
27 return ""; | 25 return ""; |
28 } catch (e, stacktrace) { | 26 } catch (e, stacktrace) { |
29 var result = e + stacktrace.toString(); | 27 var result = e + "\n" + stacktrace.toString(); |
30 return result; | 28 return result; |
31 } | 29 } |
32 } | 30 } |
33 int func2(var i) { | 31 int func2(var i) { |
34 var result = 0; | 32 var result = 0; |
35 for (var k = 0; k <= 10; k++) { | 33 for (var k = 0; k <= 10; k++) { |
36 result += func3(i + k); | 34 result += func3(i + k); |
37 } | 35 } |
38 return result; | 36 return result; |
39 } | 37 } |
(...skipping 10 matching lines...) Expand all Loading... |
50 result += func5(i + j); | 48 result += func5(i + j); |
51 } | 49 } |
52 return result; | 50 return result; |
53 } | 51 } |
54 int func5(var i) { | 52 int func5(var i) { |
55 if (i >= 520) throw "show me inlined functions"; | 53 if (i >= 520) throw "show me inlined functions"; |
56 return i; | 54 return i; |
57 } | 55 } |
58 } | 56 } |
59 | 57 |
| 58 expectHasSubstring(String string, String substring) { |
| 59 if (!string.contains(substring)) { |
| 60 var sb = new StringBuffer(); |
| 61 sb.writeln("Expect string:"); |
| 62 sb.writeln(string); |
| 63 sb.writeln("To have substring:"); |
| 64 sb.writeln(substring); |
| 65 throw new Exception(sb.toString()); |
| 66 } |
| 67 } |
| 68 |
60 main() { | 69 main() { |
61 var x = new Test(); | 70 var x = new Test(); |
62 var result = x.func1(100000); | 71 var result = x.func1(100000); |
63 Expect.isTrue(result.contains("show me inlined functions")); | 72 expectHasSubstring(result, "show me inlined functions"); |
64 Expect.isTrue(result.contains("Test.func1")); | 73 expectHasSubstring(result, "Test.func1"); |
65 Expect.isTrue(result.contains("Test.func2")); | 74 expectHasSubstring(result, "Test.func2"); |
66 Expect.isTrue(result.contains("Test.func3")); | 75 expectHasSubstring(result, "Test.func3"); |
67 Expect.isTrue(result.contains("Test.func4")); | 76 expectHasSubstring(result, "Test.func4"); |
68 Expect.isTrue(result.contains("Test.func")); | 77 expectHasSubstring(result, "Test.func5"); |
69 for (var i = 0; i <= 10; i++) { | 78 for (var i = 0; i <= 10; i++) { |
70 result = x.func1(i); | 79 result = x.func1(i); |
71 } | 80 } |
72 Expect.isTrue(result.contains("show me inlined functions")); | 81 expectHasSubstring(result, "show me inlined functions"); |
73 Expect.isTrue(result.contains("Test.func1")); | 82 expectHasSubstring(result, "Test.func1"); |
74 Expect.isTrue(result.contains("Test.func2")); | 83 expectHasSubstring(result, "Test.func2"); |
75 Expect.isTrue(result.contains("Test.func3")); | 84 expectHasSubstring(result, "Test.func3"); |
76 Expect.isTrue(result.contains("Test.func4")); | 85 expectHasSubstring(result, "Test.func4"); |
77 Expect.isTrue(result.contains("Test.func5")); | 86 expectHasSubstring(result, "Test.func5"); |
78 } | 87 } |
OLD | NEW |