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