Oracle Modern Cloud Day

Cloud Native : GraalVM

Taewan Kim / Solution Engineer Cloud Excellence Team / Oracle Korea

1 Copyright © 2019 Oracle and/or its affiliates 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, timing, and pricing of any features or functionality described for Oracle’s products may change and remains at the sole discretion of .

2 Copyright © 2019 Oracle and/or its affiliates (2) (3) (4) 개발언어 수준 고성능 자바 빠른 실행 상호 운용성

(1)

3 Copyright © 2019 Oracle and/or its affiliates What is GraalVM?

4 Copyright © 2019 Oracle and/or its affiliates Java for Cloud Native

New JIT Compiler: Java, , JavaScript, Ruby, One VM to native-image Graal , C++, Rust, Python …. Rule them

개발언어 수준 ALL (2013) 고성능 자바 빠른 실행 상호 운용성 Community Edition Enterprise Edition Java Standard Edition JDK() Java 8 & Java 11(P) Version: 19.2.1 www.graalvm.org #Non-Standard Java #Standard-Java compatibility #Extension Java #Standardization Orientation 5 Copyright © 2019 Oracle and/or its affiliates GraalVM CE vs. GraalVM EE

6 Copyright © 2019 Oracle and/or its affiliates GraalVM CE vs. GraalVM EE

• Free • Commercial - Subscription • Community Support( • Supported Enterprise Support • OpenJDK 8 Based • Oracle Java 8 Based • Native Code Protection • Free on OCI(OCI Cloud)

7 Copyright © 2019 Oracle and/or its affiliates GraalVM CE vs. GraalVM EE

• Free • Commercial - Subscription • OpenJDK 8 Based • Supported Enterprise Support • Oracle Java 8 Based • Native Code Memory Protection • Free on OCI(OCI Cloud)

8 Copyright © 2019 Oracle and/or its affiliates GraalVM: 고성능 자바 - New JIT Compiler

9 Copyright © 2019 Oracle and/or its affiliates Performance Enhancement in Every Versions

1995 1996 1998 2000 2002 2004 2006 2007 2014 2017 2018.3 2018.9 2019.3 2019.9

Java Java Java Java Java Java Java Java Java Java Java Java Java Java Beta 1.0 1.2 1.3 1.4 5 6 7 8 9 10 11 12 13

Java VM 성능 향상 요소 • Garbage Collection 알고리즘 • Runtime 메모리 구조 개선 • Java Library 효율성 향상 • CPU 최적화 • JIT(Just-in-Time) 컴파일러

10 Copyright © 2019 Oracle and/or its affiliates Performance Matrices

Peak Throughput Startup Speed 빠른 시작 시간 단위 시간당 최대 처리량

낮은 메모리 사용량

Low Memory Reduced Max Footprint 지연시간 최소화 Latency

패키키 파일 용량

11 Copyright © 2019 Oracle and/or its affiliates Small Packaging Performance Enhancement in Every Versions

1995 1996 1998 2000 2002 2004 2006 2007 2014 2017 2018.3 2018.9 2019.3 2019.9

Java Java Java Java Java Java Java Java Java Java Java Java Java Java Beta 1.0 1.2 1.3 1.4 5 6 7 8 9 10 11 12 13

Java VM 성능 향상 요소 • Garbage Collection 알고리즘 • Runtime 메모리 구조 개선 • Java Library 효율성 향상 • CPU 최적화 • JIT(Just-in-Time) 컴파일러

12 Copyright © 2019 Oracle and/or its affiliates Java Compiler & JIT(Just-in-Time) Compiler

Java Source File Java bytecode File @Compile jar file Time javac (compile) jar(packing)

Filesystem @Run Time (JVM)

Runtime Data Area Machine Class Code Loader / Execution Engine Native Code Gabage Collector JIT

13 Copyright © 2019 Oracle and/or its affiliates Java Compiler & JIT(Just-in-Time) Compiler

Java Source File Java bytecode File @Compile jar file Time javac (compile) jar(packing)

Filesystem @Run Time (JVM) Runtime Data Area Program Native Method Stack Machine Heap Counter Method Area Area Registers Stack Code Class / Execution Engine Loader Native JIT IR Generator Profiler Code Gabage Collector Optimizer Code Generator

14 Copyright © 2019 Oracle and/or its affiliates JIT Compiler: Optimizer

JVM Runtime Data Area Execution Engine Class Loader JIT IR Generator Profiler Gabage Collector Optimizer Code Generator

long count = 0, sum = 0; Arrays.stream(persons) for (int i = 0; i < persons.length; .filter(p -> p.getEmployment() == i++) { Employment.EMPLOYED) Person person = persons[i]; .filter(p -> p.getSalary() > 100_000) int age = person.age; .mapToInt(Person::getAge) Code Optimization if (person.employment == .filter(age -> age >= 40).average() Employment.EMPLOYED && .getAsDouble(); person.salary > 100_000 && age >= 40) { Partial Escape Analysis (Stadler et al. CGO ‘14) sum += age; Path Duplication (Leopoldseder et al. CGO ‘18) count += 1; Priority Inlining (Prokopec et al. CGO ‘19) } } 15 Copyright © 2019 Oracle and/or its affiliates return (double) sum / count; = + �

16 Copyright © 2019 Oracle and/or its affiliates = + � OpenJDK 8

C1 C2 C++ C++

Compiler Interface

HotSpot VM

17 Copyright © 2019 Oracle and/or its affiliates = + � OpenJDK 8 GraalVM

C1 C2 C1 Graal C++ C++ C++ Java

Compiler Interface Compiler Interface JVMCI

HotSpot VM HotSpot VM

Partial Escape Analysis (Stadler et al. CGO ‘14) Path Duplication (Leopoldseder et al. CGO ‘18)

18 Copyright © 2019 Oracle and/or its affiliates Priority Inlining (Prokopec et al. CGO ‘19) Graal Compiler와 C2 Compiler 성능 비교

Graal Compiler

C2 Compiler

19 Copyright © 2019 Oracle and/or its affiliates Graal Compiler와 C2 Compiler 성능 비교

Iteration 1: 11.961 ns/op Graal Compiler Iteration 2: 11.888 ns/op Iteration 3: 12.032 ns/op

Iteration 1: 231.342 ns/op Iteration 2: 216.852 ns/op C2 Compiler Iteration 3: 217.012 ns/op

20 Copyright © 2019 Oracle and/or its affiliates Graal Compiler와 C2 Compiler 성능 비교

21 Copyright © 2019 Oracle and/or its affiliates GraalVM: 개발언어 수준 상호 운용성

22 Copyright © 2019 Oracle and/or its affiliates 1995 Write once, Run anywhere

23 Copyright © 2019 Oracle and/or its affiliates 1995 Write once, Run anywhere

JVM JVM JVM

24 Copyright © 2019 Oracle and/or its affiliates 1995 Write once, Run anywhere

Cloud Open Source

https://landscape.cncf.io/zoom=60

25 Copyright © 2019 Oracle and/or its affiliates 1995 Write once, Run anywhere

2013 One VM to rule them all

https://landscape.cncf.io/zoom=60

26 Copyright © 2019 Oracle and/or its affiliates Polyglot Language Platform

GraalVM interpreter GraalVM LLVM bitcode interpreter Truffle Framework

GraalVM Compiler

Java HotSpot VM

27 Copyright © 2019 Oracle and/or its affiliates Polyglot Language Platform

GraalVM interpreter GraalVM LLVM bitcode interpreter Truffle Framework

GraalVM Compiler

Java HotSpot VM

28 Copyright © 2019 Oracle and/or its affiliates Node.js ∈ {Java, R}

Java

29 Copyright © 2019 Oracle and/or its affiliates Spring(Java) & R

Java

30 Copyright © 2019 Oracle and/or its affiliates GraalVM: Fast Startup Native Image

31 Copyright © 2019 Oracle and/or its affiliates How to Run Application in JIT

JVM 실행 파일 로딩 > Class Loader 클래스 파일 로딩 Class Loader 클래스 파일 로딩 프로파일 피드백 수집 바이트 코드 검증 바이트 코드 검증

코드 해석 코드 해석 Second Tier JIT 코드 컴파일 Fist Tier JIT 코드 컴파일 (C1) (C2/Graal)

머신코드 실행 머신코드 실행

32 Copyright © 2019 Oracle and/or its affiliates Performance Matrices for JIT

Peak Throughput Startup Speed

JIT

Low Memory Reduced Max Footprint Latency

33 Copyright © 2019 Oracle and/or its affiliates Small Packaging AOT mode: Native Image

@Second Compile Time with native-image Heap Image

정적 코드 분석 • heap snapshot Class Loader Machine Code 클래스 로딩 및 초기화 • AOT-compile code Substrate VM

34 Copyright © 2019 Oracle and/or its affiliates Performance Matrices for AOT (Ahead of Time)

Peak Throughput Startup Speed

AOT

Low Memory Reduced Max Footprint Latency

35 Copyright © 2019 Oracle and/or its affiliates Small Packaging ExtListDir 성능 비교

Graal mode Native mode

36 Copyright © 2019 Oracle and/or its affiliates ExtListDir 성능 비교

Graal mode Native mode

0.126s 0.037s

37 Copyright © 2019 Oracle and/or its affiliates Performance Matrices for AOT (Ahead of Time) and JIT

Peak Throughput Startup Speed

AOT JIT

Low Memory Reduced Max Footprint Latency

38 Copyright © 2019 Oracle and/or its affiliates Small Packaging How to Run Application in JIT

JVM 실행 파일 로딩 > Class Loader 클래스 파일 로딩 Class Loader 클래스 파일 로딩 프로파일 피드백 수집 바이트 코드 검증 바이트 코드 검증

코드 해석 코드 해석 Second Tier JIT 코드 컴파일 Fist Tier JIT 코드 컴파일 (C1) (C2/Graal)

머신코드 실행 머신코드 실행

39 Copyright © 2019 Oracle and/or its affiliates Native Image: Profile-Guided Optimizations (PGO) – 19.02

native-image Profiles (.iprof) --pgo-instrument Instrumented Binary

Relevant native-image --pgo Optimized Binary Workloads

Executables File $ java -Dgraal.PGOInstrument=myclass.iprof MyClass Machine Code

$ native-image --pgo=myclass.iprof MyClass Heap Image

$ ./myclass Substrate VM

40 Copyright © 2019 Oracle and/or its affiliates Hibernate 성능 측정: PGO Native

Handled requests per second

18,000 16,000 14,000 12,000 10,000 8,000 6,000 4,000 2,000 0 1,000 10,000 100,000 1,000,000 10,000,000 Cumulative number of requests sent by ApacheBench

Native Image JDK 8, Java HotSpot VM Final Goal of GraalVM AOT

Peak Throughput Startup Speed

AOT JIT

Low Memory Reduced Max Footprint Latency

42 Copyright © 2019 Oracle and/or its affiliates Small Packaging GraalVM 적용 사례

43 Copyright © 2019 Oracle and/or its affiliates Twitter 사례: 20% 성능 개선 (With GraalVM CE)

https://www.youtube.com/watch?v=ZbccuoaLChk

44 Copyright © 2019 Oracle and/or its affiliates NIVIDA 사례: grCUDA 아키텍처

Language GPU Support Library

Python Numba, cuPy, PyCUDA GraalVM LLVM Java JCuda, jCUDA, CUDA4J bitcode interpreter

C/C++ CUDA C/C++ Truffle Framework R gpuR, Rcpp

JavaScript gpu.js, node-cuda, cuda-ts GraalVM Compiler C# Hybridizer, ManagedCUDA, ILGPU

Ruby RbCUDA Java HotSpot VM

45 Copyright © 2019 Oracle and/or its affiliates 적용 사례: Microprofile Framework 성능 비교

35 ms Helidon 1030 ms 988 ms

37 ms Micronaut 2087 ms 2101 ms

16 ms Quarkus 952 ms 940 ms

0 ms 500 ms 1000 ms 1500 ms 2000 ms 2500 ms

Native Image JDK 12 JDK 8

46 Copyright © 2019 Oracle and/or its affiliates 적용 사례: Microprofile Framework 메모리 사용량 비교

31 MB Helidon 116 MB 106 MB

41 MB Micronaut 172 MB 180 MB

17 MB Quarkus 125 MB 121 MB

0 MB 20 MB 40 MB 60 MB 80 MB 100 MB 120 MB 140 MB 160 MB 180 MB 200 MB Maximum Memory Size

Native Image JDK 12 JDK 8

47 Copyright © 2019 Oracle and/or its affiliates GraalVM + Oracle Cloud

48 Copyright © 2019 Oracle and/or its affiliates Oracle Cloud + GraalVM

Virtual Machine/ Containers Functions Bare Metal • Kubernetes • PaaS

49 Copyright © 2019 Oracle and/or its affiliates Oracle Cloud + GraalVM

Virtual Machine/ Containers / OKE Functions Bare Metal 인스턴스 유지기간 일단위 ~ 월단위 분단위 ~ 일단위 초단위 ~ 분단위 Startup 시간 중요도 낮음 중요도 높음 매우 높음 성능 핵심 지표 Low Latency Response Low Latency Response Low Latency Response High Throughput Memory 요구사항 높음 보통 낮음 GraalVM EE on OCI Service 무료 이용 가능 무료 이용 가능 무료 이용 가능 Enterprise Support 지원 지원 지원 MCD 2019 관련 세션 트랙4: 14:10 ~ 14:50 트랙4: 14:10 ~ 14:50 N/A Modern Cloud Development Modern Cloud Development on OCI : New Services on OCI : New Services MCD 2019 관련 Hands-on Developer Hands-on Track Developer Hands-on Track Developer Hands-on Track 13:20 ~ 14:50, 나 혼자 시작 16:00 ~ 16:40, CI/CD with 15:10 ~ 15:50, Function with 하는 Oracle Cloud 첫걸음: OKE using Functions GraalVM featured ATP OCI Infra & Terraform

50 Copyright © 2019 Oracle and/or its affiliates GraalVM on OCI VM Peak Throughput Startup Speed

AOT JIT

Low Memory Reduced Max Footprint Latency

51 Copyright © 2019 Oracle and/or its affiliates Small Packaging GraalVM on OCI Container(OKE) Peak Throughput Startup Speed

AOT JIT

Low Memory Reduced Max Footprint Latency

52 Copyright © 2019 Oracle and/or its affiliates Small Packaging GraalVM on OCI Function Peak Throughput Startup Speed

AOT JIT

Low Memory Reduced Max Footprint Latency

53 Copyright © 2019 Oracle and/or its affiliates Small Packaging Summary

Java for Cloud Native

New JIT Compiler: Java, R, JavaScript, Ruby, One VM to native-image Graal C, C++, Rust, Python …. Rule them

개발언어 수준 ALL (2013) 고성능 자바 빠른 실행 상호 운용성 Community Edition Enterprise Edition Java Standard Edition JDK(Java Development Kit) Java 8 & Java 11(P) Version: 19.2.1 www.graalvm.org #Non-Standard Java #Standard-Java compatibility #Extension Java #Standardization Orientation

54 Copyright © 2019 Oracle and/or its affiliates GraalVM 수석 개발자 Thomas Wuerthinger 세션 2019.12.14 13:00 Asem Tower 15층

55 Copyright © 2019 Oracle and/or its affiliates 56 Copyright © 2019 Oracle and/or its affiliates Thank you

Taewan Kim Solution Engineer Cloud Excellence Team

57 Copyright © 2019 Oracle and/or its affiliates