Search in sources :

Example 1 with BadConfigurationException

use of com.jopdesign.common.config.Config.BadConfigurationException in project jop by jop-devel.

the class OptionGroup method parseOption.

protected int parseOption(String[] args, String key, int pos) throws BadConfigurationException {
    Option<?> spec = getOptionSpec(key);
    if (spec != null) {
        if (isHidden(spec)) {
            throw new BadConfigurationException("Invalid option: " + spec);
        }
        String val = null;
        if (pos + 1 < args.length) {
            String newVal = args[pos + 1];
            // allow to set to empty string
            if ("''".equals(newVal) || "\"\"".equals(newVal)) {
                newVal = "";
            }
            if (spec.isValue(newVal)) {
                val = newVal;
            }
        }
        int i = pos;
        if (spec instanceof BooleanOption && val == null) {
            val = "true";
        } else if (val == null) {
            throw new BadConfigurationException("Missing argument for option: " + spec);
        } else {
            i++;
        }
        config.setProperty(getConfigKey(spec), val);
        return i;
    }
    // maybe a boolean option, check for --no-<key>
    if (key.startsWith("no-")) {
        spec = getOptionSpec(key.substring(3));
        if (isHidden(spec)) {
            throw new BadConfigurationException("Invalid option: " + spec);
        }
        if (spec != null && spec instanceof BooleanOption) {
            config.setProperty(getConfigKey(spec), "false");
        } else if (spec != null) {
            // unset it
            config.setProperty(getConfigKey(spec), null);
        }
    // else spec == null;
    } else if (key.contains(".")) {
        // or maybe a sub-option
        int j = key.indexOf('.');
        OptionGroup group = subGroups.get(key.substring(0, j));
        if (group != null) {
            return group.parseOption(args, key.substring(j + 1), pos);
        }
    }
    if (spec == null) {
        throw new BadConfigurationException("Unknown option: " + key);
    }
    return pos;
}
Also used : BadConfigurationException(com.jopdesign.common.config.Config.BadConfigurationException)

Example 2 with BadConfigurationException

use of com.jopdesign.common.config.Config.BadConfigurationException 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 3 with BadConfigurationException

use of com.jopdesign.common.config.Config.BadConfigurationException in project jop by jop-devel.

the class CallGraph method dumpCallgraph.

/**
     * Dump this callgraph or a subgraph to a file and create a png image.
     * If you use this method, add {@link #CALLGRAPH_DIR} to the options.
     *
     * @param config the config containing options for InvokeDot and {@link #CALLGRAPH_DIR}
     * @param graphName the name of the graph, will be used to construct the file name.
     * @param suffix a suffix for the graph name, e.g. to distinguish between various subgraphs
     * @param roots The roots of the subgraph to dump. If null, dump the whole graph. If roots is empty, do nothing.
     * @param type dump the complete graph, dump only the merged graph, or dump both or nothing.
     * @param skipNoim if true, do not include methods which have a single edge to the JVM.noim method.
     * @throws IOException if exporting the file fails.
     */
public void dumpCallgraph(Config config, String graphName, String suffix, Set<ExecutionContext> roots, DUMPTYPE type, boolean skipNoim) throws IOException {
    if (type == DUMPTYPE.off)
        return;
    if (roots != null && roots.isEmpty())
        return;
    File outDir;
    try {
        outDir = config.getOutDir(config.getDebugGroup(), CallGraph.CALLGRAPH_DIR);
    } catch (BadConfigurationException e) {
        throw new BadConfigurationError("Could not create output dir " + config.getDebugGroup().getOption(CallGraph.CALLGRAPH_DIR), e);
    }
    CallGraph subGraph = roots == null ? this : getSubGraph(roots);
    if (type == CallGraph.DUMPTYPE.merged || type == CallGraph.DUMPTYPE.both) {
        dumpCallgraph(config, outDir, graphName, suffix, subGraph, true, skipNoim);
    }
    if (type == CallGraph.DUMPTYPE.full || type == CallGraph.DUMPTYPE.both) {
        dumpCallgraph(config, outDir, graphName, suffix, subGraph, false, skipNoim);
    }
    if (roots != null) {
        removeSubGraph(subGraph);
    }
}
Also used : BadConfigurationError(com.jopdesign.common.config.Config.BadConfigurationError) BadConfigurationException(com.jopdesign.common.config.Config.BadConfigurationException) File(java.io.File)

Example 4 with BadConfigurationException

use of com.jopdesign.common.config.Config.BadConfigurationException in project jop by jop-devel.

the class AppSetup method getMainMethod.

private MethodInfo getMainMethod(String signature) throws Config.BadConfigurationException {
    ClassInfo clsInfo;
    String clsName;
    MemberID sMain = getMainSignature(signature);
    clsName = sMain.getClassName();
    if (clsName == null) {
        throw new BadConfigurationException("You need to specify a classname for the main method.");
    }
    try {
        clsInfo = appInfo.loadClass(clsName, true, false);
    } catch (ClassInfoNotFoundException e) {
        throw new BadConfigurationException("Class for '" + signature + "' could not be loaded: " + e.getMessage(), e);
    }
    // check if we have a full signature
    if (sMain.hasMethodSignature()) {
        MethodInfo method = clsInfo.getMethodInfo(sMain.getMethodSignature());
        if (method == null) {
            throw new BadConfigurationException("Method '" + sMain.getMethodSignature() + "' not found in '" + clsName + "'.");
        }
        return method;
    }
    // try to find main method
    String mainName = sMain.getMemberName();
    if (mainName == null) {
        mainName = config.getOption(Config.MAIN_METHOD_NAME);
        if (mainName != null) {
            mainName = MemberID.parse(mainName).getMethodSignature();
        }
    }
    Collection<MethodInfo> methods = clsInfo.getMethodByName(mainName);
    if (methods.isEmpty()) {
        throw new BadConfigurationException("'No method '" + mainName + "' found in '" + clsName + "'.");
    }
    if (methods.size() > 1) {
        StringBuilder s = new StringBuilder(String.format("Multiple candidates for '%s' in '%s', please specify with a signature: ", mainName, clsName));
        for (MethodInfo m : methods) {
            s.append("\n");
            s.append(m.getMemberID());
        }
        throw new BadConfigurationException(s.toString());
    }
    return methods.iterator().next();
}
Also used : MemberID(com.jopdesign.common.type.MemberID) ClassInfoNotFoundException(com.jopdesign.common.misc.ClassInfoNotFoundException) BadConfigurationException(com.jopdesign.common.config.Config.BadConfigurationException)

Example 5 with BadConfigurationException

use of com.jopdesign.common.config.Config.BadConfigurationException in project jop by jop-devel.

the class AnalysisManager method initAnalyses.

/**
     * Quick'n'dirty initialization of all analyses.
     * If the analyses get more options or get more complex in the future, this will need some work.
     *
     * @param targets the root methods to use for all analyses and the callgraph.
     * @param cacheAnalysisType cache analysis type
     * @param wcaRoots if not null, initialize the WCA invoker with these roots.
     * @param updateWCEP if true, let the wcaInvoker provide a global WCET path and keep it up-to-date
     */
public void initAnalyses(Set<MethodInfo> targets, AnalysisType cacheAnalysisType, CacheCostCalculationMethod cacheApproximation, boolean useMethodCacheStrategy, Set<MethodInfo> wcaRoots, boolean updateWCEP) {
    logger.info("Initializing analyses..");
    Set<MethodInfo> allTargets = new LinkedHashSet<MethodInfo>(targets);
    if (wcaRoots != null) {
        // Just make sure the WCA callgraph is contained in the target graph..
        allTargets.addAll(wcaRoots);
        wcaInvoker = new WCAInvoker(this, wcaRoots, cacheApproximation);
        wcaInvoker.setProvideWCAExecCount(updateWCEP);
        try {
            // need to initialize the WCA Tool before the other analyses since we need the WCA callgraph
            wcaInvoker.initTool();
        } catch (BadConfigurationException e) {
            // TODO or maybe just throw the exception up a few levels more?
            throw new BadConfigurationError(e.getMessage(), e);
        }
    }
    if (wcaRoots != null && wcaRoots.equals(allTargets) && wcaInvoker.getWCACallGraphs().size() == 1) {
        targetCallGraph = wcaInvoker.getWCACallGraphs().iterator().next();
    } else {
        logger.info("Initializing Target Callgraph");
        targetCallGraph = CallGraph.buildCallGraph(allTargets, new DefaultCallgraphBuilder(AppInfo.getSingleton().getCallstringLength()));
    }
    // TODO we might want to classify methods depending on whether they are reachable from the wcaRoots
    //      for all non-wca-methods we might want to use different initial analysis data, e.g.
    //      if we use the WCA, we might want to use the IPET WCA to initialize the execCountAnalysis for
    //      wca-methods
    // We can do this as first step (after the callgraph has been created) since it does not use the ExecFrequencyAnalysis
    logger.info("Initializing MethodCacheAnalysis");
    methodCacheAnalysis = new MethodCacheAnalysis(jcopter, cacheAnalysisType, targetCallGraph);
    methodCacheAnalysis.initialize();
    if (wcaRoots != null) {
        logger.info("Initializing WCAInvoker");
        wcaInvoker.initAnalysis(useMethodCacheStrategy);
    }
    // TODO in fact, we might not even need this if we only use the wcaInvoker as provider or some other provider
    logger.info("Initializing ExecFrequencyAnalysis");
    execFreqAnalysis = new ExecFrequencyAnalysis(this, targetCallGraph);
    execFreqAnalysis.initialize();
}
Also used : LinkedHashSet(java.util.LinkedHashSet) BadConfigurationError(com.jopdesign.common.config.Config.BadConfigurationError) DefaultCallgraphBuilder(com.jopdesign.common.code.DefaultCallgraphBuilder) BadConfigurationException(com.jopdesign.common.config.Config.BadConfigurationException) MethodInfo(com.jopdesign.common.MethodInfo)

Aggregations

BadConfigurationException (com.jopdesign.common.config.Config.BadConfigurationException)8 IOException (java.io.IOException)3 DefaultCallgraphBuilder (com.jopdesign.common.code.DefaultCallgraphBuilder)2 BadConfigurationError (com.jopdesign.common.config.Config.BadConfigurationError)2 MemberID (com.jopdesign.common.type.MemberID)2 File (java.io.File)2 MethodInfo (com.jopdesign.common.MethodInfo)1 Config (com.jopdesign.common.config.Config)1 AppInfoException (com.jopdesign.common.misc.AppInfoException)1 BadGraphException (com.jopdesign.common.misc.BadGraphException)1 ClassInfoNotFoundException (com.jopdesign.common.misc.ClassInfoNotFoundException)1 MethodNotFoundException (com.jopdesign.common.misc.MethodNotFoundException)1 JOPConfig (com.jopdesign.common.processormodel.JOPConfig)1 DFACallgraphBuilder (com.jopdesign.dfa.framework.DFACallgraphBuilder)1 BlockAllocationModel (com.jopdesign.wcet.allocation.BlockAllocationModel)1 HandleAllocationModel (com.jopdesign.wcet.allocation.HandleAllocationModel)1 HeaderAllocationModel (com.jopdesign.wcet.allocation.HeaderAllocationModel)1 ObjectAllocationModel (com.jopdesign.wcet.allocation.ObjectAllocationModel)1 BadAnnotationException (com.jopdesign.wcet.annotations.BadAnnotationException)1 IPETConfig (com.jopdesign.wcet.ipet.IPETConfig)1