use of org.hotswap.agent.javassist.bytecode.BadBytecode 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.BadBytecode in project HotswapAgent by HotswapProjects.
the class Javac method compile.
/**
* Compiles a method, constructor, or field declaration
* to a class.
* A field declaration can declare only one field.
*
* <p>In a method or constructor body, $0, $1, ... and $_
* are not available.
*
* @return a <code>CtMethod</code>, <code>CtConstructor</code>,
* or <code>CtField</code> object.
* @see #recordProceed(String,String)
*/
public CtMember compile(String src) throws CompileError {
Parser p = new Parser(new Lex(src));
ASTList mem = p.parseMember1(stable);
try {
if (mem instanceof FieldDecl)
return compileField((FieldDecl) mem);
else {
CtBehavior cb = compileMethod(p, (MethodDecl) mem);
CtClass decl = cb.getDeclaringClass();
cb.getMethodInfo2().rebuildStackMapIf6(decl.getClassPool(), decl.getClassFile2());
return cb;
}
} catch (BadBytecode bb) {
throw new CompileError(bb.getMessage());
} catch (CannotCompileException e) {
throw new CompileError(e.getMessage());
}
}
Aggregations