Search in sources :

Example 1 with MethodInfo

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

the class FieldInitLink method instrument.

public void instrument(CodeConverter converter) throws CannotCompileException {
    checkModify();
    ClassFile cf = getClassFile2();
    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);
        converter.doit(this, minfo, cp);
    }
}
Also used : ConstPool(org.hotswap.agent.javassist.bytecode.ConstPool) ClassFile(org.hotswap.agent.javassist.bytecode.ClassFile) ArrayList(java.util.ArrayList) List(java.util.List) MethodInfo(org.hotswap.agent.javassist.bytecode.MethodInfo)

Example 2 with MethodInfo

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

the class FieldInitLink method instrument.

public void instrument(ExprEditor editor) throws CannotCompileException {
    checkModify();
    ClassFile cf = getClassFile2();
    List list = cf.getMethods();
    int n = list.size();
    for (int i = 0; i < n; ++i) {
        MethodInfo minfo = (MethodInfo) list.get(i);
        editor.doit(this, minfo);
    }
}
Also used : ClassFile(org.hotswap.agent.javassist.bytecode.ClassFile) ArrayList(java.util.ArrayList) List(java.util.List) MethodInfo(org.hotswap.agent.javassist.bytecode.MethodInfo)

Example 3 with MethodInfo

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

the class FieldInitLink method removeMethod.

public void removeMethod(CtMethod m) throws NotFoundException {
    checkModify();
    MethodInfo mi = m.getMethodInfo2();
    ClassFile cf = getClassFile2();
    if (cf.getMethods().remove(mi)) {
        getMembers().remove(m);
        gcConstPool = true;
    } else
        throw new NotFoundException(m.toString());
}
Also used : ClassFile(org.hotswap.agent.javassist.bytecode.ClassFile) MethodInfo(org.hotswap.agent.javassist.bytecode.MethodInfo)

Example 4 with MethodInfo

use of org.hotswap.agent.javassist.bytecode.MethodInfo 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)

Example 5 with MethodInfo

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

the class FieldInitLink method makeMemberList.

private void makeMemberList(HashMap table) {
    int mod = getModifiers();
    if (Modifier.isAbstract(mod) || Modifier.isInterface(mod))
        try {
            CtClass[] ifs = getInterfaces();
            int size = ifs.length;
            for (int i = 0; i < size; i++) {
                CtClass ic = ifs[i];
                if (ic != null && ic instanceof CtClassType)
                    ((CtClassType) ic).makeMemberList(table);
            }
        } catch (NotFoundException e) {
        }
    try {
        CtClass s = getSuperclass();
        if (s != null && s instanceof CtClassType)
            ((CtClassType) s).makeMemberList(table);
    } catch (NotFoundException e) {
    }
    List list = getClassFile2().getMethods();
    int n = list.size();
    for (int i = 0; i < n; i++) {
        MethodInfo minfo = (MethodInfo) list.get(i);
        table.put(minfo.getName(), this);
    }
    list = getClassFile2().getFields();
    n = list.size();
    for (int i = 0; i < n; i++) {
        FieldInfo finfo = (FieldInfo) list.get(i);
        table.put(finfo.getName(), this);
    }
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) MethodInfo(org.hotswap.agent.javassist.bytecode.MethodInfo) FieldInfo(org.hotswap.agent.javassist.bytecode.FieldInfo)

Aggregations

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