8066670: PrintSharedArchiveAndExit does not exit the VM when the archive is invalid

Thu, 04 Dec 2014 15:20:09 -0800

author
iklam
date
Thu, 04 Dec 2014 15:20:09 -0800
changeset 7414
0558eb13dcf3
parent 7413
9c8dbbd8694a
child 7415
b6585ac86988

8066670: PrintSharedArchiveAndExit does not exit the VM when the archive is invalid
Summary: in FileMapInfo::fail_continue do not set UseSharedSpaces = false
Reviewed-by: dholmes, ccheung

src/share/vm/memory/filemap.cpp file | annotate | diff | comparison | revisions
src/share/vm/memory/metaspaceShared.cpp file | annotate | diff | comparison | revisions
test/runtime/SharedArchiveFile/PrintSharedArchiveAndExit.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/vm/memory/filemap.cpp	Fri Dec 05 10:04:37 2014 -0800
     1.2 +++ b/src/share/vm/memory/filemap.cpp	Thu Dec 04 15:20:09 2014 -0800
     1.3 @@ -97,11 +97,11 @@
     1.4          tty->print_cr("UseSharedSpaces: %s", msg);
     1.5        }
     1.6      }
     1.7 +    UseSharedSpaces = false;
     1.8 +    assert(current_info() != NULL, "singleton must be registered");
     1.9 +    current_info()->close();
    1.10    }
    1.11    va_end(ap);
    1.12 -  UseSharedSpaces = false;
    1.13 -  assert(current_info() != NULL, "singleton must be registered");
    1.14 -  current_info()->close();
    1.15  }
    1.16  
    1.17  // Fill in the fileMapInfo structure with data about this VM instance.
     2.1 --- a/src/share/vm/memory/metaspaceShared.cpp	Fri Dec 05 10:04:37 2014 -0800
     2.2 +++ b/src/share/vm/memory/metaspaceShared.cpp	Thu Dec 04 15:20:09 2014 -0800
     2.3 @@ -967,7 +967,7 @@
     2.4  #endif
     2.5      // If -Xshare:on is specified, print out the error message and exit VM,
     2.6      // otherwise, set UseSharedSpaces to false and continue.
     2.7 -    if (RequireSharedSpaces) {
     2.8 +    if (RequireSharedSpaces || PrintSharedArchiveAndExit) {
     2.9        vm_exit_during_initialization("Unable to use shared archive.", "Failed map_region for using -Xshare:on.");
    2.10      } else {
    2.11        FLAG_SET_DEFAULT(UseSharedSpaces, false);
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/runtime/SharedArchiveFile/PrintSharedArchiveAndExit.java	Thu Dec 04 15:20:09 2014 -0800
     3.3 @@ -0,0 +1,83 @@
     3.4 +/*
     3.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
     3.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3.7 + *
     3.8 + * This code is free software; you can redistribute it and/or modify it
     3.9 + * under the terms of the GNU General Public License version 2 only, as
    3.10 + * published by the Free Software Foundation.
    3.11 + *
    3.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    3.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    3.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    3.15 + * version 2 for more details (a copy is included in the LICENSE file that
    3.16 + * accompanied this code).
    3.17 + *
    3.18 + * You should have received a copy of the GNU General Public License version
    3.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    3.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    3.21 + *
    3.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    3.23 + * or visit www.oracle.com if you need additional information or have any
    3.24 + * questions.
    3.25 + */
    3.26 +
    3.27 +/*
    3.28 + * @test
    3.29 + * @bug 8066670
    3.30 + * @summary Testing -XX:+PrintSharedArchiveAndExit option
    3.31 + * @library /testlibrary
    3.32 + */
    3.33 +
    3.34 +import com.oracle.java.testlibrary.*;
    3.35 +
    3.36 +public class PrintSharedArchiveAndExit {
    3.37 +  public static void main(String[] args) throws Exception {
    3.38 +    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
    3.39 +        "-XX:+UnlockDiagnosticVMOptions", "-XX:SharedArchiveFile=./sample.jsa", "-Xshare:dump");
    3.40 +    OutputAnalyzer output = new OutputAnalyzer(pb.start());
    3.41 +    try {
    3.42 +      output.shouldContain("Loading classes to share");
    3.43 +      output.shouldHaveExitValue(0);
    3.44 +
    3.45 +      // (1) With a valid archive
    3.46 +      pb = ProcessTools.createJavaProcessBuilder(
    3.47 +          "-XX:+UnlockDiagnosticVMOptions", "-XX:SharedArchiveFile=./sample.jsa",
    3.48 +          "-XX:+PrintSharedArchiveAndExit", "-version");
    3.49 +      output = new OutputAnalyzer(pb.start());
    3.50 +      output.shouldContain("archive is valid");
    3.51 +      output.shouldNotContain("java version");     // Should not print JVM version
    3.52 +      output.shouldHaveExitValue(0);               // Should report success in error code.
    3.53 +
    3.54 +      pb = ProcessTools.createJavaProcessBuilder(
    3.55 +          "-XX:+UnlockDiagnosticVMOptions", "-XX:SharedArchiveFile=./sample.jsa",
    3.56 +          "-XX:+PrintSharedArchiveAndExit");
    3.57 +      output = new OutputAnalyzer(pb.start());
    3.58 +      output.shouldContain("archive is valid");
    3.59 +      output.shouldNotContain("Usage:");           // Should not print JVM help message
    3.60 +      output.shouldHaveExitValue(0);               // Should report success in error code.
    3.61 +
    3.62 +      // (2) With an invalid archive (boot class path has been prepended)
    3.63 +      pb = ProcessTools.createJavaProcessBuilder(
    3.64 +          "-Xbootclasspath/p:foo.jar",
    3.65 +          "-XX:+UnlockDiagnosticVMOptions", "-XX:SharedArchiveFile=./sample.jsa",
    3.66 +          "-XX:+PrintSharedArchiveAndExit", "-version");
    3.67 +      output = new OutputAnalyzer(pb.start());
    3.68 +      output.shouldContain("archive is invalid");
    3.69 +      output.shouldNotContain("java version");     // Should not print JVM version
    3.70 +      output.shouldHaveExitValue(1);               // Should report failure in error code.
    3.71 +
    3.72 +      pb = ProcessTools.createJavaProcessBuilder(
    3.73 +          "-Xbootclasspath/p:foo.jar",
    3.74 +          "-XX:+UnlockDiagnosticVMOptions", "-XX:SharedArchiveFile=./sample.jsa",
    3.75 +          "-XX:+PrintSharedArchiveAndExit");
    3.76 +      output = new OutputAnalyzer(pb.start());
    3.77 +      output.shouldContain("archive is invalid");
    3.78 +      output.shouldNotContain("Usage:");           // Should not print JVM help message
    3.79 +      output.shouldHaveExitValue(1);               // Should report failure in error code.
    3.80 +    } catch (RuntimeException e) {
    3.81 +      e.printStackTrace();
    3.82 +      output.shouldContain("Unable to use shared archive");
    3.83 +      output.shouldHaveExitValue(1);
    3.84 +    }
    3.85 +  }
    3.86 +}

mercurial