我有一个通过 ScriptEngine 使用 JavaScript 脚本的 Spring 应用程序(由 graalvm 提供的引擎 https://docs.oracle.com/en/graalvm/enterprise/20/docs/reference-manual/js/ScriptEngine/)。我正在考虑使用 JVMCI 启用 Graal JIT 编译器,但我不确定这将如何影响我的应用程序的性能以及它是否专门用于 ScriptEngine 还是影响整个应用程序。
我如何添加 Graal JIT 编译器
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>copy</id>
<phase>process-test-classes</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.graalvm.compiler</groupId>
<artifactId>compiler</artifactId>
<version>${graalvm.version}</version>
<type>jar</type>
<overWrite>true</overWrite>
<destFileName>compiler.jar</destFileName>
</artifactItem>
<artifactItem>
<groupId>org.graalvm.compiler</groupId>
<artifactId>compiler-management</artifactId>
<version>${graalvm.version}</version>
<type>jar</type>
<overWrite>true</overWrite>
<destFileName>compiler-management.jar</destFileName>
</artifactItem>
<artifactItem>
<groupId>org.graalvm.truffle</groupId>
<artifactId>truffle-api</artifactId>
<version>${graalvm.version}</version>
<type>jar</type>
<overWrite>true</overWrite>
<destFileName>truffle-api.jar</destFileName>
</artifactItem>
<artifactItem>
<groupId>org.graalvm.sdk</groupId>
<artifactId>graal-sdk</artifactId>
<version>${graalvm.version}</version>
<type>jar</type>
<overWrite>true</overWrite>
<destFileName>graal-sdk.jar</destFileName>
</artifactItem>
</artifactItems>
<outputDirectory>${compiler.dir}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<configuration>
<arguments>
<argument>--module-path</argument>
<!-- automatically creates the modulepath using all project dependencies, also adding the project build directory -->
<modulepath/>
<argument>-classpath</argument>
<!-- automatically creates the classpath using all project dependencies, also adding the project build directory -->
<classpath/>
<argument>-XX:+UnlockExperimentalVMOptions</argument>
<argument>-XX:+EnableJVMCI</argument>
<argument>-XX:-UseJVMCICompiler</argument>
<argument>--upgrade-module-path=${compiler.dir}/compiler.jar${path.separator}${compiler.dir}/compiler-management.jar</argument>
<argument>org.benchmark.demo.Main</argument>
</arguments>
</configuration>
我主要关心的是:
如果我通过 JVMCI 为 Graal 启用 JIT 编译器,它会专门增强 ScriptEngine 的性能,还是会对整个应用程序的执行产生更广泛的影响?
通过 JVMCI 的 Graal JIT 编译器是否被认为是 JVM 生态系统中的顶级选择?
此外,我想使用 Graal JIT 优化 ScriptEngine 的性能,而不影响应用程序的其他组件。有什么策略或建议来实现这一目标吗?
使用 Graal JIT 执行此代码不会给您带来性能损失,而是相反。您应该确保您确实正在执行 JIT 编译的代码,而不仅仅是解释,这会慢得多。
我们一般建议使用 GraalVM JDK,这将为您提供最佳性能和预热。如果由于某种原因您不想使用 Graal JIT,您可以随时使用
-XX:-UseJVMCICompiler
禁用它,这可以有效地为您提供 OpenJDK 设置。
随着我们在下一个版本中所做的更改,您的用例应该变得更简单,该版本将于下周发布。