Skip to content

Commit

Permalink
Backport 1fde8b868a0e40fb79de505106ef07e3dccbd1de
Browse files Browse the repository at this point in the history
  • Loading branch information
amosshi committed Jun 19, 2024
1 parent e716aae commit dc6be07
Showing 1 changed file with 27 additions and 32 deletions.
59 changes: 27 additions & 32 deletions test/hotspot/jtreg/runtime/cds/TestCDSVMCrash.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,42 +31,37 @@
* @bug 8306583
*/

import jdk.test.lib.cds.CDSTestUtils;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;
import jdk.test.lib.cds.CDSTestUtils;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;

public class TestCDSVMCrash {
public class TestCDSVMCrash {

public static void main(String[] args) throws Exception {
if (args.length == 1) {
// This should guarantee to throw:
// java.lang.OutOfMemoryError: Requested array size exceeds VM limit
try {
Object[] oa = new Object[Integer.MAX_VALUE];
throw new Error("OOME not triggered");
} catch (OutOfMemoryError err) {
throw new Error("OOME didn't abort JVM!");
}
}
// else this is the main test
ProcessBuilder pb = ProcessTools.createLimitedTestJavaProcessBuilder("-XX:+CrashOnOutOfMemoryError",
"-XX:-CreateCoredumpOnCrash", "-Xmx128m", "-Xshare:on", TestCDSVMCrash.class.getName(),"throwOOME");
OutputAnalyzer output = new OutputAnalyzer(pb.start());
// executeAndLog should throw an exception in the VM crashed
try {
public static void main(String[] args) throws Exception {
if (args.length == 1) {
// This should guarantee to throw:
// java.lang.OutOfMemoryError: Requested array size exceeds VM limit
try {
Object[] oa = new Object[Integer.MAX_VALUE];
throw new Error("OOME not triggered");
} catch (OutOfMemoryError err) {
throw new Error("OOME didn't abort JVM!");
}
}
// else this is the main test
ProcessBuilder pb = ProcessTools.createLimitedTestJavaProcessBuilder("-XX:+CrashOnOutOfMemoryError",
"-XX:-CreateCoredumpOnCrash", "-Xmx128m",
"-Xshare:on", TestCDSVMCrash.class.getName(),
"throwOOME");
// executeAndLog should throw an exception in the VM crashed
try {
CDSTestUtils.executeAndLog(pb, "cds_vm_crash");
throw new Error("Expected VM to crash");
} catch(RuntimeException e) {
} catch(RuntimeException e) {
if (!e.getMessage().equals("Hotspot crashed")) {
throw new Error("Expected message: Hotspot crashed");
throw new Error("Expected message: Hotspot crashed");
}
}
int exitValue = output.getExitValue();
if (0 == exitValue) {
//expecting a non zero value
throw new Error("Expected to get non zero exit value");
}
output.shouldContain("A fatal error has been detected by the Java Runtime Environment");
}
System.out.println("PASSED");
}
}
}
}

0 comments on commit dc6be07

Please sign in to comment.