GraalVMãæ£å¼ã«ãªãªã¼ã¹ããã¾ãããçµæ§è©±é¡ã«ãªã£ã¦ã¾ããã
GraalVMã¯ãGraal JITã¨AoTãããã¦ASTã¨ã³ã¸ã³Truffleã®è¤åä½ã§ãã(ããªï¼)
GraalVM
ã¨ãããã¨ã§ãRuståããããJavaã§æ¸ããã¬ã¤ãã¬ã³ã¼ãããã¤ãã£ãã³ã³ãã¤ã«ããããã¦ã¿ã¾ããã
Hyper-Vã§Ubuntuãç¨æãã
ã»ãã¨ã¯Windows Subsystem of Linux(WSL)ã§ããããã£ãã®ã ãã©ãWSLä¸ã§Javaãã¡ããã¨åãã¦ãããªãã£ãã®ã§ããããã¾ããã
ã§ãVirtualBox使ãããªã¨æã£ããã©ãHyper-Vãç¡å¹ã«ããªãã¨ãããªãã¦ãHyper-Vãç¡å¹ã«ããã¨Dockerãåããªããªãã®ã§ãã ãªã¼ã¨æã£ã¦ãã®ã ãã©ãæ®éã«Hyper-Vã§Ubuntuãã¡ãããã°ããã®ã§ã¯ã¼ã¨æã£ã¦ãã£ã¦ã¿ã¾ããã
æ®éã«ä½¿ãã¾ãããç»é¢ãµã¤ãºèª¿æ´ããã©ã«ãå
±æãã¯ãªãããã¼ãå
±æãªã©ãVirtualBoxã®ã»ãã使ããããã§ããã
Macã®å ´åã¯CEçã§ã¯ãªãOracleçã使ãã¨ããã¨æãã¾ãã
RustãGraalVMã§åãã
ASTã¨ã³ã¸ã³Truffleã¨ããã®ã¯ãããã°ã©ã è¨èªãæ§ææ¨ã«è½ã¨ãã¦ãæé©åã»å®è¡ããå¦çã¨ã³ã¸ã³ã§ãã
Javaã®ãã¤ãã³ã¼ããLLVMã®ãããã³ã¼ããããæ½è±¡åº¦ãé«ãè¨èªã®æ§é ãæ®ã£ã¦ãããããæé©åããããããã¨ãããã¨ãçã£ã¦ã¾ãã(ãã¶ã)
ã§ãããã§LLVMã®ãããã³ã¼ããTruffleã³ã¼ãã«å¤æããã¨ããSulongã¨ãããã¼ã«ãããã®ã§ãRustãåãã¾ããã©ã¤ãã©ãªãªããã¯ãx86ã³ã¼ããLLVMãããã³ã¼ãã«å¤æãã¦Truffleã³ã¼ãã«å¤æãã¦åããããããå¤æ
ã
ã§ããããªæãã§Rustã³ã¼ããmain.rsã¨ããååã§ç¨æãã¾ãã
fn main() { println!("Hello rust! fib(8) is {}", fib(8)); } fn fib(i:i64) -> i64 { if i < 2 { i } else { fib(i - 2) + fib(i - 1) } }
ã¨ããããæ®éã«ã³ã³ãã¤ã«ãã¦åããã¦ã¿ã¾ãã
$ rustc main.rs $ ./main Hello rust! fib(8) is 21
ã§ã¯ããããLLVMã®ãããã³ã¼ããåãã ãã¦GraalVMã§åããã¦ã¿ã¾ãã
$ rustc --emit=llvm-bc main.rs $ ls -l main.* -rw-rw-r-- 1 naoki naoki 6860 4æ 23 01:37 main.bc -rw-rw-r-- 1 naoki naoki 146 4æ 23 01:36 main.rs $ graalvm-1.0.0-rc1/bin/lli --lib $(rustc --print sysroot)/lib/libstd-* main.bc Hello rust! fib(8) is 21
åãã¾ããï¼
Haskellã§ããããããªã¨æã£ããã©ãLLVM3.5ãå¿
è¦ã£ã½ããããã±ã¼ã¸ã3.7ãããããªãã£ã½ããã¨ããããããããã
ã¬ã¤ãã¬ããã¤ãã£ãã³ã³ãã¤ã«ãã¦ã¿ã
GraalVMã«ã¯AoTã³ã³ãã¤ã©ãããã¾ããAoTã¨ããã®ã¯Ahead of Timeã§ãäºåã³ã³ãã¤ã«ã®ãã¨ã§ããããã使ã£ã¦Javaã³ã¼ãããã¤ãã£ãã³ã³ãã¤ã«ãã¦ã¿ã¾ãã
ãããªãã«å¦çéãããã³ã¼ãã¨ãããã¨ã§ãããªãã ä½ã£ãã¬ã¤ãã¬ãåããã¦ã¿ã¾ãã
kishida/smallpt4j: smallpt Java port
ææ°çã¯ããããããã£ã¦ã¦è¤æ°ã½ã¼ã¹ã«åããã¦ããããã®ã§ãåæã®ãã®ã使ãã¾ãã
https://github.com/kishida/smallpt4j/blob/original/src/main/java/naoki/smallpt/SmallPT.java
ããã±ã¼ã¸ãããã©ã«ãããã±ã¼ã¸ã«å¤æ´ãã¦ããã¾ããã¾ããFastMathã使ã£ã¦ããã®ã§java.lang.Math.*ãstatic importãã¦ãã¡ãã使ãã¾ãã
ã§ãæ®éã«ã³ã³ãã¤ã«ãã¦å®è¡
$ graalvm-1.0.0-rc1/bin/javac SmallPT.java $ graalvm-1.0.0-rc1/bin/java SmallPT
ç»åãã§ãã¾ããã
ä»åã¯æ©ãçµãããããç»åãèãããã¾ã¾ã«ãã¦ã¾ãã
ã§ã¯ãã¤ãã£ãã³ã³ãã¤ã«ãã
ãã¤ãã£ãã³ã³ãã¤ã«ã«ã¯zlib.hãå¿
è¦ãªã®ã§ãã¨ã£ã¦ãã¾ãã
$ sudo apt install zlib1g-dev
ããã¦native-imageã§ã³ã³ãã¤ã«
$ graalvm-1.0.0-rc1/bin/javac SmallPT.java $ graalvm-1.0.0-rc1/bin/native-image SmallPT Build on Server(pid: 7220, port: 26681) classlist: 166.86 ms (cap): 544.93 ms setup: 803.27 ms analysis: 3,460.75 ms error: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: Unsupported method java.lang.ClassLoader.getParent() is reachable: The declaring class of this element has been substituted, but this element is not present in the substitution class To diagnose the issue, you can add the option -H:+ReportUnsupportedElementsAtRuntime. The unsupported element is then reported at run time when it is accessed the first time.
ãªããã¨ã©ã¼ã
ImageIOãã ãã£ã½ããåçã«ã¯ã©ã¹ãã¼ããã¦ãããã ãããªã
â» 2018/11/14è¿½è¨ GraalVM Community Edition 1.0 RC9ã§ã¯ImageIOã«å¯¾å¿ãã¦ãã¦ãã®ã¾ã¾native-imageãéãã¾ãã
ã¨ãããã¨ã§ãImageIOãããã¦ãªãªã¸ãã«ã®smallptã¨åæ§ã«ppmãåãåºãããã«å¤æ´ãã¾ãã
try(BufferedWriter bw = Files.newBufferedWriter(Paths.get("image.ppm")); PrintWriter pw = new PrintWriter(bw)) { pw.printf("P3\n%d %d\n%d\n", w, h, 255); for (Vec v : c) { pw.printf("%d %d %d ", toInt(v.x), toInt(v.y), toInt(v.z)); } }
ã¨ãããã¨ã§ãå
¨ä½ã®ã³ã¼ãã¯ãã¡ãã«
SmallPT4j without ImageIO
æ¹ãã¦Javaã§åããã¾ãã
$ graalvm-1.0.0-rc1/bin/javac SmallPT.java $ graalvm-1.0.0-rc1/bin/java SmallPT JVM:1.8.0_161 sample:40 Samples:40 Type:master Time:PT24.042S
ããããã¤ãã£ãã³ã³ãã¤ã«ã
$ graalvm-1.0.0-rc1/bin/native-image SmallPT Build on Server(pid: 7220, port: 26681) classlist: 167.94 ms (cap): 592.71 ms setup: 808.36 ms (typeflow): 2,479.49 ms (objects): 875.25 ms (features): 24.48 ms analysis: 3,439.52 ms universe: 134.33 ms (parse): 318.66 ms (inline): 550.73 ms (compile): 2,101.23 ms compile: 3,249.17 ms image: 466.18 ms write: 120.34 ms [total]: 8,412.47 ms $ ls -l smallpt -rwxrwxr-x 1 naoki naoki 5696832 4æ 23 02:27 smallpt
ããã©ã¯ ããã¾ããããã¤ãã£ããã¡ã¤ã«ãã§ãã¦ã¾ãããããã¦5MBãæ¡å¤å°ããã
å®è¡ãã¦ã¿ã¾ãã
$ rm image.ppm $ ./smallpt JVM:null sample:40 Samples:40 Type:master Time:PT37.341S $ ls -l image.ppm -rw-rw-r-- 1 naoki naoki 8244655 4æ 23 02:28 image.ppm
ã¨ããããé ããªã£ã¦ããããã24ç§ã ã£ãã®ã37ç§ã«ã
ã¤ãã§ã«ãé常ã®OpenJDKã§åããã¦ã¿ã¾ãã
$ jdk1.8.0_171/bin/java SmallPT JVM:1.8.0_171 sample:40 Samples:40 Type:master Time:PT18.565S $ jdk-10.0.1/bin/java SmallPT JVM:10.0.1 sample:40 Samples:40 Type:master Time:PT16.400068S
GraalVMã®JVMããéãããJDK10ã¯ããã«éãï¼
ã¨ãããã¨ã§ãããªæãã«ã
GraalVM | native-image | JDK8 | JDK10 |
---|---|---|---|
1.8.0_161 | null | 1.8.0_171 | 10.0.1 |
24.042 | 37.341 | 18.565 | 16.400068 |
ã¨ããããDurationã®ç²¾åº¦ãJDK10ã§ããã£ã¦ã¾ããã
ã¨ãããã¨ã§ããããããã£ã¦ã¿ã¾ããã
Swingã¢ããªã試ãã¦ã¿ããã©ãAppContextã®åæåã§ã¤ã³ãããã¡ã½ããã®å¦çããããã¨ããã¨ãã«åçã¯ã©ã¹ãã¼ããã¦ãã£ã½ãã¦ããã§ãã¡ã§ããã
ã¾ã ã¾ã åé¡ã¯ããããã ãã©ããã£ã¨éçºãé²ãã¨é¢ç½ããã