1 /*
   2  * Copyright (c) 2018, 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  * @bug 8209385
  28  * @summary non-empty dir in -cp should be fine during dump time if only classes
  29  *          from the system modules are being loaded even though some are
  30  *          defined to the PlatformClassLoader and AppClassLoader.
  31  * @requires vm.cds
  32  * @library /test/lib
  33  * @modules jdk.jartool/sun.tools.jar
  34  * @compile test-classes/Hello.java
  35  * @run main/othervm -Dtest.cds.copy.child.stdout=false UnusedCPDuringDump
  36  */
  37 
  38 import java.io.File;
  39 import jdk.test.lib.process.OutputAnalyzer;
  40 
  41 public class UnusedCPDuringDump {
  42 
  43     public static void main(String[] args) throws Exception {
  44         File dir = new File(System.getProperty("user.dir"));
  45         File emptydir = new File(dir, "emptydir");
  46         emptydir.mkdir();
  47         String appJar = JarBuilder.getOrCreateHelloJar();
  48 
  49         OutputAnalyzer output = TestCommon.dump(dir.getPath(),
  50             TestCommon.list("sun/util/resources/cldr/provider/CLDRLocaleDataMetaInfo",
  51                             "com/sun/tools/sjavac/client/ClientMain"),
  52                             "-Xlog:class+path=info,class+load=debug");
  53         TestCommon.checkDump(output,
  54                              "[class,load] sun.util.resources.cldr.provider.CLDRLocaleDataMetaInfo",
  55                              "for instance a 'jdk/internal/loader/ClassLoaders$PlatformClassLoader'",
  56                              "[class,load] com.sun.tools.sjavac.client.ClientMain",
  57                              "for instance a 'jdk/internal/loader/ClassLoaders$AppClassLoader'");
  58 
  59         String jsaOpt = "-XX:SharedArchiveFile=" + TestCommon.getCurrentArchiveName();
  60         TestCommon.run("-cp", appJar, jsaOpt, "-Xlog:class+path=info,class+load=debug", "Hello")
  61             .assertNormalExit("Hello World");
  62   }
  63 }