Java Code Examples for com.android.dx.util.Bits#findFirst()

The following examples show how to use com.android.dx.util.Bits#findFirst() . 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: BytecodeArray.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Processes the given "work set" by repeatedly finding the lowest bit
 * in the set, clearing it, and parsing and visiting the instruction at
 * the indicated offset (that is, the bit index), repeating until the
 * work set is empty. It is expected that the visitor will regularly
 * set new bits in the work set during the process.
 *
 * @param workSet {@code non-null;} the work set to process
 * @param visitor {@code non-null;} visitor to call back to for
 * each instruction
 */
public void processWorkSet(int[] workSet, Visitor visitor) {
    if (visitor == null) {
        throw new NullPointerException("visitor == null");
    }

    for (;;) {
        int offset = Bits.findFirst(workSet, 0);
        if (offset < 0) {
            break;
        }
        Bits.clear(workSet, offset);
        parseInstruction(offset, visitor);
        visitor.setPreviousOffset(offset);
    }
}
 
Example 2
Source File: BytecodeArray.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Processes the given "work set" by repeatedly finding the lowest bit
 * in the set, clearing it, and parsing and visiting the instruction at
 * the indicated offset (that is, the bit index), repeating until the
 * work set is empty. It is expected that the visitor will regularly
 * set new bits in the work set during the process.
 *
 * @param workSet {@code non-null;} the work set to process
 * @param visitor {@code non-null;} visitor to call back to for
 * each instruction
 */
public void processWorkSet(int[] workSet, Visitor visitor) {
    if (visitor == null) {
        throw new NullPointerException("visitor == null");
    }

    for (;;) {
        int offset = Bits.findFirst(workSet, 0);
        if (offset < 0) {
            break;
        }
        Bits.clear(workSet, offset);
        parseInstruction(offset, visitor);
        visitor.setPreviousOffset(offset);
    }
}
 
Example 3
Source File: BytecodeArray.java    From J2ME-Loader with Apache License 2.0 6 votes vote down vote up
/**
 * Processes the given "work set" by repeatedly finding the lowest bit
 * in the set, clearing it, and parsing and visiting the instruction at
 * the indicated offset (that is, the bit index), repeating until the
 * work set is empty. It is expected that the visitor will regularly
 * set new bits in the work set during the process.
 *
 * @param workSet {@code non-null;} the work set to process
 * @param visitor {@code non-null;} visitor to call back to for
 * each instruction
 */
public void processWorkSet(int[] workSet, Visitor visitor) {
    if (visitor == null) {
        throw new NullPointerException("visitor == null");
    }

    for (;;) {
        int offset = Bits.findFirst(workSet, 0);
        if (offset < 0) {
            break;
        }
        Bits.clear(workSet, offset);
        parseInstruction(offset, visitor);
        visitor.setPreviousOffset(offset);
    }
}
 
Example 4
Source File: BytecodeArray.java    From buck with Apache License 2.0 6 votes vote down vote up
/**
 * Processes the given "work set" by repeatedly finding the lowest bit
 * in the set, clearing it, and parsing and visiting the instruction at
 * the indicated offset (that is, the bit index), repeating until the
 * work set is empty. It is expected that the visitor will regularly
 * set new bits in the work set during the process.
 *
 * @param workSet {@code non-null;} the work set to process
 * @param visitor {@code non-null;} visitor to call back to for
 * each instruction
 */
public void processWorkSet(int[] workSet, Visitor visitor) {
    if (visitor == null) {
        throw new NullPointerException("visitor == null");
    }

    for (;;) {
        int offset = Bits.findFirst(workSet, 0);
        if (offset < 0) {
            break;
        }
        Bits.clear(workSet, offset);
        parseInstruction(offset, visitor);
        visitor.setPreviousOffset(offset);
    }
}
 
Example 5
Source File: Ropper.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Does the conversion.
 */
private void doit() {
    int[] workSet = Bits.makeBitSet(maxLabel);

    Bits.set(workSet, 0);
    addSetupBlocks();
    setFirstFrame();

    for (;;) {
        int offset = Bits.findFirst(workSet, 0);
        if (offset < 0) {
            break;
        }
        Bits.clear(workSet, offset);
        ByteBlock block = blocks.labelToBlock(offset);
        Frame frame = startFrames[offset];
        try {
            processBlock(block, frame, workSet);
        } catch (SimException ex) {
            ex.addContext("...while working on block " + Hex.u2(offset));
            throw ex;
        }
    }

    addReturnBlock();
    addSynchExceptionHandlerBlock();
    addExceptionSetupBlocks();

    if (hasSubroutines) {
        // Subroutines are very rare, so skip this step if it's n/a
        inlineSubroutines();
    }
}
 
Example 6
Source File: LocalVariableExtractor.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Does the extraction.
 *
 * @return {@code non-null;} the extracted information
 */
private LocalVariableInfo doit() {
    for (int label = method.getFirstLabel();
         label >= 0;
         label = Bits.findFirst(workSet, 0)) {
        Bits.clear(workSet, label);
        processBlock(label);
    }

    resultInfo.setImmutable();
    return resultInfo;
}
 
Example 7
Source File: Ropper.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Does the conversion.
 */
private void doit() {
    int[] workSet = Bits.makeBitSet(maxLabel);

    Bits.set(workSet, 0);
    addSetupBlocks();
    setFirstFrame();

    for (;;) {
        int offset = Bits.findFirst(workSet, 0);
        if (offset < 0) {
            break;
        }
        Bits.clear(workSet, offset);
        ByteBlock block = blocks.labelToBlock(offset);
        Frame frame = startFrames[offset];
        try {
            processBlock(block, frame, workSet);
        } catch (SimException ex) {
            ex.addContext("...while working on block " + Hex.u2(offset));
            throw ex;
        }
    }

    addReturnBlock();
    addSynchExceptionHandlerBlock();
    addExceptionSetupBlocks();

    if (hasSubroutines) {
        // Subroutines are very rare, so skip this step if it's n/a
        inlineSubroutines();
    }
}
 
Example 8
Source File: LocalVariableExtractor.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Does the extraction.
 *
 * @return {@code non-null;} the extracted information
 */
private LocalVariableInfo doit() {
    for (int label = method.getFirstLabel();
         label >= 0;
         label = Bits.findFirst(workSet, 0)) {
        Bits.clear(workSet, label);
        processBlock(label);
    }

    resultInfo.setImmutable();
    return resultInfo;
}
 
Example 9
Source File: Ropper.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/**
 * Does the conversion.
 */
private void doit() {
    int[] workSet = Bits.makeBitSet(maxLabel);

    Bits.set(workSet, 0);
    addSetupBlocks();
    setFirstFrame();

    for (;;) {
        int offset = Bits.findFirst(workSet, 0);
        if (offset < 0) {
            break;
        }
        Bits.clear(workSet, offset);
        ByteBlock block = blocks.labelToBlock(offset);
        Frame frame = startFrames[offset];
        try {
            processBlock(block, frame, workSet);
        } catch (SimException ex) {
            ex.addContext("...while working on block " + Hex.u2(offset));
            throw ex;
        }
    }

    addReturnBlock();
    addSynchExceptionHandlerBlock();
    addExceptionSetupBlocks();

    if (hasSubroutines) {
        // Subroutines are very rare, so skip this step if it's n/a
        inlineSubroutines();
    }
}
 
Example 10
Source File: LocalVariableExtractor.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/**
 * Does the extraction.
 *
 * @return {@code non-null;} the extracted information
 */
private LocalVariableInfo doit() {
    for (int label = method.getFirstLabel();
         label >= 0;
         label = Bits.findFirst(workSet, 0)) {
        Bits.clear(workSet, label);
        processBlock(label);
    }

    resultInfo.setImmutable();
    return resultInfo;
}
 
Example 11
Source File: Ropper.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * Does the conversion.
 */
private void doit() {
    int[] workSet = Bits.makeBitSet(maxLabel);

    Bits.set(workSet, 0);
    addSetupBlocks();
    setFirstFrame();

    for (;;) {
        int offset = Bits.findFirst(workSet, 0);
        if (offset < 0) {
            break;
        }
        Bits.clear(workSet, offset);
        ByteBlock block = blocks.labelToBlock(offset);
        Frame frame = startFrames[offset];
        try {
            processBlock(block, frame, workSet);
        } catch (SimException ex) {
            ex.addContext("...while working on block " + Hex.u2(offset));
            throw ex;
        }
    }

    addReturnBlock();
    addSynchExceptionHandlerBlock();
    addExceptionSetupBlocks();

    if (hasSubroutines) {
        // Subroutines are very rare, so skip this step if it's n/a
        inlineSubroutines();
    }
}
 
Example 12
Source File: LocalVariableExtractor.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * Does the extraction.
 *
 * @return {@code non-null;} the extracted information
 */
private LocalVariableInfo doit() {
    for (int label = method.getFirstLabel();
         label >= 0;
         label = Bits.findFirst(workSet, 0)) {
        Bits.clear(workSet, label);
        processBlock(label);
    }

    resultInfo.setImmutable();
    return resultInfo;
}
 
Example 13
Source File: BasicBlocker.java    From Box with Apache License 2.0 4 votes vote down vote up
/**
 * Extracts the list of basic blocks from the bit sets.
 *
 * @return {@code non-null;} the list of basic blocks
 */
private ByteBlockList getBlockList() {
    BytecodeArray bytes = method.getCode();
    ByteBlock[] bbs = new ByteBlock[bytes.size()];
    int count = 0;

    for (int at = 0, next; /*at*/; at = next) {
        next = Bits.findFirst(blockSet, at + 1);
        if (next < 0) {
            break;
        }

        if (Bits.get(liveSet, at)) {
            /*
             * Search backward for the branch or throwing
             * instruction at the end of this block, if any. If
             * there isn't any, then "next" is the sole target.
             */
            IntList targets = null;
            int targetsAt = -1;
            ByteCatchList blockCatches;

            for (int i = next - 1; i >= at; i--) {
                targets = targetLists[i];
                if (targets != null) {
                    targetsAt = i;
                    break;
                }
            }

            if (targets == null) {
                targets = IntList.makeImmutable(next);
                blockCatches = ByteCatchList.EMPTY;
            } else {
                blockCatches = catchLists[targetsAt];
                if (blockCatches == null) {
                    blockCatches = ByteCatchList.EMPTY;
                }
            }

            bbs[count] =
                new ByteBlock(at, at, next, targets, blockCatches);
            count++;
        }
    }

    ByteBlockList result = new ByteBlockList(count);
    for (int i = 0; i < count; i++) {
        result.set(i, bbs[i]);
    }

    return result;
}
 
Example 14
Source File: BasicBlocker.java    From Box with Apache License 2.0 4 votes vote down vote up
/**
 * Extracts the list of basic blocks from the bit sets.
 *
 * @return {@code non-null;} the list of basic blocks
 */
private ByteBlockList getBlockList() {
    BytecodeArray bytes = method.getCode();
    ByteBlock[] bbs = new ByteBlock[bytes.size()];
    int count = 0;

    for (int at = 0, next; /*at*/; at = next) {
        next = Bits.findFirst(blockSet, at + 1);
        if (next < 0) {
            break;
        }

        if (Bits.get(liveSet, at)) {
            /*
             * Search backward for the branch or throwing
             * instruction at the end of this block, if any. If
             * there isn't any, then "next" is the sole target.
             */
            IntList targets = null;
            int targetsAt = -1;
            ByteCatchList blockCatches;

            for (int i = next - 1; i >= at; i--) {
                targets = targetLists[i];
                if (targets != null) {
                    targetsAt = i;
                    break;
                }
            }

            if (targets == null) {
                targets = IntList.makeImmutable(next);
                blockCatches = ByteCatchList.EMPTY;
            } else {
                blockCatches = catchLists[targetsAt];
                if (blockCatches == null) {
                    blockCatches = ByteCatchList.EMPTY;
                }
            }

            bbs[count] =
                new ByteBlock(at, at, next, targets, blockCatches);
            count++;
        }
    }

    ByteBlockList result = new ByteBlockList(count);
    for (int i = 0; i < count; i++) {
        result.set(i, bbs[i]);
    }

    return result;
}
 
Example 15
Source File: BasicBlocker.java    From J2ME-Loader with Apache License 2.0 4 votes vote down vote up
/**
 * Extracts the list of basic blocks from the bit sets.
 *
 * @return {@code non-null;} the list of basic blocks
 */
private ByteBlockList getBlockList() {
    BytecodeArray bytes = method.getCode();
    ByteBlock[] bbs = new ByteBlock[bytes.size()];
    int count = 0;

    for (int at = 0, next; /*at*/; at = next) {
        next = Bits.findFirst(blockSet, at + 1);
        if (next < 0) {
            break;
        }

        if (Bits.get(liveSet, at)) {
            /*
             * Search backward for the branch or throwing
             * instruction at the end of this block, if any. If
             * there isn't any, then "next" is the sole target.
             */
            IntList targets = null;
            int targetsAt = -1;
            ByteCatchList blockCatches;

            for (int i = next - 1; i >= at; i--) {
                targets = targetLists[i];
                if (targets != null) {
                    targetsAt = i;
                    break;
                }
            }

            if (targets == null) {
                targets = IntList.makeImmutable(next);
                blockCatches = ByteCatchList.EMPTY;
            } else {
                blockCatches = catchLists[targetsAt];
                if (blockCatches == null) {
                    blockCatches = ByteCatchList.EMPTY;
                }
            }

            bbs[count] =
                new ByteBlock(at, at, next, targets, blockCatches);
            count++;
        }
    }

    ByteBlockList result = new ByteBlockList(count);
    for (int i = 0; i < count; i++) {
        result.set(i, bbs[i]);
    }

    return result;
}
 
Example 16
Source File: BasicBlocker.java    From buck with Apache License 2.0 4 votes vote down vote up
/**
 * Extracts the list of basic blocks from the bit sets.
 *
 * @return {@code non-null;} the list of basic blocks
 */
private ByteBlockList getBlockList() {
    BytecodeArray bytes = method.getCode();
    ByteBlock[] bbs = new ByteBlock[bytes.size()];
    int count = 0;

    for (int at = 0, next; /*at*/; at = next) {
        next = Bits.findFirst(blockSet, at + 1);
        if (next < 0) {
            break;
        }

        if (Bits.get(liveSet, at)) {
            /*
             * Search backward for the branch or throwing
             * instruction at the end of this block, if any. If
             * there isn't any, then "next" is the sole target.
             */
            IntList targets = null;
            int targetsAt = -1;
            ByteCatchList blockCatches;

            for (int i = next - 1; i >= at; i--) {
                targets = targetLists[i];
                if (targets != null) {
                    targetsAt = i;
                    break;
                }
            }

            if (targets == null) {
                targets = IntList.makeImmutable(next);
                blockCatches = ByteCatchList.EMPTY;
            } else {
                blockCatches = catchLists[targetsAt];
                if (blockCatches == null) {
                    blockCatches = ByteCatchList.EMPTY;
                }
            }

            bbs[count] =
                new ByteBlock(at, at, next, targets, blockCatches);
            count++;
        }
    }

    ByteBlockList result = new ByteBlockList(count);
    for (int i = 0; i < count; i++) {
        result.set(i, bbs[i]);
    }

    return result;
}