Search code examples
javajvmcompiler-optimizationjitgraalvm

JVMCI JIT Compiler (Graal Compiler)


I have a Spring application that utilizes JavaScript scripts through ScriptEngine (the engine provided by graalvm https://docs.oracle.com/en/graalvm/enterprise/20/docs/reference-manual/js/ScriptEngine/). I am considering enabling the Graal JIT compiler using JVMCI, but I'm unsure about how this would impact my application's performance and whether it would be used exclusively for ScriptEngine or influence the entire application.

how I added the Graal JIT Compiler

<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>

My primary concerns are:

  1. If I enable the JIT compiler for Graal via JVMCI, will it exclusively enhance the performance of the ScriptEngine, or will it have broader implications on the entire application's execution?

  2. Is the Graal JIT compiler through JVMCI considered a top-tier choice within the JVM ecosystem?

Additionally, I would like to optimize the ScriptEngine's performance with Graal JIT without affecting other components of the application. Are there any strategies or suggestions for achieving this?


Solution

  • Using Graal JIT to execute this code should not give you performance penalties, rather the opposite. You should just make sure you are indeed executing this code JIT compiled and not just interpreted, which would be much slower.

    Our general recommendation is to use the GraalVM JDK, which will give you the best performance and warmup. If for some reason you don’t want to use Graal JIT, you can always disable it with -XX:-UseJVMCICompiler which effectively gives you an OpenJDK setup.

    Your use case should become simpler with the changes we are making in the next release, it will be released next week.