< prev index next >

test/hotspot/jtreg/compiler/valhalla/valuetypes/TestNewAcmp.java

Print this page




  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


 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 


 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     }


 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 


 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) {


 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 


 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     }


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 


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


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     }


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


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) {


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 }


  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 false if the argument is null
  92 @Retention(RetentionPolicy.RUNTIME)
  93 @interface FalseIfNull { }
  94 
  95 // Mark test methods that return true if the argument is null
  96 @Retention(RetentionPolicy.RUNTIME)
  97 @interface TrueIfNull { }
  98 
  99 public class TestNewAcmp {
 100 
 101     public boolean testEq01_1(Object u1, Object u2) {
 102         return get(u1) == u2; // new acmp
 103     }
 104 
 105     public boolean testEq01_2(Object u1, Object u2) {
 106         return u1 == get(u2); // new acmp
 107     }
 108 
 109     public boolean testEq01_3(Object u1, Object u2) {
 110         return get(u1) == get(u2); // new acmp


 168     public boolean testEq05_2(MyObject o, MyValue1 v) {
 169         return o == get(v); // only true if both null
 170     }
 171 
 172     public boolean testEq05_3(MyObject o, MyValue1 v) {
 173         return get(o) == get(v); // only true if both null
 174     }
 175 
 176     public boolean testEq06_1(MyValue1 v, MyObject o) {
 177         return get(v) == o; // only true if both null
 178     }
 179 
 180     public boolean testEq06_2(MyValue1 v, MyObject o) {
 181         return (Object)v == get(o); // only true if both null
 182     }
 183 
 184     public boolean testEq06_3(MyValue1 v, MyObject o) {
 185         return get(v) == get(o); // only true if both null
 186     }
 187 

 188     public boolean testEq07_1(MyValue1 v1, MyValue1 v2) {
 189         return getNotNull(v1) == (Object)v2; // false
 190     }
 191 

 192     public boolean testEq07_2(MyValue1 v1, MyValue1 v2) {
 193         return (Object)v1 == getNotNull(v2); // false
 194     }
 195 

 196     public boolean testEq07_3(MyValue1 v1, MyValue1 v2) {
 197         return getNotNull(v1) == getNotNull(v2); // false
 198     }
 199 

 200     public boolean testEq08_1(MyValue1 v, Object u) {
 201         return getNotNull(v) == u; // false
 202     }
 203 

 204     public boolean testEq08_2(MyValue1 v, Object u) {
 205         return (Object)v == getNotNull(u); // false
 206     }
 207 

 208     public boolean testEq08_3(MyValue1 v, Object u) {
 209         return getNotNull(v) == getNotNull(u); // false
 210     }
 211 

 212     public boolean testEq09_1(Object u, MyValue1 v) {
 213         return getNotNull(u) == (Object)v; // false
 214     }
 215 

 216     public boolean testEq09_2(Object u, MyValue1 v) {
 217         return u == getNotNull(v); // false
 218     }
 219 

 220     public boolean testEq09_3(Object u, MyValue1 v) {
 221         return getNotNull(u) == getNotNull(v); // false
 222     }
 223 

 224     public boolean testEq10_1(MyObject o, MyValue1 v) {
 225         return getNotNull(o) == (Object)v; // false
 226     }
 227 

 228     public boolean testEq10_2(MyObject o, MyValue1 v) {
 229         return o == getNotNull(v); // false
 230     }
 231 

 232     public boolean testEq10_3(MyObject o, MyValue1 v) {
 233         return getNotNull(o) == getNotNull(v); // false
 234     }
 235 

 236     public boolean testEq11_1(MyValue1 v, MyObject o) {
 237         return getNotNull(v) == o; // false
 238     }
 239 

 240     public boolean testEq11_2(MyValue1 v, MyObject o) {
 241         return (Object)v == getNotNull(o); // false
 242     }
 243 

 244     public boolean testEq11_3(MyValue1 v, MyObject o) {
 245         return getNotNull(v) == getNotNull(o); // false
 246     }
 247 
 248     public boolean testEq12_1(MyObject o1, MyObject o2) {
 249         return get(o1) == o2; // old acmp
 250     }
 251 
 252     public boolean testEq12_2(MyObject o1, MyObject o2) {
 253         return o1 == get(o2); // old acmp
 254     }
 255 
 256     public boolean testEq12_3(MyObject o1, MyObject o2) {
 257         return get(o1) == get(o2); // old acmp
 258     }
 259 
 260     public boolean testEq13_1(Object u, MyObject o) {
 261         return get(u) == o; // old acmp
 262     }
 263 


 312     public boolean testEq17_2(Object[] a, MyValue1 v) {
 313         return a == get(v); // only true if both null
 314     }
 315 
 316     public boolean testEq17_3(Object[] a, MyValue1 v) {
 317         return get(a) == get(v); // only true if both null
 318     }
 319 
 320     public boolean testEq18_1(MyValue1 v, Object[] a) {
 321         return get(v) == a; // only true if both null
 322     }
 323 
 324     public boolean testEq18_2(MyValue1 v, Object[] a) {
 325         return (Object)v == get(a); // only true if both null
 326     }
 327 
 328     public boolean testEq18_3(MyValue1 v, Object[] a) {
 329         return get(v) == get(a); // only true if both null
 330     }
 331 

 332     public boolean testEq19_1(Object[] a, MyValue1 v) {
 333         return getNotNull(a) == (Object)v; // false
 334     }
 335 

 336     public boolean testEq19_2(Object[] a, MyValue1 v) {
 337         return a == getNotNull(v); // false
 338     }
 339 

 340     public boolean testEq19_3(Object[] a, MyValue1 v) {
 341         return getNotNull(a) == getNotNull(v); // false
 342     }
 343 

 344     public boolean testEq20_1(MyValue1 v, Object[] a) {
 345         return getNotNull(v) == a; // false
 346     }
 347 

 348     public boolean testEq20_2(MyValue1 v, Object[] a) {
 349         return (Object)v == getNotNull(a); // false
 350     }
 351 

 352     public boolean testEq20_3(MyValue1 v, Object[] a) {
 353         return getNotNull(v) == getNotNull(a); // false
 354     }
 355 
 356     public boolean testEq21_1(MyInterface u1, MyInterface u2) {
 357         return get(u1) == u2; // new acmp
 358     }
 359 
 360     public boolean testEq21_2(MyInterface u1, MyInterface u2) {
 361         return u1 == get(u2); // new acmp
 362     }
 363 
 364     public boolean testEq21_3(MyInterface u1, MyInterface u2) {
 365         return get(u1) == get(u2); // new acmp
 366     }
 367 
 368     @FalseIfNull
 369     public boolean testEq21_4(MyInterface u1, MyInterface u2) {
 370         return getNotNull(u1) == u2; // new acmp without null check
 371     }


 387     public boolean testEq22_2(MyValue1 v, MyInterface u) {
 388         return (Object)v == get(u); // only true if both null
 389     }
 390 
 391     public boolean testEq22_3(MyValue1 v, MyInterface u) {
 392         return get(v) == get(u); // only true if both null
 393     }
 394 
 395     public boolean testEq23_1(MyInterface u, MyValue1 v) {
 396         return get(u) == (Object)v; // only true if both null
 397     }
 398 
 399     public boolean testEq23_2(MyInterface u, MyValue1 v) {
 400         return u == get(v); // only true if both null
 401     }
 402 
 403     public boolean testEq23_3(MyInterface u, MyValue1 v) {
 404         return get(u) == get(v); // only true if both null
 405     }
 406 

 407     public boolean testEq24_1(MyValue1 v, MyInterface u) {
 408         return getNotNull(v) == u; // false
 409     }
 410 

 411     public boolean testEq24_2(MyValue1 v, MyInterface u) {
 412         return (Object)v == getNotNull(u); // false
 413     }
 414 

 415     public boolean testEq24_3(MyValue1 v, MyInterface u) {
 416         return getNotNull(v) == getNotNull(u); // false
 417     }
 418 

 419     public boolean testEq25_1(MyInterface u, MyValue1 v) {
 420         return getNotNull(u) == (Object)v; // false
 421     }
 422 

 423     public boolean testEq25_2(MyInterface u, MyValue1 v) {
 424         return u == getNotNull(v); // false
 425     }
 426 

 427     public boolean testEq25_3(MyInterface u, MyValue1 v) {
 428         return getNotNull(u) == getNotNull(v); // false
 429     }
 430 
 431     public boolean testEq26_1(MyInterface u, MyObject o) {
 432         return get(u) == o; // old acmp
 433     }
 434 
 435     public boolean testEq26_2(MyInterface u, MyObject o) {
 436         return u == get(o); // old acmp
 437     }
 438 
 439     public boolean testEq26_3(MyInterface u, MyObject o) {
 440         return get(u) == get(o); // old acmp
 441     }
 442 
 443     public boolean testEq27_1(MyObject o, MyInterface u) {
 444         return get(o) == u; // old acmp
 445     }
 446 


 483     public boolean testEq30_2(MyInterface[] a, MyValue1 v) {
 484         return a == get(v); // only true if both null
 485     }
 486 
 487     public boolean testEq30_3(MyInterface[] a, MyValue1 v) {
 488         return get(a) == get(v); // only true if both null
 489     }
 490 
 491     public boolean testEq31_1(MyValue1 v, MyInterface[] a) {
 492         return get(v) == a; // only true if both null
 493     }
 494 
 495     public boolean testEq31_2(MyValue1 v, MyInterface[] a) {
 496         return (Object)v == get(a); // only true if both null
 497     }
 498 
 499     public boolean testEq31_3(MyValue1 v, MyInterface[] a) {
 500         return get(v) == get(a); // only true if both null
 501     }
 502 

 503     public boolean testEq32_1(MyInterface[] a, MyValue1 v) {
 504         return getNotNull(a) == (Object)v; // false
 505     }
 506 

 507     public boolean testEq32_2(MyInterface[] a, MyValue1 v) {
 508         return a == getNotNull(v); // false
 509     }
 510 

 511     public boolean testEq32_3(MyInterface[] a, MyValue1 v) {
 512         return getNotNull(a) == getNotNull(v); // false
 513     }
 514 

 515     public boolean testEq33_1(MyValue1 v, MyInterface[] a) {
 516         return getNotNull(v) == a; // false
 517     }
 518 

 519     public boolean testEq33_2(MyValue1 v, MyInterface[] a) {
 520         return (Object)v == getNotNull(a); // false
 521     }
 522 

 523     public boolean testEq33_3(MyValue1 v, MyInterface[] a) {
 524         return getNotNull(v) == getNotNull(a); // false
 525     }
 526 
 527 
 528     // Null tests
 529 
 530     public boolean testNull01_1(MyValue1 v) {
 531         return (Object)v == null; // old acmp
 532     }
 533 
 534     public boolean testNull01_2(MyValue1 v) {
 535         return get(v) == null; // old acmp
 536     }
 537 
 538     public boolean testNull01_3(MyValue1 v) {
 539         return (Object)v == get((Object)null); // old acmp
 540     }
 541 
 542     public boolean testNull01_4(MyValue1 v) {


 727     public boolean testNotEq05_2(MyObject o, MyValue1 v) {
 728         return o != get(v); // only false if both null
 729     }
 730 
 731     public boolean testNotEq05_3(MyObject o, MyValue1 v) {
 732         return get(o) != get(v); // only false if both null
 733     }
 734 
 735     public boolean testNotEq06_1(MyValue1 v, MyObject o) {
 736         return get(v) != o; // only false if both null
 737     }
 738 
 739     public boolean testNotEq06_2(MyValue1 v, MyObject o) {
 740         return (Object)v != get(o); // only false if both null
 741     }
 742 
 743     public boolean testNotEq06_3(MyValue1 v, MyObject o) {
 744         return get(v) != get(o); // only false if both null
 745     }
 746 

 747     public boolean testNotEq07_1(MyValue1 v1, MyValue1 v2) {
 748         return getNotNull(v1) != (Object)v2; // true
 749     }
 750 

 751     public boolean testNotEq07_2(MyValue1 v1, MyValue1 v2) {
 752         return (Object)v1 != getNotNull(v2); // true
 753     }
 754 

 755     public boolean testNotEq07_3(MyValue1 v1, MyValue1 v2) {
 756         return getNotNull(v1) != getNotNull(v2); // true
 757     }
 758 

 759     public boolean testNotEq08_1(MyValue1 v, Object u) {
 760         return getNotNull(v) != u; // true
 761     }
 762 

 763     public boolean testNotEq08_2(MyValue1 v, Object u) {
 764         return (Object)v != getNotNull(u); // true
 765     }
 766 

 767     public boolean testNotEq08_3(MyValue1 v, Object u) {
 768         return getNotNull(v) != getNotNull(u); // true
 769     }
 770 

 771     public boolean testNotEq09_1(Object u, MyValue1 v) {
 772         return getNotNull(u) != (Object)v; // true
 773     }
 774 

 775     public boolean testNotEq09_2(Object u, MyValue1 v) {
 776         return u != getNotNull(v); // true
 777     }
 778 

 779     public boolean testNotEq09_3(Object u, MyValue1 v) {
 780         return getNotNull(u) != getNotNull(v); // true
 781     }
 782 

 783     public boolean testNotEq10_1(MyObject o, MyValue1 v) {
 784         return getNotNull(o) != (Object)v; // true
 785     }
 786 

 787     public boolean testNotEq10_2(MyObject o, MyValue1 v) {
 788         return o != getNotNull(v); // true
 789     }
 790 

 791     public boolean testNotEq10_3(MyObject o, MyValue1 v) {
 792         return getNotNull(o) != getNotNull(v); // true
 793     }
 794 

 795     public boolean testNotEq11_1(MyValue1 v, MyObject o) {
 796         return getNotNull(v) != o; // true
 797     }
 798 

 799     public boolean testNotEq11_2(MyValue1 v, MyObject o) {
 800         return (Object)v != getNotNull(o); // true
 801     }
 802 

 803     public boolean testNotEq11_3(MyValue1 v, MyObject o) {
 804         return getNotNull(v) != getNotNull(o); // true
 805     }
 806 
 807     public boolean testNotEq12_1(MyObject o1, MyObject o2) {
 808         return get(o1) != o2; // old acmp
 809     }
 810 
 811     public boolean testNotEq12_2(MyObject o1, MyObject o2) {
 812         return o1 != get(o2); // old acmp
 813     }
 814 
 815     public boolean testNotEq12_3(MyObject o1, MyObject o2) {
 816         return get(o1) != get(o2); // old acmp
 817     }
 818 
 819     public boolean testNotEq13_1(Object u, MyObject o) {
 820         return get(u) != o; // old acmp
 821     }
 822 


 871     public boolean testNotEq17_2(Object[] a, MyValue1 v) {
 872         return a != get(v); // only false if both null
 873     }
 874 
 875     public boolean testNotEq17_3(Object[] a, MyValue1 v) {
 876         return get(a) != get(v); // only false if both null
 877     }
 878 
 879     public boolean testNotEq18_1(MyValue1 v, Object[] a) {
 880         return get(v) != a; // only false if both null
 881     }
 882 
 883     public boolean testNotEq18_2(MyValue1 v, Object[] a) {
 884         return (Object)v != get(a); // only false if both null
 885     }
 886 
 887     public boolean testNotEq18_3(MyValue1 v, Object[] a) {
 888         return get(v) != get(a); // only false if both null
 889     }
 890 

 891     public boolean testNotEq19_1(Object[] a, MyValue1 v) {
 892         return getNotNull(a) != (Object)v; // true
 893     }
 894 

 895     public boolean testNotEq19_2(Object[] a, MyValue1 v) {
 896         return a != getNotNull(v); // true
 897     }
 898 

 899     public boolean testNotEq19_3(Object[] a, MyValue1 v) {
 900         return getNotNull(a) != getNotNull(v); // true
 901     }
 902 

 903     public boolean testNotEq20_1(MyValue1 v, Object[] a) {
 904         return getNotNull(v) != a; // true
 905     }
 906 

 907     public boolean testNotEq20_2(MyValue1 v, Object[] a) {
 908         return (Object)v != getNotNull(a); // true
 909     }
 910 

 911     public boolean testNotEq20_3(MyValue1 v, Object[] a) {
 912         return getNotNull(v) != getNotNull(a); // true
 913     }
 914 
 915     public boolean testNotEq21_1(MyInterface u1, MyInterface u2) {
 916         return get(u1) != u2; // new acmp
 917     }
 918 
 919     public boolean testNotEq21_2(MyInterface u1, MyInterface u2) {
 920         return u1 != get(u2); // new acmp
 921     }
 922 
 923     public boolean testNotEq21_3(MyInterface u1, MyInterface u2) {
 924         return get(u1) != get(u2); // new acmp
 925     }
 926 
 927     @TrueIfNull
 928     public boolean testNotEq21_4(MyInterface u1, MyInterface u2) {
 929         return getNotNull(u1) != u2; // new acmp without null check
 930     }


 946     public boolean testNotEq22_2(MyValue1 v, MyInterface u) {
 947         return (Object)v != get(u); // only false if both null
 948     }
 949 
 950     public boolean testNotEq22_3(MyValue1 v, MyInterface u) {
 951         return get(v) != get(u); // only false if both null
 952     }
 953 
 954     public boolean testNotEq23_1(MyInterface u, MyValue1 v) {
 955         return get(u) != (Object)v; // only false if both null
 956     }
 957 
 958     public boolean testNotEq23_2(MyInterface u, MyValue1 v) {
 959         return u != get(v); // only false if both null
 960     }
 961 
 962     public boolean testNotEq23_3(MyInterface u, MyValue1 v) {
 963         return get(u) != get(v); // only false if both null
 964     }
 965 

 966     public boolean testNotEq24_1(MyValue1 v, MyInterface u) {
 967         return getNotNull(v) != u; // true
 968     }
 969 

 970     public boolean testNotEq24_2(MyValue1 v, MyInterface u) {
 971         return (Object)v != getNotNull(u); // true
 972     }
 973 

 974     public boolean testNotEq24_3(MyValue1 v, MyInterface u) {
 975         return getNotNull(v) != getNotNull(u); // true
 976     }
 977 

 978     public boolean testNotEq25_1(MyInterface u, MyValue1 v) {
 979         return getNotNull(u) != (Object)v; // true
 980     }
 981 

 982     public boolean testNotEq25_2(MyInterface u, MyValue1 v) {
 983         return u != getNotNull(v); // true
 984     }
 985 

 986     public boolean testNotEq25_3(MyInterface u, MyValue1 v) {
 987         return getNotNull(u) != getNotNull(v); // true
 988     }
 989 
 990     public boolean testNotEq26_1(MyInterface u, MyObject o) {
 991         return get(u) != o; // old acmp
 992     }
 993 
 994     public boolean testNotEq26_2(MyInterface u, MyObject o) {
 995         return u != get(o); // old acmp
 996     }
 997 
 998     public boolean testNotEq26_3(MyInterface u, MyObject o) {
 999         return get(u) != get(o); // old acmp
1000     }
1001 
1002     public boolean testNotEq27_1(MyObject o, MyInterface u) {
1003         return get(o) != u; // old acmp
1004     }
1005 


1042     public boolean testNotEq30_2(MyInterface[] a, MyValue1 v) {
1043         return a != get(v); // only false if both null
1044     }
1045 
1046     public boolean testNotEq30_3(MyInterface[] a, MyValue1 v) {
1047         return get(a) != get(v); // only false if both null
1048     }
1049 
1050     public boolean testNotEq31_1(MyValue1 v, MyInterface[] a) {
1051         return get(v) != a; // only false if both null
1052     }
1053 
1054     public boolean testNotEq31_2(MyValue1 v, MyInterface[] a) {
1055         return (Object)v != get(a); // only false if both null
1056     }
1057 
1058     public boolean testNotEq31_3(MyValue1 v, MyInterface[] a) {
1059         return get(v) != get(a); // only false if both null
1060     }
1061 

1062     public boolean testNotEq32_1(MyInterface[] a, MyValue1 v) {
1063         return getNotNull(a) != (Object)v; // true
1064     }
1065 

1066     public boolean testNotEq32_2(MyInterface[] a, MyValue1 v) {
1067         return a != getNotNull(v); // true
1068     }
1069 

1070     public boolean testNotEq32_3(MyInterface[] a, MyValue1 v) {
1071         return getNotNull(a) != getNotNull(v); // true
1072     }
1073 

1074     public boolean testNotEq33_1(MyValue1 v, MyInterface[] a) {
1075         return getNotNull(v) != a; // true
1076     }
1077 

1078     public boolean testNotEq33_2(MyValue1 v, MyInterface[] a) {
1079         return (Object)v != getNotNull(a); // true
1080     }
1081 

1082     public boolean testNotEq33_3(MyValue1 v, MyInterface[] a) {
1083         return getNotNull(v) != getNotNull(a); // true
1084     }
1085 
1086     // Null tests
1087 
1088     public boolean testNotNull01_1(MyValue1 v) {
1089         return (Object)v != null; // old acmp
1090     }
1091 
1092     public boolean testNotNull01_2(MyValue1 v) {
1093         return get(v) != null; // old acmp
1094     }
1095 
1096     public boolean testNotNull01_3(MyValue1 v) {
1097         return (Object)v != get((Object)null); // old acmp
1098     }
1099 
1100     public boolean testNotNull01_4(MyValue1 v) {
1101         return get(v) != get((Object)null); // old acmp


1238     public Object getNotNull(MyObject o) {
1239         return (o != null) ? o : MyValue1.createDefault();
1240     }
1241 
1242     public Object get(Object[] a) {
1243         return a;
1244     }
1245 
1246     public Object getNotNull(Object[] a) {
1247         return (a != null) ? a : new Object[1];
1248     }
1249 
1250     public boolean trueIfNull(Method m) {
1251         return m.isAnnotationPresent(TrueIfNull.class);
1252     }
1253 
1254     public boolean falseIfNull(Method m) {
1255         return m.isAnnotationPresent(FalseIfNull.class);
1256     }
1257 










1258     public boolean isNegated(Method m) {
1259         return m.getName().startsWith("testNot");
1260     }
1261 
1262     // Tests with profiling
1263     public boolean cmpAlwaysEqual1(Object a, Object b) {
1264         return a == b;
1265     }
1266 
1267     public boolean cmpAlwaysEqual2(Object a, Object b) {
1268         return a != b;
1269     }
1270 
1271     public boolean cmpAlwaysEqual3(Object a) {
1272         return a == a;
1273     }
1274 
1275     public boolean cmpAlwaysEqual4(Object a) {
1276         return a != a;
1277     }


1293     }
1294 
1295     public boolean cmpSometimesEqual1(Object a) {
1296         return a == a;
1297     }
1298 
1299     public boolean cmpSometimesEqual2(Object a) {
1300         return a != a;
1301     }
1302 
1303     static int get_full_opt_level() {
1304         int n = (int)TieredStopAtLevel;
1305         if (n >= 4) {
1306             n = 4;
1307         }
1308         return n;
1309     }
1310     protected static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();
1311     protected static final long TieredStopAtLevel = (Long)WHITE_BOX.getVMFlag("TieredStopAtLevel");
1312     protected static final int COMP_LEVEL_FULL_OPTIMIZATION = get_full_opt_level();

1313 
1314     // FIXME: temp -- special handling for C1 testing.
1315     protected static final boolean EnableValhallaC1 = (Boolean)WHITE_BOX.getVMFlag("EnableValhallaC1");
1316 
1317     public void runTest(Method m, Object[] args, int warmup, int nullMode, boolean[][] equalities) throws Exception {
1318         Class<?>[] parameterTypes = m.getParameterTypes();
1319         int parameterCount = parameterTypes.length;
1320         // Nullness mode for first argument
1321         // 0: default, 1: never null, 2: always null
1322         int start = (nullMode != 1) ? 0 : 1;
1323         int end = (nullMode != 2) ? args.length : 1;
1324         for (int i = start; i < end; ++i) {
1325             if (args[i] != null && !parameterTypes[0].isInstance(args[i])) {
1326                 continue;
1327             }
1328             if (args[i] == null && parameterTypes[0] == MyValue1.class) {
1329                 continue;
1330             }
1331             if (parameterCount == 1) {
1332                 // Null checks


1337                     Boolean result = (Boolean)m.invoke(this, args[i]);
1338                     if (result != expected && WHITE_BOX.isMethodCompiled(m, false)) {
1339                         System.out.println(" = " + result);
1340                         throw new RuntimeException("Test failed: should return " + expected);
1341                     }
1342                 }
1343                 System.out.println(" = " + expected);
1344             } else {
1345                 // Equality checks
1346                 for (int j = 0; j < args.length; ++j) {
1347                     if (args[j] != null && !parameterTypes[1].isInstance(args[j])) {
1348                         continue;
1349                     }
1350                     if (args[j] == null && parameterTypes[1] == MyValue1.class) {
1351                         continue;
1352                     }
1353                     System.out.print("Testing " + m.getName() + "(" + args[i] + ", " + args[j] + ")");
1354                     // Avoid acmp in the computation of the expected result!
1355                     boolean equal = equalities[i][j];
1356                     equal = isNegated(m) ? !equal : equal;
1357                     boolean expected = ((i == 0 || j == 0) && trueIfNull(m)) || (equal && !(i == 0 && falseIfNull(m)));
1358                     for (int run = 0; run < warmup; ++run) {
1359                         Boolean result = (Boolean)m.invoke(this, args[i], args[j]);
1360                         if (result != expected && WHITE_BOX.isMethodCompiled(m, false) && warmup == 1) {
1361                             System.out.println(" = " + result);
1362                             throw new RuntimeException("Test failed: should return " + expected);
1363                         }
1364                     }
1365                     System.out.println(" = " + expected);
1366                 }
1367             }
1368         }
1369     }
1370 
1371     public void run(int nullMode) throws Exception {
1372         // Prepare test arguments
1373         Object[] args =  { null,
1374                            new Object(),
1375                            new MyObject(),
1376                            MyValue1.setX(MyValue1.createDefault(), 42),
1377                            new Object[10],
1378                            new MyObject[10],
1379                            MyValue1.setX(MyValue1.createDefault(), 0x42),
1380                            MyValue1.setX(MyValue1.createDefault(), 42),
1381                            MyValue2.setX(MyValue2.createDefault(), 42), };
1382 
1383         boolean[][] equalities = { { true,  false, false, false, false, false, false, false, false },
1384                                    { false, true,  false, false, false, false, false, false, false },
1385                                    { false, false, true,  false, false, false, false, false, false },
1386                                    { false, false, false, true,  false, false, false, true,  false },
1387                                    { false, false, false, false, true,  false, false, false, false },
1388                                    { false, false, false, false, false, true,  false, false, false },
1389                                    { false, false, false, false, false, false, true,  false, false },
1390                                    { false, false, false, true,  false, false, false, true,  false },
1391                                    { false, false, false, false, false, false, false, false, true  } };
1392 
1393         // Run tests
1394         for (Method m : getClass().getMethods()) {
1395             if (m.getName().startsWith("test")) {
1396                 // Do some warmup runs
1397                 runTest(m, args, 1000, nullMode, equalities);
1398                 // Make sure method is compiled
1399                 WHITE_BOX.enqueueMethodForCompilation(m, COMP_LEVEL_FULL_OPTIMIZATION);
1400                 Asserts.assertTrue(WHITE_BOX.isMethodCompiled(m, false), m + " not compiled");
1401                 // Run again to verify correctness of compiled code
1402                 runTest(m, args, 1, nullMode, equalities);
1403             }
1404         }
1405 
1406         Method cmpAlwaysUnEqual3_m = getClass().getMethod("cmpAlwaysUnEqual3", Object.class);
1407         Method cmpAlwaysUnEqual4_m = getClass().getMethod("cmpAlwaysUnEqual4", Object.class);
1408         Method cmpSometimesEqual1_m = getClass().getMethod("cmpSometimesEqual1", Object.class);
1409         Method cmpSometimesEqual2_m = getClass().getMethod("cmpSometimesEqual2", Object.class);
1410 
1411         for (int i = 0; i < 20_000; ++i) {
1412             Asserts.assertTrue(cmpAlwaysEqual1(args[1], args[1]));
1413             Asserts.assertFalse(cmpAlwaysEqual2(args[1], args[1]));
1414             Asserts.assertTrue(cmpAlwaysEqual3(args[1]));
1415             Asserts.assertFalse(cmpAlwaysEqual4(args[1]));
1416 
1417             Asserts.assertFalse(cmpAlwaysUnEqual1(args[1], args[2]));
1418             Asserts.assertTrue(cmpAlwaysUnEqual2(args[1], args[2]));

1419             boolean res = cmpAlwaysUnEqual3(args[3]);



1420             Asserts.assertTrue(res);


1421             res = cmpAlwaysUnEqual4(args[3]);



1422             Asserts.assertFalse(res);

1423 
1424             int idx = i % args.length;

1425             res = cmpSometimesEqual1(args[idx]);



1426             Asserts.assertTrue(res);


1427             res = cmpSometimesEqual2(args[idx]);



1428             Asserts.assertFalse(res);
1429         }
1430     }

1431 
1432     public static void main(String[] args) throws Exception {
1433         if (args.length == 0) {
1434             enumerateVMOptions();
1435         } else {
1436             int nullMode = Integer.valueOf(args[0]);
1437             TestNewAcmp t = new TestNewAcmp();
1438             t.run(nullMode);
1439         }
1440     }
1441 
1442     private static String[] addOptions(String prefix[], String... extra) {
1443         ArrayList<String> list = new ArrayList<String>();
1444         if (prefix != null) {
1445             for (String s : prefix) {
1446                 list.add(s);
1447             }
1448         }
1449         if (extra != null) {
1450             for (String s : extra) {


1457     }
1458 
1459     private static void enumerateVMOptions() throws Exception {
1460         String[] baseOptions = {
1461             "-Xbootclasspath/a:.",
1462             "-XX:+UnlockDiagnosticVMOptions",
1463             "-XX:+WhiteBoxAPI",
1464             "-Xbatch",
1465             "-XX:TypeProfileLevel=222",
1466             "-XX:CompileCommand=dontinline,compiler.valhalla.valuetypes.TestNewAcmp::test*",
1467             "-XX:CompileCommand=dontinline,compiler.valhalla.valuetypes.TestNewAcmp::cmp*"};
1468 
1469         String SCENARIOS = System.getProperty("Scenarios", "");
1470         List<String> scenarios = null;
1471         if (!SCENARIOS.isEmpty()) {
1472            scenarios = Arrays.asList(SCENARIOS.split(","));
1473         }
1474 
1475         int scenario = -1;
1476         for (int nullMode = 0; nullMode <= 2; nullMode++) {          // null mode

1477             for (int incrInline = 0; incrInline < 2; incrInline++) { // 0 = default, 1 = -XX:+AlwaysIncrementalInline
1478                 scenario++;
1479                 System.out.println("Scenario #" + scenario + " -------------------");
1480                 String[] cmds = baseOptions;
1481                 if (incrInline != 0) {
1482                     cmds = addOptions(cmds, "-XX:+IgnoreUnrecognizedVMOptions", "-XX:+AlwaysIncrementalInline");
1483                 }



1484 
1485                 cmds = addOptions(cmds, "compiler.valhalla.valuetypes.TestNewAcmp");
1486                 cmds = addOptions(cmds, Integer.toString(nullMode));
1487 
1488                 if (scenarios != null && !scenarios.contains(Integer.toString(scenario))) {
1489                     System.out.println("Scenario #" + scenario + " is skipped due to -Dscenarios=" + SCENARIOS);
1490                     continue;



1491                 }
1492 
1493                 OutputAnalyzer oa = ProcessTools.executeTestJvm(cmds);
1494                 String output = oa.getOutput();
1495                 oa.shouldHaveExitValue(0);
1496                 System.out.println(output);

1497             }
1498         }
1499     }
1500 }
< prev index next >