OptimizerOptionspublic class OptimizerOptions extends Object Settings for optimization of code. |
Fields Summary |
---|
private static HashSet | optimizeList{@code null-ok;} hash set of class name + method names that
should be optimized. {@code null} if this constraint was not
specified on the command line | private static HashSet | dontOptimizeList{@code null-ok;} hash set of class name + method names that should NOT
be optimized. null if this constraint was not specified on the
command line | private static boolean | optimizeListsLoadedtrue if the above lists have been loaded |
Constructors Summary |
---|
private OptimizerOptions()This class is uninstantiable.
// This space intentionally left blank.
|
Methods Summary |
---|
public static void | compareOptimizerStep(com.android.dx.rop.code.RopMethod nonOptRmeth, int paramSize, boolean isStatic, CfOptions args, com.android.dx.rop.code.TranslationAdvice advice, com.android.dx.rop.code.RopMethod rmeth)Compares the output of the optimizer run normally with a run skipping
some optional steps. Results are printed to stderr.
EnumSet<Optimizer.OptionalStep> steps;
steps = EnumSet.allOf(Optimizer.OptionalStep.class);
// This is the step to skip.
steps.remove(Optimizer.OptionalStep.CONST_COLLECTOR);
RopMethod skipRopMethod
= Optimizer.optimize(nonOptRmeth,
paramSize, isStatic, args.localInfo, advice, steps);
int normalInsns
= rmeth.getBlocks().getEffectiveInstructionCount();
int skipInsns
= skipRopMethod.getBlocks().getEffectiveInstructionCount();
System.err.printf(
"optimize step regs:(%d/%d/%.2f%%)"
+ " insns:(%d/%d/%.2f%%)\n",
rmeth.getBlocks().getRegCount(),
skipRopMethod.getBlocks().getRegCount(),
100.0 * ((skipRopMethod.getBlocks().getRegCount()
- rmeth.getBlocks().getRegCount())
/ (float) skipRopMethod.getBlocks().getRegCount()),
normalInsns, skipInsns,
100.0 * ((skipInsns - normalInsns) / (float) skipInsns));
| public static void | loadOptimizeLists(java.lang.String optimizeListFile, java.lang.String dontOptimizeListFile)Loads the optimize/don't optimize lists from files.
if (optimizeListsLoaded) {
return;
}
if (optimizeListFile != null && dontOptimizeListFile != null) {
/*
* We shouldn't get this far. The condition should have
* been caught in the arg processor.
*/
throw new RuntimeException("optimize and don't optimize lists "
+ " are mutually exclusive.");
}
if (optimizeListFile != null) {
optimizeList = loadStringsFromFile(optimizeListFile);
}
if (dontOptimizeListFile != null) {
dontOptimizeList = loadStringsFromFile(dontOptimizeListFile);
}
optimizeListsLoaded = true;
| private static java.util.HashSet | loadStringsFromFile(java.lang.String filename)Loads a list of newline-separated strings into a new HashSet and returns
the HashSet.
HashSet<String> result = new HashSet<String>();
try {
FileReader fr = new FileReader(filename);
BufferedReader bfr = new BufferedReader(fr);
String line;
while (null != (line = bfr.readLine())) {
result.add(line);
}
fr.close();
} catch (IOException ex) {
// Let the exception percolate up as a RuntimeException.
throw new RuntimeException("Error with optimize list: " +
filename, ex);
}
return result;
| public static boolean | shouldOptimize(java.lang.String canonicalMethodName)Checks whether the specified method should be optimized
// Optimize only what's in the optimize list.
if (optimizeList != null) {
return optimizeList.contains(canonicalMethodName);
}
/*
* Or don't optimize what's listed here. (The two lists are
* mutually exclusive.
*/
if (dontOptimizeList != null) {
return !dontOptimizeList.contains(canonicalMethodName);
}
// If neither list has been specified, then optimize everything.
return true;
|
|