1 /* 2 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /** 25 * @test TestNewAcmp 26 * @summary Verifies correctness of the new acmp bytecode. 27 * @library /testlibrary /test/lib /compiler/whitebox / 28 * @compile TestNewAcmp.java 29 * @run driver ClassFileInstaller sun.hotspot.WhiteBox 30 * @run main/othervm/timeout=300 -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI 31 * compiler.valhalla.valuetypes.TestNewAcmp 32 */ 33 34 package compiler.valhalla.valuetypes; 35 36 import jdk.test.lib.Asserts; 37 import jdk.test.lib.process.ProcessTools; 38 import jdk.test.lib.process.OutputAnalyzer; 39 import java.lang.annotation.Retention; 40 import java.lang.annotation.RetentionPolicy; 41 import java.lang.invoke.*; 42 import java.lang.reflect.Method; 43 import java.util.regex.Pattern; 44 import java.util.regex.Matcher; 45 import java.util.ArrayList; 46 import java.util.Arrays; 47 import java.util.List; 48 import sun.hotspot.WhiteBox; 49 50 51 interface MyInterface { 52 53 } 54 55 inline class MyValue1 implements MyInterface { 56 final int x; 57 58 MyValue1(int x) { 59 this.x = x; 60 } 61 62 static MyValue1 createDefault() { 63 return MyValue1.default; 64 } 65 66 static MyValue1 setX(MyValue1 v, int x) { 67 return new MyValue1(x); 68 } 69 } 70 71 inline class MyValue2 implements MyInterface { 72 final int x; 73 74 MyValue2(int x) { 75 this.x = x; 76 } 77 78 static MyValue2 createDefault() { 79 return MyValue2.default; 80 } 81 82 static MyValue2 setX(MyValue2 v, int x) { 83 return new MyValue2(x); 84 } 85 } 86 87 class MyObject implements MyInterface { 88 int x; 89 } 90 91 // Mark test methods that return always false 92 @Retention(RetentionPolicy.RUNTIME) 93 @interface AlwaysFalse { 94 int[] valid_for() default {1, 2}; 95 } 96 97 // Mark test methods that return always true 98 @Retention(RetentionPolicy.RUNTIME) 99 @interface AlwaysTrue { 100 int[] valid_for() default {1, 2}; 101 } 102 103 // Mark test methods that return false if the argument is null 104 @Retention(RetentionPolicy.RUNTIME) 105 @interface FalseIfNull { } 106 107 // Mark test methods that return true if the argument is null 108 @Retention(RetentionPolicy.RUNTIME) 109 @interface TrueIfNull { } 110 111 public class TestNewAcmp { 112 113 public boolean testEq01_1(Object u1, Object u2) { 114 return get(u1) == u2; // new acmp 115 } 116 117 public boolean testEq01_2(Object u1, Object u2) { 118 return u1 == get(u2); // new acmp 119 } 120 121 public boolean testEq01_3(Object u1, Object u2) { 122 return get(u1) == get(u2); // new acmp 123 } 124 125 @FalseIfNull 126 public boolean testEq01_4(Object u1, Object u2) { 127 return getNotNull(u1) == u2; // new acmp without null check 128 } 129 130 @FalseIfNull 131 public boolean testEq01_5(Object u1, Object u2) { 132 return u1 == getNotNull(u2); // new acmp without null check 133 } 134 135 @FalseIfNull 136 public boolean testEq01_6(Object u1, Object u2) { 137 return getNotNull(u1) == getNotNull(u2); // new acmp without null check 138 } 139 140 public boolean testEq02_1(MyValue1 v1, MyValue1 v2) { 141 return get(v1) == (Object)v2; // only true if both null 142 } 143 144 public boolean testEq02_2(MyValue1 v1, MyValue1 v2) { 145 return (Object)v1 == get(v2); // only true if both null 146 } 147 148 public boolean testEq02_3(MyValue1 v1, MyValue1 v2) { 149 return get(v1) == get(v2); // only true if both null 150 } 151 152 public boolean testEq03_1(MyValue1 v, Object u) { 153 return get(v) == u; // only true if both null 154 } 155 156 public boolean testEq03_2(MyValue1 v, Object u) { 157 return (Object)v == get(u); // only true if both null 158 } 159 160 public boolean testEq03_3(MyValue1 v, Object u) { 161 return get(v) == get(u); // only true if both null 162 } 163 164 public boolean testEq04_1(Object u, MyValue1 v) { 165 return get(u) == (Object)v; // only true if both null 166 } 167 168 public boolean testEq04_2(Object u, MyValue1 v) { 169 return u == get(v); // only true if both null 170 } 171 172 public boolean testEq04_3(Object u, MyValue1 v) { 173 return get(u) == get(v); // only true if both null 174 } 175 176 public boolean testEq05_1(MyObject o, MyValue1 v) { 177 return get(o) == (Object)v; // only true if both null 178 } 179 180 public boolean testEq05_2(MyObject o, MyValue1 v) { 181 return o == get(v); // only true if both null 182 } 183 184 public boolean testEq05_3(MyObject o, MyValue1 v) { 185 return get(o) == get(v); // only true if both null 186 } 187 188 public boolean testEq06_1(MyValue1 v, MyObject o) { 189 return get(v) == o; // only true if both null 190 } 191 192 public boolean testEq06_2(MyValue1 v, MyObject o) { 193 return (Object)v == get(o); // only true if both null 194 } 195 196 public boolean testEq06_3(MyValue1 v, MyObject o) { 197 return get(v) == get(o); // only true if both null 198 } 199 200 @AlwaysFalse 201 public boolean testEq07_1(MyValue1 v1, MyValue1 v2) { 202 return getNotNull(v1) == (Object)v2; // false 203 } 204 205 @AlwaysFalse 206 public boolean testEq07_2(MyValue1 v1, MyValue1 v2) { 207 return (Object)v1 == getNotNull(v2); // false 208 } 209 210 @AlwaysFalse 211 public boolean testEq07_3(MyValue1 v1, MyValue1 v2) { 212 return getNotNull(v1) == getNotNull(v2); // false 213 } 214 215 @AlwaysFalse 216 public boolean testEq08_1(MyValue1 v, Object u) { 217 return getNotNull(v) == u; // false 218 } 219 220 @AlwaysFalse 221 public boolean testEq08_2(MyValue1 v, Object u) { 222 return (Object)v == getNotNull(u); // false 223 } 224 225 @AlwaysFalse 226 public boolean testEq08_3(MyValue1 v, Object u) { 227 return getNotNull(v) == getNotNull(u); // false 228 } 229 230 @AlwaysFalse 231 public boolean testEq09_1(Object u, MyValue1 v) { 232 return getNotNull(u) == (Object)v; // false 233 } 234 235 @AlwaysFalse 236 public boolean testEq09_2(Object u, MyValue1 v) { 237 return u == getNotNull(v); // false 238 } 239 240 @AlwaysFalse 241 public boolean testEq09_3(Object u, MyValue1 v) { 242 return getNotNull(u) == getNotNull(v); // false 243 } 244 245 @AlwaysFalse 246 public boolean testEq10_1(MyObject o, MyValue1 v) { 247 return getNotNull(o) == (Object)v; // false 248 } 249 250 @AlwaysFalse 251 public boolean testEq10_2(MyObject o, MyValue1 v) { 252 return o == getNotNull(v); // false 253 } 254 255 @AlwaysFalse 256 public boolean testEq10_3(MyObject o, MyValue1 v) { 257 return getNotNull(o) == getNotNull(v); // false 258 } 259 260 @AlwaysFalse 261 public boolean testEq11_1(MyValue1 v, MyObject o) { 262 return getNotNull(v) == o; // false 263 } 264 265 @AlwaysFalse 266 public boolean testEq11_2(MyValue1 v, MyObject o) { 267 return (Object)v == getNotNull(o); // false 268 } 269 270 @AlwaysFalse 271 public boolean testEq11_3(MyValue1 v, MyObject o) { 272 return getNotNull(v) == getNotNull(o); // false 273 } 274 275 public boolean testEq12_1(MyObject o1, MyObject o2) { 276 return get(o1) == o2; // old acmp 277 } 278 279 public boolean testEq12_2(MyObject o1, MyObject o2) { 280 return o1 == get(o2); // old acmp 281 } 282 283 public boolean testEq12_3(MyObject o1, MyObject o2) { 284 return get(o1) == get(o2); // old acmp 285 } 286 287 public boolean testEq13_1(Object u, MyObject o) { 288 return get(u) == o; // old acmp 289 } 290 291 public boolean testEq13_2(Object u, MyObject o) { 292 return u == get(o); // old acmp 293 } 294 295 public boolean testEq13_3(Object u, MyObject o) { 296 return get(u) == get(o); // old acmp 297 } 298 299 public boolean testEq14_1(MyObject o, Object u) { 300 return get(o) == u; // old acmp 301 } 302 303 public boolean testEq14_2(MyObject o, Object u) { 304 return o == get(u); // old acmp 305 } 306 307 public boolean testEq14_3(MyObject o, Object u) { 308 return get(o) == get(u); // old acmp 309 } 310 311 public boolean testEq15_1(Object[] a, Object u) { 312 return get(a) == u; // old acmp 313 } 314 315 public boolean testEq15_2(Object[] a, Object u) { 316 return a == get(u); // old acmp 317 } 318 319 public boolean testEq15_3(Object[] a, Object u) { 320 return get(a) == get(u); // old acmp 321 } 322 323 public boolean testEq16_1(Object u, Object[] a) { 324 return get(u) == a; // old acmp 325 } 326 327 public boolean testEq16_2(Object u, Object[] a) { 328 return u == get(a); // old acmp 329 } 330 331 public boolean testEq16_3(Object u, Object[] a) { 332 return get(u) == get(a); // old acmp 333 } 334 335 public boolean testEq17_1(Object[] a, MyValue1 v) { 336 return get(a) == (Object)v; // only true if both null 337 } 338 339 public boolean testEq17_2(Object[] a, MyValue1 v) { 340 return a == get(v); // only true if both null 341 } 342 343 public boolean testEq17_3(Object[] a, MyValue1 v) { 344 return get(a) == get(v); // only true if both null 345 } 346 347 public boolean testEq18_1(MyValue1 v, Object[] a) { 348 return get(v) == a; // only true if both null 349 } 350 351 public boolean testEq18_2(MyValue1 v, Object[] a) { 352 return (Object)v == get(a); // only true if both null 353 } 354 355 public boolean testEq18_3(MyValue1 v, Object[] a) { 356 return get(v) == get(a); // only true if both null 357 } 358 359 @AlwaysFalse 360 public boolean testEq19_1(Object[] a, MyValue1 v) { 361 return getNotNull(a) == (Object)v; // false 362 } 363 364 @AlwaysFalse 365 public boolean testEq19_2(Object[] a, MyValue1 v) { 366 return a == getNotNull(v); // false 367 } 368 369 @AlwaysFalse 370 public boolean testEq19_3(Object[] a, MyValue1 v) { 371 return getNotNull(a) == getNotNull(v); // false 372 } 373 374 @AlwaysFalse 375 public boolean testEq20_1(MyValue1 v, Object[] a) { 376 return getNotNull(v) == a; // false 377 } 378 379 @AlwaysFalse 380 public boolean testEq20_2(MyValue1 v, Object[] a) { 381 return (Object)v == getNotNull(a); // false 382 } 383 384 @AlwaysFalse 385 public boolean testEq20_3(MyValue1 v, Object[] a) { 386 return getNotNull(v) == getNotNull(a); // false 387 } 388 389 public boolean testEq21_1(MyInterface u1, MyInterface u2) { 390 return get(u1) == u2; // new acmp 391 } 392 393 public boolean testEq21_2(MyInterface u1, MyInterface u2) { 394 return u1 == get(u2); // new acmp 395 } 396 397 public boolean testEq21_3(MyInterface u1, MyInterface u2) { 398 return get(u1) == get(u2); // new acmp 399 } 400 401 @FalseIfNull 402 public boolean testEq21_4(MyInterface u1, MyInterface u2) { 403 return getNotNull(u1) == u2; // new acmp without null check 404 } 405 406 @FalseIfNull 407 public boolean testEq21_5(MyInterface u1, MyInterface u2) { 408 return u1 == getNotNull(u2); // new acmp without null check 409 } 410 411 @FalseIfNull 412 public boolean testEq21_6(MyInterface u1, MyInterface u2) { 413 return getNotNull(u1) == getNotNull(u2); // new acmp without null check 414 } 415 416 public boolean testEq22_1(MyValue1 v, MyInterface u) { 417 return get(v) == u; // only true if both null 418 } 419 420 public boolean testEq22_2(MyValue1 v, MyInterface u) { 421 return (Object)v == get(u); // only true if both null 422 } 423 424 public boolean testEq22_3(MyValue1 v, MyInterface u) { 425 return get(v) == get(u); // only true if both null 426 } 427 428 public boolean testEq23_1(MyInterface u, MyValue1 v) { 429 return get(u) == (Object)v; // only true if both null 430 } 431 432 public boolean testEq23_2(MyInterface u, MyValue1 v) { 433 return u == get(v); // only true if both null 434 } 435 436 public boolean testEq23_3(MyInterface u, MyValue1 v) { 437 return get(u) == get(v); // only true if both null 438 } 439 440 @AlwaysFalse 441 public boolean testEq24_1(MyValue1 v, MyInterface u) { 442 return getNotNull(v) == u; // false 443 } 444 445 @AlwaysFalse 446 public boolean testEq24_2(MyValue1 v, MyInterface u) { 447 return (Object)v == getNotNull(u); // false 448 } 449 450 @AlwaysFalse 451 public boolean testEq24_3(MyValue1 v, MyInterface u) { 452 return getNotNull(v) == getNotNull(u); // false 453 } 454 455 @AlwaysFalse 456 public boolean testEq25_1(MyInterface u, MyValue1 v) { 457 return getNotNull(u) == (Object)v; // false 458 } 459 460 @AlwaysFalse 461 public boolean testEq25_2(MyInterface u, MyValue1 v) { 462 return u == getNotNull(v); // false 463 } 464 465 @AlwaysFalse 466 public boolean testEq25_3(MyInterface u, MyValue1 v) { 467 return getNotNull(u) == getNotNull(v); // false 468 } 469 470 public boolean testEq26_1(MyInterface u, MyObject o) { 471 return get(u) == o; // old acmp 472 } 473 474 public boolean testEq26_2(MyInterface u, MyObject o) { 475 return u == get(o); // old acmp 476 } 477 478 public boolean testEq26_3(MyInterface u, MyObject o) { 479 return get(u) == get(o); // old acmp 480 } 481 482 public boolean testEq27_1(MyObject o, MyInterface u) { 483 return get(o) == u; // old acmp 484 } 485 486 public boolean testEq27_2(MyObject o, MyInterface u) { 487 return o == get(u); // old acmp 488 } 489 490 public boolean testEq27_3(MyObject o, MyInterface u) { 491 return get(o) == get(u); // old acmp 492 } 493 494 public boolean testEq28_1(MyInterface[] a, MyInterface u) { 495 return get(a) == u; // old acmp 496 } 497 498 public boolean testEq28_2(MyInterface[] a, MyInterface u) { 499 return a == get(u); // old acmp 500 } 501 502 public boolean testEq28_3(MyInterface[] a, MyInterface u) { 503 return get(a) == get(u); // old acmp 504 } 505 506 public boolean testEq29_1(MyInterface u, MyInterface[] a) { 507 return get(u) == a; // old acmp 508 } 509 510 public boolean testEq29_2(MyInterface u, MyInterface[] a) { 511 return u == get(a); // old acmp 512 } 513 514 public boolean testEq29_3(MyInterface u, MyInterface[] a) { 515 return get(u) == get(a); // old acmp 516 } 517 518 public boolean testEq30_1(MyInterface[] a, MyValue1 v) { 519 return get(a) == (Object)v; // only true if both null 520 } 521 522 public boolean testEq30_2(MyInterface[] a, MyValue1 v) { 523 return a == get(v); // only true if both null 524 } 525 526 public boolean testEq30_3(MyInterface[] a, MyValue1 v) { 527 return get(a) == get(v); // only true if both null 528 } 529 530 public boolean testEq31_1(MyValue1 v, MyInterface[] a) { 531 return get(v) == a; // only true if both null 532 } 533 534 public boolean testEq31_2(MyValue1 v, MyInterface[] a) { 535 return (Object)v == get(a); // only true if both null 536 } 537 538 public boolean testEq31_3(MyValue1 v, MyInterface[] a) { 539 return get(v) == get(a); // only true if both null 540 } 541 542 @AlwaysFalse 543 public boolean testEq32_1(MyInterface[] a, MyValue1 v) { 544 return getNotNull(a) == (Object)v; // false 545 } 546 547 @AlwaysFalse 548 public boolean testEq32_2(MyInterface[] a, MyValue1 v) { 549 return a == getNotNull(v); // false 550 } 551 552 @AlwaysFalse 553 public boolean testEq32_3(MyInterface[] a, MyValue1 v) { 554 return getNotNull(a) == getNotNull(v); // false 555 } 556 557 @AlwaysFalse 558 public boolean testEq33_1(MyValue1 v, MyInterface[] a) { 559 return getNotNull(v) == a; // false 560 } 561 562 @AlwaysFalse 563 public boolean testEq33_2(MyValue1 v, MyInterface[] a) { 564 return (Object)v == getNotNull(a); // false 565 } 566 567 @AlwaysFalse 568 public boolean testEq33_3(MyValue1 v, MyInterface[] a) { 569 return getNotNull(v) == getNotNull(a); // false 570 } 571 572 573 // Null tests 574 575 public boolean testNull01_1(MyValue1 v) { 576 return (Object)v == null; // old acmp 577 } 578 579 public boolean testNull01_2(MyValue1 v) { 580 return get(v) == null; // old acmp 581 } 582 583 public boolean testNull01_3(MyValue1 v) { 584 return (Object)v == get((Object)null); // old acmp 585 } 586 587 public boolean testNull01_4(MyValue1 v) { 588 return get(v) == get((Object)null); // old acmp 589 } 590 591 public boolean testNull02_1(MyValue1 v) { 592 return null == (Object)v; // old acmp 593 } 594 595 public boolean testNull02_2(MyValue1 v) { 596 return get((Object)null) == (Object)v; // old acmp 597 } 598 599 public boolean testNull02_3(MyValue1 v) { 600 return null == get(v); // old acmp 601 } 602 603 public boolean testNull02_4(MyValue1 v) { 604 return get((Object)null) == get(v); // old acmp 605 } 606 607 public boolean testNull03_1(Object u) { 608 return u == null; // old acmp 609 } 610 611 public boolean testNull03_2(Object u) { 612 return get(u) == null; // old acmp 613 } 614 615 public boolean testNull03_3(Object u) { 616 return u == get((Object)null); // old acmp 617 } 618 619 public boolean testNull03_4(Object u) { 620 return get(u) == get((Object)null); // old acmp 621 } 622 623 public boolean testNull04_1(Object u) { 624 return null == u; // old acmp 625 } 626 627 public boolean testNull04_2(Object u) { 628 return get((Object)null) == u; // old acmp 629 } 630 631 public boolean testNull04_3(Object u) { 632 return null == get(u); // old acmp 633 } 634 635 public boolean testNull04_4(Object u) { 636 return get((Object)null) == get(u); // old acmp 637 } 638 639 public boolean testNull05_1(MyObject o) { 640 return o == null; // old acmp 641 } 642 643 public boolean testNull05_2(MyObject o) { 644 return get(o) == null; // old acmp 645 } 646 647 public boolean testNull05_3(MyObject o) { 648 return o == get((Object)null); // old acmp 649 } 650 651 public boolean testNull05_4(MyObject o) { 652 return get(o) == get((Object)null); // old acmp 653 } 654 655 public boolean testNull06_1(MyObject o) { 656 return null == o; // old acmp 657 } 658 659 public boolean testNull06_2(MyObject o) { 660 return get((Object)null) == o; // old acmp 661 } 662 663 public boolean testNull06_3(MyObject o) { 664 return null == get(o); // old acmp 665 } 666 667 public boolean testNull06_4(MyObject o) { 668 return get((Object)null) == get(o); // old acmp 669 } 670 671 public boolean testNull07_1(MyInterface u) { 672 return u == null; // old acmp 673 } 674 675 public boolean testNull07_2(MyInterface u) { 676 return get(u) == null; // old acmp 677 } 678 679 public boolean testNull07_3(MyInterface u) { 680 return u == get((Object)null); // old acmp 681 } 682 683 public boolean testNull07_4(MyInterface u) { 684 return get(u) == get((Object)null); // old acmp 685 } 686 687 public boolean testNull08_1(MyInterface u) { 688 return null == u; // old acmp 689 } 690 691 public boolean testNull08_2(MyInterface u) { 692 return get((Object)null) == u; // old acmp 693 } 694 695 public boolean testNull08_3(MyInterface u) { 696 return null == get(u); // old acmp 697 } 698 699 public boolean testNull08_4(MyInterface u) { 700 return get((Object)null) == get(u); // old acmp 701 } 702 703 // Same tests as above but negated 704 705 public boolean testNotEq01_1(Object u1, Object u2) { 706 return get(u1) != u2; // new acmp 707 } 708 709 public boolean testNotEq01_2(Object u1, Object u2) { 710 return u1 != get(u2); // new acmp 711 } 712 713 public boolean testNotEq01_3(Object u1, Object u2) { 714 return get(u1) != get(u2); // new acmp 715 } 716 717 @TrueIfNull 718 public boolean testNotEq01_4(Object u1, Object u2) { 719 return getNotNull(u1) != u2; // new acmp without null check 720 } 721 722 @TrueIfNull 723 public boolean testNotEq01_5(Object u1, Object u2) { 724 return u1 != getNotNull(u2); // new acmp without null check 725 } 726 727 @TrueIfNull 728 public boolean testNotEq01_6(Object u1, Object u2) { 729 return getNotNull(u1) != getNotNull(u2); // new acmp without null check 730 } 731 732 public boolean testNotEq02_1(MyValue1 v1, MyValue1 v2) { 733 return get(v1) != (Object)v2; // only false if both null 734 } 735 736 public boolean testNotEq02_2(MyValue1 v1, MyValue1 v2) { 737 return (Object)v1 != get(v2); // only false if both null 738 } 739 740 public boolean testNotEq02_3(MyValue1 v1, MyValue1 v2) { 741 return get(v1) != get(v2); // only false if both null 742 } 743 744 public boolean testNotEq03_1(MyValue1 v, Object u) { 745 return get(v) != u; // only false if both null 746 } 747 748 public boolean testNotEq03_2(MyValue1 v, Object u) { 749 return (Object)v != get(u); // only false if both null 750 } 751 752 public boolean testNotEq03_3(MyValue1 v, Object u) { 753 return get(v) != get(u); // only false if both null 754 } 755 756 public boolean testNotEq04_1(Object u, MyValue1 v) { 757 return get(u) != (Object)v; // only false if both null 758 } 759 760 public boolean testNotEq04_2(Object u, MyValue1 v) { 761 return u != get(v); // only false if both null 762 } 763 764 public boolean testNotEq04_3(Object u, MyValue1 v) { 765 return get(u) != get(v); // only false if both null 766 } 767 768 public boolean testNotEq05_1(MyObject o, MyValue1 v) { 769 return get(o) != (Object)v; // only false if both null 770 } 771 772 public boolean testNotEq05_2(MyObject o, MyValue1 v) { 773 return o != get(v); // only false if both null 774 } 775 776 public boolean testNotEq05_3(MyObject o, MyValue1 v) { 777 return get(o) != get(v); // only false if both null 778 } 779 780 public boolean testNotEq06_1(MyValue1 v, MyObject o) { 781 return get(v) != o; // only false if both null 782 } 783 784 public boolean testNotEq06_2(MyValue1 v, MyObject o) { 785 return (Object)v != get(o); // only false if both null 786 } 787 788 public boolean testNotEq06_3(MyValue1 v, MyObject o) { 789 return get(v) != get(o); // only false if both null 790 } 791 792 @AlwaysTrue 793 public boolean testNotEq07_1(MyValue1 v1, MyValue1 v2) { 794 return getNotNull(v1) != (Object)v2; // true 795 } 796 797 @AlwaysTrue 798 public boolean testNotEq07_2(MyValue1 v1, MyValue1 v2) { 799 return (Object)v1 != getNotNull(v2); // true 800 } 801 802 @AlwaysTrue 803 public boolean testNotEq07_3(MyValue1 v1, MyValue1 v2) { 804 return getNotNull(v1) != getNotNull(v2); // true 805 } 806 807 @AlwaysTrue 808 public boolean testNotEq08_1(MyValue1 v, Object u) { 809 return getNotNull(v) != u; // true 810 } 811 812 @AlwaysTrue 813 public boolean testNotEq08_2(MyValue1 v, Object u) { 814 return (Object)v != getNotNull(u); // true 815 } 816 817 @AlwaysTrue 818 public boolean testNotEq08_3(MyValue1 v, Object u) { 819 return getNotNull(v) != getNotNull(u); // true 820 } 821 822 @AlwaysTrue 823 public boolean testNotEq09_1(Object u, MyValue1 v) { 824 return getNotNull(u) != (Object)v; // true 825 } 826 827 @AlwaysTrue 828 public boolean testNotEq09_2(Object u, MyValue1 v) { 829 return u != getNotNull(v); // true 830 } 831 832 @AlwaysTrue 833 public boolean testNotEq09_3(Object u, MyValue1 v) { 834 return getNotNull(u) != getNotNull(v); // true 835 } 836 837 @AlwaysTrue 838 public boolean testNotEq10_1(MyObject o, MyValue1 v) { 839 return getNotNull(o) != (Object)v; // true 840 } 841 842 @AlwaysTrue 843 public boolean testNotEq10_2(MyObject o, MyValue1 v) { 844 return o != getNotNull(v); // true 845 } 846 847 @AlwaysTrue 848 public boolean testNotEq10_3(MyObject o, MyValue1 v) { 849 return getNotNull(o) != getNotNull(v); // true 850 } 851 852 @AlwaysTrue 853 public boolean testNotEq11_1(MyValue1 v, MyObject o) { 854 return getNotNull(v) != o; // true 855 } 856 857 @AlwaysTrue 858 public boolean testNotEq11_2(MyValue1 v, MyObject o) { 859 return (Object)v != getNotNull(o); // true 860 } 861 862 @AlwaysTrue 863 public boolean testNotEq11_3(MyValue1 v, MyObject o) { 864 return getNotNull(v) != getNotNull(o); // true 865 } 866 867 public boolean testNotEq12_1(MyObject o1, MyObject o2) { 868 return get(o1) != o2; // old acmp 869 } 870 871 public boolean testNotEq12_2(MyObject o1, MyObject o2) { 872 return o1 != get(o2); // old acmp 873 } 874 875 public boolean testNotEq12_3(MyObject o1, MyObject o2) { 876 return get(o1) != get(o2); // old acmp 877 } 878 879 public boolean testNotEq13_1(Object u, MyObject o) { 880 return get(u) != o; // old acmp 881 } 882 883 public boolean testNotEq13_2(Object u, MyObject o) { 884 return u != get(o); // old acmp 885 } 886 887 public boolean testNotEq13_3(Object u, MyObject o) { 888 return get(u) != get(o); // old acmp 889 } 890 891 public boolean testNotEq14_1(MyObject o, Object u) { 892 return get(o) != u; // old acmp 893 } 894 895 public boolean testNotEq14_2(MyObject o, Object u) { 896 return o != get(u); // old acmp 897 } 898 899 public boolean testNotEq14_3(MyObject o, Object u) { 900 return get(o) != get(u); // old acmp 901 } 902 903 public boolean testNotEq15_1(Object[] a, Object u) { 904 return get(a) != u; // old acmp 905 } 906 907 public boolean testNotEq15_2(Object[] a, Object u) { 908 return a != get(u); // old acmp 909 } 910 911 public boolean testNotEq15_3(Object[] a, Object u) { 912 return get(a) != get(u); // old acmp 913 } 914 915 public boolean testNotEq16_1(Object u, Object[] a) { 916 return get(u) != a; // old acmp 917 } 918 919 public boolean testNotEq16_2(Object u, Object[] a) { 920 return u != get(a); // old acmp 921 } 922 923 public boolean testNotEq16_3(Object u, Object[] a) { 924 return get(u) != get(a); // old acmp 925 } 926 927 public boolean testNotEq17_1(Object[] a, MyValue1 v) { 928 return get(a) != (Object)v; // only false if both null 929 } 930 931 public boolean testNotEq17_2(Object[] a, MyValue1 v) { 932 return a != get(v); // only false if both null 933 } 934 935 public boolean testNotEq17_3(Object[] a, MyValue1 v) { 936 return get(a) != get(v); // only false if both null 937 } 938 939 public boolean testNotEq18_1(MyValue1 v, Object[] a) { 940 return get(v) != a; // only false if both null 941 } 942 943 public boolean testNotEq18_2(MyValue1 v, Object[] a) { 944 return (Object)v != get(a); // only false if both null 945 } 946 947 public boolean testNotEq18_3(MyValue1 v, Object[] a) { 948 return get(v) != get(a); // only false if both null 949 } 950 951 @AlwaysTrue 952 public boolean testNotEq19_1(Object[] a, MyValue1 v) { 953 return getNotNull(a) != (Object)v; // true 954 } 955 956 @AlwaysTrue 957 public boolean testNotEq19_2(Object[] a, MyValue1 v) { 958 return a != getNotNull(v); // true 959 } 960 961 @AlwaysTrue 962 public boolean testNotEq19_3(Object[] a, MyValue1 v) { 963 return getNotNull(a) != getNotNull(v); // true 964 } 965 966 @AlwaysTrue 967 public boolean testNotEq20_1(MyValue1 v, Object[] a) { 968 return getNotNull(v) != a; // true 969 } 970 971 @AlwaysTrue 972 public boolean testNotEq20_2(MyValue1 v, Object[] a) { 973 return (Object)v != getNotNull(a); // true 974 } 975 976 @AlwaysTrue 977 public boolean testNotEq20_3(MyValue1 v, Object[] a) { 978 return getNotNull(v) != getNotNull(a); // true 979 } 980 981 public boolean testNotEq21_1(MyInterface u1, MyInterface u2) { 982 return get(u1) != u2; // new acmp 983 } 984 985 public boolean testNotEq21_2(MyInterface u1, MyInterface u2) { 986 return u1 != get(u2); // new acmp 987 } 988 989 public boolean testNotEq21_3(MyInterface u1, MyInterface u2) { 990 return get(u1) != get(u2); // new acmp 991 } 992 993 @TrueIfNull 994 public boolean testNotEq21_4(MyInterface u1, MyInterface u2) { 995 return getNotNull(u1) != u2; // new acmp without null check 996 } 997 998 @TrueIfNull 999 public boolean testNotEq21_5(MyInterface u1, MyInterface u2) { 1000 return u1 != getNotNull(u2); // new acmp without null check 1001 } 1002 1003 @TrueIfNull 1004 public boolean testNotEq21_6(MyInterface u1, MyInterface u2) { 1005 return getNotNull(u1) != getNotNull(u2); // new acmp without null check 1006 } 1007 1008 public boolean testNotEq22_1(MyValue1 v, MyInterface u) { 1009 return get(v) != u; // only false if both null 1010 } 1011 1012 public boolean testNotEq22_2(MyValue1 v, MyInterface u) { 1013 return (Object)v != get(u); // only false if both null 1014 } 1015 1016 public boolean testNotEq22_3(MyValue1 v, MyInterface u) { 1017 return get(v) != get(u); // only false if both null 1018 } 1019 1020 public boolean testNotEq23_1(MyInterface u, MyValue1 v) { 1021 return get(u) != (Object)v; // only false if both null 1022 } 1023 1024 public boolean testNotEq23_2(MyInterface u, MyValue1 v) { 1025 return u != get(v); // only false if both null 1026 } 1027 1028 public boolean testNotEq23_3(MyInterface u, MyValue1 v) { 1029 return get(u) != get(v); // only false if both null 1030 } 1031 1032 @AlwaysTrue 1033 public boolean testNotEq24_1(MyValue1 v, MyInterface u) { 1034 return getNotNull(v) != u; // true 1035 } 1036 1037 @AlwaysTrue 1038 public boolean testNotEq24_2(MyValue1 v, MyInterface u) { 1039 return (Object)v != getNotNull(u); // true 1040 } 1041 1042 @AlwaysTrue 1043 public boolean testNotEq24_3(MyValue1 v, MyInterface u) { 1044 return getNotNull(v) != getNotNull(u); // true 1045 } 1046 1047 @AlwaysTrue 1048 public boolean testNotEq25_1(MyInterface u, MyValue1 v) { 1049 return getNotNull(u) != (Object)v; // true 1050 } 1051 1052 @AlwaysTrue 1053 public boolean testNotEq25_2(MyInterface u, MyValue1 v) { 1054 return u != getNotNull(v); // true 1055 } 1056 1057 @AlwaysTrue 1058 public boolean testNotEq25_3(MyInterface u, MyValue1 v) { 1059 return getNotNull(u) != getNotNull(v); // true 1060 } 1061 1062 public boolean testNotEq26_1(MyInterface u, MyObject o) { 1063 return get(u) != o; // old acmp 1064 } 1065 1066 public boolean testNotEq26_2(MyInterface u, MyObject o) { 1067 return u != get(o); // old acmp 1068 } 1069 1070 public boolean testNotEq26_3(MyInterface u, MyObject o) { 1071 return get(u) != get(o); // old acmp 1072 } 1073 1074 public boolean testNotEq27_1(MyObject o, MyInterface u) { 1075 return get(o) != u; // old acmp 1076 } 1077 1078 public boolean testNotEq27_2(MyObject o, MyInterface u) { 1079 return o != get(u); // old acmp 1080 } 1081 1082 public boolean testNotEq27_3(MyObject o, MyInterface u) { 1083 return get(o) != get(u); // old acmp 1084 } 1085 1086 public boolean testNotEq28_1(MyInterface[] a, MyInterface u) { 1087 return get(a) != u; // old acmp 1088 } 1089 1090 public boolean testNotEq28_2(MyInterface[] a, MyInterface u) { 1091 return a != get(u); // old acmp 1092 } 1093 1094 public boolean testNotEq28_3(MyInterface[] a, MyInterface u) { 1095 return get(a) != get(u); // old acmp 1096 } 1097 1098 public boolean testNotEq29_1(MyInterface u, MyInterface[] a) { 1099 return get(u) != a; // old acmp 1100 } 1101 1102 public boolean testNotEq29_2(MyInterface u, MyInterface[] a) { 1103 return u != get(a); // old acmp 1104 } 1105 1106 public boolean testNotEq29_3(MyInterface u, MyInterface[] a) { 1107 return get(u) != get(a); // old acmp 1108 } 1109 1110 public boolean testNotEq30_1(MyInterface[] a, MyValue1 v) { 1111 return get(a) != (Object)v; // only false if both null 1112 } 1113 1114 public boolean testNotEq30_2(MyInterface[] a, MyValue1 v) { 1115 return a != get(v); // only false if both null 1116 } 1117 1118 public boolean testNotEq30_3(MyInterface[] a, MyValue1 v) { 1119 return get(a) != get(v); // only false if both null 1120 } 1121 1122 public boolean testNotEq31_1(MyValue1 v, MyInterface[] a) { 1123 return get(v) != a; // only false if both null 1124 } 1125 1126 public boolean testNotEq31_2(MyValue1 v, MyInterface[] a) { 1127 return (Object)v != get(a); // only false if both null 1128 } 1129 1130 public boolean testNotEq31_3(MyValue1 v, MyInterface[] a) { 1131 return get(v) != get(a); // only false if both null 1132 } 1133 1134 @AlwaysTrue 1135 public boolean testNotEq32_1(MyInterface[] a, MyValue1 v) { 1136 return getNotNull(a) != (Object)v; // true 1137 } 1138 1139 @AlwaysTrue 1140 public boolean testNotEq32_2(MyInterface[] a, MyValue1 v) { 1141 return a != getNotNull(v); // true 1142 } 1143 1144 @AlwaysTrue 1145 public boolean testNotEq32_3(MyInterface[] a, MyValue1 v) { 1146 return getNotNull(a) != getNotNull(v); // true 1147 } 1148 1149 @AlwaysTrue 1150 public boolean testNotEq33_1(MyValue1 v, MyInterface[] a) { 1151 return getNotNull(v) != a; // true 1152 } 1153 1154 @AlwaysTrue 1155 public boolean testNotEq33_2(MyValue1 v, MyInterface[] a) { 1156 return (Object)v != getNotNull(a); // true 1157 } 1158 1159 @AlwaysTrue 1160 public boolean testNotEq33_3(MyValue1 v, MyInterface[] a) { 1161 return getNotNull(v) != getNotNull(a); // true 1162 } 1163 1164 // Null tests 1165 1166 public boolean testNotNull01_1(MyValue1 v) { 1167 return (Object)v != null; // old acmp 1168 } 1169 1170 public boolean testNotNull01_2(MyValue1 v) { 1171 return get(v) != null; // old acmp 1172 } 1173 1174 public boolean testNotNull01_3(MyValue1 v) { 1175 return (Object)v != get((Object)null); // old acmp 1176 } 1177 1178 public boolean testNotNull01_4(MyValue1 v) { 1179 return get(v) != get((Object)null); // old acmp 1180 } 1181 1182 public boolean testNotNull02_1(MyValue1 v) { 1183 return null != (Object)v; // old acmp 1184 } 1185 1186 public boolean testNotNull02_2(MyValue1 v) { 1187 return get((Object)null) != (Object)v; // old acmp 1188 } 1189 1190 public boolean testNotNull02_3(MyValue1 v) { 1191 return null != get(v); // old acmp 1192 } 1193 1194 public boolean testNotNull02_4(MyValue1 v) { 1195 return get((Object)null) != get(v); // old acmp 1196 } 1197 1198 public boolean testNotNull03_1(Object u) { 1199 return u != null; // old acmp 1200 } 1201 1202 public boolean testNotNull03_2(Object u) { 1203 return get(u) != null; // old acmp 1204 } 1205 1206 public boolean testNotNull03_3(Object u) { 1207 return u != get((Object)null); // old acmp 1208 } 1209 1210 public boolean testNotNull03_4(Object u) { 1211 return get(u) != get((Object)null); // old acmp 1212 } 1213 1214 public boolean testNotNull04_1(Object u) { 1215 return null != u; // old acmp 1216 } 1217 1218 public boolean testNotNull04_2(Object u) { 1219 return get((Object)null) != u; // old acmp 1220 } 1221 1222 public boolean testNotNull04_3(Object u) { 1223 return null != get(u); // old acmp 1224 } 1225 1226 public boolean testNotNull04_4(Object u) { 1227 return get((Object)null) != get(u); // old acmp 1228 } 1229 1230 public boolean testNotNull05_1(MyObject o) { 1231 return o != null; // old acmp 1232 } 1233 1234 public boolean testNotNull05_2(MyObject o) { 1235 return get(o) != null; // old acmp 1236 } 1237 1238 public boolean testNotNull05_3(MyObject o) { 1239 return o != get((Object)null); // old acmp 1240 } 1241 1242 public boolean testNotNull05_4(MyObject o) { 1243 return get(o) != get((Object)null); // old acmp 1244 } 1245 1246 public boolean testNotNull06_1(MyObject o) { 1247 return null != o; // old acmp 1248 } 1249 1250 public boolean testNotNull06_2(MyObject o) { 1251 return get((Object)null) != o; // old acmp 1252 } 1253 1254 public boolean testNotNull06_3(MyObject o) { 1255 return null != get(o); // old acmp 1256 } 1257 1258 public boolean testNotNull06_4(MyObject o) { 1259 return get((Object)null) != get(o); // old acmp 1260 } 1261 1262 public boolean testNotNull07_1(MyInterface u) { 1263 return u != null; // old acmp 1264 } 1265 1266 public boolean testNotNull07_2(MyInterface u) { 1267 return get(u) != null; // old acmp 1268 } 1269 1270 public boolean testNotNull07_3(MyInterface u) { 1271 return u != get((Object)null); // old acmp 1272 } 1273 1274 public boolean testNotNull07_4(MyInterface u) { 1275 return get(u) != get((Object)null); // old acmp 1276 } 1277 1278 public boolean testNotNull08_1(MyInterface u) { 1279 return null != u; // old acmp 1280 } 1281 1282 public boolean testNotNull08_2(MyInterface u) { 1283 return get((Object)null) != u; // old acmp 1284 } 1285 1286 public boolean testNotNull08_3(MyInterface u) { 1287 return null != get(u); // old acmp 1288 } 1289 1290 public boolean testNotNull08_4(MyInterface u) { 1291 return get((Object)null) != get(u); // old acmp 1292 } 1293 1294 // The following methods are used with -XX:+AlwaysIncrementalInline to hide exact types during parsing 1295 1296 public Object get(Object u) { 1297 return u; 1298 } 1299 1300 public Object getNotNull(Object u) { 1301 return (u != null) ? u : new Object(); 1302 } 1303 1304 public Object get(MyValue1 v) { 1305 return v; 1306 } 1307 1308 public Object getNotNull(MyValue1 v) { 1309 return ((Object)v != null) ? v : MyValue1.createDefault(); 1310 } 1311 1312 public Object get(MyObject o) { 1313 return o; 1314 } 1315 1316 public Object getNotNull(MyObject o) { 1317 return (o != null) ? o : MyValue1.createDefault(); 1318 } 1319 1320 public Object get(Object[] a) { 1321 return a; 1322 } 1323 1324 public Object getNotNull(Object[] a) { 1325 return (a != null) ? a : new Object[1]; 1326 } 1327 1328 public boolean trueIfNull(Method m) { 1329 return m.isAnnotationPresent(TrueIfNull.class); 1330 } 1331 1332 public boolean falseIfNull(Method m) { 1333 return m.isAnnotationPresent(FalseIfNull.class); 1334 } 1335 1336 public boolean alwaysTrue(Method m) { 1337 return m.isAnnotationPresent(AlwaysTrue.class) && 1338 Arrays.asList(((AlwaysTrue)m.getAnnotation(AlwaysTrue.class)).valid_for()).contains(ACmpOnValues); 1339 } 1340 1341 public boolean alwaysFalse(Method m) { 1342 return m.isAnnotationPresent(AlwaysFalse.class) && 1343 Arrays.asList(((AlwaysFalse)m.getAnnotation(AlwaysFalse.class)).valid_for()).contains(ACmpOnValues); 1344 } 1345 1346 public boolean isNegated(Method m) { 1347 return m.getName().startsWith("testNot"); 1348 } 1349 1350 // Tests with profiling 1351 public boolean cmpAlwaysEqual1(Object a, Object b) { 1352 return a == b; 1353 } 1354 1355 public boolean cmpAlwaysEqual2(Object a, Object b) { 1356 return a != b; 1357 } 1358 1359 public boolean cmpAlwaysEqual3(Object a) { 1360 return a == a; 1361 } 1362 1363 public boolean cmpAlwaysEqual4(Object a) { 1364 return a != a; 1365 } 1366 1367 public boolean cmpAlwaysUnEqual1(Object a, Object b) { 1368 return a == b; 1369 } 1370 1371 public boolean cmpAlwaysUnEqual2(Object a, Object b) { 1372 return a != b; 1373 } 1374 1375 public boolean cmpAlwaysUnEqual3(Object a) { 1376 return a == a; 1377 } 1378 1379 public boolean cmpAlwaysUnEqual4(Object a) { 1380 return a != a; 1381 } 1382 1383 public boolean cmpSometimesEqual1(Object a) { 1384 return a == a; 1385 } 1386 1387 public boolean cmpSometimesEqual2(Object a) { 1388 return a != a; 1389 } 1390 1391 static int get_full_opt_level() { 1392 int n = (int)TieredStopAtLevel; 1393 if (n >= 4) { 1394 n = 4; 1395 } 1396 return n; 1397 } 1398 protected static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox(); 1399 protected static final long TieredStopAtLevel = (Long)WHITE_BOX.getVMFlag("TieredStopAtLevel"); 1400 protected static final int COMP_LEVEL_FULL_OPTIMIZATION = get_full_opt_level(); 1401 protected static final long ACmpOnValues = (Long)WHITE_BOX.getVMFlag("ACmpOnValues"); 1402 1403 // FIXME: temp -- special handling for C1 testing. 1404 protected static final boolean EnableValhallaC1 = (Boolean)WHITE_BOX.getVMFlag("EnableValhallaC1"); 1405 1406 public void runTest(Method m, Object[] args, int warmup, int nullMode, boolean[][] equalities) throws Exception { 1407 Class<?>[] parameterTypes = m.getParameterTypes(); 1408 int parameterCount = parameterTypes.length; 1409 // Nullness mode for first argument 1410 // 0: default, 1: never null, 2: always null 1411 int start = (nullMode != 1) ? 0 : 1; 1412 int end = (nullMode != 2) ? args.length : 1; 1413 for (int i = start; i < end; ++i) { 1414 if (args[i] != null && !parameterTypes[0].isInstance(args[i])) { 1415 continue; 1416 } 1417 if (args[i] == null && parameterTypes[0] == MyValue1.class) { 1418 continue; 1419 } 1420 if (parameterCount == 1) { 1421 // Null checks 1422 System.out.print("Testing " + m.getName() + "(" + args[i] + ")"); 1423 // Avoid acmp in the computation of the expected result! 1424 boolean expected = isNegated(m) ? (i != 0) : (i == 0); 1425 for (int run = 0; run < warmup; ++run) { 1426 Boolean result = (Boolean)m.invoke(this, args[i]); 1427 if (result != expected && WHITE_BOX.isMethodCompiled(m, false)) { 1428 System.out.println(" = " + result); 1429 throw new RuntimeException("Test failed: should return " + expected); 1430 } 1431 } 1432 System.out.println(" = " + expected); 1433 } else { 1434 // Equality checks 1435 for (int j = 0; j < args.length; ++j) { 1436 if (args[j] != null && !parameterTypes[1].isInstance(args[j])) { 1437 continue; 1438 } 1439 if (args[j] == null && parameterTypes[1] == MyValue1.class) { 1440 continue; 1441 } 1442 System.out.print("Testing " + m.getName() + "(" + args[i] + ", " + args[j] + ")"); 1443 // Avoid acmp in the computation of the expected result! 1444 boolean equal = equalities[i][j]; 1445 equal = isNegated(m) ? !equal : equal; 1446 boolean expected = alwaysTrue(m) || ((i == 0 || j == 0) && trueIfNull(m)) || (!alwaysFalse(m) && equal && !(i == 0 && falseIfNull(m))); 1447 for (int run = 0; run < warmup; ++run) { 1448 Boolean result = (Boolean)m.invoke(this, args[i], args[j]); 1449 if (result != expected && WHITE_BOX.isMethodCompiled(m, false) && warmup == 1) { 1450 System.out.println(" = " + result); 1451 throw new RuntimeException("Test failed: should return " + expected); 1452 } 1453 } 1454 System.out.println(" = " + expected); 1455 } 1456 } 1457 } 1458 } 1459 1460 public void run(int nullMode) throws Exception { 1461 // Prepare test arguments 1462 Object[] args = { null, 1463 new Object(), 1464 new MyObject(), 1465 MyValue1.setX(MyValue1.createDefault(), 42), 1466 new Object[10], 1467 new MyObject[10], 1468 MyValue1.setX(MyValue1.createDefault(), 0x42), 1469 MyValue1.setX(MyValue1.createDefault(), 42), 1470 MyValue2.setX(MyValue2.createDefault(), 42), }; 1471 1472 boolean[][] equalities = { { true, false, false, false, false, false, false, false, false }, 1473 { false, true, false, false, false, false, false, false, false }, 1474 { false, false, true, false, false, false, false, false, false }, 1475 { false, false, false, ACmpOnValues == 3,false, false, false, ACmpOnValues == 3, false }, 1476 { false, false, false, false, true, false, false, false, false }, 1477 { false, false, false, false, false, true, false, false, false }, 1478 { false, false, false, false, false, false, ACmpOnValues == 3, false, false }, 1479 { false, false, false, ACmpOnValues == 3,false, false, false, ACmpOnValues == 3, false }, 1480 { false, false, false, false, false, false, false, false, ACmpOnValues == 3 } }; 1481 1482 // Run tests 1483 for (Method m : getClass().getMethods()) { 1484 if (m.getName().startsWith("test")) { 1485 // Do some warmup runs 1486 runTest(m, args, 1000, nullMode, equalities); 1487 // Make sure method is compiled 1488 WHITE_BOX.enqueueMethodForCompilation(m, COMP_LEVEL_FULL_OPTIMIZATION); 1489 Asserts.assertTrue(WHITE_BOX.isMethodCompiled(m, false), m + " not compiled"); 1490 // Run again to verify correctness of compiled code 1491 runTest(m, args, 1, nullMode, equalities); 1492 } 1493 } 1494 1495 Method cmpAlwaysUnEqual3_m = getClass().getMethod("cmpAlwaysUnEqual3", Object.class); 1496 Method cmpAlwaysUnEqual4_m = getClass().getMethod("cmpAlwaysUnEqual4", Object.class); 1497 Method cmpSometimesEqual1_m = getClass().getMethod("cmpSometimesEqual1", Object.class); 1498 Method cmpSometimesEqual2_m = getClass().getMethod("cmpSometimesEqual2", Object.class); 1499 1500 for (int i = 0; i < 20_000; ++i) { 1501 Asserts.assertTrue(cmpAlwaysEqual1(args[1], args[1])); 1502 Asserts.assertFalse(cmpAlwaysEqual2(args[1], args[1])); 1503 Asserts.assertTrue(cmpAlwaysEqual3(args[1])); 1504 Asserts.assertFalse(cmpAlwaysEqual4(args[1])); 1505 1506 Asserts.assertFalse(cmpAlwaysUnEqual1(args[1], args[2])); 1507 Asserts.assertTrue(cmpAlwaysUnEqual2(args[1], args[2])); 1508 boolean compiled = WHITE_BOX.isMethodCompiled(cmpAlwaysUnEqual3_m, false); 1509 boolean res = cmpAlwaysUnEqual3(args[3]); 1510 if (ACmpOnValues != 3) { 1511 Asserts.assertFalse(res); 1512 } else if (compiled) { 1513 Asserts.assertTrue(res); 1514 } 1515 compiled = WHITE_BOX.isMethodCompiled(cmpAlwaysUnEqual4_m, false); 1516 res = cmpAlwaysUnEqual4(args[3]); 1517 if (ACmpOnValues != 3) { 1518 Asserts.assertTrue(res); 1519 } else if (compiled) { 1520 Asserts.assertFalse(res); 1521 } 1522 1523 int idx = i % args.length; 1524 compiled = WHITE_BOX.isMethodCompiled(cmpSometimesEqual1_m, false); 1525 res = cmpSometimesEqual1(args[idx]); 1526 if (ACmpOnValues != 3) { 1527 Asserts.assertEQ(res, args[idx] == null || !args[idx].getClass().isInlineClass()); 1528 } else if (compiled) { 1529 Asserts.assertTrue(res); 1530 } 1531 compiled = WHITE_BOX.isMethodCompiled(cmpSometimesEqual2_m, false); 1532 res = cmpSometimesEqual2(args[idx]); 1533 if (ACmpOnValues != 3) { 1534 Asserts.assertNE(res, args[idx] == null || !args[idx].getClass().isInlineClass()); 1535 } else if (compiled) { 1536 Asserts.assertFalse(res); 1537 } 1538 } 1539 } 1540 1541 public static void main(String[] args) throws Exception { 1542 if (args.length == 0) { 1543 enumerateVMOptions(); 1544 } else { 1545 int nullMode = Integer.valueOf(args[0]); 1546 TestNewAcmp t = new TestNewAcmp(); 1547 t.run(nullMode); 1548 } 1549 } 1550 1551 private static String[] addOptions(String prefix[], String... extra) { 1552 ArrayList<String> list = new ArrayList<String>(); 1553 if (prefix != null) { 1554 for (String s : prefix) { 1555 list.add(s); 1556 } 1557 } 1558 if (extra != null) { 1559 for (String s : extra) { 1560 System.out.println(" " + s); 1561 list.add(s); 1562 } 1563 } 1564 1565 return list.toArray(new String[list.size()]); 1566 } 1567 1568 private static void enumerateVMOptions() throws Exception { 1569 String[] baseOptions = { 1570 "-Xbootclasspath/a:.", 1571 "-XX:+UnlockDiagnosticVMOptions", 1572 "-XX:+WhiteBoxAPI", 1573 "-Xbatch", 1574 "-XX:TypeProfileLevel=222", 1575 "-XX:CompileCommand=dontinline,compiler.valhalla.valuetypes.TestNewAcmp::test*", 1576 "-XX:CompileCommand=dontinline,compiler.valhalla.valuetypes.TestNewAcmp::cmp*"}; 1577 1578 String SCENARIOS = System.getProperty("Scenarios", ""); 1579 List<String> scenarios = null; 1580 if (!SCENARIOS.isEmpty()) { 1581 scenarios = Arrays.asList(SCENARIOS.split(",")); 1582 } 1583 1584 int scenario = -1; 1585 for (int nullMode = 0; nullMode <= 2; nullMode++) { // null mode 1586 for (int onVal = 0; onVal < 2; onVal++) { // 0 = default, 1 = -XX:ACmpOnValues=3 1587 for (int incrInline = 0; incrInline < 2; incrInline++) { // 0 = default, 1 = -XX:+AlwaysIncrementalInline 1588 scenario++; 1589 System.out.println("Scenario #" + scenario + " -------------------"); 1590 String[] cmds = baseOptions; 1591 if (incrInline != 0) { 1592 cmds = addOptions(cmds, "-XX:+IgnoreUnrecognizedVMOptions", "-XX:+AlwaysIncrementalInline"); 1593 } 1594 if (onVal != 0) { 1595 cmds = addOptions(cmds, "-XX:+UnlockExperimentalVMOptions", "-XX:ACmpOnValues=3"); 1596 } 1597 1598 cmds = addOptions(cmds, "compiler.valhalla.valuetypes.TestNewAcmp"); 1599 cmds = addOptions(cmds, Integer.toString(nullMode)); 1600 1601 if (scenarios != null && !scenarios.contains(Integer.toString(scenario))) { 1602 System.out.println("Scenario #" + scenario + " is skipped due to -Dscenarios=" + SCENARIOS); 1603 continue; 1604 } else if (EnableValhallaC1 && onVal == 0) { 1605 System.out.println("Scenario #" + scenario + " is skipped because C1 requires -XX:ACmpOnValues=3"); 1606 continue; 1607 } 1608 1609 OutputAnalyzer oa = ProcessTools.executeTestJvm(cmds); 1610 String output = oa.getOutput(); 1611 oa.shouldHaveExitValue(0); 1612 System.out.println(output); 1613 } 1614 } 1615 } 1616 } 1617 }