-
Enhancement
-
Resolution: Fixed
-
P4
-
17
-
b25
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8268111 | 18 | David Holmes | P4 | Closed | Not an Issue |
import java.util.*;
public class OOM {
private static HashMap<Object, Object> store = new HashMap<>();
public static void main(String... args) {
int size = Integer.parseInt(args[0]);
System.out.println("Start");
try {
while (true) {
Object o = new Byte[size * 1024];
store.put(o, o);
}
} catch (Throwable t) { /// <<<<==Change to "catch (VirtualMachineError t)" and we'll be OK.
store = null;
}
}
}
$ java -Xmx64m OOM.java 100; echo $?
Start
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
1
$ java -Xmx64m OOM.java 300; echo $?
Start
0
With SerialGC, the OOM can be caught even with size==1
$ java -Xmx64m -XX:+UseSerialGC OOM.java 1; echo $?
Start
0
public class OOM {
private static HashMap<Object, Object> store = new HashMap<>();
public static void main(String... args) {
int size = Integer.parseInt(args[0]);
System.out.println("Start");
try {
while (true) {
Object o = new Byte[size * 1024];
store.put(o, o);
}
} catch (Throwable t) { /// <<<<==Change to "catch (VirtualMachineError t)" and we'll be OK.
store = null;
}
}
}
$ java -Xmx64m OOM.java 100; echo $?
Start
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
1
$ java -Xmx64m OOM.java 300; echo $?
Start
0
With SerialGC, the OOM can be caught even with size==1
$ java -Xmx64m -XX:+UseSerialGC OOM.java 1; echo $?
Start
0
- backported by
-
JDK-8268111 OutOfMemoryError cannot be caught as a Throwable
-
- Closed
-