Search in sources :

Example 6 with FieldInfo

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

the class AllocationWcetModel method getObjectFields.

public List<Type> getObjectFields(String className) {
    List<Type> l = new LinkedList<Type>();
    ClassInfo cli = project.getAppInfo().getClassInfo(className);
    if (cli.getSuperClassName() != null) {
        l.addAll(getObjectFields(cli.getSuperClassName()));
    }
    for (FieldInfo f : cli.getFields()) {
        if (!f.isStatic()) {
            l.add(f.getType());
        }
    }
    return l;
}
Also used : Type(org.apache.bcel.generic.Type) ObjectType(org.apache.bcel.generic.ObjectType) LinkedList(java.util.LinkedList) FieldInfo(com.jopdesign.common.FieldInfo) ClassInfo(com.jopdesign.common.ClassInfo)

Example 7 with FieldInfo

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

the class DescendingClassTraverser method visitClass.

public boolean visitClass(ClassInfo classInfo) {
    if (!visitor.visitClass(classInfo)) {
        return returnOnSkipClass;
    }
    visitConstantPool(classInfo);
    // methods and fields are final, no need to call accept()
    for (FieldInfo f : classInfo.getFields()) {
        if (!visitor.visitField(f)) {
            continue;
        }
        bcelVisitor.setFieldInfo(f);
        visitAttributes(f.getAttributes());
        visitor.finishField(f);
    }
    for (MethodInfo m : classInfo.getMethods()) {
        if (!visitor.visitMethod(m)) {
            continue;
        }
        bcelVisitor.setMethodInfo(m);
        visitMethodCode(m);
        visitAttributes(m.getAttributes());
        visitor.finishMethod(m);
    }
    bcelVisitor.setClassInfo(classInfo);
    visitAttributes(classInfo.getAttributes());
    visitor.finishClass(classInfo);
    return true;
}
Also used : MethodInfo(com.jopdesign.common.MethodInfo) FieldInfo(com.jopdesign.common.FieldInfo)

Example 8 with FieldInfo

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

the class ConstantPoolReferenceFinder method findPoolReferences.

////////////////////////////////////////////////////////////////
// Find/replace references, member names, Pool entries
////////////////////////////////////////////////////////////////
public static Set<Integer> findPoolReferences(ClassInfo classInfo, boolean checkMembers) {
    JavaClass javaClass = classInfo.compile();
    Set<Integer> ids = findPoolReferences(classInfo, javaClass);
    if (checkMembers) {
        for (Field field : javaClass.getFields()) {
            FieldInfo fieldInfo = classInfo.getFieldInfo(field.getName());
            ids.addAll(findPoolReferences(fieldInfo, field));
        }
        for (Method method : javaClass.getMethods()) {
            MethodInfo methodInfo = classInfo.getMethodInfo(method.getName() + method.getSignature());
            ids.addAll(findPoolReferences(methodInfo, method));
        }
    }
    return ids;
}
Also used : ConstantInteger(org.apache.bcel.classfile.ConstantInteger) Field(org.apache.bcel.classfile.Field) JavaClass(org.apache.bcel.classfile.JavaClass) MethodInfo(com.jopdesign.common.MethodInfo) ConstantMethodInfo(com.jopdesign.common.type.ConstantMethodInfo) Method(org.apache.bcel.classfile.Method) EnclosingMethod(com.jopdesign.common.bcel.EnclosingMethod) ConstantFieldInfo(com.jopdesign.common.type.ConstantFieldInfo) FieldInfo(com.jopdesign.common.FieldInfo)

Example 9 with FieldInfo

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

the class UsedCodeFinder method markUsedMembers.

public void markUsedMembers(ClassInfo rootClass, boolean visitMembers) {
    // has already been visited before, do not recurse down again.
    if (!visitMembers && setMark(rootClass, true) == Mark.USED)
        return;
    // visit superclass and interfaces, attributes, but not methods or fields
    if (logger.isTraceEnabled()) {
        logger.trace("Visiting references of " + rootClass);
    }
    Set<String> found = ConstantPoolReferenceFinder.findReferencedMembers(rootClass, false);
    visitReferences(found);
    if (visitMembers) {
        for (FieldInfo field : rootClass.getFields()) {
            markUsedMembers(field);
        }
        for (MethodInfo method : rootClass.getMethods()) {
            markUsedMembers(method);
        }
    } else {
        // at least we need to visit the static initializer
        MethodInfo clinit = rootClass.getMethodInfo(ClinitOrder.clinitSig);
        if (clinit != null) {
            markUsedMembers(clinit);
        }
    // TODO if this implements Runnable, we could also mark the run() method, but using the callgraph
    // to find used threads is a bit more flexible
    }
}
Also used : MethodInfo(com.jopdesign.common.MethodInfo) FieldInfo(com.jopdesign.common.FieldInfo)

Example 10 with FieldInfo

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

the class UsedCodeFinder method visitReferences.

private void visitReferences(Set<String> refs) {
    for (String id : refs) {
        // The member IDs returned by the reference finder use a syntax which is
        // always unique, so if in doubt, we need to interpret it as a classname, not a fieldname
        MemberID sig = MemberID.parse(id, false);
        // find/load the corresponding classInfo
        ClassInfo cls = getClassInfo(sig);
        // class has been excluded from loading, skip this class
        if (cls == null) {
            continue;
        }
        // referenced class is used, visit it if it has not yet been visited, but skip its class members
        // Note that this class might be different than the class containing the class member
        markUsedMembers(cls, false);
        // check if this id specifies a class member (or just a class, in this case we are done)
        if (sig.hasMethodSignature()) {
            // It's a method! mark the method as used (implementations are marked later)
            MethodRef ref = appInfo.getMethodRef(sig);
            MethodInfo method = ref.getMethodInfo();
            // we keep the declarations. We mark it without following it and make it abstract later.
            if (method != null) {
                setMark(method, false);
            }
        } else if (sig.hasMemberName()) {
            // It's a field! No need to look in subclasses, fields are not virtual
            FieldRef ref = appInfo.getFieldRef(sig);
            FieldInfo field = ref.getFieldInfo();
            if (field != null) {
                markUsedMembers(field);
            }
        }
    }
}
Also used : MemberID(com.jopdesign.common.type.MemberID) MethodRef(com.jopdesign.common.type.MethodRef) FieldRef(com.jopdesign.common.type.FieldRef) MethodInfo(com.jopdesign.common.MethodInfo) FieldInfo(com.jopdesign.common.FieldInfo) ClassInfo(com.jopdesign.common.ClassInfo)

Aggregations

FieldInfo (com.jopdesign.common.FieldInfo)10 MethodInfo (com.jopdesign.common.MethodInfo)8 ClassInfo (com.jopdesign.common.ClassInfo)4 InvokeSite (com.jopdesign.common.code.InvokeSite)3 FieldRef (com.jopdesign.common.type.FieldRef)3 MethodRef (com.jopdesign.common.type.MethodRef)3 MethodCode (com.jopdesign.common.MethodCode)2 EnclosingMethod (com.jopdesign.common.bcel.EnclosingMethod)2 ConstantFieldInfo (com.jopdesign.common.type.ConstantFieldInfo)2 ConstantMethodInfo (com.jopdesign.common.type.ConstantMethodInfo)2 LinkedList (java.util.LinkedList)2 ConstantInteger (org.apache.bcel.classfile.ConstantInteger)2 Field (org.apache.bcel.classfile.Field)2 JavaClass (org.apache.bcel.classfile.JavaClass)2 Method (org.apache.bcel.classfile.Method)2 ConstantPushInstruction (org.apache.bcel.generic.ConstantPushInstruction)2 FieldInstruction (org.apache.bcel.generic.FieldInstruction)2 Instruction (org.apache.bcel.generic.Instruction)2 InstructionHandle (org.apache.bcel.generic.InstructionHandle)2 InvokeInstruction (org.apache.bcel.generic.InvokeInstruction)2