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 import java.io.File; 26 import java.nio.charset.Charset; 27 import java.nio.file.Files; 28 import java.nio.file.Path; 29 import java.nio.file.Paths; 30 import java.util.List; 31 import java.util.ArrayList; 32 33 /* 34 * @test 35 * @summary Try to archive lots of classes by searching for classes from the jrt:/ file system. With JDK 12 36 * this will produce an archive with over 30,000 classes. 37 * @requires vm.cds 38 * @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds /test/hotspot/jtreg/runtime/cds/appcds/dynamicArchive/test-classes 39 * @build LoadClasses 40 * @build sun.hotspot.WhiteBox 41 * @run driver ClassFileInstaller -jar loadclasses.jar LoadClasses 42 * @run driver ClassFileInstaller -jar whitebox.jar sun.hotspot.WhiteBox sun.hotspot.WhiteBox$WhiteBoxPermission 43 * @run main/othervm/timeout=500 -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:./whitebox.jar DynamicLotsOfClasses 44 */ 45 46 public class DynamicLotsOfClasses extends DynamicArchiveTestBase { 47 48 public static void main(String[] args) throws Exception { 49 runTest(DynamicLotsOfClasses::testDefaultBase); 50 } 51 52 static void testDefaultBase() throws Exception { 53 String topArchiveName = getNewArchiveName("top"); 54 doTest(topArchiveName); 55 } 56 57 private static void doTest(String topArchiveName) throws Exception { 58 ArrayList<String> list = new ArrayList<>(); 59 TestCommon.findAllClasses(list); 60 61 String classList = System.getProperty("user.dir") + File.separator + 62 "LotsOfClasses.list"; 63 List<String> lines = list; 64 Path file = Paths.get(classList); 65 Files.write(file, lines, Charset.forName("UTF-8")); 66 67 String appJar = ClassFileInstaller.getJarPath("loadclasses.jar"); 68 String mainClass = "LoadClasses"; 69 70 String whiteBoxJar = ClassFileInstaller.getJarPath("whitebox.jar"); 71 String bootClassPath = "-Xbootclasspath/a:" + whiteBoxJar; 72 dump(topArchiveName, 73 "--add-modules", 74 "ALL-SYSTEM", 75 "-Xlog:hashtables", 76 "-Xmx500m", 77 "-Xlog:cds,cds+dynamic", 78 bootClassPath, 79 "-XX:+UnlockDiagnosticVMOptions", "-XX:+WhiteBoxAPI", 80 "-cp", appJar, mainClass, classList) 81 .assertNormalExit(output -> { 82 output.shouldContain("Buffer-space to target-space delta") 83 .shouldContain("Written dynamic archive 0x"); 84 }); 85 } 86 }