com.android.dx.rop.code.TranslationAdvice Java Examples

The following examples show how to use com.android.dx.rop.code.TranslationAdvice. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Optimizer.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Runs optimization algorthims over this method, and returns a new
 * instance of RopMethod with the changes.
 *
 * @param rmeth method to process
 * @param paramWidth the total width, in register-units, of this method's
 * parameters
 * @param isStatic true if this method has no 'this' pointer argument.
 * @param inPreserveLocals true if local variable info should be preserved,
 * at the cost of some registers and insns
 * @param inAdvice {@code non-null;} translation advice
 * @param steps set of optional optimization steps to run
 * @return optimized method
 */
public static RopMethod optimize(RopMethod rmeth, int paramWidth,
        boolean isStatic, boolean inPreserveLocals,
        TranslationAdvice inAdvice, EnumSet<OptionalStep> steps) {
    SsaMethod ssaMeth = null;

    preserveLocals = inPreserveLocals;
    advice = inAdvice;

    ssaMeth = SsaConverter.convertToSsaMethod(rmeth, paramWidth, isStatic);
    runSsaFormSteps(ssaMeth, steps);

    RopMethod resultMeth = SsaToRop.convertToRopMethod(ssaMeth, false);

    if (resultMeth.getBlocks().getRegCount()
            > advice.getMaxOptimalRegisterCount()) {
        // Try to see if we can squeeze it under the register count bar
        resultMeth = optimizeMinimizeRegisters(rmeth, paramWidth, isStatic,
                steps);
    }
    return resultMeth;
}
 
Example #2
Source File: Optimizer.java    From buck with Apache License 2.0 6 votes vote down vote up
/**
 * Runs optimization algorthims over this method, and returns a new
 * instance of RopMethod with the changes.
 *
 * @param rmeth method to process
 * @param paramWidth the total width, in register-units, of this method's
 * parameters
 * @param isStatic true if this method has no 'this' pointer argument.
 * @param inPreserveLocals true if local variable info should be preserved,
 * at the cost of some registers and insns
 * @param inAdvice {@code non-null;} translation advice
 * @param steps set of optional optimization steps to run
 * @return optimized method
 */
public static RopMethod optimize(RopMethod rmeth, int paramWidth,
        boolean isStatic, boolean inPreserveLocals,
        TranslationAdvice inAdvice, EnumSet<OptionalStep> steps) {
    SsaMethod ssaMeth = null;

    preserveLocals = inPreserveLocals;
    advice = inAdvice;

    ssaMeth = SsaConverter.convertToSsaMethod(rmeth, paramWidth, isStatic);
    runSsaFormSteps(ssaMeth, steps);

    RopMethod resultMeth = SsaToRop.convertToRopMethod(ssaMeth, false);

    if (resultMeth.getBlocks().getRegCount()
            > advice.getMaxOptimalRegisterCount()) {
        // Try to see if we can squeeze it under the register count bar
        resultMeth = optimizeMinimizeRegisters(rmeth, paramWidth, isStatic,
                steps);
    }
    return resultMeth;
}
 
Example #3
Source File: Optimizer.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Runs optimization algorthims over this method, and returns a new
 * instance of RopMethod with the changes.
 *
 * @param rmeth method to process
 * @param paramWidth the total width, in register-units, of this method's
 * parameters
 * @param isStatic true if this method has no 'this' pointer argument.
 * @param inPreserveLocals true if local variable info should be preserved,
 * at the cost of some registers and insns
 * @param inAdvice {@code non-null;} translation advice
 * @param steps set of optional optimization steps to run
 * @return optimized method
 */
public static RopMethod optimize(RopMethod rmeth, int paramWidth,
        boolean isStatic, boolean inPreserveLocals,
        TranslationAdvice inAdvice, EnumSet<OptionalStep> steps) {
    SsaMethod ssaMeth = null;

    preserveLocals = inPreserveLocals;
    advice = inAdvice;

    ssaMeth = SsaConverter.convertToSsaMethod(rmeth, paramWidth, isStatic);
    runSsaFormSteps(ssaMeth, steps);

    RopMethod resultMeth = SsaToRop.convertToRopMethod(ssaMeth, false);

    if (resultMeth.getBlocks().getRegCount()
            > advice.getMaxOptimalRegisterCount()) {
        // Try to see if we can squeeze it under the register count bar
        resultMeth = optimizeMinimizeRegisters(rmeth, paramWidth, isStatic,
                steps);
    }
    return resultMeth;
}
 
Example #4
Source File: Optimizer.java    From J2ME-Loader with Apache License 2.0 6 votes vote down vote up
/**
 * Runs optimization algorthims over this method, and returns a new
 * instance of RopMethod with the changes.
 *
 * @param rmeth method to process
 * @param paramWidth the total width, in register-units, of this method's
 * parameters
 * @param isStatic true if this method has no 'this' pointer argument.
 * @param inPreserveLocals true if local variable info should be preserved,
 * at the cost of some registers and insns
 * @param inAdvice {@code non-null;} translation advice
 * @param steps set of optional optimization steps to run
 * @return optimized method
 */
public static RopMethod optimize(RopMethod rmeth, int paramWidth,
        boolean isStatic, boolean inPreserveLocals,
        TranslationAdvice inAdvice, EnumSet<OptionalStep> steps) {
    SsaMethod ssaMeth = null;

    preserveLocals = inPreserveLocals;
    advice = inAdvice;

    ssaMeth = SsaConverter.convertToSsaMethod(rmeth, paramWidth, isStatic);
    runSsaFormSteps(ssaMeth, steps);

    RopMethod resultMeth = SsaToRop.convertToRopMethod(ssaMeth, false);

    if (resultMeth.getBlocks().getRegCount()
            > advice.getMaxOptimalRegisterCount()) {
        // Try to see if we can squeeze it under the register count bar
        resultMeth = optimizeMinimizeRegisters(rmeth, paramWidth, isStatic,
                steps);
    }
    return resultMeth;
}
 
Example #5
Source File: OptimizerOptions.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * Compares the output of the optimizer run normally with a run skipping
 * some optional steps. Results are printed to stderr.
 *
 * @param nonOptRmeth {@code non-null;} origional rop method
 * @param paramSize {@code >= 0;} parameter size of method
 * @param isStatic true if this method has no 'this' pointer argument.
 * @param args {@code non-null;} translator arguments
 * @param advice {@code non-null;} translation advice
 * @param rmeth {@code non-null;} method with all optimization steps run.
 */
public void compareOptimizerStep(RopMethod nonOptRmeth,
        int paramSize, boolean isStatic, CfOptions args,
        TranslationAdvice advice, RopMethod rmeth) {
    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));
}
 
Example #6
Source File: Optimizer.java    From Box with Apache License 2.0 5 votes vote down vote up
public static SsaMethod debugEdgeSplit(RopMethod rmeth, int paramWidth,
        boolean isStatic, boolean inPreserveLocals,
        TranslationAdvice inAdvice) {

    preserveLocals = inPreserveLocals;
    advice = inAdvice;

    return SsaConverter.testEdgeSplit(rmeth, paramWidth, isStatic);
}
 
Example #7
Source File: Optimizer.java    From Box with Apache License 2.0 5 votes vote down vote up
public static SsaMethod debugPhiPlacement(RopMethod rmeth, int paramWidth,
        boolean isStatic, boolean inPreserveLocals,
        TranslationAdvice inAdvice) {

    preserveLocals = inPreserveLocals;
    advice = inAdvice;

    return SsaConverter.testPhiPlacement(rmeth, paramWidth, isStatic);
}
 
Example #8
Source File: Optimizer.java    From Box with Apache License 2.0 5 votes vote down vote up
public static SsaMethod debugRenaming(RopMethod rmeth, int paramWidth,
        boolean isStatic, boolean inPreserveLocals,
        TranslationAdvice inAdvice) {

    preserveLocals = inPreserveLocals;
    advice = inAdvice;

    return SsaConverter.convertToSsaMethod(rmeth, paramWidth, isStatic);
}
 
Example #9
Source File: Optimizer.java    From Box with Apache License 2.0 5 votes vote down vote up
public static SsaMethod debugDeadCodeRemover(RopMethod rmeth,
        int paramWidth, boolean isStatic, boolean inPreserveLocals,
        TranslationAdvice inAdvice) {

    SsaMethod ssaMeth;

    preserveLocals = inPreserveLocals;
    advice = inAdvice;

    ssaMeth = SsaConverter.convertToSsaMethod(rmeth, paramWidth, isStatic);
    DeadCodeRemover.process(ssaMeth);

    return ssaMeth;
}
 
Example #10
Source File: OptimizerOptions.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/**
 * Compares the output of the optimizer run normally with a run skipping
 * some optional steps. Results are printed to stderr.
 *
 * @param nonOptRmeth {@code non-null;} origional rop method
 * @param paramSize {@code >= 0;} parameter size of method
 * @param isStatic true if this method has no 'this' pointer argument.
 * @param args {@code non-null;} translator arguments
 * @param advice {@code non-null;} translation advice
 * @param rmeth {@code non-null;} method with all optimization steps run.
 */
public void compareOptimizerStep(RopMethod nonOptRmeth,
        int paramSize, boolean isStatic, CfOptions args,
        TranslationAdvice advice, RopMethod rmeth) {
    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));
}
 
Example #11
Source File: Ropper.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/**
 * Converts a {@link ConcreteMethod} to a {@link RopMethod}.
 *
 * @param method {@code non-null;} method to convert
 * @param advice {@code non-null;} translation advice to use
 * @param methods {@code non-null;} list of methods defined by the class
 *     that defines {@code method}.
 * @return {@code non-null;} the converted instance
 */
public static RopMethod convert(ConcreteMethod method,
        TranslationAdvice advice, MethodList methods, DexOptions dexOptions) {
    try {
        Ropper r = new Ropper(method, advice, methods, dexOptions);
        r.doit();
        return r.getRopMethod();
    } catch (SimException ex) {
        ex.addContext("...while working on method " +
                      method.getNat().toHuman());
        throw ex;
    }
}
 
Example #12
Source File: Ropper.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs an instance. This class is not publicly instantiable; use
 * {@link #convert}.
 *
 * @param method {@code non-null;} method to convert
 * @param advice {@code non-null;} translation advice to use
 * @param methods {@code non-null;} list of methods defined by the class
 *     that defines {@code method}.
 * @param dexOptions {@code non-null;} options for dex output
 */
private Ropper(ConcreteMethod method, TranslationAdvice advice, MethodList methods,
        DexOptions dexOptions) {
    if (method == null) {
        throw new NullPointerException("method == null");
    }

    if (advice == null) {
        throw new NullPointerException("advice == null");
    }

    this.method = method;
    this.blocks = BasicBlocker.identifyBlocks(method);
    this.maxLabel = blocks.getMaxLabel();
    this.maxLocals = method.getMaxLocals();
    this.machine = new RopperMachine(this, method, advice, methods);
    this.sim = new Simulator(machine, method, dexOptions);
    this.startFrames = new Frame[maxLabel];
    this.subroutines = new Subroutine[maxLabel];

    /*
     * The "* 2 + 10" below is to conservatively believe that every
     * block is an exception handler target and should also
     * take care of enough other possible extra overhead such that
     * the underlying array is unlikely to need resizing.
     */
    this.result = new ArrayList<BasicBlock>(blocks.size() * 2 + 10);
    this.resultSubroutines =
        new ArrayList<IntList>(blocks.size() * 2 + 10);

    this.catchInfos = new CatchInfo[maxLabel];
    this.synchNeedsExceptionHandler = false;

    /*
     * Set up the first stack frame with the right limits, but leave it
     * empty here (to be filled in outside of the constructor).
     */
    startFrames[0] = new Frame(maxLocals, method.getMaxStack());
    exceptionSetupLabelAllocator = new ExceptionSetupLabelAllocator();
}
 
Example #13
Source File: RopperMachine.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs an instance.
 *
 * @param ropper {@code non-null;} ropper controlling this instance
 * @param method {@code non-null;} method being converted
 * @param advice {@code non-null;} translation advice to use
 * @param methods {@code non-null;} list of methods defined by the class
 *     that defines {@code method}.
 */
public RopperMachine(Ropper ropper, ConcreteMethod method,
        TranslationAdvice advice, MethodList methods) {
    super(method.getEffectiveDescriptor());

    if (methods == null) {
        throw new NullPointerException("methods == null");
    }

    if (ropper == null) {
        throw new NullPointerException("ropper == null");
    }

    if (advice == null) {
        throw new NullPointerException("advice == null");
    }

    this.ropper = ropper;
    this.method = method;
    this.methods = methods;
    this.advice = advice;
    this.maxLocals = method.getMaxLocals();
    this.insns = new ArrayList<Insn>(25);
    this.catches = null;
    this.catchesUsed = false;
    this.returns = false;
    this.primarySuccessorIndex = -1;
    this.extraBlockCount = 0;
    this.blockCanThrow = false;
    this.returnOp = null;
    this.returnPosition = null;
}
 
Example #14
Source File: Ropper.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Converts a {@link ConcreteMethod} to a {@link RopMethod}.
 *
 * @param method {@code non-null;} method to convert
 * @param advice {@code non-null;} translation advice to use
 * @param methods {@code non-null;} list of methods defined by the class
 *     that defines {@code method}.
 * @return {@code non-null;} the converted instance
 */
public static RopMethod convert(ConcreteMethod method,
        TranslationAdvice advice, MethodList methods, DexOptions dexOptions) {
    try {
        Ropper r = new Ropper(method, advice, methods, dexOptions);
        r.doit();
        return r.getRopMethod();
    } catch (SimException ex) {
        ex.addContext("...while working on method " +
                      method.getNat().toHuman());
        throw ex;
    }
}
 
Example #15
Source File: Ropper.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * Converts a {@link ConcreteMethod} to a {@link RopMethod}.
 *
 * @param method {@code non-null;} method to convert
 * @param advice {@code non-null;} translation advice to use
 * @param methods {@code non-null;} list of methods defined by the class
 *     that defines {@code method}.
 * @return {@code non-null;} the converted instance
 */
public static RopMethod convert(ConcreteMethod method,
        TranslationAdvice advice, MethodList methods) {
    try {
        Ropper r = new Ropper(method, advice, methods);
        r.doit();
        return r.getRopMethod();
    } catch (SimException ex) {
        ex.addContext("...while working on method " +
                      method.getNat().toHuman());
        throw ex;
    }
}
 
Example #16
Source File: Ropper.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs an instance. This class is not publicly instantiable; use
 * {@link #convert}.
 *
 * @param method {@code non-null;} method to convert
 * @param advice {@code non-null;} translation advice to use
 * @param methods {@code non-null;} list of methods defined by the class
 *     that defines {@code method}.
 */
private Ropper(ConcreteMethod method, TranslationAdvice advice, MethodList methods) {
    if (method == null) {
        throw new NullPointerException("method == null");
    }

    if (advice == null) {
        throw new NullPointerException("advice == null");
    }

    this.method = method;
    this.blocks = BasicBlocker.identifyBlocks(method);
    this.maxLabel = blocks.getMaxLabel();
    this.maxLocals = method.getMaxLocals();
    this.machine = new RopperMachine(this, method, advice, methods);
    this.sim = new Simulator(machine, method);
    this.startFrames = new Frame[maxLabel];
    this.subroutines = new Subroutine[maxLabel];

    /*
     * The "* 2 + 10" below is to conservatively believe that every
     * block is an exception handler target and should also
     * take care of enough other possible extra overhead such that
     * the underlying array is unlikely to need resizing.
     */
    this.result = new ArrayList<BasicBlock>(blocks.size() * 2 + 10);
    this.resultSubroutines =
        new ArrayList<IntList>(blocks.size() * 2 + 10);

    this.catchInfos = new CatchInfo[maxLabel];
    this.synchNeedsExceptionHandler = false;

    /*
     * Set up the first stack frame with the right limits, but leave it
     * empty here (to be filled in outside of the constructor).
     */
    startFrames[0] = new Frame(maxLocals, method.getMaxStack());
    exceptionSetupLabelAllocator = new ExceptionSetupLabelAllocator();
}
 
Example #17
Source File: RopperMachine.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs an instance.
 *
 * @param ropper {@code non-null;} ropper controlling this instance
 * @param method {@code non-null;} method being converted
 * @param advice {@code non-null;} translation advice to use
 * @param methods {@code non-null;} list of methods defined by the class
 *     that defines {@code method}.
 */
public RopperMachine(Ropper ropper, ConcreteMethod method,
        TranslationAdvice advice, MethodList methods) {
    super(method.getEffectiveDescriptor());

    if (methods == null) {
        throw new NullPointerException("methods == null");
    }

    if (ropper == null) {
        throw new NullPointerException("ropper == null");
    }

    if (advice == null) {
        throw new NullPointerException("advice == null");
    }

    this.ropper = ropper;
    this.method = method;
    this.methods = methods;
    this.advice = advice;
    this.maxLocals = method.getMaxLocals();
    this.insns = new ArrayList<Insn>(25);
    this.catches = null;
    this.catchesUsed = false;
    this.returns = false;
    this.primarySuccessorIndex = -1;
    this.extraBlockCount = 0;
    this.blockCanThrow = false;
    this.returnOp = null;
    this.returnPosition = null;
}
 
Example #18
Source File: Optimizer.java    From buck with Apache License 2.0 5 votes vote down vote up
public static SsaMethod debugEdgeSplit(RopMethod rmeth, int paramWidth,
        boolean isStatic, boolean inPreserveLocals,
        TranslationAdvice inAdvice) {

    preserveLocals = inPreserveLocals;
    advice = inAdvice;

    return SsaConverter.testEdgeSplit(rmeth, paramWidth, isStatic);
}
 
Example #19
Source File: Optimizer.java    From buck with Apache License 2.0 5 votes vote down vote up
public static SsaMethod debugPhiPlacement(RopMethod rmeth, int paramWidth,
        boolean isStatic, boolean inPreserveLocals,
        TranslationAdvice inAdvice) {

    preserveLocals = inPreserveLocals;
    advice = inAdvice;

    return SsaConverter.testPhiPlacement(rmeth, paramWidth, isStatic);
}
 
Example #20
Source File: Optimizer.java    From buck with Apache License 2.0 5 votes vote down vote up
public static SsaMethod debugRenaming(RopMethod rmeth, int paramWidth,
        boolean isStatic, boolean inPreserveLocals,
        TranslationAdvice inAdvice) {

    preserveLocals = inPreserveLocals;
    advice = inAdvice;

    return SsaConverter.convertToSsaMethod(rmeth, paramWidth, isStatic);
}
 
Example #21
Source File: Optimizer.java    From buck with Apache License 2.0 5 votes vote down vote up
public static SsaMethod debugDeadCodeRemover(RopMethod rmeth,
        int paramWidth, boolean isStatic, boolean inPreserveLocals,
        TranslationAdvice inAdvice) {

    SsaMethod ssaMeth;

    preserveLocals = inPreserveLocals;
    advice = inAdvice;

    ssaMeth = SsaConverter.convertToSsaMethod(rmeth, paramWidth, isStatic);
    DeadCodeRemover.process(ssaMeth);

    return ssaMeth;
}
 
Example #22
Source File: RopperMachine.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs an instance.
 *
 * @param ropper {@code non-null;} ropper controlling this instance
 * @param method {@code non-null;} method being converted
 * @param advice {@code non-null;} translation advice to use
 * @param methods {@code non-null;} list of methods defined by the class
 *     that defines {@code method}.
 */
public RopperMachine(Ropper ropper, ConcreteMethod method,
        TranslationAdvice advice, MethodList methods) {
    super(method.getEffectiveDescriptor());

    if (methods == null) {
        throw new NullPointerException("methods == null");
    }

    if (ropper == null) {
        throw new NullPointerException("ropper == null");
    }

    if (advice == null) {
        throw new NullPointerException("advice == null");
    }

    this.ropper = ropper;
    this.method = method;
    this.methods = methods;
    this.advice = advice;
    this.maxLocals = method.getMaxLocals();
    this.insns = new ArrayList<Insn>(25);
    this.catches = null;
    this.catchesUsed = false;
    this.returns = false;
    this.primarySuccessorIndex = -1;
    this.extraBlockCount = 0;
    this.blockCanThrow = false;
    this.returnOp = null;
    this.returnPosition = null;
}
 
Example #23
Source File: Ropper.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs an instance. This class is not publicly instantiable; use
 * {@link #convert}.
 *
 * @param method {@code non-null;} method to convert
 * @param advice {@code non-null;} translation advice to use
 * @param methods {@code non-null;} list of methods defined by the class
 *     that defines {@code method}.
 * @param dexOptions {@code non-null;} options for dex output
 */
private Ropper(ConcreteMethod method, TranslationAdvice advice, MethodList methods,
        DexOptions dexOptions) {
    if (method == null) {
        throw new NullPointerException("method == null");
    }

    if (advice == null) {
        throw new NullPointerException("advice == null");
    }

    this.method = method;
    this.blocks = BasicBlocker.identifyBlocks(method);
    this.maxLabel = blocks.getMaxLabel();
    this.maxLocals = method.getMaxLocals();
    this.machine = new RopperMachine(this, method, advice, methods);
    this.sim = new Simulator(machine, method, dexOptions);
    this.startFrames = new Frame[maxLabel];
    this.subroutines = new Subroutine[maxLabel];

    /*
     * The "* 2 + 10" below is to conservatively believe that every
     * block is an exception handler target and should also
     * take care of enough other possible extra overhead such that
     * the underlying array is unlikely to need resizing.
     */
    this.result = new ArrayList<BasicBlock>(blocks.size() * 2 + 10);
    this.resultSubroutines =
        new ArrayList<IntList>(blocks.size() * 2 + 10);

    this.catchInfos = new CatchInfo[maxLabel];
    this.synchNeedsExceptionHandler = false;

    /*
     * Set up the first stack frame with the right limits, but leave it
     * empty here (to be filled in outside of the constructor).
     */
    startFrames[0] = new Frame(maxLocals, method.getMaxStack());
    exceptionSetupLabelAllocator = new ExceptionSetupLabelAllocator();
}
 
Example #24
Source File: OptimizerOptions.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Compares the output of the optimizer run normally with a run skipping
 * some optional steps. Results are printed to stderr.
 *
 * @param nonOptRmeth {@code non-null;} origional rop method
 * @param paramSize {@code >= 0;} parameter size of method
 * @param isStatic true if this method has no 'this' pointer argument.
 * @param args {@code non-null;} translator arguments
 * @param advice {@code non-null;} translation advice
 * @param rmeth {@code non-null;} method with all optimization steps run.
 */
public void compareOptimizerStep(RopMethod nonOptRmeth,
        int paramSize, boolean isStatic, CfOptions args,
        TranslationAdvice advice, RopMethod rmeth) {
    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));
}
 
Example #25
Source File: Ropper.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs an instance. This class is not publicly instantiable; use
 * {@link #convert}.
 *
 * @param method {@code non-null;} method to convert
 * @param advice {@code non-null;} translation advice to use
 * @param methods {@code non-null;} list of methods defined by the class
 *     that defines {@code method}.
 * @param dexOptions {@code non-null;} options for dex output
 */
private Ropper(ConcreteMethod method, TranslationAdvice advice, MethodList methods,
        DexOptions dexOptions) {
    if (method == null) {
        throw new NullPointerException("method == null");
    }

    if (advice == null) {
        throw new NullPointerException("advice == null");
    }

    this.method = method;
    this.blocks = BasicBlocker.identifyBlocks(method);
    this.maxLabel = blocks.getMaxLabel();
    this.maxLocals = method.getMaxLocals();
    this.machine = new RopperMachine(this, method, advice, methods);
    this.sim = new Simulator(machine, method, dexOptions);
    this.startFrames = new Frame[maxLabel];
    this.subroutines = new Subroutine[maxLabel];

    /*
     * The "* 2 + 10" below is to conservatively believe that every
     * block is an exception handler target and should also
     * take care of enough other possible extra overhead such that
     * the underlying array is unlikely to need resizing.
     */
    this.result = new ArrayList<BasicBlock>(blocks.size() * 2 + 10);
    this.resultSubroutines =
        new ArrayList<IntList>(blocks.size() * 2 + 10);

    this.catchInfos = new CatchInfo[maxLabel];
    this.synchNeedsExceptionHandler = false;

    /*
     * Set up the first stack frame with the right limits, but leave it
     * empty here (to be filled in outside of the constructor).
     */
    startFrames[0] = new Frame(maxLocals, method.getMaxStack());
    exceptionSetupLabelAllocator = new ExceptionSetupLabelAllocator();
}
 
Example #26
Source File: Ropper.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Converts a {@link ConcreteMethod} to a {@link RopMethod}.
 *
 * @param method {@code non-null;} method to convert
 * @param advice {@code non-null;} translation advice to use
 * @param methods {@code non-null;} list of methods defined by the class
 *     that defines {@code method}.
 * @return {@code non-null;} the converted instance
 */
public static RopMethod convert(ConcreteMethod method,
        TranslationAdvice advice, MethodList methods, DexOptions dexOptions) {
    try {
        Ropper r = new Ropper(method, advice, methods, dexOptions);
        r.doit();
        return r.getRopMethod();
    } catch (SimException ex) {
        ex.addContext("...while working on method " +
                      method.getNat().toHuman());
        throw ex;
    }
}
 
Example #27
Source File: OptimizerOptions.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Compares the output of the optimizer run normally with a run skipping
 * some optional steps. Results are printed to stderr.
 *
 * @param nonOptRmeth {@code non-null;} origional rop method
 * @param paramSize {@code >= 0;} parameter size of method
 * @param isStatic true if this method has no 'this' pointer argument.
 * @param args {@code non-null;} translator arguments
 * @param advice {@code non-null;} translation advice
 * @param rmeth {@code non-null;} method with all optimization steps run.
 */
public void compareOptimizerStep(RopMethod nonOptRmeth,
        int paramSize, boolean isStatic, CfOptions args,
        TranslationAdvice advice, RopMethod rmeth) {
    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));
}
 
Example #28
Source File: RopperMachine.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs an instance.
 *
 * @param ropper {@code non-null;} ropper controlling this instance
 * @param method {@code non-null;} method being converted
 * @param advice {@code non-null;} translation advice to use
 * @param methods {@code non-null;} list of methods defined by the class
 *     that defines {@code method}.
 */
public RopperMachine(Ropper ropper, ConcreteMethod method,
        TranslationAdvice advice, MethodList methods) {
    super(method.getEffectiveDescriptor());

    if (methods == null) {
        throw new NullPointerException("methods == null");
    }

    if (ropper == null) {
        throw new NullPointerException("ropper == null");
    }

    if (advice == null) {
        throw new NullPointerException("advice == null");
    }

    this.ropper = ropper;
    this.method = method;
    this.methods = methods;
    this.advice = advice;
    this.maxLocals = method.getMaxLocals();
    this.insns = new ArrayList<Insn>(25);
    this.catches = null;
    this.catchesUsed = false;
    this.returns = false;
    this.primarySuccessorIndex = -1;
    this.extraBlockCount = 0;
    this.blockCanThrow = false;
    this.returnOp = null;
    this.returnPosition = null;
}
 
Example #29
Source File: Optimizer.java    From Box with Apache License 2.0 5 votes vote down vote up
public static SsaMethod debugEdgeSplit(RopMethod rmeth, int paramWidth,
        boolean isStatic, boolean inPreserveLocals,
        TranslationAdvice inAdvice) {

    preserveLocals = inPreserveLocals;
    advice = inAdvice;

    return SsaConverter.testEdgeSplit(rmeth, paramWidth, isStatic);
}
 
Example #30
Source File: Optimizer.java    From Box with Apache License 2.0 5 votes vote down vote up
public static SsaMethod debugPhiPlacement(RopMethod rmeth, int paramWidth,
        boolean isStatic, boolean inPreserveLocals,
        TranslationAdvice inAdvice) {

    preserveLocals = inPreserveLocals;
    advice = inAdvice;

    return SsaConverter.testPhiPlacement(rmeth, paramWidth, isStatic);
}