use of org.hotswap.agent.javassist.bytecode.CodeIterator in project HotswapAgent by HotswapProjects.
the class FramePrinter method print.
/**
* Prints the instructions and the frame states of the given method.
*/
public void print(CtMethod method) {
stream.println("\n" + getMethodString(method));
MethodInfo info = method.getMethodInfo2();
ConstPool pool = info.getConstPool();
CodeAttribute code = info.getCodeAttribute();
if (code == null)
return;
Frame[] frames;
try {
frames = (new Analyzer()).analyze(method.getDeclaringClass(), info);
} catch (BadBytecode e) {
throw new RuntimeException(e);
}
int spacing = String.valueOf(code.getCodeLength()).length();
CodeIterator iterator = code.iterator();
while (iterator.hasNext()) {
int pos;
try {
pos = iterator.next();
} catch (BadBytecode e) {
throw new RuntimeException(e);
}
stream.println(pos + ": " + InstructionPrinter.instructionString(iterator, pos, pool));
addSpacing(spacing + 3);
Frame frame = frames[pos];
if (frame == null) {
stream.println("--DEAD CODE--");
continue;
}
printStack(frame);
addSpacing(spacing + 3);
printLocals(frame);
}
}
use of org.hotswap.agent.javassist.bytecode.CodeIterator in project HotswapAgent by HotswapProjects.
the class FieldInitLink method insertAuxInitializer.
private static void insertAuxInitializer(CodeAttribute codeAttr, Bytecode initializer, int stacksize) throws BadBytecode {
CodeIterator it = codeAttr.iterator();
int index = it.skipSuperConstructor();
if (index < 0) {
index = it.skipThisConstructor();
if (index >= 0)
// this() is called.
return;
// Neither this() or super() is called.
}
int pos = it.insertEx(initializer.get());
it.insert(initializer.getExceptionTable(), pos);
int maxstack = codeAttr.getMaxStack();
if (maxstack < stacksize)
codeAttr.setMaxStack(stacksize);
}
Aggregations