From 1138dc3883123b0331e535ca651505588463c60d Mon Sep 17 00:00:00 2001 From: vamsi-parasa Date: Tue, 10 Oct 2023 09:36:59 -0700 Subject: [PATCH 1/5] 8317763:Restrict AVX512 intrinsics for Arrays.sort() methods to Intel CPUs --- src/hotspot/cpu/x86/stubGenerator_x86_64.cpp | 2 +- .../classes/java/util/DualPivotQuicksort.java | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/hotspot/cpu/x86/stubGenerator_x86_64.cpp b/src/hotspot/cpu/x86/stubGenerator_x86_64.cpp index 79ebef8b58113..35d77029fe590 100644 --- a/src/hotspot/cpu/x86/stubGenerator_x86_64.cpp +++ b/src/hotspot/cpu/x86/stubGenerator_x86_64.cpp @@ -4173,7 +4173,7 @@ void StubGenerator::generate_compiler_stubs() { } // Load x86_64_sort library on supported hardware to enable avx512 sort and partition intrinsics - if (UseAVX > 2 && VM_Version::supports_avx512dq()) { + if (VM_Version::is_intel() && UseAVX > 2 && VM_Version::supports_avx512dq()) { void *libsimdsort = nullptr; char ebuf_[1024]; char dll_name_simd_sort[JVM_MAXPATHLEN]; diff --git a/src/java.base/share/classes/java/util/DualPivotQuicksort.java b/src/java.base/share/classes/java/util/DualPivotQuicksort.java index 0dd4b6e354aed..306113fbbeb87 100644 --- a/src/java.base/share/classes/java/util/DualPivotQuicksort.java +++ b/src/java.base/share/classes/java/util/DualPivotQuicksort.java @@ -166,9 +166,9 @@ interface PartitionOperation { /** * Partitions the specified range of the array using the given pivots. * - * @param a the array to be sorted - * @param low the index of the first element, inclusive, to be sorted - * @param high the index of the last element, exclusive, to be sorted + * @param a the array to be partitioned + * @param low the index of the first element, inclusive, to be partitioned + * @param high the index of the last element, exclusive, to be partitioned * @param pivotIndex1 the index of pivot1, the first pivot * @param pivotIndex2 the index of pivot2, the second pivot */ @@ -178,13 +178,13 @@ interface PartitionOperation { /** * Partitions the specified range of the array using the two pivots provided. * - * @param elemType the class of the array to be sorted - * @param array the array to be sorted + * @param elemType the class of the array to be partitioned + * @param array the array to be partitioned * @param offset the relative offset, in bytes, from the base address of * the array to partition, otherwise if the array is {@code null},an absolute * address pointing to the first element to partition from. - * @param low the index of the first element, inclusive, to be sorted - * @param high the index of the last element, exclusive, to be sorted + * @param low the index of the first element, inclusive, to be partitioned + * @param high the index of the last element, exclusive, to be partitioned * @param pivotIndex1 the index of pivot1, the first pivot * @param pivotIndex2 the index of pivot2, the second pivot * @param po the method reference for the fallback implementation From 386bdd88be6385bc1113ef8ab5c087c178c2de86 Mon Sep 17 00:00:00 2001 From: vamsi-parasa Date: Tue, 10 Oct 2023 11:46:47 -0700 Subject: [PATCH 2/5] pragma workround for GCC12 bug --- src/hotspot/cpu/x86/stubGenerator_x86_64.cpp | 2 +- .../linux/native/libsimdsort/avx512-common-qsort.h | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/hotspot/cpu/x86/stubGenerator_x86_64.cpp b/src/hotspot/cpu/x86/stubGenerator_x86_64.cpp index 35d77029fe590..e071583b10ba7 100644 --- a/src/hotspot/cpu/x86/stubGenerator_x86_64.cpp +++ b/src/hotspot/cpu/x86/stubGenerator_x86_64.cpp @@ -4173,7 +4173,7 @@ void StubGenerator::generate_compiler_stubs() { } // Load x86_64_sort library on supported hardware to enable avx512 sort and partition intrinsics - if (VM_Version::is_intel() && UseAVX > 2 && VM_Version::supports_avx512dq()) { + if (VM_Version::is_intel() && VM_Version::supports_avx512dq()) { void *libsimdsort = nullptr; char ebuf_[1024]; char dll_name_simd_sort[JVM_MAXPATHLEN]; diff --git a/src/java.base/linux/native/libsimdsort/avx512-common-qsort.h b/src/java.base/linux/native/libsimdsort/avx512-common-qsort.h index b008bcd54b80c..7e1c1e31a3152 100644 --- a/src/java.base/linux/native/libsimdsort/avx512-common-qsort.h +++ b/src/java.base/linux/native/libsimdsort/avx512-common-qsort.h @@ -57,9 +57,18 @@ #include #include #include -#include #include +/* +Workaround for the bug in GCC12 (that was fixed in GCC 12.3.1). +More details are available at: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105593 +*/ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" +#pragma GCC diagnostic ignored "-Wuninitialized" +#include +#pragma GCC diagnostic pop + #define X86_SIMD_SORT_INFINITY std::numeric_limits::infinity() #define X86_SIMD_SORT_INFINITYF std::numeric_limits::infinity() #define X86_SIMD_SORT_INFINITYH 0x7c00 From a565f1d89dc70c9ec85101ceded0c1f71d2e003d Mon Sep 17 00:00:00 2001 From: vamsi-parasa Date: Tue, 10 Oct 2023 13:02:10 -0700 Subject: [PATCH 3/5] fix whitespace in build script --- make/modules/java.base/Lib.gmk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/make/modules/java.base/Lib.gmk b/make/modules/java.base/Lib.gmk index 57f98707cb7bc..6d63795f6de63 100644 --- a/make/modules/java.base/Lib.gmk +++ b/make/modules/java.base/Lib.gmk @@ -227,7 +227,7 @@ ifeq ($(ENABLE_FALLBACK_LINKER), true) NAME := fallbackLinker, \ CFLAGS := $(CFLAGS_JDKLIB) $(LIBFFI_CFLAGS), \ LDFLAGS := $(LDFLAGS_JDKLIB) \ - $(call SET_SHARED_LIBRARY_ORIGIN), \ + $(call SET_SHARED_LIBRARY_ORIGIN), \ LIBS := $(LIBFFI_LIBS), \ LIBS_windows := $(LIBFFI_LIBS) ws2_32.lib, \ )) From 1de07fb7cd8293481813a2c2b79aa5aac07b561a Mon Sep 17 00:00:00 2001 From: vamsi-parasa Date: Wed, 11 Oct 2023 10:17:30 -0700 Subject: [PATCH 4/5] Add @ForceInline annotation to insertion and mixedInsertion sort --- .../share/classes/java/util/DualPivotQuicksort.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/java.base/share/classes/java/util/DualPivotQuicksort.java b/src/java.base/share/classes/java/util/DualPivotQuicksort.java index 306113fbbeb87..ea217e44ec76d 100644 --- a/src/java.base/share/classes/java/util/DualPivotQuicksort.java +++ b/src/java.base/share/classes/java/util/DualPivotQuicksort.java @@ -569,6 +569,7 @@ private static int[] partitionSinglePivot(int[] a, int low, int high, int pivotI * @param low the index of the first element, inclusive, to be sorted * @param high the index of the last element, exclusive, to be sorted */ + @ForceInline private static void mixedInsertionSort(int[] a, int low, int high) { int size = high - low; int end = high - 3 * ((size >> 5) << 3); @@ -684,6 +685,7 @@ private static void mixedInsertionSort(int[] a, int low, int high) { * @param low the index of the first element, inclusive, to be sorted * @param high the index of the last element, exclusive, to be sorted */ + @ForceInline private static void insertionSort(int[] a, int low, int high) { for (int i, k = low; ++k < high; ) { int ai = a[i = k]; @@ -1371,6 +1373,7 @@ private static int[] partitionSinglePivot(long[] a, int low, int high, int pivot * @param low the index of the first element, inclusive, to be sorted * @param high the index of the last element, exclusive, to be sorted */ + @ForceInline private static void mixedInsertionSort(long[] a, int low, int high) { int size = high - low; int end = high - 3 * ((size >> 5) << 3); @@ -1486,6 +1489,7 @@ private static void mixedInsertionSort(long[] a, int low, int high) { * @param low the index of the first element, inclusive, to be sorted * @param high the index of the last element, exclusive, to be sorted */ + @ForceInline private static void insertionSort(long[] a, int low, int high) { for (int i, k = low; ++k < high; ) { long ai = a[i = k]; @@ -2959,6 +2963,7 @@ private static int[] partitionSinglePivot(float[] a, int low, int high, int pivo * @param low the index of the first element, inclusive, to be sorted * @param high the index of the last element, exclusive, to be sorted */ + @ForceInline private static void mixedInsertionSort(float[] a, int low, int high) { int size = high - low; int end = high - 3 * ((size >> 5) << 3); @@ -3074,6 +3079,7 @@ private static void mixedInsertionSort(float[] a, int low, int high) { * @param low the index of the first element, inclusive, to be sorted * @param high the index of the last element, exclusive, to be sorted */ + @ForceInline private static void insertionSort(float[] a, int low, int high) { for (int i, k = low; ++k < high; ) { float ai = a[i = k]; @@ -3812,6 +3818,7 @@ private static int[] partitionSinglePivot(double[] a, int low, int high, int piv * @param low the index of the first element, inclusive, to be sorted * @param high the index of the last element, exclusive, to be sorted */ + @ForceInline private static void mixedInsertionSort(double[] a, int low, int high) { int size = high - low; int end = high - 3 * ((size >> 5) << 3); @@ -3927,6 +3934,7 @@ private static void mixedInsertionSort(double[] a, int low, int high) { * @param low the index of the first element, inclusive, to be sorted * @param high the index of the last element, exclusive, to be sorted */ + @ForceInline private static void insertionSort(double[] a, int low, int high) { for (int i, k = low; ++k < high; ) { double ai = a[i = k]; From 9bce68048f5d20908e82529cb2eb1299c6289e93 Mon Sep 17 00:00:00 2001 From: vamsi-parasa Date: Wed, 11 Oct 2023 13:50:44 -0700 Subject: [PATCH 5/5] Revert @ForceInline annotations for small array sort methods --- .../share/classes/java/util/DualPivotQuicksort.java | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/java.base/share/classes/java/util/DualPivotQuicksort.java b/src/java.base/share/classes/java/util/DualPivotQuicksort.java index ea217e44ec76d..306113fbbeb87 100644 --- a/src/java.base/share/classes/java/util/DualPivotQuicksort.java +++ b/src/java.base/share/classes/java/util/DualPivotQuicksort.java @@ -569,7 +569,6 @@ private static int[] partitionSinglePivot(int[] a, int low, int high, int pivotI * @param low the index of the first element, inclusive, to be sorted * @param high the index of the last element, exclusive, to be sorted */ - @ForceInline private static void mixedInsertionSort(int[] a, int low, int high) { int size = high - low; int end = high - 3 * ((size >> 5) << 3); @@ -685,7 +684,6 @@ private static void mixedInsertionSort(int[] a, int low, int high) { * @param low the index of the first element, inclusive, to be sorted * @param high the index of the last element, exclusive, to be sorted */ - @ForceInline private static void insertionSort(int[] a, int low, int high) { for (int i, k = low; ++k < high; ) { int ai = a[i = k]; @@ -1373,7 +1371,6 @@ private static int[] partitionSinglePivot(long[] a, int low, int high, int pivot * @param low the index of the first element, inclusive, to be sorted * @param high the index of the last element, exclusive, to be sorted */ - @ForceInline private static void mixedInsertionSort(long[] a, int low, int high) { int size = high - low; int end = high - 3 * ((size >> 5) << 3); @@ -1489,7 +1486,6 @@ private static void mixedInsertionSort(long[] a, int low, int high) { * @param low the index of the first element, inclusive, to be sorted * @param high the index of the last element, exclusive, to be sorted */ - @ForceInline private static void insertionSort(long[] a, int low, int high) { for (int i, k = low; ++k < high; ) { long ai = a[i = k]; @@ -2963,7 +2959,6 @@ private static int[] partitionSinglePivot(float[] a, int low, int high, int pivo * @param low the index of the first element, inclusive, to be sorted * @param high the index of the last element, exclusive, to be sorted */ - @ForceInline private static void mixedInsertionSort(float[] a, int low, int high) { int size = high - low; int end = high - 3 * ((size >> 5) << 3); @@ -3079,7 +3074,6 @@ private static void mixedInsertionSort(float[] a, int low, int high) { * @param low the index of the first element, inclusive, to be sorted * @param high the index of the last element, exclusive, to be sorted */ - @ForceInline private static void insertionSort(float[] a, int low, int high) { for (int i, k = low; ++k < high; ) { float ai = a[i = k]; @@ -3818,7 +3812,6 @@ private static int[] partitionSinglePivot(double[] a, int low, int high, int piv * @param low the index of the first element, inclusive, to be sorted * @param high the index of the last element, exclusive, to be sorted */ - @ForceInline private static void mixedInsertionSort(double[] a, int low, int high) { int size = high - low; int end = high - 3 * ((size >> 5) << 3); @@ -3934,7 +3927,6 @@ private static void mixedInsertionSort(double[] a, int low, int high) { * @param low the index of the first element, inclusive, to be sorted * @param high the index of the last element, exclusive, to be sorted */ - @ForceInline private static void insertionSort(double[] a, int low, int high) { for (int i, k = low; ++k < high; ) { double ai = a[i = k];