mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-17 09:34:38 +02:00
8267118: OutOfMemoryError cannot be caught as a Throwable
Co-authored-by: Ioi Lam <iklam@openjdk.org> Reviewed-by: coleenp
This commit is contained in:
parent
de6472c441
commit
71425ddfb4
3 changed files with 125 additions and 1 deletions
|
@ -226,6 +226,11 @@ void Method::print_external_name(outputStream *os, Klass* klass, Symbol* method_
|
|||
}
|
||||
|
||||
int Method::fast_exception_handler_bci_for(const methodHandle& mh, Klass* ex_klass, int throw_bci, TRAPS) {
|
||||
if (log_is_enabled(Debug, exceptions)) {
|
||||
ResourceMark rm(THREAD);
|
||||
log_debug(exceptions)("Looking for catch handler for exception of type \"%s\" in method \"%s\"",
|
||||
ex_klass == NULL ? "NULL" : ex_klass->external_name(), mh->name()->as_C_string());
|
||||
}
|
||||
// exception table holds quadruple entries of the form (beg_bci, end_bci, handler_bci, klass_index)
|
||||
// access exception table
|
||||
ExceptionTable table(mh());
|
||||
|
@ -238,27 +243,67 @@ int Method::fast_exception_handler_bci_for(const methodHandle& mh, Klass* ex_kla
|
|||
int beg_bci = table.start_pc(i);
|
||||
int end_bci = table.end_pc(i);
|
||||
assert(beg_bci <= end_bci, "inconsistent exception table");
|
||||
log_debug(exceptions)(" - checking exception table entry for BCI %d to %d",
|
||||
beg_bci, end_bci);
|
||||
|
||||
if (beg_bci <= throw_bci && throw_bci < end_bci) {
|
||||
// exception handler bci range covers throw_bci => investigate further
|
||||
log_debug(exceptions)(" - entry covers throw point BCI %d", throw_bci);
|
||||
|
||||
int handler_bci = table.handler_pc(i);
|
||||
int klass_index = table.catch_type_index(i);
|
||||
if (klass_index == 0) {
|
||||
if (log_is_enabled(Info, exceptions)) {
|
||||
ResourceMark rm(THREAD);
|
||||
log_info(exceptions)("Found catch-all handler for exception of type \"%s\" in method \"%s\" at BCI: %d",
|
||||
ex_klass == NULL ? "NULL" : ex_klass->external_name(), mh->name()->as_C_string(), handler_bci);
|
||||
}
|
||||
return handler_bci;
|
||||
} else if (ex_klass == NULL) {
|
||||
// Is this even possible?
|
||||
if (log_is_enabled(Info, exceptions)) {
|
||||
ResourceMark rm(THREAD);
|
||||
log_info(exceptions)("NULL exception class is implicitly caught by handler in method \"%s\" at BCI: %d",
|
||||
mh()->name()->as_C_string(), handler_bci);
|
||||
}
|
||||
return handler_bci;
|
||||
} else {
|
||||
if (log_is_enabled(Debug, exceptions)) {
|
||||
ResourceMark rm(THREAD);
|
||||
log_debug(exceptions)(" - resolving catch type \"%s\"",
|
||||
pool->klass_name_at(klass_index)->as_C_string());
|
||||
}
|
||||
// we know the exception class => get the constraint class
|
||||
// this may require loading of the constraint class; if verification
|
||||
// fails or some other exception occurs, return handler_bci
|
||||
Klass* k = pool->klass_at(klass_index, CHECK_(handler_bci));
|
||||
Klass* k = pool->klass_at(klass_index, THREAD);
|
||||
if (HAS_PENDING_EXCEPTION) {
|
||||
if (log_is_enabled(Debug, exceptions)) {
|
||||
ResourceMark rm(THREAD);
|
||||
log_debug(exceptions)(" - exception \"%s\" occurred resolving catch type",
|
||||
PENDING_EXCEPTION->klass()->external_name());
|
||||
}
|
||||
return handler_bci;
|
||||
}
|
||||
assert(k != NULL, "klass not loaded");
|
||||
if (ex_klass->is_subtype_of(k)) {
|
||||
if (log_is_enabled(Info, exceptions)) {
|
||||
ResourceMark rm(THREAD);
|
||||
log_info(exceptions)("Found matching handler for exception of type \"%s\" in method \"%s\" at BCI: %d",
|
||||
ex_klass == NULL ? "NULL" : ex_klass->external_name(), mh->name()->as_C_string(), handler_bci);
|
||||
}
|
||||
return handler_bci;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (log_is_enabled(Debug, exceptions)) {
|
||||
ResourceMark rm(THREAD);
|
||||
log_debug(exceptions)("No catch handler found for exception of type \"%s\" in method \"%s\"",
|
||||
ex_klass->external_name(), mh->name()->as_C_string());
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue