I've heard that
In an attempt to speed up a Maven build, I've downloaded jdk9-ea
and find out that it takes even longer with it. Moreover, it feels like there is a longer delay before Maven starts.
I've tried to roughly measure JVM startup time using following code
public class Sampler {
public static void main(String[] args) throws IOException, InterruptedException {
long t = System.currentTimeMillis();
if (args.length == 0 || args[0].startsWith("-")) {
sample(30, args);
} else {
long t0 = Long.parseLong(args[0]);
System.out.println(t - t0);
}
}
static void sample(int n, String[] options) throws IOException, InterruptedException {
File samples = new File("samples.txt");
for (int i = 0; i < n; i++) {
String javaPath = String.join(
System.getProperty("file.separator"),
System.getProperty("java.home"),
"bin",
"java");
List<String> command = new ArrayList<String>();
command.add(javaPath);
command.addAll(Arrays.asList(options));
command.add("Sampler");
command.add(Long.toString(System.currentTimeMillis()));
ProcessBuilder processBuilder = new ProcessBuilder(command)
.inheritIO()
.redirectOutput(ProcessBuilder.Redirect.appendTo(samples));
Process process = processBuilder.start();
process.waitFor();
}
prettyPrint(samples);
samples.delete();
}
...
}
And it takes twice as long to start with Java 9
>java -version java version "1.8.0_74" Java(TM) SE Runtime Environment (build 1.8.0_74-b02) Java HotSpot(TM) Client VM (build 25.74-b02, mixed mode, sharing) >javac Sampler.java && java Sampler n=30 units=milisec min=124 max=205 mean=143 median=132 >java -version java version "9-ea" Java(TM) SE Runtime Environment (build 9-ea+111) Java HotSpot(TM) Client VM (build 9-ea+111, mixed mode) >javac Sampler.java && java Sampler n=30 units=milisec min=279 max=387 mean=301 median=294 >javac Sampler.java && java Sampler -XX:+UseParallelGC n=30 units=milisec min=279 max=382 mean=297 median=292 >java -version java version "1.8.0_76-ea" Java(TM) SE Runtime Environment (build 1.8.0_76-ea-b04) Java HotSpot(TM) Client VM (build 25.76-b04, mixed mode, sharing) >javac Sampler.java && java Sampler n=30 units=milisec min=123 max=227 mean=159 median=141 >java Sampler -XX:+UseG1GC n=99 units=milisec min=188 max=340 mean=213 median=199
Note: Originally I've used Server VMs (x64), same 2x gap, Java9 startup time was around 0.6sec.
After java -Xshare:dump
>java -version java version "9-ea" Java(TM) SE Runtime Environment (build 9-ea+111) Java HotSpot(TM) Client VM (build 9-ea+111, mixed mode, sharing) >javac Sampler.java && java Sampler n=50 units=milisec min=228 max=422 mean=269 median=269 >javac Sampler.java && java Sampler -Xshare:on <error messages> n=44 units=milisec min=227 max=392 mean=247 median=238 >javac Sampler.java && java Sampler -Xshare:off n=50 units=milisec min=280 max=513 mean=315 median=288 >javac Sampler.java && java Sampler -Xshare:auto n=50 units=milisec min=228 max=361 mean=283 median=285
With Java 8 ea
>java -Xshare:off Sampler n=99 units=milisec min=124 max=264 mean=150 median=136
Error message:
An error has occurred while processing the shared archive file. Unable to map ReadOnly shared space at required address. Error occurred during initialization of VM Unable to use shared archive.
44 successful starts out of 50 is the highest number I could get. Lowest was - 13.
Yes, there definitely are some startup regressions in current EA builds - some causes are known and actively worked on - others are more of a "Death by a thousand cuts" ordeal: small, insignificant inefficiencies accumulated over the course of development of JDK 9 as features are implemented and integrated, which then has to be fine-tuned and optimized before actual release.
Edit: In subsequent JDK releases we eliminated most startup regressions introduced with JDK 9. One notable exception is startup regressions caused by JEP 280 where innocuous string concatenations in the JDK library may cause small but noticeable overheads in some applications.
It's likely that G1 garbage collector, which is default on Java-9, causes significant startup delay. Try -XX:+UseParallelGC
on Java-9 or -XX:+UseG1GC
on Java-8 to check with the same garbage collector.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With