1 /*
   2  * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 /*
  26  * @test
  27  * @summary Try different combination of mismatched UseAppCDS between dump time and run time.
  28  * @requires vm.cds
  29  * @library /test/lib
  30  * @modules java.base/jdk.internal.misc
  31  *          java.management
  32  *          jdk.jartool/sun.tools.jar
  33  * @compile test-classes/CheckIfShared.java
  34  * @build sun.hotspot.WhiteBox
  35  * @run driver ClassFileInstaller sun.hotspot.WhiteBox
  36  * @run main MismatchedUseAppCDS
  37  */
  38 
  39 import jdk.test.lib.process.OutputAnalyzer;
  40 
  41 public class MismatchedUseAppCDS {
  42   public static void main(String[] args) throws Exception {
  43     String wbJar = JarBuilder.build(true, "WhiteBox", "sun/hotspot/WhiteBox");
  44     String use_whitebox_jar = "-Xbootclasspath/a:" + wbJar;
  45 
  46     String appJar = JarBuilder.build("MismatchedUseAppCDS", "CheckIfShared");
  47 
  48     OutputAnalyzer output;
  49 
  50     // (1): dump with -XX:+UseAppCDS, but run with -XX:-UseAppCDS
  51     TestCommon.testDump(appJar, TestCommon.list("CheckIfShared"),
  52                         // command-line arguments ...
  53                         "-XX:+UseAppCDS",
  54                         use_whitebox_jar);
  55 
  56     output = TestCommon.exec(appJar,
  57                              // command-line arguments ...
  58                              use_whitebox_jar,
  59                              "-XX:-UseAppCDS",
  60                              "-XX:+UnlockDiagnosticVMOptions",
  61                              "-XX:+WhiteBoxAPI",
  62                              "CheckIfShared", "false");
  63     TestCommon.checkExec(output);
  64 
  65     // (2): dump with -XX:-UseAppCDS, but run with -XX:+UseAppCDS
  66     TestCommon.testDump(appJar, TestCommon.list("CheckIfShared"),
  67                         // command-line arguments ...
  68                         "-XX:-UseAppCDS",
  69                         use_whitebox_jar);
  70 
  71     output = TestCommon.exec(appJar,
  72                              // command-line arguments ...
  73                              use_whitebox_jar,
  74                              "-XX:+UseAppCDS",
  75                              "-XX:+UnlockDiagnosticVMOptions",
  76                              "-XX:+WhiteBoxAPI",
  77                              "CheckIfShared", "false");
  78     TestCommon.checkExec(output);
  79   }
  80 }