SlideShare a Scribd company logo
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Ahead-of-Time Compilation with JDK 9
日本オラクル株式会社
Java SE Sustaining Engineering
バック デイビッド
Java Day Tokyo 2017
2017年5月17日
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
2
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.
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
3
• JVM Sustaining Engineer
• OpenJDK 8 Update Project
Maintainer
• JavaOne Rock Star
• Co-author of Oracle WebLogic
Server 11g 構築・運用ガイド
• @DavidBuckJP
• https://blogs.oracle.com/buck/
Hi There!
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
4
Program Agenda
注意点
AoT のいろは
似ている機能
使い方
1
2
3
4
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
5
注意点
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
6
要注意
• AoT は実験的なものであり、正式にはサポートされていない
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
7
要注意
• AoT は実験的なものであり、正式にはサポートされていない
• 現時点では、AMD64 の Linux しかサポートされていない
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
8
要注意
• AoT は実験的なものであり、正式にはサポートされていない
• 現時点では、AMD64 の Linux しかサポートされていない
• 正式なドキュメントはない(JEP のみ)
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
9
要注意
• AoT は実験的なものであり、正式にはサポートされていない
• 現時点では、AMD64 の Linux しかサポートされていない
• 正式なドキュメントはない(JEP のみ)
• 現時点では、将来的にサポートされる予定はない
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
10
AoT のいろは
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
11
AoT を勉強する価値
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
12
AoT を勉強する価値
• 将来にサポートされるようになる可能性がある
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
13
AoT を勉強する価値
• 将来にサポートされるようになる可能性がある
• HotSpot の他の機能を勉強するきっかけである
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
14
AoT を勉強する価値
• 将来にサポートされるようになる可能性がある
• HotSpot の他の機能を勉強するきっかけである
• やはり、面白い!
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
15
Java Build / Execution Model (Interpreter)
MyClass.java MyClass.class java
(HotSpot)
javac
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
16
Java Build / Execution Model (JIT)
MyClass.java MyClass.class java
(HotSpot)
javac
マシン語
(メモリ上)
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
17
Just in Time Compilation (JIT)
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
18
Just in Time Compilation (JIT)
• メソッドがコンパイルされる
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
19
Just in Time Compilation (JIT)
• メソッドがコンパイルされる
• コンパイル処理は重い
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
20
Just in Time Compilation (JIT)
• メソッドがコンパイルされる
• コンパイル処理は重い
• マシン語のバージョンは早い
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
21
Just in Time Compilation (JIT)
• メソッドがコンパイルされる
• コンパイル処理は重い
• マシン語のバージョンは早い
• パフォーマンスは interpreter よりいい?
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
22
Just in Time Compilation (JIT)
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
23
Just in Time Compilation (JIT)
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
24
Just in Time Compilation (JIT)
パフォーマンスは interpreter よりいい?
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
25
Just in Time Compilation (JIT)
パフォーマンスは interpreter よりいい?
パフォーマンスの定義次第
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
26
$ time ./hello_jdt
Hello JavaDay Tokyo!
real 0m0.002s
user 0m0.001s
$ time java HelloJDT
Hello JavaDay Tokyo!
real 0m0.104s
user 0m0.077s
sys 0m0.020s
Just in Time Compilation (JIT)
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
27
Just in Time Compilation (JIT)
弱点
• コンパイル処理が重い
– メソッドを実行出来るようになるまで時間かかる
– メモリの使用量が大きい
• Hot ではないメソッドの場合、interpreter のほうが適切
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
28
Just in Time Compilation (JIT)
(HotSpot の実装)
• まず、 すべてのメソッドは interpreter のみで実行
• サンプリングで Hot なメソッドを検出
• Hot のメソッドだけをコンパイル
• Hot ではないメソッドは interpreter で実行
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
29
HotSpot のJIT でも
• アプリの起動が時間がかかる
• 起動しても、最高のパフォーマンスまで時間がかかる
• コンパイル処理がメモリを消費する
• 実行時にマシン語を生成出来ないプラットフォームもある
ネイティブ(C/C++ などと比べると)
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
30
Just in Time Compilation (JIT) (HotSpot の実装)
2コンパイラ物語
• C2
– Server 用
– 最適化を頑張る
– Interpreter が収集するプロファイリングデータを参考する
– デフォルト CompileThreshold : 10000
• C1
– Client 用
– 最適化はあまりしない
– プロファイリングデータをあまり利用しない
– デフォルト CompileThreshold : 1500
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
31
Ahead of Time (AoT) の戦略
• 実行の前にマシン語を生成しておく
• 実行時に既存のマシン語をロードして実行する
• 実行時にマシン語を生成する必要はなくなる
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
32
Java Build / Execution Model (AoT)
MyClass.java MyClass.class java
(HotSpot)
javac
マシン語
(メモリ上)
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
33
Java Build / Execution Model (AoT)
MyClass.java MyClass.class java
(HotSpot)
javac
my_class.so
jaotc
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
34
Java Build / Execution Model
java
(HotSpot)
マシン語
(メモリ上)
java
(HotSpot)
マシン語
(メモリ上)
java
(HotSpot)
マシン語
(メモリ上)
java
(HotSpot)
マシン語
(メモリ上)
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
35
Java Build / Execution Model
java
(HotSpot)
java
(HotSpot)
java
(HotSpot)
java
(HotSpot)
my_class.so
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
36
Ahead of Time (AoT) の戦略
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
37
Ahead of Time (AoT) の戦略
• アプリの起動が早くなる ★
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
38
Ahead of Time (AoT) の戦略
• アプリの起動が早くなる ★
• peak performance / steady state まですぐ達成する ★
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
39
Ahead of Time (AoT) の戦略
• アプリの起動が早くなる ★
• peak performance / steady state まですぐ達成する ★
• コンパイルの負荷( CPU 使用 / メモリの消費)を減らす ★
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
40
Ahead of Time (AoT) の戦略
• アプリの起動が早くなる ★
• peak performance / steady state まですぐ達成する ★
• コンパイルの負荷( CPU 使用 / メモリの消費)を減らす ★
• 同じマシン語のデータを共有することが出来る ★
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
41
Ahead of Time (AoT) の戦略
• アプリの起動が早くなる ★
• peak performance / steady state まですぐ達成する ★
• コンパイルの負荷( CPU 使用 / メモリの消費)を減らす ★
• 同じマシン語のデータを共有することが出来る ★
• 実行時にマシン語を生成出来ないプラットフォームでも利用できる ★
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
42
Ahead of Time (AoT) の戦略
• アプリの起動が早くなる ★
• peak performance / steady state まですぐ達成する ★
• コンパイルの負荷( CPU 使用 / メモリの消費)を減らす ★
• 同じマシン語のデータを共有することが出来る ★
• 実行時にマシン語を生成出来ないプラットフォームでも利用できる ★
★ 場合がある
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
43
?
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
44
似ている機能
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
45
少し似ている技術
• Tiered Compilation
• Class Data Sharing(CDS) / AppCDS
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
46
Tiered Compilation
• 従来の server JVM
– インタプリタ(プロファイリング)
– C2
• Tiered Compilation
– インタプリタ(プロファイリング)
– プロファイリング付きの C1
– C2
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
47
No Class Data Sharing
java
(HotSpot)
クラスデータ
(メモリ上)
java
(HotSpot)
クラスデータ
(メモリ上)
java
(HotSpot)
クラスデータ
(メモリ上)
java
(HotSpot)
クラスデータ
(メモリ上)
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
48
Class Data Sharing
java
(HotSpot)
java
(HotSpot)
java
(HotSpot)
java
(HotSpot)
クラスデータ
classes.jsa
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
49
• Class Data Sharing
– Java SE のクラスライブラリ
• AppCDS
– アプリケーションのクラスも含む
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
50
AoT との共通点
• Tiered Compilation
– Warm up を早くしたい
• Class Data Sharing(CDS) / AppCDS
– Warm up を早くしたい
– メモリの使用量を減らしたい
AoT と異なる点
• マシン語を保存し、共用する機能
はない
少し似ている技術
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
51
Corporate Photography Collection
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
52
使い方
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
53
新しいツール: jaotc
MyClass.class my_class.sojaotc
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
54
$ jaotc --output libHelloAOT.so HelloAoT.class
jaotc
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
55
$ jaotc --help
Usage: jaotc <options> list
list A : separated list of class names, modules, jar files
or directories which contain class files.
where options include:
--output <file> Output file name
--class-name <class names> List of classes to compile
--jar <jarfiles> List of jar files to compile
--module <modules> List of modules to compile
--directory <dirs> List of directories where to search for files to compile
--search-path <dirs> List of directories where to search for specified files
--compile-commands <file> Name of file with compile commands
--compile-for-tiered Generate profiling code for tiered compilation
--compile-with-assertions Compile with java assertions
--compile-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
jaotc (on-line help)
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
56
$ jaotc --info --output libHelloAOT.so HelloAoT.class
Compiling libHelloAOT...
1 classes found (30 ms)
2 methods total, 2 methods to compile (4 ms)
Compiling with 8 threads
.
2 methods compiled, 0 methods failed (409 ms)
Parsing compiled code (1 ms)
Processing metadata (15 ms)
Preparing stubs binary (1 ms)
Preparing compiled binary (1 ms)
Creating binary: libHelloAOT.o (8 ms)
Creating shared library: libHelloAOT.so (13 ms)
Total time: 912 ms
jaotc (--info flag)
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
57
$ jaotc --info --compile-with-assertions --output libHelloAOT.so HelloAoT.class
jaotc (--compile-with-assertions flag)
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
58
$ jaotc --compile-commands cc.txt --output libHelloAOT.so HelloAoT.class
$ cat cc.txt
exclude org.sample.code.MyClass.method*
exclude org.sample.code.MyClass.<init>
jaotc (--compile-commands flag)
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
59
$ jaotc --output libjava.base.so --module java.base
jaotc (module)
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
60
$ jaotc --output libjava.base.so --jar my-spiffy-app.jar
jaotc (jar file)
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
61
$ jaotc -J-XX:-UseCompressedOop --output libHelloAOT.so HelloAoT.class
意外に大事なオプション!(後ほど説明を。。。)
jaotc (VM options)
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
62
$ java -XX:AOTLibrary=./libHelloAoT.so HelloAoT
実行時
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
63
$ java -XX:AOTLibrary=./libHelloAoT.so HelloAoT
Hello AoT!
$
実行時
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
64
$ java -XX:+PrintAOT -XX:AOTLibrary=./libHelloAoT.so HelloAoT
実行時 (-XX:+/-PrintAOT)
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
65
$ builds/jdk-9/bin/java -XX:+PrintAOT -XX:AOTLibrary=./libHelloAoT.so HelloAoT
13 1 loaded ./libHelloAoT.so aot library
76 1 aot[ 1] HelloAoT.<init>()V
76 2 aot[ 1] HelloAoT.main([Ljava/lang/String;)V
Hello AoT!
$
実行時 (-XX:+/-PrintAOT)
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
66
$ java -XX:-UseCompressedOops -XX:+PrintAOT -XX:AOTLibrary=./libHelloAoT.so HelloAoT
実行時 (圧縮 OOP を無効)
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
67
$ java -XX:-UseCompressedOops -XX:+PrintAOT -XX:AOTLibrary=./libHelloAoT.so HelloAoT
Shared file ./libHelloAoT.so error: UseCompressedOops has different value 'true' from
current 'false'
7 1 skipped ./libHelloAoT.so aot library
Hello AoT!
$
実行時 (圧縮 OOP を無効)
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
68
$ builds/jdk-9/bin/java -XX:-UseCompressedOops -XX:AOTLibrary=./libHelloAoT.so HelloAoT
Hello AoT!
$
実行時 (圧縮 OOP を無効)
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
69
$ jaotc -J-XX:-UseCompressedOop --output libHelloAOT.so HelloAoT.class
jaotc (VM options を合わせましょう)
圧縮されたOOP 普通の OOP
G1 -J-XX:+UseCompressedOops
-J-XX:+UseG1GC
-J-XX:-UseCompressedOops
-J-XX:+UseG1GC
ParallelGC -J-XX:+UseCompressedOops
-J-XX:+UseParallelGC
-J-XX:-UseCompressedOops
-J-XX:+UseParallelGC
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
70
まとめ
• 価値
– Peak performance までの時間を短縮 ★
– 複数の JVM のメモリ使用量を減らす ★
– JITを使えないプラットフォームでも利用できる ★
• 注意点
– 実験的なもので、サポートされていない
– 正式なドキュメントはない
– AMD64 の Linux しか動かない
– Invoke dynamic や カスタムクラスローダーをサポートしない
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
71
まとめ
• 価値
– Peak performance までの時間を短縮 ★
– 複数の JVM のメモリ使用量を減らす ★
– JITを使えないプラットフォームでも利用できる ★
• 注意点
– 実験的なもので、サポートされていない
– 正式なドキュメントはない
– AMD64 の Linux しか動かない
– Invoke dynamic や カスタムクラスローダーをサポートしない
★ 場合があります。
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
72
Ahead-of-Time Compilation with JDK 9 [Java Day Tokyo 2017 D1-A1]
Ahead-of-Time Compilation with JDK 9 [Java Day Tokyo 2017 D1-A1]

More Related Content

PDF
Lambda: A Peek Under The Hood [Java Day Tokyo 2015 6-3]
PPTX
Spring I/O 2015 報告
PDF
Yahoo! JAPANのサービス開発を10倍早くした社内PaaS構築の今とこれから
PDF
リクルートの利用事例から考える AWSの各サービスとセキュリティ
PDF
Apache Big Data Miami 2017 - Hadoop Source Code Reading #23 #hadoopreading
PDF
Dragon: A Distributed Object Storage at Yahoo! JAPAN (WebDB Forum 2017)
PDF
Yahoo! JAPANが実践するOpenStackと大規模環境でのコンテナ利用 #devsumi
PPTX
開発組織を急成長させる AWS 〜 Opt Technologies の歩みと AWS 活用
Lambda: A Peek Under The Hood [Java Day Tokyo 2015 6-3]
Spring I/O 2015 報告
Yahoo! JAPANのサービス開発を10倍早くした社内PaaS構築の今とこれから
リクルートの利用事例から考える AWSの各サービスとセキュリティ
Apache Big Data Miami 2017 - Hadoop Source Code Reading #23 #hadoopreading
Dragon: A Distributed Object Storage at Yahoo! JAPAN (WebDB Forum 2017)
Yahoo! JAPANが実践するOpenStackと大規模環境でのコンテナ利用 #devsumi
開発組織を急成長させる AWS 〜 Opt Technologies の歩みと AWS 活用

What's hot (16)

PDF
実運用して分かったRabbit MQの良いところ・気をつけること #jjug
PDF
ヤフーの広告レポートシステムをSpring Cloud Stream化するまで #jjug_ccc #ccc_a4
PDF
Cloud stack概要とaccel認定試験のご紹介
PDF
Hive on Tezのベストプラクティス
PDF
20131212 morphlabs okinawa_presentation
PDF
Spring I/O 2017 報告 ThymeleafのWebFlux対応
PPTX
機械学習ハンズオン
PDF
Design pattern in presto source code
PPTX
Spring 5に備えるリアクティブプログラミング入門
PDF
楽天がCloud foundryを選んだ理由
PDF
Spring social の基礎
PDF
YJTC18 A-1 大規模サーバの戦略
PPTX
Oracle advanced analyticsによる機械学習full version
PDF
おすすめインフラ! for スタートアップ
PDF
Elasticsearch勉強会
PDF
検索基盤Qass
実運用して分かったRabbit MQの良いところ・気をつけること #jjug
ヤフーの広告レポートシステムをSpring Cloud Stream化するまで #jjug_ccc #ccc_a4
Cloud stack概要とaccel認定試験のご紹介
Hive on Tezのベストプラクティス
20131212 morphlabs okinawa_presentation
Spring I/O 2017 報告 ThymeleafのWebFlux対応
機械学習ハンズオン
Design pattern in presto source code
Spring 5に備えるリアクティブプログラミング入門
楽天がCloud foundryを選んだ理由
Spring social の基礎
YJTC18 A-1 大規模サーバの戦略
Oracle advanced analyticsによる機械学習full version
おすすめインフラ! for スタートアップ
Elasticsearch勉強会
検索基盤Qass
Ad

Similar to Ahead-of-Time Compilation with JDK 9 [Java Day Tokyo 2017 D1-A1] (20)

PDF
より速く より運用しやすく 進化し続けるJVM(Java Developers Summit Online 2023 発表資料)
PDF
Java SE 8におけるHotSpotの進化 [Java Day Tokyo 2014 C-2]
PDF
Javaコードが速く実⾏される秘密 - JITコンパイラ⼊⾨(JJUG CCC 2020 Fall講演資料)
PDF
Adaptive optimization of JIT compiler
PDF
ソースコードは要求にとって地球の裏側なのか
PPTX
Introduction to JIT Compiler in JVM
PPTX
Japan it week_アプリケーション開発に最適なクラウド
PDF
Jenkins ユーザ・カンファレンス 2012 東京 S406-4/マルチステージ型継続的インテグレーションのすすめ
PPTX
Enterprise Development Conference 2016 プライベートPaaSが実現するアジャイル開発と次世代型アプリケーションの実例
PDF
Io t,ai時代のソフトウェア
PPTX
GBDC 勉強会 #2 Android Studio 実践レポート
PDF
Dodai projectの紹介
PDF
Oracle code one 2018 報告会概要
PDF
20161119 java one-feedback_osaka
PDF
20121119.dodai projectの紹介
PDF
Java によるクラウドネイティブ の実現に向けて
PPTX
Prig 残業泥棒 - 01. プロローグ 120121 杉浦
PDF
OpenJDK HotSpot C1Compiler Overview
PDF
Liferayのパートナーの視点からみた オープンソースのこれから
PDF
日本のシステム開発とDevOpsテクノロジ
より速く より運用しやすく 進化し続けるJVM(Java Developers Summit Online 2023 発表資料)
Java SE 8におけるHotSpotの進化 [Java Day Tokyo 2014 C-2]
Javaコードが速く実⾏される秘密 - JITコンパイラ⼊⾨(JJUG CCC 2020 Fall講演資料)
Adaptive optimization of JIT compiler
ソースコードは要求にとって地球の裏側なのか
Introduction to JIT Compiler in JVM
Japan it week_アプリケーション開発に最適なクラウド
Jenkins ユーザ・カンファレンス 2012 東京 S406-4/マルチステージ型継続的インテグレーションのすすめ
Enterprise Development Conference 2016 プライベートPaaSが実現するアジャイル開発と次世代型アプリケーションの実例
Io t,ai時代のソフトウェア
GBDC 勉強会 #2 Android Studio 実践レポート
Dodai projectの紹介
Oracle code one 2018 報告会概要
20161119 java one-feedback_osaka
20121119.dodai projectの紹介
Java によるクラウドネイティブ の実現に向けて
Prig 残業泥棒 - 01. プロローグ 120121 杉浦
OpenJDK HotSpot C1Compiler Overview
Liferayのパートナーの視点からみた オープンソースのこれから
日本のシステム開発とDevOpsテクノロジ
Ad

More from David Buck (20)

PDF
JDK 13 New Features [MeetUp with Java Experts! @Gaienmae/Dojima 2019]
PDF
JDK Mission Control: Where We Are, Where We Are Going [Groundbreakers APAC 20...
PDF
Java Bytecode Crash Course [Code One 2019]
PDF
CSI (Crash Scene Investigation) HotSpot: Common JVM Crash Causes and Solution...
PDF
invokedynamic for Mere Mortals [Code One 2019]
PDF
Hangs, Slowdowns, Starvation—Oh My! A Deep Dive into the Life of a Java Threa...
PDF
JDK Mission Control: Where We Are, Where We Are Going [Code One 2019]
PDF
Java Concurrency, A(nother) Peek Under the Hood [Code One 2019]
PDF
Z Garbage Collector
PDF
Valhalla Update JJUG CCC Spring 2019
PDF
Var handles jjug_ccc_spring_2018
PDF
JDK 10 へようこそ
PDF
HotSpot のロック: A Peek Under the Hood [JJUG ナイトセミナ JVM 特集 2015年8月]
PDF
Java Concurrency, A(nother) Peek Under the Hood [JavaOne 2016 CON1497]
PDF
Bytecode Verification, the Hero That Java Needs [JavaOne 2016 CON1500]
PDF
Java Debuggers: A Peek Under the Hood [JavaOne 2016 CON1503]
PDF
Java Concurrency, A(nother) Peek Under the Hood [Java Day Tokyo 2016 3-C]
PDF
InvokeDynamic for Mere Mortals [JavaOne 2015 CON7682]
PDF
HotSpot Synchronization, A Peek Under the Hood [JavaOne 2015 CON7570]
PDF
Let’s Write Our Own Chip-8 Interpreter! [JavaOne 2017 CON3584]
JDK 13 New Features [MeetUp with Java Experts! @Gaienmae/Dojima 2019]
JDK Mission Control: Where We Are, Where We Are Going [Groundbreakers APAC 20...
Java Bytecode Crash Course [Code One 2019]
CSI (Crash Scene Investigation) HotSpot: Common JVM Crash Causes and Solution...
invokedynamic for Mere Mortals [Code One 2019]
Hangs, Slowdowns, Starvation—Oh My! A Deep Dive into the Life of a Java Threa...
JDK Mission Control: Where We Are, Where We Are Going [Code One 2019]
Java Concurrency, A(nother) Peek Under the Hood [Code One 2019]
Z Garbage Collector
Valhalla Update JJUG CCC Spring 2019
Var handles jjug_ccc_spring_2018
JDK 10 へようこそ
HotSpot のロック: A Peek Under the Hood [JJUG ナイトセミナ JVM 特集 2015年8月]
Java Concurrency, A(nother) Peek Under the Hood [JavaOne 2016 CON1497]
Bytecode Verification, the Hero That Java Needs [JavaOne 2016 CON1500]
Java Debuggers: A Peek Under the Hood [JavaOne 2016 CON1503]
Java Concurrency, A(nother) Peek Under the Hood [Java Day Tokyo 2016 3-C]
InvokeDynamic for Mere Mortals [JavaOne 2015 CON7682]
HotSpot Synchronization, A Peek Under the Hood [JavaOne 2015 CON7570]
Let’s Write Our Own Chip-8 Interpreter! [JavaOne 2017 CON3584]

Ahead-of-Time Compilation with JDK 9 [Java Day Tokyo 2017 D1-A1]

  • 1. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Ahead-of-Time Compilation with JDK 9 日本オラクル株式会社 Java SE Sustaining Engineering バック デイビッド Java Day Tokyo 2017 2017年5月17日
  • 2. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 2 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.
  • 3. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 3 • JVM Sustaining Engineer • OpenJDK 8 Update Project Maintainer • JavaOne Rock Star • Co-author of Oracle WebLogic Server 11g 構築・運用ガイド • @DavidBuckJP • https://blogs.oracle.com/buck/ Hi There!
  • 4. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 4 Program Agenda 注意点 AoT のいろは 似ている機能 使い方 1 2 3 4
  • 5. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 5 注意点
  • 6. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 6 要注意 • AoT は実験的なものであり、正式にはサポートされていない
  • 7. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 7 要注意 • AoT は実験的なものであり、正式にはサポートされていない • 現時点では、AMD64 の Linux しかサポートされていない
  • 8. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 8 要注意 • AoT は実験的なものであり、正式にはサポートされていない • 現時点では、AMD64 の Linux しかサポートされていない • 正式なドキュメントはない(JEP のみ)
  • 9. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 9 要注意 • AoT は実験的なものであり、正式にはサポートされていない • 現時点では、AMD64 の Linux しかサポートされていない • 正式なドキュメントはない(JEP のみ) • 現時点では、将来的にサポートされる予定はない
  • 10. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 10 AoT のいろは
  • 11. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 11 AoT を勉強する価値
  • 12. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 12 AoT を勉強する価値 • 将来にサポートされるようになる可能性がある
  • 13. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 13 AoT を勉強する価値 • 将来にサポートされるようになる可能性がある • HotSpot の他の機能を勉強するきっかけである
  • 14. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 14 AoT を勉強する価値 • 将来にサポートされるようになる可能性がある • HotSpot の他の機能を勉強するきっかけである • やはり、面白い!
  • 15. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 15 Java Build / Execution Model (Interpreter) MyClass.java MyClass.class java (HotSpot) javac
  • 16. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 16 Java Build / Execution Model (JIT) MyClass.java MyClass.class java (HotSpot) javac マシン語 (メモリ上)
  • 17. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 17 Just in Time Compilation (JIT)
  • 18. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 18 Just in Time Compilation (JIT) • メソッドがコンパイルされる
  • 19. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 19 Just in Time Compilation (JIT) • メソッドがコンパイルされる • コンパイル処理は重い
  • 20. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 20 Just in Time Compilation (JIT) • メソッドがコンパイルされる • コンパイル処理は重い • マシン語のバージョンは早い
  • 21. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 21 Just in Time Compilation (JIT) • メソッドがコンパイルされる • コンパイル処理は重い • マシン語のバージョンは早い • パフォーマンスは interpreter よりいい?
  • 22. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 22 Just in Time Compilation (JIT)
  • 23. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 23 Just in Time Compilation (JIT)
  • 24. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 24 Just in Time Compilation (JIT) パフォーマンスは interpreter よりいい?
  • 25. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 25 Just in Time Compilation (JIT) パフォーマンスは interpreter よりいい? パフォーマンスの定義次第
  • 26. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 26 $ time ./hello_jdt Hello JavaDay Tokyo! real 0m0.002s user 0m0.001s $ time java HelloJDT Hello JavaDay Tokyo! real 0m0.104s user 0m0.077s sys 0m0.020s Just in Time Compilation (JIT)
  • 27. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 27 Just in Time Compilation (JIT) 弱点 • コンパイル処理が重い – メソッドを実行出来るようになるまで時間かかる – メモリの使用量が大きい • Hot ではないメソッドの場合、interpreter のほうが適切
  • 28. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 28 Just in Time Compilation (JIT) (HotSpot の実装) • まず、 すべてのメソッドは interpreter のみで実行 • サンプリングで Hot なメソッドを検出 • Hot のメソッドだけをコンパイル • Hot ではないメソッドは interpreter で実行
  • 29. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 29 HotSpot のJIT でも • アプリの起動が時間がかかる • 起動しても、最高のパフォーマンスまで時間がかかる • コンパイル処理がメモリを消費する • 実行時にマシン語を生成出来ないプラットフォームもある ネイティブ(C/C++ などと比べると)
  • 30. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 30 Just in Time Compilation (JIT) (HotSpot の実装) 2コンパイラ物語 • C2 – Server 用 – 最適化を頑張る – Interpreter が収集するプロファイリングデータを参考する – デフォルト CompileThreshold : 10000 • C1 – Client 用 – 最適化はあまりしない – プロファイリングデータをあまり利用しない – デフォルト CompileThreshold : 1500
  • 31. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 31 Ahead of Time (AoT) の戦略 • 実行の前にマシン語を生成しておく • 実行時に既存のマシン語をロードして実行する • 実行時にマシン語を生成する必要はなくなる
  • 32. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 32 Java Build / Execution Model (AoT) MyClass.java MyClass.class java (HotSpot) javac マシン語 (メモリ上)
  • 33. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 33 Java Build / Execution Model (AoT) MyClass.java MyClass.class java (HotSpot) javac my_class.so jaotc
  • 34. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 34 Java Build / Execution Model java (HotSpot) マシン語 (メモリ上) java (HotSpot) マシン語 (メモリ上) java (HotSpot) マシン語 (メモリ上) java (HotSpot) マシン語 (メモリ上)
  • 35. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 35 Java Build / Execution Model java (HotSpot) java (HotSpot) java (HotSpot) java (HotSpot) my_class.so
  • 36. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 36 Ahead of Time (AoT) の戦略
  • 37. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 37 Ahead of Time (AoT) の戦略 • アプリの起動が早くなる ★
  • 38. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 38 Ahead of Time (AoT) の戦略 • アプリの起動が早くなる ★ • peak performance / steady state まですぐ達成する ★
  • 39. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 39 Ahead of Time (AoT) の戦略 • アプリの起動が早くなる ★ • peak performance / steady state まですぐ達成する ★ • コンパイルの負荷( CPU 使用 / メモリの消費)を減らす ★
  • 40. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 40 Ahead of Time (AoT) の戦略 • アプリの起動が早くなる ★ • peak performance / steady state まですぐ達成する ★ • コンパイルの負荷( CPU 使用 / メモリの消費)を減らす ★ • 同じマシン語のデータを共有することが出来る ★
  • 41. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 41 Ahead of Time (AoT) の戦略 • アプリの起動が早くなる ★ • peak performance / steady state まですぐ達成する ★ • コンパイルの負荷( CPU 使用 / メモリの消費)を減らす ★ • 同じマシン語のデータを共有することが出来る ★ • 実行時にマシン語を生成出来ないプラットフォームでも利用できる ★
  • 42. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 42 Ahead of Time (AoT) の戦略 • アプリの起動が早くなる ★ • peak performance / steady state まですぐ達成する ★ • コンパイルの負荷( CPU 使用 / メモリの消費)を減らす ★ • 同じマシン語のデータを共有することが出来る ★ • 実行時にマシン語を生成出来ないプラットフォームでも利用できる ★ ★ 場合がある
  • 43. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 43 ?
  • 44. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 44 似ている機能
  • 45. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 45 少し似ている技術 • Tiered Compilation • Class Data Sharing(CDS) / AppCDS
  • 46. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 46 Tiered Compilation • 従来の server JVM – インタプリタ(プロファイリング) – C2 • Tiered Compilation – インタプリタ(プロファイリング) – プロファイリング付きの C1 – C2
  • 47. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 47 No Class Data Sharing java (HotSpot) クラスデータ (メモリ上) java (HotSpot) クラスデータ (メモリ上) java (HotSpot) クラスデータ (メモリ上) java (HotSpot) クラスデータ (メモリ上)
  • 48. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 48 Class Data Sharing java (HotSpot) java (HotSpot) java (HotSpot) java (HotSpot) クラスデータ classes.jsa
  • 49. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 49 • Class Data Sharing – Java SE のクラスライブラリ • AppCDS – アプリケーションのクラスも含む
  • 50. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 50 AoT との共通点 • Tiered Compilation – Warm up を早くしたい • Class Data Sharing(CDS) / AppCDS – Warm up を早くしたい – メモリの使用量を減らしたい AoT と異なる点 • マシン語を保存し、共用する機能 はない 少し似ている技術
  • 51. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 51 Corporate Photography Collection
  • 52. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 52 使い方
  • 53. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 53 新しいツール: jaotc MyClass.class my_class.sojaotc
  • 54. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 54 $ jaotc --output libHelloAOT.so HelloAoT.class jaotc
  • 55. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 55 $ jaotc --help Usage: jaotc <options> list list A : separated list of class names, modules, jar files or directories which contain class files. where options include: --output <file> Output file name --class-name <class names> List of classes to compile --jar <jarfiles> List of jar files to compile --module <modules> List of modules to compile --directory <dirs> List of directories where to search for files to compile --search-path <dirs> List of directories where to search for specified files --compile-commands <file> Name of file with compile commands --compile-for-tiered Generate profiling code for tiered compilation --compile-with-assertions Compile with java assertions --compile-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 jaotc (on-line help)
  • 56. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 56 $ jaotc --info --output libHelloAOT.so HelloAoT.class Compiling libHelloAOT... 1 classes found (30 ms) 2 methods total, 2 methods to compile (4 ms) Compiling with 8 threads . 2 methods compiled, 0 methods failed (409 ms) Parsing compiled code (1 ms) Processing metadata (15 ms) Preparing stubs binary (1 ms) Preparing compiled binary (1 ms) Creating binary: libHelloAOT.o (8 ms) Creating shared library: libHelloAOT.so (13 ms) Total time: 912 ms jaotc (--info flag)
  • 57. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 57 $ jaotc --info --compile-with-assertions --output libHelloAOT.so HelloAoT.class jaotc (--compile-with-assertions flag)
  • 58. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 58 $ jaotc --compile-commands cc.txt --output libHelloAOT.so HelloAoT.class $ cat cc.txt exclude org.sample.code.MyClass.method* exclude org.sample.code.MyClass.<init> jaotc (--compile-commands flag)
  • 59. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 59 $ jaotc --output libjava.base.so --module java.base jaotc (module)
  • 60. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 60 $ jaotc --output libjava.base.so --jar my-spiffy-app.jar jaotc (jar file)
  • 61. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 61 $ jaotc -J-XX:-UseCompressedOop --output libHelloAOT.so HelloAoT.class 意外に大事なオプション!(後ほど説明を。。。) jaotc (VM options)
  • 62. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 62 $ java -XX:AOTLibrary=./libHelloAoT.so HelloAoT 実行時
  • 63. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 63 $ java -XX:AOTLibrary=./libHelloAoT.so HelloAoT Hello AoT! $ 実行時
  • 64. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 64 $ java -XX:+PrintAOT -XX:AOTLibrary=./libHelloAoT.so HelloAoT 実行時 (-XX:+/-PrintAOT)
  • 65. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 65 $ builds/jdk-9/bin/java -XX:+PrintAOT -XX:AOTLibrary=./libHelloAoT.so HelloAoT 13 1 loaded ./libHelloAoT.so aot library 76 1 aot[ 1] HelloAoT.<init>()V 76 2 aot[ 1] HelloAoT.main([Ljava/lang/String;)V Hello AoT! $ 実行時 (-XX:+/-PrintAOT)
  • 66. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 66 $ java -XX:-UseCompressedOops -XX:+PrintAOT -XX:AOTLibrary=./libHelloAoT.so HelloAoT 実行時 (圧縮 OOP を無効)
  • 67. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 67 $ java -XX:-UseCompressedOops -XX:+PrintAOT -XX:AOTLibrary=./libHelloAoT.so HelloAoT Shared file ./libHelloAoT.so error: UseCompressedOops has different value 'true' from current 'false' 7 1 skipped ./libHelloAoT.so aot library Hello AoT! $ 実行時 (圧縮 OOP を無効)
  • 68. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 68 $ builds/jdk-9/bin/java -XX:-UseCompressedOops -XX:AOTLibrary=./libHelloAoT.so HelloAoT Hello AoT! $ 実行時 (圧縮 OOP を無効)
  • 69. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 69 $ jaotc -J-XX:-UseCompressedOop --output libHelloAOT.so HelloAoT.class jaotc (VM options を合わせましょう) 圧縮されたOOP 普通の OOP G1 -J-XX:+UseCompressedOops -J-XX:+UseG1GC -J-XX:-UseCompressedOops -J-XX:+UseG1GC ParallelGC -J-XX:+UseCompressedOops -J-XX:+UseParallelGC -J-XX:-UseCompressedOops -J-XX:+UseParallelGC
  • 70. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 70 まとめ • 価値 – Peak performance までの時間を短縮 ★ – 複数の JVM のメモリ使用量を減らす ★ – JITを使えないプラットフォームでも利用できる ★ • 注意点 – 実験的なもので、サポートされていない – 正式なドキュメントはない – AMD64 の Linux しか動かない – Invoke dynamic や カスタムクラスローダーをサポートしない
  • 71. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 71 まとめ • 価値 – Peak performance までの時間を短縮 ★ – 複数の JVM のメモリ使用量を減らす ★ – JITを使えないプラットフォームでも利用できる ★ • 注意点 – 実験的なもので、サポートされていない – 正式なドキュメントはない – AMD64 の Linux しか動かない – Invoke dynamic や カスタムクラスローダーをサポートしない ★ 場合があります。
  • 72. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 72