1/*
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
19  private void inlinedForNull(Iterable it) {
20    if (it != null) {
21      // We're not inlining invoke-interface at the moment.
22      it.iterator();
23    }
24  }
25
26  private void inlinedForFalse(boolean value, Iterable it) {
27    if (value) {
28      // We're not inlining invoke-interface at the moment.
29      it.iterator();
30    }
31  }
32
33  /// CHECK-START: void Main.testInlinedForFalseInlined(java.lang.Iterable) inliner (before)
34  /// CHECK:                          InvokeStaticOrDirect
35
36  /// CHECK-START: void Main.testInlinedForFalseInlined(java.lang.Iterable) inliner (after)
37  /// CHECK-NOT:                      InvokeStaticOrDirect
38  /// CHECK-NOT:                      InvokeInterface
39
40  public void testInlinedForFalseInlined(Iterable it) {
41    inlinedForFalse(false, it);
42  }
43
44  /// CHECK-START: void Main.testInlinedForFalseNotInlined(java.lang.Iterable) inliner (before)
45  /// CHECK:                          InvokeStaticOrDirect
46
47  /// CHECK-START: void Main.testInlinedForFalseNotInlined(java.lang.Iterable) inliner (after)
48  /// CHECK:                          InvokeStaticOrDirect
49
50  public void testInlinedForFalseNotInlined(Iterable it) {
51    inlinedForFalse(true, it);
52  }
53
54  /// CHECK-START: void Main.testInlinedForNullInlined(java.lang.Iterable) inliner (before)
55  /// CHECK:                          InvokeStaticOrDirect
56
57  /// CHECK-START: void Main.testInlinedForNullInlined(java.lang.Iterable) inliner (after)
58  /// CHECK-NOT:                      InvokeStaticOrDirect
59  /// CHECK-NOT:                      InvokeInterface
60
61  public void testInlinedForNullInlined(Iterable it) {
62    inlinedForNull(null);
63  }
64
65  /// CHECK-START: void Main.testInlinedForNullNotInlined(java.lang.Iterable) inliner (before)
66  /// CHECK:                          InvokeStaticOrDirect
67
68  /// CHECK-START: void Main.testInlinedForNullNotInlined(java.lang.Iterable) inliner (after)
69  /// CHECK:                          InvokeStaticOrDirect
70
71  public void testInlinedForNullNotInlined(Iterable it) {
72    inlinedForNull(it);
73  }
74
75  public static void main(String[] args) {
76    Main m = new Main();
77    Iterable it = new Iterable() {
78      public java.util.Iterator iterator() { return null; }
79    };
80    m.testInlinedForFalseInlined(it);
81    m.testInlinedForFalseNotInlined(it);
82    m.testInlinedForNullInlined(it);
83    m.testInlinedForNullNotInlined(it);
84  }
85}
86