Search in sources :

Example 6 with CodeIterator

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);
    }
}
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 7 with CodeIterator

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

Aggregations

CodeIterator (org.hotswap.agent.javassist.bytecode.CodeIterator)7 CodeAttribute (org.hotswap.agent.javassist.bytecode.CodeAttribute)4 BadBytecode (org.hotswap.agent.javassist.bytecode.BadBytecode)3 MethodInfo (org.hotswap.agent.javassist.bytecode.MethodInfo)2 Iterator (java.util.Iterator)1 CannotCompileException (org.hotswap.agent.javassist.CannotCompileException)1 NotFoundException (org.hotswap.agent.javassist.NotFoundException)1 ConstPool (org.hotswap.agent.javassist.bytecode.ConstPool)1 ExceptionTable (org.hotswap.agent.javassist.bytecode.ExceptionTable)1