11/*
2- * Copyright (c) 2013, 2017 , Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2013, 2018 , Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
2525 * @test
2626 * @requires vm.cds
2727 * @bug 8005933
28- * @summary Test that -Xshare:auto uses CDS when explicitly specified with -server.
28+ * @summary -Xshare:auto is the default when -Xshare is not specified
2929 * @library /test/lib
3030 * @modules java.base/jdk.internal.misc
3131 * java.management
@@ -45,34 +45,30 @@ public static void main(String[] args) throws Exception {
4545 output .shouldContain ("Loading classes to share" );
4646 output .shouldHaveExitValue (0 );
4747
48- pb = ProcessTools .createJavaProcessBuilder (
49- "-server" , "-XX:+UnlockDiagnosticVMOptions" ,
50- "-XX:SharedArchiveFile=./XShareAuto.jsa" , "-version" );
51- output = new OutputAnalyzer (pb .start ());
52- String outputString = output .getOutput ();
53- // We asked for server but it could be aliased to something else
54- if (outputString .contains ("Server VM" ) && !outputString .contains ("emulated-client" )) {
55- // In server case we don't expect to see sharing flag
56- output .shouldNotContain ("sharing" );
57- output .shouldHaveExitValue (0 );
58- }
59- else {
60- System .out .println ("Skipping test - no Server VM available" );
61- return ;
62- }
6348
64- pb = ProcessTools .createJavaProcessBuilder (
65- "-server" , "-Xshare:auto" , "-XX:+UnlockDiagnosticVMOptions" ,
66- "-XX:SharedArchiveFile=./XShareAuto.jsa" , "-Xlog:cds" , "-version" );
67- output = new OutputAnalyzer (pb .start ());
68- try {
69- output .shouldContain ("sharing" );
70- } catch (RuntimeException e ) {
71- // if sharing failed due to ASLR or similar reasons,
72- // check whether sharing was attempted at all (UseSharedSpaces)
73- output .shouldContain ("UseSharedSpaces:" );
74- output .shouldNotContain ("Unable to map %s" );
49+ // We have 2 test cases:
50+ String cases [] = {
51+ "-Xshare:auto" , // case [1]: -Xshare:auto is explicitly specified.
52+ "-showversion" // case [2]: -Xshare:auto is not explicitly specified,
53+ // but VM should still use it by default.
54+ };
55+
56+ for (String x : cases ) {
57+ pb = ProcessTools .createJavaProcessBuilder (
58+ "-XX:+UnlockDiagnosticVMOptions" ,
59+ "-XX:SharedArchiveFile=./XShareAuto.jsa" ,
60+ "-Xlog:cds" ,
61+ x ,
62+ "-version" );
63+ output = new OutputAnalyzer (pb .start ());
64+ String outputString = output .getOutput ();
65+
66+ if (!outputString .contains ("Unable to map" )) {
67+ // sharing may not be enabled if XShareAuto.jsa cannot be mapped due to
68+ // ASLR.
69+ output .shouldContain ("sharing" );
70+ }
71+ output .shouldHaveExitValue (0 );
7572 }
76- output .shouldHaveExitValue (0 );
7773 }
7874}
0 commit comments