Java 9中是否提供提前编译? [英] Is Ahead-Of-Time compilation available in Java 9?

查看:136
本文介绍了Java 9中是否提供提前编译?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据 JEP 295

任何JDK模块,类或用户代码的AOT编译都是实验性的,JDK 9不支持.

AOT compilation of any JDK modules, classes, or of user code, is experimental and not supported in JDK 9.

要使用AOTed java.base模块,用户必须编译该模块并将生成的AOT库复制到JDK安装目录中,或在java命令行上指定它.

To use the AOTed java.base module, the user will have to compile the module and copy the resulting AOT library into the JDK installation directory or specify it on java command line.

我对以上声明感到困惑,如果JDK 9不支持AOT,那么我们如何使用AOT编译模块?

I am confused with the above statement, if AOT is not supported in JDK 9 then how can we compile the module using AOT?

我的第二个问题是,如果JOT 9中有很多

My second question is why AOT not supported in JDK 9 if it has many advantages over JIT?

推荐答案

它是一项实验功能.

首先从问题中回答后一部分.就与Java 9 API的兼容性而言,AOT尚未完全成熟.链接的JEP中也列出了一些限制:

To answer the latter part first from your question. AOT is not fully fledged in terms of compatibility with Java 9 APIs. Some of its restrictions also listed in the linked JEP are:

  • 它仍然仅限于基于64位Linux的系统.

  • It's still restricted to 64 bit Linux based systems.

要使用AOT编译,用户需要使用相同的JDK进行编译和执行.有关用于编译的jaotc的版本信息被添加为库的一部分,并在加载期间进行检查.如果Java运行时已更新,则需要在执行AOT编译模块之前重新编译它们.用于编译和执行的JDK版本不匹配可能导致应用程序崩溃.

To use AOT compilation, users need to use the same JDK for compilation and execution. Version information about jaotc used for compilation is added as a part of the libraries and are checked during load time. If the Java runtime is updated, you need to recompile the AOT compiled modules before executing them. Mismatch in JDK versions used for compilation and execution may result in application crashes.

Lambda表达式和其他复杂的Java概念,这些概念在运行时使用动态生成的类.

Lambda expressions and other complex concepts of Java, which uses dynamically generated classes at runtime are not currently supported by AOT compiler.

要生成共享对象(.so)文件,系统需要预安装libelf.

To generate shared object (.so) files, the system needs libelf to be pre-installed.

java.base的逻辑编译模式是AOT分层,因为需要对java.base方法进行JIT重新编译以达到最佳性能.仅在某些情况下,无级AOT编译才有意义.当占用空间比峰值性能更重要时,或者在不允许动态代码生成的系统中,这包括需要可预测行为的应用程序.在这种情况下,需要在整个应用程序上进行AOT编译,因此在JDK 9中是试验性的.

The logical compilation mode for java.base is tiered AOT since JIT recompilation of java.base methods is desired to reach peak performance. Only in certain scenarios does a non-tiered AOT compilation make sense. This includes applications which require predictable behavior, when footprint is more important than peak performance, or for systems where dynamic code generation is not allowed. In these cases, AOT compilation needs to be done on the entire application and is thus experimental in JDK 9.

这些限制可以在将来的版本中解决,也就是当我非常确定将删除该功能中的实验"标记时.

These limitations can be addressed in future releases and that is when I am pretty sure the Experimental tag from the feature would be removed.

如果JDK 9不支持AOT,那么我们如何使用AOT编译模块?

要使用AOT,需要使用jaotc编译器来编译应用程序代码,而上面列出的限制很少.如提前编译:AOT使用情况(如果已使用AOT库进行了编译)该工具为:

To make use of the AOT, the application code needs to be compiled using jaotc compiler considering few of the restrictions as listed above. As stated in Ahead-of-Time Compilation: AOT Usage if an AOT library has been compiled using the tool as:

jaotc --output libHelloWorld.so HelloWorld.class

它可以在执行阶段使用

java -XX:AOTLibrary=./libHelloWorld.so HelloWorld

在编译时和运行时都使用提供的相同发行版JVM配置.

provided same release JVM configurations are used during both compile time and runtime.

使用上述命令触发执行后,默认打开会使用AOT编译文件.为了切换是否使用这些文件,引入了一个新的参数,该参数可以在执行阶段使用.即-

Once the execution is triggered using the above command, the use of AOT compiled files in by default ON. To toggle whether or not making use of those files a new argument has been introduced that can be used in the execution phase. i.e -

-XX:+/-UseAOT    


更重要的是要与您的上述两个问题以及建议的风险和假设部分中明确提到的问题相关联:


More importantly to relate to both of your questions above and even as clearly mentioned in Risks and Assumption section of the proposal:

如果用户发现应用程序启动速度较慢,或者未达到预期的峰值性能或崩溃,则只需切换 使用-XX:-UseAOT标志关闭AOT,或删除所有AOT库.

If a user finds that an application starts up more slowly, or doesn't reach the expected peak performance, or crash, they can just switch AOT off with the -XX:-UseAOT flag, or remove any AOT libraries.

这篇关于Java 9中是否提供提前编译?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆