Apache Lucene open-source search software
Limit vectorization API to Hotspot VMs (and rename some constants and fix Javadocs) (#12765)
Uwe Schindler382aa549a7d6
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex 5fae1e4b88f..418b3024c69 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -200,8 +200,8 @@ Improvements* GITHUB#12677: Better detect vector module in non-default setups (e.g., custom module layers).(Uwe Schindler)-* GITHUB#12634, GITHUB#12632, GITHUB#12680, GITHUB#12681, GITHUB#12731: Speed up Panama vector support- and test improvements. (Uwe Schindler, Robert Muir)+* GITHUB#12634, GITHUB#12632, GITHUB#12680, GITHUB#12681, GITHUB#12731, GITHUB#12737: Speed up+ Panama vector support and test improvements. (Uwe Schindler, Robert Muir)* GITHUB#12586: Remove over-counting of deleted terms. (Guo Feng)@@ -267,6 +267,8 @@ Changes in runtime behavior* GITHUB#12569: Prevent concurrent tasks from parallelizing execution further which could cause deadlock(Luca Cavanna)+* GITHUB#12765: Disable vectorization on VMs that are not Hotspot-based. (Uwe Schindler, Robert Muir)+Bug Fixes---------------------diff --git a/lucene/core/src/java/org/apache/lucene/internal/vectorization/VectorizationProvider.java b/lucene/core/src/java/org/apache/lucene/internal/vectorization/VectorizationProvider.javaindex 3d565b650a9..35a485243d5 100644--- a/lucene/core/src/java/org/apache/lucene/internal/vectorization/VectorizationProvider.java+++ b/lucene/core/src/java/org/apache/lucene/internal/vectorization/VectorizationProvider.java@@ -111,6 +111,12 @@ public abstract class VectorizationProvider {+ Locale.getDefault());return new DefaultVectorizationProvider();}+ // only use vector module with Hotspot VM+ if (!Constants.IS_HOTSPOT_VM) {+ LOG.warning(+ "Java runtime is not using Hotspot VM; Java vector incubator API can't be enabled.");+ return new DefaultVectorizationProvider();+ }// is the incubator module present and readable (JVM providers may to exclude them or it is// build with jlink)final var vectorMod = lookupVectorModule();diff --git a/lucene/core/src/java/org/apache/lucene/util/Constants.java b/lucene/core/src/java/org/apache/lucene/util/Constants.javaindex 179cb851e03..01ead03fc04 100644--- a/lucene/core/src/java/org/apache/lucene/util/Constants.java+++ b/lucene/core/src/java/org/apache/lucene/util/Constants.java@@ -59,10 +59,13 @@ public final class Constants {/** The value of <code>System.getProperty("java.vendor")</code>. */public static final String JAVA_VENDOR = getSysProp("java.vendor", UNKNOWN);- /** True iff the Java runtime is a client runtime and C2 compiler is not enabled */+ /** True iff the Java runtime is a client runtime and C2 compiler is not enabled. */public static final boolean IS_CLIENT_VM =getSysProp("java.vm.info", "").contains("emulated-client");+ /** True iff the Java VM is based on Hotspot and has the Hotspot MX bean readable by Lucene. */+ public static final boolean IS_HOTSPOT_VM = HotspotVMOptions.IS_HOTSPOT_VM;+/** True iff running on a 64bit JVM */public static final boolean JRE_IS_64BIT = is64Bit();@@ -75,22 +78,22 @@ public final class Constants {}}- /** true if FMA likely means a cpu instruction and not BigDecimal logic */+ /** true if FMA likely means a cpu instruction and not BigDecimal logic. */private static final boolean HAS_FMA =(IS_CLIENT_VM == false) && HotspotVMOptions.get("UseFMA").map(Boolean::valueOf).orElse(false);- /** maximum supported vectorsize */+ /** maximum supported vectorsize. */private static final int MAX_VECTOR_SIZE =HotspotVMOptions.get("MaxVectorSize").map(Integer::valueOf).orElse(0);- /** true for an AMD cpu with SSE4a instructions */+ /** true for an AMD cpu with SSE4a instructions. */private static final boolean HAS_SSE4A =HotspotVMOptions.get("UseXmmI2F").map(Boolean::valueOf).orElse(false);- /** true iff we know VFMA has faster throughput than separate vmul/vadd */+ /** true iff we know VFMA has faster throughput than separate vmul/vadd. */public static final boolean HAS_FAST_VECTOR_FMA = hasFastVectorFMA();- /** true iff we know FMA has faster throughput than separate mul/add */+ /** true iff we know FMA has faster throughput than separate mul/add. */public static final boolean HAS_FAST_SCALAR_FMA = hasFastScalarFMA();private static boolean hasFastVectorFMA() {diff --git a/lucene/core/src/java/org/apache/lucene/util/HotspotVMOptions.java b/lucene/core/src/java/org/apache/lucene/util/HotspotVMOptions.javaindex 70f963e1b37..e9fc58415ba 100644--- a/lucene/core/src/java/org/apache/lucene/util/HotspotVMOptions.java+++ b/lucene/core/src/java/org/apache/lucene/util/HotspotVMOptions.java@@ -26,8 +26,8 @@ import java.util.logging.Logger;final class HotspotVMOptions {private HotspotVMOptions() {} // can't construct- /** True if the Java VM is based on Hotspot and has the Hotspot MX bean readable by Lucene */- public static final boolean IS_HOTSPOT;+ /** True iff the Java VM is based on Hotspot and has the Hotspot MX bean readable by Lucene */+ public static final boolean IS_HOTSPOT_VM;/*** Returns an optional with the value of a Hotspot VM option. If the VM option does not exist or@@ -84,7 +84,7 @@ final class HotspotVMOptions {"Lucene cannot optimize algorithms or calculate object sizes for JVMs that are not based on Hotspot or a compatible implementation.");}}- IS_HOTSPOT = isHotspot;+ IS_HOTSPOT_VM = isHotspot;ACCESSOR = accessor;}}diff --git a/lucene/core/src/java/org/apache/lucene/util/RamUsageEstimator.java b/lucene/core/src/java/org/apache/lucene/util/RamUsageEstimator.javaindex e9941c7251e..fd32ece1ebd 100644--- a/lucene/core/src/java/org/apache/lucene/util/RamUsageEstimator.java+++ b/lucene/core/src/java/org/apache/lucene/util/RamUsageEstimator.java@@ -113,7 +113,7 @@ public final class RamUsageEstimator {/** Initialize constants and try to collect information about the JVM internals. */static {if (Constants.JRE_IS_64BIT) {- JVM_IS_HOTSPOT_64BIT = HotspotVMOptions.IS_HOTSPOT;+ JVM_IS_HOTSPOT_64BIT = HotspotVMOptions.IS_HOTSPOT_VM;// Try to get compressed oops and object alignment (the default seems to be 8 on Hotspot);// (this only works on 64 bit, on 32 bits the alignment and reference size is fixed):COMPRESSED_REFS_ENABLED =