Skip to content

Commit

Permalink
Allow easier verification of the Panama Vectorization provider with n…
Browse files Browse the repository at this point in the history
…ewer 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.
  • Loading branch information
ChrisHegarty authored Nov 14, 2024
1 parent 6fe8165 commit 8698dd8
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
8 changes: 7 additions & 1 deletion gradle/testing/defaults-tests.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand Down
6 changes: 5 additions & 1 deletion lucene/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
---------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,16 @@
* 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();
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -108,7 +133,7 @@ public static VectorizationProvider getInstance() {
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(
Expand Down

0 comments on commit 8698dd8

Please sign in to comment.