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
36; public static int $noinline$test(boolean escape) {
37;   Foo f = new Foo();
38;   f.intField = 7
39;   if (escape) {
40;     if (f instanceof Bar) {
41;       $noinline$escape(f);
42;     }
43;   }
44;   return f.intField;
45; }
46.method public static $noinline$test(Z)I
47  .limit stack 3
48  new Foo
49  ; Stack: [f]
50  dup
51  ; Stack: [f, f]
52  invokespecial Foo/<init>()V
53  ; Stack: [f]
54  dup
55  ; Stack: [f, f]
56  ldc 7
57  ; Stack: [f, f, 7]
58  putfield Foo/intField I
59  ; Stack: [f]
60  iload_0
61  ; Stack: [f, escape]
62  ifeq finish
63  ; Stack: [f]
64  dup
65  ; Stack: [f, f]
66  ; NB Baz does not exist
67  instanceof Baz
68  ; Stack: [f, is_instance]
69  ifeq finish
70  ; Stack: [f]
71  dup
72  ; Stack: [f, f]
73  invokestatic Main/$noinline$escape(Ljava/lang/Object;)V
74  ; Stack: [f]
75finish:   ; Stack: [f]
76  getfield Foo/intField I
77  ; Stack: [f.intField]
78  ireturn
79.end method
80
81.method public static $noinline$escape(Ljava/lang/Object;)V
82  .limit stack 0
83  return
84.end method
85
86; public static void main(String[] args) {
87;   PrintStream out = System.out;
88;   int i = $noinline$test(false);
89;   if (i != 7) {
90;     out.print("FAIL! GOT ");
91;     out.println(i);
92;   }
93; }
94.method public static main([Ljava/lang/String;)V
95  .limit stack 5
96  ; Stack: []
97  ; locals: [args]
98  getstatic java/lang/System/out Ljava/io/PrintStream;
99  ; Stack: [out]
100  ; locals: [args]
101  astore_0
102  ; Stack: []
103  ; locals: [out]
104  bipush 0
105  ; Stack: [0]
106  ; locals: [out]
107  invokestatic Main/$noinline$test(Z)I
108  ; Stack: [res]
109  ; locals: [out]
110  dup
111  ; Stack: [res, res]
112  ; locals: [out]
113  bipush 7
114  ; Stack: [res, res, 7]
115  ; locals: [out]
116  if_icmpeq finish
117  ; Stack: [res]
118  ; locals: [out]
119  aload_0
120  ; Stack: [res, out]
121  ; locals: [out]
122  dup2
123  ; Stack: [res, out, res, out]
124  ; locals: [out]
125  ldc "FAIL! GOT "
126  ; Stack: [res, out, res, out, "FAIL! GOT "]
127  ; locals: [out]
128  invokevirtual java/io/PrintStream/print(Ljava/lang/String;)V
129  ; Stack: [res, out, res]
130  ; locals: [out]
131  invokevirtual java/io/PrintStream/println(I)V
132  ; Stack: [res]
133  ; locals: [out]
134finish:
135  ; Stack: [res]
136  ; locals: [out]
137  return
138.end method
139