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

The following examples show how to use com.android.dx.rop.code.LocalVariableInfo. 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: 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 #2
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 #3
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 #4
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 #5
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 #6
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 #7
Source Project: Box   Author: lulululbj   File: RopTranslator.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Constructs an instance. This method is private. Use {@link #translate}.
 *
 * @param method {@code non-null;} the original method
 * @param positionInfo how much position info to preserve; one of the
 * static constants in {@link PositionList}
 * @param locals {@code null-ok;} local variable information to use
 * @param paramSize size, in register units, of all the parameters to
 * this method
 * @param dexOptions {@code non-null;} options for dex output
 */
private RopTranslator(RopMethod method, int positionInfo, LocalVariableInfo locals,
        int paramSize, DexOptions dexOptions) {
    this.dexOptions = dexOptions;
    this.method = method;
    this.positionInfo = positionInfo;
    this.locals = locals;
    this.addresses = new BlockAddresses(method);
    this.paramSize = paramSize;
    this.order = null;
    this.paramsAreInOrder = calculateParamsAreInOrder(method, paramSize);

    BasicBlockList blocks = method.getBlocks();
    int bsz = blocks.size();

    /*
     * Max possible instructions includes three code address
     * objects per basic block (to the first and last instruction,
     * and just past the end of the block), and the possibility of
     * an extra goto at the end of each basic block.
     */
    int maxInsns = (bsz * 3) + blocks.getInstructionCount();

    if (locals != null) {
        /*
         * If we're tracking locals, then there's could be another
         * extra instruction per block (for the locals state at the
         * start of the block) as well as one for each interblock
         * local introduction.
         */
        maxInsns += bsz + locals.getAssignmentCount();
    }

    /*
     * If params are not in order, we will need register space
     * for them before this is all over...
     */
    this.regCount = blocks.getRegCount()
            + (paramsAreInOrder ? 0 : this.paramSize);

    this.output = new OutputCollector(dexOptions, maxInsns, bsz * 3, regCount, paramSize);

    if (locals != null) {
        this.translationVisitor =
            new LocalVariableAwareTranslationVisitor(output, locals);
    } else {
        this.translationVisitor = new TranslationVisitor(output);
    }
}
 
Example #8
Source Project: Box   Author: lulululbj   File: RopTranslator.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Constructs an instance. This method is private. Use {@link #translate}.
 *
 * @param method {@code non-null;} the original method
 * @param positionInfo how much position info to preserve; one of the
 * static constants in {@link PositionList}
 * @param locals {@code null-ok;} local variable information to use
 * @param paramSize size, in register units, of all the parameters to
 * this method
 * @param dexOptions {@code non-null;} options for dex output
 */
private RopTranslator(RopMethod method, int positionInfo, LocalVariableInfo locals,
        int paramSize, DexOptions dexOptions) {
    this.dexOptions = dexOptions;
    this.method = method;
    this.positionInfo = positionInfo;
    this.locals = locals;
    this.addresses = new BlockAddresses(method);
    this.paramSize = paramSize;
    this.order = null;
    this.paramsAreInOrder = calculateParamsAreInOrder(method, paramSize);

    BasicBlockList blocks = method.getBlocks();
    int bsz = blocks.size();

    /*
     * Max possible instructions includes three code address
     * objects per basic block (to the first and last instruction,
     * and just past the end of the block), and the possibility of
     * an extra goto at the end of each basic block.
     */
    int maxInsns = (bsz * 3) + blocks.getInstructionCount();

    if (locals != null) {
        /*
         * If we're tracking locals, then there's could be another
         * extra instruction per block (for the locals state at the
         * start of the block) as well as one for each interblock
         * local introduction.
         */
        maxInsns += bsz + locals.getAssignmentCount();
    }

    /*
     * If params are not in order, we will need register space
     * for them before this is all over...
     */
    this.regCount = blocks.getRegCount()
            + (paramsAreInOrder ? 0 : this.paramSize);

    this.output = new OutputCollector(dexOptions, maxInsns, bsz * 3, regCount, paramSize);

    if (locals != null) {
        this.translationVisitor =
            new LocalVariableAwareTranslationVisitor(output, locals);
    } else {
        this.translationVisitor = new TranslationVisitor(output);
    }
}
 
Example #9
Source Project: J2ME-Loader   Author: nikita36078   File: RopTranslator.java    License: Apache License 2.0 4 votes vote down vote up
/**
   * Constructs an instance. This method is private. Use {@link #translate}.
   *
   * @param method {@code non-null;} the original method
   * @param positionInfo how much position info to preserve; one of the
   * static constants in {@link PositionList}
   * @param locals {@code null-ok;} local variable information to use
   * @param paramSize size, in register units, of all the parameters to
   * this method
   * @param dexOptions {@code non-null;} options for dex output
   */
  private RopTranslator(RopMethod method, int positionInfo, LocalVariableInfo locals,
          int paramSize, DexOptions dexOptions) {
this.method = method;
      this.positionInfo = positionInfo;
      this.locals = locals;
      this.addresses = new BlockAddresses(method);
      this.paramSize = paramSize;
      this.order = null;
      this.paramsAreInOrder = calculateParamsAreInOrder(method, paramSize);

      BasicBlockList blocks = method.getBlocks();
      int bsz = blocks.size();

      /*
       * Max possible instructions includes three code address
       * objects per basic block (to the first and last instruction,
       * and just past the end of the block), and the possibility of
       * an extra goto at the end of each basic block.
       */
      int maxInsns = (bsz * 3) + blocks.getInstructionCount();

      if (locals != null) {
          /*
           * If we're tracking locals, then there's could be another
           * extra instruction per block (for the locals state at the
           * start of the block) as well as one for each interblock
           * local introduction.
           */
          maxInsns += bsz + locals.getAssignmentCount();
      }

      /*
       * If params are not in order, we will need register space
       * for them before this is all over...
       */
      this.regCount = blocks.getRegCount()
              + (paramsAreInOrder ? 0 : this.paramSize);

      this.output = new OutputCollector(dexOptions, maxInsns, bsz * 3, regCount, paramSize);

      if (locals != null) {
          this.translationVisitor =
              new LocalVariableAwareTranslationVisitor(output, locals);
      } else {
          this.translationVisitor = new TranslationVisitor(output);
      }
  }
 
Example #10
Source Project: buck   Author: facebook   File: RopTranslator.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Constructs an instance. This method is private. Use {@link #translate}.
 *
 * @param method {@code non-null;} the original method
 * @param positionInfo how much position info to preserve; one of the
 * static constants in {@link PositionList}
 * @param locals {@code null-ok;} local variable information to use
 * @param paramSize size, in register units, of all the parameters to
 * this method
 * @param dexOptions {@code non-null;} options for dex output
 */
private RopTranslator(RopMethod method, int positionInfo, LocalVariableInfo locals,
        int paramSize, DexOptions dexOptions) {
    this.dexOptions = dexOptions;
    this.method = method;
    this.positionInfo = positionInfo;
    this.locals = locals;
    this.addresses = new BlockAddresses(method);
    this.paramSize = paramSize;
    this.order = null;
    this.paramsAreInOrder = calculateParamsAreInOrder(method, paramSize);

    BasicBlockList blocks = method.getBlocks();
    int bsz = blocks.size();

    /*
     * Max possible instructions includes three code address
     * objects per basic block (to the first and last instruction,
     * and just past the end of the block), and the possibility of
     * an extra goto at the end of each basic block.
     */
    int maxInsns = (bsz * 3) + blocks.getInstructionCount();

    if (locals != null) {
        /*
         * If we're tracking locals, then there's could be another
         * extra instruction per block (for the locals state at the
         * start of the block) as well as one for each interblock
         * local introduction.
         */
        maxInsns += bsz + locals.getAssignmentCount();
    }

    /*
     * If params are not in order, we will need register space
     * for them before this is all over...
     */
    this.regCount = blocks.getRegCount()
            + (paramsAreInOrder ? 0 : this.paramSize);

    this.output = new OutputCollector(dexOptions, maxInsns, bsz * 3, regCount, paramSize);

    if (locals != null) {
        this.translationVisitor =
            new LocalVariableAwareTranslationVisitor(output, locals);
    } else {
        this.translationVisitor = new TranslationVisitor(output);
    }
}
 
Example #11
Source Project: Box   Author: lulululbj   File: RopTranslator.java    License: Apache License 2.0 3 votes vote down vote up
/**
 * Translates a {@link RopMethod}. This may modify the given
 * input.
 *
 * @param method {@code non-null;} the original method
 * @param positionInfo how much position info to preserve; one of the
 * static constants in {@link PositionList}
 * @param locals {@code null-ok;} local variable information to use
 * @param paramSize size, in register units, of all the parameters to
 * this method
 * @param dexOptions {@code non-null;} options for dex output
 * @return {@code non-null;} the translated version
 */
public static DalvCode translate(RopMethod method, int positionInfo,
        LocalVariableInfo locals, int paramSize, DexOptions dexOptions) {
    RopTranslator translator =
        new RopTranslator(method, positionInfo, locals, paramSize, dexOptions);
    return translator.translateAndGetResult();
}
 
Example #12
Source Project: Box   Author: lulululbj   File: RopTranslator.java    License: Apache License 2.0 3 votes vote down vote up
/**
 * Translates a {@link RopMethod}. This may modify the given
 * input.
 *
 * @param method {@code non-null;} the original method
 * @param positionInfo how much position info to preserve; one of the
 * static constants in {@link PositionList}
 * @param locals {@code null-ok;} local variable information to use
 * @param paramSize size, in register units, of all the parameters to
 * this method
 * @param dexOptions {@code non-null;} options for dex output
 * @return {@code non-null;} the translated version
 */
public static DalvCode translate(RopMethod method, int positionInfo,
        LocalVariableInfo locals, int paramSize, DexOptions dexOptions) {
    RopTranslator translator =
        new RopTranslator(method, positionInfo, locals, paramSize, dexOptions);
    return translator.translateAndGetResult();
}
 
Example #13
Source Project: J2ME-Loader   Author: nikita36078   File: RopTranslator.java    License: Apache License 2.0 3 votes vote down vote up
/**
 * Translates a {@link RopMethod}. This may modify the given
 * input.
 *
 * @param method {@code non-null;} the original method
 * @param positionInfo how much position info to preserve; one of the
 * static constants in {@link PositionList}
 * @param locals {@code null-ok;} local variable information to use
 * @param paramSize size, in register units, of all the parameters to
 * this method
 * @param dexOptions {@code non-null;} options for dex output
 * @return {@code non-null;} the translated version
 */
public static DalvCode translate(RopMethod method, int positionInfo,
        LocalVariableInfo locals, int paramSize, DexOptions dexOptions) {
    RopTranslator translator =
        new RopTranslator(method, positionInfo, locals, paramSize, dexOptions);
    return translator.translateAndGetResult();
}
 
Example #14
Source Project: buck   Author: facebook   File: RopTranslator.java    License: Apache License 2.0 3 votes vote down vote up
/**
 * Translates a {@link RopMethod}. This may modify the given
 * input.
 *
 * @param method {@code non-null;} the original method
 * @param positionInfo how much position info to preserve; one of the
 * static constants in {@link PositionList}
 * @param locals {@code null-ok;} local variable information to use
 * @param paramSize size, in register units, of all the parameters to
 * this method
 * @param dexOptions {@code non-null;} options for dex output
 * @return {@code non-null;} the translated version
 */
public static DalvCode translate(RopMethod method, int positionInfo,
        LocalVariableInfo locals, int paramSize, DexOptions dexOptions) {
    RopTranslator translator =
        new RopTranslator(method, positionInfo, locals, paramSize, dexOptions);
    return translator.translateAndGetResult();
}
 
Example #15
Source Project: Box   Author: lulululbj   File: RopTranslator.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Constructs an instance.
 *
 * @param output {@code non-null;} destination for instruction output
 * @param locals {@code non-null;} the local variable info
 */
public LocalVariableAwareTranslationVisitor(OutputCollector output,
                                            LocalVariableInfo locals) {
    super(output);
    this.locals = locals;
}
 
Example #16
Source Project: Box   Author: lulululbj   File: RopTranslator.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Constructs an instance.
 *
 * @param output {@code non-null;} destination for instruction output
 * @param locals {@code non-null;} the local variable info
 */
public LocalVariableAwareTranslationVisitor(OutputCollector output,
                                            LocalVariableInfo locals) {
    super(output);
    this.locals = locals;
}
 
Example #17
Source Project: J2ME-Loader   Author: nikita36078   File: RopTranslator.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Constructs an instance.
 *
 * @param output {@code non-null;} destination for instruction output
 * @param locals {@code non-null;} the local variable info
 */
public LocalVariableAwareTranslationVisitor(OutputCollector output,
                                            LocalVariableInfo locals) {
    super(output);
    this.locals = locals;
}
 
Example #18
Source Project: buck   Author: facebook   File: RopTranslator.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Constructs an instance.
 *
 * @param output {@code non-null;} destination for instruction output
 * @param locals {@code non-null;} the local variable info
 */
public LocalVariableAwareTranslationVisitor(OutputCollector output,
                                            LocalVariableInfo locals) {
    super(output);
    this.locals = locals;
}