You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by us...@apache.org on 2023/11/05 18:24:32 UTC
(lucene) branch branch_9x updated: Limit vectorization API to Hotspot VMs (and rename some constants and fix Javadocs) (#12765)
This is an automated email from the ASF dual-hosted git repository.
uschindler pushed a commit to branch branch_9x
in repository https://gitbox.apache.org/repos/asf/lucene.git
The following commit(s) were added to refs/heads/branch_9x by this push:
new 6684da1908a Limit vectorization API to Hotspot VMs (and rename some constants and fix Javadocs) (#12765)
6684da1908a is described below
commit 6684da1908a573543eb08baff66e39f24bb49f6f
Author: Uwe Schindler <us...@apache.org>
AuthorDate: Sun Nov 5 19:22:33 2023 +0100
Limit vectorization API to Hotspot VMs (and rename some constants and fix Javadocs) (#12765)
---
lucene/CHANGES.txt | 6 ++++--
.../internal/vectorization/VectorizationProvider.java | 6 ++++++
.../core/src/java/org/apache/lucene/util/Constants.java | 15 +++++++++------
.../src/java/org/apache/lucene/util/HotspotVMOptions.java | 6 +++---
.../java/org/apache/lucene/util/RamUsageEstimator.java | 2 +-
5 files changed, 23 insertions(+), 12 deletions(-)
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 2d76ff54249..08b07b0e801 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -63,8 +63,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)
@@ -130,6 +130,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.java
index 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.java
index 979f98fcbce..58b43f5242e 100644
--- a/lucene/core/src/java/org/apache/lucene/util/Constants.java
+++ b/lucene/core/src/java/org/apache/lucene/util/Constants.java
@@ -83,10 +83,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();
@@ -99,22 +102,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.java
index 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.java
index 2ea0d4adbb0..a7109f2b2ea 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 =