1 /* 2 * Copyright (c) 2017, 2020, 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 When dumping the CDS archive, try to cause garbage collection while classes are being loaded. 28 * @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds /test/hotspot/jtreg/runtime/cds/appcds/test-classes 29 * @requires vm.cds 30 * @requires vm.flavor != "minimal" 31 * @run driver GCDuringDump 32 */ 33 34 import jdk.test.lib.cds.CDSOptions; 35 import jdk.test.lib.process.OutputAnalyzer; 36 import jdk.test.lib.process.ProcessTools; 37 38 public class GCDuringDump { 39 public static String appClasses[] = { 40 Hello.class.getName(), 41 }; 42 public static String agentClasses[] = { 43 GCDuringDumpTransformer.class.getName(), 44 GCDuringDumpTransformer.MyCleaner.class.getName(), 45 }; 46 47 public static void main(String[] args) throws Throwable { 48 String agentJar = 49 ClassFileInstaller.writeJar("GCDuringDumpTransformer.jar", 50 ClassFileInstaller.Manifest.fromSourceFile("GCDuringDumpTransformer.mf"), 51 agentClasses); 52 53 String appJar = 54 ClassFileInstaller.writeJar("GCDuringDumpApp.jar", appClasses); 55 56 String gcLog = Boolean.getBoolean("test.cds.verbose.gc") ? 57 "-Xlog:gc*=info,gc+region=trace,gc+alloc+region=debug" : "-showversion"; 58 59 for (int i=0; i<3; i++) { 60 // i = 0 -- run without agent = no extra GCs 61 // i = 1 -- run with agent = cause extra GCs 62 // i = 2 -- run with agent = cause extra GCs + use java.lang.ref.Cleaner 63 64 String extraArg = (i == 0) ? "-showversion" : "-javaagent:" + agentJar; 65 String extraOption = (i == 0) ? "-showversion" : "-XX:+AllowArchivingWithJavaAgent"; 66 String extraOption2 = (i != 2) ? "-showversion" : "-Dtest.with.cleaner=true"; 67 68 TestCommon.testDump(appJar, TestCommon.list(Hello.class.getName()), 69 "-XX:+UnlockDiagnosticVMOptions", extraOption, extraOption2, 70 "-Xlog:exceptions=trace", 71 extraArg, "-Xmx32m", gcLog); 72 73 TestCommon.run( 74 "-cp", appJar, 75 "-Xmx32m", 76 "-XX:+PrintSharedSpaces", 77 "-XX:+UnlockDiagnosticVMOptions", extraOption, 78 gcLog, 79 Hello.class.getName()) 80 .assertNormalExit(); 81 } 82 } 83 } 84