File tree Expand file tree Collapse file tree 1 file changed +22
-4
lines changed
libs/common/src/main/java20/org/opensearch/common/round Expand file tree Collapse file tree 1 file changed +22
-4
lines changed Original file line number Diff line number Diff line change 10
10
11
11
import org .opensearch .common .annotation .InternalApi ;
12
12
13
- import jdk .incubator .vector .LongVector ;
14
-
15
13
/**
16
14
* Factory class to create and return the fastest implementation of {@link Roundable}.
17
15
*
@@ -34,10 +32,30 @@ public final class RoundableFactory {
34
32
*/
35
33
private static final boolean USE_BTREE_SEARCHER ;
36
34
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
+
37
44
static {
38
45
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 ;
41
59
}
42
60
43
61
private RoundableFactory () {}
You can’t perform that action at this time.
0 commit comments