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