final VmProcessor proc = VmProcessor.current();
final VmStackReader reader = proc.getArchitecture()
.getStackReader();
final VmType exClass = VmMagic.getObjectType(ex);
final VmMethod method = reader.getMethod(frame);
if (method == null) {
Unsafe.debug("Unknown method in class " + ex.getClass().getName());
return null;
}
// if (interpreted) {
/*
* Screen.debug("{ex at pc:"); Screen.debug(pc); Screen.debug(" of " +
* method.getBytecodeSize()); Screen.debug(method.getName());
*/
// }
final int count;
final VmByteCode bc = method.getBytecode();
final VmCompiledCode cc = reader.getCompiledCode(frame);
if (bc != null) {
count = bc.getNoExceptionHandlers();
} else {
count = 0;
}
// Screen.debug("eCount=" + count);
for (int i = 0; i < count; i++) {
final AbstractExceptionHandler eh;
final VmCompiledExceptionHandler ceh;
ceh = cc.getExceptionHandler(i);
eh = ceh;
boolean match;
match = ceh.isInScope(address);
if (match) {
final VmConstClass catchType = eh.getCatchType();
if (catchType == null) {
/* Catch all exceptions */
return Address.fromAddress(ceh.getHandler());
} else {
if (!catchType.isResolved()) {
SoftByteCodes.resolveClass(catchType);
}
final VmType handlerClass = catchType
.getResolvedVmClass();
if (handlerClass != null) {
if (handlerClass.isAssignableFrom(exClass)) {
return Address.fromAddress(ceh.getHandler());
}
} else {
System.err
.println("Warning: handler class==null in "
+ method.getName());
}
}
}
}