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/appcds /test/hotspot/jtreg/runtime/appcds/dynamicArchive/test-classes |
|
39 * @build LoadClasses |
|
40 * @build sun.hotspot.WhiteBox |
|
41 * @modules jdk.jartool/sun.tools.jar |
|
42 * @run driver ClassFileInstaller -jar loadclasses.jar LoadClasses |
|
43 * @run driver ClassFileInstaller -jar whitebox.jar sun.hotspot.WhiteBox |
|
44 * @run driver/timeout=500 DynamicLotsOfClasses |
|
45 */ |
|
46 |
|
47 public class DynamicLotsOfClasses extends DynamicArchiveTestBase { |
|
48 |
|
49 public static void main(String[] args) throws Throwable { |
|
50 runTest(DynamicLotsOfClasses::testDefaultBase); |
|
51 } |
|
52 |
|
53 static void testDefaultBase() throws Exception { |
|
54 String topArchiveName = getNewArchiveName("top"); |
|
55 try { |
|
56 doTest(topArchiveName); |
|
57 } catch (Throwable th) { |
|
58 System.out.println(th.toString()); |
|
59 Exception ex = new Exception(th); |
|
60 throw ex; |
|
61 } |
|
62 } |
|
63 |
|
64 private static void doTest(String topArchiveName) throws Throwable { |
|
65 ArrayList<String> list = new ArrayList<>(); |
|
66 TestCommon.findAllClasses(list); |
|
67 |
|
68 String classList = System.getProperty("user.dir") + File.separator + |
|
69 "LotsOfClasses.list"; |
|
70 List<String> lines = list; |
|
71 Path file = Paths.get(classList); |
|
72 Files.write(file, lines, Charset.forName("UTF-8")); |
|
73 |
|
74 String appJar = ClassFileInstaller.getJarPath("loadclasses.jar"); |
|
75 String mainClass = "LoadClasses"; |
|
76 |
|
77 String whiteBoxJar = ClassFileInstaller.getJarPath("whitebox.jar"); |
|
78 String bootClassPath = "-Xbootclasspath/a:" + whiteBoxJar; |
|
79 dump(topArchiveName, |
|
80 "--add-modules", |
|
81 "ALL-SYSTEM", |
|
82 "-Xlog:hashtables", |
|
83 "-Xmx500m", |
|
84 "-Xlog:cds,cds+dynamic", |
|
85 bootClassPath, |
|
86 "-XX:+UnlockDiagnosticVMOptions", "-XX:+WhiteBoxAPI", |
|
87 "-cp", appJar, mainClass, classList) |
|
88 .assertNormalExit(output -> { |
|
89 output.shouldContain("Buffer-space to target-space delta") |
|
90 .shouldContain("Written dynamic archive 0x"); |
|
91 }); |
|
92 } |
|
93 } |
|