-
Bug
-
Resolution: Won't Fix
-
P3
-
7
-
generic
-
generic
The Throwable and its subclasses are mutable. The stack trace and suppressed
exceptions fields can be set programmatically. The VM should clear these fields
when the preallocated exceptions are reused.
From Remi Forax:
This code change the stack trace of permanently allocated OutOfMerroryError.
public static void main(String[] args) {
Error last = null;
for(int i=0; i<100; i++) {
try {
Object o = new int[Integer.MAX_VALUE];
} catch (Error e) {
StackTraceElement[] stackTrace = e.getStackTrace();
if (stackTrace != null && stackTrace.length>0 && stackTrace[0].getLineNumber() == -3) {
e.printStackTrace();
return;
}
if (last == e) {
StackTraceElement element = new StackTraceElement("Foo", "foo", null, -3);
e.setStackTrace(new StackTraceElement[]{element});
}
last = e;
}
}
}
To avoid that the VM has to clear the stacktrace when using the default error:
in universe.cpp, in Universe::gen_out_of_memory_error:
if (next < 0) {
// all preallocated errors have been used.
// return default
+ java_lang_Throwable::clear_stacktrace(default_err);
return default_err;
} else {
And we should do the same for the field suppressed exceptions.
exceptions fields can be set programmatically. The VM should clear these fields
when the preallocated exceptions are reused.
From Remi Forax:
This code change the stack trace of permanently allocated OutOfMerroryError.
public static void main(String[] args) {
Error last = null;
for(int i=0; i<100; i++) {
try {
Object o = new int[Integer.MAX_VALUE];
} catch (Error e) {
StackTraceElement[] stackTrace = e.getStackTrace();
if (stackTrace != null && stackTrace.length>0 && stackTrace[0].getLineNumber() == -3) {
e.printStackTrace();
return;
}
if (last == e) {
StackTraceElement element = new StackTraceElement("Foo", "foo", null, -3);
e.setStackTrace(new StackTraceElement[]{element});
}
last = e;
}
}
}
To avoid that the VM has to clear the stacktrace when using the default error:
in universe.cpp, in Universe::gen_out_of_memory_error:
if (next < 0) {
// all preallocated errors have been used.
// return default
+ java_lang_Throwable::clear_stacktrace(default_err);
return default_err;
} else {
And we should do the same for the field suppressed exceptions.
- relates to
-
JDK-6911258 Project Coin: Add essential API support for Automatic Resource Management (ARM) blocks
-
- Closed
-
-
JDK-6991528 Support making Throwable.suppressedExceptions immutable
-
- Closed
-
-
JDK-6998871 Support making the Throwable.stackTrace field immutable
-
- Closed
-
-
JDK-7005628 Clarify NPE behavior of Throwable.addSuppressed(null)
-
- Closed
-
-
JDK-5026971 (hotspot) Clean up hiding of exception backtrace field
-
- Closed
-