GraalVMæµè¡ã£ã¦ã¾ããã
ããã¦ãå¤ãã®äººã¯GraalãAOTã¨ãã¦ä½¿ãnative-imageã®ãã¨ã ããGraalVMã¨è¨ã£ã¦ãããã¾ãã
ãå®å¿ãããã®ã¨ã³ããªã§ã¯GraalãJITã¨ãã¦ä½¿ãHotSpotã¢ã¼ãã¨GraalãAOTã¨ãã¦ä½¿ãnative-imageã®ä¸¡æ¹ãé
ãã¨ãã話ã§ãã
GraalVMã¯éããã¨è¨ããã¦ã¾ãããæ®å¿µãªããHotSpotã¢ã¼ãã§C2ããéãçµæãæå
ã§ã¯åºãã¦ãã¾ããã
å
¬å¼ããã°ã§ã¯1.7åãã5åéããªãã¨æ¸ãã¦ã¾ããã©ãæå
ã§ã¯åç¾ã§ãã¦ã¾ããã
Under the hood of GraalVM JIT optimizations - graalvm - Medium
native-imageã¯éããã¨ããã®ã¯ããããã¾ãããããã¯ãã¤ãã£ãåã«ããJVMã®èµ·åæéãæé©åã®æéãæé©åãããã«åãæéãçç¥ãããã®ã§èµ·åãéããã¨ãã話ã§ããé·ãåãããã»ã¹ã®å ´åããããã£ãèµ·åã«ãããæéã¨ããã®ã¯ç¡è¦ã§ããããã«ãªããå®è¡æã«éããæ å ±ã使ã£ã¦æé©åããJITã®ã»ããéãã§ãã
ç¨èªã«ã¤ãã¦
ã¨ããã§ããã§ç¨èªã®ç¢ºèªãã
GraalVMã¨ããã®ã¯ãJavaã§æ¸ãããJITã³ã³ãã¤ã©Graalãä¸å¿ã¨ããå¤è¨èªç°å¢ã§ãã
æ®éã«GraalãJavaã®JITã³ã³ãã¤ã©ã¨ãã¦ä½¿ãã®ãGraalVMã®HotSpotã¢ã¼ãã§ããããããã«javaã³ãã³ãã§ãã
Graalã®æé©åæ©æ§ãä¸è¬ã®ã¹ã¯ãªããè¨èªãã使ããããã«ãã¦JavaScriptãRubyã®JITã³ã³ãã¤ã©ã«ãã¦ãã¾ãã®ãTruffleã§ãã
ããã¦ãGraalãäºåã«Javaã³ã¼ãã«é©ç¨ãã¦ãã¤ãã£ãåããã¨ããã®ãnative-imageã§ãã
è¨æ¸¬
ã¨ãããã¨ã§ãã©ã®ãããé
ããæ¯ã¹ã¦ã¿ã¾ãã
ã³ã¼ãã¯ãã®ã¬ã¤ãã¬ã
https://github.com/kishida/smallpt4j/blob/original/src/main/java/naoki/smallpt/SmallPT.java
commonsã®FastMathã使ã£ã¦ããã®ã§ãé常ã®java.lang.Mathã«ç½®ãæãã¦å®è¡ãã¾ããã¾ããã«ã¼ãä¸ã®System.out.printlnã¯ã³ã¡ã³ãã¢ã¦ããã¾ããã
ããã¯ããã¨ã以åã¯ãã®ã³ã¼ãã¯ImageIOã使ã£ã¦ããã®ã§GraalVMã§ãã¤ãã£ãåã§ããªãã£ãã®ã§ããããã¾ã§ã¯ã§ããããã«ãªã£ã¦ã¾ãã
å®è¡ããã¨ãããªæãã®PNGç»åãåºåããã¾ãã
GraalVM 19.0.2 CE
ããã§ã¯Windowsã§åããã¦ã¿ã¾ãããGraalVMã¯19.0.2CEã§ãã
ã¾ãã¯HotSpotã¢ã¼ãã
C:\Users\naoki\Documents\prj>java -version openjdk version "1.8.0_212" OpenJDK Runtime Environment (build 1.8.0_212-20190603180034.buildslave.jdk8u-src-tar--b03) OpenJDK 64-Bit GraalVM CE 19.0.2 (build 25.212-b03-jvmci-19-b04, mixed mode) C:\Users\naoki\Documents\prj>java SmallPT Samples:40 Type:master Time:PT9.713S
10ç§å¼±ã
ãã¤ãã£ãåãã¦ã¿ã¾ãã
C:\Users\naoki\Documents\prj>native-image SmallPT [smallpt:21796] classlist: 1,793.30 ms ... [smallpt:21796] write: 786.36 ms [smallpt:21796] [total]: 26,307.39 ms C:\Users\naoki\Documents\prj>smallpt Samples:40 Type:master Time:PT45.234S
45ç§ãã ãã¶é ãï¼
GraalVM 19.0.2 EE
ã¤ãã§ã«EEã§ã試ãã¦ã¿ã¾ãã
C:\Users\naoki\Documents\prj>java -version java version "1.8.0_212" Java(TM) SE Runtime Environment (build 1.8.0_212-b31) Java HotSpot(TM) 64-Bit GraalVM EE 19.0.2 (build 25.212-b31-jvmci-19-b04, mixed mode) C:\Users\naoki\Documents\prj>java SmallPT Samples:40 Type:master Time:PT10.281S
10ç§å¼·ãããã¾å¤ãããã
ã§ã¯ãã¤ãã£ãåã
C:\Users\naoki\Documents\prj>native-image SmallPT [smallpt:43056] classlist: 2,165.31 ms ... [smallpt:43056] image: 788.17 ms Warning: Generating and stripping of debug info not supported on Windows[smallpt:43056] write: 775.12 ms [smallpt:43056] [total]: 29,450.40 ms C:\Users\naoki\Documents\prj>smallpt Samples:40 Type:master Time:PT13.039S
13ç§ï¼CEã«æ¯ã¹ãã¨ãã£ã¡ãéãï¼
OpenJDK
ããã§ã¯C2çãã¤ã¾ããµã¤ãã®OpenJDK
$ java -version openjdk version "1.8.0_212" OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_212-b03) OpenJDK 64-Bit Server VM (AdoptOpenJDK)(build 25.212-b03, mixed mode) $ java SmallPT Samples:40 Type:master Time:PT6.795S
6.8ç§ãGraalVMã«æ¯ã¹ãã¨ã ãã¶éãã§ãã
OpenJDKã®11ã§ã試ãã¦ã¿ã¾ãã
$ java -version openjdk version "11.0.2" 2019-01-15 OpenJDK Runtime Environment 18.9 (build 11.0.2+9) OpenJDK 64-Bit Server VM 18.9 (build 11.0.2+9, mixed mode) $ java SmallPT Samples:40 Type:master Time:PT5.8484946S
5.8ç§ãããã¡ãã£ã¨éããªã£ã¦ãï¼
ã¾ã¨ã
ã¨ãããã¨ã§ãã¾ã¨ããã¨ããã
ã¤ãã§ã«Macã§ãè¨æ¸¬ãã¦ãã¾ããWindowsã8ã³ã¢ã§Macã4ã³ã¢ãªã®ã§ãã¡ããã©åãããã®æéãããã£ã¦ã¾ãããCEã®native-imageãããã»ã©é
ããªãã®ã ãã©ãã³ã¢æ°ã«ãããã®ãWindowsã¨Macã®éããæ°ã«ãªãã¨ããã
GraalVM CE HotSpot | GraalVM CE Native | GraalVM EE HotSpot | GraalVM EE Native | OpenJDK 8 | OpenJDK 11 | |
---|---|---|---|---|---|---|
Windows(i7-8Cores) | 9.713 | 45.234 | 10.281 | 13.039 | 6.795 | 5.848 |
Mac(i7-4Cores) | 20.966 | 47.069 | 18.797 | 19.135 | 16.783 | 12.594 |
ã°ã©ãã«ããã¨ããã
ã¨ãããã¨ã§ãGraalVMã®ãã¤ãã£ãã¤ã¡ã¼ã¸ã¯èµ·å以å¤ã¯éããªã ãããé
ããGraalVM EEã®ãã¤ãã£ãã¤ã¡ã¼ã¸ã¯CEã«æ¯ã¹ãã¨ããªãéããã©HotSpotã¢ã¼ãã»ã©ã§ã¯ãªããJDKã¯8ãã11ã§ãéããªã£ã¦ããã¨ããçµæã«ãªãã¾ããã
Linuxã§ããã°Graalã¯éãã¨ããåãããã¾ãã
7/4è¿½è¨ 19.1.0ãåºã¦ãã®ã§è©¦ãã¦ã¿ããã©ãCEã®native-imageãã¡ãã£ã¨éããªã£ãï¼
CE HotSpot | CE Native | EE HotSpot | EE Native | |
---|---|---|---|---|
19.1.0 Win | 10.676 | 43.419 | 10.787 | 12.972 |