4.1.8. GraalVM

GraalVM 是一个高性能的虚拟机,它使用 LLVM 作为其即时编译器,并且支持多种编程语言,包括 Java、JavaScript、Python 等。

GraalVM 的主要特点包括:

  1. 即时编译:GraalVM 使用 LLVM 作为其即时编译器,可以显著提高程序的执行效率。

  2. 多语言支持:GraalVM 支持多种编程语言,包括 Java、JavaScript、Python 等。

  3. 高性能:GraalVM 的即时编译器可以显著提高程序的执行效率,并且支持多种编程语言。

官方文档链接:https://www.graalvm.org/latest/docs/

4.1.8.1. GraalVM 的安装

4.1.8.2. Native Image

4.1.8.2.1. 构建共享库

https://www.graalvm.org/latest/reference-manual/native-image/guides/build-native-shared-library/

4.1.8.2.2. native-maven-plugin

https://graalvm.github.io/native-build-tools/latest/maven-plugin.html

<properties>
    <native.maven.plugin.version>0.10.6</native.maven.plugin.version>
</properties>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.12.1</version>
            <configuration>
                <fork>true</fork>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>3.4.2</version>
        </plugin>
    </plugins>
</build>

<profiles>
    <profile>
        <id>native</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.graalvm.buildtools</groupId>
                    <artifactId>native-maven-plugin</artifactId>
                    <version>${native.maven.plugin.version}</version>
                    <extensions>true</extensions>
                    <executions>
                        <execution>
                            <id>build-native</id>
                            <goals>
                                <goal>compile-no-fork</goal>
                            </goals>
                            <phase>package</phase>
                            <configuration>
                                <imageName>libfwdj-${project.version}</imageName> <!-- 构建动态链接库的名字,注意格式,必须以lib开头。 -->
                                <sharedLibrary>true</sharedLibrary> <!-- 构建共享库 -->
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>
# 特别注意,一定要用graalvm的jdk。其他jdk不支持native-image的方式构建。
mvn -Dnative clean package