1 /* 2 * Copyright (c) 2017, 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 * @summary Similar to GCDuringDumping.java, this test adds the -XX:SharedArchiveConfigFile 28 * option for testing the interaction with GC and shared strings. 29 * @library /test/lib /test/hotspot/jtreg/runtime/appcds /test/hotspot/jtreg/runtime/appcds/test-classes 30 * @requires vm.cds.archived.java.heap 31 * @modules java.base/jdk.internal.misc 32 * jdk.jartool/sun.tools.jar 33 * java.management 34 * @build sun.hotspot.WhiteBox GCDuringDumpTransformer GCSharedStringsDuringDumpWb 35 * @run driver ClassFileInstaller sun.hotspot.WhiteBox 36 * @run main/othervm/timeout=480 GCSharedStringsDuringDump 37 */ 38 39 import java.io.File; 40 import java.io.FileOutputStream; 41 import java.io.OutputStreamWriter; 42 import java.io.PrintWriter; 43 import jdk.test.lib.cds.CDSOptions; 44 import jdk.test.lib.process.OutputAnalyzer; 45 import jdk.test.lib.process.ProcessTools; 46 import sun.hotspot.WhiteBox; 47 48 public class GCSharedStringsDuringDump { 49 public static String appClasses[] = { 50 "GCSharedStringsDuringDumpWb", 51 }; 52 public static String agentClasses[] = { 53 "GCDuringDumpTransformer", 54 }; 55 56 public static void main(String[] args) throws Throwable { 57 String agentJar = 58 ClassFileInstaller.writeJar("GCDuringDumpTransformer.jar", 59 ClassFileInstaller.Manifest.fromSourceFile("GCDuringDumpTransformer.mf"), 60 agentClasses); 61 62 String appJar = 63 ClassFileInstaller.writeJar("GCSharedStringsDuringDumpApp.jar", appClasses); 64 65 String sharedArchiveCfgFile = 66 System.getProperty("user.dir") + File.separator + "GCSharedStringDuringDump_gen.txt"; 67 try (FileOutputStream fos = new FileOutputStream(sharedArchiveCfgFile)) { 68 PrintWriter out = new PrintWriter(new OutputStreamWriter(fos)); 69 out.println("VERSION: 1.0"); 70 out.println("@SECTION: String"); 71 out.println("31: shared_test_string_unique_14325"); 72 for (int i=0; i<100000; i++) { 73 String s = "generated_string " + i; 74 out.println(s.length() + ": " + s); 75 } 76 out.close(); 77 } 78 79 JarBuilder.build(true, "WhiteBox", "sun/hotspot/WhiteBox"); 80 String whiteBoxJar = TestCommon.getTestJar("WhiteBox.jar"); 81 String bootClassPath = "-Xbootclasspath/a:" + whiteBoxJar; 82 83 for (int i=0; i<2; i++) { 84 // i = 0 -- run without agent = no extra GCs 85 // i = 1 -- run with agent = cause extra GCs 86 87 String extraArg = (i == 0) ? "-showversion" : "-javaagent:" + agentJar; 88 89 OutputAnalyzer output = TestCommon.dump( 90 appJar, TestCommon.list("GCSharedStringsDuringDumpWb"), 91 bootClassPath, extraArg, "-Xmx32m", 92 "-XX:SharedArchiveConfigFile=" + sharedArchiveCfgFile); 93 94 if (output.getStdout().contains("Too many string space regions") || 95 output.getStderr().contains("Unable to write archive heap memory regions") || 96 output.getStdout().contains("Try increasing NewSize") || 97 !output.getStdout().contains("oa0 space:") || 98 output.getExitValue() != 0) { 99 // Try again with larger heap and NewSize, this should increase the 100 // G1 heap region size to 2M 101 TestCommon.testDump( 102 appJar, TestCommon.list("GCSharedStringsDuringDumpWb"), 103 bootClassPath, extraArg, "-Xmx8g", "-XX:NewSize=8m", 104 "-XX:SharedArchiveConfigFile=" + sharedArchiveCfgFile); 105 } 106 107 TestCommon.run( 108 "-cp", appJar, 109 bootClassPath, 110 "-Xmx32m", 111 "-XX:+PrintSharedSpaces", 112 "-XX:+UnlockDiagnosticVMOptions", 113 "-XX:+WhiteBoxAPI", 114 "-XX:SharedReadOnlySize=30m", 115 "GCSharedStringsDuringDumpWb") 116 .assertNormalExit(); 117 } 118 } 119 } 120