1 /* 2 * Copyright (C) 2017 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 19 /// CHECK-START: int Main.bar(Main) inliner (before) 20 /// CHECK: InvokeVirtual 21 /// CHECK: InvokeVirtual 22 23 /// CHECK-START: int Main.bar(Main) inliner (after) 24 /// CHECK-NOT: InvokeVirtual bar(Main m)25 public static int bar(Main m) { 26 if (m.getClass() == Main.class) { 27 return m.foo(); 28 } 29 return 4; 30 } 31 foo()32 public int foo() { 33 return 42; 34 } 35 36 /// CHECK-START: boolean Main.classEquality1() instruction_simplifier$after_inlining (before) 37 /// CHECK-DAG: <<Eq:z\d+>> {{Equal|NotEqual}} 38 /// CHECK-DAG: <<Select:i\d+>> Select [{{i\d+}},{{i\d+}},<<Eq>>] 39 /// CHECK-DAG: Return [<<Select>>] 40 41 /// CHECK-START: boolean Main.classEquality1() instruction_simplifier$after_inlining (after) 42 /// CHECK-DAG: <<Constant:i\d+>> IntConstant 1 43 /// CHECK-DAG: Return [<<Constant>>] classEquality1()44 public static boolean classEquality1() { 45 return new Main().getClass() == Main.class; 46 } 47 48 /// CHECK-START: boolean Main.classEquality2() instruction_simplifier$after_inlining (before) 49 /// CHECK-DAG: <<Eq:z\d+>> {{Equal|NotEqual}} 50 /// CHECK-DAG: <<Select:i\d+>> Select [{{i\d+}},{{i\d+}},<<Eq>>] 51 /// CHECK-DAG: Return [<<Select>>] 52 53 /// CHECK-START: boolean Main.classEquality2() instruction_simplifier$after_inlining (after) 54 /// CHECK-DAG: <<Constant:i\d+>> IntConstant 0 55 /// CHECK-DAG: Return [<<Constant>>] classEquality2()56 public static boolean classEquality2() { 57 Object o = new SubMain(); 58 return o.getClass() == Main.class; 59 } 60 61 /// CHECK-START: boolean Main.classEquality3() instruction_simplifier$after_inlining (before) 62 /// CHECK-DAG: <<Eq:z\d+>> {{Equal|NotEqual}} 63 /// CHECK-DAG: <<Select:i\d+>> Select [{{i\d+}},{{i\d+}},<<Eq>>] 64 /// CHECK-DAG: Return [<<Select>>] 65 66 /// CHECK-START: boolean Main.classEquality3() instruction_simplifier$after_inlining (after) 67 /// CHECK-DAG: <<Constant:i\d+>> IntConstant 0 68 /// CHECK-DAG: Return [<<Constant>>] classEquality3()69 public static boolean classEquality3() { 70 return new Main().getClass() != Main.class; 71 } 72 73 /// CHECK-START: boolean Main.classEquality4() instruction_simplifier$after_inlining (before) 74 /// CHECK-DAG: <<Eq:z\d+>> {{Equal|NotEqual}} 75 /// CHECK-DAG: <<Select:i\d+>> Select [{{i\d+}},{{i\d+}},<<Eq>>] 76 /// CHECK-DAG: Return [<<Select>>] 77 78 /// CHECK-START: boolean Main.classEquality4() instruction_simplifier$after_inlining (after) 79 /// CHECK-DAG: <<Constant:i\d+>> IntConstant 1 80 /// CHECK-DAG: Return [<<Constant>>] classEquality4()81 public static boolean classEquality4() { 82 Object o = new SubMain(); 83 return o.getClass() != Main.class; 84 } 85 main(String[] args)86 public static void main(String[] args) { 87 int actual = bar(new Main()); 88 if (actual != 42) { 89 throw new Error("Expected 42, got " + actual); 90 } 91 actual = bar(new SubMain()); 92 if (actual != 4) { 93 throw new Error("Expected 4, got " + actual); 94 } 95 } 96 } 97 98 class SubMain extends Main { 99 } 100