1 /* 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 17 public 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 68 public Class<?> willInlineWithReturnValue() { 69 return Main.class; 70 } 71 72 public Class<?> willOnlyInlineForMainWithReturnValue() { 73 return Main.class; 74 } 75 public static boolean doThrow; 76 } 77 78 class SubMain extends Main { 79 public void willOnlyInlineForMainVoid() { 80 if (doThrow) throw new Error(""); 81 } 82 83 public void willInlineVoid() { 84 } 85 86 public Class<?> willInlineWithReturnValue() { 87 return SubMain.class; 88 } 89 90 public Class<?> willOnlyInlineForMainWithReturnValue() { 91 return SubMain.class; 92 } 93 } 94 95 class SubSubMain extends SubMain { 96 public Class<?> willInlineWithReturnValue() { 97 return SubSubMain.class; 98 } 99 100 public Class<?> willOnlyInlineForMainWithReturnValue() { 101 return SubSubMain.class; 102 } 103 } 104