1 /* 2 * Copyright (C) 2023 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 class Square { foo()18 public int foo() { return 0; } 19 } 20 21 class Circle extends Square { 22 @Override foo()23 public final int foo() { return 42; } 24 } 25 26 public class Main { assertEquals(int expected, int actual)27 public static void assertEquals(int expected, int actual) { 28 if (expected != actual) { 29 throw new Error("Expected " + expected + ", got " + actual); 30 } 31 } 32 main(String[] args)33 public static void main(String[] args) { 34 assertEquals(42, square(new Circle())); 35 assertEquals(42, circle(new Circle())); 36 } 37 38 /// CHECK-START: int Main.square(Circle) inliner (before) 39 /// CHECK: InvokeVirtual 40 41 /// CHECK-START: int Main.square(Circle) inliner (after) 42 /// CHECK-NOT: InvokeVirtual square(Circle c)43 static int square(Circle c) { 44 Square s = c; 45 return s.foo(); 46 } 47 48 /// CHECK-START: int Main.circle(Circle) inliner (before) 49 /// CHECK: InvokeVirtual 50 51 /// CHECK-START: int Main.circle(Circle) inliner (after) 52 /// CHECK-NOT: InvokeVirtual circle(Circle c)53 static int circle(Circle c) { 54 Circle s = c; 55 return s.foo(); 56 } 57 } 58