Search in sources :

Example 1 with CstBaseMethodRef

use of com.android.dx.rop.cst.CstBaseMethodRef in project buck by facebook.

the class DalvInsnList method getOutsSize.

/**
     * Gets the size of the outgoing arguments area required by this
     * method. This is equal to the largest argument word count of any
     * method referred to by this instance.
     *
     * @return {@code >= 0;} the required outgoing arguments size
     */
public int getOutsSize() {
    int sz = size();
    int result = 0;
    for (int i = 0; i < sz; i++) {
        DalvInsn insn = (DalvInsn) get0(i);
        if (!(insn instanceof CstInsn)) {
            continue;
        }
        Constant cst = ((CstInsn) insn).getConstant();
        if (!(cst instanceof CstBaseMethodRef)) {
            continue;
        }
        boolean isStatic = (insn.getOpcode().getFamily() == Opcodes.INVOKE_STATIC);
        int count = ((CstBaseMethodRef) cst).getParameterWordCount(isStatic);
        if (count > result) {
            result = count;
        }
    }
    return result;
}
Also used : CstBaseMethodRef(com.android.dx.rop.cst.CstBaseMethodRef) Constant(com.android.dx.rop.cst.Constant)

Example 2 with CstBaseMethodRef

use of com.android.dx.rop.cst.CstBaseMethodRef in project RocooFix by dodola.

the class ClassReferenceListBuilder method addDependencies.

private void addDependencies(DirectClassFile classFile) {
    for (Constant constant : classFile.getConstantPool().getEntries()) {
        if (constant instanceof CstType) {
            checkDescriptor(((CstType) constant).getClassType().getDescriptor());
        } else if (constant instanceof CstFieldRef) {
            checkDescriptor(((CstFieldRef) constant).getType().getDescriptor());
        } else if (constant instanceof CstBaseMethodRef) {
            checkPrototype(((CstBaseMethodRef) constant).getPrototype());
        }
    }
    FieldList fields = classFile.getFields();
    int nbField = fields.size();
    for (int i = 0; i < nbField; i++) {
        checkDescriptor(fields.get(i).getDescriptor().getString());
    }
    MethodList methods = classFile.getMethods();
    int nbMethods = methods.size();
    for (int i = 0; i < nbMethods; i++) {
        checkPrototype(Prototype.intern(methods.get(i).getDescriptor().getString()));
    }
}
Also used : CstBaseMethodRef(com.android.dx.rop.cst.CstBaseMethodRef) Constant(com.android.dx.rop.cst.Constant) CstType(com.android.dx.rop.cst.CstType) CstFieldRef(com.android.dx.rop.cst.CstFieldRef) MethodList(com.android.dx.cf.iface.MethodList) FieldList(com.android.dx.cf.iface.FieldList)

Example 3 with CstBaseMethodRef

use of com.android.dx.rop.cst.CstBaseMethodRef in project J2ME-Loader by nikita36078.

the class DalvInsnList method getOutsSize.

/**
 * Gets the size of the outgoing arguments area required by this
 * method. This is equal to the largest argument word count of any
 * method referred to by this instance.
 *
 * @return {@code >= 0;} the required outgoing arguments size
 */
public int getOutsSize() {
    int sz = size();
    int result = 0;
    for (int i = 0; i < sz; i++) {
        DalvInsn insn = (DalvInsn) get0(i);
        int count = 0;
        if (insn instanceof CstInsn) {
            Constant cst = ((CstInsn) insn).getConstant();
            if (cst instanceof CstBaseMethodRef) {
                CstBaseMethodRef methodRef = (CstBaseMethodRef) cst;
                boolean isStatic = (insn.getOpcode().getFamily() == Opcodes.INVOKE_STATIC);
                count = methodRef.getParameterWordCount(isStatic);
            }
        } else if (insn instanceof MultiCstInsn) {
            if (insn.getOpcode().getFamily() != Opcodes.INVOKE_POLYMORPHIC) {
                throw new RuntimeException("Expecting invoke-polymorphic");
            }
            MultiCstInsn mci = (MultiCstInsn) insn;
            // Invoke-polymorphic has two constants: [0] method-ref and
            // [1] call site prototype. The number of arguments is based
            // on the call site prototype since these are the arguments
            // presented. The method-ref is always MethodHandle.invoke(Object[])
            // or MethodHandle.invokeExact(Object[]).
            CstProtoRef proto = (CstProtoRef) mci.getConstant(1);
            count = proto.getPrototype().getParameterTypes().getWordCount();
            // And one for receiver (method handle).
            count = count + 1;
        } else {
            continue;
        }
        if (count > result) {
            result = count;
        }
    }
    return result;
}
Also used : CstProtoRef(com.android.dx.rop.cst.CstProtoRef) CstBaseMethodRef(com.android.dx.rop.cst.CstBaseMethodRef) Constant(com.android.dx.rop.cst.Constant)

Aggregations

Constant (com.android.dx.rop.cst.Constant)3 CstBaseMethodRef (com.android.dx.rop.cst.CstBaseMethodRef)3 FieldList (com.android.dx.cf.iface.FieldList)1 MethodList (com.android.dx.cf.iface.MethodList)1 CstFieldRef (com.android.dx.rop.cst.CstFieldRef)1 CstProtoRef (com.android.dx.rop.cst.CstProtoRef)1 CstType (com.android.dx.rop.cst.CstType)1