blob: 9a85c812497fabb08da2eaee856f454f1a151c3f [file] [log] [blame]
Vladimir Markobe10e8e2016-01-22 12:09:44 +00001/*
2 * Copyright (C) 2016 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
17public class Main {
18 /// CHECK-START: void Main.staticNop() inliner (before)
19 /// CHECK: InvokeStaticOrDirect
20
21 /// CHECK-START: void Main.staticNop() inliner (after)
22 /// CHECK-NOT: InvokeStaticOrDirect
23
24 public static void staticNop() {
25 Second.staticNop(11);
26 }
27
28 /// CHECK-START: void Main.nop(Second) inliner (before)
29 /// CHECK: InvokeVirtual
30
31 /// CHECK-START: void Main.nop(Second) inliner (after)
32 /// CHECK-NOT: InvokeVirtual
33
34 public static void nop(Second s) {
35 s.nop();
36 }
37
38 /// CHECK-START: java.lang.Object Main.staticReturnArg2(java.lang.String) inliner (before)
39 /// CHECK-DAG: <<Value:l\d+>> ParameterValue
40 /// CHECK-DAG: <<Ignored:i\d+>> IntConstant 77
41 /// CHECK-DAG: <<ClinitCk:l\d+>> ClinitCheck
42 /// CHECK-DAG: <<Invoke:l\d+>> InvokeStaticOrDirect [<<Ignored>>,<<Value>>,<<ClinitCk>>]
43 /// CHECK-DAG: Return [<<Invoke>>]
44
45 /// CHECK-START: java.lang.Object Main.staticReturnArg2(java.lang.String) inliner (after)
46 /// CHECK-DAG: <<Value:l\d+>> ParameterValue
47 /// CHECK-DAG: Return [<<Value>>]
48
49 /// CHECK-START: java.lang.Object Main.staticReturnArg2(java.lang.String) inliner (after)
50 /// CHECK-NOT: InvokeStaticOrDirect
51
52 public static Object staticReturnArg2(String value) {
53 return Second.staticReturnArg2(77, value);
54 }
55
56 /// CHECK-START: long Main.returnArg1(Second, long) inliner (before)
57 /// CHECK-DAG: <<Second:l\d+>> ParameterValue
58 /// CHECK-DAG: <<Value:j\d+>> ParameterValue
59 /// CHECK-DAG: <<NullCk:l\d+>> NullCheck [<<Second>>]
60 /// CHECK-DAG: <<Invoke:j\d+>> InvokeVirtual [<<NullCk>>,<<Value>>]
61 /// CHECK-DAG: Return [<<Invoke>>]
62
63 /// CHECK-START: long Main.returnArg1(Second, long) inliner (after)
64 /// CHECK-DAG: <<Value:j\d+>> ParameterValue
65 /// CHECK-DAG: Return [<<Value>>]
66
67 /// CHECK-START: long Main.returnArg1(Second, long) inliner (after)
68 /// CHECK-NOT: InvokeVirtual
69
70 public static long returnArg1(Second s, long value) {
71 return s.returnArg1(value);
72 }
73
74 /// CHECK-START: int Main.staticReturn9() inliner (before)
75 /// CHECK: {{i\d+}} InvokeStaticOrDirect
76
77 /// CHECK-START: int Main.staticReturn9() inliner (before)
78 /// CHECK-NOT: IntConstant 9
79
80 /// CHECK-START: int Main.staticReturn9() inliner (after)
81 /// CHECK-DAG: <<Const9:i\d+>> IntConstant 9
82 /// CHECK-DAG: Return [<<Const9>>]
83
84 /// CHECK-START: int Main.staticReturn9() inliner (after)
85 /// CHECK-NOT: InvokeStaticOrDirect
86
87 public static int staticReturn9() {
88 return Second.staticReturn9();
89 }
90
91 /// CHECK-START: int Main.return7(Second) inliner (before)
92 /// CHECK: {{i\d+}} InvokeVirtual
93
94 /// CHECK-START: int Main.return7(Second) inliner (before)
95 /// CHECK-NOT: IntConstant 7
96
97 /// CHECK-START: int Main.return7(Second) inliner (after)
98 /// CHECK-DAG: <<Const7:i\d+>> IntConstant 7
99 /// CHECK-DAG: Return [<<Const7>>]
100
101 /// CHECK-START: int Main.return7(Second) inliner (after)
102 /// CHECK-NOT: InvokeVirtual
103
104 public static int return7(Second s) {
105 return s.return7(null);
106 }
107
108 /// CHECK-START: java.lang.String Main.staticReturnNull() inliner (before)
109 /// CHECK: {{l\d+}} InvokeStaticOrDirect
110
111 /// CHECK-START: java.lang.String Main.staticReturnNull() inliner (before)
112 /// CHECK-NOT: NullConstant
113
114 /// CHECK-START: java.lang.String Main.staticReturnNull() inliner (after)
115 /// CHECK-DAG: <<Null:l\d+>> NullConstant
116 /// CHECK-DAG: Return [<<Null>>]
117
118 /// CHECK-START: java.lang.String Main.staticReturnNull() inliner (after)
119 /// CHECK-NOT: InvokeStaticOrDirect
120
121 public static String staticReturnNull() {
122 return Second.staticReturnNull();
123 }
124
125 /// CHECK-START: java.lang.Object Main.returnNull(Second) inliner (before)
126 /// CHECK: {{l\d+}} InvokeVirtual
127
128 /// CHECK-START: java.lang.Object Main.returnNull(Second) inliner (before)
129 /// CHECK-NOT: NullConstant
130
131 /// CHECK-START: java.lang.Object Main.returnNull(Second) inliner (after)
132 /// CHECK-DAG: <<Null:l\d+>> NullConstant
133 /// CHECK-DAG: Return [<<Null>>]
134
135 /// CHECK-START: java.lang.Object Main.returnNull(Second) inliner (after)
136 /// CHECK-NOT: InvokeVirtual
137
138 public static Object returnNull(Second s) {
139 return s.returnNull();
140 }
141
142 /// CHECK-START: int Main.getInt(Second) inliner (before)
143 /// CHECK: {{i\d+}} InvokeVirtual
144
145 /// CHECK-START: int Main.getInt(Second) inliner (after)
146 /// CHECK: {{i\d+}} InstanceFieldGet
147
148 /// CHECK-START: int Main.getInt(Second) inliner (after)
149 /// CHECK-NOT: InvokeVirtual
150
151 public static int getInt(Second s) {
152 return s.getInstanceIntField();
153 }
154
155 /// CHECK-START: double Main.getDouble(Second) inliner (before)
156 /// CHECK: {{d\d+}} InvokeVirtual
157
158 /// CHECK-START: double Main.getDouble(Second) inliner (after)
159 /// CHECK: {{d\d+}} InstanceFieldGet
160
161 /// CHECK-START: double Main.getDouble(Second) inliner (after)
162 /// CHECK-NOT: InvokeVirtual
163
164 public static double getDouble(Second s) {
165 return s.getInstanceDoubleField(22);
166 }
167
168 /// CHECK-START: java.lang.Object Main.getObject(Second) inliner (before)
169 /// CHECK: {{l\d+}} InvokeVirtual
170
171 /// CHECK-START: java.lang.Object Main.getObject(Second) inliner (after)
172 /// CHECK: {{l\d+}} InstanceFieldGet
173
174 /// CHECK-START: java.lang.Object Main.getObject(Second) inliner (after)
175 /// CHECK-NOT: InvokeVirtual
176
177 public static Object getObject(Second s) {
178 return s.getInstanceObjectField(-1L);
179 }
180
181 /// CHECK-START: java.lang.String Main.getString(Second) inliner (before)
182 /// CHECK: {{l\d+}} InvokeVirtual
183
184 /// CHECK-START: java.lang.String Main.getString(Second) inliner (after)
185 /// CHECK: {{l\d+}} InstanceFieldGet
186
187 /// CHECK-START: java.lang.String Main.getString(Second) inliner (after)
188 /// CHECK-NOT: InvokeVirtual
189
190 public static String getString(Second s) {
191 return s.getInstanceStringField(null, "whatever", 1234L);
192 }
193
194 /// CHECK-START: int Main.staticGetInt(Second) inliner (before)
195 /// CHECK: {{i\d+}} InvokeStaticOrDirect
196
197 /// CHECK-START: int Main.staticGetInt(Second) inliner (after)
198 /// CHECK: {{i\d+}} InvokeStaticOrDirect
199
200 /// CHECK-START: int Main.staticGetInt(Second) inliner (after)
201 /// CHECK-NOT: InstanceFieldGet
202
203 public static int staticGetInt(Second s) {
204 return Second.staticGetInstanceIntField(s);
205 }
206
207 /// CHECK-START: double Main.getDoubleFromParam(Second) inliner (before)
208 /// CHECK: {{d\d+}} InvokeVirtual
209
210 /// CHECK-START: double Main.getDoubleFromParam(Second) inliner (after)
211 /// CHECK: {{d\d+}} InvokeVirtual
212
213 /// CHECK-START: double Main.getDoubleFromParam(Second) inliner (after)
214 /// CHECK-NOT: InstanceFieldGet
215
216 public static double getDoubleFromParam(Second s) {
217 return s.getInstanceDoubleFieldFromParam(s);
218 }
219
220 /// CHECK-START: int Main.getStaticInt(Second) inliner (before)
221 /// CHECK: {{i\d+}} InvokeVirtual
222
223 /// CHECK-START: int Main.getStaticInt(Second) inliner (after)
224 /// CHECK: {{i\d+}} InvokeVirtual
225
226 /// CHECK-START: int Main.getStaticInt(Second) inliner (after)
227 /// CHECK-NOT: InstanceFieldGet
228 /// CHECK-NOT: StaticFieldGet
229
230 public static int getStaticInt(Second s) {
231 return s.getStaticIntField();
232 }
233
234 /// CHECK-START: long Main.setLong(Second, long) inliner (before)
235 /// CHECK: InvokeVirtual
236
237 /// CHECK-START: long Main.setLong(Second, long) inliner (after)
238 /// CHECK: InstanceFieldSet
239
240 /// CHECK-START: long Main.setLong(Second, long) inliner (after)
241 /// CHECK-NOT: InvokeVirtual
242
243 public static long setLong(Second s, long value) {
244 s.setInstanceLongField(-1, value);
245 return s.instanceLongField;
246 }
247
248 /// CHECK-START: long Main.setLongReturnArg2(Second, long, int) inliner (before)
249 /// CHECK: InvokeVirtual
250
251 /// CHECK-START: long Main.setLongReturnArg2(Second, long, int) inliner (after)
252 /// CHECK-DAG: <<Second:l\d+>> ParameterValue
253 /// CHECK-DAG: <<Value:j\d+>> ParameterValue
254 /// CHECK-DAG: <<Arg2:i\d+>> ParameterValue
255 /// CHECK-DAG: <<NullCk:l\d+>> NullCheck [<<Second>>]
256 /// CHECK-DAG: InstanceFieldSet [<<NullCk>>,<<Value>>]
257 /// CHECK-DAG: <<NullCk2:l\d+>> NullCheck [<<Second>>]
258 /// CHECK-DAG: <<IGet:j\d+>> InstanceFieldGet [<<NullCk2>>]
259 /// CHECK-DAG: <<Conv:j\d+>> TypeConversion [<<Arg2>>]
260 /// CHECK-DAG: <<Add:j\d+>> Add [<<IGet>>,<<Conv>>]
261 /// CHECK-DAG: Return [<<Add>>]
262
263 /// CHECK-START: long Main.setLongReturnArg2(Second, long, int) inliner (after)
264 /// CHECK-NOT: InvokeVirtual
265
266 public static long setLongReturnArg2(Second s, long value, int arg2) {
267 int result = s.setInstanceLongFieldReturnArg2(value, arg2);
268 return s.instanceLongField + result;
269 }
270
271 /// CHECK-START: long Main.staticSetLong(Second, long) inliner (before)
272 /// CHECK: InvokeStaticOrDirect
273
274 /// CHECK-START: long Main.staticSetLong(Second, long) inliner (after)
275 /// CHECK: InvokeStaticOrDirect
276
277 /// CHECK-START: long Main.staticSetLong(Second, long) inliner (after)
278 /// CHECK-NOT: InstanceFieldSet
279
280 public static long staticSetLong(Second s, long value) {
281 Second.staticSetInstanceLongField(s, value);
282 return s.instanceLongField;
283 }
284
285 /// CHECK-START: long Main.setLongThroughParam(Second, long) inliner (before)
286 /// CHECK: InvokeVirtual
287
288 /// CHECK-START: long Main.setLongThroughParam(Second, long) inliner (after)
289 /// CHECK: InvokeVirtual
290
291 /// CHECK-START: long Main.setLongThroughParam(Second, long) inliner (after)
292 /// CHECK-NOT: InstanceFieldSet
293
294 public static long setLongThroughParam(Second s, long value) {
295 s.setInstanceLongFieldThroughParam(s, value);
296 return s.instanceLongField;
297 }
298
299 /// CHECK-START: float Main.setStaticFloat(Second, float) inliner (before)
300 /// CHECK: InvokeVirtual
301
302 /// CHECK-START: float Main.setStaticFloat(Second, float) inliner (after)
303 /// CHECK: InvokeVirtual
304
305 /// CHECK-START: float Main.setStaticFloat(Second, float) inliner (after)
306 /// CHECK-NOT: InstanceFieldSet
307 /// CHECK-NOT: StaticFieldSet
308
309 public static float setStaticFloat(Second s, float value) {
310 s.setStaticFloatField(value);
311 return s.staticFloatField;
312 }
313
314 /// CHECK-START: java.lang.Object Main.newObject() inliner (before)
315 /// CHECK-DAG: <<Obj:l\d+>> NewInstance
316 /// CHECK-DAG: InvokeStaticOrDirect [<<Obj>>] method_name:java.lang.Object.<init>
317
318 /// CHECK-START: java.lang.Object Main.newObject() inliner (after)
319 /// CHECK-NOT: InvokeStaticOrDirect
320
321 public static Object newObject() {
322 return new Object();
323 }
324
325 public static void main(String[] args) throws Exception {
326 Second s = new Second();
327
328 // Replaced NOP pattern.
329 staticNop();
330 nop(s);
331 // Replaced "return arg" pattern.
332 assertEquals("arbitrary string", staticReturnArg2("arbitrary string"));
333 assertEquals(4321L, returnArg1(s, 4321L));
334 // Replaced "return const" pattern.
335 assertEquals(9, staticReturn9());
336 assertEquals(7, return7(s));
337 assertEquals(null, staticReturnNull());
338 assertEquals(null, returnNull(s));
339 // Replaced IGET pattern.
340 assertEquals(42, getInt(s));
341 assertEquals(-42.0, getDouble(s));
342 assertEquals(null, getObject(s));
343 assertEquals("dummy", getString(s));
344 // Not replaced IGET pattern.
345 assertEquals(42, staticGetInt(s));
346 assertEquals(-42.0, getDoubleFromParam(s));
347 // SGET.
348 assertEquals(4242, getStaticInt(s));
349 // Replaced IPUT pattern.
350 assertEquals(111L, setLong(s, 111L));
351 assertEquals(345L, setLongReturnArg2(s, 222L, 123));
352 // Not replaced IPUT pattern.
353 assertEquals(222L, staticSetLong(s, 222L));
354 assertEquals(333L, setLongThroughParam(s, 333L));
355 // SPUT.
356 assertEquals(-11.5f, setStaticFloat(s, -11.5f));
357
358 if (newObject() == null) {
359 throw new AssertionError("new Object() cannot be null.");
360 }
361 }
362
363 private static void assertEquals(int expected, int actual) {
364 if (expected != actual) {
365 throw new AssertionError("Wrong result: " + expected + " != " + actual);
366 }
367 }
368
369 private static void assertEquals(double expected, double actual) {
370 if (expected != actual) {
371 throw new AssertionError("Wrong result: " + expected + " != " + actual);
372 }
373 }
374
375 private static void assertEquals(Object expected, Object actual) {
376 if (expected != actual && (expected == null || !expected.equals(actual))) {
377 throw new AssertionError("Wrong result: " + expected + " != " + actual);
378 }
379 }
380}