RFR: 8355698: JDK not supporting sleef could cause exception at runtime after JDK-8353786

Vladimir Ivanov vlivanov at openjdk.org
Tue May 6 02:48:16 UTC 2025


On Mon, 28 Apr 2025 10:34:49 GMT, Hamlin Li <mli at openjdk.org> wrote:

> Hi,
> Can you help to review this patch?
> 
> Before [JDK-8353786](https://bugs.openjdk.org/browse/JDK-8353786), when a released jdk not supportting sleef (for any reason, e.g. low gcc version, intrinsic not supported, rvv not supported, and so on) runs on machine support vector operation (e.g. on riscv, it supports rvv), it can not call into sleef, but will not fail either, it falls back to java scalar version implementation.
> But after [JDK-8353786](https://bugs.openjdk.org/browse/JDK-8353786), it will cause an exception thrown at runtime.
> 
> This change the behaviour of existing jdk, and it should not throw exception anyway.
> 
> @iwanowww @RealFYang 
> 
> Thanks!

Thanks, Li. I think I have a better understanding now how it all works across platforms.

I agree with Andrew that it's highly undesireable to have divergence across JDK builds, but I don't have a good understanding how mature toolchain support is when it comes to vector intrinsics SLEEF library relies on.

As of now, producing empty native library is the only way to communicate that a vector math library isn't properly built.

So, 2 problems to address:
  (1) JDK build may produce an empty vector math library (and no build failures);
  (2) vector math library is built unconditionally (there's no way to configure JDK build to skip it).

Speaking of SVML, it requires GCC 4.9+ and MSVC 2017. According to JDK build documentation [1], newer toolchain versions are required for JDK build. So, it should be fine to remove GCC version checks. (JDK-8355656 is reported for a JDK build using Clang. I have no idea whether Clang can build SVML stubs or not.) 

So, the stop-the-gap fix for JDK-8355698 is to disable SLEEF build when toolchain doesn't have proper support. Alternatively, VectorMathLibrary can probe the library to ensure it is not empty [2]. 

[1] https://github.com/openjdk/jdk/blob/master/doc/building.md

[2] 

diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/VectorMathLibrary.java b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/VectorMathLibrary.java
index 4729235e2d9..9f0abb9afa1 100644
--- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/VectorMathLibrary.java
+++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/VectorMathLibrary.java
@@ -189,6 +189,16 @@ public boolean isSupported(Operator op, VectorSpecies<?> vspecies) {
     private static class SLEEF implements Library {
         static {
             VectorSupport.loadNativeLibrary("sleef");
+            ensureValidLibrary();
+        }
+
+        private static void ensureValidLibrary() {
+            // Probe an arbitrary entry point to ensure the library is not empty.
+            // JDK build of SLEEF-based vector math library may produce an empty library when
+            // proper toolchain support is absent. Until it is fixed, ensure the corresponding
+            // native library is not empty.
+            // Throws an exception on lookup failure which triggers a switch to Java-based implementation.
+            LOOKUP.findOrThrow(LIBRARY.symbolName(VectorOperators.SIN, FloatVector.SPECIES_64));
         }
 
         private static String suffix(VectorShape vshape, boolean isShapeAgnostic) {

-------------

PR Comment: https://git.openjdk.org/jdk/pull/24914#issuecomment-2853122819


More information about the hotspot-dev mailing list