author | chegar |
Thu, 17 Oct 2019 20:54:25 +0100 | |
branch | datagramsocketimpl-branch |
changeset 58679 | 9c3209ff7550 |
parent 58678 | 9cf78a70fa4f |
parent 58056 | db92a157dd70 |
permissions | -rw-r--r-- |
52027 | 1 |
/* |
53523
4c5184c56dc2
8214799: Add package declaration to each JTREG test case in the gc folder
lkorinth
parents:
52027
diff
changeset
|
2 |
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. |
52027 | 3 |
* Copyright (c) 2018, Google and/or its affiliates. All rights reserved. |
4 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
5 |
* |
|
6 |
* This code is free software; you can redistribute it and/or modify it |
|
7 |
* under the terms of the GNU General Public License version 2 only, as |
|
8 |
* published by the Free Software Foundation. |
|
9 |
* |
|
10 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
11 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
12 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
13 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
14 |
* accompanied this code). |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License version |
|
17 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
18 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
19 |
* |
|
20 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
21 |
* or visit www.oracle.com if you need additional information or have any |
|
22 |
* questions. |
|
23 |
*/ |
|
24 |
||
53523
4c5184c56dc2
8214799: Add package declaration to each JTREG test case in the gc folder
lkorinth
parents:
52027
diff
changeset
|
25 |
package gc.logging; |
4c5184c56dc2
8214799: Add package declaration to each JTREG test case in the gc folder
lkorinth
parents:
52027
diff
changeset
|
26 |
|
52027 | 27 |
import java.io.File; |
28 |
import java.net.URL; |
|
29 |
import java.net.URLClassLoader; |
|
30 |
import java.util.regex.Pattern; |
|
31 |
import java.util.regex.Matcher; |
|
32 |
||
33 |
import jdk.test.lib.Asserts; |
|
34 |
import jdk.test.lib.process.OutputAnalyzer; |
|
35 |
import jdk.test.lib.process.ProcessTools; |
|
36 |
import sun.hotspot.WhiteBox; |
|
37 |
||
38 |
/* |
|
39 |
* @test TestMetaSpaceLog |
|
40 |
* @bug 8211123 |
|
41 |
* @summary Ensure that the Metaspace is updated in the log |
|
42 |
* @key gc |
|
43 |
* @library /test/lib |
|
44 |
* @modules java.base/jdk.internal.misc |
|
45 |
* java.management |
|
55203
8e31e083fe3c
8212630: jtreg/gc/logging/TestMetaSpaceLog.java failed with Agent timed out
kbarrett
parents:
54638
diff
changeset
|
46 |
* @requires vm.gc != "Epsilon" |
8e31e083fe3c
8212630: jtreg/gc/logging/TestMetaSpaceLog.java failed with Agent timed out
kbarrett
parents:
54638
diff
changeset
|
47 |
* @requires vm.gc != "Z" |
8e31e083fe3c
8212630: jtreg/gc/logging/TestMetaSpaceLog.java failed with Agent timed out
kbarrett
parents:
54638
diff
changeset
|
48 |
* @requires vm.gc != "Shenandoah" |
52027 | 49 |
* |
50 |
* @compile TestMetaSpaceLog.java |
|
51 |
* @run driver ClassFileInstaller sun.hotspot.WhiteBox |
|
55203
8e31e083fe3c
8212630: jtreg/gc/logging/TestMetaSpaceLog.java failed with Agent timed out
kbarrett
parents:
54638
diff
changeset
|
52 |
* @run driver gc.logging.TestMetaSpaceLog |
52027 | 53 |
*/ |
54 |
||
55 |
public class TestMetaSpaceLog { |
|
56 |
private static Pattern metaSpaceRegexp; |
|
57 |
||
58 |
static { |
|
59 |
// Do this once here. |
|
60 |
metaSpaceRegexp = Pattern.compile(".*Metaspace: ([0-9]+).*->([0-9]+).*"); |
|
61 |
} |
|
62 |
||
63 |
public static void main(String[] args) throws Exception { |
|
55203
8e31e083fe3c
8212630: jtreg/gc/logging/TestMetaSpaceLog.java failed with Agent timed out
kbarrett
parents:
54638
diff
changeset
|
64 |
testMetaSpaceUpdate(); |
52027 | 65 |
} |
66 |
||
67 |
private static void verifyContainsMetaSpaceUpdate(OutputAnalyzer output) { |
|
68 |
// At least one metaspace line from GC should show GC being collected. |
|
69 |
boolean foundCollectedMetaSpace = output.asLines().stream() |
|
70 |
.filter(s -> s.contains("[gc,metaspace")) |
|
71 |
.anyMatch(TestMetaSpaceLog::check); |
|
72 |
Asserts.assertTrue(foundCollectedMetaSpace); |
|
73 |
} |
|
74 |
||
75 |
private static boolean check(String line) { |
|
76 |
Matcher m = metaSpaceRegexp.matcher(line); |
|
77 |
Asserts.assertTrue(m.matches(), "Unexpected line for metaspace logging: " + line); |
|
78 |
long before = Long.parseLong(m.group(1)); |
|
79 |
long after = Long.parseLong(m.group(2)); |
|
80 |
return before > after; |
|
81 |
} |
|
82 |
||
55203
8e31e083fe3c
8212630: jtreg/gc/logging/TestMetaSpaceLog.java failed with Agent timed out
kbarrett
parents:
54638
diff
changeset
|
83 |
private static void testMetaSpaceUpdate() throws Exception { |
52027 | 84 |
// Propagate test.src for the jar file. |
85 |
String testSrc= "-Dtest.src=" + System.getProperty("test.src", "."); |
|
86 |
||
87 |
ProcessBuilder pb = |
|
88 |
ProcessTools.createJavaProcessBuilder( |
|
55203
8e31e083fe3c
8212630: jtreg/gc/logging/TestMetaSpaceLog.java failed with Agent timed out
kbarrett
parents:
54638
diff
changeset
|
89 |
true, |
52027 | 90 |
"-Xlog:gc*", |
91 |
"-Xbootclasspath/a:.", |
|
92 |
"-XX:+UnlockDiagnosticVMOptions", |
|
93 |
"-XX:+WhiteBoxAPI", |
|
94 |
"-Xmx1000M", |
|
95 |
"-Xms1000M", |
|
96 |
testSrc, StressMetaSpace.class.getName()); |
|
97 |
||
98 |
OutputAnalyzer output = null; |
|
99 |
try { |
|
100 |
output = new OutputAnalyzer(pb.start()); |
|
101 |
verifyContainsMetaSpaceUpdate(output); |
|
102 |
} catch (Exception e) { |
|
103 |
// For error diagnosis: print and throw. |
|
104 |
e.printStackTrace(); |
|
105 |
output.reportDiagnosticSummary(); |
|
106 |
throw e; |
|
107 |
} |
|
108 |
} |
|
109 |
||
110 |
static class StressMetaSpace { |
|
111 |
private static URL[] urls = new URL[1]; |
|
112 |
||
113 |
static { |
|
114 |
try { |
|
115 |
File jarFile = new File(System.getProperty("test.src") + "/testcases.jar"); |
|
116 |
urls[0] = jarFile.toURI().toURL(); |
|
117 |
} catch (Exception e) { |
|
118 |
e.printStackTrace(); |
|
119 |
} |
|
120 |
} |
|
121 |
||
122 |
public static void main(String args[]) { |
|
123 |
WhiteBox wb = WhiteBox.getWhiteBox(); |
|
124 |
for(int i = 0; i < 10000; i++) { |
|
125 |
loadClass(wb); |
|
126 |
} |
|
127 |
wb.fullGC(); |
|
128 |
} |
|
129 |
||
130 |
public static void loadClass(WhiteBox wb) { |
|
131 |
try { |
|
132 |
URLClassLoader ucl = new URLClassLoader(urls); |
|
58056
db92a157dd70
8212117: Class.forName may return a reference to a loaded but not linked Class
bchristi
parents:
55203
diff
changeset
|
133 |
ucl.loadClass("case00"); |
52027 | 134 |
} catch (Exception e) { |
135 |
e.printStackTrace(); |
|
136 |
} |
|
137 |
} |
|
138 |
} |
|
139 |
} |