GraalVM的资料

  • 官网

    An advanced JDK with ahead-of-time Native Image compilation.

  • 代码社区

  • 下载主页

  • 文档主页

    GraalVM compiles your Java applications ahead of time into standalone binaries. These binaries are smaller, start up to 100x faster, provide peak performance with no warmup, and use less memory and CPU than applications running on a Java Virtual Machine (JVM).

    在编译期,将字节码转换为机器码。

    GraalVM reduces the attack surface of your application. It excludes unused classes, methods, and fields from the application binary. It restricts reflection and other dynamic Java language features to build time only. It does not load any unknown code at run time.

    在编译器,裁剪、消除掉应用程序在运行时不需要、不使用、不加载的类和代码,减少目标应用程序的大小。类似gcc/clang提供的编译选项-ffunction-sections -fdata-sections -Wl,-gc-sections

  • GraalVM Documentation

Getting Started

  • Getting Started

    GraalVM compiles your Java applications ahead of time into standalone binaries that start instantly, provide peak performance with no warmup, and use fewer resources.

Native Image

  • Native Image

    创建验证项目,执行如下命令:

     mvn archetype:generate -DgroupId=com.example -DartifactId=helloworld -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
    

    构建可执行的jar,修改项目的pom.xml,增加如下配置:

    <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.3.0</version>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>com.example.App</mainClass>
                            <addClasspath>true</addClasspath>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </build>
    

    使用graalvm转换为本地代码,修改pom.xml,增加如下配置:

    <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>
                </execution>
                <execution>
                <id>test-native</id>
                  <goals>
                    <goal>test</goal>
                  </goals>
                  <phase>test</phase>
                </execution>
              </executions>
            </plugin>
          </plugins>
        </build>
      </profile>
    </profiles>
    

    启动构建,执行如下命令:

    mvn -Pnative package
    
  • User Guides

  • Native Image Basics

Build
  • Build Overview
    native-image的常见命令行样例。

  • Build Output
    执行native-image构建时,命令行的输出信息。

  • Build Configuration
    在jar中增加native-image的配置文件,用于指示构建选项,配置文件的位置,样例如下:

    META-INF/
    └── native-image
        └── groupID
            └── artifactID
                └── native-image.properties
    

    groupID/artifactID如何确定?
    通过学习官方提供的样例,快速上手native-image的使用方法。

  • Bundles
    对于使用maven管理、构建的项目,修改项目的pom.xml,增加如下配置:

    <plugin>
      <groupId>org.graalvm.buildtools</groupId>
      <artifactId>native-maven-plugin</artifactId>
      <configuration>
          <buildArgs combine.children="append">
              <buildArg>--bundle-create</buildArg>
          </buildArgs>
      </configuration>
    </plugin>
    

    构建软件时,执行如下命令:

    ./mvnw package -Dpackaging=native-image
    
  • Command-line Options
    native-image的选项。

Reachability Metadata
Optimizations and Performance
Debugging and Diagnostics
Dynamic Features
Interoperability with Native Code

Reference Manuals

Java and JVM
Java on Truffle
  • 62
    点赞
  • 48
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小南家的青蛙

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值