author | erikj |
Tue, 12 Sep 2017 19:03:39 +0200 | |
changeset 47216 | 71c04702a3d5 |
parent 46779 | hotspot/test/runtime/SharedArchiveFile/SpaceUtilizationCheck.java@d80ca591ae48 |
child 47574 | 15294343ba19 |
permissions | -rw-r--r-- |
24840
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
1 |
/* |
46389 | 2 |
* Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved. |
24840
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
4 |
* |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
8 |
* |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
13 |
* accompanied this code). |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
14 |
* |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
18 |
* |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
21 |
* questions. |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
22 |
*/ |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
23 |
|
46779
d80ca591ae48
8185436: jtreg: introduce @requires property to disable cds tests
goetz
parents:
46746
diff
changeset
|
24 |
/** |
24840
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
25 |
* @test SpaceUtilizationCheck |
46779
d80ca591ae48
8185436: jtreg: introduce @requires property to disable cds tests
goetz
parents:
46746
diff
changeset
|
26 |
* @requires vm.cds |
24840
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
27 |
* @summary Check if the space utilization for shared spaces is adequate |
46417
1593c061e6af
8179243: [TESTBUG] CDS tests should be excluded from running with -UseCompressedOops
mseledtsov
parents:
46389
diff
changeset
|
28 |
* @requires (vm.opt.UseCompressedOops == null) | (vm.opt.UseCompressedOops == true) |
40631
ed82623d7831
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
36851
diff
changeset
|
29 |
* @library /test/lib |
36851 | 30 |
* @modules java.base/jdk.internal.misc |
29678
dd2f3932c21e
8075586: Add @modules as needed to the open hotspot tests
ykantser
parents:
24840
diff
changeset
|
31 |
* java.management |
46746
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46417
diff
changeset
|
32 |
* @build sun.hotspot.WhiteBox |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46417
diff
changeset
|
33 |
* @run main ClassFileInstaller sun.hotspot.WhiteBox |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46417
diff
changeset
|
34 |
* sun.hotspot.WhiteBox$WhiteBoxPermission |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46417
diff
changeset
|
35 |
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI SpaceUtilizationCheck |
24840
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
36 |
*/ |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
37 |
|
46389 | 38 |
import jdk.test.lib.cds.CDSTestUtils; |
40631
ed82623d7831
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
36851
diff
changeset
|
39 |
import jdk.test.lib.process.OutputAnalyzer; |
46746
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46417
diff
changeset
|
40 |
import sun.hotspot.WhiteBox; |
24840
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
41 |
|
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
42 |
import java.util.regex.Pattern; |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
43 |
import java.util.regex.Matcher; |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
44 |
import java.util.ArrayList; |
46746
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46417
diff
changeset
|
45 |
import java.util.Hashtable; |
24840
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
46 |
import java.lang.Integer; |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
47 |
|
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
48 |
public class SpaceUtilizationCheck { |
46746
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46417
diff
changeset
|
49 |
// [1] Each region must have strictly less than |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46417
diff
changeset
|
50 |
// WhiteBox.metaspaceReserveAlignment() bytes of unused space. |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46417
diff
changeset
|
51 |
// [2] There must be no gap between two consecutive regions. |
24840
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
52 |
|
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
53 |
public static void main(String[] args) throws Exception { |
46746
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46417
diff
changeset
|
54 |
// (1) Default VM arguments |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46417
diff
changeset
|
55 |
test(); |
24840
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
56 |
|
46746
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46417
diff
changeset
|
57 |
// (2) Use the now deprecated VM arguments. They should have no effect. |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46417
diff
changeset
|
58 |
test("-XX:SharedReadWriteSize=128M", |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46417
diff
changeset
|
59 |
"-XX:SharedReadOnlySize=128M", |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46417
diff
changeset
|
60 |
"-XX:SharedMiscDataSize=128M", |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46417
diff
changeset
|
61 |
"-XX:SharedMiscCodeSize=128M"); |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46417
diff
changeset
|
62 |
} |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46417
diff
changeset
|
63 |
|
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46417
diff
changeset
|
64 |
static void test(String... extra_options) throws Exception { |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46417
diff
changeset
|
65 |
OutputAnalyzer output = CDSTestUtils.createArchive(extra_options); |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46417
diff
changeset
|
66 |
CDSTestUtils.checkDump(output); |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46417
diff
changeset
|
67 |
Pattern pattern = Pattern.compile("^(..) space: *([0-9]+).* out of *([0-9]+) bytes .* at 0x([0-9a0-f]+)"); |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46417
diff
changeset
|
68 |
WhiteBox wb = WhiteBox.getWhiteBox(); |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46417
diff
changeset
|
69 |
long reserve_alignment = wb.metaspaceReserveAlignment(); |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46417
diff
changeset
|
70 |
System.out.println("Metaspace::reserve_alignment() = " + reserve_alignment); |
24840
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
71 |
|
46746
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46417
diff
changeset
|
72 |
long last_region = -1; |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46417
diff
changeset
|
73 |
Hashtable<String,String> checked = new Hashtable<>(); |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46417
diff
changeset
|
74 |
for (String line : output.getStdout().split("\n")) { |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46417
diff
changeset
|
75 |
if (line.contains(" space:") && !line.contains("st space:")) { |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46417
diff
changeset
|
76 |
Matcher matcher = pattern.matcher(line); |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46417
diff
changeset
|
77 |
if (matcher.find()) { |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46417
diff
changeset
|
78 |
String name = matcher.group(1); |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46417
diff
changeset
|
79 |
if (name.equals("s0") || name.equals("s1")) { |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46417
diff
changeset
|
80 |
// String regions are listed at the end and they may not be fully occupied. |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46417
diff
changeset
|
81 |
break; |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46417
diff
changeset
|
82 |
} else { |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46417
diff
changeset
|
83 |
System.out.println("Checking " + name + " in : " + line); |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46417
diff
changeset
|
84 |
checked.put(name, name); |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46417
diff
changeset
|
85 |
} |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46417
diff
changeset
|
86 |
long used = Long.parseLong(matcher.group(2)); |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46417
diff
changeset
|
87 |
long capacity = Long.parseLong(matcher.group(3)); |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46417
diff
changeset
|
88 |
long address = Long.parseLong(matcher.group(4), 16); |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46417
diff
changeset
|
89 |
long unused = capacity - used; |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46417
diff
changeset
|
90 |
if (unused < 0) { |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46417
diff
changeset
|
91 |
throw new RuntimeException("Unused space (" + unused + ") less than 0"); |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46417
diff
changeset
|
92 |
} |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46417
diff
changeset
|
93 |
if (unused > reserve_alignment) { |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46417
diff
changeset
|
94 |
// [1] Check for unused space |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46417
diff
changeset
|
95 |
throw new RuntimeException("Unused space (" + unused + ") must be smaller than Metaspace::reserve_alignment() (" + |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46417
diff
changeset
|
96 |
reserve_alignment + ")"); |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46417
diff
changeset
|
97 |
} |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46417
diff
changeset
|
98 |
if (last_region >= 0 && address != last_region) { |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46417
diff
changeset
|
99 |
// [2] Check for no-gap |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46417
diff
changeset
|
100 |
throw new RuntimeException("Region 0x" + address + " should have started at 0x" + Long.toString(last_region, 16)); |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46417
diff
changeset
|
101 |
} |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46417
diff
changeset
|
102 |
last_region = address + capacity; |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46417
diff
changeset
|
103 |
} |
24840
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
104 |
} |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
105 |
} |
46746
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46417
diff
changeset
|
106 |
if (checked.size() != 5) { |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46417
diff
changeset
|
107 |
throw new RuntimeException("Must have 5 consecutive, fully utilized regions"); |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46417
diff
changeset
|
108 |
} |
24840
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
109 |
} |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
110 |
} |