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

This commit allows easier verification of the Panama Vectorization provider with newer Java versions.

The upper bound Java version of the Vectorization provider is hardcoded to the version that has been tested and is known to work. This is a bit inflexible when experimenting with and verifying newer JDK versions. This change proposes to add a new system property that allows to set the upper bound of the range of Java versions supported.

With this change, and the accompanying small gradle change, then one can verify newer JDKs as follows:

CI=true; RUNTIME_JAVA_HOME=/Users/chegar/binaries/jdk-24.jdk-ea-b23/Contents/Home
./gradlew :lucene:core:test -Dorg.apache.lucene.vectorization.upperJavaFeatureVersion=24

This change helps both testing and verifying with Early Access JDK builds, as well as allowing to override the upper bound when the JDK is known to work fine.
This commit is contained in:
Chris Hegarty 2024-11-14 09:02:15 +00:00 committed by GitHub
parent 6fe8165cac
commit 8698dd85d8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 38 additions and 3 deletions

View File

@ -128,8 +128,14 @@ allprojects {
jvmArgs '--add-modules', 'jdk.management' jvmArgs '--add-modules', 'jdk.management'
// Enable the vector incubator module on supported Java versions: // 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' 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 [ jvmArgs '--enable-native-access=' + (project.path in [

View File

@ -47,7 +47,11 @@ New Features
Improvements 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 Optimizations
--------------------- ---------------------

View File

@ -38,12 +38,16 @@ import org.apache.lucene.util.VectorUtil;
* vectorization modules in the Java runtime this class provides optimized implementations (using * vectorization modules in the Java runtime this class provides optimized implementations (using
* SIMD) of several algorithms used throughout Apache Lucene. * 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 * @lucene.internal
*/ */
public abstract class VectorizationProvider { public abstract class VectorizationProvider {
static final OptionalInt TESTS_VECTOR_SIZE; static final OptionalInt TESTS_VECTOR_SIZE;
static final boolean TESTS_FORCE_INTEGER_VECTORS; static final boolean TESTS_FORCE_INTEGER_VECTORS;
static final int UPPER_JAVA_FEATURE_VERSION = getUpperJavaFeatureVersion();
static { static {
var vs = OptionalInt.empty(); var vs = OptionalInt.empty();
@ -71,6 +75,27 @@ public abstract class VectorizationProvider {
TESTS_FORCE_INTEGER_VECTORS = enforce; 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 * Returns the default instance of the provider matching vectorization possibilities of actual
* runtime. * runtime.
@ -108,7 +133,7 @@ public abstract class VectorizationProvider {
static VectorizationProvider lookup(boolean testMode) { static VectorizationProvider lookup(boolean testMode) {
final int runtimeVersion = Runtime.version().feature(); final int runtimeVersion = Runtime.version().feature();
assert runtimeVersion >= 21; assert runtimeVersion >= 21;
if (runtimeVersion <= 23) { if (runtimeVersion <= UPPER_JAVA_FEATURE_VERSION) {
// only use vector module with Hotspot VM // only use vector module with Hotspot VM
if (!Constants.IS_HOTSPOT_VM) { if (!Constants.IS_HOTSPOT_VM) {
LOG.warning( LOG.warning(