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

The following examples show how to use com.android.dx.util.IntList#makeImmutable() . 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: 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 2
Source File: BasicBlocker.java    From Box with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public void visitBranch(int opcode, int offset, int length,
        int target) {
    switch (opcode) {
        case ByteOps.GOTO: {
            visitCommon(offset, length, false);
            targetLists[offset] = IntList.makeImmutable(target);
            break;
        }
        case ByteOps.JSR: {
            /*
             * Each jsr is quarantined into a separate block (containing
             * only the jsr instruction) but is otherwise treated
             * as a conditional branch. (That is to say, both its
             * target and next instruction begin new blocks.)
             */
            addWorkIfNecessary(offset, true);
            // Fall through to next case...
        }
        default: {
            int next = offset + length;
            visitCommon(offset, length, true);
            addWorkIfNecessary(next, true);
            targetLists[offset] = IntList.makeImmutable(next, target);
            break;
        }
    }

    addWorkIfNecessary(target, true);
}
 
Example 3
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 4
Source File: BasicBlocker.java    From Box with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public void visitBranch(int opcode, int offset, int length,
        int target) {
    switch (opcode) {
        case ByteOps.GOTO: {
            visitCommon(offset, length, false);
            targetLists[offset] = IntList.makeImmutable(target);
            break;
        }
        case ByteOps.JSR: {
            /*
             * Each jsr is quarantined into a separate block (containing
             * only the jsr instruction) but is otherwise treated
             * as a conditional branch. (That is to say, both its
             * target and next instruction begin new blocks.)
             */
            addWorkIfNecessary(offset, true);
            // Fall through to next case...
        }
        default: {
            int next = offset + length;
            visitCommon(offset, length, true);
            addWorkIfNecessary(next, true);
            targetLists[offset] = IntList.makeImmutable(next, target);
            break;
        }
    }

    addWorkIfNecessary(target, true);
}
 
Example 5
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 6
Source File: BasicBlocker.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
   @Override
public void visitBranch(int opcode, int offset, int length,
						int target) {
       switch (opcode) {
           case ByteOps.GOTO: {
               visitCommon(offset, length, false);
               targetLists[offset] = IntList.makeImmutable(target);
               break;
           }
           case ByteOps.JSR: {
               /*
                * Each jsr is quarantined into a separate block (containing
                * only the jsr instruction) but is otherwise treated
                * as a conditional branch. (That is to say, both its
                * target and next instruction begin new blocks.)
                */
               addWorkIfNecessary(offset, true);
               // Fall through to next case...
           }
           default: {
               int next = offset + length;
               visitCommon(offset, length, true);
               addWorkIfNecessary(next, true);
               targetLists[offset] = IntList.makeImmutable(next, target);
               break;
           }
       }

       addWorkIfNecessary(target, true);
   }
 
Example 7
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 8
Source File: BasicBlocker.java    From buck with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
public void visitBranch(int opcode, int offset, int length,
        int target) {
    switch (opcode) {
        case ByteOps.GOTO: {
            visitCommon(offset, length, false);
            targetLists[offset] = IntList.makeImmutable(target);
            break;
        }
        case ByteOps.JSR: {
            /*
             * Each jsr is quarantined into a separate block (containing
             * only the jsr instruction) but is otherwise treated
             * as a conditional branch. (That is to say, both its
             * target and next instruction begin new blocks.)
             */
            addWorkIfNecessary(offset, true);
            // Fall through to next case...
        }
 // fall through
        default: {
            int next = offset + length;
            visitCommon(offset, length, true);
            addWorkIfNecessary(next, true);
            targetLists[offset] = IntList.makeImmutable(next, target);
            break;
        }
    }

    addWorkIfNecessary(target, true);
}
 
Example 9
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 10
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 11
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 12
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;
}
 
Example 13
Source File: Frame.java    From Box with Apache License 2.0 3 votes vote down vote up
/**
 * Makes a frame for a subroutine start block, given that this is the
 * ending frame of one of the subroutine's calling blocks. Subroutine
 * calls may be nested and thus may have nested locals state, so we
 * start with an initial state as seen by the subroutine, but keep track
 * of the individual locals states that will be expected when the individual
 * subroutine calls return.
 *
 * @param subLabel label of subroutine start block
 * @param callerLabel {@code >=0;} label of the caller block where this frame
 * came from.
 * @return a new instance to begin a called subroutine.
 */
public Frame makeNewSubroutineStartFrame(int subLabel, int callerLabel) {
    IntList newSubroutines = subroutines.mutableCopy();
    newSubroutines.add(subLabel);
    Frame newFrame = new Frame(locals.getPrimary(), stack,
            IntList.makeImmutable(subLabel));
    return newFrame.mergeWithSubroutineCaller(this, subLabel, callerLabel);
}
 
Example 14
Source File: Frame.java    From Box with Apache License 2.0 3 votes vote down vote up
/**
 * Makes a frame for a subroutine start block, given that this is the
 * ending frame of one of the subroutine's calling blocks. Subroutine
 * calls may be nested and thus may have nested locals state, so we
 * start with an initial state as seen by the subroutine, but keep track
 * of the individual locals states that will be expected when the individual
 * subroutine calls return.
 *
 * @param subLabel label of subroutine start block
 * @param callerLabel {@code >=0;} label of the caller block where this frame
 * came from.
 * @return a new instance to begin a called subroutine.
 */
public Frame makeNewSubroutineStartFrame(int subLabel, int callerLabel) {
    IntList newSubroutines = subroutines.mutableCopy();
    newSubroutines.add(subLabel);
    Frame newFrame = new Frame(locals.getPrimary(), stack,
            IntList.makeImmutable(subLabel));
    return newFrame.mergeWithSubroutineCaller(this, subLabel, callerLabel);
}
 
Example 15
Source File: Frame.java    From J2ME-Loader with Apache License 2.0 3 votes vote down vote up
/**
 * Makes a frame for a subroutine start block, given that this is the
 * ending frame of one of the subroutine's calling blocks. Subroutine
 * calls may be nested and thus may have nested locals state, so we
 * start with an initial state as seen by the subroutine, but keep track
 * of the individual locals states that will be expected when the individual
 * subroutine calls return.
 *
 * @param subLabel label of subroutine start block
 * @param callerLabel {@code >=0;} label of the caller block where this frame
 * came from.
 * @return a new instance to begin a called subroutine.
 */
public Frame makeNewSubroutineStartFrame(int subLabel, int callerLabel) {
    IntList newSubroutines = subroutines.mutableCopy();
    newSubroutines.add(subLabel);
    Frame newFrame = new Frame(locals.getPrimary(), stack,
            IntList.makeImmutable(subLabel));
    return newFrame.mergeWithSubroutineCaller(this, subLabel, callerLabel);
}
 
Example 16
Source File: Frame.java    From buck with Apache License 2.0 3 votes vote down vote up
/**
 * Makes a frame for a subroutine start block, given that this is the
 * ending frame of one of the subroutine's calling blocks. Subroutine
 * calls may be nested and thus may have nested locals state, so we
 * start with an initial state as seen by the subroutine, but keep track
 * of the individual locals states that will be expected when the individual
 * subroutine calls return.
 *
 * @param subLabel label of subroutine start block
 * @param callerLabel {@code >=0;} label of the caller block where this frame
 * came from.
 * @return a new instance to begin a called subroutine.
 */
public Frame makeNewSubroutineStartFrame(int subLabel, int callerLabel) {
    IntList newSubroutines = subroutines.mutableCopy();
    newSubroutines.add(subLabel);
    Frame newFrame = new Frame(locals.getPrimary(), stack,
            IntList.makeImmutable(subLabel));
    return newFrame.mergeWithSubroutineCaller(this, subLabel, callerLabel);
}