As covered in the article “ What the JIT!? Anatomy of the OpenJDK HotSpot VM”, HotSpot’s execution engine has a Just-in-Time (JIT) compiler. In order to improve startup times, the tiered compilation starts interpreting the code and then quickly moves to tiers 1, 2, or 3 where the methods are compiled at the client compilation level (but with different profiling information) and then finally moves to the server compilation level. (For more information on this please refer the above article). But even with the improvements in the compilation levels, HotSpot still starts interpreting its bytecode and then moves on to JIT-ting it.
您需要 登录 才可以下载或查看，没有帐号？立即注册
This September, a proposalwas submitted to add Ahead-of-Time (AOT) compilation to HotSpot. AOT helps with improving the startup time by loading pre-compiled classes. This helps avoid running those classes in the interpretated mode or at a sub-optimized compilation level.
AOT compilation is not new to dynamic compilers; IBM’s J9 VM supports AOT, so does Excelsior JETand others. AOT has helped many dynamic compilers achieve better startup/warmup times by using (shared) libraries that have already been compiled to native code.
Similar to the JIT compiler, the AOT compilation proposed in the JEP will have a tiered and a non-tiered mode. The difference being in the collection of profiling information and JIT recompilation. As mentioned in thearticle, with tiered compilation, simple profiling information is gathered at tier 2 – the same goes for tiered AOT compiled code. And when the AOT invocation thresholds are crossed, those methods get recompiled by the client compiler at tier 3, so that full profiling information can be captured for the server recompilation that will happen at tier 4.
The proposal as laid by Valdimir Kozlov, lead of the HotSpot compiler team, mentions that for the first release, only java.basemodule will be supported as tiered AOT, since the base module is well known and can help with thorough internal testing.
AOT brings about a new tool called ‘jaotc'which uses Graalas the backend (to generate code). The Graal dynamic compiler integrates with the HotSpot VM and depends on the JVM Compiler Interface (JVMCI), hence the JDK (that supports Graal or AOT) should also support JVMCI. There are some JVMCI enabled builds available on the Oracle technetwork site.
According to the proposal, the jaotctool supports various flags:
Also, the JVM product will have the following flags: 复制代码
- --module <name> Module to compile
- --output <file> Output file name
- --compile-commands <file> Name of file with compile commands
- --compile-for-tiered Generated profiling code for tiered compilation
- --classpath <path> Specify where to find user class files
- --threads <number> Number of compilation threads to be used
- --ignore-errors Ignores all exceptions thrown during class loading
- --exit-on-error Exit on compilation errors
- --info Print information during compilation
- --verbose Print verbose information
- --debug Print debug information
- --help Print this usage message
- --version Version information
- -J<flag> Pass <flag> directly to the runtime system
A few notproduct/develop flags will also be made available for users: 复制代码
- +/-UseAOT - Use AOT-compiled files
- +/-PrintAOT - Print used AOT klasses and methods
- AOTLibrary=<file> - Specify the AOT library file
The proposal also states that the logging of AOT runtime events will be integrated with the unified GC loggingand the following tags will be supported: 复制代码
- PrintAOTStatistics - Print AOT statistics
- UseAOTStrictLoading - Exit the VM if any of the AOT libraries has invalid config
No proposal is complete without listing the risks and assumptions made, and the risk with the AOT proposal is highlighted as follows: 复制代码
It’s possible that the use of pre-compiled code could result in less-than-optimal code being used, resulting in a loss of performance. Performance testing shows that some applications benefit from AOT-compiled code while others clearly show regressions. Since the AOT feature is an opt-in feature, possible performance regressions with user applications are avoidable. If a user finds that an application starts up more slowly, or doesn't reach the expected peak performance, they can just rebuild a new JDK without AOT libraries.
上一篇：Zsh vs Bash
下一篇：IDG Contributor Network: Best practices in .Net asynchronous programming