Java Code Examples for com.android.dx.rop.type.Type#BT_OBJECT

The following examples show how to use com.android.dx.rop.type.Type#BT_OBJECT . 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: EscapeAnalysis.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Process a single instruction, looking for new objects resulting from
 * move result or move param.
 *
 * @param insn {@code non-null;} instruction to process
 */
private void processInsn(SsaInsn insn) {
    int op = insn.getOpcode().getOpcode();
    RegisterSpec result = insn.getResult();
    EscapeSet escSet;

    // Identify new objects
    if (op == RegOps.MOVE_RESULT_PSEUDO &&
            result.getTypeBearer().getBasicType() == Type.BT_OBJECT) {
        // Handle objects generated through move_result_pseudo
        escSet = processMoveResultPseudoInsn(insn);
        processRegister(result, escSet);
    } else if (op == RegOps.MOVE_PARAM &&
                  result.getTypeBearer().getBasicType() == Type.BT_OBJECT) {
        // Track method arguments that are objects
        escSet = new EscapeSet(result.getReg(), regCount, EscapeState.NONE);
        latticeValues.add(escSet);
        processRegister(result, escSet);
    } else if (op == RegOps.MOVE_RESULT &&
            result.getTypeBearer().getBasicType() == Type.BT_OBJECT) {
        // Track method return values that are objects
        escSet = new EscapeSet(result.getReg(), regCount, EscapeState.NONE);
        latticeValues.add(escSet);
        processRegister(result, escSet);
    }
}
 
Example 2
Source File: Rops.java    From J2ME-Loader with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the appropriate {@code get-static} rop for the given
 * type. The result is a shared instance.
 *
 * @param type {@code non-null;} type of the field in question
 * @return {@code non-null;} an appropriate instance
 */
public static Rop opGetStatic(TypeBearer type) {
    switch (type.getBasicType()) {
        case Type.BT_INT:     return GET_STATIC_INT;
        case Type.BT_LONG:    return GET_STATIC_LONG;
        case Type.BT_FLOAT:   return GET_STATIC_FLOAT;
        case Type.BT_DOUBLE:  return GET_STATIC_DOUBLE;
        case Type.BT_OBJECT:  return GET_STATIC_OBJECT;
        case Type.BT_BOOLEAN: return GET_STATIC_BOOLEAN;
        case Type.BT_BYTE:    return GET_STATIC_BYTE;
        case Type.BT_CHAR:    return GET_STATIC_CHAR;
        case Type.BT_SHORT:   return GET_STATIC_SHORT;
    }

    return throwBadType(type);
}
 
Example 3
Source File: Rops.java    From buck with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the appropriate {@code put-field} rop for the given
 * type. The result is a shared instance.
 *
 * @param type {@code non-null;} type of the field in question
 * @return {@code non-null;} an appropriate instance
 */
public static Rop opPutField(TypeBearer type) {
    switch (type.getBasicType()) {
        case Type.BT_INT:     return PUT_FIELD_INT;
        case Type.BT_LONG:    return PUT_FIELD_LONG;
        case Type.BT_FLOAT:   return PUT_FIELD_FLOAT;
        case Type.BT_DOUBLE:  return PUT_FIELD_DOUBLE;
        case Type.BT_OBJECT:  return PUT_FIELD_OBJECT;
        case Type.BT_BOOLEAN: return PUT_FIELD_BOOLEAN;
        case Type.BT_BYTE:    return PUT_FIELD_BYTE;
        case Type.BT_CHAR:    return PUT_FIELD_CHAR;
        case Type.BT_SHORT:   return PUT_FIELD_SHORT;
    }

    return throwBadType(type);
}
 
Example 4
Source File: Rops.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the appropriate {@code const} rop for the given
 * type. The result is a shared instance.
 *
 * @param type {@code non-null;} type of the constant
 * @return {@code non-null;} an appropriate instance
 */
public static Rop opConst(TypeBearer type) {
    if (type.getType() == Type.KNOWN_NULL) {
        return CONST_OBJECT_NOTHROW;
    }

    switch (type.getBasicFrameType()) {
        case Type.BT_INT:    return CONST_INT;
        case Type.BT_LONG:   return CONST_LONG;
        case Type.BT_FLOAT:  return CONST_FLOAT;
        case Type.BT_DOUBLE: return CONST_DOUBLE;
        case Type.BT_OBJECT: return CONST_OBJECT;
    }

    return throwBadType(type);
}
 
Example 5
Source File: Rops.java    From J2ME-Loader with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the appropriate {@code const} rop for the given
 * type. The result is a shared instance.
 *
 * @param type {@code non-null;} type of the constant
 * @return {@code non-null;} an appropriate instance
 */
public static Rop opConst(TypeBearer type) {
    if (type.getType() == Type.KNOWN_NULL) {
        return CONST_OBJECT_NOTHROW;
    }

    switch (type.getBasicFrameType()) {
        case Type.BT_INT:    return CONST_INT;
        case Type.BT_LONG:   return CONST_LONG;
        case Type.BT_FLOAT:  return CONST_FLOAT;
        case Type.BT_DOUBLE: return CONST_DOUBLE;
        case Type.BT_OBJECT: return CONST_OBJECT;
    }

    return throwBadType(type);
}
 
Example 6
Source File: Rops.java    From J2ME-Loader with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the appropriate {@code put-field} rop for the given
 * type. The result is a shared instance.
 *
 * @param type {@code non-null;} type of the field in question
 * @return {@code non-null;} an appropriate instance
 */
public static Rop opPutField(TypeBearer type) {
    switch (type.getBasicType()) {
        case Type.BT_INT:     return PUT_FIELD_INT;
        case Type.BT_LONG:    return PUT_FIELD_LONG;
        case Type.BT_FLOAT:   return PUT_FIELD_FLOAT;
        case Type.BT_DOUBLE:  return PUT_FIELD_DOUBLE;
        case Type.BT_OBJECT:  return PUT_FIELD_OBJECT;
        case Type.BT_BOOLEAN: return PUT_FIELD_BOOLEAN;
        case Type.BT_BYTE:    return PUT_FIELD_BYTE;
        case Type.BT_CHAR:    return PUT_FIELD_CHAR;
        case Type.BT_SHORT:   return PUT_FIELD_SHORT;
    }

    return throwBadType(type);
}
 
Example 7
Source File: Rops.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the appropriate {@code new-array} rop for the given
 * type. The result is a shared instance.
 *
 * @param arrayType {@code non-null;} array type of array being created
 * @return {@code non-null;} an appropriate instance
 */
public static Rop opNewArray(TypeBearer arrayType) {
    Type type = arrayType.getType();
    Type elementType = type.getComponentType();

    switch (elementType.getBasicType()) {
        case Type.BT_INT:     return NEW_ARRAY_INT;
        case Type.BT_LONG:    return NEW_ARRAY_LONG;
        case Type.BT_FLOAT:   return NEW_ARRAY_FLOAT;
        case Type.BT_DOUBLE:  return NEW_ARRAY_DOUBLE;
        case Type.BT_BOOLEAN: return NEW_ARRAY_BOOLEAN;
        case Type.BT_BYTE:    return NEW_ARRAY_BYTE;
        case Type.BT_CHAR:    return NEW_ARRAY_CHAR;
        case Type.BT_SHORT:   return NEW_ARRAY_SHORT;
        case Type.BT_OBJECT: {
            return new Rop(RegOps.NEW_ARRAY, type, StdTypeList.INT,
                    Exceptions.LIST_Error_NegativeArraySizeException,
                    "new-array-object");
        }
    }

    return throwBadType(type);
}
 
Example 8
Source File: Rops.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the appropriate {@code get-field} rop for the given
 * type. The result is a shared instance.
 *
 * @param type {@code non-null;} type of the field in question
 * @return {@code non-null;} an appropriate instance
 */
public static Rop opGetField(TypeBearer type) {
    switch (type.getBasicType()) {
        case Type.BT_INT:     return GET_FIELD_INT;
        case Type.BT_LONG:    return GET_FIELD_LONG;
        case Type.BT_FLOAT:   return GET_FIELD_FLOAT;
        case Type.BT_DOUBLE:  return GET_FIELD_DOUBLE;
        case Type.BT_OBJECT:  return GET_FIELD_OBJECT;
        case Type.BT_BOOLEAN: return GET_FIELD_BOOLEAN;
        case Type.BT_BYTE:    return GET_FIELD_BYTE;
        case Type.BT_CHAR:    return GET_FIELD_CHAR;
        case Type.BT_SHORT:   return GET_FIELD_SHORT;
    }

    return throwBadType(type);
}
 
Example 9
Source File: Rops.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the appropriate {@code aget} rop for the given type. The
 * result is a shared instance.
 *
 * @param type {@code non-null;} element type of array being accessed
 * @return {@code non-null;} an appropriate instance
 */
public static Rop opAget(TypeBearer type) {
    switch (type.getBasicType()) {
        case Type.BT_INT:     return AGET_INT;
        case Type.BT_LONG:    return AGET_LONG;
        case Type.BT_FLOAT:   return AGET_FLOAT;
        case Type.BT_DOUBLE:  return AGET_DOUBLE;
        case Type.BT_OBJECT:  return AGET_OBJECT;
        case Type.BT_BOOLEAN: return AGET_BOOLEAN;
        case Type.BT_BYTE:    return AGET_BYTE;
        case Type.BT_CHAR:    return AGET_CHAR;
        case Type.BT_SHORT:   return AGET_SHORT;
    }

    return throwBadType(type);
}
 
Example 10
Source File: Rops.java    From J2ME-Loader with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the appropriate {@code get-field} rop for the given
 * type. The result is a shared instance.
 *
 * @param type {@code non-null;} type of the field in question
 * @return {@code non-null;} an appropriate instance
 */
public static Rop opGetField(TypeBearer type) {
    switch (type.getBasicType()) {
        case Type.BT_INT:     return GET_FIELD_INT;
        case Type.BT_LONG:    return GET_FIELD_LONG;
        case Type.BT_FLOAT:   return GET_FIELD_FLOAT;
        case Type.BT_DOUBLE:  return GET_FIELD_DOUBLE;
        case Type.BT_OBJECT:  return GET_FIELD_OBJECT;
        case Type.BT_BOOLEAN: return GET_FIELD_BOOLEAN;
        case Type.BT_BYTE:    return GET_FIELD_BYTE;
        case Type.BT_CHAR:    return GET_FIELD_CHAR;
        case Type.BT_SHORT:   return GET_FIELD_SHORT;
    }

    return throwBadType(type);
}
 
Example 11
Source File: Zeroes.java    From J2ME-Loader with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the "zero" (or {@code null}) value for the given type.
 *
 * @param type {@code non-null;} the type in question
 * @return {@code non-null;} its "zero" value
 */
public static Constant zeroFor(Type type) {
    switch (type.getBasicType()) {
        case Type.BT_BOOLEAN: return CstBoolean.VALUE_FALSE;
        case Type.BT_BYTE:    return CstByte.VALUE_0;
        case Type.BT_CHAR:    return CstChar.VALUE_0;
        case Type.BT_DOUBLE:  return CstDouble.VALUE_0;
        case Type.BT_FLOAT:   return CstFloat.VALUE_0;
        case Type.BT_INT:     return CstInteger.VALUE_0;
        case Type.BT_LONG:    return CstLong.VALUE_0;
        case Type.BT_SHORT:   return CstShort.VALUE_0;
        case Type.BT_OBJECT:  return CstKnownNull.THE_ONE;
        default: {
            throw new UnsupportedOperationException("no zero for type: " +
                    type.toHuman());
        }
    }
}
 
Example 12
Source File: Rops.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the appropriate {@code mark-local} rop for the given type.
 * The result is a shared instance.
 *
 * @param type {@code non-null;} type of value being marked
 * @return {@code non-null;} an appropriate instance
 */
public static Rop opMarkLocal(TypeBearer type) {
    switch (type.getBasicFrameType()) {
        case Type.BT_INT:    return MARK_LOCAL_INT;
        case Type.BT_LONG:   return MARK_LOCAL_LONG;
        case Type.BT_FLOAT:  return MARK_LOCAL_FLOAT;
        case Type.BT_DOUBLE: return MARK_LOCAL_DOUBLE;
        case Type.BT_OBJECT: return MARK_LOCAL_OBJECT;
    }

    return throwBadType(type);
}
 
Example 13
Source File: Rops.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the appropriate {@code return} rop for the given type. The
 * result is a shared instance.
 *
 * @param type {@code non-null;} type of value being returned
 * @return {@code non-null;} an appropriate instance
 */
public static Rop opReturn(TypeBearer type) {
    switch (type.getBasicFrameType()) {
        case Type.BT_INT:    return RETURN_INT;
        case Type.BT_LONG:   return RETURN_LONG;
        case Type.BT_FLOAT:  return RETURN_FLOAT;
        case Type.BT_DOUBLE: return RETURN_DOUBLE;
        case Type.BT_OBJECT: return RETURN_OBJECT;
        case Type.BT_VOID:   return RETURN_VOID;
    }

    return throwBadType(type);
}
 
Example 14
Source File: Rops.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the appropriate {@code move} rop for the given type. The
 * result is a shared instance.
 *
 * @param type {@code non-null;} type of value being moved
 * @return {@code non-null;} an appropriate instance
 */
public static Rop opMove(TypeBearer type) {
    switch (type.getBasicFrameType()) {
        case Type.BT_INT:    return MOVE_INT;
        case Type.BT_LONG:   return MOVE_LONG;
        case Type.BT_FLOAT:  return MOVE_FLOAT;
        case Type.BT_DOUBLE: return MOVE_DOUBLE;
        case Type.BT_OBJECT: return MOVE_OBJECT;
        case Type.BT_ADDR:   return MOVE_RETURN_ADDRESS;
    }

    return throwBadType(type);
}
 
Example 15
Source File: Rops.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the appropriate {@code move-param} rop for the
 * given type. The result is a shared instance.
 *
 * @param type {@code non-null;} type of value being moved
 * @return {@code non-null;} an appropriate instance
 */
public static Rop opMoveParam(TypeBearer type) {
    switch (type.getBasicFrameType()) {
        case Type.BT_INT:    return MOVE_PARAM_INT;
        case Type.BT_LONG:   return MOVE_PARAM_LONG;
        case Type.BT_FLOAT:  return MOVE_PARAM_FLOAT;
        case Type.BT_DOUBLE: return MOVE_PARAM_DOUBLE;
        case Type.BT_OBJECT: return MOVE_PARAM_OBJECT;
    }

    return throwBadType(type);
}
 
Example 16
Source File: Rops.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Helper for all the {@code if*}-related methods, which
 * checks types and picks one of the four variants, throwing if
 * there's a problem.
 *
 * @param types {@code non-null;} the types
 * @param intZ {@code non-null;} the int-to-0 comparison
 * @param objZ {@code null-ok;} the object-to-null comparison
 * @param intInt {@code non-null;} the int-to-int comparison
 * @param objObj {@code non-null;} the object-to-object comparison
 * @return {@code non-null;} the appropriate instance
 */
private static Rop pickIf(TypeList types, Rop intZ, Rop objZ, Rop intInt,
                          Rop objObj) {
    switch(types.size()) {
        case 1: {
            switch (types.getType(0).getBasicFrameType()) {
                case Type.BT_INT: {
                    return intZ;
                }
                case Type.BT_OBJECT: {
                    if (objZ != null) {
                        return objZ;
                    }
                }
            }
            break;
        }
        case 2: {
            int bt = types.getType(0).getBasicFrameType();
            if (bt == types.getType(1).getBasicFrameType()) {
                switch (bt) {
                    case Type.BT_INT: {
                        return intInt;
                    }
                    case Type.BT_OBJECT: {
                        if (objObj != null) {
                            return objObj;
                        }
                    }
                }
            }
            break;
        }
    }

    return throwBadTypes(types);
}
 
Example 17
Source File: Rops.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the appropriate {@code move-param} rop for the
 * given type. The result is a shared instance.
 *
 * @param type {@code non-null;} type of value being moved
 * @return {@code non-null;} an appropriate instance
 */
public static Rop opMoveParam(TypeBearer type) {
    switch (type.getBasicFrameType()) {
        case Type.BT_INT:    return MOVE_PARAM_INT;
        case Type.BT_LONG:   return MOVE_PARAM_LONG;
        case Type.BT_FLOAT:  return MOVE_PARAM_FLOAT;
        case Type.BT_DOUBLE: return MOVE_PARAM_DOUBLE;
        case Type.BT_OBJECT: return MOVE_PARAM_OBJECT;
    }

    return throwBadType(type);
}
 
Example 18
Source File: Rops.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the appropriate {@code move} rop for the given type. The
 * result is a shared instance.
 *
 * @param type {@code non-null;} type of value being moved
 * @return {@code non-null;} an appropriate instance
 */
public static Rop opMove(TypeBearer type) {
    switch (type.getBasicFrameType()) {
        case Type.BT_INT:    return MOVE_INT;
        case Type.BT_LONG:   return MOVE_LONG;
        case Type.BT_FLOAT:  return MOVE_FLOAT;
        case Type.BT_DOUBLE: return MOVE_DOUBLE;
        case Type.BT_OBJECT: return MOVE_OBJECT;
        case Type.BT_ADDR:   return MOVE_RETURN_ADDRESS;
    }

    return throwBadType(type);
}
 
Example 19
Source File: Merger.java    From Box with Apache License 2.0 4 votes vote down vote up
/**
 * Returns whether the given supertype is possibly assignable from
 * the given subtype. This takes into account primitiveness,
 * int-likeness, known-nullness, and array dimensions, but does
 * not assume anything about class hierarchy other than that the
 * type {@code Object} is the supertype of all reference
 * types and all arrays are assignable to
 * {@code Serializable} and {@code Cloneable}.
 *
 * @param supertypeBearer {@code non-null;} the supertype
 * @param subtypeBearer {@code non-null;} the subtype
 */
public static boolean isPossiblyAssignableFrom(TypeBearer supertypeBearer,
        TypeBearer subtypeBearer) {
    Type supertype = supertypeBearer.getType();
    Type subtype = subtypeBearer.getType();

    if (supertype.equals(subtype)) {
        // Easy out.
        return true;
    }

    int superBt = supertype.getBasicType();
    int subBt = subtype.getBasicType();

    // Treat return types as Object for the purposes of this method.

    if (superBt == Type.BT_ADDR) {
        supertype = Type.OBJECT;
        superBt = Type.BT_OBJECT;
    }

    if (subBt == Type.BT_ADDR) {
        subtype = Type.OBJECT;
        subBt = Type.BT_OBJECT;
    }

    if ((superBt != Type.BT_OBJECT) || (subBt != Type.BT_OBJECT)) {
        /*
         * No two distinct primitive types are assignable in this sense,
         * unless they are both int-like.
         */
        return supertype.isIntlike() && subtype.isIntlike();
    }

    // At this point, we know both types are reference types.

    if (supertype == Type.KNOWN_NULL) {
        /*
         * A known-null supertype is only assignable from another
         * known-null (handled in the easy out at the top of the
         * method).
         */
        return false;
    } else if (subtype == Type.KNOWN_NULL) {
        /*
         * A known-null subtype is in fact assignable to any
         * reference type.
         */
        return true;
    } else if (supertype == Type.OBJECT) {
        /*
         * Object is assignable from any reference type.
         */
        return true;
    } else if (supertype.isArray()) {
        // The supertype is an array type.
        if (! subtype.isArray()) {
            // The subtype isn't an array, and so can't be assignable.
            return false;
        }

        /*
         * Strip off as many matched component types from both
         * types as possible, and check the assignability of the
         * results.
         */
        do {
            supertype = supertype.getComponentType();
            subtype = subtype.getComponentType();
        } while (supertype.isArray() && subtype.isArray());

        return isPossiblyAssignableFrom(supertype, subtype);
    } else if (subtype.isArray()) {
        /*
         * Other than Object (handled above), array types are
         * assignable only to Serializable and Cloneable.
         */
        return (supertype == Type.SERIALIZABLE) ||
            (supertype == Type.CLONEABLE);
    } else {
        /*
         * All other unequal reference types are considered at
         * least possibly assignable.
         */
        return true;
    }
}
 
Example 20
Source File: Merger.java    From J2ME-Loader with Apache License 2.0 4 votes vote down vote up
/**
 * Returns whether the given supertype is possibly assignable from
 * the given subtype. This takes into account primitiveness,
 * int-likeness, known-nullness, and array dimensions, but does
 * not assume anything about class hierarchy other than that the
 * type {@code Object} is the supertype of all reference
 * types and all arrays are assignable to
 * {@code Serializable} and {@code Cloneable}.
 *
 * @param supertypeBearer {@code non-null;} the supertype
 * @param subtypeBearer {@code non-null;} the subtype
 */
public static boolean isPossiblyAssignableFrom(TypeBearer supertypeBearer,
        TypeBearer subtypeBearer) {
    Type supertype = supertypeBearer.getType();
    Type subtype = subtypeBearer.getType();

    if (supertype.equals(subtype)) {
        // Easy out.
        return true;
    }

    int superBt = supertype.getBasicType();
    int subBt = subtype.getBasicType();

    // Treat return types as Object for the purposes of this method.

    if (superBt == Type.BT_ADDR) {
        supertype = Type.OBJECT;
        superBt = Type.BT_OBJECT;
    }

    if (subBt == Type.BT_ADDR) {
        subtype = Type.OBJECT;
        subBt = Type.BT_OBJECT;
    }

    if ((superBt != Type.BT_OBJECT) || (subBt != Type.BT_OBJECT)) {
        /*
         * No two distinct primitive types are assignable in this sense,
         * unless they are both int-like.
         */
        return supertype.isIntlike() && subtype.isIntlike();
    }

    // At this point, we know both types are reference types.

    if (supertype == Type.KNOWN_NULL) {
        /*
         * A known-null supertype is only assignable from another
         * known-null (handled in the easy out at the top of the
         * method).
         */
        return false;
    } else if (subtype == Type.KNOWN_NULL) {
        /*
         * A known-null subtype is in fact assignable to any
         * reference type.
         */
        return true;
    } else if (supertype == Type.OBJECT) {
        /*
         * Object is assignable from any reference type.
         */
        return true;
    } else if (supertype.isArray()) {
        // The supertype is an array type.
        if (! subtype.isArray()) {
            // The subtype isn't an array, and so can't be assignable.
            return false;
        }

        /*
         * Strip off as many matched component types from both
         * types as possible, and check the assignability of the
         * results.
         */
        do {
            supertype = supertype.getComponentType();
            subtype = subtype.getComponentType();
        } while (supertype.isArray() && subtype.isArray());

        return isPossiblyAssignableFrom(supertype, subtype);
    } else if (subtype.isArray()) {
        /*
         * Other than Object (handled above), array types are
         * assignable only to Serializable and Cloneable.
         */
        return (supertype == Type.SERIALIZABLE) ||
            (supertype == Type.CLONEABLE);
    } else {
        /*
         * All other unequal reference types are considered at
         * least possibly assignable.
         */
        return true;
    }
}