use of org.hotswap.agent.javassist.bytecode.ExceptionTable in project HotswapAgent by HotswapProjects.
the class SubroutineScanner method scan.
public Subroutine[] scan(MethodInfo method) throws BadBytecode {
CodeAttribute code = method.getCodeAttribute();
CodeIterator iter = code.iterator();
subroutines = new Subroutine[code.getCodeLength()];
subTable.clear();
done.clear();
scan(0, iter, null);
ExceptionTable exceptions = code.getExceptionTable();
for (int i = 0; i < exceptions.size(); i++) {
int handler = exceptions.handlerPc(i);
// If an exception is thrown in subroutine, the handler
// is part of the same subroutine.
scan(handler, iter, subroutines[exceptions.startPc(i)]);
}
return subroutines;
}
use of org.hotswap.agent.javassist.bytecode.ExceptionTable in project HotswapAgent by HotswapProjects.
the class Analyzer method buildExceptionInfo.
private ExceptionInfo[] buildExceptionInfo(MethodInfo method) {
ConstPool constPool = method.getConstPool();
ClassPool classes = clazz.getClassPool();
ExceptionTable table = method.getCodeAttribute().getExceptionTable();
ExceptionInfo[] exceptions = new ExceptionInfo[table.size()];
for (int i = 0; i < table.size(); i++) {
int index = table.catchType(i);
Type type;
try {
type = index == 0 ? Type.THROWABLE : Type.get(classes.get(constPool.getClassInfo(index)));
} catch (NotFoundException e) {
throw new IllegalStateException(e.getMessage());
}
exceptions[i] = new ExceptionInfo(table.startPc(i), table.endPc(i), table.handlerPc(i), type);
}
return exceptions;
}
use of org.hotswap.agent.javassist.bytecode.ExceptionTable in project HotswapAgent by HotswapProjects.
the class Expr method mayThrow.
/**
* Returns the list of exceptions that the expression may throw. This list
* includes both the exceptions that the try-catch statements including the
* expression can catch and the exceptions that the throws declaration
* allows the method to throw.
*/
public CtClass[] mayThrow() {
ClassPool pool = thisClass.getClassPool();
ConstPool cp = thisMethod.getConstPool();
LinkedList list = new LinkedList();
try {
CodeAttribute ca = thisMethod.getCodeAttribute();
ExceptionTable et = ca.getExceptionTable();
int pos = currentPos;
int n = et.size();
for (int i = 0; i < n; ++i) if (et.startPc(i) <= pos && pos < et.endPc(i)) {
int t = et.catchType(i);
if (t > 0)
try {
addClass(list, pool.get(cp.getClassInfo(t)));
} catch (NotFoundException e) {
}
}
} catch (NullPointerException e) {
}
ExceptionsAttribute ea = thisMethod.getExceptionsAttribute();
if (ea != null) {
String[] exceptions = ea.getExceptions();
if (exceptions != null) {
int n = exceptions.length;
for (int i = 0; i < n; ++i) try {
addClass(list, pool.get(exceptions[i]));
} catch (NotFoundException e) {
}
}
}
return (CtClass[]) list.toArray(new CtClass[list.size()]);
}
Aggregations