blob: 5763d89cf9cfa7d82d36b079313ad307694b2c4a [file] [log] [blame]
Nicolas Geoffray916cc1d2016-02-18 11:12:31 +00001/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17public class Main {
18 public static void main(String[] args) {
19 for (int i = 0; i < 20000; ++i) {
20 $noinline$testVoid(new Main());
21 $noinline$testVoid(new SubMain());
22 $noinline$testVoid(new SubSubMain());
23
24 $noinline$testWithReturnValue(new Main());
25 $noinline$testWithReturnValue(new SubMain());
26 $noinline$testWithReturnValue(new SubSubMain());
27
28 $noinline$testWithBackEdge(new Main());
29 $noinline$testWithBackEdge(new SubMain());
30 $noinline$testWithBackEdge(new SubSubMain());
31 }
32 }
33
34 public static void assertIdentical(Object expected, Object actual) {
35 if (expected != actual) {
36 throw new Error("Expected " + expected + ", got " + actual);
37 }
38 }
39
40 public static void $noinline$testVoid(Main m) {
41 if (doThrow) throw new Error("");
42 m.willInlineVoid();
43 m.willOnlyInlineForMainVoid();
44 }
45
46 public static void $noinline$testWithReturnValue(Main m) {
47 if (doThrow) throw new Error("");
48 assertIdentical(m.getClass(), m.willInlineWithReturnValue());
49 assertIdentical(m.getClass(), m.willOnlyInlineForMainWithReturnValue());
50 }
51
52 public static void $noinline$testWithBackEdge(Main m) {
53 if (doThrow) throw new Error("");
54 for (int i = 0; i < 10; ++i) {
55 m.willInlineVoid();
56 }
57 for (int i = 0; i < 10; ++i) {
58 m.willOnlyInlineForMainVoid();
59 }
60 }
61
62 public void willInlineVoid() {
63 }
64
65 public void willOnlyInlineForMainVoid() {
66 }
67
Andreas Gampe166aaee2016-07-18 08:27:23 -070068 public Class<?> willInlineWithReturnValue() {
Nicolas Geoffray916cc1d2016-02-18 11:12:31 +000069 return Main.class;
70 }
71
Andreas Gampe166aaee2016-07-18 08:27:23 -070072 public Class<?> willOnlyInlineForMainWithReturnValue() {
Nicolas Geoffray916cc1d2016-02-18 11:12:31 +000073 return Main.class;
74 }
75 public static boolean doThrow;
76}
77
78class SubMain extends Main {
79 public void willOnlyInlineForMainVoid() {
80 if (doThrow) throw new Error("");
81 }
82
83 public void willInlineVoid() {
84 }
85
Andreas Gampe166aaee2016-07-18 08:27:23 -070086 public Class<?> willInlineWithReturnValue() {
Nicolas Geoffray916cc1d2016-02-18 11:12:31 +000087 return SubMain.class;
88 }
89
Andreas Gampe166aaee2016-07-18 08:27:23 -070090 public Class<?> willOnlyInlineForMainWithReturnValue() {
Nicolas Geoffray916cc1d2016-02-18 11:12:31 +000091 return SubMain.class;
92 }
93}
94
95class SubSubMain extends SubMain {
Andreas Gampe166aaee2016-07-18 08:27:23 -070096 public Class<?> willInlineWithReturnValue() {
Nicolas Geoffray916cc1d2016-02-18 11:12:31 +000097 return SubSubMain.class;
98 }
99
Andreas Gampe166aaee2016-07-18 08:27:23 -0700100 public Class<?> willOnlyInlineForMainWithReturnValue() {
Nicolas Geoffray916cc1d2016-02-18 11:12:31 +0000101 return SubSubMain.class;
102 }
103}