Skip to content

Commit 382aa54

Browse files
authored
Limit vectorization API to Hotspot VMs (and rename some constants and fix Javadocs) (#12765)
1 parent 5358b72 commit 382aa54

File tree

5 files changed

+23
-12
lines changed

5 files changed

+23
-12
lines changed

lucene/CHANGES.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,8 @@ Improvements
200200
* GITHUB#12677: Better detect vector module in non-default setups (e.g., custom module layers).
201201
(Uwe Schindler)
202202

203-
* GITHUB#12634, GITHUB#12632, GITHUB#12680, GITHUB#12681, GITHUB#12731: Speed up Panama vector support
204-
and test improvements. (Uwe Schindler, Robert Muir)
203+
* GITHUB#12634, GITHUB#12632, GITHUB#12680, GITHUB#12681, GITHUB#12731, GITHUB#12737: Speed up
204+
Panama vector support and test improvements. (Uwe Schindler, Robert Muir)
205205

206206
* GITHUB#12586: Remove over-counting of deleted terms. (Guo Feng)
207207

@@ -267,6 +267,8 @@ Changes in runtime behavior
267267
* GITHUB#12569: Prevent concurrent tasks from parallelizing execution further which could cause deadlock
268268
(Luca Cavanna)
269269

270+
* GITHUB#12765: Disable vectorization on VMs that are not Hotspot-based. (Uwe Schindler, Robert Muir)
271+
270272
Bug Fixes
271273
---------------------
272274

lucene/core/src/java/org/apache/lucene/internal/vectorization/VectorizationProvider.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ static VectorizationProvider lookup(boolean testMode) {
111111
+ Locale.getDefault());
112112
return new DefaultVectorizationProvider();
113113
}
114+
// only use vector module with Hotspot VM
115+
if (!Constants.IS_HOTSPOT_VM) {
116+
LOG.warning(
117+
"Java runtime is not using Hotspot VM; Java vector incubator API can't be enabled.");
118+
return new DefaultVectorizationProvider();
119+
}
114120
// is the incubator module present and readable (JVM providers may to exclude them or it is
115121
// build with jlink)
116122
final var vectorMod = lookupVectorModule();

lucene/core/src/java/org/apache/lucene/util/Constants.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,13 @@ private Constants() {} // can't construct
5959
/** The value of <code>System.getProperty("java.vendor")</code>. */
6060
public static final String JAVA_VENDOR = getSysProp("java.vendor", UNKNOWN);
6161

62-
/** True iff the Java runtime is a client runtime and C2 compiler is not enabled */
62+
/** True iff the Java runtime is a client runtime and C2 compiler is not enabled. */
6363
public static final boolean IS_CLIENT_VM =
6464
getSysProp("java.vm.info", "").contains("emulated-client");
6565

66+
/** True iff the Java VM is based on Hotspot and has the Hotspot MX bean readable by Lucene. */
67+
public static final boolean IS_HOTSPOT_VM = HotspotVMOptions.IS_HOTSPOT_VM;
68+
6669
/** True iff running on a 64bit JVM */
6770
public static final boolean JRE_IS_64BIT = is64Bit();
6871

@@ -75,22 +78,22 @@ private static boolean is64Bit() {
7578
}
7679
}
7780

78-
/** true if FMA likely means a cpu instruction and not BigDecimal logic */
81+
/** true if FMA likely means a cpu instruction and not BigDecimal logic. */
7982
private static final boolean HAS_FMA =
8083
(IS_CLIENT_VM == false) && HotspotVMOptions.get("UseFMA").map(Boolean::valueOf).orElse(false);
8184

82-
/** maximum supported vectorsize */
85+
/** maximum supported vectorsize. */
8386
private static final int MAX_VECTOR_SIZE =
8487
HotspotVMOptions.get("MaxVectorSize").map(Integer::valueOf).orElse(0);
8588

86-
/** true for an AMD cpu with SSE4a instructions */
89+
/** true for an AMD cpu with SSE4a instructions. */
8790
private static final boolean HAS_SSE4A =
8891
HotspotVMOptions.get("UseXmmI2F").map(Boolean::valueOf).orElse(false);
8992

90-
/** true iff we know VFMA has faster throughput than separate vmul/vadd */
93+
/** true iff we know VFMA has faster throughput than separate vmul/vadd. */
9194
public static final boolean HAS_FAST_VECTOR_FMA = hasFastVectorFMA();
9295

93-
/** true iff we know FMA has faster throughput than separate mul/add */
96+
/** true iff we know FMA has faster throughput than separate mul/add. */
9497
public static final boolean HAS_FAST_SCALAR_FMA = hasFastScalarFMA();
9598

9699
private static boolean hasFastVectorFMA() {

lucene/core/src/java/org/apache/lucene/util/HotspotVMOptions.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
final class HotspotVMOptions {
2727
private HotspotVMOptions() {} // can't construct
2828

29-
/** True if the Java VM is based on Hotspot and has the Hotspot MX bean readable by Lucene */
30-
public static final boolean IS_HOTSPOT;
29+
/** True iff the Java VM is based on Hotspot and has the Hotspot MX bean readable by Lucene */
30+
public static final boolean IS_HOTSPOT_VM;
3131

3232
/**
3333
* Returns an optional with the value of a Hotspot VM option. If the VM option does not exist or
@@ -84,7 +84,7 @@ public static Optional<String> get(String name) {
8484
"Lucene cannot optimize algorithms or calculate object sizes for JVMs that are not based on Hotspot or a compatible implementation.");
8585
}
8686
}
87-
IS_HOTSPOT = isHotspot;
87+
IS_HOTSPOT_VM = isHotspot;
8888
ACCESSOR = accessor;
8989
}
9090
}

lucene/core/src/java/org/apache/lucene/util/RamUsageEstimator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ private RamUsageEstimator() {}
113113
/** Initialize constants and try to collect information about the JVM internals. */
114114
static {
115115
if (Constants.JRE_IS_64BIT) {
116-
JVM_IS_HOTSPOT_64BIT = HotspotVMOptions.IS_HOTSPOT;
116+
JVM_IS_HOTSPOT_64BIT = HotspotVMOptions.IS_HOTSPOT_VM;
117117
// Try to get compressed oops and object alignment (the default seems to be 8 on Hotspot);
118118
// (this only works on 64 bit, on 32 bits the alignment and reference size is fixed):
119119
COMPRESSED_REFS_ENABLED =

0 commit comments

Comments
 (0)