Is time regression enabled in Java 9 EA?

I've heard of it

>Each major version of the JVM becomes faster (in some ways) > 9 modularity will lead to faster startup time

In order to speed up Maven build, I have downloaded jdk9 EA and found that it takes longer In addition, I feel there is a longer delay before Maven starts

I tried to roughly measure JVM startup time using the 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();
    }
    ...
}

Java 9 takes twice as long to start

>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,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: I used the server virtual machine (x64) originally. With the same 2x gap, the startup time of Java 9 is about 0.6 seconds

After that, 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,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

Using 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.

50 successful starts are the highest number you can get The lowest is – 13

Solution

Yes, the current EA version must have some enlightening regression - some reasons are known and positive work - others are more of a torture of "a thousand times of death reduction": small and insignificant inefficient function implementation and integration accumulated in the development process of JDK 9, and then must be fine tuned and optimized before actual release

I will also notice that your 8 / 8-ea enables running class data sharing, but your 9-ea installation will not (please note that "sharing" is missing in the - version output) If you run Java - xshare: dump to generate the default CDs archive, you can get better numbers on 9-ea. For details, see https://docs.oracle.com/javase/8/docs/technotes/guides/vm/class-data-sharing.html.

Edit: I just realized that sharing is turned off by default in 9 versions, so you must also add - xshare: Auto in 9-ea to enable sharing

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>