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 final class Main implements Interface { 18 methodWithInvokeInterface(Interface interf)19 static void methodWithInvokeInterface(Interface interf) { 20 interf.doCall(); 21 } 22 doCall()23 public void doCall() { 24 // We do not inline methods that always throw. 25 throw new Error(""); 26 } 27 main(String[] args)28 public static void main(String[] args) { 29 try { 30 testInlineInterfaceCall(); 31 } catch (Error e) { 32 // Expected 33 } 34 try { 35 testInterfaceToVirtualCall(); 36 } catch (Error e) { 37 // Expected. 38 } 39 } 40 41 /// CHECK-START: void Main.testInlineInterfaceCall() inliner (before) 42 /// CHECK: InvokeStaticOrDirect method_name:Main.methodWithInvokeInterface 43 44 /// CHECK-START: void Main.testInlineInterfaceCall() inliner (before) 45 /// CHECK-NOT: InvokeInterface 46 47 /// CHECK-START: void Main.testInlineInterfaceCall() inliner (after) 48 /// CHECK: InvokeInterface method_name:Interface.doCall 49 50 /// CHECK-START: void Main.testInlineInterfaceCall() inliner (after) 51 /// CHECK-NOT: InvokeStaticOrDirect testInlineInterfaceCall()52 public static void testInlineInterfaceCall() { 53 methodWithInvokeInterface(itf); 54 } 55 56 /// CHECK-START: void Main.testInterfaceToVirtualCall() inliner (before) 57 /// CHECK: InvokeStaticOrDirect method_name:Main.methodWithInvokeInterface 58 59 /// CHECK-START: void Main.testInterfaceToVirtualCall() inliner (before) 60 /// CHECK-NOT: InvokeInterface 61 62 /// CHECK-START: void Main.testInterfaceToVirtualCall() inliner (after) 63 /// CHECK: InvokeVirtual method_name:Main.doCall 64 65 /// CHECK-START: void Main.testInterfaceToVirtualCall() inliner (after) 66 /// CHECK-NOT: InvokeStaticOrDirect 67 /// CHECK-NOT: InvokeInterface testInterfaceToVirtualCall()68 public static void testInterfaceToVirtualCall() { 69 methodWithInvokeInterface(m); 70 } 71 72 static Interface itf = new Main(); 73 static Main m = new Main(); 74 } 75 76 interface Interface { doCall()77 public void doCall(); 78 } 79