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;
}
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;
}
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);
}
}
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();
}
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();
}
Aggregations