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;
}
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);
}
}
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);
}
}
Aggregations