Search in sources :

Example 1 with BadBytecode

use of org.hotswap.agent.javassist.bytecode.BadBytecode in project HotswapAgent by HotswapProjects.

the class Analyzer method mergeJsr.

private void mergeJsr(IntQueue queue, Frame frame, Subroutine sub, int pos, int next) throws BadBytecode {
    if (sub == null)
        throw new BadBytecode("No subroutine at jsr target! [pos = " + pos + "]");
    Frame old = frames[next];
    boolean changed = false;
    if (old == null) {
        old = frames[next] = frame.copy();
        changed = true;
    } else {
        for (int i = 0; i < frame.localsLength(); i++) {
            // Skip everything accessed by a subroutine, mergeRet must handle this
            if (!sub.isAccessed(i)) {
                Type oldType = old.getLocal(i);
                Type newType = frame.getLocal(i);
                if (oldType == null) {
                    old.setLocal(i, newType);
                    changed = true;
                    continue;
                }
                newType = oldType.merge(newType);
                // Always set the type, in case a multi-type switched to a standard type.
                old.setLocal(i, newType);
                if (!newType.equals(oldType) || newType.popChanged())
                    changed = true;
            }
        }
    }
    if (!old.isJsrMerged()) {
        old.setJsrMerged(true);
        changed = true;
    }
    if (changed && old.isRetMerged())
        queue.add(next);
}
Also used : BadBytecode(org.hotswap.agent.javassist.bytecode.BadBytecode)

Example 2 with BadBytecode

use of org.hotswap.agent.javassist.bytecode.BadBytecode in project HotswapAgent by HotswapProjects.

the class Analyzer method mergeRet.

private void mergeRet(IntQueue queue, CodeIterator iter, int pos, Frame frame, Subroutine subroutine) throws BadBytecode {
    if (subroutine == null)
        throw new BadBytecode("Ret on no subroutine! [pos = " + pos + "]");
    Iterator callerIter = subroutine.callers().iterator();
    while (callerIter.hasNext()) {
        int caller = ((Integer) callerIter.next()).intValue();
        int returnLoc = getNext(iter, caller, pos);
        boolean changed = false;
        Frame old = frames[returnLoc];
        if (old == null) {
            old = frames[returnLoc] = frame.copyStack();
            changed = true;
        } else {
            changed = old.mergeStack(frame);
        }
        for (Iterator i = subroutine.accessed().iterator(); i.hasNext(); ) {
            int index = ((Integer) i.next()).intValue();
            Type oldType = old.getLocal(index);
            Type newType = frame.getLocal(index);
            if (oldType != newType) {
                old.setLocal(index, newType);
                changed = true;
            }
        }
        if (!old.isRetMerged()) {
            old.setRetMerged(true);
            changed = true;
        }
        if (changed && old.isJsrMerged())
            queue.add(returnLoc);
    }
}
Also used : Iterator(java.util.Iterator) CodeIterator(org.hotswap.agent.javassist.bytecode.CodeIterator) BadBytecode(org.hotswap.agent.javassist.bytecode.BadBytecode)

Example 3 with BadBytecode

use of org.hotswap.agent.javassist.bytecode.BadBytecode in project HotswapAgent by HotswapProjects.

the class Executor method paramTypesFromDesc.

private Type[] paramTypesFromDesc(String desc) throws BadBytecode {
    CtClass[] classes = null;
    try {
        classes = Descriptor.getParameterTypes(desc, classPool);
    } catch (NotFoundException e) {
        throw new BadBytecode("Could not find class in descriptor [pos = " + lastPos + "]: " + e.getMessage());
    }
    if (classes == null)
        throw new BadBytecode("Could not obtain parameters for descriptor [pos = " + lastPos + "]: " + desc);
    Type[] types = new Type[classes.length];
    for (int i = 0; i < types.length; i++) types[i] = Type.get(classes[i]);
    return types;
}
Also used : CtClass(org.hotswap.agent.javassist.CtClass) NotFoundException(org.hotswap.agent.javassist.NotFoundException) BadBytecode(org.hotswap.agent.javassist.bytecode.BadBytecode)

Example 4 with BadBytecode

use of org.hotswap.agent.javassist.bytecode.BadBytecode in project HotswapAgent by HotswapProjects.

the class TypeData method aastore.

public static void aastore(TypeData array, TypeData value, ClassPool cp) throws BadBytecode {
    if (array instanceof AbsTypeVar)
        if (!value.isNullType())
            ((AbsTypeVar) array).merge(ArrayType.make(value));
    if (value instanceof AbsTypeVar)
        if (array instanceof AbsTypeVar)
            // should call value.setType() later.
            ArrayElement.make(array);
        else if (array instanceof ClassName) {
            if (!array.isNullType()) {
                String type = ArrayElement.typeName(array.getName());
                value.setType(type, cp);
            }
        } else
            throw new BadBytecode("bad AASTORE: " + array);
}
Also used : BadBytecode(org.hotswap.agent.javassist.bytecode.BadBytecode)

Example 5 with BadBytecode

use of org.hotswap.agent.javassist.bytecode.BadBytecode in project HotswapAgent by HotswapProjects.

the class FieldInitLink method modifyConstructors.

private void modifyConstructors(ClassFile cf) throws CannotCompileException, NotFoundException {
    if (fieldInitializers == null)
        return;
    ConstPool cp = cf.getConstPool();
    List list = cf.getMethods();
    int n = list.size();
    for (int i = 0; i < n; ++i) {
        MethodInfo minfo = (MethodInfo) list.get(i);
        if (minfo.isConstructor()) {
            CodeAttribute codeAttr = minfo.getCodeAttribute();
            if (codeAttr != null)
                try {
                    Bytecode init = new Bytecode(cp, 0, codeAttr.getMaxLocals());
                    CtClass[] params = Descriptor.getParameterTypes(minfo.getDescriptor(), classPool);
                    int stacksize = makeFieldInitializer(init, params);
                    insertAuxInitializer(codeAttr, init, stacksize);
                    minfo.rebuildStackMapIf6(classPool, cf);
                } catch (BadBytecode e) {
                    throw new CannotCompileException(e);
                }
        }
    }
}
Also used : ConstPool(org.hotswap.agent.javassist.bytecode.ConstPool) CodeAttribute(org.hotswap.agent.javassist.bytecode.CodeAttribute) ArrayList(java.util.ArrayList) List(java.util.List) MethodInfo(org.hotswap.agent.javassist.bytecode.MethodInfo) BadBytecode(org.hotswap.agent.javassist.bytecode.BadBytecode) Bytecode(org.hotswap.agent.javassist.bytecode.Bytecode) 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