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