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 
17 public class Main {
18 
19   static boolean doThrow = false;
20 
inlinedForNull(Iterable it)21   private void inlinedForNull(Iterable it) {
22     if (it != null) {
23       // We're not inlining throw at the moment.
24       if (doThrow) { throw new Error(""); }
25     }
26   }
27 
inlinedForFalse(boolean value, Iterable it)28   private void inlinedForFalse(boolean value, Iterable it) {
29     if (value) {
30       // We're not inlining throw at the moment.
31       if (doThrow) { throw new Error(""); }
32     }
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 
testInlinedForFalseInlined(Iterable it)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 
testInlinedForFalseNotInlined(Iterable it)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 
testInlinedForNullInlined(Iterable it)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 
testInlinedForNullNotInlined(Iterable it)73   public void testInlinedForNullNotInlined(Iterable it) {
74     inlinedForNull(it);
75   }
76 
main(String[] args)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 }
88