Skip to content

Commit

Permalink
Only check LongVector.SPECIES_PREFERRED when jdk.incubator.vector is …
Browse files Browse the repository at this point in the history
…enabled (opensearch-project#11939) (opensearch-project#11943)

(cherry picked from commit 774e7d4)

Signed-off-by: Andriy Redko <andriy.redko@aiven.io>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
1 parent 0d12779 commit f54ae8b
Showing 1 changed file with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

import org.opensearch.common.annotation.InternalApi;

import jdk.incubator.vector.LongVector;

/**
* Factory class to create and return the fastest implementation of {@link Roundable}.
*
Expand All @@ -34,10 +32,30 @@ public final class RoundableFactory {
*/
private static final boolean USE_BTREE_SEARCHER;

/**
* This class is initialized only when:
* - JDK-20+
* - jdk.incubator.vector.LongVector is available (--add-modules=jdk.incubator.vector is passed)
*/
private static final class VectorCheck {
final static int SPECIES_PREFERRED = jdk.incubator.vector.LongVector.SPECIES_PREFERRED.length();
}

static {
String simdRoundingFeatureFlag = System.getProperty("opensearch.experimental.feature.simd.rounding.enabled");
USE_BTREE_SEARCHER = "forced".equalsIgnoreCase(simdRoundingFeatureFlag)
|| (LongVector.SPECIES_PREFERRED.length() >= 4 && "true".equalsIgnoreCase(simdRoundingFeatureFlag));
boolean useBtreeSearcher = false;

try {
final Class<?> incubator = Class.forName("jdk.incubator.vector.LongVector");

useBtreeSearcher = "forced".equalsIgnoreCase(simdRoundingFeatureFlag)
|| (VectorCheck.SPECIES_PREFERRED >= 4 && "true".equalsIgnoreCase(simdRoundingFeatureFlag));

} catch (final ClassNotFoundException ex) {
/* do not use BtreeSearcher */
}

USE_BTREE_SEARCHER = useBtreeSearcher;
}

private RoundableFactory() {}
Expand Down

0 comments on commit f54ae8b

Please sign in to comment.