Search in sources :

Example 11 with ClassInfo

use of com.jopdesign.common.ClassInfo in project jop by jop-devel.

the class AppLoader method processClassName.

private int processClassName(String className) {
    AppInfo appInfo = AppInfo.getSingleton();
    int cnt = 0;
    ClassInfo cls;
    if (appInfo.hasClassInfo(className)) {
        cls = appInfo.getClassInfo(className);
    } else {
        cls = appInfo.loadClass(className);
        if (cls != null) {
            newClasses.add(cls);
            cnt++;
        }
    }
    if (cls != null) {
        enqueue(cls);
    }
    return cnt;
}
Also used : AppInfo(com.jopdesign.common.AppInfo) ClassInfo(com.jopdesign.common.ClassInfo)

Example 12 with ClassInfo

use of com.jopdesign.common.ClassInfo in project jop by jop-devel.

the class ClinitOrder method printDependency.

/**
     * Print the dependency for debugging. Not used at the moment.
     * @param warn if true, print with warning level
     */
private void printDependency(boolean warn) {
    Priority lvl = warn ? Level.WARN : Level.DEBUG;
    Set<ClassInfo> cliSet = clinit.keySet();
    for (ClassInfo clinf : cliSet) {
        logger.log(lvl, "Class " + clinf.getClassName());
        Set<ClassInfo> depends = clinit.get(clinf);
        for (ClassInfo clf : depends) {
            logger.log(lvl, "\tdepends " + clf.getClassName());
        }
    }
}
Also used : Priority(org.apache.log4j.Priority) ClassInfo(com.jopdesign.common.ClassInfo)

Example 13 with ClassInfo

use of com.jopdesign.common.ClassInfo in project jop by jop-devel.

the class ClinitOrder method visitClass.

@Override
public boolean visitClass(ClassInfo classInfo) {
    MethodInfo mi = classInfo.getMethodInfo(clinitSig);
    if (mi != null) {
        Set<ClassInfo> depends = findDependencies(mi, false);
        clinit.put(classInfo, depends);
    }
    return true;
}
Also used : MethodInfo(com.jopdesign.common.MethodInfo) ConstantMethodInfo(com.jopdesign.common.type.ConstantMethodInfo) ClassInfo(com.jopdesign.common.ClassInfo)

Example 14 with ClassInfo

use of com.jopdesign.common.ClassInfo in project jop by jop-devel.

the class ClinitOrder method findDependencies.

private Set<ClassInfo> findDependencies(MethodInfo method, boolean inRec) {
    //		System.out.println("find dep. in "+cli.clazz.getClassName()+":"+mi.getMethod().getName());
    Set<ClassInfo> depends = new HashSet<ClassInfo>();
    if (method.isNative() || method.isAbstract()) {
        // subclasses???? :-(
        return depends;
    }
    ClassInfo classInfo = method.getClassInfo();
    ConstantPoolGen cpoolgen = method.getConstantPoolGen();
    InstructionList il = method.getCode().getInstructionList();
    InstructionFinder f = new InstructionFinder(il);
    // TODO can we encounter an empty instruction list?
    //if(il.getStart() == null) {
    //    return depends;
    //}
    // find instructions that access the constant pool
    // collect all indices to constants in ClassInfo
    String cpInstr = "CPInstruction";
    for (Iterator it = f.search(cpInstr); it.hasNext(); ) {
        InstructionHandle[] match = (InstructionHandle[]) it.next();
        InstructionHandle first = match[0];
        CPInstruction ii = (CPInstruction) first.getInstruction();
        int idx = ii.getIndex();
        Constant co = cpoolgen.getConstant(idx);
        ClassRef classRef = null;
        Set addDepends = null;
        ClassInfo clinfo;
        MethodInfo minfo;
        switch(co.getTag()) {
            case Constants.CONSTANT_Class:
                classRef = classInfo.getConstantInfo(co).getClassRef();
                clinfo = classRef.getClassInfo();
                if (clinfo != null) {
                    minfo = clinfo.getMethodInfo("<init>()V");
                    if (minfo != null) {
                        addDepends = findDependencies(minfo, true);
                    }
                }
                break;
            case Constants.CONSTANT_Fieldref:
            case Constants.CONSTANT_InterfaceMethodref:
                classRef = classInfo.getConstantInfo(co).getClassRef();
                break;
            case Constants.CONSTANT_Methodref:
                ConstantMethodInfo mref = (ConstantMethodInfo) classInfo.getConstantInfo(co);
                classRef = mref.getClassRef();
                minfo = mref.getMethodRef().getMethodInfo();
                if (minfo != null) {
                    addDepends = findDependencies(minfo, true);
                }
                break;
        }
        if (classRef != null) {
            ClassInfo clinf = classRef.getClassInfo();
            if (clinf != null) {
                if (clinf.getMethodInfo(clinitSig) != null) {
                    // don't add myself as dependency
                    if (!clinf.equals(method.getClassInfo())) {
                        depends.add(clinf);
                    }
                }
            }
        }
        if (addDepends != null) {
            for (Object addDepend : addDepends) {
                ClassInfo addCli = (ClassInfo) addDepend;
                if (addCli.equals(method.getClassInfo())) {
                    throw new JavaClassFormatError("cyclic indirect <clinit> dependency");
                }
                depends.add(addCli);
            }
        }
    }
    return depends;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) ClassRef(com.jopdesign.common.type.ClassRef) InstructionList(org.apache.bcel.generic.InstructionList) Constant(org.apache.bcel.classfile.Constant) InstructionFinder(org.apache.bcel.util.InstructionFinder) InstructionHandle(org.apache.bcel.generic.InstructionHandle) ConstantMethodInfo(com.jopdesign.common.type.ConstantMethodInfo) ConstantPoolGen(org.apache.bcel.generic.ConstantPoolGen) CPInstruction(org.apache.bcel.generic.CPInstruction) JavaClassFormatError(com.jopdesign.common.misc.JavaClassFormatError) Iterator(java.util.Iterator) MethodInfo(com.jopdesign.common.MethodInfo) ConstantMethodInfo(com.jopdesign.common.type.ConstantMethodInfo) HashSet(java.util.HashSet) ClassInfo(com.jopdesign.common.ClassInfo)

Example 15 with ClassInfo

use of com.jopdesign.common.ClassInfo in project jop by jop-devel.

the class UsedCodeFinder method getClassInfo.

private ClassInfo getClassInfo(MemberID sig) {
    String className;
    if (sig.isArrayClass()) {
        ArrayTypeInfo at = ArrayTypeInfo.parse(sig.getClassName());
        if (at.getElementType() instanceof ObjectTypeInfo) {
            className = ((ObjectTypeInfo) at.getElementType()).getClassRef().getClassName();
        } else {
            return null;
        }
    } else {
        className = sig.getClassName();
    }
    ClassInfo classInfo = appInfo.getClassInfo(className);
    if (classInfo == null) {
        ignoreClass(className);
    }
    return classInfo;
}
Also used : ObjectTypeInfo(com.jopdesign.common.type.ObjectTypeInfo) ArrayTypeInfo(com.jopdesign.common.type.ArrayTypeInfo) ClassInfo(com.jopdesign.common.ClassInfo)

Aggregations

ClassInfo (com.jopdesign.common.ClassInfo)49 MethodInfo (com.jopdesign.common.MethodInfo)19 DefaultEdge (org.jgrapht.graph.DefaultEdge)8 AppInfo (com.jopdesign.common.AppInfo)7 HashMap (java.util.HashMap)7 InstructionHandle (org.apache.bcel.generic.InstructionHandle)7 HashSet (java.util.HashSet)6 Set (java.util.Set)6 IOException (java.io.IOException)5 LinkedList (java.util.LinkedList)5 FieldInfo (com.jopdesign.common.FieldInfo)4 JavaClassFormatError (com.jopdesign.common.misc.JavaClassFormatError)4 MemberID (com.jopdesign.common.type.MemberID)4 BitSet (java.util.BitSet)3 AppSetup (com.jopdesign.common.AppSetup)2 MethodCode (com.jopdesign.common.MethodCode)2 BasicBlock (com.jopdesign.common.code.BasicBlock)2 CallString (com.jopdesign.common.code.CallString)2 CFGNode (com.jopdesign.common.code.ControlFlowGraph.CFGNode)2 ExecutionContext (com.jopdesign.common.code.ExecutionContext)2