1 /* 2 * Copyright (c) 2019, 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 non-empty dir in -cp should be fine during dump time if only classes 28 * from the system modules are being loaded even though some are 29 * defined to the PlatformClassLoader and AppClassLoader. 30 * @requires vm.cds 31 * @library /test/lib /test/hotspot/jtreg/runtime/appcds 32 * @modules jdk.jartool/sun.tools.jar 33 * @compile ../test-classes/Hello.java 34 * @run main/othervm -Dtest.cds.copy.child.stdout=false UnusedCPDuringDump 35 */ 36 37 import java.io.File; 38 39 public class UnusedCPDuringDump extends DynamicArchiveTestBase { 40 41 public static void main(String[] args) throws Exception { 42 runTest(UnusedCPDuringDump::testDefaultBase); 43 } 44 45 static void testDefaultBase() throws Exception { 46 String topArchiveName = getNewArchiveName("top"); 47 doTest(topArchiveName); 48 } 49 50 private static void doTest(String topArchiveName) throws Exception { 51 File dir = new File(System.getProperty("user.dir")); 52 File emptydir = new File(dir, "emptydir"); 53 emptydir.mkdir(); 54 String appJar = JarBuilder.getOrCreateHelloJar(); 55 String bootClassPath = "-Xbootclasspath/a:" + appJar; 56 57 // Dumping with a non-empty directory in the -cp. 58 // It should be fine because the app class won't be loaded from the 59 // -cp, it is being loaded from the bootclasspath. 60 dump(topArchiveName, 61 "-Xlog:cds", 62 "-Xlog:cds+dynamic=debug", 63 bootClassPath, 64 "-cp", dir.getPath(), 65 "Hello") 66 .assertNormalExit(output -> { 67 output.shouldContain("Buffer-space to target-space delta") 68 .shouldContain("Written dynamic archive 0x"); 69 }); 70 71 // Running with -cp different from dumping. It should be fine because 72 // the runtime classpath won't be checked against unused classpath 73 // during dump time. 74 run(topArchiveName, 75 "-Xlog:class+load", 76 "-Xlog:cds+dynamic=debug,cds=debug", 77 bootClassPath, 78 "-cp", appJar, "Hello") 79 .assertNormalExit(output -> { 80 output.shouldContain("Hello World") 81 .shouldHaveExitValue(0); 82 }); 83 } 84 }