FileDocCategorySizeDatePackage
DexTranslationAdvice.javaAPI DocAndroid 5.1 API4295Thu Mar 12 22:18:30 GMT 2015com.android.dx.rop.code

DexTranslationAdvice

public final class DexTranslationAdvice extends Object implements TranslationAdvice
Implementation of {@link TranslationAdvice} which represents what the dex format will be able to represent.

Fields Summary
public static final DexTranslationAdvice
THE_ONE
{@code non-null;} standard instance of this class
public static final DexTranslationAdvice
NO_SOURCES_IN_ORDER
debug advice for disabling invoke-range optimization
private static final int
MIN_INVOKE_IN_ORDER
The minimum source width, in register units, for an invoke instruction that requires its sources to be in order and contiguous.
private final boolean
disableSourcesInOrder
when true: always returns false for requiresSourcesInOrder
Constructors Summary
private DexTranslationAdvice()
This class is not publicly instantiable. Use {@link #THE_ONE}.


                  
      
        disableSourcesInOrder = false;
    
private DexTranslationAdvice(boolean disableInvokeRange)

        this.disableSourcesInOrder = disableInvokeRange;
    
Methods Summary
public intgetMaxOptimalRegisterCount()
{@inheritDoc}

        return 16;
    
public booleanhasConstantOperation(Rop opcode, RegisterSpec sourceA, RegisterSpec sourceB)
{@inheritDoc}

        if (sourceA.getType() != Type.INT) {
            return false;
        }

        // Return false if second source isn't a constant
        if (! (sourceB.getTypeBearer() instanceof CstInteger)) {
            // Except for rsub-int (reverse sub) where first source is constant
            if (sourceA.getTypeBearer() instanceof CstInteger &&
                    opcode.getOpcode() == RegOps.SUB) {
                CstInteger cst = (CstInteger) sourceA.getTypeBearer();
                return cst.fitsIn16Bits();
            } else {
                return false;
            }
        }

        CstInteger cst = (CstInteger) sourceB.getTypeBearer();

        switch (opcode.getOpcode()) {
            // These have 8 and 16 bit cst representations
            case RegOps.REM:
            case RegOps.ADD:
            case RegOps.MUL:
            case RegOps.DIV:
            case RegOps.AND:
            case RegOps.OR:
            case RegOps.XOR:
                return cst.fitsIn16Bits();
            // These only have 8 bit cst reps
            case RegOps.SHL:
            case RegOps.SHR:
            case RegOps.USHR:
                return cst.fitsIn8Bits();
            // No sub-const insn, so check if equivalent add-const fits
            case RegOps.SUB:
                CstInteger cst2 = CstInteger.make(-cst.getValue());
                return cst2.fitsIn16Bits();
            default:
                return false;
        }
    
public booleanrequiresSourcesInOrder(Rop opcode, RegisterSpecList sources)
{@inheritDoc}


        return !disableSourcesInOrder && opcode.isCallLike()
                && totalRopWidth(sources) >= MIN_INVOKE_IN_ORDER;
    
private inttotalRopWidth(RegisterSpecList sources)
Calculates the total rop width of the list of SSA registers

param
sources {@code non-null;} list of SSA registers
return
{@code >= 0;} rop-form width in register units

        int sz = sources.size();
        int total = 0;

        for (int i = 0; i < sz; i++) {
            total += sources.get(i).getCategory();
        }

        return total;