Skip to content

Apache Lucene open-source search software

Allow easier verification of the Panama Vectorization provider with newer Java versions (#13986)

Chris Hegarty8698dd85d867
diff --git a/gradle/testing/defaults-tests.gradle b/gradle/testing/defaults-tests.gradle
index 1f3a7d8b1a0..14e64647d66 100644
--- a/gradle/testing/defaults-tests.gradle
+++ b/gradle/testing/defaults-tests.gradle
@@ -128,8 +128,14 @@ allprojects {
jvmArgs '--add-modules', 'jdk.management'
// Enable the vector incubator module on supported Java versions:
- if (rootProject.vectorIncubatorJavaVersions.contains(rootProject.runtimeJavaVersion)) {
+ def prop = propertyOrDefault("org.apache.lucene.vectorization.upperJavaFeatureVersion", "1") as String
+ def v = JavaVersion.toVersion(Integer.parseInt(prop)).majorVersion
+ if (rootProject.vectorIncubatorJavaVersions.contains(rootProject.runtimeJavaVersion) ||
+ rootProject.runtimeJavaVersion.majorVersion <= v) {
jvmArgs '--add-modules', 'jdk.incubator.vector'
+ if (rootProject.runtimeJavaVersion.majorVersion <= v) {
+ systemProperty 'org.apache.lucene.vectorization.upperJavaFeatureVersion', v
+ }
}
jvmArgs '--enable-native-access=' + (project.path in [
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 1c4b5cbb249..062c107158b 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -47,7 +47,11 @@ New Features
Improvements
---------------------
-(No changes)
+
+* GITHUB#13986: Allow easier configuration of the Panama Vectorization provider with
+ newer Java versions. Set the `org.apache.lucene.vectorization.upperJavaFeatureVersion`
+ system property to increase the set of Java versions that Panama Vectorization will
+ provide optimized implementations for. (Chris Hegarty)
Optimizations
---------------------
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 e6441310dcc..c0ed905353b 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
@@ -38,12 +38,16 @@ import org.apache.lucene.util.VectorUtil;
* vectorization modules in the Java runtime this class provides optimized implementations (using
* SIMD) of several algorithms used throughout Apache Lucene.
*
+ * <p>Expert: set the {@value #UPPER_JAVA_FEATURE_VERSION_SYSPROP} system property to increase the
+ * set of Java versions this class will provide optimized implementations for.
+ *
* @lucene.internal
*/
public abstract class VectorizationProvider {
static final OptionalInt TESTS_VECTOR_SIZE;
static final boolean TESTS_FORCE_INTEGER_VECTORS;
+ static final int UPPER_JAVA_FEATURE_VERSION = getUpperJavaFeatureVersion();
static {
var vs = OptionalInt.empty();
@@ -71,6 +75,27 @@ public abstract class VectorizationProvider {
TESTS_FORCE_INTEGER_VECTORS = enforce;
}
+ private static final String UPPER_JAVA_FEATURE_VERSION_SYSPROP =
+ "org.apache.lucene.vectorization.upperJavaFeatureVersion";
+ private static final int DEFAULT_UPPER_JAVA_FEATURE_VERSION = 23;
+
+ private static int getUpperJavaFeatureVersion() {
+ int runtimeVersion = DEFAULT_UPPER_JAVA_FEATURE_VERSION;
+ try {
+ String str = System.getProperty(UPPER_JAVA_FEATURE_VERSION_SYSPROP);
+ if (str != null) {
+ runtimeVersion = Math.max(Integer.parseInt(str), runtimeVersion);
+ }
+ } catch (@SuppressWarnings("unused") NumberFormatException | SecurityException ignored) {
+ Logger.getLogger(VectorizationProvider.class.getName())
+ .warning(
+ "Cannot read sysprop "
+ + UPPER_JAVA_FEATURE_VERSION_SYSPROP
+ + ", so the default value will be used.");
+ }
+ return runtimeVersion;
+ }
+
/**
* Returns the default instance of the provider matching vectorization possibilities of actual
* runtime.
@@ -108,7 +133,7 @@ public abstract class VectorizationProvider {
static VectorizationProvider lookup(boolean testMode) {
final int runtimeVersion = Runtime.version().feature();
assert runtimeVersion >= 21;
- if (runtimeVersion <= 23) {
+ if (runtimeVersion <= UPPER_JAVA_FEATURE_VERSION) {
// only use vector module with Hotspot VM
if (!Constants.IS_HOTSPOT_VM) {
LOG.warning(