Skip to content

Commit f54ae8b

Browse files
Only check LongVector.SPECIES_PREFERRED when jdk.incubator.vector is enabled (#11939) (#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>
1 parent 0d12779 commit f54ae8b

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

libs/common/src/main/java20/org/opensearch/common/round/RoundableFactory.java

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
import org.opensearch.common.annotation.InternalApi;
1212

13-
import jdk.incubator.vector.LongVector;
14-
1513
/**
1614
* Factory class to create and return the fastest implementation of {@link Roundable}.
1715
*
@@ -34,10 +32,30 @@ public final class RoundableFactory {
3432
*/
3533
private static final boolean USE_BTREE_SEARCHER;
3634

35+
/**
36+
* This class is initialized only when:
37+
* - JDK-20+
38+
* - jdk.incubator.vector.LongVector is available (--add-modules=jdk.incubator.vector is passed)
39+
*/
40+
private static final class VectorCheck {
41+
final static int SPECIES_PREFERRED = jdk.incubator.vector.LongVector.SPECIES_PREFERRED.length();
42+
}
43+
3744
static {
3845
String simdRoundingFeatureFlag = System.getProperty("opensearch.experimental.feature.simd.rounding.enabled");
39-
USE_BTREE_SEARCHER = "forced".equalsIgnoreCase(simdRoundingFeatureFlag)
40-
|| (LongVector.SPECIES_PREFERRED.length() >= 4 && "true".equalsIgnoreCase(simdRoundingFeatureFlag));
46+
boolean useBtreeSearcher = false;
47+
48+
try {
49+
final Class<?> incubator = Class.forName("jdk.incubator.vector.LongVector");
50+
51+
useBtreeSearcher = "forced".equalsIgnoreCase(simdRoundingFeatureFlag)
52+
|| (VectorCheck.SPECIES_PREFERRED >= 4 && "true".equalsIgnoreCase(simdRoundingFeatureFlag));
53+
54+
} catch (final ClassNotFoundException ex) {
55+
/* do not use BtreeSearcher */
56+
}
57+
58+
USE_BTREE_SEARCHER = useBtreeSearcher;
4159
}
4260

4361
private RoundableFactory() {}

0 commit comments

Comments
 (0)