author | phh |
Sat, 30 Nov 2019 14:33:05 -0800 | |
changeset 59330 | 5b96c12f909d |
parent 59053 | ba6c248cae19 |
permissions | -rw-r--r-- |
48632 | 1 |
/* |
53523
4c5184c56dc2
8214799: Add package declaration to each JTREG test case in the gc folder
lkorinth
parents:
50455
diff
changeset
|
2 |
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. |
48632 | 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 |
||
53523
4c5184c56dc2
8214799: Add package declaration to each JTREG test case in the gc folder
lkorinth
parents:
50455
diff
changeset
|
24 |
package gc.stress; |
4c5184c56dc2
8214799: Add package declaration to each JTREG test case in the gc folder
lkorinth
parents:
50455
diff
changeset
|
25 |
|
48632 | 26 |
/* |
27 |
* @test TestReclaimStringsLeaksMemory |
|
28 |
* @bug 8180048 |
|
29 |
* @summary Ensure that during a Full GC interned string memory is reclaimed completely. |
|
50455
2b73cce96dce
8202611: [GRAAL] Exclude CMS GC testing from runs with Graal
kvn
parents:
48632
diff
changeset
|
30 |
* @requires vm.gc=="null" & !vm.graal.enabled & !vm.debug |
48632 | 31 |
* @key gc |
32 |
* @library /test/lib |
|
33 |
* @modules java.base/jdk.internal.misc |
|
53523
4c5184c56dc2
8214799: Add package declaration to each JTREG test case in the gc folder
lkorinth
parents:
50455
diff
changeset
|
34 |
* @run main/othervm gc.stress.TestReclaimStringsLeaksMemory |
4c5184c56dc2
8214799: Add package declaration to each JTREG test case in the gc folder
lkorinth
parents:
50455
diff
changeset
|
35 |
* @run main/othervm gc.stress.TestReclaimStringsLeaksMemory -XX:+UseSerialGC |
4c5184c56dc2
8214799: Add package declaration to each JTREG test case in the gc folder
lkorinth
parents:
50455
diff
changeset
|
36 |
* @run main/othervm gc.stress.TestReclaimStringsLeaksMemory -XX:+UseParallelGC |
4c5184c56dc2
8214799: Add package declaration to each JTREG test case in the gc folder
lkorinth
parents:
50455
diff
changeset
|
37 |
* @run main/othervm gc.stress.TestReclaimStringsLeaksMemory -XX:+UseParallelGC -XX:-UseParallelOldGC |
4c5184c56dc2
8214799: Add package declaration to each JTREG test case in the gc folder
lkorinth
parents:
50455
diff
changeset
|
38 |
* @run main/othervm gc.stress.TestReclaimStringsLeaksMemory -XX:+UseG1GC |
48632 | 39 |
*/ |
40 |
||
41 |
import java.util.Arrays; |
|
42 |
import java.util.ArrayList; |
|
43 |
import java.util.regex.Pattern; |
|
44 |
import java.util.regex.Matcher; |
|
45 |
||
46 |
import jdk.test.lib.Asserts; |
|
47 |
import jdk.test.lib.process.OutputAnalyzer; |
|
48 |
import jdk.test.lib.process.ProcessTools; |
|
49 |
||
50 |
public class TestReclaimStringsLeaksMemory { |
|
51 |
||
52 |
// The amount of memory in kB reserved in the "Symbol" category that indicates a memory leak for |
|
53 |
// this test. |
|
54 |
public static final int ReservedThreshold = 70000; |
|
55 |
||
56 |
public static void main(String[] args) throws Exception { |
|
53694
a0a327cae58f
8217332: JTREG: Clean up, use generics instead of raw types
lkorinth
parents:
53523
diff
changeset
|
57 |
ArrayList<String> baseargs = new ArrayList<>(Arrays.asList("-Xms256M", |
a0a327cae58f
8217332: JTREG: Clean up, use generics instead of raw types
lkorinth
parents:
53523
diff
changeset
|
58 |
"-Xmx256M", |
55328
d9a157f6fd71
8224847: gc/stress/TestReclaimStringsLeaksMemory.java fails with reserved greater than expected
coleenp
parents:
53694
diff
changeset
|
59 |
"-Xlog:gc*,stringtable*=debug:gc.log", |
53694
a0a327cae58f
8217332: JTREG: Clean up, use generics instead of raw types
lkorinth
parents:
53523
diff
changeset
|
60 |
"-XX:NativeMemoryTracking=summary", |
a0a327cae58f
8217332: JTREG: Clean up, use generics instead of raw types
lkorinth
parents:
53523
diff
changeset
|
61 |
"-XX:+UnlockDiagnosticVMOptions", |
a0a327cae58f
8217332: JTREG: Clean up, use generics instead of raw types
lkorinth
parents:
53523
diff
changeset
|
62 |
"-XX:+PrintNMTStatistics" )); |
48632 | 63 |
baseargs.addAll(Arrays.asList(args)); |
64 |
baseargs.add(GCTest.class.getName()); |
|
65 |
ProcessBuilder pb_default = |
|
66 |
ProcessTools.createJavaProcessBuilder(baseargs.toArray(new String[] {})); |
|
67 |
verifySymbolMemoryUsageNotTooHigh(new OutputAnalyzer(pb_default.start())); |
|
68 |
} |
|
69 |
||
70 |
private static void verifySymbolMemoryUsageNotTooHigh(OutputAnalyzer output) throws Exception { |
|
71 |
String stdout = output.getStdout(); |
|
72 |
System.out.println(stdout); |
|
73 |
||
74 |
Pattern p = Pattern.compile("Symbol \\(reserved=(\\d*)"); |
|
75 |
Matcher m = p.matcher(stdout); |
|
76 |
||
77 |
if (!m.find()) { |
|
78 |
throw new RuntimeException("Could not find Symbol memory usage in NMT output"); |
|
79 |
} |
|
80 |
||
81 |
int reserved = Integer.parseInt(m.group(1)); |
|
82 |
Asserts.assertLT(reserved, ReservedThreshold, "Reserved memory size is " + reserved + "KB which is greater than or equal to " + ReservedThreshold + "KB indicating a memory leak"); |
|
83 |
||
84 |
output.shouldHaveExitValue(0); |
|
85 |
} |
|
86 |
||
87 |
static class GCTest { |
|
88 |
public static final String BaseName = "SomeRandomBaseString"; |
|
89 |
public static volatile String lastString; |
|
90 |
||
91 |
public static void main(String [] args) { |
|
92 |
for (int iterations = 0; iterations < 20;) { |
|
93 |
for (int i = 0; i < 1000000; i++) { |
|
94 |
lastString = (BaseName + i).intern(); |
|
95 |
} |
|
96 |
if (++iterations % 5 == 0) { |
|
55328
d9a157f6fd71
8224847: gc/stress/TestReclaimStringsLeaksMemory.java fails with reserved greater than expected
coleenp
parents:
53694
diff
changeset
|
97 |
System.gc(); |
48632 | 98 |
} |
99 |
} |
|
55328
d9a157f6fd71
8224847: gc/stress/TestReclaimStringsLeaksMemory.java fails with reserved greater than expected
coleenp
parents:
53694
diff
changeset
|
100 |
// Do one last GC and sleep to give ServiceThread a chance to run. |
d9a157f6fd71
8224847: gc/stress/TestReclaimStringsLeaksMemory.java fails with reserved greater than expected
coleenp
parents:
53694
diff
changeset
|
101 |
System.out.println("One last gc"); |
d9a157f6fd71
8224847: gc/stress/TestReclaimStringsLeaksMemory.java fails with reserved greater than expected
coleenp
parents:
53694
diff
changeset
|
102 |
System.gc(); |
d9a157f6fd71
8224847: gc/stress/TestReclaimStringsLeaksMemory.java fails with reserved greater than expected
coleenp
parents:
53694
diff
changeset
|
103 |
for (int i = 0; i < 100; i++) { |
d9a157f6fd71
8224847: gc/stress/TestReclaimStringsLeaksMemory.java fails with reserved greater than expected
coleenp
parents:
53694
diff
changeset
|
104 |
try { |
d9a157f6fd71
8224847: gc/stress/TestReclaimStringsLeaksMemory.java fails with reserved greater than expected
coleenp
parents:
53694
diff
changeset
|
105 |
Thread.sleep(10); |
d9a157f6fd71
8224847: gc/stress/TestReclaimStringsLeaksMemory.java fails with reserved greater than expected
coleenp
parents:
53694
diff
changeset
|
106 |
} catch (InterruptedException ex) { |
d9a157f6fd71
8224847: gc/stress/TestReclaimStringsLeaksMemory.java fails with reserved greater than expected
coleenp
parents:
53694
diff
changeset
|
107 |
} |
d9a157f6fd71
8224847: gc/stress/TestReclaimStringsLeaksMemory.java fails with reserved greater than expected
coleenp
parents:
53694
diff
changeset
|
108 |
} |
d9a157f6fd71
8224847: gc/stress/TestReclaimStringsLeaksMemory.java fails with reserved greater than expected
coleenp
parents:
53694
diff
changeset
|
109 |
System.out.println("End of test"); |
48632 | 110 |
} |
111 |
} |
|
112 |
} |
|
113 |