blob: 249b7781f0c1dbff01a1133c22e75bbfc885e6aa [file] [log] [blame]
Nicolas Geoffray5bf7bac2016-07-06 14:18:23 +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 final class Main implements Interface {
18
19 static void methodWithInvokeInterface(Interface interf) {
20 interf.doCall();
21 }
22
23 public void doCall() {
Nicolas Geoffrayfdb7d632017-02-08 15:07:18 +000024 // We do not inline methods that always throw.
25 throw new Error("");
Nicolas Geoffray5bf7bac2016-07-06 14:18:23 +000026 }
27
28 public static void main(String[] args) {
Nicolas Geoffrayfdb7d632017-02-08 15:07:18 +000029 try {
30 testInlineInterfaceCall();
31 } catch (Error e) {
32 // Expected
33 }
34 try {
35 testInterfaceToVirtualCall();
36 } catch (Error e) {
37 // Expected.
38 }
Nicolas Geoffray5bf7bac2016-07-06 14:18:23 +000039 }
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
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
68 public static void testInterfaceToVirtualCall() {
69 methodWithInvokeInterface(m);
70 }
71
72 static Interface itf = new Main();
73 static Main m = new Main();
Nicolas Geoffray5bf7bac2016-07-06 14:18:23 +000074}
75
76interface Interface {
77 public void doCall();
78}