Java Code Examples for com.android.dx.util.IntList#setImmutable()

The following examples show how to use com.android.dx.util.IntList#setImmutable() . 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: Ropper.java    From buck with Apache License 2.0 6 votes vote down vote up
/**
 * Generates a list of subroutine successors. Note: successor blocks
 * could be listed more than once. This is ok, because this successor
 * list (and the block it's associated with) will be copied and inlined
 * before we leave the ropper. Redundent successors will result in
 * redundent (no-op) merges.
 *
 * @return all currently known successors
 * (return destinations) for that subroutine
 */
IntList getSuccessors() {
    IntList successors = new IntList(callerBlocks.size());

    /*
     * For each subroutine caller, get it's target. If the
     * target is us, add the ret target (subroutine successor)
     * to our list
     */

    for (int label = callerBlocks.nextSetBit(0); label >= 0;
         label = callerBlocks.nextSetBit(label+1)) {
        BasicBlock subCaller = labelToBlock(label);
        successors.add(subCaller.getSuccessors().get(0));
    }

    successors.setImmutable();

    return successors;
}
 
Example 2
Source File: Frame.java    From buck with Apache License 2.0 6 votes vote down vote up
/**
 * Merges this frame's subroutine lists with another. The result
 * is the deepest common nesting (effectively, the common prefix of the
 * two lists).
 *
 * @param otherSubroutines label list of subroutine start blocks, from
 * least-nested to most-nested.
 * @return {@code non-null;} merged subroutine nest list as described above
 */
private IntList mergeSubroutineLists(IntList otherSubroutines) {
    if (subroutines.equals(otherSubroutines)) {
        return subroutines;
    }

    IntList resultSubroutines = new IntList();

    int szSubroutines = subroutines.size();
    int szOthers = otherSubroutines.size();
    for (int i = 0; i < szSubroutines && i < szOthers
            && (subroutines.get(i) == otherSubroutines.get(i)); i++) {
        resultSubroutines.add(i);
    }

    resultSubroutines.setImmutable();

    return resultSubroutines;
}
 
Example 3
Source File: IdenticalBlockCombiner.java    From J2ME-Loader with Apache License 2.0 6 votes vote down vote up
/**
 * Replaces one of a block's successors with a different label. Constructs
 * an updated BasicBlock instance and places it in {@code newBlocks}.
 *
 * @param block block to replace
 * @param oldLabel label of successor to replace
 * @param newLabel label of new successor
 */
private void replaceSucc(BasicBlock block, int oldLabel, int newLabel) {
    IntList newSuccessors = block.getSuccessors().mutableCopy();
    int newPrimarySuccessor;

    newSuccessors.set(newSuccessors.indexOf(oldLabel), newLabel);
    newPrimarySuccessor = block.getPrimarySuccessor();

    if (newPrimarySuccessor == oldLabel) {
        newPrimarySuccessor = newLabel;
    }

    newSuccessors.setImmutable();

    BasicBlock newBB = new BasicBlock(block.getLabel(),
            block.getInsns(), newSuccessors, newPrimarySuccessor);

    newBlocks.set(newBlocks.indexOfLabel(block.getLabel()), newBB);
}
 
Example 4
Source File: Ropper.java    From J2ME-Loader with Apache License 2.0 6 votes vote down vote up
/**
 * Generates a list of subroutine successors. Note: successor blocks
 * could be listed more than once. This is ok, because this successor
 * list (and the block it's associated with) will be copied and inlined
 * before we leave the ropper. Redundent successors will result in
 * redundent (no-op) merges.
 *
 * @return all currently known successors
 * (return destinations) for that subroutine
 */
IntList getSuccessors() {
    IntList successors = new IntList(callerBlocks.size());

    /*
     * For each subroutine caller, get it's target. If the
     * target is us, add the ret target (subroutine successor)
     * to our list
     */

    for (int label = callerBlocks.nextSetBit(0); label >= 0;
         label = callerBlocks.nextSetBit(label+1)) {
        BasicBlock subCaller = labelToBlock(label);
        successors.add(subCaller.getSuccessors().get(0));
    }

    successors.setImmutable();

    return successors;
}
 
Example 5
Source File: Frame.java    From J2ME-Loader with Apache License 2.0 6 votes vote down vote up
/**
 * Merges this frame's subroutine lists with another. The result
 * is the deepest common nesting (effectively, the common prefix of the
 * two lists).
 *
 * @param otherSubroutines label list of subroutine start blocks, from
 * least-nested to most-nested.
 * @return {@code non-null;} merged subroutine nest list as described above
 */
private IntList mergeSubroutineLists(IntList otherSubroutines) {
    if (subroutines.equals(otherSubroutines)) {
        return subroutines;
    }

    IntList resultSubroutines = new IntList();

    int szSubroutines = subroutines.size();
    int szOthers = otherSubroutines.size();
    for (int i = 0; i < szSubroutines && i < szOthers
            && (subroutines.get(i) == otherSubroutines.get(i)); i++) {
        resultSubroutines.add(i);
    }

    resultSubroutines.setImmutable();

    return resultSubroutines;
}
 
Example 6
Source File: Ropper.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Generates a list of subroutine successors. Note: successor blocks
 * could be listed more than once. This is ok, because this successor
 * list (and the block it's associated with) will be copied and inlined
 * before we leave the ropper. Redundent successors will result in
 * redundent (no-op) merges.
 *
 * @return all currently known successors
 * (return destinations) for that subroutine
 */
IntList getSuccessors() {
    IntList successors = new IntList(callerBlocks.size());

    /*
     * For each subroutine caller, get it's target. If the
     * target is us, add the ret target (subroutine successor)
     * to our list
     */

    for (int label = callerBlocks.nextSetBit(0); label >= 0;
         label = callerBlocks.nextSetBit(label+1)) {
        BasicBlock subCaller = labelToBlock(label);
        successors.add(subCaller.getSuccessors().get(0));
    }

    successors.setImmutable();

    return successors;
}
 
Example 7
Source File: Frame.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Merges this frame's subroutine lists with another. The result
 * is the deepest common nesting (effectively, the common prefix of the
 * two lists).
 *
 * @param otherSubroutines label list of subroutine start blocks, from
 * least-nested to most-nested.
 * @return {@code non-null;} merged subroutine nest list as described above
 */
private IntList mergeSubroutineLists(IntList otherSubroutines) {
    if (subroutines.equals(otherSubroutines)) {
        return subroutines;
    }

    IntList resultSubroutines = new IntList();

    int szSubroutines = subroutines.size();
    int szOthers = otherSubroutines.size();
    for (int i = 0; i < szSubroutines && i < szOthers
            && (subroutines.get(i) == otherSubroutines.get(i)); i++) {
        resultSubroutines.add(i);
    }

    resultSubroutines.setImmutable();

    return resultSubroutines;
}
 
Example 8
Source File: IdenticalBlockCombiner.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Replaces one of a block's successors with a different label. Constructs
 * an updated BasicBlock instance and places it in {@code newBlocks}.
 *
 * @param block block to replace
 * @param oldLabel label of successor to replace
 * @param newLabel label of new successor
 */
private void replaceSucc(BasicBlock block, int oldLabel, int newLabel) {
    IntList newSuccessors = block.getSuccessors().mutableCopy();
    int newPrimarySuccessor;

    newSuccessors.set(newSuccessors.indexOf(oldLabel), newLabel);
    newPrimarySuccessor = block.getPrimarySuccessor();

    if (newPrimarySuccessor == oldLabel) {
        newPrimarySuccessor = newLabel;
    }

    newSuccessors.setImmutable();

    BasicBlock newBB = new BasicBlock(block.getLabel(),
            block.getInsns(), newSuccessors, newPrimarySuccessor);

    newBlocks.set(newBlocks.indexOfLabel(block.getLabel()), newBB);
}
 
Example 9
Source File: Ropper.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Generates a list of subroutine successors. Note: successor blocks
 * could be listed more than once. This is ok, because this successor
 * list (and the block it's associated with) will be copied and inlined
 * before we leave the ropper. Redundent successors will result in
 * redundent (no-op) merges.
 *
 * @return all currently known successors
 * (return destinations) for that subroutine
 */
IntList getSuccessors() {
    IntList successors = new IntList(callerBlocks.size());

    /*
     * For each subroutine caller, get it's target. If the
     * target is us, add the ret target (subroutine successor)
     * to our list
     */

    for (int label = callerBlocks.nextSetBit(0); label >= 0;
         label = callerBlocks.nextSetBit(label+1)) {
        BasicBlock subCaller = labelToBlock(label);
        successors.add(subCaller.getSuccessors().get(0));
    }

    successors.setImmutable();

    return successors;
}
 
Example 10
Source File: Frame.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Merges this frame's subroutine lists with another. The result
 * is the deepest common nesting (effectively, the common prefix of the
 * two lists).
 *
 * @param otherSubroutines label list of subroutine start blocks, from
 * least-nested to most-nested.
 * @return {@code non-null;} merged subroutine nest list as described above
 */
private IntList mergeSubroutineLists(IntList otherSubroutines) {
    if (subroutines.equals(otherSubroutines)) {
        return subroutines;
    }

    IntList resultSubroutines = new IntList();

    int szSubroutines = subroutines.size();
    int szOthers = otherSubroutines.size();
    for (int i = 0; i < szSubroutines && i < szOthers
            && (subroutines.get(i) == otherSubroutines.get(i)); i++) {
        resultSubroutines.add(i);
    }

    resultSubroutines.setImmutable();

    return resultSubroutines;
}
 
Example 11
Source File: ByteCatchList.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a target list corresponding to this instance. The result
 * is a list of all the exception handler addresses, with the given
 * {@code noException} address appended if appropriate. The
 * result is automatically made immutable.
 *
 * @param noException {@code >= -1;} the no-exception address to append, or
 * {@code -1} not to append anything
 * @return {@code non-null;} list of exception targets, with
 * {@code noException} appended if necessary
 */
public IntList toTargetList(int noException) {
    if (noException < -1) {
        throw new IllegalArgumentException("noException < -1");
    }

    boolean hasDefault = (noException >= 0);
    int sz = size();

    if (sz == 0) {
        if (hasDefault) {
            /*
             * The list is empty, but there is a no-exception
             * address; so, the result is just that address.
             */
            return IntList.makeImmutable(noException);
        }
        /*
         * The list is empty and there isn't even a no-exception
         * address.
         */
        return IntList.EMPTY;
    }

    IntList result = new IntList(sz + (hasDefault ? 1 : 0));

    for (int i = 0; i < sz; i++) {
        result.add(get(i).getHandlerPc());
    }

    if (hasDefault) {
        result.add(noException);
    }

    result.setImmutable();
    return result;
}
 
Example 12
Source File: ByteCatchList.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a target list corresponding to this instance. The result
 * is a list of all the exception handler addresses, with the given
 * {@code noException} address appended if appropriate. The
 * result is automatically made immutable.
 *
 * @param noException {@code >= -1;} the no-exception address to append, or
 * {@code -1} not to append anything
 * @return {@code non-null;} list of exception targets, with
 * {@code noException} appended if necessary
 */
public IntList toTargetList(int noException) {
    if (noException < -1) {
        throw new IllegalArgumentException("noException < -1");
    }

    boolean hasDefault = (noException >= 0);
    int sz = size();

    if (sz == 0) {
        if (hasDefault) {
            /*
             * The list is empty, but there is a no-exception
             * address; so, the result is just that address.
             */
            return IntList.makeImmutable(noException);
        }
        /*
         * The list is empty and there isn't even a no-exception
         * address.
         */
        return IntList.EMPTY;
    }

    IntList result = new IntList(sz + (hasDefault ? 1 : 0));

    for (int i = 0; i < sz; i++) {
        result.add(get(i).getHandlerPc());
    }

    if (hasDefault) {
        result.add(noException);
    }

    result.setImmutable();
    return result;
}
 
Example 13
Source File: ByteCatchList.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a target list corresponding to this instance. The result
 * is a list of all the exception handler addresses, with the given
 * {@code noException} address appended if appropriate. The
 * result is automatically made immutable.
 *
 * @param noException {@code >= -1;} the no-exception address to append, or
 * {@code -1} not to append anything
 * @return {@code non-null;} list of exception targets, with
 * {@code noException} appended if necessary
 */
public IntList toTargetList(int noException) {
    if (noException < -1) {
        throw new IllegalArgumentException("noException < -1");
    }

    boolean hasDefault = (noException >= 0);
    int sz = size();

    if (sz == 0) {
        if (hasDefault) {
            /*
             * The list is empty, but there is a no-exception
             * address; so, the result is just that address.
             */
            return IntList.makeImmutable(noException);
        }
        /*
         * The list is empty and there isn't even a no-exception
         * address.
         */
        return IntList.EMPTY;
    }

    IntList result = new IntList(sz + (hasDefault ? 1 : 0));

    for (int i = 0; i < sz; i++) {
        result.add(get(i).getHandlerPc());
    }

    if (hasDefault) {
        result.add(noException);
    }

    result.setImmutable();
    return result;
}
 
Example 14
Source File: SsaToRop.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * Converts a single basic block to rop form.
 *
 * @param block SSA block to process
 * @return {@code non-null;} ROP block
 */
private BasicBlock convertBasicBlock(SsaBasicBlock block) {
    IntList successorList = block.getRopLabelSuccessorList();
    int primarySuccessorLabel = block.getPrimarySuccessorRopLabel();

    // Filter out any reference to the SSA form's exit block.

    // Exit block may be null.
    SsaBasicBlock exitBlock = ssaMeth.getExitBlock();
    int exitRopLabel = (exitBlock == null) ? -1 : exitBlock.getRopLabel();

    if (successorList.contains(exitRopLabel)) {
        if (successorList.size() > 1) {
            throw new RuntimeException(
                    "Exit predecessor must have no other successors"
                            + Hex.u2(block.getRopLabel()));
        } else {
            successorList = IntList.EMPTY;
            primarySuccessorLabel = -1;

            verifyValidExitPredecessor(block);
        }
    }

    successorList.setImmutable();

    BasicBlock result = new BasicBlock(
            block.getRopLabel(), convertInsns(block.getInsns()),
            successorList,
            primarySuccessorLabel);

    return result;
}
 
Example 15
Source File: ByteCatchList.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a target list corresponding to this instance. The result
 * is a list of all the exception handler addresses, with the given
 * {@code noException} address appended if appropriate. The
 * result is automatically made immutable.
 *
 * @param noException {@code >= -1;} the no-exception address to append, or
 * {@code -1} not to append anything
 * @return {@code non-null;} list of exception targets, with
 * {@code noException} appended if necessary
 */
public IntList toTargetList(int noException) {
    if (noException < -1) {
        throw new IllegalArgumentException("noException < -1");
    }

    boolean hasDefault = (noException >= 0);
    int sz = size();

    if (sz == 0) {
        if (hasDefault) {
            /*
             * The list is empty, but there is a no-exception
             * address; so, the result is just that address.
             */
            return IntList.makeImmutable(noException);
        }
        /*
         * The list is empty and there isn't even a no-exception
         * address.
         */
        return IntList.EMPTY;
    }

    IntList result = new IntList(sz + (hasDefault ? 1 : 0));

    for (int i = 0; i < sz; i++) {
        result.add(get(i).getHandlerPc());
    }

    if (hasDefault) {
        result.add(noException);
    }

    result.setImmutable();
    return result;
}
 
Example 16
Source File: SsaToRop.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Converts a single basic block to rop form.
 *
 * @param block SSA block to process
 * @return {@code non-null;} ROP block
 */
private BasicBlock convertBasicBlock(SsaBasicBlock block) {
    IntList successorList = block.getRopLabelSuccessorList();
    int primarySuccessorLabel = block.getPrimarySuccessorRopLabel();

    // Filter out any reference to the SSA form's exit block.

    // Exit block may be null.
    SsaBasicBlock exitBlock = ssaMeth.getExitBlock();
    int exitRopLabel = (exitBlock == null) ? -1 : exitBlock.getRopLabel();

    if (successorList.contains(exitRopLabel)) {
        if (successorList.size() > 1) {
            throw new RuntimeException(
                    "Exit predecessor must have no other successors"
                            + Hex.u2(block.getRopLabel()));
        } else {
            successorList = IntList.EMPTY;
            primarySuccessorLabel = -1;

            verifyValidExitPredecessor(block);
        }
    }

    successorList.setImmutable();

    BasicBlock result = new BasicBlock(
            block.getRopLabel(), convertInsns(block.getInsns()),
            successorList,
            primarySuccessorLabel);

    return result;
}
 
Example 17
Source File: SsaToRop.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/**
 * Converts a single basic block to rop form.
 *
 * @param block SSA block to process
 * @return {@code non-null;} ROP block
 */
private BasicBlock convertBasicBlock(SsaBasicBlock block) {
    IntList successorList = block.getRopLabelSuccessorList();
    int primarySuccessorLabel = block.getPrimarySuccessorRopLabel();

    // Filter out any reference to the SSA form's exit block.

    // Exit block may be null.
    SsaBasicBlock exitBlock = ssaMeth.getExitBlock();
    int exitRopLabel = (exitBlock == null) ? -1 : exitBlock.getRopLabel();

    if (successorList.contains(exitRopLabel)) {
        if (successorList.size() > 1) {
            throw new RuntimeException(
                    "Exit predecessor must have no other successors"
                            + Hex.u2(block.getRopLabel()));
        } else {
            successorList = IntList.EMPTY;
            primarySuccessorLabel = -1;

            verifyValidExitPredecessor(block);
        }
    }

    successorList.setImmutable();

    BasicBlock result = new BasicBlock(
            block.getRopLabel(), convertInsns(block.getInsns()),
            successorList,
            primarySuccessorLabel);

    return result;
}
 
Example 18
Source File: Frame.java    From Box with Apache License 2.0 4 votes vote down vote up
/**
 * Merges this frame with the frame of a subroutine caller at
 * {@code predLabel}. Only called on the frame at the first
 * block of a subroutine.
 *
 * @param other {@code non-null;} another frame
 * @param subLabel label of subroutine start block
 * @param predLabel label of calling block
 * @return {@code non-null;} the result of merging the two frames
 */
public Frame mergeWithSubroutineCaller(Frame other, int subLabel,
        int predLabel) {
    LocalsArray resultLocals;
    ExecutionStack resultStack;

    resultLocals = getLocals().mergeWithSubroutineCaller(
            other.getLocals(), predLabel);
    resultStack = getStack().merge(other.getStack());

    IntList newOtherSubroutines = other.subroutines.mutableCopy();
    newOtherSubroutines.add(subLabel);
    newOtherSubroutines.setImmutable();

    if ((resultLocals == getLocals())
            && (resultStack == getStack())
            && subroutines.equals(newOtherSubroutines)) {
        return this;
    }

    IntList resultSubroutines;

    if (subroutines.equals(newOtherSubroutines)) {
        resultSubroutines = subroutines;
    } else {
        /*
         * The new subroutines list should be the deepest of the two
         * lists being merged, but the postfix of the resultant list
         * must be equal to the shorter list.
         */
        IntList nonResultSubroutines;

        if (subroutines.size() > newOtherSubroutines.size()) {
            resultSubroutines = subroutines;
            nonResultSubroutines = newOtherSubroutines;
        } else {
            resultSubroutines = newOtherSubroutines;
            nonResultSubroutines = subroutines;
        }

        int szResult = resultSubroutines.size();
        int szNonResult = nonResultSubroutines.size();

        for (int i = szNonResult - 1; i >=0; i-- ) {
            if (nonResultSubroutines.get(i)
                    != resultSubroutines.get(
                    i + (szResult - szNonResult))) {
                throw new
                        RuntimeException("Incompatible merged subroutines");
            }
        }

    }

    return new Frame(resultLocals, resultStack, resultSubroutines);
}
 
Example 19
Source File: Frame.java    From buck with Apache License 2.0 4 votes vote down vote up
/**
 * Merges this frame with the frame of a subroutine caller at
 * {@code predLabel}. Only called on the frame at the first
 * block of a subroutine.
 *
 * @param other {@code non-null;} another frame
 * @param subLabel label of subroutine start block
 * @param predLabel label of calling block
 * @return {@code non-null;} the result of merging the two frames
 */
public Frame mergeWithSubroutineCaller(Frame other, int subLabel,
        int predLabel) {
    LocalsArray resultLocals;
    ExecutionStack resultStack;

    resultLocals = getLocals().mergeWithSubroutineCaller(
            other.getLocals(), predLabel);
    resultStack = getStack().merge(other.getStack());

    IntList newOtherSubroutines = other.subroutines.mutableCopy();
    newOtherSubroutines.add(subLabel);
    newOtherSubroutines.setImmutable();

    if ((resultLocals == getLocals())
            && (resultStack == getStack())
            && subroutines.equals(newOtherSubroutines)) {
        return this;
    }

    IntList resultSubroutines;

    if (subroutines.equals(newOtherSubroutines)) {
        resultSubroutines = subroutines;
    } else {
        /*
         * The new subroutines list should be the deepest of the two
         * lists being merged, but the postfix of the resultant list
         * must be equal to the shorter list.
         */
        IntList nonResultSubroutines;

        if (subroutines.size() > newOtherSubroutines.size()) {
            resultSubroutines = subroutines;
            nonResultSubroutines = newOtherSubroutines;
        } else {
            resultSubroutines = newOtherSubroutines;
            nonResultSubroutines = subroutines;
        }

        int szResult = resultSubroutines.size();
        int szNonResult = nonResultSubroutines.size();

        for (int i = szNonResult - 1; i >=0; i-- ) {
            if (nonResultSubroutines.get(i)
                    != resultSubroutines.get(
                    i + (szResult - szNonResult))) {
                throw new
                        RuntimeException("Incompatible merged subroutines");
            }
        }

    }

    return new Frame(resultLocals, resultStack, resultSubroutines);
}
 
Example 20
Source File: Frame.java    From Box with Apache License 2.0 4 votes vote down vote up
/**
 * Merges this frame with the frame of a subroutine caller at
 * {@code predLabel}. Only called on the frame at the first
 * block of a subroutine.
 *
 * @param other {@code non-null;} another frame
 * @param subLabel label of subroutine start block
 * @param predLabel label of calling block
 * @return {@code non-null;} the result of merging the two frames
 */
public Frame mergeWithSubroutineCaller(Frame other, int subLabel,
        int predLabel) {
    LocalsArray resultLocals;
    ExecutionStack resultStack;

    resultLocals = getLocals().mergeWithSubroutineCaller(
            other.getLocals(), predLabel);
    resultStack = getStack().merge(other.getStack());

    IntList newOtherSubroutines = other.subroutines.mutableCopy();
    newOtherSubroutines.add(subLabel);
    newOtherSubroutines.setImmutable();

    if ((resultLocals == getLocals())
            && (resultStack == getStack())
            && subroutines.equals(newOtherSubroutines)) {
        return this;
    }

    IntList resultSubroutines;

    if (subroutines.equals(newOtherSubroutines)) {
        resultSubroutines = subroutines;
    } else {
        /*
         * The new subroutines list should be the deepest of the two
         * lists being merged, but the postfix of the resultant list
         * must be equal to the shorter list.
         */
        IntList nonResultSubroutines;

        if (subroutines.size() > newOtherSubroutines.size()) {
            resultSubroutines = subroutines;
            nonResultSubroutines = newOtherSubroutines;
        } else {
            resultSubroutines = newOtherSubroutines;
            nonResultSubroutines = subroutines;
        }

        int szResult = resultSubroutines.size();
        int szNonResult = nonResultSubroutines.size();

        for (int i = szNonResult - 1; i >=0; i-- ) {
            if (nonResultSubroutines.get(i)
                    != resultSubroutines.get(
                    i + (szResult - szNonResult))) {
                throw new
                        RuntimeException("Incompatible merged subroutines");
            }
        }

    }

    return new Frame(resultLocals, resultStack, resultSubroutines);
}