You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by rm...@apache.org on 2023/10/15 12:49:56 UTC
[lucene] 02/03: Move testing properties to provider class (no classloading deadlock possible) and fallback to default provider in non-test mode
This is an automated email from the ASF dual-hosted git repository.
rmuir pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/lucene.git
commit c8852a012faf0c2e522134a22f4c94d7cc76ee5d
Author: Uwe Schindler <us...@apache.org>
AuthorDate: Sun Oct 15 14:33:43 2023 +0200
Move testing properties to provider class (no classloading deadlock possible) and fallback to default provider in non-test mode
---
.../vectorization/VectorizationProvider.java | 47 ++++++++++++++++++++--
.../vectorization/PanamaVectorUtilSupport.java | 16 ++------
2 files changed, 46 insertions(+), 17 deletions(-)
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 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 we
diff --git a/lucene/core/src/java20/org/apache/lucene/internal/vectorization/PanamaVectorUtilSupport.java b/lucene/core/src/java20/org/apache/lucene/internal/vectorization/PanamaVectorUtilSupport.java
index 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 bitsize
int 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 Neon
boolean 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