1 /* 2 * Copyright 2019 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 import dalvik.annotation.optimization.FastNative; 18 import dalvik.annotation.optimization.CriticalNative; 19 20 // clang-format off 21 22 public class Main { 23 main(String[] args)24 public static void main(String[] args) throws Exception { 25 System.loadLibrary(args[0]); 26 27 // To avoid going through resolution trampoline, make test classes visibly initialized. 28 new Test(); 29 new TestFast(); 30 new TestCritical(); 31 new TestMissing(); 32 new TestMissingFast(); 33 new TestMissingCritical(); 34 new CriticalSignatures(); 35 makeVisiblyInitialized(); // Make sure they are visibly initialized. 36 37 $noinline$opt$test(); 38 $noinline$opt$testFast(); 39 $noinline$opt$testCritical(); 40 $noinline$opt$testMissing(); 41 $noinline$opt$testMissingFast(); 42 $noinline$opt$testMissingCritical(); 43 $noinline$opt$testCriticalSignatures(); 44 45 // For calls from AOT-compiled code, the first call shall use the resolution method 46 // retrieved from the .bss and the second call should find the .bss entry populated 47 // with the target method. Re-run these tests to exercise the second path. 48 $noinline$opt$test(); 49 $noinline$opt$testFast(); 50 $noinline$opt$testCritical(); 51 $noinline$opt$testMissing(); 52 $noinline$opt$testMissingFast(); 53 $noinline$opt$testMissingCritical(); 54 $noinline$opt$testCriticalSignatures(); 55 56 $noinline$regressionTestB181736463(); 57 $noinline$regressionTestB189235039(); 58 59 new CriticalClinitCheck(); 60 sTestCriticalClinitCheckOtherThread.join(); 61 } 62 $noinline$opt$test()63 static void $noinline$opt$test() { 64 System.out.println("test"); 65 assertEquals(42, Test.nativeMethodVoid()); 66 assertEquals(42, Test.nativeMethod(42)); 67 assertEquals(42, Test.nativeMethodWithManyParameters( 68 11, 12L, 13.0f, 14.0d, 69 21, 22L, 23.0f, 24.0d, 70 31, 32L, 33.0f, 34.0d, 71 41, 42L, 43.0f, 44.0d, 72 51, 52L, 53.0f, 54.0d, 73 61, 62L, 63.0f, 64.0d, 74 71, 72L, 73.0f, 74.0d, 75 81, 82L, 83.0f, 84.0d)); 76 } 77 $noinline$opt$testFast()78 static void $noinline$opt$testFast() { 79 System.out.println("testFast"); 80 assertEquals(42, TestFast.nativeMethodVoid()); 81 assertEquals(42, TestFast.nativeMethod(42)); 82 assertEquals(42, TestFast.nativeMethodWithManyParameters( 83 11, 12L, 13.0f, 14.0d, 84 21, 22L, 23.0f, 24.0d, 85 31, 32L, 33.0f, 34.0d, 86 41, 42L, 43.0f, 44.0d, 87 51, 52L, 53.0f, 54.0d, 88 61, 62L, 63.0f, 64.0d, 89 71, 72L, 73.0f, 74.0d, 90 81, 82L, 83.0f, 84.0d)); 91 } 92 $noinline$opt$testCritical()93 static void $noinline$opt$testCritical() { 94 System.out.println("testCritical"); 95 assertEquals(42, TestCritical.nativeMethodVoid()); 96 assertEquals(42, TestCritical.nativeMethod(42)); 97 assertEquals(42, TestCritical.nativeMethodWithManyParameters( 98 11, 12L, 13.0f, 14.0d, 99 21, 22L, 23.0f, 24.0d, 100 31, 32L, 33.0f, 34.0d, 101 41, 42L, 43.0f, 44.0d, 102 51, 52L, 53.0f, 54.0d, 103 61, 62L, 63.0f, 64.0d, 104 71, 72L, 73.0f, 74.0d, 105 81, 82L, 83.0f, 84.0d)); 106 } 107 $noinline$opt$testMissing()108 static void $noinline$opt$testMissing() { 109 System.out.println("testMissing"); 110 111 try { 112 TestMissing.nativeMethodVoid(); 113 throw new Error("UNREACHABLE"); 114 } catch (LinkageError expected) {} 115 116 try { 117 TestMissing.nativeMethod(42); 118 throw new Error("UNREACHABLE"); 119 } catch (LinkageError expected) {} 120 121 try { 122 TestMissing.nativeMethodWithManyParameters( 123 11, 12L, 13.0f, 14.0d, 124 21, 22L, 23.0f, 24.0d, 125 31, 32L, 33.0f, 34.0d, 126 41, 42L, 43.0f, 44.0d, 127 51, 52L, 53.0f, 54.0d, 128 61, 62L, 63.0f, 64.0d, 129 71, 72L, 73.0f, 74.0d, 130 81, 82L, 83.0f, 84.0d); 131 throw new Error("UNREACHABLE"); 132 } catch (LinkageError expected) {} 133 } 134 $noinline$opt$testMissingFast()135 static void $noinline$opt$testMissingFast() { 136 System.out.println("testMissingFast"); 137 138 try { 139 TestMissingFast.nativeMethodVoid(); 140 throw new Error("UNREACHABLE"); 141 } catch (LinkageError expected) {} 142 143 try { 144 TestMissingFast.nativeMethod(42); 145 throw new Error("UNREACHABLE"); 146 } catch (LinkageError expected) {} 147 148 try { 149 TestMissingFast.nativeMethodWithManyParameters( 150 11, 12L, 13.0f, 14.0d, 151 21, 22L, 23.0f, 24.0d, 152 31, 32L, 33.0f, 34.0d, 153 41, 42L, 43.0f, 44.0d, 154 51, 52L, 53.0f, 54.0d, 155 61, 62L, 63.0f, 64.0d, 156 71, 72L, 73.0f, 74.0d, 157 81, 82L, 83.0f, 84.0d); 158 throw new Error("UNREACHABLE"); 159 } catch (LinkageError expected) {} 160 } 161 $noinline$opt$testMissingCritical()162 static void $noinline$opt$testMissingCritical() { 163 System.out.println("testMissingCritical"); 164 165 try { 166 TestMissingCritical.nativeMethodVoid(); 167 throw new Error("UNREACHABLE"); 168 } catch (LinkageError expected) {} 169 170 try { 171 TestMissingCritical.nativeMethod(42); 172 throw new Error("UNREACHABLE"); 173 } catch (LinkageError expected) {} 174 175 try { 176 TestMissingCritical.nativeMethodWithManyParameters( 177 11, 12L, 13.0f, 14.0d, 178 21, 22L, 23.0f, 24.0d, 179 31, 32L, 33.0f, 34.0d, 180 41, 42L, 43.0f, 44.0d, 181 51, 52L, 53.0f, 54.0d, 182 61, 62L, 63.0f, 64.0d, 183 71, 72L, 73.0f, 74.0d, 184 81, 82L, 83.0f, 84.0d); 185 throw new Error("UNREACHABLE"); 186 } catch (LinkageError expected) {} 187 } 188 $noinline$opt$testCriticalSignatures()189 static void $noinline$opt$testCriticalSignatures() { 190 System.out.println("testCriticalSignatures"); 191 long l = 0xf00000000L; 192 assertEquals(42, CriticalSignatures.nativeILFFFFD(1, l + 2L, 3.0f, 4.0f, 5.0f, 6.0f, 7.0)); 193 assertEquals(42, CriticalSignatures.nativeLIFFFFD(l + 7L, 6, 5.0f, 4.0f, 3.0f, 2.0f, 1.0)); 194 assertEquals(42, CriticalSignatures.nativeFLIFFFD(1.0f, l + 2L, 3, 4.0f, 5.0f, 6.0f, 7.0)); 195 assertEquals(42, CriticalSignatures.nativeDDIIIIII(8.0, 7.0, 6, 5, 4, 3, 2, 1)); 196 assertEquals(42, CriticalSignatures.nativeDFFILIII(1.0, 2.0f, 3.0f, 4, l + 5L, 6, 7, 8)); 197 assertEquals(42, CriticalSignatures.nativeDDFILIII(8.0, 7.0, 6.0f, 5, l + 4L, 3, 2, 1)); 198 assertEquals(42, CriticalSignatures.nativeDDIFII(1.0, 2.0, 3, 4.0f, 5, 6)); 199 assertEquals(42, CriticalSignatures.nativeFullArgs( 200 // Generated by script (then modified to close argument list): 201 // for i in {0..84}; \ 202 // do echo " 0xf00000000L + $((i*3))L,"; \ 203 // echo " $((i*3+2)),"; \ 204 // done 205 0xf00000000L + 0L, 206 2, 207 0xf00000000L + 3L, 208 5, 209 0xf00000000L + 6L, 210 8, 211 0xf00000000L + 9L, 212 11, 213 0xf00000000L + 12L, 214 14, 215 0xf00000000L + 15L, 216 17, 217 0xf00000000L + 18L, 218 20, 219 0xf00000000L + 21L, 220 23, 221 0xf00000000L + 24L, 222 26, 223 0xf00000000L + 27L, 224 29, 225 0xf00000000L + 30L, 226 32, 227 0xf00000000L + 33L, 228 35, 229 0xf00000000L + 36L, 230 38, 231 0xf00000000L + 39L, 232 41, 233 0xf00000000L + 42L, 234 44, 235 0xf00000000L + 45L, 236 47, 237 0xf00000000L + 48L, 238 50, 239 0xf00000000L + 51L, 240 53, 241 0xf00000000L + 54L, 242 56, 243 0xf00000000L + 57L, 244 59, 245 0xf00000000L + 60L, 246 62, 247 0xf00000000L + 63L, 248 65, 249 0xf00000000L + 66L, 250 68, 251 0xf00000000L + 69L, 252 71, 253 0xf00000000L + 72L, 254 74, 255 0xf00000000L + 75L, 256 77, 257 0xf00000000L + 78L, 258 80, 259 0xf00000000L + 81L, 260 83, 261 0xf00000000L + 84L, 262 86, 263 0xf00000000L + 87L, 264 89, 265 0xf00000000L + 90L, 266 92, 267 0xf00000000L + 93L, 268 95, 269 0xf00000000L + 96L, 270 98, 271 0xf00000000L + 99L, 272 101, 273 0xf00000000L + 102L, 274 104, 275 0xf00000000L + 105L, 276 107, 277 0xf00000000L + 108L, 278 110, 279 0xf00000000L + 111L, 280 113, 281 0xf00000000L + 114L, 282 116, 283 0xf00000000L + 117L, 284 119, 285 0xf00000000L + 120L, 286 122, 287 0xf00000000L + 123L, 288 125, 289 0xf00000000L + 126L, 290 128, 291 0xf00000000L + 129L, 292 131, 293 0xf00000000L + 132L, 294 134, 295 0xf00000000L + 135L, 296 137, 297 0xf00000000L + 138L, 298 140, 299 0xf00000000L + 141L, 300 143, 301 0xf00000000L + 144L, 302 146, 303 0xf00000000L + 147L, 304 149, 305 0xf00000000L + 150L, 306 152, 307 0xf00000000L + 153L, 308 155, 309 0xf00000000L + 156L, 310 158, 311 0xf00000000L + 159L, 312 161, 313 0xf00000000L + 162L, 314 164, 315 0xf00000000L + 165L, 316 167, 317 0xf00000000L + 168L, 318 170, 319 0xf00000000L + 171L, 320 173, 321 0xf00000000L + 174L, 322 176, 323 0xf00000000L + 177L, 324 179, 325 0xf00000000L + 180L, 326 182, 327 0xf00000000L + 183L, 328 185, 329 0xf00000000L + 186L, 330 188, 331 0xf00000000L + 189L, 332 191, 333 0xf00000000L + 192L, 334 194, 335 0xf00000000L + 195L, 336 197, 337 0xf00000000L + 198L, 338 200, 339 0xf00000000L + 201L, 340 203, 341 0xf00000000L + 204L, 342 206, 343 0xf00000000L + 207L, 344 209, 345 0xf00000000L + 210L, 346 212, 347 0xf00000000L + 213L, 348 215, 349 0xf00000000L + 216L, 350 218, 351 0xf00000000L + 219L, 352 221, 353 0xf00000000L + 222L, 354 224, 355 0xf00000000L + 225L, 356 227, 357 0xf00000000L + 228L, 358 230, 359 0xf00000000L + 231L, 360 233, 361 0xf00000000L + 234L, 362 236, 363 0xf00000000L + 237L, 364 239, 365 0xf00000000L + 240L, 366 242, 367 0xf00000000L + 243L, 368 245, 369 0xf00000000L + 246L, 370 248, 371 0xf00000000L + 249L, 372 251, 373 0xf00000000L + 252L, 374 254)); 375 assertEquals(42, CriticalSignatures.nativeDFDFDFDFDFIJ( 376 1.0, 2.0f, 3.0, 4.0f, 5.0, 6.0f, 7.0, 8.0f, 9.0, 10.0f, 11, 12L)); 377 // Exercise spilling args from registers on riscv64. 378 double double9_0 = $noinline$returnDoubleArg(9.0); 379 float float10_0 = $noinline$returnFloatArg(10.0f); 380 int int11 = $noinline$returnIntArg(11); 381 long long12 = $noinline$returnLongArg(12); 382 assertEquals(42, CriticalSignatures.nativeDFDFDFDFDFIJ( 383 1.0, 2.0f, 3.0, 4.0f, 5.0, 6.0f, 7.0, 8.0f, double9_0, float10_0, int11, long12)); 384 // Split out the last test to keep this method under the large method threshold. 385 $noinline$opt$testCriticalSignaturesStackMoves(); 386 } 387 $noinline$opt$testCriticalSignaturesStackMoves()388 public static void $noinline$opt$testCriticalSignaturesStackMoves() { 389 // Exercise moving non-const args to stack by having more non-const args than registers. 390 // At least on riscv64, where we need to properly sign-extend narrow (int) arguments 391 // passed on stack, this covers both register and stack source locations. 392 assertEquals(42, CriticalSignatures.nativeFullArgs( 393 // Generated by script (then modified to close argument list): 394 // for i in {0..84}; \ 395 // do echo " \$noinline\$returnLongArg(0xf00000000L + $((i*3))L),"; \ 396 // echo " \$noinline\$returnIntArg($((i*3+2))),"; \ 397 // done 398 $noinline$returnLongArg(0xf00000000L + 0L), 399 $noinline$returnIntArg(2), 400 $noinline$returnLongArg(0xf00000000L + 3L), 401 $noinline$returnIntArg(5), 402 $noinline$returnLongArg(0xf00000000L + 6L), 403 $noinline$returnIntArg(8), 404 $noinline$returnLongArg(0xf00000000L + 9L), 405 $noinline$returnIntArg(11), 406 $noinline$returnLongArg(0xf00000000L + 12L), 407 $noinline$returnIntArg(14), 408 $noinline$returnLongArg(0xf00000000L + 15L), 409 $noinline$returnIntArg(17), 410 $noinline$returnLongArg(0xf00000000L + 18L), 411 $noinline$returnIntArg(20), 412 $noinline$returnLongArg(0xf00000000L + 21L), 413 $noinline$returnIntArg(23), 414 $noinline$returnLongArg(0xf00000000L + 24L), 415 $noinline$returnIntArg(26), 416 $noinline$returnLongArg(0xf00000000L + 27L), 417 $noinline$returnIntArg(29), 418 $noinline$returnLongArg(0xf00000000L + 30L), 419 $noinline$returnIntArg(32), 420 $noinline$returnLongArg(0xf00000000L + 33L), 421 $noinline$returnIntArg(35), 422 $noinline$returnLongArg(0xf00000000L + 36L), 423 $noinline$returnIntArg(38), 424 $noinline$returnLongArg(0xf00000000L + 39L), 425 $noinline$returnIntArg(41), 426 $noinline$returnLongArg(0xf00000000L + 42L), 427 $noinline$returnIntArg(44), 428 $noinline$returnLongArg(0xf00000000L + 45L), 429 $noinline$returnIntArg(47), 430 $noinline$returnLongArg(0xf00000000L + 48L), 431 $noinline$returnIntArg(50), 432 $noinline$returnLongArg(0xf00000000L + 51L), 433 $noinline$returnIntArg(53), 434 $noinline$returnLongArg(0xf00000000L + 54L), 435 $noinline$returnIntArg(56), 436 $noinline$returnLongArg(0xf00000000L + 57L), 437 $noinline$returnIntArg(59), 438 $noinline$returnLongArg(0xf00000000L + 60L), 439 $noinline$returnIntArg(62), 440 $noinline$returnLongArg(0xf00000000L + 63L), 441 $noinline$returnIntArg(65), 442 $noinline$returnLongArg(0xf00000000L + 66L), 443 $noinline$returnIntArg(68), 444 $noinline$returnLongArg(0xf00000000L + 69L), 445 $noinline$returnIntArg(71), 446 $noinline$returnLongArg(0xf00000000L + 72L), 447 $noinline$returnIntArg(74), 448 $noinline$returnLongArg(0xf00000000L + 75L), 449 $noinline$returnIntArg(77), 450 $noinline$returnLongArg(0xf00000000L + 78L), 451 $noinline$returnIntArg(80), 452 $noinline$returnLongArg(0xf00000000L + 81L), 453 $noinline$returnIntArg(83), 454 $noinline$returnLongArg(0xf00000000L + 84L), 455 $noinline$returnIntArg(86), 456 $noinline$returnLongArg(0xf00000000L + 87L), 457 $noinline$returnIntArg(89), 458 $noinline$returnLongArg(0xf00000000L + 90L), 459 $noinline$returnIntArg(92), 460 $noinline$returnLongArg(0xf00000000L + 93L), 461 $noinline$returnIntArg(95), 462 $noinline$returnLongArg(0xf00000000L + 96L), 463 $noinline$returnIntArg(98), 464 $noinline$returnLongArg(0xf00000000L + 99L), 465 $noinline$returnIntArg(101), 466 $noinline$returnLongArg(0xf00000000L + 102L), 467 $noinline$returnIntArg(104), 468 $noinline$returnLongArg(0xf00000000L + 105L), 469 $noinline$returnIntArg(107), 470 $noinline$returnLongArg(0xf00000000L + 108L), 471 $noinline$returnIntArg(110), 472 $noinline$returnLongArg(0xf00000000L + 111L), 473 $noinline$returnIntArg(113), 474 $noinline$returnLongArg(0xf00000000L + 114L), 475 $noinline$returnIntArg(116), 476 $noinline$returnLongArg(0xf00000000L + 117L), 477 $noinline$returnIntArg(119), 478 $noinline$returnLongArg(0xf00000000L + 120L), 479 $noinline$returnIntArg(122), 480 $noinline$returnLongArg(0xf00000000L + 123L), 481 $noinline$returnIntArg(125), 482 $noinline$returnLongArg(0xf00000000L + 126L), 483 $noinline$returnIntArg(128), 484 $noinline$returnLongArg(0xf00000000L + 129L), 485 $noinline$returnIntArg(131), 486 $noinline$returnLongArg(0xf00000000L + 132L), 487 $noinline$returnIntArg(134), 488 $noinline$returnLongArg(0xf00000000L + 135L), 489 $noinline$returnIntArg(137), 490 $noinline$returnLongArg(0xf00000000L + 138L), 491 $noinline$returnIntArg(140), 492 $noinline$returnLongArg(0xf00000000L + 141L), 493 $noinline$returnIntArg(143), 494 $noinline$returnLongArg(0xf00000000L + 144L), 495 $noinline$returnIntArg(146), 496 $noinline$returnLongArg(0xf00000000L + 147L), 497 $noinline$returnIntArg(149), 498 $noinline$returnLongArg(0xf00000000L + 150L), 499 $noinline$returnIntArg(152), 500 $noinline$returnLongArg(0xf00000000L + 153L), 501 $noinline$returnIntArg(155), 502 $noinline$returnLongArg(0xf00000000L + 156L), 503 $noinline$returnIntArg(158), 504 $noinline$returnLongArg(0xf00000000L + 159L), 505 $noinline$returnIntArg(161), 506 $noinline$returnLongArg(0xf00000000L + 162L), 507 $noinline$returnIntArg(164), 508 $noinline$returnLongArg(0xf00000000L + 165L), 509 $noinline$returnIntArg(167), 510 $noinline$returnLongArg(0xf00000000L + 168L), 511 $noinline$returnIntArg(170), 512 $noinline$returnLongArg(0xf00000000L + 171L), 513 $noinline$returnIntArg(173), 514 $noinline$returnLongArg(0xf00000000L + 174L), 515 $noinline$returnIntArg(176), 516 $noinline$returnLongArg(0xf00000000L + 177L), 517 $noinline$returnIntArg(179), 518 $noinline$returnLongArg(0xf00000000L + 180L), 519 $noinline$returnIntArg(182), 520 $noinline$returnLongArg(0xf00000000L + 183L), 521 $noinline$returnIntArg(185), 522 $noinline$returnLongArg(0xf00000000L + 186L), 523 $noinline$returnIntArg(188), 524 $noinline$returnLongArg(0xf00000000L + 189L), 525 $noinline$returnIntArg(191), 526 $noinline$returnLongArg(0xf00000000L + 192L), 527 $noinline$returnIntArg(194), 528 $noinline$returnLongArg(0xf00000000L + 195L), 529 $noinline$returnIntArg(197), 530 $noinline$returnLongArg(0xf00000000L + 198L), 531 $noinline$returnIntArg(200), 532 $noinline$returnLongArg(0xf00000000L + 201L), 533 $noinline$returnIntArg(203), 534 $noinline$returnLongArg(0xf00000000L + 204L), 535 $noinline$returnIntArg(206), 536 $noinline$returnLongArg(0xf00000000L + 207L), 537 $noinline$returnIntArg(209), 538 $noinline$returnLongArg(0xf00000000L + 210L), 539 $noinline$returnIntArg(212), 540 $noinline$returnLongArg(0xf00000000L + 213L), 541 $noinline$returnIntArg(215), 542 $noinline$returnLongArg(0xf00000000L + 216L), 543 $noinline$returnIntArg(218), 544 $noinline$returnLongArg(0xf00000000L + 219L), 545 $noinline$returnIntArg(221), 546 $noinline$returnLongArg(0xf00000000L + 222L), 547 $noinline$returnIntArg(224), 548 $noinline$returnLongArg(0xf00000000L + 225L), 549 $noinline$returnIntArg(227), 550 $noinline$returnLongArg(0xf00000000L + 228L), 551 $noinline$returnIntArg(230), 552 $noinline$returnLongArg(0xf00000000L + 231L), 553 $noinline$returnIntArg(233), 554 $noinline$returnLongArg(0xf00000000L + 234L), 555 $noinline$returnIntArg(236), 556 $noinline$returnLongArg(0xf00000000L + 237L), 557 $noinline$returnIntArg(239), 558 $noinline$returnLongArg(0xf00000000L + 240L), 559 $noinline$returnIntArg(242), 560 $noinline$returnLongArg(0xf00000000L + 243L), 561 $noinline$returnIntArg(245), 562 $noinline$returnLongArg(0xf00000000L + 246L), 563 $noinline$returnIntArg(248), 564 $noinline$returnLongArg(0xf00000000L + 249L), 565 $noinline$returnIntArg(251), 566 $noinline$returnLongArg(0xf00000000L + 252L), 567 $noinline$returnIntArg(254))); 568 } 569 $noinline$returnDoubleArg(double d)570 static double $noinline$returnDoubleArg(double d) { return d; } $noinline$returnFloatArg(float f)571 static float $noinline$returnFloatArg(float f) { return f; } $noinline$returnIntArg(int i)572 static int $noinline$returnIntArg(int i) { return i; } $noinline$returnLongArg(long l)573 static long $noinline$returnLongArg(long l) { return l; } 574 $noinline$regressionTestB181736463()575 static void $noinline$regressionTestB181736463() { 576 // Regression test for bug 181736463 (GenericJNI crashing when class initializer throws). 577 try { 578 BadClassB181736463.nativeMethodVoid(); 579 throw new Error("Unreachable"); 580 } catch (B181736463Error expected) { 581 } 582 } 583 $noinline$regressionTestB189235039()584 static void $noinline$regressionTestB189235039() { 585 assertEquals(42, new Main().b189235039CallThrough()); 586 } 587 initializingCriticalClinitCheck()588 static void initializingCriticalClinitCheck() { 589 // Called from CriticalClinitCheck.<clinit>(). 590 // Test @CriticalNative calls on the initializing thread. 591 $noinline$opt$testCriticalClinitCheck(); 592 sTestCriticalClinitCheckOtherThread = new Thread() { 593 public void run() { 594 $noinline$opt$testCriticalClinitCheck(); 595 } 596 }; 597 sTestCriticalClinitCheckOtherThread.start(); 598 // Sleep for a second to give the other thread an opportunity to run. 599 // We're testing that it performs a clinit check and blocks until we 600 // exit the class initializer after writing the output below. 601 try { 602 Thread.sleep(1000); 603 } catch (InterruptedException ie) { 604 throw new Error(ie); 605 } 606 System.out.println("initializingCriticalClinitCheck finished"); 607 } 608 $noinline$opt$testCriticalClinitCheck()609 static void $noinline$opt$testCriticalClinitCheck() { 610 assertEquals(42, CriticalClinitCheck.nativeMethodVoid()); 611 assertEquals(42, CriticalClinitCheck.nativeMethod(42)); 612 assertEquals(42, CriticalClinitCheck.nativeMethodWithManyParameters( 613 11, 12L, 13.0f, 14.0d, 614 21, 22L, 23.0f, 24.0d, 615 31, 32L, 33.0f, 34.0d, 616 41, 42L, 43.0f, 44.0d, 617 51, 52L, 53.0f, 54.0d, 618 61, 62L, 63.0f, 64.0d, 619 71, 72L, 73.0f, 74.0d, 620 81, 82L, 83.0f, 84.0d)); 621 System.out.println("testCriticalClinitCheck passed"); 622 } 623 624 static Thread sTestCriticalClinitCheckOtherThread = null; 625 assertEquals(int expected, int actual)626 static void assertEquals(int expected, int actual) { 627 if (expected != actual) { 628 throw new AssertionError("Expected " + expected + " got " + actual); 629 } 630 } 631 makeVisiblyInitialized()632 public static native void makeVisiblyInitialized(); 633 b189235039CallThrough()634 public native synchronized int b189235039CallThrough(); b189235039CheckLocks(int placeholder, Main m)635 public static native int b189235039CheckLocks(int placeholder, Main m); 636 } 637 638 class Test { nativeMethodVoid()639 public static native int nativeMethodVoid(); 640 nativeMethod(int i)641 public static native int nativeMethod(int i); 642 nativeMethodWithManyParameters( int i1, long l1, float f1, double d1, int i2, long l2, float f2, double d2, int i3, long l3, float f3, double d3, int i4, long l4, float f4, double d4, int i5, long l5, float f5, double d5, int i6, long l6, float f6, double d6, int i7, long l7, float f7, double d7, int i8, long l8, float f8, double d8)643 public static native int nativeMethodWithManyParameters( 644 int i1, long l1, float f1, double d1, 645 int i2, long l2, float f2, double d2, 646 int i3, long l3, float f3, double d3, 647 int i4, long l4, float f4, double d4, 648 int i5, long l5, float f5, double d5, 649 int i6, long l6, float f6, double d6, 650 int i7, long l7, float f7, double d7, 651 int i8, long l8, float f8, double d8); 652 } 653 654 class TestFast { 655 @FastNative nativeMethodVoid()656 public static native int nativeMethodVoid(); 657 658 @FastNative nativeMethod(int i)659 public static native int nativeMethod(int i); 660 661 @FastNative nativeMethodWithManyParameters( int i1, long l1, float f1, double d1, int i2, long l2, float f2, double d2, int i3, long l3, float f3, double d3, int i4, long l4, float f4, double d4, int i5, long l5, float f5, double d5, int i6, long l6, float f6, double d6, int i7, long l7, float f7, double d7, int i8, long l8, float f8, double d8)662 public static native int nativeMethodWithManyParameters( 663 int i1, long l1, float f1, double d1, 664 int i2, long l2, float f2, double d2, 665 int i3, long l3, float f3, double d3, 666 int i4, long l4, float f4, double d4, 667 int i5, long l5, float f5, double d5, 668 int i6, long l6, float f6, double d6, 669 int i7, long l7, float f7, double d7, 670 int i8, long l8, float f8, double d8); 671 } 672 673 class TestCritical { 674 @CriticalNative nativeMethodVoid()675 public static native int nativeMethodVoid(); 676 677 @CriticalNative nativeMethod(int i)678 public static native int nativeMethod(int i); 679 680 @CriticalNative nativeMethodWithManyParameters( int i1, long l1, float f1, double d1, int i2, long l2, float f2, double d2, int i3, long l3, float f3, double d3, int i4, long l4, float f4, double d4, int i5, long l5, float f5, double d5, int i6, long l6, float f6, double d6, int i7, long l7, float f7, double d7, int i8, long l8, float f8, double d8)681 public static native int nativeMethodWithManyParameters( 682 int i1, long l1, float f1, double d1, 683 int i2, long l2, float f2, double d2, 684 int i3, long l3, float f3, double d3, 685 int i4, long l4, float f4, double d4, 686 int i5, long l5, float f5, double d5, 687 int i6, long l6, float f6, double d6, 688 int i7, long l7, float f7, double d7, 689 int i8, long l8, float f8, double d8); 690 } 691 692 class TestMissing { nativeMethodVoid()693 public static native int nativeMethodVoid(); 694 nativeMethod(int i)695 public static native int nativeMethod(int i); 696 nativeMethodWithManyParameters( int i1, long l1, float f1, double d1, int i2, long l2, float f2, double d2, int i3, long l3, float f3, double d3, int i4, long l4, float f4, double d4, int i5, long l5, float f5, double d5, int i6, long l6, float f6, double d6, int i7, long l7, float f7, double d7, int i8, long l8, float f8, double d8)697 public static native int nativeMethodWithManyParameters( 698 int i1, long l1, float f1, double d1, 699 int i2, long l2, float f2, double d2, 700 int i3, long l3, float f3, double d3, 701 int i4, long l4, float f4, double d4, 702 int i5, long l5, float f5, double d5, 703 int i6, long l6, float f6, double d6, 704 int i7, long l7, float f7, double d7, 705 int i8, long l8, float f8, double d8); 706 } 707 708 class TestMissingFast { 709 @FastNative nativeMethodVoid()710 public static native int nativeMethodVoid(); 711 712 @FastNative nativeMethod(int i)713 public static native int nativeMethod(int i); 714 715 @FastNative nativeMethodWithManyParameters( int i1, long l1, float f1, double d1, int i2, long l2, float f2, double d2, int i3, long l3, float f3, double d3, int i4, long l4, float f4, double d4, int i5, long l5, float f5, double d5, int i6, long l6, float f6, double d6, int i7, long l7, float f7, double d7, int i8, long l8, float f8, double d8)716 public static native int nativeMethodWithManyParameters( 717 int i1, long l1, float f1, double d1, 718 int i2, long l2, float f2, double d2, 719 int i3, long l3, float f3, double d3, 720 int i4, long l4, float f4, double d4, 721 int i5, long l5, float f5, double d5, 722 int i6, long l6, float f6, double d6, 723 int i7, long l7, float f7, double d7, 724 int i8, long l8, float f8, double d8); 725 } 726 727 class TestMissingCritical { 728 @CriticalNative nativeMethodVoid()729 public static native int nativeMethodVoid(); 730 731 @CriticalNative nativeMethod(int i)732 public static native int nativeMethod(int i); 733 734 @CriticalNative nativeMethodWithManyParameters( int i1, long l1, float f1, double d1, int i2, long l2, float f2, double d2, int i3, long l3, float f3, double d3, int i4, long l4, float f4, double d4, int i5, long l5, float f5, double d5, int i6, long l6, float f6, double d6, int i7, long l7, float f7, double d7, int i8, long l8, float f8, double d8)735 public static native int nativeMethodWithManyParameters( 736 int i1, long l1, float f1, double d1, 737 int i2, long l2, float f2, double d2, 738 int i3, long l3, float f3, double d3, 739 int i4, long l4, float f4, double d4, 740 int i5, long l5, float f5, double d5, 741 int i6, long l6, float f6, double d6, 742 int i7, long l7, float f7, double d7, 743 int i8, long l8, float f8, double d8); 744 } 745 746 class CriticalSignatures { 747 // The following signatures exercise ARM argument moving and serve 748 // as an example of the optimizations performed by the assembler. 749 // Moving arguments is a lot simpler for other architectures. 750 751 // JNI compiler does not emit the CFG, so we cannot CHECK the "dissassembly (after)". 752 753 // vstm sp, {d0-d2} # f1, f2, f3, f4, d -- store floats as D regs together with double 754 // mov r4, r0 # hidden arg 755 // mov r0, r1 # i 756 // # l stays in r2-r3 757 @CriticalNative nativeILFFFFD( int i, long l, float f1, float f2, float f3, float f4, double d)758 public static native int nativeILFFFFD( 759 int i, long l, float f1, float f2, float f3, float f4, double d); 760 761 // vstm sp, {s1-s3} # f2, f3, f4 -- store floats up to alignment gap 762 // vstr d2, [sp, #16] # d 763 // mov r4, r0 # hidden arg 764 // mov r0, r2 # low(l) 765 // mov r1, r3 # high(l) 766 // ldr r2, [sp, #...] # i 767 // vmov r3, s0 # f1 768 @CriticalNative nativeLIFFFFD( long l, int i, float f1, float f2, float f3, float f4, double d)769 public static native int nativeLIFFFFD( 770 long l, int i, float f1, float f2, float f3, float f4, double d); 771 772 // ldr ip, [sp, #...] # i 773 // str ip, [sp] # i 774 // add ip, sp, #4 # Spilling multiple floats at an offset from SP 775 // vstm ip, {s1-s5} # f2, f3, f4, d 776 // mov r4, r0 # hidden arg 777 // vmov r0, s0 # f1 778 // # l stays in r2-r3 779 @CriticalNative nativeFLIFFFD( float f1, long l, int i, float f2, float f3, float f4, double d)780 public static native int nativeFLIFFFD( 781 float f1, long l, int i, float f2, float f3, float f4, double d); 782 783 // stm sp, {r1,r2,r3} # i1, i2, i3 -- store ints together 784 // ldrd r1, ip, [sp, #...] # i4, i5 785 // strd r1, ip, [sp, #12] # i4, i5 786 // ldr ip, [sp, #72] # i6 787 // str ip, [sp, #20] # i6 788 // mov r4, r0 # hidden arg 789 // vmov r0, r1, d0 # d1 790 // vmov r2, r3, d1 # d2 791 @CriticalNative nativeDDIIIIII( double d1, double d2, int i1, int i2, int i3, int i4, int i5, int i6)792 public static native int nativeDDIIIIII( 793 double d1, double d2, int i1, int i2, int i3, int i4, int i5, int i6); 794 795 // str r1, [sp] # i1 -- cannot store with l due to alignment gap 796 // strd r2, r3, [sp, #8] # l 797 // ldrd r1, ip, [sp, #...] # i2, i3 798 // strd r1, ip, [sp, #16] # i2, i3 799 // ldr ip, [sp, #...] # i4 800 // str ip, [sp, #24] # i4 801 // mov r4, r0 # hidden arg 802 // vmov r0, r1, d0 # d 803 // vmov r2, r3, d1 # f1, f2 -- move both floats together as double 804 @CriticalNative nativeDFFILIII( double d, float f1, float f2, int i1, long l, int i2, int i3, int i4)805 public static native int nativeDFFILIII( 806 double d, float f1, float f2, int i1, long l, int i2, int i3, int i4); 807 808 // vstr s4, [sp] # f 809 // add ip, sp, #4 # Spilling multiple core registers at an offset from SP 810 // stm ip, {r1,r2,r3} # i1, l -- store int together with long 811 // ldrd r1, ip, [sp, #...] # i2, i3 812 // strd r1, ip, [sp, #16] # i2, i3 813 // ldr ip, [sp, #...] # i4 814 // str ip, [sp, #24] # i4 815 // mov r4, r0 # hidden arg 816 // vmov r0, r1, d0 # d1 817 // vmov r2, r3, d1 # d2 818 @CriticalNative nativeDDFILIII( double d1, double d2, float f, int i1, long l, int i2, int i3, int i4)819 public static native int nativeDDFILIII( 820 double d1, double d2, float f, int i1, long l, int i2, int i3, int i4); 821 822 // str r1, [sp] # i1 823 // vstr s4, [sp, #4] # f 824 // strd r2, r3, [sp, #8] # i2, i3 -- store ints together with STRD 825 // mov r4, r0 # hidden arg 826 // vmov r0, r1, d0 # d1 827 // vmov r2, r3, d1 # d2 828 @CriticalNative nativeDDIFII( double d1, double d2, int i1, float f, int i2, int i3)829 public static native int nativeDDIFII( 830 double d1, double d2, int i1, float f, int i2, int i3); 831 832 // ... 833 // ldr ip, [sp, #2112] # int 834 // str ip, [sp, #1000] # int 835 // add r1, sp, #2048 # Prepare to use LDRD for loading long from a large offset 836 // ldrd r1, ip, [r1, #68] # long 837 // strd r1, ip, [sp, #1008] # long 838 // ldr ip, [sp, #2124] # int 839 // str ip, [sp, #1016] # int 840 // ldr ip, [sp, #2128] # low(long) -- copy the next long as two words because the offset 841 // str ip, [sp, #1024] # low(long) -- is too large for STRD and we only use 2 temps (r1, ip) 842 // ldr ip, [sp, #2132] # high(long) 843 // str ip, [sp, #1028] # high(long) 844 // ... 845 @CriticalNative nativeFullArgs( long l0, int i2, long l3, int i5, long l6, int i8, long l9, int i11, long l12, int i14, long l15, int i17, long l18, int i20, long l21, int i23, long l24, int i26, long l27, int i29, long l30, int i32, long l33, int i35, long l36, int i38, long l39, int i41, long l42, int i44, long l45, int i47, long l48, int i50, long l51, int i53, long l54, int i56, long l57, int i59, long l60, int i62, long l63, int i65, long l66, int i68, long l69, int i71, long l72, int i74, long l75, int i77, long l78, int i80, long l81, int i83, long l84, int i86, long l87, int i89, long l90, int i92, long l93, int i95, long l96, int i98, long l99, int i101, long l102, int i104, long l105, int i107, long l108, int i110, long l111, int i113, long l114, int i116, long l117, int i119, long l120, int i122, long l123, int i125, long l126, int i128, long l129, int i131, long l132, int i134, long l135, int i137, long l138, int i140, long l141, int i143, long l144, int i146, long l147, int i149, long l150, int i152, long l153, int i155, long l156, int i158, long l159, int i161, long l162, int i164, long l165, int i167, long l168, int i170, long l171, int i173, long l174, int i176, long l177, int i179, long l180, int i182, long l183, int i185, long l186, int i188, long l189, int i191, long l192, int i194, long l195, int i197, long l198, int i200, long l201, int i203, long l204, int i206, long l207, int i209, long l210, int i212, long l213, int i215, long l216, int i218, long l219, int i221, long l222, int i224, long l225, int i227, long l228, int i230, long l231, int i233, long l234, int i236, long l237, int i239, long l240, int i242, long l243, int i245, long l246, int i248, long l249, int i251, long l252, int i254)846 public static native int nativeFullArgs( 847 // Note: Numbered by dalvik registers, 0-254 (max 255 regs for invoke-*-range) 848 // 849 // Generated by script (then modified to close the argument list): 850 // for i in {0..84}; do echo " long l$((i*3)),"; echo " int i$(($i*3+2)),"; done 851 long l0, 852 int i2, 853 long l3, 854 int i5, 855 long l6, 856 int i8, 857 long l9, 858 int i11, 859 long l12, 860 int i14, 861 long l15, 862 int i17, 863 long l18, 864 int i20, 865 long l21, 866 int i23, 867 long l24, 868 int i26, 869 long l27, 870 int i29, 871 long l30, 872 int i32, 873 long l33, 874 int i35, 875 long l36, 876 int i38, 877 long l39, 878 int i41, 879 long l42, 880 int i44, 881 long l45, 882 int i47, 883 long l48, 884 int i50, 885 long l51, 886 int i53, 887 long l54, 888 int i56, 889 long l57, 890 int i59, 891 long l60, 892 int i62, 893 long l63, 894 int i65, 895 long l66, 896 int i68, 897 long l69, 898 int i71, 899 long l72, 900 int i74, 901 long l75, 902 int i77, 903 long l78, 904 int i80, 905 long l81, 906 int i83, 907 long l84, 908 int i86, 909 long l87, 910 int i89, 911 long l90, 912 int i92, 913 long l93, 914 int i95, 915 long l96, 916 int i98, 917 long l99, 918 int i101, 919 long l102, 920 int i104, 921 long l105, 922 int i107, 923 long l108, 924 int i110, 925 long l111, 926 int i113, 927 long l114, 928 int i116, 929 long l117, 930 int i119, 931 long l120, 932 int i122, 933 long l123, 934 int i125, 935 long l126, 936 int i128, 937 long l129, 938 int i131, 939 long l132, 940 int i134, 941 long l135, 942 int i137, 943 long l138, 944 int i140, 945 long l141, 946 int i143, 947 long l144, 948 int i146, 949 long l147, 950 int i149, 951 long l150, 952 int i152, 953 long l153, 954 int i155, 955 long l156, 956 int i158, 957 long l159, 958 int i161, 959 long l162, 960 int i164, 961 long l165, 962 int i167, 963 long l168, 964 int i170, 965 long l171, 966 int i173, 967 long l174, 968 int i176, 969 long l177, 970 int i179, 971 long l180, 972 int i182, 973 long l183, 974 int i185, 975 long l186, 976 int i188, 977 long l189, 978 int i191, 979 long l192, 980 int i194, 981 long l195, 982 int i197, 983 long l198, 984 int i200, 985 long l201, 986 int i203, 987 long l204, 988 int i206, 989 long l207, 990 int i209, 991 long l210, 992 int i212, 993 long l213, 994 int i215, 995 long l216, 996 int i218, 997 long l219, 998 int i221, 999 long l222, 1000 int i224, 1001 long l225, 1002 int i227, 1003 long l228, 1004 int i230, 1005 long l231, 1006 int i233, 1007 long l234, 1008 int i236, 1009 long l237, 1010 int i239, 1011 long l240, 1012 int i242, 1013 long l243, 1014 int i245, 1015 long l246, 1016 int i248, 1017 long l249, 1018 int i251, 1019 long l252, 1020 int i254); 1021 1022 // This signature exercises passing FP args in core registers on riscv64. 1023 @CriticalNative nativeDFDFDFDFDFIJ( double d1, float f1, double d2, float f2, double d3, float f3, double d4, float f4, double d5, float f5, int i, long j)1024 public static native int nativeDFDFDFDFDFIJ( 1025 double d1, 1026 float f1, 1027 double d2, 1028 float f2, 1029 double d3, 1030 float f3, 1031 double d4, 1032 float f4, 1033 double d5, 1034 float f5, 1035 int i, 1036 long j); 1037 } 1038 1039 class CriticalClinitCheck { 1040 @CriticalNative nativeMethodVoid()1041 public static native int nativeMethodVoid(); 1042 1043 @CriticalNative nativeMethod(int i)1044 public static native int nativeMethod(int i); 1045 1046 @CriticalNative nativeMethodWithManyParameters( int i1, long l1, float f1, double d1, int i2, long l2, float f2, double d2, int i3, long l3, float f3, double d3, int i4, long l4, float f4, double d4, int i5, long l5, float f5, double d5, int i6, long l6, float f6, double d6, int i7, long l7, float f7, double d7, int i8, long l8, float f8, double d8)1047 public static native int nativeMethodWithManyParameters( 1048 int i1, long l1, float f1, double d1, 1049 int i2, long l2, float f2, double d2, 1050 int i3, long l3, float f3, double d3, 1051 int i4, long l4, float f4, double d4, 1052 int i5, long l5, float f5, double d5, 1053 int i6, long l6, float f6, double d6, 1054 int i7, long l7, float f7, double d7, 1055 int i8, long l8, float f8, double d8); 1056 1057 static { Main.initializingCriticalClinitCheck()1058 Main.initializingCriticalClinitCheck(); 1059 } 1060 } 1061 1062 class B181736463Error extends Error { 1063 } 1064 1065 class BadClassB181736463 { 1066 static { 1067 // Deliberately throw from class initializer. 1068 if (true) { B181736463Error()1069 throw new B181736463Error(); 1070 } 1071 } 1072 nativeMethodVoid()1073 public static native int nativeMethodVoid(); 1074 } 1075