1*795d594fSAndroid Build Coastguard Worker /* 2*795d594fSAndroid Build Coastguard Worker * Copyright (C) 2015 The Android Open Source Project 3*795d594fSAndroid Build Coastguard Worker * 4*795d594fSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*795d594fSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*795d594fSAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*795d594fSAndroid Build Coastguard Worker * 8*795d594fSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*795d594fSAndroid Build Coastguard Worker * 10*795d594fSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*795d594fSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*795d594fSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*795d594fSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*795d594fSAndroid Build Coastguard Worker * limitations under the License. 15*795d594fSAndroid Build Coastguard Worker */ 16*795d594fSAndroid Build Coastguard Worker 17*795d594fSAndroid Build Coastguard Worker public class Main { 18*795d594fSAndroid Build Coastguard Worker 19*795d594fSAndroid Build Coastguard Worker static boolean doThrow = false; 20*795d594fSAndroid Build Coastguard Worker inlinedForNull(Iterable it)21*795d594fSAndroid Build Coastguard Worker private void inlinedForNull(Iterable it) { 22*795d594fSAndroid Build Coastguard Worker if (it != null) { 23*795d594fSAndroid Build Coastguard Worker // We're not inlining throw at the moment. 24*795d594fSAndroid Build Coastguard Worker if (doThrow) { throw new Error(""); } 25*795d594fSAndroid Build Coastguard Worker } 26*795d594fSAndroid Build Coastguard Worker } 27*795d594fSAndroid Build Coastguard Worker inlinedForFalse(boolean value, Iterable it)28*795d594fSAndroid Build Coastguard Worker private void inlinedForFalse(boolean value, Iterable it) { 29*795d594fSAndroid Build Coastguard Worker if (value) { 30*795d594fSAndroid Build Coastguard Worker // We're not inlining throw at the moment. 31*795d594fSAndroid Build Coastguard Worker if (doThrow) { throw new Error(""); } 32*795d594fSAndroid Build Coastguard Worker } 33*795d594fSAndroid Build Coastguard Worker } 34*795d594fSAndroid Build Coastguard Worker 35*795d594fSAndroid Build Coastguard Worker /// CHECK-START: void Main.testInlinedForFalseInlined(java.lang.Iterable) inliner (before) 36*795d594fSAndroid Build Coastguard Worker /// CHECK: InvokeStaticOrDirect 37*795d594fSAndroid Build Coastguard Worker 38*795d594fSAndroid Build Coastguard Worker /// CHECK-START: void Main.testInlinedForFalseInlined(java.lang.Iterable) inliner (after) 39*795d594fSAndroid Build Coastguard Worker /// CHECK-NOT: InvokeStaticOrDirect 40*795d594fSAndroid Build Coastguard Worker /// CHECK-NOT: InvokeInterface 41*795d594fSAndroid Build Coastguard Worker testInlinedForFalseInlined(Iterable it)42*795d594fSAndroid Build Coastguard Worker public void testInlinedForFalseInlined(Iterable it) { 43*795d594fSAndroid Build Coastguard Worker inlinedForFalse(false, it); 44*795d594fSAndroid Build Coastguard Worker } 45*795d594fSAndroid Build Coastguard Worker 46*795d594fSAndroid Build Coastguard Worker /// CHECK-START: void Main.testInlinedForFalseNotInlined(java.lang.Iterable) inliner (before) 47*795d594fSAndroid Build Coastguard Worker /// CHECK: InvokeStaticOrDirect 48*795d594fSAndroid Build Coastguard Worker 49*795d594fSAndroid Build Coastguard Worker /// CHECK-START: void Main.testInlinedForFalseNotInlined(java.lang.Iterable) inliner (after) 50*795d594fSAndroid Build Coastguard Worker /// CHECK: InvokeStaticOrDirect 51*795d594fSAndroid Build Coastguard Worker testInlinedForFalseNotInlined(Iterable it)52*795d594fSAndroid Build Coastguard Worker public void testInlinedForFalseNotInlined(Iterable it) { 53*795d594fSAndroid Build Coastguard Worker inlinedForFalse(true, it); 54*795d594fSAndroid Build Coastguard Worker } 55*795d594fSAndroid Build Coastguard Worker 56*795d594fSAndroid Build Coastguard Worker /// CHECK-START: void Main.testInlinedForNullInlined(java.lang.Iterable) inliner (before) 57*795d594fSAndroid Build Coastguard Worker /// CHECK: InvokeStaticOrDirect 58*795d594fSAndroid Build Coastguard Worker 59*795d594fSAndroid Build Coastguard Worker /// CHECK-START: void Main.testInlinedForNullInlined(java.lang.Iterable) inliner (after) 60*795d594fSAndroid Build Coastguard Worker /// CHECK-NOT: InvokeStaticOrDirect 61*795d594fSAndroid Build Coastguard Worker /// CHECK-NOT: InvokeInterface 62*795d594fSAndroid Build Coastguard Worker testInlinedForNullInlined(Iterable it)63*795d594fSAndroid Build Coastguard Worker public void testInlinedForNullInlined(Iterable it) { 64*795d594fSAndroid Build Coastguard Worker inlinedForNull(null); 65*795d594fSAndroid Build Coastguard Worker } 66*795d594fSAndroid Build Coastguard Worker 67*795d594fSAndroid Build Coastguard Worker /// CHECK-START: void Main.testInlinedForNullNotInlined(java.lang.Iterable) inliner (before) 68*795d594fSAndroid Build Coastguard Worker /// CHECK: InvokeStaticOrDirect 69*795d594fSAndroid Build Coastguard Worker 70*795d594fSAndroid Build Coastguard Worker /// CHECK-START: void Main.testInlinedForNullNotInlined(java.lang.Iterable) inliner (after) 71*795d594fSAndroid Build Coastguard Worker /// CHECK: InvokeStaticOrDirect 72*795d594fSAndroid Build Coastguard Worker testInlinedForNullNotInlined(Iterable it)73*795d594fSAndroid Build Coastguard Worker public void testInlinedForNullNotInlined(Iterable it) { 74*795d594fSAndroid Build Coastguard Worker inlinedForNull(it); 75*795d594fSAndroid Build Coastguard Worker } 76*795d594fSAndroid Build Coastguard Worker main(String[] args)77*795d594fSAndroid Build Coastguard Worker public static void main(String[] args) { 78*795d594fSAndroid Build Coastguard Worker Main m = new Main(); 79*795d594fSAndroid Build Coastguard Worker Iterable it = new Iterable() { 80*795d594fSAndroid Build Coastguard Worker public java.util.Iterator iterator() { return null; } 81*795d594fSAndroid Build Coastguard Worker }; 82*795d594fSAndroid Build Coastguard Worker m.testInlinedForFalseInlined(it); 83*795d594fSAndroid Build Coastguard Worker m.testInlinedForFalseNotInlined(it); 84*795d594fSAndroid Build Coastguard Worker m.testInlinedForNullInlined(it); 85*795d594fSAndroid Build Coastguard Worker m.testInlinedForNullNotInlined(it); 86*795d594fSAndroid Build Coastguard Worker } 87*795d594fSAndroid Build Coastguard Worker } 88