author | jiangli |
Tue, 27 Nov 2018 17:53:17 -0500 | |
changeset 52702 | 10c6e9066819 |
parent 52631 | 3009ca99de32 |
child 52811 | ff04b71bf6f1 |
permissions | -rw-r--r-- |
52631
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
1 |
/* |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
2 |
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
4 |
* |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
8 |
* |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
13 |
* accompanied this code). |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
14 |
* |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
18 |
* |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
21 |
* questions. |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
22 |
* |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
23 |
*/ |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
24 |
|
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
25 |
import java.net.URI; |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
26 |
import java.nio.file.DirectoryStream; |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
27 |
import java.nio.file.Files; |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
28 |
import java.nio.file.FileSystem; |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
29 |
import java.nio.file.FileSystems; |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
30 |
import java.nio.file.Path; |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
31 |
import java.util.ArrayList; |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
32 |
import java.util.regex.Matcher; |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
33 |
import java.util.regex.Pattern; |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
34 |
|
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
35 |
import jdk.test.lib.cds.CDSTestUtils; |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
36 |
import jdk.test.lib.cds.CDSOptions; |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
37 |
import jdk.test.lib.process.OutputAnalyzer; |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
38 |
|
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
39 |
/* |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
40 |
* @test |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
41 |
* @summary Try to archive lots of classes by searching for classes from the jrt:/ file system. With JDK 12 |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
42 |
* this will produce an archive with over 30,000 classes. |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
43 |
* @requires vm.cds |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
44 |
* @library /test/lib |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
45 |
* @run driver/timeout=500 LotsOfClasses |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
46 |
*/ |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
47 |
|
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
48 |
public class LotsOfClasses { |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
49 |
static Pattern pattern; |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
50 |
|
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
51 |
public static void main(String[] args) throws Throwable { |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
52 |
ArrayList<String> list = new ArrayList<>(); |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
53 |
findAllClasses(list); |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
54 |
|
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
55 |
CDSOptions opts = new CDSOptions(); |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
56 |
opts.setClassList(list); |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
57 |
opts.addSuffix("--add-modules"); |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
58 |
opts.addSuffix("ALL-SYSTEM"); |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
59 |
opts.addSuffix("-Xlog:hashtables"); |
52702
10c6e9066819
8214217: [TESTBUG] runtime/appcds/LotsOfClasses.java failed with fragmented heap
jiangli
parents:
52631
diff
changeset
|
60 |
opts.addSuffix("-Xms500m"); |
10c6e9066819
8214217: [TESTBUG] runtime/appcds/LotsOfClasses.java failed with fragmented heap
jiangli
parents:
52631
diff
changeset
|
61 |
opts.addSuffix("-Xmx500m"); |
52631
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
62 |
|
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
63 |
OutputAnalyzer out = CDSTestUtils.createArchive(opts); |
52702
10c6e9066819
8214217: [TESTBUG] runtime/appcds/LotsOfClasses.java failed with fragmented heap
jiangli
parents:
52631
diff
changeset
|
64 |
try { |
10c6e9066819
8214217: [TESTBUG] runtime/appcds/LotsOfClasses.java failed with fragmented heap
jiangli
parents:
52631
diff
changeset
|
65 |
CDSTestUtils.checkDump(out); |
10c6e9066819
8214217: [TESTBUG] runtime/appcds/LotsOfClasses.java failed with fragmented heap
jiangli
parents:
52631
diff
changeset
|
66 |
} catch (java.lang.RuntimeException re) { |
10c6e9066819
8214217: [TESTBUG] runtime/appcds/LotsOfClasses.java failed with fragmented heap
jiangli
parents:
52631
diff
changeset
|
67 |
out.shouldContain( |
10c6e9066819
8214217: [TESTBUG] runtime/appcds/LotsOfClasses.java failed with fragmented heap
jiangli
parents:
52631
diff
changeset
|
68 |
"number of memory regions exceeds maximum due to fragmentation"); |
10c6e9066819
8214217: [TESTBUG] runtime/appcds/LotsOfClasses.java failed with fragmented heap
jiangli
parents:
52631
diff
changeset
|
69 |
} |
52631
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
70 |
} |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
71 |
|
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
72 |
static void findAllClasses(ArrayList<String> list) throws Throwable { |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
73 |
// Find all the classes in the jrt file system |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
74 |
pattern = Pattern.compile("/modules/[a-z.]*[a-z]+/([^-]*)[.]class"); |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
75 |
FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/")); |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
76 |
Path base = fs.getPath("/modules/"); |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
77 |
find(base, list); |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
78 |
} |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
79 |
|
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
80 |
static void find(Path p, ArrayList<String> list) throws Throwable { |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
81 |
try (DirectoryStream<Path> stream = Files.newDirectoryStream(p)) { |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
82 |
for (Path entry: stream) { |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
83 |
Matcher matcher = pattern.matcher(entry.toString()); |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
84 |
if (matcher.find()) { |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
85 |
String className = matcher.group(1); |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
86 |
list.add(className); |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
87 |
//System.out.println(className); |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
88 |
} |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
89 |
try { |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
90 |
find(entry, list); |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
91 |
} catch (Throwable t) {} |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
92 |
} |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
93 |
} |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
94 |
} |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
diff
changeset
|
95 |
} |