blob: 07709ea216e29f9be76f04d88da98bf8a13eeb81 [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 {
Nicolas Geoffrayec068092021-05-10 17:28:32 +000035 testInterfaceToDirectCall();
Nicolas Geoffrayfdb7d632017-02-08 15:07:18 +000036 } 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
Nicolas Geoffrayec068092021-05-10 17:28:32 +000056 /// CHECK-START: void Main.testInterfaceToDirectCall() inliner (before)
Nicolas Geoffray5bf7bac2016-07-06 14:18:23 +000057 /// CHECK: InvokeStaticOrDirect method_name:Main.methodWithInvokeInterface
58
Nicolas Geoffrayec068092021-05-10 17:28:32 +000059 /// CHECK-START: void Main.testInterfaceToDirectCall() inliner (before)
Nicolas Geoffray5bf7bac2016-07-06 14:18:23 +000060 /// CHECK-NOT: InvokeInterface
61
Nicolas Geoffrayec068092021-05-10 17:28:32 +000062 /// CHECK-START: void Main.testInterfaceToDirectCall() inliner (after)
63 /// CHECK: InvokeStaticOrDirect method_name:Main.doCall
Nicolas Geoffray5bf7bac2016-07-06 14:18:23 +000064
Nicolas Geoffrayec068092021-05-10 17:28:32 +000065 /// CHECK-START: void Main.testInterfaceToDirectCall() inliner (after)
66 /// CHECK-NOT: InvokeVirtual
Nicolas Geoffray5bf7bac2016-07-06 14:18:23 +000067 /// CHECK-NOT: InvokeInterface
Nicolas Geoffrayec068092021-05-10 17:28:32 +000068 public static void testInterfaceToDirectCall() {
Nicolas Geoffray5bf7bac2016-07-06 14:18:23 +000069 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}