1*795d594fSAndroid Build Coastguard Worker; Copyright (C) 2021 The Android Open Source Project 2*795d594fSAndroid Build Coastguard Worker; 3*795d594fSAndroid Build Coastguard Worker; Licensed under the Apache License, Version 2.0 (the "License"); 4*795d594fSAndroid Build Coastguard Worker; you may not use this file except in compliance with the License. 5*795d594fSAndroid Build Coastguard Worker; You may obtain a copy of the License at 6*795d594fSAndroid Build Coastguard Worker; 7*795d594fSAndroid Build Coastguard Worker; http://www.apache.org/licenses/LICENSE-2.0 8*795d594fSAndroid Build Coastguard Worker; 9*795d594fSAndroid Build Coastguard Worker; Unless required by applicable law or agreed to in writing, software 10*795d594fSAndroid Build Coastguard Worker; distributed under the License is distributed on an "AS IS" BASIS, 11*795d594fSAndroid Build Coastguard Worker; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12*795d594fSAndroid Build Coastguard Worker; See the License for the specific language governing permissions and 13*795d594fSAndroid Build Coastguard Worker; limitations under the License. 14*795d594fSAndroid Build Coastguard Worker 15*795d594fSAndroid Build Coastguard Worker.class public Main 16*795d594fSAndroid Build Coastguard Worker.super java/lang/Object 17*795d594fSAndroid Build Coastguard Worker 18*795d594fSAndroid Build Coastguard Worker; Just do simple check that we remove the instance-of. Well formedness 19*795d594fSAndroid Build Coastguard Worker; checks will be done in gtests. 20*795d594fSAndroid Build Coastguard Worker;; CHECK-START: int Main.$noinline$test(boolean) instruction_simplifier (before) 21*795d594fSAndroid Build Coastguard Worker;; CHECK-DAG: LoadClass 22*795d594fSAndroid Build Coastguard Worker;; CHECK-DAG: LoadClass 23*795d594fSAndroid Build Coastguard Worker;; CHECK-DAG: InstanceOf 24*795d594fSAndroid Build Coastguard Worker; 25*795d594fSAndroid Build Coastguard Worker;; CHECK-START: int Main.$noinline$test(boolean) instruction_simplifier (after) 26*795d594fSAndroid Build Coastguard Worker;; CHECK-DAG: LoadClass 27*795d594fSAndroid Build Coastguard Worker;; CHECK-DAG: LoadClass 28*795d594fSAndroid Build Coastguard Worker; 29*795d594fSAndroid Build Coastguard Worker;; CHECK-START: int Main.$noinline$test(boolean) instruction_simplifier (after) 30*795d594fSAndroid Build Coastguard Worker;; CHECK-NOT: InstanceOf 31*795d594fSAndroid Build Coastguard Worker; 32*795d594fSAndroid Build Coastguard Worker;; CHECK-START: int Main.$noinline$test(boolean) instruction_simplifier$before_codegen (after) 33*795d594fSAndroid Build Coastguard Worker;; CHECK-NOT: InstanceFieldSet 34*795d594fSAndroid Build Coastguard Worker;; CHECK-NOT: InstanceFieldGet 35*795d594fSAndroid Build Coastguard Worker 36*795d594fSAndroid Build Coastguard Worker; public static int $noinline$test(boolean escape) { 37*795d594fSAndroid Build Coastguard Worker; Foo f = new Foo(); 38*795d594fSAndroid Build Coastguard Worker; f.intField = 7 39*795d594fSAndroid Build Coastguard Worker; if (escape) { 40*795d594fSAndroid Build Coastguard Worker; if (f instanceof Bar) { 41*795d594fSAndroid Build Coastguard Worker; $noinline$escape(f); 42*795d594fSAndroid Build Coastguard Worker; } 43*795d594fSAndroid Build Coastguard Worker; } 44*795d594fSAndroid Build Coastguard Worker; return f.intField; 45*795d594fSAndroid Build Coastguard Worker; } 46*795d594fSAndroid Build Coastguard Worker.method public static $noinline$test(Z)I 47*795d594fSAndroid Build Coastguard Worker .limit stack 3 48*795d594fSAndroid Build Coastguard Worker new Foo 49*795d594fSAndroid Build Coastguard Worker ; Stack: [f] 50*795d594fSAndroid Build Coastguard Worker dup 51*795d594fSAndroid Build Coastguard Worker ; Stack: [f, f] 52*795d594fSAndroid Build Coastguard Worker invokespecial Foo/<init>()V 53*795d594fSAndroid Build Coastguard Worker ; Stack: [f] 54*795d594fSAndroid Build Coastguard Worker dup 55*795d594fSAndroid Build Coastguard Worker ; Stack: [f, f] 56*795d594fSAndroid Build Coastguard Worker ldc 7 57*795d594fSAndroid Build Coastguard Worker ; Stack: [f, f, 7] 58*795d594fSAndroid Build Coastguard Worker putfield Foo/intField I 59*795d594fSAndroid Build Coastguard Worker ; Stack: [f] 60*795d594fSAndroid Build Coastguard Worker iload_0 61*795d594fSAndroid Build Coastguard Worker ; Stack: [f, escape] 62*795d594fSAndroid Build Coastguard Worker ifeq finish 63*795d594fSAndroid Build Coastguard Worker ; Stack: [f] 64*795d594fSAndroid Build Coastguard Worker dup 65*795d594fSAndroid Build Coastguard Worker ; Stack: [f, f] 66*795d594fSAndroid Build Coastguard Worker ; NB Baz does not exist 67*795d594fSAndroid Build Coastguard Worker instanceof Baz 68*795d594fSAndroid Build Coastguard Worker ; Stack: [f, is_instance] 69*795d594fSAndroid Build Coastguard Worker ifeq finish 70*795d594fSAndroid Build Coastguard Worker ; Stack: [f] 71*795d594fSAndroid Build Coastguard Worker dup 72*795d594fSAndroid Build Coastguard Worker ; Stack: [f, f] 73*795d594fSAndroid Build Coastguard Worker invokestatic Main/$noinline$escape(Ljava/lang/Object;)V 74*795d594fSAndroid Build Coastguard Worker ; Stack: [f] 75*795d594fSAndroid Build Coastguard Workerfinish: ; Stack: [f] 76*795d594fSAndroid Build Coastguard Worker getfield Foo/intField I 77*795d594fSAndroid Build Coastguard Worker ; Stack: [f.intField] 78*795d594fSAndroid Build Coastguard Worker ireturn 79*795d594fSAndroid Build Coastguard Worker.end method 80*795d594fSAndroid Build Coastguard Worker 81*795d594fSAndroid Build Coastguard Worker.method public static $noinline$escape(Ljava/lang/Object;)V 82*795d594fSAndroid Build Coastguard Worker .limit stack 0 83*795d594fSAndroid Build Coastguard Worker return 84*795d594fSAndroid Build Coastguard Worker.end method 85*795d594fSAndroid Build Coastguard Worker 86*795d594fSAndroid Build Coastguard Worker; public static void main(String[] args) { 87*795d594fSAndroid Build Coastguard Worker; PrintStream out = System.out; 88*795d594fSAndroid Build Coastguard Worker; int i = $noinline$test(false); 89*795d594fSAndroid Build Coastguard Worker; if (i != 7) { 90*795d594fSAndroid Build Coastguard Worker; out.print("FAIL! GOT "); 91*795d594fSAndroid Build Coastguard Worker; out.println(i); 92*795d594fSAndroid Build Coastguard Worker; } 93*795d594fSAndroid Build Coastguard Worker; } 94*795d594fSAndroid Build Coastguard Worker.method public static main([Ljava/lang/String;)V 95*795d594fSAndroid Build Coastguard Worker .limit stack 5 96*795d594fSAndroid Build Coastguard Worker ; Stack: [] 97*795d594fSAndroid Build Coastguard Worker ; locals: [args] 98*795d594fSAndroid Build Coastguard Worker getstatic java/lang/System/out Ljava/io/PrintStream; 99*795d594fSAndroid Build Coastguard Worker ; Stack: [out] 100*795d594fSAndroid Build Coastguard Worker ; locals: [args] 101*795d594fSAndroid Build Coastguard Worker astore_0 102*795d594fSAndroid Build Coastguard Worker ; Stack: [] 103*795d594fSAndroid Build Coastguard Worker ; locals: [out] 104*795d594fSAndroid Build Coastguard Worker bipush 0 105*795d594fSAndroid Build Coastguard Worker ; Stack: [0] 106*795d594fSAndroid Build Coastguard Worker ; locals: [out] 107*795d594fSAndroid Build Coastguard Worker invokestatic Main/$noinline$test(Z)I 108*795d594fSAndroid Build Coastguard Worker ; Stack: [res] 109*795d594fSAndroid Build Coastguard Worker ; locals: [out] 110*795d594fSAndroid Build Coastguard Worker dup 111*795d594fSAndroid Build Coastguard Worker ; Stack: [res, res] 112*795d594fSAndroid Build Coastguard Worker ; locals: [out] 113*795d594fSAndroid Build Coastguard Worker bipush 7 114*795d594fSAndroid Build Coastguard Worker ; Stack: [res, res, 7] 115*795d594fSAndroid Build Coastguard Worker ; locals: [out] 116*795d594fSAndroid Build Coastguard Worker if_icmpeq finish 117*795d594fSAndroid Build Coastguard Worker ; Stack: [res] 118*795d594fSAndroid Build Coastguard Worker ; locals: [out] 119*795d594fSAndroid Build Coastguard Worker aload_0 120*795d594fSAndroid Build Coastguard Worker ; Stack: [res, out] 121*795d594fSAndroid Build Coastguard Worker ; locals: [out] 122*795d594fSAndroid Build Coastguard Worker dup2 123*795d594fSAndroid Build Coastguard Worker ; Stack: [res, out, res, out] 124*795d594fSAndroid Build Coastguard Worker ; locals: [out] 125*795d594fSAndroid Build Coastguard Worker ldc "FAIL! GOT " 126*795d594fSAndroid Build Coastguard Worker ; Stack: [res, out, res, out, "FAIL! GOT "] 127*795d594fSAndroid Build Coastguard Worker ; locals: [out] 128*795d594fSAndroid Build Coastguard Worker invokevirtual java/io/PrintStream/print(Ljava/lang/String;)V 129*795d594fSAndroid Build Coastguard Worker ; Stack: [res, out, res] 130*795d594fSAndroid Build Coastguard Worker ; locals: [out] 131*795d594fSAndroid Build Coastguard Worker invokevirtual java/io/PrintStream/println(I)V 132*795d594fSAndroid Build Coastguard Worker ; Stack: [res] 133*795d594fSAndroid Build Coastguard Worker ; locals: [out] 134*795d594fSAndroid Build Coastguard Workerfinish: 135*795d594fSAndroid Build Coastguard Worker ; Stack: [res] 136*795d594fSAndroid Build Coastguard Worker ; locals: [out] 137*795d594fSAndroid Build Coastguard Worker return 138*795d594fSAndroid Build Coastguard Worker.end method 139