Search in sources :

Example 1 with MemberID

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

the class DFACallgraphBuilder method getInvokedMethods.

@Override
protected Set<MethodInfo> getInvokedMethods(ExecutionContext context, InvokeSite invokeSite) {
    // to avoid problems we only use the DFA for virtual calls, all other can be uniquely resolved anyway.
    if (!invokeSite.isVirtual()) {
        return Collections.singleton(invokeSite.getInvokeeRef().getMethodInfo());
    }
    Set<String> receivers = dfaTool.getReceivers(invokeSite.getInstructionHandle(), context.getCallString());
    if (receivers == null) {
        // This can happen e.g. because we have all Runnable.run() methods as roots, regardless if they are used
        logger.debug("No receivers for " + invokeSite.getInvokeeRef() + " at " + invokeSite + " in call context " + context.getCallString().toStringVerbose(false));
        return appInfo.findImplementations(invokeSite, context.getCallString());
    }
    if (receivers.size() == 0) {
        // This can happen if a method is analyzed for some contexts but not for this context
        logger.debug("No receivers for " + invokeSite.getInvokeeRef() + " at " + invokeSite + " in call context " + context.getCallString().toStringVerbose(false));
        return appInfo.findImplementations(invokeSite, context.getCallString());
    }
    Set<MethodInfo> methods = new LinkedHashSet<MethodInfo>(receivers.size());
    for (String rcv : receivers) {
        MemberID mId = MemberID.parse(rcv);
        methods.add(appInfo.getMethodRef(mId).getMethodInfo());
    }
    return methods;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) MemberID(com.jopdesign.common.type.MemberID) MethodInfo(com.jopdesign.common.MethodInfo)

Example 2 with MemberID

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

the class InlineHelper method makePublic.

private void makePublic(ClassMemberInfo member) {
    boolean wasPrivate = member.isPrivate();
    // If we need to make it public, check if we need to make the class and all enclosing classes public too
    ClassInfo cls = member.getClassInfo();
    while (cls != null) {
        if (!cls.isPublic()) {
            cls.setAccessType(AccessType.ACC_PUBLIC);
        }
        cls = cls.getEnclosingClassInfo();
    }
    if (wasPrivate && member instanceof MethodInfo) {
        // we are done here. if the method was private, there are no conflicting
        // methods or we needed to rename it anyway.
        member.setAccessType(AccessType.ACC_PUBLIC);
        return;
    }
    // if we make a non-private method or any field public, need to go down to find all overriding
    // members and make them public too
    final MemberID memberID = member.getMemberID();
    ClassVisitor visitor = new EmptyClassVisitor() {

        @Override
        public boolean visitClass(ClassInfo classInfo) {
            ClassMemberInfo m = classInfo.getMemberInfo(memberID);
            if (m == null) {
                return true;
            }
            if (m.isPublic()) {
                // we do not need to go further down if we find a public member
                return false;
            }
            m.setAccessType(AccessType.ACC_PUBLIC);
            return true;
        }
    };
    new ClassHierarchyTraverser(visitor).traverseDown(member.getClassInfo());
}
Also used : MemberID(com.jopdesign.common.type.MemberID) ClassMemberInfo(com.jopdesign.common.ClassMemberInfo) MethodInfo(com.jopdesign.common.MethodInfo) ClassHierarchyTraverser(com.jopdesign.common.graphutils.ClassHierarchyTraverser) EmptyClassVisitor(com.jopdesign.common.graphutils.EmptyClassVisitor) ClassVisitor(com.jopdesign.common.graphutils.ClassVisitor) EmptyClassVisitor(com.jopdesign.common.graphutils.EmptyClassVisitor) ClassInfo(com.jopdesign.common.ClassInfo)

Example 3 with MemberID

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

the class AppSetup method getMainSignature.

private MemberID getMainSignature(String signature) throws BadConfigurationException {
    MemberID sMain;
    ClassPath path = new ClassPath(config.getOption(Config.CLASSPATH));
    MemberID sMainMethod = MemberID.parse(config.getOption(Config.MAIN_METHOD_NAME), path);
    if (signature == null || "".equals(signature)) {
        sMain = sMainMethod;
    } else {
        // try to parse the signature
        sMain = MemberID.parse(signature, path);
        // use --mm if only main class has been given
        if (!sMain.hasMemberName()) {
            if (!sMainMethod.hasMemberName()) {
                throw new BadConfigurationException("Option '" + Config.MAIN_METHOD_NAME.getKey() + "' needs to specify a method name.");
            }
            sMain = new MemberID(sMain.getClassName(), sMainMethod.getMemberName(), sMainMethod.getDescriptor());
        }
    }
    return sMain;
}
Also used : MemberID(com.jopdesign.common.type.MemberID) ClassPath(org.apache.bcel.util.ClassPath) BadConfigurationException(com.jopdesign.common.config.Config.BadConfigurationException)

Example 4 with MemberID

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

the class AppSetup method initProcessorModel.

private void initProcessorModel(Model model) {
    ProcessorModel pm;
    switch(model) {
        case JOP:
            pm = new JOPModel(config);
            break;
        case jamuth:
            pm = new JamuthModel(config);
            break;
        case allocation:
            pm = new AllocationModel(config);
            break;
        case JVM:
            pm = new JVMModel();
            break;
        default:
            throw new BadConfigurationError("Unknown processor model " + model);
    }
    appInfo.setProcessorModel(pm);
    // load referenced classes as roots
    for (String jvmClass : pm.getJVMClasses()) {
        ClassInfo rootInfo = appInfo.loadClass(jvmClass.replaceAll("/", "."));
        if (rootInfo == null) {
            System.err.println("Error loading JVM class '" + jvmClass + "'.");
            System.exit(4);
        }
    }
    if (appInfo.doLoadNatives()) {
        for (String nativeClass : pm.getNativeClasses()) {
            ClassInfo rootInfo = appInfo.loadClass(nativeClass.replaceAll("/", "."));
            if (rootInfo == null) {
                System.err.println("Error loading Native class '" + nativeClass + "'.");
                System.exit(4);
            }
        }
    }
    // we do not set the JVM and native classes as root anymore, instead we let the PM decide which roots we need
    for (String root : pm.getJVMRoots()) {
        MemberID mID = MemberID.parse(root);
        // make sure the class exists..
        ClassInfo cls = appInfo.loadClass(mID.getClassName());
        // Get the member and add it as root
        if (mID.hasMemberName()) {
            MethodInfo methodInfo = cls.getMethodInfo(mID);
            if (methodInfo == null) {
                System.err.println("Could not find JVM root " + root);
                System.exit(5);
            }
            appInfo.addRoot(methodInfo);
        } else {
            appInfo.addRoot(cls);
        }
    }
}
Also used : MemberID(com.jopdesign.common.type.MemberID) BadConfigurationError(com.jopdesign.common.config.Config.BadConfigurationError) JOPModel(com.jopdesign.common.processormodel.JOPModel) AllocationModel(com.jopdesign.common.processormodel.AllocationModel) ProcessorModel(com.jopdesign.common.processormodel.ProcessorModel) JVMModel(com.jopdesign.common.processormodel.JVMModel) JamuthModel(com.jopdesign.common.processormodel.JamuthModel)

Example 5 with MemberID

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

the class InvokeSite method resolveInvokeSuper.

/**
 * Resolve the reference to the super method.
 * See #isInvokeSuper() for more details.
 *
 * @param ref the method referenced by the instruction
 * @return the reference to the method to invoke
 */
private MethodRef resolveInvokeSuper(MethodRef ref) {
    String superClass = invoker.getClassInfo().getSuperClassName();
    // Restart the lookup in the super class of the invoker class
    MemberID superId = new MemberID(superClass, ref.getName(), ref.getDescriptor());
    // invokespecial is never used for interface invokes
    MethodRef superRef = AppInfo.getSingleton().getMethodRef(superId, false);
    if (ref.getMethodInfo() != null && !ref.getMethodInfo().equals(superRef.getMethodInfo())) {
        // Just give a warning, just in case there is some code out there which handles this incorrectly..
        // Warning level might be changed to debug someday..
        logger.warn("InvokeSpecial in " + invoker + " calls super method " + superRef + " but refers to " + ref + " which is valid, but you might want to know that..");
    }
    return superRef;
}
Also used : MemberID(com.jopdesign.common.type.MemberID) MethodRef(com.jopdesign.common.type.MethodRef)

Aggregations

MemberID (com.jopdesign.common.type.MemberID)15 MethodInfo (com.jopdesign.common.MethodInfo)7 ClassInfo (com.jopdesign.common.ClassInfo)4 ArrayList (java.util.ArrayList)3 BadConfigurationException (com.jopdesign.common.config.Config.BadConfigurationException)2 MethodNotFoundException (com.jopdesign.common.misc.MethodNotFoundException)2 MethodRef (com.jopdesign.common.type.MethodRef)2 BufferedReader (java.io.BufferedReader)2 FileReader (java.io.FileReader)2 IOException (java.io.IOException)2 LinkedHashSet (java.util.LinkedHashSet)2 List (java.util.List)2 ConstantPoolGen (org.apache.bcel.generic.ConstantPoolGen)2 ClassMemberInfo (com.jopdesign.common.ClassMemberInfo)1 FieldInfo (com.jopdesign.common.FieldInfo)1 CallString (com.jopdesign.common.code.CallString)1 BadConfigurationError (com.jopdesign.common.config.Config.BadConfigurationError)1 ClassHierarchyTraverser (com.jopdesign.common.graphutils.ClassHierarchyTraverser)1 ClassVisitor (com.jopdesign.common.graphutils.ClassVisitor)1 EmptyClassVisitor (com.jopdesign.common.graphutils.EmptyClassVisitor)1