Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/runtime/ErrorHandling/TestHeapDumpOnOutOfMemoryError.java
40942 views
1
/*
2
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
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
24
/*
25
* @test TestHeapDumpOnOutOfMemoryError
26
* @summary Test verifies that -XX:HeapDumpOnOutOfMemoryError dumps heap when OutOfMemory is thrown in heap
27
* @library /test/lib
28
* @run driver TestHeapDumpOnOutOfMemoryError run heap
29
*/
30
31
/*
32
* @test TestHeapDumpOnOutOfMemoryError
33
* @summary Test verifies that -XX:HeapDumpOnOutOfMemoryError dumps heap when OutOfMemory is thrown in metaspace.
34
* @library /test/lib
35
* @run driver/timeout=240 TestHeapDumpOnOutOfMemoryError run metaspace
36
*/
37
38
import jdk.test.lib.Asserts;
39
import jdk.test.lib.Platform;
40
import jdk.test.lib.classloader.GeneratingClassLoader;
41
import jdk.test.lib.hprof.HprofParser;
42
import jdk.test.lib.process.ProcessTools;
43
import jdk.test.lib.process.OutputAnalyzer;
44
45
import java.io.File;
46
47
public class TestHeapDumpOnOutOfMemoryError {
48
49
public static final String HEAP_OOME = "heap";
50
public static final String METASPACE_OOME = "metaspace";
51
52
public static void main(String[] args) throws Exception {
53
if (args.length == 1) {
54
try {
55
if (args[0].equals(HEAP_OOME)) {
56
Object[] oa = new Object[Integer.MAX_VALUE];
57
for(int i = 0; i < oa.length; i++) {
58
oa[i] = new Object[Integer.MAX_VALUE];
59
}
60
} else {
61
GeneratingClassLoader loader = new GeneratingClassLoader();
62
for (int i = 0; ; i++) {
63
loader.loadClass(loader.getClassName(i));
64
}
65
}
66
throw new Error("OOME not triggered");
67
} catch (OutOfMemoryError err) {
68
return;
69
}
70
}
71
test(args[1]);
72
}
73
74
static void test(String type) throws Exception {
75
String heapdumpFilename = type + ".hprof";
76
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+HeapDumpOnOutOfMemoryError",
77
"-XX:HeapDumpPath=" + heapdumpFilename,
78
// Note: When trying to provoke a metaspace OOM we may generate a lot of classes. In debug VMs this
79
// can cause considerable wait times since:
80
// - Compiler Dependencies verification iterates the class tree
81
// - Before exit, the CLDG is checked.
82
// Both verifications show quadratic time or worse wrt to number of loaded classes. Therefore it
83
// makes sense to switch one or both off and limit the metaspace size to something sensible.
84
// Example numbers on a slow ppc64 machine:
85
// MaxMetaspaceSize=64M - ~60-70K classes - ~20min runtime with all verifications
86
// MaxMetaspaceSize=16M - ~12-15K classes - ~12sec runtime with all verifications
87
// MaxMetaspaceSize=16M - ~12-15K classes - VerifyDependencies off - ~3seconds on ppc
88
"-XX:MaxMetaspaceSize=16m",
89
"-Xmx128m",
90
Platform.isDebugBuild() ? "-XX:-VerifyDependencies" : "-Dx",
91
TestHeapDumpOnOutOfMemoryError.class.getName(), type);
92
93
OutputAnalyzer output = new OutputAnalyzer(pb.start());
94
output.stdoutShouldNotBeEmpty();
95
output.shouldContain("Dumping heap to " + type + ".hprof");
96
File dump = new File(heapdumpFilename);
97
Asserts.assertTrue(dump.exists() && dump.isFile(),
98
"Could not find dump file " + dump.getAbsolutePath());
99
100
HprofParser.parse(new File(heapdumpFilename));
101
System.out.println("PASSED");
102
}
103
104
}
105
106