Search in sources :

Example 6 with ClassInfo

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

the class UnusedCodeRemover method removeMethod.

private int removeMethod(MethodInfo m) {
    ClassInfo cls = m.getClassInfo();
    logger.debug("Removing unused method " + m);
    cls.removeMethod(m.getMethodSignature());
    return 1;
}
Also used : ClassInfo(com.jopdesign.common.ClassInfo)

Example 7 with ClassInfo

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

the class UnusedCodeRemover method removeField.

private int removeField(FieldInfo f) {
    if (f.isStatic() && f.isFinal() && !removeConstFields) {
        logger.debug("Not removing unused static final " + f);
        // Instead, mark it as unused
        f.setUnusedAnnotation();
        return 0;
    } else {
        ClassInfo cls = f.getClassInfo();
        logger.debug("Removing unused field " + f);
        cls.removeField(f.getShortName());
        return 1;
    }
}
Also used : ClassInfo(com.jopdesign.common.ClassInfo)

Example 8 with ClassInfo

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

the class UnusedCodeRemover method removeUnusedMembers.

/**
     * Remove all unused classes, methods and fields.
     */
private void removeUnusedMembers() {
    AppInfo appInfo = AppInfo.getSingleton();
    // we cannot modify the lists while iterating through it
    List<ClassInfo> unusedClasses = new LinkedList<ClassInfo>();
    List<FieldInfo> unusedFields = new LinkedList<FieldInfo>();
    List<MethodInfo> unusedMethods = new LinkedList<MethodInfo>();
    int fields = 0;
    int methods = 0;
    for (ClassInfo cls : appInfo.getClassInfos()) {
        if (ucf.getMark(cls) == Mark.UNUSED) {
            unusedClasses.add(cls);
            logger.debug("Removing unused class " + cls);
            continue;
        }
        unusedFields.clear();
        unusedMethods.clear();
        if (appInfo.isHwObject(cls)) {
            // Do not remove fields from hardware objects, else the mapping gets broken and
            // chaos takes over!
            logger.debug("Skipping fields of used hardware object " + cls);
        } else {
            for (FieldInfo f : cls.getFields()) {
                if (ucf.getMark(f) == Mark.UNUSED) {
                    unusedFields.add(f);
                }
            }
        }
        for (MethodInfo m : cls.getMethods()) {
            Mark mark = ucf.getMark(m);
            if (mark == Mark.UNUSED) {
                unusedMethods.add(m);
            }
            if (mark == Mark.MARKED && !m.isNative() && !m.isAbstract()) {
                logger.info("Making unused method " + m + " abstract");
                m.setAbstract(true);
                m.getClassInfo().setAbstract(true);
            }
        }
        for (FieldInfo f : unusedFields) {
            fields += removeField(f);
        }
        for (MethodInfo m : unusedMethods) {
            methods += removeMethod(m);
        }
    }
    appInfo.removeClasses(unusedClasses);
    int classes = unusedClasses.size();
    logger.info("Removed " + classes + (classes == 1 ? " class, " : " classes, ") + fields + (fields == 1 ? " field, " : " fields, ") + methods + (methods == 1 ? " method" : " methods"));
}
Also used : Mark(com.jopdesign.common.tools.UsedCodeFinder.Mark) MethodInfo(com.jopdesign.common.MethodInfo) LinkedList(java.util.LinkedList) FieldInfo(com.jopdesign.common.FieldInfo) AppInfo(com.jopdesign.common.AppInfo) ClassInfo(com.jopdesign.common.ClassInfo)

Example 9 with ClassInfo

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

the class JOPModel method getJavaImplementation.

public MethodInfo getJavaImplementation(AppInfo ai, MethodInfo context, Instruction instr) {
    ClassInfo receiver = ai.getClassInfo(JVM_CLASS);
    String methodName = "f_" + JopInstr.name(getNativeOpCode(context, instr));
    Set<MethodInfo> mi = receiver.getMethodByName(methodName);
    if (!mi.isEmpty()) {
        if (mi.size() > 1) {
            throw new JavaClassFormatError("JVM class " + JVM_CLASS + " has more than one implementation of " + methodName);
        }
        return mi.iterator().next();
    }
    return null;
}
Also used : JavaClassFormatError(com.jopdesign.common.misc.JavaClassFormatError) MethodInfo(com.jopdesign.common.MethodInfo) ClassInfo(com.jopdesign.common.ClassInfo)

Example 10 with ClassInfo

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

the class AppLoader method processQueue.

private void processQueue() {
    if (logger.isInfoEnabled()) {
        logger.info("Starting transitive hull loader");
    }
    while (!queue.isEmpty()) {
        ClassInfo next = queue.remove(0);
        if (logger.isDebugEnabled()) {
            logger.debug("Processing class: " + next.getClassName());
        }
        int found = 0;
        for (String name : ConstantPoolReferenceFinder.findReferencedClasses(next)) {
            found += processClassName(name);
        }
        if (logger.isDebugEnabled()) {
            logger.debug("Found " + found + " new classes in " + next.getClassName());
        }
    }
    if (logger.isInfoEnabled()) {
        logger.info("AppLoader loaded " + newClasses.size() + " new classes");
    }
}
Also used : 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