com.android.dx.dex.code.DalvCode Java Examples

The following examples show how to use com.android.dx.dex.code.DalvCode. 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 Project: Box   Author: lulululbj   File: CodeStatistics.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Updates the dex statistics.
 *
 * @param nonOptCode non-optimized code block
 * @param code optimized code block
 */
public void updateDexStatistics(DalvCode nonOptCode,
        DalvCode code) {
    if (DEBUG) {
        System.err.println("dex insns (old/new) "
                + nonOptCode.getInsns().codeSize()
                + "/" + code.getInsns().codeSize()
                + " regs (o/n) "
                + nonOptCode.getInsns().getRegistersSize()
                + "/" + code.getInsns().getRegistersSize()
        );
    }

    dexRunningDeltaInsns
        += (code.getInsns().codeSize()
            - nonOptCode.getInsns().codeSize());

    dexRunningDeltaRegisters
        += (code.getInsns().getRegistersSize()
            - nonOptCode.getInsns().getRegistersSize());

    dexRunningTotalInsns += code.getInsns().codeSize();
}
 
Example #2
Source Project: Box   Author: lulululbj   File: DebugInfoDecoder.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Validates an encoded debug info stream against data used to encode it,
 * throwing an exception if they do not match. Used to validate the
 * encoder.
 *
 * @param info encoded debug info
 * @param file {@code non-null;} file to refer to during decoding
 * @param ref {@code non-null;} method whose info is being decoded
 * @param code {@code non-null;} original code object that was encoded
 * @param isStatic whether the method is static
 */
public static void validateEncode(byte[] info, DexFile file,
        CstMethodRef ref, DalvCode code, boolean isStatic) {
    PositionList pl = code.getPositions();
    LocalList ll = code.getLocals();
    DalvInsnList insns = code.getInsns();
    int codeSize = insns.codeSize();
    int countRegisters = insns.getRegistersSize();

    try {
        validateEncode0(info, codeSize, countRegisters,
                isStatic, ref, file, pl, ll);
    } catch (RuntimeException ex) {
        System.err.println("instructions:");
        insns.debugPrint(System.err, "  ", true);
        System.err.println("local list:");
        ll.debugPrint(System.err, "  ");
        throw ExceptionWithContext.withContext(ex,
                "while processing " + ref.toHuman());
    }
}
 
Example #3
Source Project: Box   Author: lulululbj   File: EncodedMethod.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Constructs an instance.
 *
 * @param method {@code non-null;} constant for the method
 * @param accessFlags access flags
 * @param code {@code null-ok;} code for the method, if it is neither
 * {@code abstract} nor {@code native}
 * @param throwsList {@code non-null;} list of possibly-thrown exceptions,
 * just used in generating debugging output (listings)
 */
public EncodedMethod(CstMethodRef method, int accessFlags,
        DalvCode code, TypeList throwsList) {
    super(accessFlags);

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

    this.method = method;

    if (code == null) {
        this.code = null;
    } else {
        boolean isStatic = (accessFlags & AccessFlags.ACC_STATIC) != 0;
        this.code = new CodeItem(method, code, isStatic, throwsList);
    }
}
 
Example #4
Source Project: Box   Author: lulululbj   File: CodeItem.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Constructs an instance.
 *
 * @param ref {@code non-null;} method that this code implements
 * @param code {@code non-null;} the underlying code
 * @param isStatic whether this instance is for a {@code static}
 * method
 * @param throwsList {@code non-null;} list of possibly-thrown exceptions,
 * just used in generating debugging output (listings)
 */
public CodeItem(CstMethodRef ref, DalvCode code, boolean isStatic,
        TypeList throwsList) {
    super(ALIGNMENT, -1);

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

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

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

    this.ref = ref;
    this.code = code;
    this.isStatic = isStatic;
    this.throwsList = throwsList;
    this.catches = null;
    this.debugInfo = null;
}
 
Example #5
Source Project: Box   Author: lulululbj   File: CodeStatistics.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Updates the dex statistics.
 *
 * @param nonOptCode non-optimized code block
 * @param code optimized code block
 */
public void updateDexStatistics(DalvCode nonOptCode,
        DalvCode code) {
    if (DEBUG) {
        System.err.println("dex insns (old/new) "
                + nonOptCode.getInsns().codeSize()
                + "/" + code.getInsns().codeSize()
                + " regs (o/n) "
                + nonOptCode.getInsns().getRegistersSize()
                + "/" + code.getInsns().getRegistersSize()
        );
    }

    dexRunningDeltaInsns
        += (code.getInsns().codeSize()
            - nonOptCode.getInsns().codeSize());

    dexRunningDeltaRegisters
        += (code.getInsns().getRegistersSize()
            - nonOptCode.getInsns().getRegistersSize());

    dexRunningTotalInsns += code.getInsns().codeSize();
}
 
Example #6
Source Project: Box   Author: lulululbj   File: DebugInfoDecoder.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Validates an encoded debug info stream against data used to encode it,
 * throwing an exception if they do not match. Used to validate the
 * encoder.
 *
 * @param info encoded debug info
 * @param file {@code non-null;} file to refer to during decoding
 * @param ref {@code non-null;} method whose info is being decoded
 * @param code {@code non-null;} original code object that was encoded
 * @param isStatic whether the method is static
 */
public static void validateEncode(byte[] info, DexFile file,
        CstMethodRef ref, DalvCode code, boolean isStatic) {
    PositionList pl = code.getPositions();
    LocalList ll = code.getLocals();
    DalvInsnList insns = code.getInsns();
    int codeSize = insns.codeSize();
    int countRegisters = insns.getRegistersSize();

    try {
        validateEncode0(info, codeSize, countRegisters,
                isStatic, ref, file, pl, ll);
    } catch (RuntimeException ex) {
        System.err.println("instructions:");
        insns.debugPrint(System.err, "  ", true);
        System.err.println("local list:");
        ll.debugPrint(System.err, "  ");
        throw ExceptionWithContext.withContext(ex,
                "while processing " + ref.toHuman());
    }
}
 
Example #7
Source Project: Box   Author: lulululbj   File: EncodedMethod.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Constructs an instance.
 *
 * @param method {@code non-null;} constant for the method
 * @param accessFlags access flags
 * @param code {@code null-ok;} code for the method, if it is neither
 * {@code abstract} nor {@code native}
 * @param throwsList {@code non-null;} list of possibly-thrown exceptions,
 * just used in generating debugging output (listings)
 */
public EncodedMethod(CstMethodRef method, int accessFlags,
        DalvCode code, TypeList throwsList) {
    super(accessFlags);

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

    this.method = method;

    if (code == null) {
        this.code = null;
    } else {
        boolean isStatic = (accessFlags & AccessFlags.ACC_STATIC) != 0;
        this.code = new CodeItem(method, code, isStatic, throwsList);
    }
}
 
Example #8
Source Project: Box   Author: lulululbj   File: CodeItem.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Constructs an instance.
 *
 * @param ref {@code non-null;} method that this code implements
 * @param code {@code non-null;} the underlying code
 * @param isStatic whether this instance is for a {@code static}
 * method
 * @param throwsList {@code non-null;} list of possibly-thrown exceptions,
 * just used in generating debugging output (listings)
 */
public CodeItem(CstMethodRef ref, DalvCode code, boolean isStatic,
        TypeList throwsList) {
    super(ALIGNMENT, -1);

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

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

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

    this.ref = ref;
    this.code = code;
    this.isStatic = isStatic;
    this.throwsList = throwsList;
    this.catches = null;
    this.debugInfo = null;
}
 
Example #9
Source Project: J2ME-Loader   Author: nikita36078   File: CodeStatistics.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Updates the dex statistics.
 *
 * @param nonOptCode non-optimized code block
 * @param code optimized code block
 */
public void updateDexStatistics(DalvCode nonOptCode,
        DalvCode code) {
    if (DEBUG) {
        System.err.println("dex insns (old/new) "
                + nonOptCode.getInsns().codeSize()
                + "/" + code.getInsns().codeSize()
                + " regs (o/n) "
                + nonOptCode.getInsns().getRegistersSize()
                + "/" + code.getInsns().getRegistersSize()
        );
    }

    dexRunningDeltaInsns
        += (code.getInsns().codeSize()
            - nonOptCode.getInsns().codeSize());

    dexRunningDeltaRegisters
        += (code.getInsns().getRegistersSize()
            - nonOptCode.getInsns().getRegistersSize());

    dexRunningTotalInsns += code.getInsns().codeSize();
}
 
Example #10
Source Project: J2ME-Loader   Author: nikita36078   File: DebugInfoDecoder.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Validates an encoded debug info stream against data used to encode it,
 * throwing an exception if they do not match. Used to validate the
 * encoder.
 *
 * @param info encoded debug info
 * @param file {@code non-null;} file to refer to during decoding
 * @param ref {@code non-null;} method whose info is being decoded
 * @param code {@code non-null;} original code object that was encoded
 * @param isStatic whether the method is static
 */
public static void validateEncode(byte[] info, DexFile file,
        CstMethodRef ref, DalvCode code, boolean isStatic) {
    PositionList pl = code.getPositions();
    LocalList ll = code.getLocals();
    DalvInsnList insns = code.getInsns();
    int codeSize = insns.codeSize();
    int countRegisters = insns.getRegistersSize();

    try {
        validateEncode0(info, codeSize, countRegisters,
                isStatic, ref, file, pl, ll);
    } catch (RuntimeException ex) {
        System.err.println("instructions:");
        insns.debugPrint(System.err, "  ", true);
        System.err.println("local list:");
        ll.debugPrint(System.err, "  ");
        throw ExceptionWithContext.withContext(ex,
                "while processing " + ref.toHuman());
    }
}
 
Example #11
Source Project: J2ME-Loader   Author: nikita36078   File: EncodedMethod.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Constructs an instance.
 *
 * @param method {@code non-null;} constant for the method
 * @param accessFlags access flags
 * @param code {@code null-ok;} code for the method, if it is neither
 * {@code abstract} nor {@code native}
 * @param throwsList {@code non-null;} list of possibly-thrown exceptions,
 * just used in generating debugging output (listings)
 */
public EncodedMethod(CstMethodRef method, int accessFlags,
        DalvCode code, TypeList throwsList) {
    super(accessFlags);

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

    this.method = method;

    if (code == null) {
        this.code = null;
    } else {
        boolean isStatic = (accessFlags & AccessFlags.ACC_STATIC) != 0;
        this.code = new CodeItem(method, code, isStatic, throwsList);
    }
}
 
Example #12
Source Project: J2ME-Loader   Author: nikita36078   File: CodeItem.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Constructs an instance.
 *
 * @param ref {@code non-null;} method that this code implements
 * @param code {@code non-null;} the underlying code
 * @param isStatic whether this instance is for a {@code static}
 * method
 * @param throwsList {@code non-null;} list of possibly-thrown exceptions,
 * just used in generating debugging output (listings)
 */
public CodeItem(CstMethodRef ref, DalvCode code, boolean isStatic,
        TypeList throwsList) {
    super(ALIGNMENT, -1);

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

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

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

    this.ref = ref;
    this.code = code;
    this.isStatic = isStatic;
    this.throwsList = throwsList;
    this.catches = null;
    this.debugInfo = null;
}
 
Example #13
Source Project: buck   Author: facebook   File: CodeStatistics.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Updates the dex statistics.
 *
 * @param nonOptCode non-optimized code block
 * @param code optimized code block
 */
public void updateDexStatistics(DalvCode nonOptCode,
        DalvCode code) {
    if (DEBUG) {
        System.err.println("dex insns (old/new) "
                + nonOptCode.getInsns().codeSize()
                + "/" + code.getInsns().codeSize()
                + " regs (o/n) "
                + nonOptCode.getInsns().getRegistersSize()
                + "/" + code.getInsns().getRegistersSize()
        );
    }

    dexRunningDeltaInsns
        += (code.getInsns().codeSize()
            - nonOptCode.getInsns().codeSize());

    dexRunningDeltaRegisters
        += (code.getInsns().getRegistersSize()
            - nonOptCode.getInsns().getRegistersSize());

    dexRunningTotalInsns += code.getInsns().codeSize();
}
 
Example #14
Source Project: buck   Author: facebook   File: DebugInfoDecoder.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Validates an encoded debug info stream against data used to encode it,
 * throwing an exception if they do not match. Used to validate the
 * encoder.
 *
 * @param info encoded debug info
 * @param file {@code non-null;} file to refer to during decoding
 * @param ref {@code non-null;} method whose info is being decoded
 * @param code {@code non-null;} original code object that was encoded
 * @param isStatic whether the method is static
 */
public static void validateEncode(byte[] info, DexFile file,
        CstMethodRef ref, DalvCode code, boolean isStatic) {
    PositionList pl = code.getPositions();
    LocalList ll = code.getLocals();
    DalvInsnList insns = code.getInsns();
    int codeSize = insns.codeSize();
    int countRegisters = insns.getRegistersSize();

    try {
        validateEncode0(info, codeSize, countRegisters,
                isStatic, ref, file, pl, ll);
    } catch (RuntimeException ex) {
        System.err.println("instructions:");
        insns.debugPrint(System.err, "  ", true);
        System.err.println("local list:");
        ll.debugPrint(System.err, "  ");
        throw ExceptionWithContext.withContext(ex,
                "while processing " + ref.toHuman());
    }
}
 
Example #15
Source Project: buck   Author: facebook   File: EncodedMethod.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Constructs an instance.
 *
 * @param method {@code non-null;} constant for the method
 * @param accessFlags access flags
 * @param code {@code null-ok;} code for the method, if it is neither
 * {@code abstract} nor {@code native}
 * @param throwsList {@code non-null;} list of possibly-thrown exceptions,
 * just used in generating debugging output (listings)
 */
public EncodedMethod(CstMethodRef method, int accessFlags,
        DalvCode code, TypeList throwsList) {
    super(accessFlags);

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

    this.method = method;

    if (code == null) {
        this.code = null;
    } else {
        boolean isStatic = (accessFlags & AccessFlags.ACC_STATIC) != 0;
        this.code = new CodeItem(method, code, isStatic, throwsList);
    }
}
 
Example #16
Source Project: buck   Author: facebook   File: CodeItem.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Constructs an instance.
 *
 * @param ref {@code non-null;} method that this code implements
 * @param code {@code non-null;} the underlying code
 * @param isStatic whether this instance is for a {@code static}
 * method
 * @param throwsList {@code non-null;} list of possibly-thrown exceptions,
 * just used in generating debugging output (listings)
 */
public CodeItem(CstMethodRef ref, DalvCode code, boolean isStatic,
        TypeList throwsList) {
    super(ALIGNMENT, -1);

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

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

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

    this.ref = ref;
    this.code = code;
    this.isStatic = isStatic;
    this.throwsList = throwsList;
    this.catches = null;
    this.debugInfo = null;
}
 
Example #17
Source Project: Box   Author: lulululbj   File: CfTranslator.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Helper that updates the dex statistics.
 */
private static void updateDexStatistics(DxContext context, CfOptions cfOptions, DexOptions dexOptions,
        RopMethod optRmeth, RopMethod nonOptRmeth,
        LocalVariableInfo locals, int paramSize, int originalByteCount) {
    /*
     * Run rop->dex again on optimized vs. non-optimized method to
     * collect statistics. We have to totally convert both ways,
     * since converting the "real" method getting added to the
     * file would corrupt it (by messing with its constant pool
     * indices).
     */

    DalvCode optCode = RopTranslator.translate(optRmeth,
            cfOptions.positionInfo, locals, paramSize, dexOptions);
    DalvCode nonOptCode = RopTranslator.translate(nonOptRmeth,
            cfOptions.positionInfo, locals, paramSize, dexOptions);

    /*
     * Fake out the indices, so code.getInsns() can work well enough
     * for the current purpose.
     */

    DalvCode.AssignIndicesCallback callback =
        new DalvCode.AssignIndicesCallback() {
            @Override
            public int getIndex(Constant cst) {
                // Everything is at index 0!
                return 0;
            }
        };

    optCode.assignIndices(callback);
    nonOptCode.assignIndices(callback);

    context.codeStatistics.updateDexStatistics(nonOptCode, optCode);
    context.codeStatistics.updateOriginalByteCount(originalByteCount);
}
 
Example #18
Source Project: Box   Author: lulululbj   File: CatchStructs.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Constructs an instance.
 *
 * @param code {@code non-null;} code that contains the catches
 */
public CatchStructs(DalvCode code) {
    this.code = code;
    this.table = null;
    this.encodedHandlers = null;
    this.encodedHandlerHeaderSize = 0;
    this.handlerOffsets = null;
}
 
Example #19
Source Project: Box   Author: lulululbj   File: DebugInfoItem.java    License: Apache License 2.0 5 votes vote down vote up
public DebugInfoItem(DalvCode code, boolean isStatic, CstMethodRef ref) {
    // We don't know the write size yet.
    super (ALIGNMENT, -1);

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

    this.code = code;
    this.isStatic = isStatic;
    this.ref = ref;
}
 
Example #20
Source Project: Box   Author: lulululbj   File: CfTranslator.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Helper that updates the dex statistics.
 */
private static void updateDexStatistics(DxContext context, CfOptions cfOptions, DexOptions dexOptions,
        RopMethod optRmeth, RopMethod nonOptRmeth,
        LocalVariableInfo locals, int paramSize, int originalByteCount) {
    /*
     * Run rop->dex again on optimized vs. non-optimized method to
     * collect statistics. We have to totally convert both ways,
     * since converting the "real" method getting added to the
     * file would corrupt it (by messing with its constant pool
     * indices).
     */

    DalvCode optCode = RopTranslator.translate(optRmeth,
            cfOptions.positionInfo, locals, paramSize, dexOptions);
    DalvCode nonOptCode = RopTranslator.translate(nonOptRmeth,
            cfOptions.positionInfo, locals, paramSize, dexOptions);

    /*
     * Fake out the indices, so code.getInsns() can work well enough
     * for the current purpose.
     */

    DalvCode.AssignIndicesCallback callback =
        new DalvCode.AssignIndicesCallback() {
            @Override
            public int getIndex(Constant cst) {
                // Everything is at index 0!
                return 0;
            }
        };

    optCode.assignIndices(callback);
    nonOptCode.assignIndices(callback);

    context.codeStatistics.updateDexStatistics(nonOptCode, optCode);
    context.codeStatistics.updateOriginalByteCount(originalByteCount);
}
 
Example #21
Source Project: Box   Author: lulululbj   File: CatchStructs.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Constructs an instance.
 *
 * @param code {@code non-null;} code that contains the catches
 */
public CatchStructs(DalvCode code) {
    this.code = code;
    this.table = null;
    this.encodedHandlers = null;
    this.encodedHandlerHeaderSize = 0;
    this.handlerOffsets = null;
}
 
Example #22
Source Project: Box   Author: lulululbj   File: DebugInfoItem.java    License: Apache License 2.0 5 votes vote down vote up
public DebugInfoItem(DalvCode code, boolean isStatic, CstMethodRef ref) {
    // We don't know the write size yet.
    super (ALIGNMENT, -1);

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

    this.code = code;
    this.isStatic = isStatic;
    this.ref = ref;
}
 
Example #23
Source Project: lua-for-android   Author: qtiuto   File: DexMaker.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
EncodedMethod toEncodedMethod(DexOptions dexOptions) {
    if (code != null) {
        RopMethod ropMethod = new RopMethod(code.toBasicBlocks(), 0);
        LocalVariableInfo locals = null;
        DalvCode dalvCode = RopTranslator.translate(
                ropMethod, PositionList.NONE, locals, code.paramSize(), dexOptions);
        return new EncodedMethod(method.constant, flags, dalvCode, StdTypeList.EMPTY);
    } else return new EncodedMethod(method.constant, flags, null, StdTypeList.EMPTY);

}
 
Example #24
Source Project: J2ME-Loader   Author: nikita36078   File: CfTranslator.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Helper that updates the dex statistics.
 */
private static void updateDexStatistics(DxContext context, CfOptions cfOptions, DexOptions dexOptions,
        RopMethod optRmeth, RopMethod nonOptRmeth,
        LocalVariableInfo locals, int paramSize, int originalByteCount) {
    /*
     * Run rop->dex again on optimized vs. non-optimized method to
     * collect statistics. We have to totally convert both ways,
     * since converting the "real" method getting added to the
     * file would corrupt it (by messing with its constant pool
     * indices).
     */

    DalvCode optCode = RopTranslator.translate(optRmeth,
            cfOptions.positionInfo, locals, paramSize, dexOptions);
    DalvCode nonOptCode = RopTranslator.translate(nonOptRmeth,
            cfOptions.positionInfo, locals, paramSize, dexOptions);

    /*
     * Fake out the indices, so code.getInsns() can work well enough
     * for the current purpose.
     */

    DalvCode.AssignIndicesCallback callback =
        new DalvCode.AssignIndicesCallback() {
            @Override
public int getIndex(Constant cst) {
                // Everything is at index 0!
                return 0;
            }
        };

    optCode.assignIndices(callback);
    nonOptCode.assignIndices(callback);

    context.codeStatistics.updateDexStatistics(nonOptCode, optCode);
    context.codeStatistics.updateOriginalByteCount(originalByteCount);
}
 
Example #25
Source Project: J2ME-Loader   Author: nikita36078   File: CatchStructs.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Constructs an instance.
 *
 * @param code {@code non-null;} code that contains the catches
 */
public CatchStructs(DalvCode code) {
    this.code = code;
    this.table = null;
    this.encodedHandlers = null;
    this.encodedHandlerHeaderSize = 0;
    this.handlerOffsets = null;
}
 
Example #26
Source Project: J2ME-Loader   Author: nikita36078   File: DebugInfoItem.java    License: Apache License 2.0 5 votes vote down vote up
public DebugInfoItem(DalvCode code, boolean isStatic, CstMethodRef ref) {
    // We don't know the write size yet.
    super (ALIGNMENT, -1);

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

    this.code = code;
    this.isStatic = isStatic;
    this.ref = ref;
}
 
Example #27
Source Project: dexmaker   Author: linkedin   File: DexMaker.java    License: Apache License 2.0 5 votes vote down vote up
EncodedMethod toEncodedMethod(DexOptions dexOptions) {
    if((flags & ABSTRACT) != 0 || (flags & NATIVE) != 0){
        return new EncodedMethod(method.constant, flags, null, StdTypeList.EMPTY);
    }

    RopMethod ropMethod = new RopMethod(code.toBasicBlocks(), 0);
    LocalVariableInfo locals = null;
    DalvCode dalvCode = RopTranslator.translate(
            ropMethod, PositionList.NONE, locals, code.paramSize(), dexOptions);
    return new EncodedMethod(method.constant, flags, dalvCode, StdTypeList.EMPTY);
}
 
Example #28
Source Project: buck   Author: facebook   File: CfTranslator.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Helper that updates the dex statistics.
 */
private static void updateDexStatistics(DxContext context, CfOptions cfOptions, DexOptions dexOptions,
                                        RopMethod optRmeth, RopMethod nonOptRmeth,
                                        LocalVariableInfo locals, int paramSize, int originalByteCount) {
    /*
     * Run rop->dex again on optimized vs. non-optimized method to
     * collect statistics. We have to totally convert both ways,
     * since converting the "real" method getting added to the
     * file would corrupt it (by messing with its constant pool
     * indices).
     */

    DalvCode optCode = RopTranslator.translate(optRmeth,
            cfOptions.positionInfo, locals, paramSize, dexOptions);
    DalvCode nonOptCode = RopTranslator.translate(nonOptRmeth,
            cfOptions.positionInfo, locals, paramSize, dexOptions);

    /*
     * Fake out the indices, so code.getInsns() can work well enough
     * for the current purpose.
     */

    DalvCode.AssignIndicesCallback callback =
        new DalvCode.AssignIndicesCallback() {
            public int getIndex(Constant cst) {
                // Everything is at index 0!
                return 0;
            }
        };

    optCode.assignIndices(callback);
    nonOptCode.assignIndices(callback);

    context.codeStatistics.updateDexStatistics(nonOptCode, optCode);
    context.codeStatistics.updateOriginalByteCount(originalByteCount);
}
 
Example #29
Source Project: buck   Author: facebook   File: CodeItem.java    License: Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
protected void place0(Section addedTo, int offset) {
    final DexFile file = addedTo.getFile();
    int catchesSize;

    /*
     * In order to get the catches and insns, all the code's
     * constants need to be assigned indices.
     */
    code.assignIndices(new DalvCode.AssignIndicesCallback() {
            public int getIndex(Constant cst) {
                IndexedItem item = file.findItemOrNull(cst);
                if (item == null) {
                    return -1;
                }
                return item.getIndex();
            }
        });

    if (catches != null) {
        catches.encode(file);
        catchesSize = catches.writeSize();
    } else {
        catchesSize = 0;
    }

    /*
     * The write size includes the header, two bytes per code
     * unit, post-code padding if necessary, and however much
     * space the catches need.
     */

    int insnsSize = code.getInsns().codeSize();
    if ((insnsSize & 1) != 0) {
        insnsSize++;
    }

    setWriteSize(HEADER_SIZE + (insnsSize * 2) + catchesSize);
}
 
Example #30
Source Project: buck   Author: facebook   File: CatchStructs.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Constructs an instance.
 *
 * @param code {@code non-null;} code that contains the catches
 */
public CatchStructs(DalvCode code) {
    this.code = code;
    this.table = null;
    this.encodedHandlers = null;
    this.encodedHandlerHeaderSize = 0;
    this.handlerOffsets = null;
}