Apache Lucene open-source search software
Move testing properties to provider class (no classloading deadlock possible) and fallback to default provider in non-test mode
Uwe Schindlerc8852a012faf
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.javaindex f1936199b0b..ed4066a94ac 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@@ -26,8 +26,11 @@ import java.security.PrivilegedAction;import java.util.Locale;import java.util.Objects;import java.util.Optional;+import java.util.OptionalInt;import java.util.Set;+import java.util.function.Predicate;import java.util.logging.Logger;+import java.util.stream.Stream;import org.apache.lucene.util.SuppressForbidden;import org.apache.lucene.util.VectorUtil;@@ -40,6 +43,35 @@ import org.apache.lucene.util.VectorUtil;*/public abstract class VectorizationProvider {+ static final OptionalInt TESTS_VECTOR_SIZE;+ static final boolean TESTS_FORCE_INTEGER_VECTORS;++ static {+ var vs = OptionalInt.empty();+ try {+ vs =+ Stream.ofNullable(System.getProperty("tests.vectorsize"))+ .filter(Predicate.not(String::isEmpty))+ .mapToInt(Integer::parseInt)+ .findAny();+ } catch (+ @SuppressWarnings("unused")+ SecurityException se) {+ // ignored+ }+ TESTS_VECTOR_SIZE = vs;++ boolean enforce = false;+ try {+ enforce = Boolean.getBoolean("tests.forceintegervectors");+ } catch (+ @SuppressWarnings("unused")+ SecurityException se) {+ // ignored+ }+ TESTS_FORCE_INTEGER_VECTORS = enforce;+ }+/*** Returns the default instance of the provider matching vectorization possibilities of actual* runtime.@@ -90,10 +122,17 @@ public abstract class VectorizationProvider {return new DefaultVectorizationProvider();}vectorMod.ifPresent(VectorizationProvider.class.getModule()::addReads);- // check if client VM- if (!testMode && isClientVM()) {- LOG.warning("C2 compiler is disabled; Java vector incubator API can't be enabled");- return new DefaultVectorizationProvider();+ // check for testMode and otherwise fallback to default if slowness could happen+ if (!testMode) {+ if (TESTS_VECTOR_SIZE.isPresent() || TESTS_FORCE_INTEGER_VECTORS) {+ LOG.warning(+ "Vector bitsize and/or integer vectors enforcement; using default vectorization provider outside of testMode");+ return new DefaultVectorizationProvider();+ }+ if (isClientVM()) {+ LOG.warning("C2 compiler is disabled; Java vector incubator API can't be enabled");+ return new DefaultVectorizationProvider();+ }}try {// we use method handles with lookup, so we do not need to deal with setAccessible as wediff --git a/lucene/core/src/java20/org/apache/lucene/internal/vectorization/PanamaVectorUtilSupport.java b/lucene/core/src/java20/org/apache/lucene/internal/vectorization/PanamaVectorUtilSupport.javaindex dad428845b7..e509f6ef49c 100644--- a/lucene/core/src/java20/org/apache/lucene/internal/vectorization/PanamaVectorUtilSupport.java+++ b/lucene/core/src/java20/org/apache/lucene/internal/vectorization/PanamaVectorUtilSupport.java@@ -57,10 +57,7 @@ final class PanamaVectorUtilSupport implements VectorUtilSupport {// default to platform supported bitsizeint vectorBitSize = VectorShape.preferredShape().vectorBitSize();// but allow easy overriding for testing- try {- vectorBitSize = Integer.getInteger("tests.vectorsize", vectorBitSize);- } catch (SecurityException ignored) {- }+ vectorBitSize = VectorizationProvider.TESTS_VECTOR_SIZE.orElse(vectorBitSize);INT_SPECIES = VectorSpecies.of(int.class, VectorShape.forBitSize(vectorBitSize));VECTOR_BITSIZE = INT_SPECIES.vectorBitSize();FLOAT_SPECIES = INT_SPECIES.withLanes(float.class);@@ -76,15 +73,8 @@ final class PanamaVectorUtilSupport implements VectorUtilSupport {// hotspot misses some SSE intrinsics, workaround it// to be fair, they do document this thing only works well with AVX2/AVX3 and Neonboolean isAMD64withoutAVX2 = Constants.OS_ARCH.equals("amd64") && VECTOR_BITSIZE < 256;- boolean hasFastIntegerVectors = isAMD64withoutAVX2 == false;- try {- hasFastIntegerVectors =- Boolean.parseBoolean(- System.getProperty(- "tests.forceintegervectors", Boolean.toString(hasFastIntegerVectors)));- } catch (SecurityException ignored) {- }- HAS_FAST_INTEGER_VECTORS = hasFastIntegerVectors;+ HAS_FAST_INTEGER_VECTORS =+ VectorizationProvider.TESTS_FORCE_INTEGER_VECTORS || (isAMD64withoutAVX2 == false);}@Override