Search in sources :

Example 11 with BadBytecode

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);
    }
}
Also used : ConstPool(org.hotswap.agent.javassist.bytecode.ConstPool) CodeAttribute(org.hotswap.agent.javassist.bytecode.CodeAttribute) CodeIterator(org.hotswap.agent.javassist.bytecode.CodeIterator) MethodInfo(org.hotswap.agent.javassist.bytecode.MethodInfo) BadBytecode(org.hotswap.agent.javassist.bytecode.BadBytecode)

Example 12 with BadBytecode

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());
    }
}
Also used : CtBehavior(org.hotswap.agent.javassist.CtBehavior) CtClass(org.hotswap.agent.javassist.CtClass) CannotCompileException(org.hotswap.agent.javassist.CannotCompileException) BadBytecode(org.hotswap.agent.javassist.bytecode.BadBytecode)

Aggregations

BadBytecode (org.hotswap.agent.javassist.bytecode.BadBytecode)12 CtClass (org.hotswap.agent.javassist.CtClass)3 CodeAttribute (org.hotswap.agent.javassist.bytecode.CodeAttribute)3 CodeIterator (org.hotswap.agent.javassist.bytecode.CodeIterator)3 MethodInfo (org.hotswap.agent.javassist.bytecode.MethodInfo)3 NotFoundException (org.hotswap.agent.javassist.NotFoundException)2 ConstPool (org.hotswap.agent.javassist.bytecode.ConstPool)2 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 List (java.util.List)1 CannotCompileException (org.hotswap.agent.javassist.CannotCompileException)1 CtBehavior (org.hotswap.agent.javassist.CtBehavior)1 Bytecode (org.hotswap.agent.javassist.bytecode.Bytecode)1