532 phase = CompilePhase.FINAL_CODE)
533 @IR(applyIf = {"UseCompressedOops", "true"},
534 counts = {IRNode.G1_ENCODE_P_AND_STORE_N_WITH_BARRIER_FLAG, PRE_AND_POST, "1"},
535 phase = CompilePhase.FINAL_CODE)
536 public static Object[] testStoreAllOnNewLargeArray(Object o1) {
537 Object[] a = new Object[1024];
538 for (int i = 0; i < a.length; i++) {
539 a[i] = o1;
540 }
541 return a;
542 }
543
544 @Run(test = {"testArrayStore",
545 "testArrayStoreNull",
546 "testArrayStoreNotNull",
547 "testArrayStoreTwice",
548 "testStoreOnNewArrayAtKnownIndex",
549 "testStoreOnNewArrayAtUnknownIndex",
550 "testStoreAllOnNewSmallArray",
551 "testStoreAllOnNewLargeArray"})
552 public void runArrayStoreTests() {
553 {
554 Object[] a = new Object[10];
555 Object o1 = new Object();
556 testArrayStore(a, 4, o1);
557 Asserts.assertEquals(o1, a[4]);
558 }
559 {
560 Object[] a = new Object[10];
561 testArrayStoreNull(a, 4);
562 Asserts.assertNull(a[4]);
563 }
564 {
565 Object[] a = new Object[10];
566 Object o1 = new Object();
567 testArrayStoreNotNull(a, 4, o1);
568 Asserts.assertEquals(o1, a[4]);
569 }
570 {
571 Object[] a = new Object[10];
711 @IR(applyIf = {"UseCompressedOops", "true"},
712 counts = {IRNode.G1_COMPARE_AND_EXCHANGE_N_WITH_BARRIER_FLAG, PRE_AND_POST, "1"},
713 phase = CompilePhase.FINAL_CODE)
714 static Object testCompareAndExchange(Outer o, Object oldVal, Object newVal) {
715 return fVarHandle.compareAndExchange(o, oldVal, newVal);
716 }
717
718 @Test
719 @IR(applyIf = {"UseCompressedOops", "false"},
720 counts = {IRNode.G1_COMPARE_AND_SWAP_P_WITH_BARRIER_FLAG, PRE_AND_POST, "1"},
721 phase = CompilePhase.FINAL_CODE)
722 @IR(applyIf = {"UseCompressedOops", "true"},
723 counts = {IRNode.G1_COMPARE_AND_SWAP_N_WITH_BARRIER_FLAG, PRE_AND_POST, "1"},
724 phase = CompilePhase.FINAL_CODE)
725 static boolean testCompareAndSwap(Outer o, Object oldVal, Object newVal) {
726 return fVarHandle.compareAndSet(o, oldVal, newVal);
727 }
728
729 @Test
730 @IR(applyIf = {"UseCompressedOops", "false"},
731 counts = {IRNode.G1_GET_AND_SET_P_WITH_BARRIER_FLAG, PRE_AND_POST, "1"},
732 phase = CompilePhase.FINAL_CODE)
733 @IR(applyIf = {"UseCompressedOops", "true"},
734 counts = {IRNode.G1_GET_AND_SET_N_WITH_BARRIER_FLAG, PRE_AND_POST, "1"},
735 phase = CompilePhase.FINAL_CODE)
736 static Object testGetAndSet(Outer o, Object newVal) {
737 return fVarHandle.getAndSet(o, newVal);
738 }
739
740 // IR checks are disabled for s390 because barriers are not elided (to be investigated).
741 @Test
742 @IR(applyIfAnd = {"UseCompressedOops", "false", "ReduceInitialCardMarks", "false"},
743 applyIfPlatform = {"s390", "false"},
744 counts = {IRNode.G1_COMPARE_AND_EXCHANGE_P_WITH_BARRIER_FLAG, POST_ONLY, "1"},
745 phase = CompilePhase.FINAL_CODE)
746 @IR(applyIfAnd = {"UseCompressedOops", "true", "ReduceInitialCardMarks", "false"},
747 applyIfPlatform = {"s390", "false"},
748 counts = {IRNode.G1_COMPARE_AND_EXCHANGE_N_WITH_BARRIER_FLAG, POST_ONLY, "1"},
749 phase = CompilePhase.FINAL_CODE)
750 @IR(applyIfAnd = {"UseCompressedOops", "false", "ReduceInitialCardMarks", "true"},
751 applyIfPlatform = {"s390", "false"},
752 failOn = {IRNode.G1_COMPARE_AND_EXCHANGE_P_WITH_BARRIER_FLAG, ANY},
753 phase = CompilePhase.FINAL_CODE)
754 @IR(applyIfAnd = {"UseCompressedOops", "true", "ReduceInitialCardMarks", "true"},
769 counts = {IRNode.G1_COMPARE_AND_SWAP_P_WITH_BARRIER_FLAG, POST_ONLY, "1"},
770 phase = CompilePhase.FINAL_CODE)
771 @IR(applyIfAnd = {"UseCompressedOops", "true", "ReduceInitialCardMarks", "false"},
772 counts = {IRNode.G1_COMPARE_AND_SWAP_N_WITH_BARRIER_FLAG, POST_ONLY, "1"},
773 phase = CompilePhase.FINAL_CODE)
774 @IR(applyIfAnd = {"UseCompressedOops", "false", "ReduceInitialCardMarks", "true"},
775 applyIfPlatform = {"s390", "false"},
776 failOn = {IRNode.G1_COMPARE_AND_SWAP_P_WITH_BARRIER_FLAG, ANY},
777 phase = CompilePhase.FINAL_CODE)
778 @IR(applyIfAnd = {"UseCompressedOops", "true", "ReduceInitialCardMarks", "true"},
779 failOn = {IRNode.G1_COMPARE_AND_SWAP_N_WITH_BARRIER_FLAG, ANY},
780 phase = CompilePhase.FINAL_CODE)
781 static boolean testCompareAndSwapOnNewObject(Object oldVal, Object newVal) {
782 Outer o = new Outer();
783 o.f = oldVal;
784 return fVarHandle.compareAndSet(o, oldVal, newVal);
785 }
786
787 @Test
788 @IR(applyIfAnd = {"UseCompressedOops", "false", "ReduceInitialCardMarks", "false"},
789 counts = {IRNode.G1_GET_AND_SET_P_WITH_BARRIER_FLAG, POST_ONLY, "1"},
790 phase = CompilePhase.FINAL_CODE)
791 @IR(applyIfAnd = {"UseCompressedOops", "true", "ReduceInitialCardMarks", "false"},
792 counts = {IRNode.G1_GET_AND_SET_N_WITH_BARRIER_FLAG, POST_ONLY, "1"},
793 phase = CompilePhase.FINAL_CODE)
794 @IR(applyIfAnd = {"UseCompressedOops", "false", "ReduceInitialCardMarks", "true"},
795 failOn = {IRNode.G1_GET_AND_SET_P_WITH_BARRIER_FLAG, ANY},
796 phase = CompilePhase.FINAL_CODE)
797 @IR(applyIfAnd = {"UseCompressedOops", "true", "ReduceInitialCardMarks", "true"},
798 failOn = {IRNode.G1_GET_AND_SET_N_WITH_BARRIER_FLAG, ANY},
799 phase = CompilePhase.FINAL_CODE)
800 static Object testGetAndSetOnNewObject(Object oldVal, Object newVal) {
801 Outer o = new Outer();
802 o.f = oldVal;
803 return fVarHandle.getAndSet(o, newVal);
804 }
805
806 @Test
807 @IR(applyIfAnd = {"UseCompressedOops", "false", "ReduceInitialCardMarks", "false"},
808 counts = {IRNode.G1_GET_AND_SET_P_WITH_BARRIER_FLAG, POST_ONLY, "1"},
809 phase = CompilePhase.FINAL_CODE)
810 @IR(applyIfAnd = {"UseCompressedOops", "true", "ReduceInitialCardMarks", "false"},
811 counts = {IRNode.G1_GET_AND_SET_N_WITH_BARRIER_FLAG, POST_ONLY, "1"},
812 phase = CompilePhase.FINAL_CODE)
813 @IR(applyIfAnd = {"UseCompressedOops", "false", "ReduceInitialCardMarks", "true"},
814 failOn = {IRNode.G1_GET_AND_SET_P_WITH_BARRIER_FLAG, ANY},
815 phase = CompilePhase.FINAL_CODE)
816 @IR(applyIfAnd = {"UseCompressedOops", "true", "ReduceInitialCardMarks", "true"},
817 failOn = {IRNode.G1_GET_AND_SET_N_WITH_BARRIER_FLAG, ANY},
818 phase = CompilePhase.FINAL_CODE)
819 static Object testGetAndSetConditionallyOnNewObject(Object oldVal, Object newVal, boolean c) {
820 Outer o = new Outer();
821 o.f = oldVal;
822 if (c) {
823 return fVarHandle.getAndSet(o, newVal);
824 }
825 return oldVal;
826 }
827
828 @Test
829 @IR(applyIfAnd = {"UseCompressedOops", "false", "ReduceInitialCardMarks", "false"},
830 counts = {IRNode.G1_GET_AND_SET_P_WITH_BARRIER_FLAG, POST_ONLY, "1"},
831 phase = CompilePhase.FINAL_CODE)
832 @IR(applyIfAnd = {"UseCompressedOops", "true", "ReduceInitialCardMarks", "false"},
833 counts = {IRNode.G1_GET_AND_SET_N_WITH_BARRIER_FLAG, POST_ONLY, "1"},
834 phase = CompilePhase.FINAL_CODE)
835 @IR(applyIfAnd = {"UseCompressedOops", "false", "ReduceInitialCardMarks", "true"},
836 failOn = {IRNode.G1_GET_AND_SET_P_WITH_BARRIER_FLAG, ANY},
837 phase = CompilePhase.FINAL_CODE)
838 @IR(applyIfAnd = {"UseCompressedOops", "true", "ReduceInitialCardMarks", "true"},
839 failOn = {IRNode.G1_GET_AND_SET_N_WITH_BARRIER_FLAG, ANY},
840 phase = CompilePhase.FINAL_CODE)
841 static Object testGetAndSetOnNewObjectAfterException(Object oldVal, Object newVal, boolean c) throws Exception {
842 Outer o = new Outer();
843 if (c) {
844 throw new Exception("");
845 }
846 o.f = oldVal;
847 return fVarHandle.getAndSet(o, newVal);
848 }
849
850 @Test
851 @IR(applyIf = {"UseCompressedOops", "false"},
852 counts = {IRNode.G1_GET_AND_SET_P_WITH_BARRIER_FLAG, PRE_AND_POST, "1"},
853 phase = CompilePhase.FINAL_CODE)
854 @IR(applyIf = {"UseCompressedOops", "true"},
855 counts = {IRNode.G1_GET_AND_SET_N_WITH_BARRIER_FLAG, PRE_AND_POST, "1"},
856 phase = CompilePhase.FINAL_CODE)
857 static Object testGetAndSetOnNewObjectAfterCall(Object oldVal, Object newVal) {
858 Outer o = new Outer();
859 nonInlinedMethod();
860 o.f = oldVal;
861 return fVarHandle.getAndSet(o, newVal);
862 }
863
864 @Run(test = {"testCompareAndExchange",
865 "testCompareAndSwap",
866 "testGetAndSet",
867 "testCompareAndExchangeOnNewObject",
868 "testCompareAndSwapOnNewObject",
869 "testGetAndSetOnNewObject",
870 "testGetAndSetConditionallyOnNewObject",
871 "testGetAndSetOnNewObjectAfterException",
872 "testGetAndSetOnNewObjectAfterCall"})
873 public void runAtomicTests() {
874 {
875 Outer o = new Outer();
|
532 phase = CompilePhase.FINAL_CODE)
533 @IR(applyIf = {"UseCompressedOops", "true"},
534 counts = {IRNode.G1_ENCODE_P_AND_STORE_N_WITH_BARRIER_FLAG, PRE_AND_POST, "1"},
535 phase = CompilePhase.FINAL_CODE)
536 public static Object[] testStoreAllOnNewLargeArray(Object o1) {
537 Object[] a = new Object[1024];
538 for (int i = 0; i < a.length; i++) {
539 a[i] = o1;
540 }
541 return a;
542 }
543
544 @Run(test = {"testArrayStore",
545 "testArrayStoreNull",
546 "testArrayStoreNotNull",
547 "testArrayStoreTwice",
548 "testStoreOnNewArrayAtKnownIndex",
549 "testStoreOnNewArrayAtUnknownIndex",
550 "testStoreAllOnNewSmallArray",
551 "testStoreAllOnNewLargeArray"})
552 @Warmup(5000)
553 public void runArrayStoreTests() {
554 {
555 Object[] a = new Object[10];
556 Object o1 = new Object();
557 testArrayStore(a, 4, o1);
558 Asserts.assertEquals(o1, a[4]);
559 }
560 {
561 Object[] a = new Object[10];
562 testArrayStoreNull(a, 4);
563 Asserts.assertNull(a[4]);
564 }
565 {
566 Object[] a = new Object[10];
567 Object o1 = new Object();
568 testArrayStoreNotNull(a, 4, o1);
569 Asserts.assertEquals(o1, a[4]);
570 }
571 {
572 Object[] a = new Object[10];
712 @IR(applyIf = {"UseCompressedOops", "true"},
713 counts = {IRNode.G1_COMPARE_AND_EXCHANGE_N_WITH_BARRIER_FLAG, PRE_AND_POST, "1"},
714 phase = CompilePhase.FINAL_CODE)
715 static Object testCompareAndExchange(Outer o, Object oldVal, Object newVal) {
716 return fVarHandle.compareAndExchange(o, oldVal, newVal);
717 }
718
719 @Test
720 @IR(applyIf = {"UseCompressedOops", "false"},
721 counts = {IRNode.G1_COMPARE_AND_SWAP_P_WITH_BARRIER_FLAG, PRE_AND_POST, "1"},
722 phase = CompilePhase.FINAL_CODE)
723 @IR(applyIf = {"UseCompressedOops", "true"},
724 counts = {IRNode.G1_COMPARE_AND_SWAP_N_WITH_BARRIER_FLAG, PRE_AND_POST, "1"},
725 phase = CompilePhase.FINAL_CODE)
726 static boolean testCompareAndSwap(Outer o, Object oldVal, Object newVal) {
727 return fVarHandle.compareAndSet(o, oldVal, newVal);
728 }
729
730 @Test
731 @IR(applyIf = {"UseCompressedOops", "false"},
732 counts = {IRNode.G1_COMPARE_AND_SWAP_P_WITH_BARRIER_FLAG, PRE_AND_POST, "1"},
733 phase = CompilePhase.FINAL_CODE)
734 @IR(applyIf = {"UseCompressedOops", "true"},
735 counts = {IRNode.G1_COMPARE_AND_SWAP_N_WITH_BARRIER_FLAG, PRE_AND_POST, "1"},
736 phase = CompilePhase.FINAL_CODE)
737 static Object testGetAndSet(Outer o, Object newVal) {
738 return fVarHandle.getAndSet(o, newVal);
739 }
740
741 // IR checks are disabled for s390 because barriers are not elided (to be investigated).
742 @Test
743 @IR(applyIfAnd = {"UseCompressedOops", "false", "ReduceInitialCardMarks", "false"},
744 applyIfPlatform = {"s390", "false"},
745 counts = {IRNode.G1_COMPARE_AND_EXCHANGE_P_WITH_BARRIER_FLAG, POST_ONLY, "1"},
746 phase = CompilePhase.FINAL_CODE)
747 @IR(applyIfAnd = {"UseCompressedOops", "true", "ReduceInitialCardMarks", "false"},
748 applyIfPlatform = {"s390", "false"},
749 counts = {IRNode.G1_COMPARE_AND_EXCHANGE_N_WITH_BARRIER_FLAG, POST_ONLY, "1"},
750 phase = CompilePhase.FINAL_CODE)
751 @IR(applyIfAnd = {"UseCompressedOops", "false", "ReduceInitialCardMarks", "true"},
752 applyIfPlatform = {"s390", "false"},
753 failOn = {IRNode.G1_COMPARE_AND_EXCHANGE_P_WITH_BARRIER_FLAG, ANY},
754 phase = CompilePhase.FINAL_CODE)
755 @IR(applyIfAnd = {"UseCompressedOops", "true", "ReduceInitialCardMarks", "true"},
770 counts = {IRNode.G1_COMPARE_AND_SWAP_P_WITH_BARRIER_FLAG, POST_ONLY, "1"},
771 phase = CompilePhase.FINAL_CODE)
772 @IR(applyIfAnd = {"UseCompressedOops", "true", "ReduceInitialCardMarks", "false"},
773 counts = {IRNode.G1_COMPARE_AND_SWAP_N_WITH_BARRIER_FLAG, POST_ONLY, "1"},
774 phase = CompilePhase.FINAL_CODE)
775 @IR(applyIfAnd = {"UseCompressedOops", "false", "ReduceInitialCardMarks", "true"},
776 applyIfPlatform = {"s390", "false"},
777 failOn = {IRNode.G1_COMPARE_AND_SWAP_P_WITH_BARRIER_FLAG, ANY},
778 phase = CompilePhase.FINAL_CODE)
779 @IR(applyIfAnd = {"UseCompressedOops", "true", "ReduceInitialCardMarks", "true"},
780 failOn = {IRNode.G1_COMPARE_AND_SWAP_N_WITH_BARRIER_FLAG, ANY},
781 phase = CompilePhase.FINAL_CODE)
782 static boolean testCompareAndSwapOnNewObject(Object oldVal, Object newVal) {
783 Outer o = new Outer();
784 o.f = oldVal;
785 return fVarHandle.compareAndSet(o, oldVal, newVal);
786 }
787
788 @Test
789 @IR(applyIfAnd = {"UseCompressedOops", "false", "ReduceInitialCardMarks", "false"},
790 counts = {IRNode.G1_COMPARE_AND_SWAP_P_WITH_BARRIER_FLAG, POST_ONLY, "1"},
791 phase = CompilePhase.FINAL_CODE)
792 @IR(applyIfAnd = {"UseCompressedOops", "true", "ReduceInitialCardMarks", "false"},
793 counts = {IRNode.G1_COMPARE_AND_SWAP_N_WITH_BARRIER_FLAG, POST_ONLY, "1"},
794 phase = CompilePhase.FINAL_CODE)
795 @IR(applyIfAnd = {"UseCompressedOops", "false", "ReduceInitialCardMarks", "true"},
796 failOn = {IRNode.G1_COMPARE_AND_SWAP_P_WITH_BARRIER_FLAG, ANY},
797 phase = CompilePhase.FINAL_CODE)
798 @IR(applyIfAnd = {"UseCompressedOops", "true", "ReduceInitialCardMarks", "true"},
799 failOn = {IRNode.G1_COMPARE_AND_SWAP_N_WITH_BARRIER_FLAG, ANY},
800 phase = CompilePhase.FINAL_CODE)
801 static Object testGetAndSetOnNewObject(Object oldVal, Object newVal) {
802 Outer o = new Outer();
803 o.f = oldVal;
804 return fVarHandle.getAndSet(o, newVal);
805 }
806
807 @Test
808 @IR(applyIfAnd = {"UseCompressedOops", "false", "ReduceInitialCardMarks", "false"},
809 counts = {IRNode.G1_COMPARE_AND_SWAP_P_WITH_BARRIER_FLAG, POST_ONLY, "1"},
810 phase = CompilePhase.FINAL_CODE)
811 @IR(applyIfAnd = {"UseCompressedOops", "true", "ReduceInitialCardMarks", "false"},
812 counts = {IRNode.G1_COMPARE_AND_SWAP_N_WITH_BARRIER_FLAG, POST_ONLY, "1"},
813 phase = CompilePhase.FINAL_CODE)
814 @IR(applyIfAnd = {"UseCompressedOops", "false", "ReduceInitialCardMarks", "true"},
815 failOn = {IRNode.G1_COMPARE_AND_SWAP_P_WITH_BARRIER_FLAG, ANY},
816 phase = CompilePhase.FINAL_CODE)
817 @IR(applyIfAnd = {"UseCompressedOops", "true", "ReduceInitialCardMarks", "true"},
818 failOn = {IRNode.G1_COMPARE_AND_SWAP_N_WITH_BARRIER_FLAG, ANY},
819 phase = CompilePhase.FINAL_CODE)
820 static Object testGetAndSetConditionallyOnNewObject(Object oldVal, Object newVal, boolean c) {
821 Outer o = new Outer();
822 o.f = oldVal;
823 if (c) {
824 return fVarHandle.getAndSet(o, newVal);
825 }
826 return oldVal;
827 }
828
829 @Test
830 @IR(applyIfAnd = {"UseCompressedOops", "false", "ReduceInitialCardMarks", "false"},
831 counts = {IRNode.G1_COMPARE_AND_SWAP_P_WITH_BARRIER_FLAG, POST_ONLY, "1"},
832 phase = CompilePhase.FINAL_CODE)
833 @IR(applyIfAnd = {"UseCompressedOops", "true", "ReduceInitialCardMarks", "false"},
834 counts = {IRNode.G1_COMPARE_AND_SWAP_N_WITH_BARRIER_FLAG, POST_ONLY, "1"},
835 phase = CompilePhase.FINAL_CODE)
836 @IR(applyIfAnd = {"UseCompressedOops", "false", "ReduceInitialCardMarks", "true"},
837 failOn = {IRNode.G1_COMPARE_AND_SWAP_P_WITH_BARRIER_FLAG, ANY},
838 phase = CompilePhase.FINAL_CODE)
839 @IR(applyIfAnd = {"UseCompressedOops", "true", "ReduceInitialCardMarks", "true"},
840 failOn = {IRNode.G1_COMPARE_AND_SWAP_N_WITH_BARRIER_FLAG, ANY},
841 phase = CompilePhase.FINAL_CODE)
842 static Object testGetAndSetOnNewObjectAfterException(Object oldVal, Object newVal, boolean c) throws Exception {
843 Outer o = new Outer();
844 if (c) {
845 throw new Exception("");
846 }
847 o.f = oldVal;
848 return fVarHandle.getAndSet(o, newVal);
849 }
850
851 @Test
852 @IR(applyIf = {"UseCompressedOops", "false"},
853 counts = {IRNode.G1_COMPARE_AND_SWAP_P_WITH_BARRIER_FLAG, PRE_AND_POST, "1"},
854 phase = CompilePhase.FINAL_CODE)
855 @IR(applyIf = {"UseCompressedOops", "true"},
856 counts = {IRNode.G1_COMPARE_AND_SWAP_N_WITH_BARRIER_FLAG, PRE_AND_POST, "1"},
857 phase = CompilePhase.FINAL_CODE)
858 static Object testGetAndSetOnNewObjectAfterCall(Object oldVal, Object newVal) {
859 Outer o = new Outer();
860 nonInlinedMethod();
861 o.f = oldVal;
862 return fVarHandle.getAndSet(o, newVal);
863 }
864
865 @Run(test = {"testCompareAndExchange",
866 "testCompareAndSwap",
867 "testGetAndSet",
868 "testCompareAndExchangeOnNewObject",
869 "testCompareAndSwapOnNewObject",
870 "testGetAndSetOnNewObject",
871 "testGetAndSetConditionallyOnNewObject",
872 "testGetAndSetOnNewObjectAfterException",
873 "testGetAndSetOnNewObjectAfterCall"})
874 public void runAtomicTests() {
875 {
876 Outer o = new Outer();
|