Search in sources :

Example 11 with Type

use of com.taobao.android.dx.rop.type.Type in project atlas by alibaba.

the class ClassReferenceListBuilder method addDependencies.

private void addDependencies(ConstantPool pool) {
    for (Constant constant : pool.getEntries()) {
        if (constant instanceof CstType) {
            Type type = ((CstType) constant).getClassType();
            String descriptor = type.getDescriptor();
            if (descriptor.endsWith(";")) {
                int lastBrace = descriptor.lastIndexOf('[');
                if (lastBrace < 0) {
                    addClassWithHierachy(descriptor.substring(1, descriptor.length() - 1));
                } else {
                    assert descriptor.length() > lastBrace + 3 && descriptor.charAt(lastBrace + 1) == 'L';
                    addClassWithHierachy(descriptor.substring(lastBrace + 2, descriptor.length() - 1));
                }
            }
        }
    }
}
Also used : CstType(com.taobao.android.dx.rop.cst.CstType) Type(com.taobao.android.dx.rop.type.Type) Constant(com.taobao.android.dx.rop.cst.Constant) CstType(com.taobao.android.dx.rop.cst.CstType)

Example 12 with Type

use of com.taobao.android.dx.rop.type.Type in project atlas by alibaba.

the class EscapeAnalysis method replaceDef.

/**
     * Replaces the instructions that define an array with equivalent registers.
     * For each entry in the array, a register is created, initialized to zero.
     * A mapping between this register and the corresponding array index is
     * added.
     *
     * @param def {@code non-null;} move result instruction for array
     * @param prev {@code non-null;} instruction for instantiating new array
     * @param length size of the new array
     * @param newRegs {@code non-null;} mapping of array indices to new
     * registers to be populated
     */
private void replaceDef(SsaInsn def, SsaInsn prev, int length, ArrayList<RegisterSpec> newRegs) {
    Type resultType = def.getResult().getType();
    // Create new zeroed out registers for each element in the array
    for (int i = 0; i < length; i++) {
        Constant newZero = Zeroes.zeroFor(resultType.getComponentType());
        TypedConstant typedZero = (TypedConstant) newZero;
        RegisterSpec newReg = RegisterSpec.make(ssaMeth.makeNewSsaReg(), typedZero);
        newRegs.add(newReg);
        insertPlainInsnBefore(def, RegisterSpecList.EMPTY, newReg, RegOps.CONST, newZero);
    }
}
Also used : CstType(com.taobao.android.dx.rop.cst.CstType) Type(com.taobao.android.dx.rop.type.Type) TypedConstant(com.taobao.android.dx.rop.cst.TypedConstant) Constant(com.taobao.android.dx.rop.cst.Constant) TypedConstant(com.taobao.android.dx.rop.cst.TypedConstant) RegisterSpec(com.taobao.android.dx.rop.code.RegisterSpec)

Example 13 with Type

use of com.taobao.android.dx.rop.type.Type in project atlas by alibaba.

the class PhiTypeResolver method resolveResultType.

/**
     * Resolves the result of a phi insn based on its operands. The "void"
     * type, which is a nonsensical type for a register, is used for
     * registers defined by as-of-yet-unresolved phi operations.
     *
     * @return true if the result type changed, false if no change
     */
boolean resolveResultType(PhiInsn insn) {
    insn.updateSourcesToDefinitions(ssaMeth);
    RegisterSpecList sources = insn.getSources();
    // Start by finding the first non-void operand
    RegisterSpec first = null;
    int firstIndex = -1;
    int szSources = sources.size();
    for (int i = 0; i < szSources; i++) {
        RegisterSpec rs = sources.get(i);
        if (rs.getBasicType() != Type.BT_VOID) {
            first = rs;
            firstIndex = i;
        }
    }
    if (first == null) {
        // All operands are void -- we're not ready to resolve yet
        return false;
    }
    LocalItem firstLocal = first.getLocalItem();
    Type mergedType = first.getType();
    boolean sameLocals = true;
    for (int i = 0; i < szSources; i++) {
        if (i == firstIndex) {
            continue;
        }
        RegisterSpec rs = sources.get(i);
        // Just skip void (unresolved phi results) for now
        if (rs.getBasicType() == Type.BT_VOID) {
            continue;
        }
        sameLocals = sameLocals && equalsHandlesNulls(firstLocal, rs.getLocalItem());
        mergedType = (Type) Merger.mergeType(mergedType, rs.getType());
    }
    Type newResultType;
    if (mergedType != null) {
        newResultType = mergedType;
    } else {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < szSources; i++) {
            sb.append(sources.get(i).toString());
            sb.append(' ');
        }
        throw new RuntimeException("Couldn't map types in phi insn:" + sb);
    }
    LocalItem newLocal = sameLocals ? firstLocal : null;
    RegisterSpec result = insn.getResult();
    if ((result.getTypeBearer() == newResultType) && equalsHandlesNulls(newLocal, result.getLocalItem())) {
        return false;
    }
    insn.changeResultType(newResultType, newLocal);
    return true;
}
Also used : Type(com.taobao.android.dx.rop.type.Type) LocalItem(com.taobao.android.dx.rop.code.LocalItem) RegisterSpecList(com.taobao.android.dx.rop.code.RegisterSpecList) RegisterSpec(com.taobao.android.dx.rop.code.RegisterSpec)

Example 14 with Type

use of com.taobao.android.dx.rop.type.Type in project atlas by alibaba.

the class Merger method isPossiblyAssignableFrom.

/**
     * 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();
    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();
    }
    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;
    }
}
Also used : Type(com.taobao.android.dx.rop.type.Type)

Example 15 with Type

use of com.taobao.android.dx.rop.type.Type in project atlas by alibaba.

the class OneLocalsArray method makeInitialized.

/** @inheritDoc */
public void makeInitialized(Type type) {
    int len = locals.length;
    if (len == 0) {
        // We have to check for this before checking for immutability.
        return;
    }
    throwIfImmutable();
    Type initializedType = type.getInitializedType();
    for (int i = 0; i < len; i++) {
        if (locals[i] == type) {
            locals[i] = initializedType;
        }
    }
}
Also used : Type(com.taobao.android.dx.rop.type.Type)

Aggregations

Type (com.taobao.android.dx.rop.type.Type)33 CstType (com.taobao.android.dx.rop.cst.CstType)19 Constant (com.taobao.android.dx.rop.cst.Constant)5 StdTypeList (com.taobao.android.dx.rop.type.StdTypeList)5 TypeBearer (com.taobao.android.dx.rop.type.TypeBearer)5 RegisterSpec (com.taobao.android.dx.rop.code.RegisterSpec)4 CstString (com.taobao.android.dx.rop.cst.CstString)4 TypeList (com.taobao.android.dx.rop.type.TypeList)3 BasicBlock (com.taobao.android.dx.rop.code.BasicBlock)2 Insn (com.taobao.android.dx.rop.code.Insn)2 LocalItem (com.taobao.android.dx.rop.code.LocalItem)2 PlainCstInsn (com.taobao.android.dx.rop.code.PlainCstInsn)2 PlainInsn (com.taobao.android.dx.rop.code.PlainInsn)2 RegisterSpecList (com.taobao.android.dx.rop.code.RegisterSpecList)2 SourcePosition (com.taobao.android.dx.rop.code.SourcePosition)2 ThrowingCstInsn (com.taobao.android.dx.rop.code.ThrowingCstInsn)2 ThrowingInsn (com.taobao.android.dx.rop.code.ThrowingInsn)2 CstInteger (com.taobao.android.dx.rop.cst.CstInteger)2 ByteArrayByteInput (com.taobao.android.dex.util.ByteArrayByteInput)1 ByteInput (com.taobao.android.dex.util.ByteInput)1