author | tschatzl |
Wed, 19 Aug 2015 13:47:40 +0200 | |
changeset 32377 | 5ee15c417d02 |
parent 30604 | b8d532cb6420 |
child 36851 | 03e2f4d0a421 |
permissions | -rw-r--r-- |
24840
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
1 |
/* |
29678
dd2f3932c21e
8075586: Add @modules as needed to the open hotspot tests
ykantser
parents:
24840
diff
changeset
|
2 |
* Copyright (c) 2014, 2015, 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 |
|
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
24 |
/* |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
25 |
* @test SpaceUtilizationCheck |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
26 |
* @summary Check if the space utilization for shared spaces is adequate |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
27 |
* @library /testlibrary |
29678
dd2f3932c21e
8075586: Add @modules as needed to the open hotspot tests
ykantser
parents:
24840
diff
changeset
|
28 |
* @modules java.base/sun.misc |
dd2f3932c21e
8075586: Add @modules as needed to the open hotspot tests
ykantser
parents:
24840
diff
changeset
|
29 |
* java.management |
24840
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
30 |
* @run main SpaceUtilizationCheck |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
31 |
*/ |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
32 |
|
30604
b8d532cb6420
8067013: Rename the com.oracle.java.testlibary package
ykantser
parents:
30146
diff
changeset
|
33 |
import jdk.test.lib.*; |
24840
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
34 |
|
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
35 |
import java.util.regex.Pattern; |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
36 |
import java.util.regex.Matcher; |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
37 |
import java.util.ArrayList; |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
38 |
import java.lang.Integer; |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
39 |
|
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
40 |
public class SpaceUtilizationCheck { |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
41 |
// Minimum allowed utilization value (percent) |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
42 |
// The goal is to have this number to be 50% for RO and RW regions |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
43 |
// Once that feature is implemented, increase the MIN_UTILIZATION to 50 |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
44 |
private static final int MIN_UTILIZATION = 30; |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
45 |
|
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
46 |
// Only RO and RW regions are considered for this check, since they |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
47 |
// currently account for the bulk of the shared space |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
48 |
private static final int NUMBER_OF_CHECKED_SHARED_REGIONS = 2; |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
49 |
|
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
50 |
public static void main(String[] args) throws Exception { |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
51 |
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
52 |
"-XX:+UnlockDiagnosticVMOptions", |
30123
7a8b6bd85e24
8075438: [TESTBUG] Hotspot JTREG tests should use unique CDS archive names
ctornqvi
parents:
24840
diff
changeset
|
53 |
"-XX:SharedArchiveFile=./SpaceUtilizationCheck.jsa", |
24840
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
54 |
"-Xshare:dump"); |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
55 |
|
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
56 |
OutputAnalyzer output = new OutputAnalyzer(pb.start()); |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
57 |
String stdout = output.getStdout(); |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
58 |
ArrayList<String> utilization = findUtilization(stdout); |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
59 |
|
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
60 |
if (utilization.size() != NUMBER_OF_CHECKED_SHARED_REGIONS ) |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
61 |
throw new RuntimeException("The output format of sharing summary has changed"); |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
62 |
|
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
63 |
for(String str : utilization) { |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
64 |
int value = Integer.parseInt(str); |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
65 |
if (value < MIN_UTILIZATION) { |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
66 |
System.out.println(stdout); |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
67 |
throw new RuntimeException("Utilization for one of the regions" + |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
68 |
"is below a threshold of " + MIN_UTILIZATION + "%"); |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
69 |
} |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
70 |
} |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
71 |
} |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
72 |
|
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
73 |
public static ArrayList<String> findUtilization(String input) { |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
74 |
ArrayList<String> regions = filterRegionsOfInterest(input.split("\n")); |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
75 |
return filterByPattern(filterByPattern(regions, "bytes \\[.*% used\\]"), "\\d+"); |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
76 |
} |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
77 |
|
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
78 |
private static ArrayList<String> filterByPattern(Iterable<String> input, String pattern) { |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
79 |
ArrayList<String> result = new ArrayList<String>(); |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
80 |
for (String str : input) { |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
81 |
Matcher matcher = Pattern.compile(pattern).matcher(str); |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
82 |
if (matcher.find()) { |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
83 |
result.add(matcher.group()); |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
84 |
} |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
85 |
} |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
86 |
return result; |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
87 |
} |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
88 |
|
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
89 |
private static ArrayList<String> filterRegionsOfInterest(String[] inputLines) { |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
90 |
ArrayList<String> result = new ArrayList<String>(); |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
91 |
for (String str : inputLines) { |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
92 |
if (str.contains("ro space:") || str.contains("rw space:")) { |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
93 |
result.add(str); |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
94 |
} |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
95 |
} |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
96 |
return result; |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
97 |
} |
96be34dfc72a
8038587: [TESTBUG] Create CDS tests to exercise region sizes and base address
mseledtsov
parents:
diff
changeset
|
98 |
} |