LoginSignup
0
0

More than 3 years have passed since last update.

GraalVM for Java Performance (Windows Developer Build)

Last updated at Posted at 2019-06-07

What is GraalVM?

High-performance polyglot VM

Install GraalVM

Download GraalVM from OTN

Windows GraalVM Early Adopter
Support for GraalVM on Windows is currently under development.
Note: You will need to accept the license at the top of the page before downloading:
Download GraalVM based on JDK8, preview for Windows (19.0.1) (cksum - 3226557420)

Extract the downloaded file to any directory

Expand-Archive "C:\<DOWNLOADED FOLDER>\graalvm-ee-windows-amd64-19.0.1.zip" "C:\Program Files\Java\"

Installation Check

PS C:> & 'C:\Program Files\Java\graalvm-ee-19.0.1\bin\java.exe' -version
java.exe : java version "1.8.0_212"
Java(TM) SE Runtime Environment (build 1.8.0_212-b31)
Java HotSpot(TM) GraalVM EE 19.0.1 (build 25.212-b31-jvmci-19-b01, mixed mode)

Case.2 Performance Check and Compare

  1. Compile JDK1.8 + Run JDK1.8
  2. Compile JDK1.8 + Run JDK11
  3. Compile JDK1.8 + Run GraalVM Java (NOT native)
GraalSample.java
public class GraalSample {
    static final int ITERATIONS = Math.max(Integer.getInteger("iterations", 1), 1);
    public static void main(String[] args) {
        String sentence = String.join(" ", args);
        for (int iter = 0; iter < ITERATIONS; iter++) {
            if (ITERATIONS != 1) System.out.println("-- iteration " + (iter + 1) + " --");
            long total = 0, start = System.currentTimeMillis(), last = start;
            for (int i = 1; i < 10000000; i++) {
                total += sentence.chars().filter(Character::isUpperCase).count();
                if (i % 1000000 == 0) {
                    long now = System.currentTimeMillis();
                    System.out.printf("%d (%d ms)%n", i / 1000000, now - last);
                    last = now;
                }
            }
            System.out.printf("total: %d (%d ms)%n", total, System.currentTimeMillis() - start);
        }
    }
}

Compile GraalSample.java by JDK1.8

PS C:> & 'C:\Program Files\Java\jdk1.8.0\bin\javac.exe' -source 1.8 -d C:\Temp GraalSample.java

Run JDK1.8

PS C:\Temp> Measure-Command { & 'C:\Program Files\Java\jdk1.8.0\bin\java.exe' GraalSample }
TotalMilliseconds : 1272.6506
TotalMilliseconds : 1157.0957
TotalMilliseconds : 1155.1402
TotalMilliseconds : 1165.2418
TotalMilliseconds : 1176.3292

PS C:\Temp> Measure-Command { & 'C:\Program Files\Java\jdk1.8.0\bin\java.exe' GraalSample In 2019 I would like to run ALL languages in one VM.}
TotalMilliseconds : 3806.2965
TotalMilliseconds : 3795.3136
TotalMilliseconds : 3800.0122
TotalMilliseconds : 3791.7407
TotalMilliseconds : 3783.8776

Run GraalVM Java (NOT native)

PS C:\Temp>  Measure-Command { & 'C:\Program Files\Java\graalvm-ee-19.0.1\bin\java.exe' GraalSample }
TotalMilliseconds : 2400.0316
TotalMilliseconds : 2394.7220
TotalMilliseconds : 2413.2863
TotalMilliseconds : 2372.2009
TotalMilliseconds : 2870.4932

PS C:\Temp>  Measure-Command { & 'C:\Program Files\Java\graalvm-ee-19.0.1\bin\java.exe' GraalSample In 2019 I would like to run ALL languages in one VM. }
TotalMilliseconds : 3579.2619
TotalMilliseconds : 3628.8374
TotalMilliseconds : 3516.2905
TotalMilliseconds : 3453.3161
TotalMilliseconds : 3655.8266

Conclusion

GraalVM takes overhead for the first few times, BUT GraalVM is more stable and FASTER than JDK1.8, as the number of iterations increase.
It seems GraalVM isn't suitable for single-shot like a simple cli java programs.

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0