Search in sources :

Example 1 with ConstantMethodHandle

use of org.apache.bcel.classfile.ConstantMethodHandle in project fb-contrib by mebigfatguy.

the class FunctionalInterfaceIssues method getMethodHandle.

private ConstantMethodHandle getMethodHandle(int bootstrapIndex) {
    int offset = bootstrapIndex * 6;
    byte[] attBytes = ((Unknown) bootstrapAtt).getBytes();
    int methodRefIndex = CodeByteUtils.getshort(attBytes, offset += 2);
    int numArgs = CodeByteUtils.getshort(attBytes, offset += 2);
    for (int i = 0; i < numArgs; i++) {
        int arg = CodeByteUtils.getshort(attBytes, offset += 2);
        Constant c = getConstantPool().getConstant(arg);
        if (c instanceof ConstantMethodHandle) {
            return (ConstantMethodHandle) c;
        }
    }
    return null;
}
Also used : Unknown(org.apache.bcel.classfile.Unknown) Constant(org.apache.bcel.classfile.Constant) ConstantMethodHandle(org.apache.bcel.classfile.ConstantMethodHandle)

Example 2 with ConstantMethodHandle

use of org.apache.bcel.classfile.ConstantMethodHandle in project fb-contrib by mebigfatguy.

the class FunctionalInterfaceIssues method sawOpcode.

@Override
public void sawOpcode(int seen) {
    try {
        switch(seen) {
            case Const.INVOKEDYNAMIC:
                List<FIInfo> fiis = functionalInterfaceInfo.get(getMethod());
                if (fiis == null) {
                    fiis = new ArrayList<>();
                    functionalInterfaceInfo.put(getMethod(), fiis);
                }
                ConstantInvokeDynamic cid = (ConstantInvokeDynamic) getConstantRefOperand();
                ConstantMethodHandle cmh = getMethodHandle(cid.getBootstrapMethodAttrIndex());
                FIInfo fii = new FIInfo(getPC(), cid.getBootstrapMethodAttrIndex());
                fiis.add(fii);
                break;
        }
    } finally {
        stack.sawOpcode(this, seen);
    }
}
Also used : ConstantInvokeDynamic(org.apache.bcel.classfile.ConstantInvokeDynamic) ConstantMethodHandle(org.apache.bcel.classfile.ConstantMethodHandle)

Example 3 with ConstantMethodHandle

use of org.apache.bcel.classfile.ConstantMethodHandle in project fb-contrib by mebigfatguy.

the class OverlyPermissiveMethod method sawOpcode.

@Override
public void sawOpcode(int seen) {
    try {
        stack.precomputation(this);
        switch(seen) {
            case Const.INVOKEVIRTUAL:
            case Const.INVOKEINTERFACE:
            case Const.INVOKESTATIC:
            case Const.INVOKESPECIAL:
                {
                    String calledClass = getClassConstantOperand();
                    String sig = getSigConstantOperand();
                    MethodInfo mi = Statistics.getStatistics().getMethodStatistics(calledClass, getNameConstantOperand(), sig);
                    if (mi != null) {
                        if (seen == Const.INVOKEINTERFACE) {
                            mi.addCallingAccess(Const.ACC_PUBLIC);
                        } else {
                            String calledPackage;
                            int slashPos = calledClass.lastIndexOf('/');
                            if (slashPos >= 0) {
                                calledPackage = calledClass.substring(0, slashPos);
                            } else {
                                calledPackage = "";
                            }
                            boolean sameClass = calledClass.equals(callingClass);
                            boolean samePackage = calledPackage.equals(callingPackage);
                            if (sameClass) {
                                mi.addCallingAccess(Const.ACC_PRIVATE);
                            } else if (samePackage) {
                                mi.addCallingAccess(0);
                            } else {
                                if (seen == Const.INVOKESTATIC) {
                                    mi.addCallingAccess(Const.ACC_PUBLIC);
                                } else if (isCallingOnThis(sig)) {
                                    mi.addCallingAccess(Const.ACC_PROTECTED);
                                } else {
                                    mi.addCallingAccess(Const.ACC_PUBLIC);
                                }
                            }
                        }
                    }
                }
                break;
            case Const.INVOKEDYNAMIC:
                ConstantInvokeDynamic id = (ConstantInvokeDynamic) getConstantRefOperand();
                BootstrapMethod bm = getBootstrapMethod(id.getBootstrapMethodAttrIndex());
                if (bm != null) {
                    ConstantPool pool = getConstantPool();
                    ConstantMethodHandle mh = getFirstMethodHandle(pool, bm);
                    if (mh != null) {
                        ConstantCP ref = (ConstantCP) pool.getConstant(mh.getReferenceIndex());
                        ConstantClass cc = (ConstantClass) pool.getConstant(ref.getClassIndex());
                        String clz = ((ConstantUtf8) pool.getConstant(cc.getNameIndex())).getBytes();
                        ConstantNameAndType nameAndType = (ConstantNameAndType) pool.getConstant(ref.getNameAndTypeIndex());
                        String sig = ((ConstantUtf8) pool.getConstant(nameAndType.getSignatureIndex())).getBytes();
                        String name = ((ConstantUtf8) pool.getConstant(nameAndType.getNameIndex())).getBytes();
                        MethodInfo mi = Statistics.getStatistics().getMethodStatistics(clz, name, sig);
                        mi.addCallingAccess(Const.ACC_PUBLIC);
                    }
                }
                break;
            default:
                break;
        }
    } finally {
        stack.sawOpcode(this, seen);
    }
}
Also used : BootstrapMethod(org.apache.bcel.classfile.BootstrapMethod) ConstantPool(org.apache.bcel.classfile.ConstantPool) ConstantInvokeDynamic(org.apache.bcel.classfile.ConstantInvokeDynamic) MethodInfo(com.mebigfatguy.fbcontrib.collect.MethodInfo) ConstantMethodHandle(org.apache.bcel.classfile.ConstantMethodHandle) ConstantUtf8(org.apache.bcel.classfile.ConstantUtf8) ConstantCP(org.apache.bcel.classfile.ConstantCP) ConstantClass(org.apache.bcel.classfile.ConstantClass) ConstantNameAndType(org.apache.bcel.classfile.ConstantNameAndType)

Aggregations

ConstantMethodHandle (org.apache.bcel.classfile.ConstantMethodHandle)3 ConstantInvokeDynamic (org.apache.bcel.classfile.ConstantInvokeDynamic)2 MethodInfo (com.mebigfatguy.fbcontrib.collect.MethodInfo)1 BootstrapMethod (org.apache.bcel.classfile.BootstrapMethod)1 Constant (org.apache.bcel.classfile.Constant)1 ConstantCP (org.apache.bcel.classfile.ConstantCP)1 ConstantClass (org.apache.bcel.classfile.ConstantClass)1 ConstantNameAndType (org.apache.bcel.classfile.ConstantNameAndType)1 ConstantPool (org.apache.bcel.classfile.ConstantPool)1 ConstantUtf8 (org.apache.bcel.classfile.ConstantUtf8)1 Unknown (org.apache.bcel.classfile.Unknown)1