Search in sources :

Example 11 with DFATool

use of com.jopdesign.dfa.DFATool in project jop by jop-devel.

the class CallStringReceiverTypes method doInvokeVirtual.

private void doInvokeVirtual(String receiver, MethodInfo method, InstructionHandle stmt, Context context, ContextMap<CallString, Set<TypeMapping>> input, Interpreter<CallString, Set<TypeMapping>> interpreter, Map<InstructionHandle, ContextMap<CallString, Set<TypeMapping>>> state, ContextMap<CallString, Set<TypeMapping>> result) {
    String methodImplName = method.getClassName() + "." + method.getMethodSignature();
    recordReceiver(stmt, context, methodImplName);
    //		LineNumberTable lines = p.getMethods().get(context.method).getLineNumberTable(context.constPool);
    //		int sourceLine = lines.getSourceLine(stmt.getPosition());
    //		String invokeId = context.method+"\t"+":"+sourceLine+"."+stmt.getPosition();
    // set up new context
    int varPtr = context.stackPtr - MethodHelper.getArgSize(method);
    Context c = new Context(context);
    c.stackPtr = method.getCode().getMaxLocals();
    if (method.isSynchronized()) {
        c.syncLevel = context.syncLevel + 1;
    }
    c.setMethodInfo(method);
    c.callString = c.callString.push(context.getMethodInfo(), stmt, callStringLength);
    boolean threaded = false;
    DFATool p = interpreter.getDFATool();
    if (p.getAppInfo().getClassInfo(receiver).isSubclassOf(p.getAppInfo().getClassInfo("joprt.RtThread")) && "run()V".equals(method.getMethodSignature())) {
        c.createThread();
        threaded = true;
    }
    // carry only minimal information with call
    Set<TypeMapping> in = input.get(context.callString);
    Set<TypeMapping> out = new LinkedHashSet<TypeMapping>();
    ContextMap<CallString, Set<TypeMapping>> tmpresult = new ContextMap<CallString, Set<TypeMapping>>(c, new LinkedHashMap<CallString, Set<TypeMapping>>());
    tmpresult.put(c.callString, out);
    for (TypeMapping m : in) {
        if (m.stackLoc < 0) {
            out.add(m);
        }
        if (m.stackLoc > varPtr) {
            out.add(new TypeMapping(m.stackLoc - varPtr, m.type));
        }
        if (m.stackLoc == varPtr) {
            // add "this"
            ClassInfo staticClass = p.getAppInfo().getClassInfo(receiver);
            ClassInfo dynamicClass = null;
            try {
                dynamicClass = p.getAppInfo().getClassInfo(m.type.split("@")[0]);
            } catch (MissingClassError ex) {
                logger.error("doInvokeVirtual - trying to improve type of " + staticClass + ": " + ex);
            // TODO: maybe we should throw an exception/error instead?
            }
            if (dynamicClass != null && dynamicClass.isSubclassOf(staticClass)) {
                out.add(new TypeMapping(0, m.type));
            }
        }
    }
    InstructionHandle entry = p.getEntryHandle(method);
    state.put(entry, join(state.get(entry), tmpresult));
    // interpret method
    Map<InstructionHandle, ContextMap<CallString, Set<TypeMapping>>> r = interpreter.interpret(c, entry, state, false);
    // pull out relevant information from call
    InstructionHandle exit = p.getExitHandle(method);
    if (r.get(exit) != null) {
        Set<TypeMapping> returned = r.get(exit).get(c.callString);
        if (returned != null) {
            filterReturnSet(returned, result.get(context.callString), varPtr);
        }
    }
    // update all threads
    if (threaded) {
        threads.put(methodImplName, new ContextMap<CallString, Set<TypeMapping>>(c, result));
        updateThreads(result, interpreter, state);
    }
}
Also used : Context(com.jopdesign.dfa.framework.Context) LinkedHashSet(java.util.LinkedHashSet) DFATool(com.jopdesign.dfa.DFATool) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) CallString(com.jopdesign.common.code.CallString) ContextMap(com.jopdesign.dfa.framework.ContextMap) InstructionHandle(org.apache.bcel.generic.InstructionHandle) CallString(com.jopdesign.common.code.CallString) ClassInfo(com.jopdesign.common.ClassInfo) MissingClassError(com.jopdesign.common.misc.MissingClassError)

Example 12 with DFATool

use of com.jopdesign.dfa.DFATool in project jop by jop-devel.

the class PhaseExecutor method dataflowAnalysis.

/////////////////////////////////////////////////////////////////////////////////////
// Perform analyses
/////////////////////////////////////////////////////////////////////////////////////
@SuppressWarnings("unchecked")
public void dataflowAnalysis(boolean loopBounds) {
    int callstringLength = appInfo.getCallstringLength();
    // TODO this code is the same as in WCETTool ..
    DFATool dfaTool = jcopter.getDfaTool();
    logger.info("Starting DFA analysis");
    dfaTool.setAnalyzeBootMethod(true);
    dfaTool.load();
    logger.info("Receiver analysis");
    dfaTool.runReceiverAnalysis(callstringLength);
    if (loopBounds) {
        logger.info("Loop bound analysis");
        dfaTool.runLoopboundAnalysis(callstringLength);
        // need to tell this to the WCA tool
        if (jcopter.useWCA()) {
            jcopter.getWcetTool().setHasDfaResults(true);
        }
    }
    dfaTool.cleanup();
}
Also used : DFATool(com.jopdesign.dfa.DFATool)

Example 13 with DFATool

use of com.jopdesign.dfa.DFATool in project jop by jop-devel.

the class UppAalAnalysis method main.

public static void main(String[] args) {
    // We set a different output path for this tool if invoked by cmdline
    // Note that WCETTool could also override defaults, but we do not want to change the
    // default value of outdir if WCETTool is invoked from another tool
    Properties defaultProps = new Properties();
    defaultProps.put("outdir", "java/target/wcet/${projectname}");
    AppSetup setup = new AppSetup(defaultProps, false);
    setup.setVersionInfo("1.0 [deprecated]");
    // We do not load a config file automatically, user has to specify it explicitly to avoid
    // unintentional misconfiguration
    //setup.setConfigFilename(CONFIG_FILE_NAME);
    setup.setUsageInfo("UppAllAnalysis", "UppAll WCET Analysis");
    WCETTool wcetTool = new WCETTool();
    DFATool dfaTool = new DFATool();
    setup.registerTool("dfa", dfaTool, true, false);
    setup.registerTool("wcet", wcetTool);
    @SuppressWarnings("unused") AppInfo appInfo = setup.initAndLoad(args, true, false, false);
    if (setup.useTool("dfa")) {
        wcetTool.setDfaTool(dfaTool);
    }
    ExecHelper exec = new ExecHelper(setup.getConfig(), tlLogger);
    exec.dumpConfig();
    UppAalAnalysis inst = new UppAalAnalysis(wcetTool);
    /* run */
    if (!inst.run(exec))
        exec.bail("UppAal translation failed");
    tlLogger.info("UppAal translation finished");
}
Also used : DFATool(com.jopdesign.dfa.DFATool) AppSetup(com.jopdesign.common.AppSetup) Properties(java.util.Properties) AppInfo(com.jopdesign.common.AppInfo)

Aggregations

DFATool (com.jopdesign.dfa.DFATool)13 CallString (com.jopdesign.common.code.CallString)8 Context (com.jopdesign.dfa.framework.Context)8 ContextMap (com.jopdesign.dfa.framework.ContextMap)8 MethodInfo (com.jopdesign.common.MethodInfo)6 Set (java.util.Set)6 LinkedHashSet (java.util.LinkedHashSet)5 InstructionHandle (org.apache.bcel.generic.InstructionHandle)5 AppSetup (com.jopdesign.common.AppSetup)3 AppInfoError (com.jopdesign.common.misc.AppInfoError)3 LinkedHashMap (java.util.LinkedHashMap)3 GETFIELD (org.apache.bcel.generic.GETFIELD)3 GETSTATIC (org.apache.bcel.generic.GETSTATIC)3 Instruction (org.apache.bcel.generic.Instruction)3 LDC (org.apache.bcel.generic.LDC)3 LoadInstruction (org.apache.bcel.generic.LoadInstruction)3 PUTFIELD (org.apache.bcel.generic.PUTFIELD)3 PUTSTATIC (org.apache.bcel.generic.PUTSTATIC)3 ReferenceType (org.apache.bcel.generic.ReferenceType)3 StoreInstruction (org.apache.bcel.generic.StoreInstruction)3