Skip to main content
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		| Confidential	– Oracle	Internal/Restricted/Highly	Restricted 1
Oracle	
Developer
Meetup8
th
김태완
taewanme@gmail.com
@taewanme
Cloud Native Java: GraalVM
2019.02.16
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
About:	김 태완(@taewanme)
• taewanme@gmail.com
• 1999	~	2006	Java	(SI,	Developer)
• 2007	~	2013	Middleware	Engineer
– WAS,	Memory	Cache,	CEP,	DB	Replication
• 2013	~	2014	CouchDB,	Erlang (SE)
• 2015	~	Big	Data,	ML,	Deep	Learning(SC)
http://taewan.kim
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
Demo	code
• https://github.com/taewanme/graalvm_seminar_examples
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 3
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		| Confidential	– Oracle	Internal/Restricted/Highly	Restricted 4
Graal Truffle
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
Java의 3대 전환점
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 5
1996 2019
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
Java의 3대 전환점: Java	1.2	à Enterprise
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 6
1996 20191999.12
1998.12	è Java	SE	1.2
1999.12	è Java	EE	1.2
2000.05	è Java	SE	1.3
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
Java의 3대 전환점: OpenSource Community 주도
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 7
1996 20191999.12 2006.05
Java	EE	5.0
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
Java의 3대 전환점: OpenSource Community 주도
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 8
1996 20191999.12 2006.05
Java	EE	5.0
POJO
Dependency	Injection
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
Java의 3대 전환점: OpenSource Community 주도
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 9
1996 20191999.12 2006.05
Java	EE	5.0
POJO
Dependency	Injection
StandardizationStandardization
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
Java의 3대 전환점:	OpenJDK à 다양성 자바
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 10
1996 20191999.12 2006.05
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
Java의 3대 전환점:	OpenJDK à 다양성 자바
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 11
1996 20191999.12 2006.05
Excelsior	JET
Java	Virtual	Machine
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
Java의 3대 전환점:	OpenJDK à 다양성 자바
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 12
1996 20191999.12 2006.05
Excelsior	JET
Java	Virtual	Machine
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
GraalVM
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 13
http://www.graalvm.org/
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
Why	GraalVM?
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 14
8.	Java	code	as	a	native	library
1.	High-performance	modern	Java
2.	Low-footprint,	fast-startup	Java
3.	Combine	JavaScript,	Java,	Ruby,	and	R
4.	Run	native	languages	on	the	JVM
5.	Tools	that	work	across	all	languages
6.	Extend	a	JVM-based	application
7.	Extend	a	native	application
9.	Polyglot	in	the	database
10.	Create	your	own	languagehttps://chrisseaton.com/truffleruby/tenthings/
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
Why	GraalVM?
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 15
8.	Java	code	as	a	native	library
1.	High-performance	modern	Java
2.	Low-footprint,	fast-startup	Java
3.	Combine	JavaScript,	Java,	Ruby,	and	R
4.	Run	native	languages	on	the	JVM
5.	Tools	that	work	across	all	languages
6.	Extend	a	JVM-based	application
7.	Extend	a	native	application
9.	Polyglot	in	the	database
10.	Create	your	own	language
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
Why	GraalVM?
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 16
8.	Java	code	as	a	native	library
1.	High-performance	modern	Java
2.	Low-footprint,	fast-startup	Java
3.	Combine	JavaScript,	Java,	Ruby,	and	R
4.	Run	native	languages	on	the	JVM
5.	Tools	that	work	across	all	languages
6.	Extend	a	JVM-based	application
7.	Extend	a	native	application
9.	Polyglot	in	the	database
10.	Create	your	own	language
IoT
Polyglot
Cloud	Native
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
생각해 볼 거리
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 17
Static(AOT) vs	Dynamic(JIT)
Compiler
Java	vs	 C/C++
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
Java와 C/C++
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 18
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		| Confidential	– Oracle	Internal/Restricted/Highly	Restricted 19
{AOT,	JIT}	Compiler
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
Compiler
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 20
• AOT(Ahead-of-Time)	Compiler
• JIT (Just-In-Time)	Compiler
Static vs	Dynamic
Compiler
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
AOT 컴파일러와 Dynamic	컴파일러 차이점
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 21
AOT	
Compiler
JIT
Compiler
è Machine	Code è Machine	Code
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
AOT 컴파일러와 Dynamic	컴파일러 차이점
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 22
AOT	Compiler JIT Compiler
Source code → Native executable Source code → Bytecode →
Interpreter + JIT executable
실행전에 무겁고 복잡한 분석&최적화 수행
실행 환경 정보 수집 어려움
특정 환경 특화된 최적화가 어려움
공격적이고 낙관적인 최적화
실행 프로파일 정보를 활용
특정 환경 특화된 최적화가 용이
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
AOT 컴파일러와 Dynamic	컴파일러 차이점
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 23
AOT	Compiler JIT Compiler
Source code → Native executable Source code → Bytecode →
Interpreter + JIT executable
실행전에 무겁고 복잡한 분석&최적화 수행
실행 환경 정보 수집 어려움
특정 환경 특화된 최적화가 어려움
공격적이고 낙관적인 최적화
실행 프로파일 정보를 활용
특정 환경 특화된 최적화가 용이
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
Write	Once,	Run	Anywhere
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 24
이미지 출처: https://commons.wikimedia.org/wiki/File:Java-program-execution.png
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
Write	Once,	Run	Anywhere
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 25
이미지 출처: https://commons.wikimedia.org/wiki/File:Java-program-execution.png
- javac compiler
- Java	code(String)	è byte[]
- java	파일을 Binary	Representation
- compact	&	small
- JIT	compiler
- byte[]	è byte[]	(machine	code)
- compact	&	small	representation
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
Write	Once,	Run	Anywhere
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 26
이미지 출처: https://commons.wikimedia.org/wiki/File:Java-program-execution.png
- Runtime
- 클래스 로딩, 바이트코드 검증, 동기화
- JIT
- 프로파일링, 컴파일 계획, OSR
- Aggressive Optimization
- GC
- Throughput & Response Time에 따른 알고리즘
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
JIT	Compiler의 목표
빠른 컴파일 속도 & 최적화
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 27
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
Bytecode	실행
2
3
4
1
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 28
Interpretation
Profiling
Dynamic	Compilation
Deoptimization
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
JIT	Compiler
• Speculation	Without	Regret:	Reducing	Deoptimization Meta-data	in	the	
Graal compiler
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 29
http://ssw.jku.at/General/Staff/GD/PPPJ-2014-duboscq-29.pdf
JVM
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
HotSpot Optimization
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 30
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
Optimization:	inlining
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 31
int addAll(int max){
int accum = 0;
for(int i = 0; i<max; i++) {
accum = add (accum, i);
}
return accum;
}
int add(int a, int b){return a+b;}
int addAll(int max){
int accum = 0;
for(int i = 0; i<max; i++) {
accum = accum + i;
}
return accum;
}
Optimization:	inlining
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
JVM	성능 향상
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 32
http://www.dominicgiles.com/blog/files/abdb7a96e9db63644317c62d6e40c40b-142.html
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
JVM	성능 향상 주체
• JIT	Compiler
– Profiling &
• CPU,	Memory,	Object	Tracking,	Mem
– Optimization
• 더 효율적인 코디 패턴 감지
• 더 효율적인 머신 코드 생성
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 33
http://ssw.jku.at/General/Staff/GD/PPPJ-2014-duboscq-29.pdf
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
Quiz:	누가 더 빠를까요?
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 34
Linux Linux
Java Java
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
Oracle	&	Intel
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 35
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
Intel	CPU의 Java	최적화
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 36
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		| Confidential	– Oracle	Internal/Restricted/Highly	Restricted 37
HotSpot
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
HotSpot
• Oracle	Java	JVM
• Java	SE	1.3(1999.	04)에 추가
• 개발 언어: C++
• 2개의 JIT	compiler를 포함
– C1:	client compiler
• C1	디자인:	빠른 시작
• 코드 최적화의 비중 낮춤
– C2:	server compiler
• C2	디자인:	약간 느린 시작
• 코드 최적화 비중 높임
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 38
HotSpot VM
C1 C2
Compiler	Interface
HotSpot VM
c++
c++
c++
c++
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
HotSpot – JVM
• client	/	C1
– $	java	–client
– 32-bit	VM
– machine	code	생성 속도 빠름
– 기본 최적화
– 프로파일 지원하지 않음
– 장점: 빠른 시작
– 단점: 최대 성능 저하
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 39
• server	/	C2
– $	java	–server
– 32-bit	VM
– 코드 최적화 수준 높음
– 프로파일 기반 최적화
– C++과 비슷하거나 더 빠른 코드를
생산
– gcc 와 같은 AOT	컴파일러가 할 수
없는 런타임 최적화를 적용
– 장점: 머신코드 품질이 좋음
– 단점: 느린 시작, warmup	필요
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
HotSpot – Tiered	Compilation
• -XX:+TieredCompilation
• 기본 JIT	컴파일 설정
• Level
– Level0:	Interpreter
– Level1:	C1,	프로파일 없음
– Level2:	C1,	기본 프로파일
– Level3:	C1,	완전 프로파일
– Level4:	C2
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 40
Time	to	Performance
Peak	Performance
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
JVM
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 41
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
HotSpot – Limitation
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 42
https://github.com/netroby/jdk9-
dev/blob/master/jdk/src/java.base/share/classes/jdk/internal/HotSpotIntrinsicCandidate.java
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		| Confidential	– Oracle	Internal/Restricted/Highly	Restricted 43
GraalVM &	Graal
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
GraalVM에 들어가기 앞서 다시한번….
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 44
Static(AOT) vs	Dynamic(JIT)
Compiler
Java	vs	 C/C++
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
GraalVM
GraalVM =	Hotspot	VM+	𝜶
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 45
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		| Confidential	– Oracle	Internal/Restricted/Highly	Restricted 46
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
GraalVM Team
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 47
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
OMZ……
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 48
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
GraalVM의 핵심 키워드
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 49
Graal /	JVMCI Polyglot/	Truffle Native	Image
NEW	JIT	Complier Language	Platform AOT	Compiler
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
GraalVM 키워드
• Graal
• GraalVM
• Polyglot	
• Truffle	
• Substrate	VM	
• JVMCI,	Compiler	Interface	
• JIT	Compiler	
• AOT	
• HotSpotVM
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 50
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
Graal !=	GraalVM
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 51
HotSpot VM
C1 C2
Compiler	Interface
OpenJDK 8
HotSpot VM
Compiler	Interface JVMCI
C1 Graal
GraalVM
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
Graal
• GraalVM의 새로운 JIT	Compiler
• Hotspot의 C2	JIT	컴파일러 대체가 목표
• Java로 개발
• C2와 비교하여 20% 선능 개선 (Twitter	사례)
– Production	Scala	애플리케이션에 적용
– GraalVM CE(Community	Edition)
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 52
https://www.youtube.com/watch?v=ZbccuoaLChk
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
Community	Edition
• Free
• Unsupported
• Runs	all	GraalVM languages
– Java	(+Scala),	JavaScript,	Python,	Ruby,	R
• Support	for	native	libraries	in	context	of	those	languages	too
– Tools	(debugger,	profiler,	monitor	agent)
• Basic	version	of	SubstrateVM
– Native	code	has	full	access	to	address	space
• Runs	code	in	JVM,	Node.js,	MySQL,	or	standalone
Enterprise	Edition
• Not	Free
• Supported
• Best	performance	&	size
– Graal	EE	Java	is	20%	faster	than	CE	(on	average)
– Dynamic	languages	(JS,	Python,	R,	Ruby)	2x	faster
– Smallest	footprint	– 2x	smaller	vs CE
• Native	code	memory	protection
• Debugging	tools	for	embedded	use
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 53
GraalVM 라이센스
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
Scala	2.12.6	&	GraalVM
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 54
https://medium.com/graalvm/compiling-scala-faster-with-graalvm-86c5c0857fa3
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
graal compiler
• OpenJDK 9	+
• OpenJDK 10	+
• OpenJDK 11	+
• GraalVM
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 55
-XX:+UnlockExperimentalVMOptions 
-XX:+UseJVMCICompiler 
-XX:+EnableJVMCI
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
GraalVM 설치
#	다운로드
$	wget https://github.com/oracle/graal/releases/download/vm-1.0.0-
rc12/graalvm-ce-1.0.0-rc12-macos-amd64.tar.gz
#	압축풀기
$	tar	zxf graalvm-ce-1.0.0-rc12-macos-amd64.tar.gz
#	환경 변수
$ export	GRAAL_HOME=…
$	PATH=PATH=$GRAAL_HOME/bin:$PATH	
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 56
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
GraalVM 설치
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 57
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
graal compiler
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 58
https://www.graalvm.org/docs/examples/java-performance-examples/
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
graal compiler	Demo
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 59
OpenJDK 11,	Tiered	Compiler OpenJDK 11,	Graal Compiler
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
graal compiler	Demo:	compile	log
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 60
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
Graal과 Twitter
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 61
https://www.youtube.com/watch?v=G-vlQaPMAxg
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
GraalVM 기능과 JEP
• JEP:	JDK	Enhancement	Proposal
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 62
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		| Confidential	– Oracle	Internal/Restricted/Highly	Restricted 63
Native	Image
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
작은 footprint,	신속한 startup
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 64
OpenJDK 11,	Graal Compiler
SubstrateVM	(SVM)
• GraalVM의 하위 프로젝트
• JVM	애플리케이션을 컴파일하여 Native	실행파일을 생성
• Ahead-of-time	compiler- 빠른 시작을 유도
• Virtual	머신이 필요 없음
• 작은 메모리로 시작
• 38Mbyte	virt.x	애플리케이션을 10MB	RAM에서 돌린 사례
• https://www.jetdrone.xyz/2018/08/10/Vertx-native-image-
10mb.html
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
Native	Image	Demo
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 65
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
Graal &	SubstrateVM
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 66
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
빠른 Startup:	Heap	Image
• d
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 67
https://medium.com/graalvm/isolates-and-compressed-references-more-flexible-and-
efficient-memory-management-for-graalvm-a044cc50b67e
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
Substrate	VM	Java	Limitations
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 68
https://github.com/oracle/graal/blob/master/substratevm/LIMITATIONS.md
항목 지원
Dynamic	Class	Loading	/	Unloading Not	supported
Reflection Mostly	supported
Dynamic	Proxy Mostly	supported
Java	Native	Interface	(JNI) Mostly	supported
Unsafe	Memory	Access Mostly	supported
Static	Initializers Partially	supported
InvokeDynamic	Bytecode	and	Method	Handles Not	supported
Finalizers Not	supported
References Mostly	supported
Security	Manager Not	supported
JVMTI,	JMX,	other	native	VM	interfaces Not	supported
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
Micronaut의 GraalVM 지원
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 69
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
Micronaut의 GraalVM 지원
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 70
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
Micronaut의 GraalVM 지원
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 71
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
GraalVM 기능과 JEP
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 72
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		| Confidential	– Oracle	Internal/Restricted/Highly	Restricted 73
Polyglot
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
Truffle
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 74
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
Polyglot	Virtualization
75
Truffle	API
Java	Runtime
JavaScript
Interpreter
Ruby
Interpreter
R
Interpreter
Python
Interpreter
GraalVM
compiler
Compiled	
code	snippetCompiled	
code	snippetCompiled	
code	snippetCompiled	
code	snippetCompiled	
code	snippetCompiled	
code	snippet
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
Polyglot	Virtualization
76
Truffle	API
Java	Runtime
JavaScript
Interpreter
Ruby
Interpreter
R
Interpreter
Python
Interpreter
GraalVM
compiler
Compiled	
code	snippetCompiled	
code	snippetCompiled	
code	snippetCompiled	
code	snippetCompiled	
code	snippetCompiled	
code	snippet
…JavaScript	
application
JavaScript	
libraries
Node.js
Ruby	
application
Ruby	gems	
&	libraries
Rails
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
Polyglot	Virtualization
77
Truffle	API
Java	Runtime
JavaScript
Interpreter
Ruby
Interpreter
R
Interpreter
Python
InterpreterGraalVM
compiler
Compiled	
code	snippetCompiled	
code	snippetCompiled	
code	snippetCompiled	
code	snippetCompiled	
code	snippetCompiled	
code	snippet
…JavaScript	
application
JavaScript	
libraries
Node.js
Ruby	
application
Ruby	gems	
&	libraries
Rails
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
Polyglot	Virtualization
7878
Truffle	API
Java	Runtime
JavaScript
Interpreter
Ruby
Interpreter
R
Interpreter
Python
Interpreter
GraalVM
compiler
Compiled	
code	snippetCompiled	
code	snippetCompiled	
code	snippetCompiled	
code	snippetCompiled	
code	snippetCompiled	
code	snippet
JavaScript	
application
JavaScript	
libraries
Node.js
…Ruby	
application
Ruby	gems	
&	libraries
Rails
LLVM	.bc
Interpreter
R	native	
libraries
Node.js	
native	libs
Ruby/Rails	
native	libs
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
Polyglot	Virtualization
79
Truffle	API
JavaVM Runtime
JavaScript
Interpreter
Ruby
Interpreter
R
Interpreter
Graal
compiler
Compiled	
code	snippetCompiled	
code	snippetCompiled	
code	snippetCompiled	
code	snippetCompiled	
code	snippetCompiled	
code	snippet
JavaScript	
application
JavaScript	
libraries
Node.js
…
Ruby	
application
Ruby	gems	
&	libraries
Rails
LLVM	.bc
Interpreter
R	native	
libraries
Node.js	
native	libs
Ruby/Rails	
native	libs
Threads	/	Scheduler Filesystem Network GC	/	heap Code	cache
Java	
application
Truffle	
Polyglot	
API
eval("application/x-ruby",
"def add(a, b) a + b;
end;");
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
Truffle
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 80
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
Ployglot Performance
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 81
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
Java에서 다른 언어 호출
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 82
import org.graalvm.polyglot.*;
public class Sample {
public static void main(String[] args) {
try (Context context = Context.newBuilder().allowAllAccess(true).build()){
System.out.println( context.getEngine().getLanguages().keySet());
context.eval("ruby", "puts '안녕, 루비’”);
context.eval("python", "print(안녕, 파이썬')");
context.eval("js", "console.log(‘안녕, JS')");
context.eval("R", "cat(‘안녕, R')");
} catch (PolyglotException e) {
e.printStackTrace();
}
}
}
graaldemo/example/e04
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
spring-r:	mvn spring-boot:run
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 83
example/e06/spring-r
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
Spring-r	UI:	http://localhost:8080/load
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 84
example/e06/spring-r
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
Java에서 다른 언어를 호출 (LLVM)
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 85
#include	<stdio.h>
int main(){
print(“Hello	from	graalvm!n”);
return 0;	
}
$	clang	-c	-O1	-emit-llvm hello.c
$	lli hello.bc
Hello	from	graalvm!
$
graaldemo/example/e03
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
Java에서 다른 언어를 호출 (LLVM)
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 86
import	org.graalvm.polyglot.*;	
import	java.io.*;	
public	class	Sample	{	
public	static	void	main(String[]	args)	throws	Exception	{
File	f	=	new	File("hello.bc");	
Source	source	=	Source.newBuilder("llvm",	new	File("hello.bc")).build();	
try	(Context	 context	=	Context.newBuilder().allowAllAccess(true).build()){	
context.eval(source).execute();	
}	
}	
}	
graaldemo/example/e03
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
PolyGlot Demo
public	class	Test	{
public	static	String	getString()	{
return	"Hello	from	Java!	<br>	";
}
}
87
Test.java
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
PolyGlot Demo
const express	=	require('express')
const app	=	express()
const BigInteger =	Java.type('java.math.BigInteger')
app.get('/',	function	(req,	res)	{
var text	=	'Hello	World	from	Graal.js!	'
//	Using	Java	standard	library	classes
text	+=	BigInteger.valueOf(2).pow(100).toString(16)
text	+=	'	'	
//	Using	custom	Java	class
text	+=	Java.type('Test').getString()
//	Using	R	methods	to	return	arrays
text	+=	Interop.eval('application/x-r',	'runif(1000)')[0]
//	Using	R	interoperability	to	create	graphs
text	+=	Interop.eval('application/x-r',
`svg();
require(lattice);
x	<- 1:100
y	<- sin(x/10)
z	<- cos(x^1.3/(runif(1)*5+10))
print(cloud(x~y*z,	main="cloud	plot"))
grDevices:::svg.off()
`);
res.send(text)
})
app.listen(3000,	function	()	{
console.log('Example	app	listening	on	port	3000!')
})
88
server.js
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
PolyGlot Demo
const express	=	require('express')
const app	=	express()
const BigInteger =	Java.type('java.math.BigInteger')
app.get('/',	function	(req,	res)	{
var text	=	'Hello	World	from	Graal.js!	'
89
server.js
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
PolyGlot Demo	(2)
//	Using	Java	standard	library	classes
text	+=	BigInteger.valueOf(2).pow(100).toString(16)
text	+=	'	'	
//	Using	custom	Java	class
text	+=	Java.type('Test').getString()
90
server.js
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
PolyGlot Demo	(3)
//	Using	R	methods	to	return	arrays
text	+=	Interop.eval('application/x-r',	'runif(1000)')[0]
91
server.js
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
PolyGlot Demo	(4)
//	Using	R	interoperability	to	create	graphs
text	+=	Interop.eval('application/x-r',
`svg();
require(lattice);
x	<- 1:100
y	<- sin(x/10)
z	<- cos(x^1.3/(runif(1)*5+10))
print(cloud(x~y*z,	main="cloud	plot"))
grDevices:::svg.off()
`);
res.send(text)
})
92
server.js
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
PolyGlot Demo	(5)
app.listen(3000,	function	()	{
console.log('Example	app	listening	on	port	3000!')
})
93
server.js
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
Ployglot Database
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 94
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		| Confidential	– Oracle	Internal/Restricted/Highly	Restricted 95
GraalVM Summary
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
GraalVM
Confidential	– Oracle	Internal
Languages Graal Embeddings* *
Java
JavaScript
Ruby
R
Python
C/C++.	FORTRAN,	…
HotSpot	JVM
MySQL
Oracle	RDBMS
Spark
nginx
…
Optimizations
Tooling
Interoperability
Code
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
GraalVM의 목표: Six	degrees	of	freedom
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 97
https://commons.wikimedia.org/wiki/File:6DOF.svg
• Fast	Startup	Java	Application:	Native
• High	Performance	Java	Application
• Integrated	Polyglot	Application
• Java	as	Language	Platform
• Embedded	Java	Application
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
GraalVM, OpenJDK, Oracle	Java
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 98
Graal
Native	Image
JVMCI
JEP	243:	Java-Level	JVM	Compiler	Interface
JEP	295:	Ahead-of-Time	Compilation
JEP	317:	Experimental	Java-Based	JIT	Compiler
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
GraalVM의 비전
언어에 자유롭고, 빠르고, 자유도가 높은 가상머신
Write	code	once	(in	whatever	language	you	want)	and	use	it	in	any	
application	written	in	any	other	language,	and	run	it	in	whatever	engine	you	
want	(Java	HotSpot,	Node.js,	MySQL,	Oracle	RDBMS,	or	standalone)
Already	In	Production
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 99
Copyright	©	2017, Oracle	and/or	its	affiliates.	All	rights	reserved.		|
GraalVM
• Fastest Runtime
– Faster	in	standard	JVM	– Twitter	says	EE	is	30%	faster,	Morgan	Stanley	reports	35%
– Native	Image	Mode	compiles	Java	code	into	standalone	binaries	- no	JVM	required
• Multilingual w/	high	compatibility	(eg.	runs	Node.js	&	Java	in	one	process)
• More	secure (runs	native	libraries	in	bounds-checked	&	GC’ed mode)
• Embeddable (run	in	a	device,	native	or	JVM-based	engine)	with	low	overhead
Confidential	– Oracle	Internal/Restricted/Highly	Restricted 100
Null	method	in	Function-as-a-Service JDK8 Go GraalVM EE
Cold Execution	(w/o	Docker) 210	ms 20	ms 10	ms
Container Memory 17.8	MB 1.2	MB 0.9 MB
Container	Image	Size 266	MB 15.1	MB 13.6	MB Serverless Compute	
Footprint	&	Startup