FileDocCategorySizeDatePackage
OptimizerOptions.javaAPI DocAndroid 1.5 API6124Wed May 06 22:41:02 BST 2009com.android.dx.dex.cf

OptimizerOptions

public class OptimizerOptions extends Object
Settings for optimization of code.

Fields Summary
private static HashSet
optimizeList
null-ok; hash set of class name + method names that should be optimized. null if this constraint was not specified on the command line
private static HashSet
dontOptimizeList
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
optimizeListsLoaded
true if the above lists have been loaded
Constructors Summary
private OptimizerOptions()
This class is uninstantiable.

        // This space intentionally left blank.
    
Methods Summary
public static voidcompareOptimizerStep(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.

param
nonOptRmeth non-null; origional rop method
param
paramSize >= 0 parameter size of method
param
isStatic true if this method has no 'this' pointer argument.
param
args non-null; translator arguments
param
advice non-null; translation advice
param
rmeth non-null; method with all optimization steps run.

        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 voidloadOptimizeLists(java.lang.String optimizeListFile, java.lang.String dontOptimizeListFile)
Loads the optimize/don't optimize lists from files.

param
optimizeListFile Pathname
param
dontOptimizeListFile Pathname

        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.HashSetloadStringsFromFile(java.lang.String filename)
Loads a list of newline-separated strings into a new HashSet and returns the HashSet.

param
filename filename to process
return
set of all unique lines in the file

        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);
            }
        } catch (IOException ex) {
            // Let the exception percolate up as a RuntimeException.
            throw new RuntimeException("Error with optimize list: " +
                    filename, ex);
        }

        return result;
    
public static booleanshouldOptimize(java.lang.String canonicalMethodName)
Checks whether the specified method should be optimized

param
canonicalMethodName name of method being considered
return
true if it 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;