blob: bf64c3bb3678c8ff1ee716d58580ec2b865496ec [file] [log] [blame]
Vladimir Marko9e23df52015-11-10 17:14:35 +00001/*
2 * Copyright (C) 2015 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 class Main {
18
Nicolas Geoffray5bf7bac2016-07-06 14:18:23 +000019 static boolean doThrow = false;
20
Vladimir Marko9e23df52015-11-10 17:14:35 +000021 private void inlinedForNull(Iterable it) {
22 if (it != null) {
Nicolas Geoffray5bf7bac2016-07-06 14:18:23 +000023 // We're not inlining throw at the moment.
24 if (doThrow) { throw new Error(""); }
Vladimir Marko9e23df52015-11-10 17:14:35 +000025 }
26 }
27
28 private void inlinedForFalse(boolean value, Iterable it) {
29 if (value) {
Nicolas Geoffray5bf7bac2016-07-06 14:18:23 +000030 // We're not inlining throw at the moment.
31 if (doThrow) { throw new Error(""); }
Vladimir Marko9e23df52015-11-10 17:14:35 +000032 }
33 }
34
35 /// CHECK-START: void Main.testInlinedForFalseInlined(java.lang.Iterable) inliner (before)
36 /// CHECK: InvokeStaticOrDirect
37
38 /// CHECK-START: void Main.testInlinedForFalseInlined(java.lang.Iterable) inliner (after)
39 /// CHECK-NOT: InvokeStaticOrDirect
40 /// CHECK-NOT: InvokeInterface
41
42 public void testInlinedForFalseInlined(Iterable it) {
43 inlinedForFalse(false, it);
44 }
45
46 /// CHECK-START: void Main.testInlinedForFalseNotInlined(java.lang.Iterable) inliner (before)
47 /// CHECK: InvokeStaticOrDirect
48
49 /// CHECK-START: void Main.testInlinedForFalseNotInlined(java.lang.Iterable) inliner (after)
50 /// CHECK: InvokeStaticOrDirect
51
52 public void testInlinedForFalseNotInlined(Iterable it) {
53 inlinedForFalse(true, it);
54 }
55
56 /// CHECK-START: void Main.testInlinedForNullInlined(java.lang.Iterable) inliner (before)
57 /// CHECK: InvokeStaticOrDirect
58
59 /// CHECK-START: void Main.testInlinedForNullInlined(java.lang.Iterable) inliner (after)
60 /// CHECK-NOT: InvokeStaticOrDirect
61 /// CHECK-NOT: InvokeInterface
62
63 public void testInlinedForNullInlined(Iterable it) {
64 inlinedForNull(null);
65 }
66
67 /// CHECK-START: void Main.testInlinedForNullNotInlined(java.lang.Iterable) inliner (before)
68 /// CHECK: InvokeStaticOrDirect
69
70 /// CHECK-START: void Main.testInlinedForNullNotInlined(java.lang.Iterable) inliner (after)
71 /// CHECK: InvokeStaticOrDirect
72
73 public void testInlinedForNullNotInlined(Iterable it) {
74 inlinedForNull(it);
75 }
76
77 public static void main(String[] args) {
78 Main m = new Main();
79 Iterable it = new Iterable() {
80 public java.util.Iterator iterator() { return null; }
81 };
82 m.testInlinedForFalseInlined(it);
83 m.testInlinedForFalseNotInlined(it);
84 m.testInlinedForNullInlined(it);
85 m.testInlinedForNullNotInlined(it);
86 }
87}