Slide 1

Slide 1 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. Another compilation method in Java AOT (Ahead of Time) Compilation Akihiro Nishikawa Oracle Corporation Japan 1

Slide 2

Slide 2 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. Safe Harbor Statement The following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle. 2

Slide 3

Slide 3 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. Agenda JIT (Just-in-Time) Compilation AOT (Ahead-of-Time) Compilation Limitations Summary 1 2 3 4 3

Slide 4

Slide 4 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 4 In this session, I mainly cover HotSpot.

Slide 5

Slide 5 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 5 JIT (Just in Time) Compilation Source Code (*.java) javac Class file (*.class) HotSpot Compile

Slide 6

Slide 6 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 6 For improvement of warm up time Tiered compilation C1 (-client/client use) C2 (-server/server use) • Longer compilation time and longer startup time, but generated code runs faster. • Heavy optimization • In case of prioritizing performance after invocation... • Shorter compilation time and shorter startup time, but generated code runs slow. • Less optimization • In case of prioritizing startup time...

Slide 7

Slide 7 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 7 Compilation Level • 4: C2 • 0: Interpreter C2 Interpreter C1 • 1: C1 full optimization (no profiling) • 2: C1 with profiling about invocation and back-edge only • 3: C1 full profiling (level2 + MDO) 1,500 10,000

Slide 8

Slide 8 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. AOT – Ahead Of Time compilation • Generate native code in advance • JEP 295 • Based on Graal 8

Slide 9

Slide 9 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 9 AOT Compilation Source Code (*.java) javac Class file (*.class) HotSpot jaotc Shared object file (*.so)

Slide 10

Slide 10 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 10 *.java javac *.class HotSpot jaotc *.so javac Compile

Slide 11

Slide 11 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. *.so 11 Able to share “*.so” file among JVMs HotSpot HotSpot HotSpot HotSpot

Slide 12

Slide 12 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 12 AOT looks like CDS/AppCDS… !

Slide 13

Slide 13 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. CDS/AppCDS (Class Data Sharing) • CDS is the scheme for sharing Java SE class library only. • In case of AppCDS, application classes are also included. 13 Class Data classes.jsa HotSpot HotSpot HotSpot HotSpot

Slide 14

Slide 14 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. Works for... • Quicker warmup • Lower total memory footprint Does not work for... • No feature to persist or share machine (native) code. 14 CDS/AppCDS

Slide 15

Slide 15 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 15 Is AOT a new compilation method ? !

Slide 16

Slide 16 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 16 $ gcc -o HelloAoT HelloAoT.c In case of C...

Slide 17

Slide 17 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 17 How about other Java implementations? !

Slide 18

Slide 18 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. AOT Java Compilers • IBM Java SDK for AIX • IBM Java SDK for z/OS • Oracle Java ME Embedded Client • WebSphere Real Time • Gluon VM etc. 18

Slide 19

Slide 19 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 19 Does AOT support tiered compilation (C1/C2)? !

Slide 20

Slide 20 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. AOT Supports Tiered Compilation • Non-tiered compilation mode (default) –Similar to C1 in Client VM –No collecting profiling information –No JIT recompilation if AOT code is not deoptimized. • Tied compilation mode (--compile-for-tiered) –Profiling level is as same as C1 Level 2. –If hitting AOT invocation thresholds, methods are recompiled by C1 at Level 3 first for gathering full profiling information. 20

Slide 21

Slide 21 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 21 What does AOT work for? !

Slide 22

Slide 22 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. Benefits might be gained from AOT... • No compilation overhead at runtime. • Improve startup time and able to achieve peak performance faster. • Able to run on the platform where native code cannot be not generated at runtime (e.g. iOS, embedded). • Density improvement - Able to share native code. 22

Slide 23

Slide 23 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 23 $ jaotc --output libHelloAOT.so HelloAOT.class $ jaotc --output libjava.base.so --module java.base $ jaotc --output libmyapp.so --jar myapp.jar $ jaotc -J-XX:+UseCompressedOops --output libHelloAOT.so HelloAOT.class How to use jaotc

Slide 24

Slide 24 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. jaotc does not resolve all referenced classes • jaotc does not resolve referenced classes which are not system classes or part of compiled classes. 1. Have to add referenced classes to class path. 2. Specify additional java modules 24 jaotc --output=libfoo.so --jar foo.jar ¥ -J-cp -J./ jaotc --output=libactivation.so --module ¥ java.activation -J--add-module=java.se.ee

Slide 25

Slide 25 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 25 $ java -XX:AOTLibrary=./libHelloAOT.so HelloAOT Hello AOT! $ java -XX:+PrintAOT ¥ -XX:AOTLibrary=./libHelloAoT.so HelloAoT 13 1 loaded ./libHelloAoT.so aot library 76 1 aot[ 1] HelloAoT.()V 76 2 aot[ 1] HelloAoT.main([Ljava/lang/String;)V Hello AOT! Run AOT compiled code

Slide 26

Slide 26 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. On JVM startup... • AOT initialization code looks for well-known AOT libraries in well- known location ($JAVA_HOME/lib) or libraries specified using -XX:AOTLibrary. • JVM knows AOT library name for the following Java modules. –java.base –jdk.compiler (javac) –jdk.scripting.nashorn (Nashorn) –jdk.internal.vm.ci (JVMCI) –jdk.internal.vm.compiler (Graal) 26

Slide 27

Slide 27 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. VM Options should be synchronized. • libjava.base.so -XX:-UseCompressedOops -XX:+UseG1GC • libjava.base-coop.so -XX:+UseCompressedOops -XX:+UseG1GC • libjava.base-nong1.so -XX:-UseCompressedOops -XX:+UseParallelGC • libjava.base-coop-nong1.so -XX:+UseCompressedOops -XX:+UseParallelGC 27

Slide 28

Slide 28 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 28

Slide 29

Slide 29 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. Limitations • Experimental release • No support • No official document (except for JEP) 29 First of all...

Slide 30

Slide 30 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. Limitations • Available only when using either Parallel or G1 GC on Linux x64 with libelf.so. • AOT compilation must be executed on the same system or a system with the same configuration on which AOT code will be used by Java application. • Unable to compile java code using dynamically generated classes and bytecode (lambda expressions, InvokeDynamic) 30 These limitations are in Java 9, and may be addressed in future releases.

Slide 31

Slide 31 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. When and where to use AOT? • Event-driven services such as Functions • Embedded, IoT, mobile • Not often invoked classes... (not hot code) • Application code which should be protected from decompilers ...etc. 31 If AOT is officially supported and is available on several platforms...

Slide 32

Slide 32 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. Summary • Since Java 9 (HotSpot), AOT compilation is available, but positioned as experimental release and no official support. • AOT have several characteristics and is expected to improve performance of applications, especially such short-lived objects as functions • Working to remove current limitation and improve AOT. 32

Slide 33

Slide 33 text

Copyright © 2017, Oracle and/or its affiliates. All rights reserved. Safe Harbor Statement The preceding is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle. 33

Slide 34

Slide 34 text

No content