1 /* 2 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /** 25 * @test TestNewAcmp 26 * @summary Verifies correctness of the new acmp bytecode. 27 * @library /testlibrary /test/lib /compiler/whitebox / 28 * @compile TestNewAcmp.java 29 * @run driver ClassFileInstaller sun.hotspot.WhiteBox 30 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:+EnableValhalla 31 * compiler.valhalla.valuetypes.TestNewAcmp 32 */ 33 34 package compiler.valhalla.valuetypes; 35 36 import jdk.test.lib.Asserts; 37 import jdk.test.lib.process.ProcessTools; 38 import jdk.test.lib.process.OutputAnalyzer; 39 import java.lang.annotation.Retention; 40 import java.lang.annotation.RetentionPolicy; 41 import java.lang.reflect.Method; 42 import java.util.ArrayList; 43 import java.util.Arrays; 44 import java.util.List; 45 import sun.hotspot.WhiteBox; 46 47 48 interface MyInterface { 49 50 } 51 52 inline class MyValue1 implements MyInterface { 53 final int x; 54 55 MyValue1(int x) { 56 this.x = x; 57 } 58 59 static MyValue1 createDefault() { 60 return MyValue1.default; 61 } 62 63 static MyValue1 setX(MyValue1 v, int x) { 64 return new MyValue1(x); 65 } 66 } 67 68 inline class MyValue2 implements MyInterface { 69 final int x; 70 71 MyValue2(int x) { 72 this.x = x; 73 } 74 75 static MyValue2 createDefault() { 76 return MyValue2.default; 77 } 78 79 static MyValue2 setX(MyValue2 v, int x) { 80 return new MyValue2(x); 81 } 82 } 83 84 class MyObject implements MyInterface { 85 int x; 86 } 87 88 // Mark test methods that return always false 89 @Retention(RetentionPolicy.RUNTIME) 90 @interface AlwaysFalse { 91 int[] valid_for() default {1, 2}; 92 } 93 94 // Mark test methods that return always true 95 @Retention(RetentionPolicy.RUNTIME) 96 @interface AlwaysTrue { 97 int[] valid_for() default {1, 2}; 98 } 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(MyValue1 v1, MyValue1 v2) { 138 return get(v1) == (Object)v2; // only true if both null 139 } 140 141 public boolean testEq02_2(MyValue1 v1, MyValue1 v2) { 142 return (Object)v1 == get(v2); // only true if both null 143 } 144 145 public boolean testEq02_3(MyValue1 v1, MyValue1 v2) { 146 return get(v1) == get(v2); // only true if both null 147 } 148 149 public boolean testEq03_1(MyValue1 v, Object u) { 150 return get(v) == u; // only true if both null 151 } 152 153 public boolean testEq03_2(MyValue1 v, Object u) { 154 return (Object)v == get(u); // only true if both null 155 } 156 157 public boolean testEq03_3(MyValue1 v, Object u) { 158 return get(v) == get(u); // only true if both null 159 } 160 161 public boolean testEq04_1(Object u, MyValue1 v) { 162 return get(u) == (Object)v; // only true if both null 163 } 164 165 public boolean testEq04_2(Object u, MyValue1 v) { 166 return u == get(v); // only true if both null 167 } 168 169 public boolean testEq04_3(Object u, MyValue1 v) { 170 return get(u) == get(v); // only true if both null 171 } 172 173 public boolean testEq05_1(MyObject o, MyValue1 v) { 174 return get(o) == (Object)v; // only true if both null 175 } 176 177 public boolean testEq05_2(MyObject o, MyValue1 v) { 178 return o == get(v); // only true if both null 179 } 180 181 public boolean testEq05_3(MyObject o, MyValue1 v) { 182 return get(o) == get(v); // only true if both null 183 } 184 185 public boolean testEq06_1(MyValue1 v, MyObject o) { 186 return get(v) == o; // only true if both null 187 } 188 189 public boolean testEq06_2(MyValue1 v, MyObject o) { 190 return (Object)v == get(o); // only true if both null 191 } 192 193 public boolean testEq06_3(MyValue1 v, MyObject o) { 194 return get(v) == get(o); // only true if both null 195 } 196 197 @AlwaysFalse 198 public boolean testEq07_1(MyValue1 v1, MyValue1 v2) { 199 return getNotNull(v1) == (Object)v2; // false 200 } 201 202 @AlwaysFalse 203 public boolean testEq07_2(MyValue1 v1, MyValue1 v2) { 204 return (Object)v1 == getNotNull(v2); // false 205 } 206 207 @AlwaysFalse 208 public boolean testEq07_3(MyValue1 v1, MyValue1 v2) { 209 return getNotNull(v1) == getNotNull(v2); // false 210 } 211 212 @AlwaysFalse 213 public boolean testEq08_1(MyValue1 v, Object u) { 214 return getNotNull(v) == u; // false 215 } 216 217 @AlwaysFalse 218 public boolean testEq08_2(MyValue1 v, Object u) { 219 return (Object)v == getNotNull(u); // false 220 } 221 222 @AlwaysFalse 223 public boolean testEq08_3(MyValue1 v, Object u) { 224 return getNotNull(v) == getNotNull(u); // false 225 } 226 227 @AlwaysFalse 228 public boolean testEq09_1(Object u, MyValue1 v) { 229 return getNotNull(u) == (Object)v; // false 230 } 231 232 @AlwaysFalse 233 public boolean testEq09_2(Object u, MyValue1 v) { 234 return u == getNotNull(v); // false 235 } 236 237 @AlwaysFalse 238 public boolean testEq09_3(Object u, MyValue1 v) { 239 return getNotNull(u) == getNotNull(v); // false 240 } 241 242 @AlwaysFalse 243 public boolean testEq10_1(MyObject o, MyValue1 v) { 244 return getNotNull(o) == (Object)v; // false 245 } 246 247 @AlwaysFalse 248 public boolean testEq10_2(MyObject o, MyValue1 v) { 249 return o == getNotNull(v); // false 250 } 251 252 @AlwaysFalse 253 public boolean testEq10_3(MyObject o, MyValue1 v) { 254 return getNotNull(o) == getNotNull(v); // false 255 } 256 257 @AlwaysFalse 258 public boolean testEq11_1(MyValue1 v, MyObject o) { 259 return getNotNull(v) == o; // false 260 } 261 262 @AlwaysFalse 263 public boolean testEq11_2(MyValue1 v, MyObject o) { 264 return (Object)v == getNotNull(o); // false 265 } 266 267 @AlwaysFalse 268 public boolean testEq11_3(MyValue1 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) { 289 return u == get(o); // old acmp 290 } 291 292 public boolean testEq13_3(Object u, MyObject o) { 293 return get(u) == get(o); // old acmp 294 } 295 296 public boolean testEq14_1(MyObject o, Object u) { 297 return get(o) == u; // old acmp 298 } 299 300 public boolean testEq14_2(MyObject o, Object u) { 301 return o == get(u); // old acmp 302 } 303 304 public boolean testEq14_3(MyObject o, Object u) { 305 return get(o) == get(u); // old acmp 306 } 307 308 public boolean testEq15_1(Object[] a, Object u) { 309 return get(a) == u; // old acmp 310 } 311 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, MyValue1 v) { 333 return get(a) == (Object)v; // only true if both null 334 } 335 336 public boolean testEq17_2(Object[] a, MyValue1 v) { 337 return a == get(v); // only true if both null 338 } 339 340 public boolean testEq17_3(Object[] a, MyValue1 v) { 341 return get(a) == get(v); // only true if both null 342 } 343 344 public boolean testEq18_1(MyValue1 v, Object[] a) { 345 return get(v) == a; // only true if both null 346 } 347 348 public boolean testEq18_2(MyValue1 v, Object[] a) { 349 return (Object)v == get(a); // only true if both null 350 } 351 352 public boolean testEq18_3(MyValue1 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, MyValue1 v) { 358 return getNotNull(a) == (Object)v; // false 359 } 360 361 @AlwaysFalse 362 public boolean testEq19_2(Object[] a, MyValue1 v) { 363 return a == getNotNull(v); // false 364 } 365 366 @AlwaysFalse 367 public boolean testEq19_3(Object[] a, MyValue1 v) { 368 return getNotNull(a) == getNotNull(v); // false 369 } 370 371 @AlwaysFalse 372 public boolean testEq20_1(MyValue1 v, Object[] a) { 373 return getNotNull(v) == a; // false 374 } 375 376 @AlwaysFalse 377 public boolean testEq20_2(MyValue1 v, Object[] a) { 378 return (Object)v == getNotNull(a); // false 379 } 380 381 @AlwaysFalse 382 public boolean testEq20_3(MyValue1 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(MyValue1 v, MyInterface u) { 414 return get(v) == u; // only true if both null 415 } 416 417 public boolean testEq22_2(MyValue1 v, MyInterface u) { 418 return (Object)v == get(u); // only true if both null 419 } 420 421 public boolean testEq22_3(MyValue1 v, MyInterface u) { 422 return get(v) == get(u); // only true if both null 423 } 424 425 public boolean testEq23_1(MyInterface u, MyValue1 v) { 426 return get(u) == (Object)v; // only true if both null 427 } 428 429 public boolean testEq23_2(MyInterface u, MyValue1 v) { 430 return u == get(v); // only true if both null 431 } 432 433 public boolean testEq23_3(MyInterface u, MyValue1 v) { 434 return get(u) == get(v); // only true if both null 435 } 436 437 @AlwaysFalse 438 public boolean testEq24_1(MyValue1 v, MyInterface u) { 439 return getNotNull(v) == u; // false 440 } 441 442 @AlwaysFalse 443 public boolean testEq24_2(MyValue1 v, MyInterface u) { 444 return (Object)v == getNotNull(u); // false 445 } 446 447 @AlwaysFalse 448 public boolean testEq24_3(MyValue1 v, MyInterface u) { 449 return getNotNull(v) == getNotNull(u); // false 450 } 451 452 @AlwaysFalse 453 public boolean testEq25_1(MyInterface u, MyValue1 v) { 454 return getNotNull(u) == (Object)v; // false 455 } 456 457 @AlwaysFalse 458 public boolean testEq25_2(MyInterface u, MyValue1 v) { 459 return u == getNotNull(v); // false 460 } 461 462 @AlwaysFalse 463 public boolean testEq25_3(MyInterface u, MyValue1 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) { 484 return o == get(u); // old acmp 485 } 486 487 public boolean testEq27_3(MyObject o, MyInterface u) { 488 return get(o) == get(u); // old acmp 489 } 490 491 public boolean testEq28_1(MyInterface[] a, MyInterface u) { 492 return get(a) == u; // old acmp 493 } 494 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, MyValue1 v) { 516 return get(a) == (Object)v; // only true if both null 517 } 518 519 public boolean testEq30_2(MyInterface[] a, MyValue1 v) { 520 return a == get(v); // only true if both null 521 } 522 523 public boolean testEq30_3(MyInterface[] a, MyValue1 v) { 524 return get(a) == get(v); // only true if both null 525 } 526 527 public boolean testEq31_1(MyValue1 v, MyInterface[] a) { 528 return get(v) == a; // only true if both null 529 } 530 531 public boolean testEq31_2(MyValue1 v, MyInterface[] a) { 532 return (Object)v == get(a); // only true if both null 533 } 534 535 public boolean testEq31_3(MyValue1 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, MyValue1 v) { 541 return getNotNull(a) == (Object)v; // false 542 } 543 544 @AlwaysFalse 545 public boolean testEq32_2(MyInterface[] a, MyValue1 v) { 546 return a == getNotNull(v); // false 547 } 548 549 @AlwaysFalse 550 public boolean testEq32_3(MyInterface[] a, MyValue1 v) { 551 return getNotNull(a) == getNotNull(v); // false 552 } 553 554 @AlwaysFalse 555 public boolean testEq33_1(MyValue1 v, MyInterface[] a) { 556 return getNotNull(v) == a; // false 557 } 558 559 @AlwaysFalse 560 public boolean testEq33_2(MyValue1 v, MyInterface[] a) { 561 return (Object)v == getNotNull(a); // false 562 } 563 564 @AlwaysFalse 565 public boolean testEq33_3(MyValue1 v, MyInterface[] a) { 566 return getNotNull(v) == getNotNull(a); // false 567 } 568 569 570 // Null tests 571 572 public boolean testNull01_1(MyValue1 v) { 573 return (Object)v == null; // old acmp 574 } 575 576 public boolean testNull01_2(MyValue1 v) { 577 return get(v) == null; // old acmp 578 } 579 580 public boolean testNull01_3(MyValue1 v) { 581 return (Object)v == get((Object)null); // old acmp 582 } 583 584 public boolean testNull01_4(MyValue1 v) { 585 return get(v) == get((Object)null); // old acmp 586 } 587 588 public boolean testNull02_1(MyValue1 v) { 589 return null == (Object)v; // old acmp 590 } 591 592 public boolean testNull02_2(MyValue1 v) { 593 return get((Object)null) == (Object)v; // old acmp 594 } 595 596 public boolean testNull02_3(MyValue1 v) { 597 return null == get(v); // old acmp 598 } 599 600 public boolean testNull02_4(MyValue1 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) { 621 return null == u; // old acmp 622 } 623 624 public boolean testNull04_2(Object u) { 625 return get((Object)null) == u; // old acmp 626 } 627 628 public boolean testNull04_3(Object u) { 629 return null == get(u); // old acmp 630 } 631 632 public boolean testNull04_4(Object u) { 633 return get((Object)null) == get(u); // old acmp 634 } 635 636 public boolean testNull05_1(MyObject o) { 637 return o == null; // old acmp 638 } 639 640 public boolean testNull05_2(MyObject o) { 641 return get(o) == null; // old acmp 642 } 643 644 public boolean testNull05_3(MyObject o) { 645 return o == get((Object)null); // old acmp 646 } 647 648 public boolean testNull05_4(MyObject o) { 649 return get(o) == get((Object)null); // old acmp 650 } 651 652 public boolean testNull06_1(MyObject o) { 653 return null == o; // old acmp 654 } 655 656 public boolean testNull06_2(MyObject o) { 657 return get((Object)null) == o; // old acmp 658 } 659 660 public boolean testNull06_3(MyObject o) { 661 return null == get(o); // old acmp 662 } 663 664 public boolean testNull06_4(MyObject o) { 665 return get((Object)null) == get(o); // old acmp 666 } 667 668 public boolean testNull07_1(MyInterface u) { 669 return u == null; // old acmp 670 } 671 672 public boolean testNull07_2(MyInterface u) { 673 return get(u) == null; // old acmp 674 } 675 676 public boolean testNull07_3(MyInterface u) { 677 return u == get((Object)null); // old acmp 678 } 679 680 public boolean testNull07_4(MyInterface u) { 681 return get(u) == get((Object)null); // old acmp 682 } 683 684 public boolean testNull08_1(MyInterface u) { 685 return null == u; // old acmp 686 } 687 688 public boolean testNull08_2(MyInterface u) { 689 return get((Object)null) == u; // old acmp 690 } 691 692 public boolean testNull08_3(MyInterface u) { 693 return null == get(u); // old acmp 694 } 695 696 public boolean testNull08_4(MyInterface u) { 697 return get((Object)null) == get(u); // old acmp 698 } 699 700 // Same tests as above but negated 701 702 public boolean testNotEq01_1(Object u1, Object u2) { 703 return get(u1) != u2; // new acmp 704 } 705 706 public boolean testNotEq01_2(Object u1, Object u2) { 707 return u1 != get(u2); // new acmp 708 } 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(MyValue1 v1, MyValue1 v2) { 730 return get(v1) != (Object)v2; // only false if both null 731 } 732 733 public boolean testNotEq02_2(MyValue1 v1, MyValue1 v2) { 734 return (Object)v1 != get(v2); // only false if both null 735 } 736 737 public boolean testNotEq02_3(MyValue1 v1, MyValue1 v2) { 738 return get(v1) != get(v2); // only false if both null 739 } 740 741 public boolean testNotEq03_1(MyValue1 v, Object u) { 742 return get(v) != u; // only false if both null 743 } 744 745 public boolean testNotEq03_2(MyValue1 v, Object u) { 746 return (Object)v != get(u); // only false if both null 747 } 748 749 public boolean testNotEq03_3(MyValue1 v, Object u) { 750 return get(v) != get(u); // only false if both null 751 } 752 753 public boolean testNotEq04_1(Object u, MyValue1 v) { 754 return get(u) != (Object)v; // only false if both null 755 } 756 757 public boolean testNotEq04_2(Object u, MyValue1 v) { 758 return u != get(v); // only false if both null 759 } 760 761 public boolean testNotEq04_3(Object u, MyValue1 v) { 762 return get(u) != get(v); // only false if both null 763 } 764 765 public boolean testNotEq05_1(MyObject o, MyValue1 v) { 766 return get(o) != (Object)v; // only false if both null 767 } 768 769 public boolean testNotEq05_2(MyObject o, MyValue1 v) { 770 return o != get(v); // only false if both null 771 } 772 773 public boolean testNotEq05_3(MyObject o, MyValue1 v) { 774 return get(o) != get(v); // only false if both null 775 } 776 777 public boolean testNotEq06_1(MyValue1 v, MyObject o) { 778 return get(v) != o; // only false if both null 779 } 780 781 public boolean testNotEq06_2(MyValue1 v, MyObject o) { 782 return (Object)v != get(o); // only false if both null 783 } 784 785 public boolean testNotEq06_3(MyValue1 v, MyObject o) { 786 return get(v) != get(o); // only false if both null 787 } 788 789 @AlwaysTrue 790 public boolean testNotEq07_1(MyValue1 v1, MyValue1 v2) { 791 return getNotNull(v1) != (Object)v2; // true 792 } 793 794 @AlwaysTrue 795 public boolean testNotEq07_2(MyValue1 v1, MyValue1 v2) { 796 return (Object)v1 != getNotNull(v2); // true 797 } 798 799 @AlwaysTrue 800 public boolean testNotEq07_3(MyValue1 v1, MyValue1 v2) { 801 return getNotNull(v1) != getNotNull(v2); // true 802 } 803 804 @AlwaysTrue 805 public boolean testNotEq08_1(MyValue1 v, Object u) { 806 return getNotNull(v) != u; // true 807 } 808 809 @AlwaysTrue 810 public boolean testNotEq08_2(MyValue1 v, Object u) { 811 return (Object)v != getNotNull(u); // true 812 } 813 814 @AlwaysTrue 815 public boolean testNotEq08_3(MyValue1 v, Object u) { 816 return getNotNull(v) != getNotNull(u); // true 817 } 818 819 @AlwaysTrue 820 public boolean testNotEq09_1(Object u, MyValue1 v) { 821 return getNotNull(u) != (Object)v; // true 822 } 823 824 @AlwaysTrue 825 public boolean testNotEq09_2(Object u, MyValue1 v) { 826 return u != getNotNull(v); // true 827 } 828 829 @AlwaysTrue 830 public boolean testNotEq09_3(Object u, MyValue1 v) { 831 return getNotNull(u) != getNotNull(v); // true 832 } 833 834 @AlwaysTrue 835 public boolean testNotEq10_1(MyObject o, MyValue1 v) { 836 return getNotNull(o) != (Object)v; // true 837 } 838 839 @AlwaysTrue 840 public boolean testNotEq10_2(MyObject o, MyValue1 v) { 841 return o != getNotNull(v); // true 842 } 843 844 @AlwaysTrue 845 public boolean testNotEq10_3(MyObject o, MyValue1 v) { 846 return getNotNull(o) != getNotNull(v); // true 847 } 848 849 @AlwaysTrue 850 public boolean testNotEq11_1(MyValue1 v, MyObject o) { 851 return getNotNull(v) != o; // true 852 } 853 854 @AlwaysTrue 855 public boolean testNotEq11_2(MyValue1 v, MyObject o) { 856 return (Object)v != getNotNull(o); // true 857 } 858 859 @AlwaysTrue 860 public boolean testNotEq11_3(MyValue1 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) { 881 return u != get(o); // old acmp 882 } 883 884 public boolean testNotEq13_3(Object u, MyObject o) { 885 return get(u) != get(o); // old acmp 886 } 887 888 public boolean testNotEq14_1(MyObject o, Object u) { 889 return get(o) != u; // old acmp 890 } 891 892 public boolean testNotEq14_2(MyObject o, Object u) { 893 return o != get(u); // old acmp 894 } 895 896 public boolean testNotEq14_3(MyObject o, Object u) { 897 return get(o) != get(u); // old acmp 898 } 899 900 public boolean testNotEq15_1(Object[] a, Object u) { 901 return get(a) != u; // old acmp 902 } 903 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, MyValue1 v) { 925 return get(a) != (Object)v; // only false if both null 926 } 927 928 public boolean testNotEq17_2(Object[] a, MyValue1 v) { 929 return a != get(v); // only false if both null 930 } 931 932 public boolean testNotEq17_3(Object[] a, MyValue1 v) { 933 return get(a) != get(v); // only false if both null 934 } 935 936 public boolean testNotEq18_1(MyValue1 v, Object[] a) { 937 return get(v) != a; // only false if both null 938 } 939 940 public boolean testNotEq18_2(MyValue1 v, Object[] a) { 941 return (Object)v != get(a); // only false if both null 942 } 943 944 public boolean testNotEq18_3(MyValue1 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, MyValue1 v) { 950 return getNotNull(a) != (Object)v; // true 951 } 952 953 @AlwaysTrue 954 public boolean testNotEq19_2(Object[] a, MyValue1 v) { 955 return a != getNotNull(v); // true 956 } 957 958 @AlwaysTrue 959 public boolean testNotEq19_3(Object[] a, MyValue1 v) { 960 return getNotNull(a) != getNotNull(v); // true 961 } 962 963 @AlwaysTrue 964 public boolean testNotEq20_1(MyValue1 v, Object[] a) { 965 return getNotNull(v) != a; // true 966 } 967 968 @AlwaysTrue 969 public boolean testNotEq20_2(MyValue1 v, Object[] a) { 970 return (Object)v != getNotNull(a); // true 971 } 972 973 @AlwaysTrue 974 public boolean testNotEq20_3(MyValue1 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(MyValue1 v, MyInterface u) { 1006 return get(v) != u; // only false if both null 1007 } 1008 1009 public boolean testNotEq22_2(MyValue1 v, MyInterface u) { 1010 return (Object)v != get(u); // only false if both null 1011 } 1012 1013 public boolean testNotEq22_3(MyValue1 v, MyInterface u) { 1014 return get(v) != get(u); // only false if both null 1015 } 1016 1017 public boolean testNotEq23_1(MyInterface u, MyValue1 v) { 1018 return get(u) != (Object)v; // only false if both null 1019 } 1020 1021 public boolean testNotEq23_2(MyInterface u, MyValue1 v) { 1022 return u != get(v); // only false if both null 1023 } 1024 1025 public boolean testNotEq23_3(MyInterface u, MyValue1 v) { 1026 return get(u) != get(v); // only false if both null 1027 } 1028 1029 @AlwaysTrue 1030 public boolean testNotEq24_1(MyValue1 v, MyInterface u) { 1031 return getNotNull(v) != u; // true 1032 } 1033 1034 @AlwaysTrue 1035 public boolean testNotEq24_2(MyValue1 v, MyInterface u) { 1036 return (Object)v != getNotNull(u); // true 1037 } 1038 1039 @AlwaysTrue 1040 public boolean testNotEq24_3(MyValue1 v, MyInterface u) { 1041 return getNotNull(v) != getNotNull(u); // true 1042 } 1043 1044 @AlwaysTrue 1045 public boolean testNotEq25_1(MyInterface u, MyValue1 v) { 1046 return getNotNull(u) != (Object)v; // true 1047 } 1048 1049 @AlwaysTrue 1050 public boolean testNotEq25_2(MyInterface u, MyValue1 v) { 1051 return u != getNotNull(v); // true 1052 } 1053 1054 @AlwaysTrue 1055 public boolean testNotEq25_3(MyInterface u, MyValue1 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) { 1076 return o != get(u); // old acmp 1077 } 1078 1079 public boolean testNotEq27_3(MyObject o, MyInterface u) { 1080 return get(o) != get(u); // old acmp 1081 } 1082 1083 public boolean testNotEq28_1(MyInterface[] a, MyInterface u) { 1084 return get(a) != u; // old acmp 1085 } 1086 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, MyValue1 v) { 1108 return get(a) != (Object)v; // only false if both null 1109 } 1110 1111 public boolean testNotEq30_2(MyInterface[] a, MyValue1 v) { 1112 return a != get(v); // only false if both null 1113 } 1114 1115 public boolean testNotEq30_3(MyInterface[] a, MyValue1 v) { 1116 return get(a) != get(v); // only false if both null 1117 } 1118 1119 public boolean testNotEq31_1(MyValue1 v, MyInterface[] a) { 1120 return get(v) != a; // only false if both null 1121 } 1122 1123 public boolean testNotEq31_2(MyValue1 v, MyInterface[] a) { 1124 return (Object)v != get(a); // only false if both null 1125 } 1126 1127 public boolean testNotEq31_3(MyValue1 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, MyValue1 v) { 1133 return getNotNull(a) != (Object)v; // true 1134 } 1135 1136 @AlwaysTrue 1137 public boolean testNotEq32_2(MyInterface[] a, MyValue1 v) { 1138 return a != getNotNull(v); // true 1139 } 1140 1141 @AlwaysTrue 1142 public boolean testNotEq32_3(MyInterface[] a, MyValue1 v) { 1143 return getNotNull(a) != getNotNull(v); // true 1144 } 1145 1146 @AlwaysTrue 1147 public boolean testNotEq33_1(MyValue1 v, MyInterface[] a) { 1148 return getNotNull(v) != a; // true 1149 } 1150 1151 @AlwaysTrue 1152 public boolean testNotEq33_2(MyValue1 v, MyInterface[] a) { 1153 return (Object)v != getNotNull(a); // true 1154 } 1155 1156 @AlwaysTrue 1157 public boolean testNotEq33_3(MyValue1 v, MyInterface[] a) { 1158 return getNotNull(v) != getNotNull(a); // true 1159 } 1160 1161 // Null tests 1162 1163 public boolean testNotNull01_1(MyValue1 v) { 1164 return (Object)v != null; // old acmp 1165 } 1166 1167 public boolean testNotNull01_2(MyValue1 v) { 1168 return get(v) != null; // old acmp 1169 } 1170 1171 public boolean testNotNull01_3(MyValue1 v) { 1172 return (Object)v != get((Object)null); // old acmp 1173 } 1174 1175 public boolean testNotNull01_4(MyValue1 v) { 1176 return get(v) != get((Object)null); // old acmp 1177 } 1178 1179 public boolean testNotNull02_1(MyValue1 v) { 1180 return null != (Object)v; // old acmp 1181 } 1182 1183 public boolean testNotNull02_2(MyValue1 v) { 1184 return get((Object)null) != (Object)v; // old acmp 1185 } 1186 1187 public boolean testNotNull02_3(MyValue1 v) { 1188 return null != get(v); // old acmp 1189 } 1190 1191 public boolean testNotNull02_4(MyValue1 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) { 1212 return null != u; // old acmp 1213 } 1214 1215 public boolean testNotNull04_2(Object u) { 1216 return get((Object)null) != u; // old acmp 1217 } 1218 1219 public boolean testNotNull04_3(Object u) { 1220 return null != get(u); // old acmp 1221 } 1222 1223 public boolean testNotNull04_4(Object u) { 1224 return get((Object)null) != get(u); // old acmp 1225 } 1226 1227 public boolean testNotNull05_1(MyObject o) { 1228 return o != null; // old acmp 1229 } 1230 1231 public boolean testNotNull05_2(MyObject o) { 1232 return get(o) != null; // old acmp 1233 } 1234 1235 public boolean testNotNull05_3(MyObject o) { 1236 return o != get((Object)null); // old acmp 1237 } 1238 1239 public boolean testNotNull05_4(MyObject o) { 1240 return get(o) != get((Object)null); // old acmp 1241 } 1242 1243 public boolean testNotNull06_1(MyObject o) { 1244 return null != o; // old acmp 1245 } 1246 1247 public boolean testNotNull06_2(MyObject o) { 1248 return get((Object)null) != o; // old acmp 1249 } 1250 1251 public boolean testNotNull06_3(MyObject o) { 1252 return null != get(o); // old acmp 1253 } 1254 1255 public boolean testNotNull06_4(MyObject o) { 1256 return get((Object)null) != get(o); // old acmp 1257 } 1258 1259 public boolean testNotNull07_1(MyInterface u) { 1260 return u != null; // old acmp 1261 } 1262 1263 public boolean testNotNull07_2(MyInterface u) { 1264 return get(u) != null; // old acmp 1265 } 1266 1267 public boolean testNotNull07_3(MyInterface u) { 1268 return u != get((Object)null); // old acmp 1269 } 1270 1271 public boolean testNotNull07_4(MyInterface u) { 1272 return get(u) != get((Object)null); // old acmp 1273 } 1274 1275 public boolean testNotNull08_1(MyInterface u) { 1276 return null != u; // old acmp 1277 } 1278 1279 public boolean testNotNull08_2(MyInterface u) { 1280 return get((Object)null) != u; // old acmp 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(MyValue1 v) { 1302 return v; 1303 } 1304 1305 public Object getNotNull(MyValue1 v) { 1306 return ((Object)v != null) ? v : MyValue1.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 : MyValue1.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 Arrays.asList(((AlwaysTrue)m.getAnnotation(AlwaysTrue.class)).valid_for()).contains(ACmpOnValues); 1336 } 1337 1338 public boolean alwaysFalse(Method m) { 1339 return m.isAnnotationPresent(AlwaysFalse.class) && 1340 Arrays.asList(((AlwaysFalse)m.getAnnotation(AlwaysFalse.class)).valid_for()).contains(ACmpOnValues); 1341 } 1342 1343 public boolean isNegated(Method m) { 1344 return m.getName().startsWith("testNot"); 1345 } 1346 1347 // Tests with profiling 1348 public boolean cmpAlwaysEqual1(Object a, Object b) { 1349 return a == b; 1350 } 1351 1352 public boolean cmpAlwaysEqual2(Object a, Object b) { 1353 return a != b; 1354 } 1355 1356 public boolean cmpAlwaysEqual3(Object a) { 1357 return a == a; 1358 } 1359 1360 public boolean cmpAlwaysEqual4(Object a) { 1361 return a != a; 1362 } 1363 1364 public boolean cmpAlwaysUnEqual1(Object a, Object b) { 1365 return a == b; 1366 } 1367 1368 public boolean cmpAlwaysUnEqual2(Object a, Object b) { 1369 return a != b; 1370 } 1371 1372 public boolean cmpAlwaysUnEqual3(Object a) { 1373 return a == a; 1374 } 1375 1376 public boolean cmpAlwaysUnEqual4(Object a) { 1377 return a != a; 1378 } 1379 1380 public boolean cmpSometimesEqual1(Object a) { 1381 return a == a; 1382 } 1383 1384 public boolean cmpSometimesEqual2(Object a) { 1385 return a != a; 1386 } 1387 1388 protected static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox(); 1389 protected static final int COMP_LEVEL_FULL_OPTIMIZATION = 4; 1390 protected static final long ACmpOnValues = (Long)WHITE_BOX.getVMFlag("ACmpOnValues"); 1391 1392 public void runTest(Method m, Object[] args, int warmup, int nullMode, boolean[][] equalities) throws Exception { 1393 Class<?>[] parameterTypes = m.getParameterTypes(); 1394 int parameterCount = parameterTypes.length; 1395 // Nullness mode for first argument 1396 // 0: default, 1: never null, 2: always null 1397 int start = (nullMode != 1) ? 0 : 1; 1398 int end = (nullMode != 2) ? args.length : 1; 1399 for (int i = start; i < end; ++i) { 1400 if (args[i] != null && !parameterTypes[0].isInstance(args[i])) { 1401 continue; 1402 } 1403 if (args[i] == null && parameterTypes[0] == MyValue1.class.asPrimaryType()) { 1404 continue; 1405 } 1406 if (parameterCount == 1) { 1407 // Null checks 1408 System.out.print("Testing " + m.getName() + "(" + args[i] + ")"); 1409 // Avoid acmp in the computation of the expected result! 1410 boolean expected = isNegated(m) ? (i != 0) : (i == 0); 1411 for (int run = 0; run < warmup; ++run) { 1412 Boolean result = (Boolean)m.invoke(this, args[i]); 1413 if (result != expected && WHITE_BOX.isMethodCompiled(m, false)) { 1414 System.out.println(" = " + result); 1415 throw new RuntimeException("Test failed: should return " + expected); 1416 } 1417 } 1418 System.out.println(" = " + expected); 1419 } else { 1420 // Equality checks 1421 for (int j = 0; j < args.length; ++j) { 1422 if (args[j] != null && !parameterTypes[1].isInstance(args[j])) { 1423 continue; 1424 } 1425 if (args[j] == null && parameterTypes[1] == MyValue1.class.asPrimaryType()) { 1426 continue; 1427 } 1428 System.out.print("Testing " + m.getName() + "(" + args[i] + ", " + args[j] + ")"); 1429 // Avoid acmp in the computation of the expected result! 1430 boolean equal = equalities[i][j]; 1431 equal = isNegated(m) ? !equal : equal; 1432 boolean expected = alwaysTrue(m) || ((i == 0 || j == 0) && trueIfNull(m)) || (!alwaysFalse(m) && equal && !(i == 0 && falseIfNull(m))); 1433 for (int run = 0; run < warmup; ++run) { 1434 Boolean result = (Boolean)m.invoke(this, args[i], args[j]); 1435 if (result != expected && WHITE_BOX.isMethodCompiled(m, false) && warmup == 1) { 1436 System.out.println(" = " + result); 1437 throw new RuntimeException("Test failed: should return " + expected); 1438 } 1439 } 1440 System.out.println(" = " + expected); 1441 } 1442 } 1443 } 1444 } 1445 1446 public void run(int nullMode) throws Exception { 1447 // Prepare test arguments 1448 Object[] args = { null, 1449 new Object(), 1450 new MyObject(), 1451 MyValue1.setX(MyValue1.createDefault(), 42), 1452 new Object[10], 1453 new MyObject[10], 1454 MyValue1.setX(MyValue1.createDefault(), 0x42), 1455 MyValue1.setX(MyValue1.createDefault(), 42), 1456 MyValue2.setX(MyValue2.createDefault(), 42), }; 1457 1458 boolean[][] equalities = { { true, false, false, false, false, false, false, false, false }, 1459 { false, true, false, false, false, false, false, false, false }, 1460 { false, false, true, false, false, false, false, false, false }, 1461 { false, false, false, ACmpOnValues == 3,false, false, false, ACmpOnValues == 3, false }, 1462 { false, false, false, false, true, false, false, false, false }, 1463 { false, false, false, false, false, true, false, false, false }, 1464 { false, false, false, false, false, false, ACmpOnValues == 3, false, false }, 1465 { false, false, false, ACmpOnValues == 3,false, false, false, ACmpOnValues == 3, false }, 1466 { false, false, false, false, false, false, false, false, ACmpOnValues == 3 } }; 1467 1468 // Run tests 1469 for (Method m : getClass().getMethods()) { 1470 if (m.getName().startsWith("test")) { 1471 // Do some warmup runs 1472 runTest(m, args, 1000, nullMode, equalities); 1473 // Make sure method is compiled 1474 WHITE_BOX.enqueueMethodForCompilation(m, COMP_LEVEL_FULL_OPTIMIZATION); 1475 Asserts.assertTrue(WHITE_BOX.isMethodCompiled(m, false), m + " not compiled"); 1476 // Run again to verify correctness of compiled code 1477 runTest(m, args, 1, nullMode, equalities); 1478 } 1479 } 1480 1481 Method cmpAlwaysUnEqual3_m = getClass().getMethod("cmpAlwaysUnEqual3", Object.class); 1482 Method cmpAlwaysUnEqual4_m = getClass().getMethod("cmpAlwaysUnEqual4", Object.class); 1483 Method cmpSometimesEqual1_m = getClass().getMethod("cmpSometimesEqual1", Object.class); 1484 Method cmpSometimesEqual2_m = getClass().getMethod("cmpSometimesEqual2", Object.class); 1485 1486 for (int i = 0; i < 20_000; ++i) { 1487 Asserts.assertTrue(cmpAlwaysEqual1(args[1], args[1])); 1488 Asserts.assertFalse(cmpAlwaysEqual2(args[1], args[1])); 1489 Asserts.assertTrue(cmpAlwaysEqual3(args[1])); 1490 Asserts.assertFalse(cmpAlwaysEqual4(args[1])); 1491 1492 Asserts.assertFalse(cmpAlwaysUnEqual1(args[1], args[2])); 1493 Asserts.assertTrue(cmpAlwaysUnEqual2(args[1], args[2])); 1494 boolean compiled = WHITE_BOX.isMethodCompiled(cmpAlwaysUnEqual3_m, false); 1495 boolean res = cmpAlwaysUnEqual3(args[3]); 1496 if (ACmpOnValues != 3) { 1497 Asserts.assertFalse(res); 1498 } else if (compiled) { 1499 Asserts.assertTrue(res); 1500 } 1501 compiled = WHITE_BOX.isMethodCompiled(cmpAlwaysUnEqual4_m, false); 1502 res = cmpAlwaysUnEqual4(args[3]); 1503 if (ACmpOnValues != 3) { 1504 Asserts.assertTrue(res); 1505 } else if (compiled) { 1506 Asserts.assertFalse(res); 1507 } 1508 1509 int idx = i % args.length; 1510 compiled = WHITE_BOX.isMethodCompiled(cmpSometimesEqual1_m, false); 1511 res = cmpSometimesEqual1(args[idx]); 1512 if (ACmpOnValues != 3) { 1513 Asserts.assertEQ(res, args[idx] == null || !args[idx].getClass().isInlineClass()); 1514 } else if (compiled) { 1515 Asserts.assertTrue(res); 1516 } 1517 compiled = WHITE_BOX.isMethodCompiled(cmpSometimesEqual2_m, false); 1518 res = cmpSometimesEqual2(args[idx]); 1519 if (ACmpOnValues != 3) { 1520 Asserts.assertNE(res, args[idx] == null || !args[idx].getClass().isInlineClass()); 1521 } else if (compiled) { 1522 Asserts.assertFalse(res); 1523 } 1524 } 1525 } 1526 1527 public static void main(String[] args) throws Exception { 1528 if (Boolean.getBoolean("test.c1")) { 1529 System.out.println("new acmp is not implemented for C1"); // TMP 1530 return; 1531 } 1532 1533 if (args.length == 0) { 1534 enumerateVMOptions(); 1535 } else { 1536 int nullMode = Integer.valueOf(args[0]); 1537 TestNewAcmp t = new TestNewAcmp(); 1538 t.run(nullMode); 1539 } 1540 } 1541 1542 private static String[] addOptions(String prefix[], String... extra) { 1543 ArrayList<String> list = new ArrayList<String>(); 1544 if (prefix != null) { 1545 for (String s : prefix) { 1546 list.add(s); 1547 } 1548 } 1549 if (extra != null) { 1550 for (String s : extra) { 1551 System.out.println(" " + s); 1552 list.add(s); 1553 } 1554 } 1555 1556 return list.toArray(new String[list.size()]); 1557 } 1558 1559 private static void enumerateVMOptions() throws Exception { 1560 String[] baseOptions = { 1561 "-Xbootclasspath/a:.", 1562 "-XX:+UnlockDiagnosticVMOptions", 1563 "-XX:+WhiteBoxAPI", 1564 "-Xbatch", 1565 "-XX:+EnableValhalla", 1566 "-XX:TypeProfileLevel=222", 1567 "-XX:CompileCommand=dontinline,compiler.valhalla.valuetypes.TestNewAcmp::test*", 1568 "-XX:CompileCommand=dontinline,compiler.valhalla.valuetypes.TestNewAcmp::cmp*"}; 1569 1570 String SCENARIOS = System.getProperty("Scenarios", ""); 1571 List<String> scenarios = null; 1572 if (!SCENARIOS.isEmpty()) { 1573 scenarios = Arrays.asList(SCENARIOS.split(",")); 1574 } 1575 1576 int scenario = -1; 1577 for (int nullMode = 0; nullMode <= 2; nullMode++) { // null mode 1578 for (int onVal = 0; onVal < 2; onVal++) { // 0 = default, 1 = -XX:ACmpOnValues=3 1579 for (int incrInline = 0; incrInline < 2; incrInline++) { // 0 = default, 1 = -XX:+AlwaysIncrementalInline 1580 scenario++; 1581 if (scenarios != null && !scenarios.contains(Integer.toString(scenario))) { 1582 System.out.println("Scenario #" + scenario + " is skipped due to -Dscenarios=" + SCENARIOS); 1583 continue; 1584 } else { 1585 System.out.println("Scenario #" + scenario + " -------------------"); 1586 } 1587 1588 String[] cmds = baseOptions; 1589 if (incrInline != 0) { 1590 cmds = addOptions(cmds, "-XX:+IgnoreUnrecognizedVMOptions", "-XX:+AlwaysIncrementalInline"); 1591 } 1592 if (onVal != 0) { 1593 cmds = addOptions(cmds, "-XX:+UnlockExperimentalVMOptions", "-XX:ACmpOnValues=3"); 1594 } 1595 cmds = addOptions(cmds, "compiler.valhalla.valuetypes.TestNewAcmp"); 1596 cmds = addOptions(cmds, Integer.toString(nullMode)); 1597 1598 OutputAnalyzer oa = ProcessTools.executeTestJvm(cmds); 1599 String output = oa.getOutput(); 1600 oa.shouldHaveExitValue(0); 1601 System.out.println(output); 1602 } 1603 } 1604 } 1605 } 1606 }