Java Code Examples for com.android.dx.util.IntList#EMPTY

The following examples show how to use com.android.dx.util.IntList#EMPTY . 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 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 2
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 3
Source File: BasicBlocker.java    From buck with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
public void visitLocal(int opcode, int offset, int length,
        int idx, Type type, int value) {
    if (opcode == ByteOps.RET) {
        visitCommon(offset, length, false);
        targetLists[offset] = IntList.EMPTY;
    } else {
        visitCommon(offset, length, true);
    }
}
 
Example 4
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 5
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 6
Source File: BasicBlocker.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
   @Override
public void visitLocal(int opcode, int offset, int length,
					   int idx, Type type, int value) {
       if (opcode == ByteOps.RET) {
           visitCommon(offset, length, false);
           targetLists[offset] = IntList.EMPTY;
       } else {
           visitCommon(offset, length, true);
       }
   }
 
Example 7
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 8
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 9
Source File: BasicBlocker.java    From Box with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public void visitLocal(int opcode, int offset, int length,
        int idx, Type type, int value) {
    if (opcode == ByteOps.RET) {
        visitCommon(offset, length, false);
        targetLists[offset] = IntList.EMPTY;
    } else {
        visitCommon(offset, length, true);
    }
}
 
Example 10
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 11
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 12
Source File: BasicBlocker.java    From Box with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public void visitLocal(int opcode, int offset, int length,
        int idx, Type type, int value) {
    if (opcode == ByteOps.RET) {
        visitCommon(offset, length, false);
        targetLists[offset] = IntList.EMPTY;
    } else {
        visitCommon(offset, length, true);
    }
}
 
Example 13
Source File: BasicBlocker.java    From Box with Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
@Override
public void visitNoArgs(int opcode, int offset, int length, Type type) {
    switch (opcode) {
        case ByteOps.IRETURN:
        case ByteOps.RETURN: {
            visitCommon(offset, length, false);
            targetLists[offset] = IntList.EMPTY;
            break;
        }
        case ByteOps.ATHROW: {
            visitCommon(offset, length, false);
            visitThrowing(offset, length, false);
            break;
        }
        case ByteOps.IALOAD:
        case ByteOps.LALOAD:
        case ByteOps.FALOAD:
        case ByteOps.DALOAD:
        case ByteOps.AALOAD:
        case ByteOps.BALOAD:
        case ByteOps.CALOAD:
        case ByteOps.SALOAD:
        case ByteOps.IASTORE:
        case ByteOps.LASTORE:
        case ByteOps.FASTORE:
        case ByteOps.DASTORE:
        case ByteOps.AASTORE:
        case ByteOps.BASTORE:
        case ByteOps.CASTORE:
        case ByteOps.SASTORE:
        case ByteOps.ARRAYLENGTH:
        case ByteOps.MONITORENTER:
        case ByteOps.MONITOREXIT: {
            /*
             * These instructions can all throw, so they have to end
             * the block they appear in (since throws are branches).
             */
            visitCommon(offset, length, true);
            visitThrowing(offset, length, true);
            break;
        }
        case ByteOps.IDIV:
        case ByteOps.IREM: {
            /*
             * The int and long versions of division and remainder may
             * throw, but not the other types.
             */
            visitCommon(offset, length, true);
            if ((type == Type.INT) || (type == Type.LONG)) {
                visitThrowing(offset, length, true);
            }
            break;
        }
        default: {
            visitCommon(offset, length, true);
            break;
        }
    }
}
 
Example 14
Source File: BasicBlocker.java    From J2ME-Loader with Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
   @Override
public void visitNoArgs(int opcode, int offset, int length, Type type) {
       switch (opcode) {
           case ByteOps.IRETURN:
           case ByteOps.RETURN: {
               visitCommon(offset, length, false);
               targetLists[offset] = IntList.EMPTY;
               break;
           }
           case ByteOps.ATHROW: {
               visitCommon(offset, length, false);
               visitThrowing(offset, length, false);
               break;
           }
           case ByteOps.IALOAD:
           case ByteOps.LALOAD:
           case ByteOps.FALOAD:
           case ByteOps.DALOAD:
           case ByteOps.AALOAD:
           case ByteOps.BALOAD:
           case ByteOps.CALOAD:
           case ByteOps.SALOAD:
           case ByteOps.IASTORE:
           case ByteOps.LASTORE:
           case ByteOps.FASTORE:
           case ByteOps.DASTORE:
           case ByteOps.AASTORE:
           case ByteOps.BASTORE:
           case ByteOps.CASTORE:
           case ByteOps.SASTORE:
           case ByteOps.ARRAYLENGTH:
           case ByteOps.MONITORENTER:
           case ByteOps.MONITOREXIT: {
               /*
                * These instructions can all throw, so they have to end
                * the block they appear in (since throws are branches).
                */
               visitCommon(offset, length, true);
               visitThrowing(offset, length, true);
               break;
           }
           case ByteOps.IDIV:
           case ByteOps.IREM: {
               /*
                * The int and long versions of division and remainder may
                * throw, but not the other types.
                */
               visitCommon(offset, length, true);
               if ((type == Type.INT) || (type == Type.LONG)) {
                   visitThrowing(offset, length, true);
               }
               break;
           }
           default: {
               visitCommon(offset, length, true);
               break;
           }
       }
   }
 
Example 15
Source File: BasicBlocker.java    From buck with Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
public void visitNoArgs(int opcode, int offset, int length, Type type) {
    switch (opcode) {
        case ByteOps.IRETURN:
        case ByteOps.RETURN: {
            visitCommon(offset, length, false);
            targetLists[offset] = IntList.EMPTY;
            break;
        }
        case ByteOps.ATHROW: {
            visitCommon(offset, length, false);
            visitThrowing(offset, length, false);
            break;
        }
        case ByteOps.IALOAD:
        case ByteOps.LALOAD:
        case ByteOps.FALOAD:
        case ByteOps.DALOAD:
        case ByteOps.AALOAD:
        case ByteOps.BALOAD:
        case ByteOps.CALOAD:
        case ByteOps.SALOAD:
        case ByteOps.IASTORE:
        case ByteOps.LASTORE:
        case ByteOps.FASTORE:
        case ByteOps.DASTORE:
        case ByteOps.AASTORE:
        case ByteOps.BASTORE:
        case ByteOps.CASTORE:
        case ByteOps.SASTORE:
        case ByteOps.ARRAYLENGTH:
        case ByteOps.MONITORENTER:
        case ByteOps.MONITOREXIT: {
            /*
             * These instructions can all throw, so they have to end
             * the block they appear in (since throws are branches).
             */
            visitCommon(offset, length, true);
            visitThrowing(offset, length, true);
            break;
        }
        case ByteOps.IDIV:
        case ByteOps.IREM: {
            /*
             * The int and long versions of division and remainder may
             * throw, but not the other types.
             */
            visitCommon(offset, length, true);
            if ((type == Type.INT) || (type == Type.LONG)) {
                visitThrowing(offset, length, true);
            }
            break;
        }
        default: {
            visitCommon(offset, length, true);
            break;
        }
    }
}
 
Example 16
Source File: BasicBlocker.java    From Box with Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
@Override
public void visitNoArgs(int opcode, int offset, int length, Type type) {
    switch (opcode) {
        case ByteOps.IRETURN:
        case ByteOps.RETURN: {
            visitCommon(offset, length, false);
            targetLists[offset] = IntList.EMPTY;
            break;
        }
        case ByteOps.ATHROW: {
            visitCommon(offset, length, false);
            visitThrowing(offset, length, false);
            break;
        }
        case ByteOps.IALOAD:
        case ByteOps.LALOAD:
        case ByteOps.FALOAD:
        case ByteOps.DALOAD:
        case ByteOps.AALOAD:
        case ByteOps.BALOAD:
        case ByteOps.CALOAD:
        case ByteOps.SALOAD:
        case ByteOps.IASTORE:
        case ByteOps.LASTORE:
        case ByteOps.FASTORE:
        case ByteOps.DASTORE:
        case ByteOps.AASTORE:
        case ByteOps.BASTORE:
        case ByteOps.CASTORE:
        case ByteOps.SASTORE:
        case ByteOps.ARRAYLENGTH:
        case ByteOps.MONITORENTER:
        case ByteOps.MONITOREXIT: {
            /*
             * These instructions can all throw, so they have to end
             * the block they appear in (since throws are branches).
             */
            visitCommon(offset, length, true);
            visitThrowing(offset, length, true);
            break;
        }
        case ByteOps.IDIV:
        case ByteOps.IREM: {
            /*
             * The int and long versions of division and remainder may
             * throw, but not the other types.
             */
            visitCommon(offset, length, true);
            if ((type == Type.INT) || (type == Type.LONG)) {
                visitThrowing(offset, length, true);
            }
            break;
        }
        default: {
            visitCommon(offset, length, true);
            break;
        }
    }
}
 
Example 17
Source File: Frame.java    From Box with Apache License 2.0 2 votes vote down vote up
/**
 * Constructs an instance.
 *
 * @param locals {@code non-null;} the locals array to use
 * @param stack {@code non-null;} the execution stack to use
 */
private Frame(LocalsArray locals, ExecutionStack stack) {
    this(locals, stack, IntList.EMPTY);
}
 
Example 18
Source File: Frame.java    From J2ME-Loader with Apache License 2.0 2 votes vote down vote up
/**
 * Constructs an instance.
 *
 * @param locals {@code non-null;} the locals array to use
 * @param stack {@code non-null;} the execution stack to use
 */
private Frame(LocalsArray locals, ExecutionStack stack) {
    this(locals, stack, IntList.EMPTY);
}
 
Example 19
Source File: Frame.java    From Box with Apache License 2.0 2 votes vote down vote up
/**
 * Constructs an instance.
 *
 * @param locals {@code non-null;} the locals array to use
 * @param stack {@code non-null;} the execution stack to use
 */
private Frame(LocalsArray locals, ExecutionStack stack) {
    this(locals, stack, IntList.EMPTY);
}
 
Example 20
Source File: Frame.java    From buck with Apache License 2.0 2 votes vote down vote up
/**
 * Constructs an instance.
 *
 * @param locals {@code non-null;} the locals array to use
 * @param stack {@code non-null;} the execution stack to use
 */
private Frame(LocalsArray locals, ExecutionStack stack) {
    this(locals, stack, IntList.EMPTY);
}