41.5 Build Integration and Compatibility

Enable the Vector API module and configure builds for portability.


41.5.1 Module Enablement

Depending on JDK release, the API may be provided as an incubator module:

  • javac --add-modules jdk.incubator.vector ...
  • java --add-modules jdk.incubator.vector ...

Check your JDK docs for whether preview or incubator flags are required.


41.5.2 Gradle Configuration (Example)

tasks.withType(JavaCompile).configureEach {
  options.compilerArgs += ['--add-modules', 'jdk.incubator.vector']
}

tasks.withType(JavaExec).configureEach {
  jvmArgs += ['--add-modules', 'jdk.incubator.vector']
}

41.5.3 Maven Configuration (Example)

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin</artifactId>
  <version>3.11.0</version>
  <configuration>
    <compilerArgs>
      <arg>--add-modules</arg>
      <arg>jdk.incubator.vector</arg>
    </compilerArgs>
  </configuration>
</plugin>

For runtime, configure surefire/failsafe or exec plugins similarly.


41.5.4 Cross‑Architecture Notes

  • Species choose lane width based on platform (e.g., AVX2 vs NEON)
  • Prefer SPECIES_PREFERRED to adapt automatically
  • Validate on target hardware; performance varies with instruction set

41.5.5 Feature Detection

Use species queries to adapt at runtime:

var lanes = FloatVector.SPECIES_PREFERRED.length();
if (lanes >= 8) {
  // use wider path
} else {
  // narrower path
}

Fallback to scalar implementation when necessary.