Search in sources :

Example 16 with AppInfo

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

the class InlineHelper method devirtualize.

/**
 * Devirtualize an invocation.
 * <p>
 * Since this uses the callgraph if available, the callstring must match the state of the callgraph,
 * i.e. if an invocation in the callstring has been inlined and the callgraph has been updated to reflect
 * the new invoke, the inlined invocation must be removed from the callstring too.
 * Contrariwise, if an invoke has been inlined but the callgraph has not yet been updated, the callstring
 * must also contain the inlined invoke. Also the callstring does not need to start at the method to optimize.
 * This is different from what {@link #canInline(CallString, InvokeSite, MethodInfo)} expects.
 * </p>
 *
 * @see #canInline(CallString, InvokeSite, MethodInfo)
 * @param invokers the callstring of the invocation to devirtualize. The last entry must be the invoke site to
 *                 devirtualize. The first first entry does not need to be the method into which inlining
 *                 is performed.
 * @return the method info to call if unique, else null.
 */
public MethodInfo devirtualize(CallString invokers) {
    AppInfo appInfo = AppInfo.getSingleton();
    Set<MethodInfo> methods = appInfo.findImplementations(invokers);
    if (methods.size() == 1) {
        return methods.iterator().next();
    } else {
        return null;
    }
}
Also used : MethodInfo(com.jopdesign.common.MethodInfo) AppInfo(com.jopdesign.common.AppInfo)

Example 17 with AppInfo

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

the class UnusedCodeRemover method execute.

public void execute() {
    ucf.resetMarks();
    // This starts at all app roots and JVM roots, as well as all threads,
    // <clinit> methods are marked in all reached classes
    ucf.markUsedMembers();
    // We also need to mark everything else we do not want to remove ..
    AppInfo appInfo = AppInfo.getSingleton();
    ProcessorModel pm = appInfo.getProcessorModel();
    if (pm.keepJVMClasses()) {
        for (String clName : pm.getJVMClasses()) {
            ClassInfo cls = appInfo.getClassInfo(clName);
            if (cls != null) {
                ucf.markUsedMembers(cls, true);
            }
        }
    }
    removeUnusedMembers();
}
Also used : ProcessorModel(com.jopdesign.common.processormodel.ProcessorModel) AppInfo(com.jopdesign.common.AppInfo) ClassInfo(com.jopdesign.common.ClassInfo)

Example 18 with AppInfo

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

the class AppLoader method loadAll.

public void loadAll(boolean startFromRootsOnly) {
    AppInfo appInfo = AppInfo.getSingleton();
    if (startFromRootsOnly) {
        // we only work on classes, not methods, so starting with root classes is sufficient here
        enqueue(appInfo.getRootClasses());
    } else {
        enqueue(appInfo.getClassInfos());
    }
    processQueue();
}
Also used : AppInfo(com.jopdesign.common.AppInfo)

Example 19 with AppInfo

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

the class ExampleTool method doSomething.

public void doSomething(Config config) {
    AppInfo appInfo = AppInfo.getSingleton();
    // access and modify some classes
    System.out.println("field of main class: " + manager.getMyField(appInfo.getMainMethod().getClassInfo()));
    for (ClassInfo root : appInfo.getRootClasses()) {
        System.out.println("field of root: " + manager.getMyField(root));
    }
    // create a new class and new methods
    try {
        ClassInfo newCls = appInfo.createClass("MyTest", appInfo.getClassRef("java.lang.Object"), false);
    } catch (NamingConflictException e) {
        e.printStackTrace();
    }
}
Also used : AppInfo(com.jopdesign.common.AppInfo) ClassInfo(com.jopdesign.common.ClassInfo) NamingConflictException(com.jopdesign.common.misc.NamingConflictException)

Example 20 with AppInfo

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

the class ClassWriter method write.

public void write(String writeDir) throws IOException {
    AppInfo appInfo = AppInfo.getSingleton();
    if (logger.isInfoEnabled()) {
        logger.info("Start writing classes to '" + writeDir + "' ..");
    }
    File classDir = new File(writeDir);
    if (classDir.exists()) {
        if (classDir.isFile()) {
            throw new IOException("Output directory '" + classDir + "' is a file.");
        }
    } else if (!classDir.mkdirs()) {
        throw new IOException("Could not create output directory " + classDir);
    }
    for (ClassInfo cls : appInfo.getClassInfos()) {
        if (logger.isDebugEnabled()) {
            logger.debug("Writing class: " + cls.getClassName());
        }
        JavaClass jc = cls.compile();
        String filename = classDir + File.separator + cls.getClassName().replace(".", File.separator) + ".class";
        File file = new File(filename);
        String parent = file.getParent();
        if (parent != null) {
            File pDir = new File(parent);
            // noinspection ResultOfMethodCallIgnored
            pDir.mkdirs();
        }
        BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(file));
        DataOutputStream stream = new DataOutputStream(out);
        jc.dump(stream);
        stream.close();
    }
    if (logger.isInfoEnabled()) {
        logger.info(appInfo.getClassInfos().size() + " classes written.");
    }
}
Also used : JavaClass(org.apache.bcel.classfile.JavaClass) DataOutputStream(java.io.DataOutputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream) AppInfo(com.jopdesign.common.AppInfo) ClassInfo(com.jopdesign.common.ClassInfo)

Aggregations

AppInfo (com.jopdesign.common.AppInfo)21 AppSetup (com.jopdesign.common.AppSetup)7 ClassInfo (com.jopdesign.common.ClassInfo)7 MethodInfo (com.jopdesign.common.MethodInfo)7 File (java.io.File)4 IOException (java.io.IOException)4 TestFramework (com.jopdesign.common.TestFramework)3 JavaClassFormatError (com.jopdesign.common.misc.JavaClassFormatError)2 FileWriter (java.io.FileWriter)2 LinkedHashSet (java.util.LinkedHashSet)2 FieldInfo (com.jopdesign.common.FieldInfo)1 MethodCode (com.jopdesign.common.MethodCode)1 CallGraph (com.jopdesign.common.code.CallGraph)1 CFGNode (com.jopdesign.common.code.ControlFlowGraph.CFGNode)1 InvokeNode (com.jopdesign.common.code.ControlFlowGraph.InvokeNode)1 ExecutionContext (com.jopdesign.common.code.ExecutionContext)1 InvokeSite (com.jopdesign.common.code.InvokeSite)1 SuperGraph (com.jopdesign.common.code.SuperGraph)1 ContextCFG (com.jopdesign.common.code.SuperGraph.ContextCFG)1 SuperEdge (com.jopdesign.common.code.SuperGraph.SuperEdge)1