use of org.objectweb.asm.tree.InvokeDynamicInsnNode in project robolectric by robolectric.
the class ClassInstrumentor method interceptInvokeVirtualMethod.
/**
* Decides to call through the appropriate method to intercept the method with an INVOKEVIRTUAL
* Opcode, depending if the invokedynamic bytecode instruction is available (Java 7+).
*/
protected void interceptInvokeVirtualMethod(MutableClass mutableClass, ListIterator<AbstractInsnNode> instructions, MethodInsnNode targetMethod) {
// remove the method invocation
instructions.remove();
Type type = Type.getObjectType(targetMethod.owner);
String description = targetMethod.desc;
String owner = type.getClassName();
if (targetMethod.getOpcode() != Opcodes.INVOKESTATIC) {
String thisType = type.getDescriptor();
description = "(" + thisType + description.substring(1);
}
instructions.add(new InvokeDynamicInsnNode(targetMethod.name, description, BOOTSTRAP_INTRINSIC, owner));
}
use of org.objectweb.asm.tree.InvokeDynamicInsnNode in project spring-loaded by spring-projects.
the class TypeDiffComputer method sameInvokeDynamicInsnNode.
private static boolean sameInvokeDynamicInsnNode(AbstractInsnNode o, AbstractInsnNode n) {
InvokeDynamicInsnNode oi = (InvokeDynamicInsnNode) o;
if (!(n instanceof InvokeDynamicInsnNode)) {
return false;
}
InvokeDynamicInsnNode ni = (InvokeDynamicInsnNode) n;
if (!oi.name.equals(ni.name) || !oi.desc.equals(ni.desc)) {
return false;
}
if (!sameBsm(oi.bsm, ni.bsm)) {
return false;
}
Object[] oArgs = oi.bsmArgs;
Object[] nArgs = ni.bsmArgs;
if ((oArgs == null && nArgs != null) || (nArgs == null && oArgs != null)) {
return false;
}
if (oArgs.length != nArgs.length) {
return false;
}
for (int i = 0; i < oArgs.length; i++) {
if (!oArgs[i].equals(nArgs[i])) {
return false;
}
}
return true;
}
use of org.objectweb.asm.tree.InvokeDynamicInsnNode in project quasar by puniverse.
the class InstrumentMethod method isSuspendableCall.
private static boolean isSuspendableCall(MethodDatabase db, AbstractInsnNode in) {
final int type = in.getType();
String owner;
String name;
String desc;
if (type == AbstractInsnNode.METHOD_INSN) {
final MethodInsnNode min = (MethodInsnNode) in;
owner = min.owner;
name = min.name;
desc = min.desc;
} else if (type == AbstractInsnNode.INVOKE_DYNAMIC_INSN) {
// invoke dynamic
final InvokeDynamicInsnNode idd = (InvokeDynamicInsnNode) in;
owner = idd.bsm.getOwner();
name = idd.name;
desc = idd.desc;
} else {
throw new RuntimeException("Not a call: " + in);
}
return isSuspendableCall(db, type, in.getOpcode(), owner, name, desc);
}
use of org.objectweb.asm.tree.InvokeDynamicInsnNode in project quasar by puniverse.
the class InstrumentMethod method collectCodeBlocks.
private void collectCodeBlocks() {
final int numIns = mn.instructions.size();
codeBlocks[0] = FrameInfo.FIRST;
for (int i = 0; i < numIns; i++) {
final Frame f = frames[i];
if (f != null) {
// reachable ?
final AbstractInsnNode in = mn.instructions.get(i);
if (in.getType() == AbstractInsnNode.METHOD_INSN || in.getType() == AbstractInsnNode.INVOKE_DYNAMIC_INSN) {
boolean susp = true;
if (in.getType() == AbstractInsnNode.METHOD_INSN) {
final MethodInsnNode min = (MethodInsnNode) in;
int opcode = min.getOpcode();
if (isSyntheticAccess(min.owner, min.name))
db.log(LogLevel.DEBUG, "Synthetic accessor method call at instruction %d is assumed suspendable", i);
else if (isReflectInvocation(min.owner, min.name))
db.log(LogLevel.DEBUG, "Reflective method call at instruction %d is assumed suspendable", i);
else if (isMethodHandleInvocation(min.owner, min.name))
db.log(LogLevel.DEBUG, "MethodHandle invocation at instruction %d is assumed suspendable", i);
else if (isInvocationHandlerInvocation(min.owner, min.name))
db.log(LogLevel.DEBUG, "InvocationHandler invocation at instruction %d is assumed suspendable", i);
else {
SuspendableType st = db.isMethodSuspendable(min.owner, min.name, min.desc, opcode);
if (st == SuspendableType.NON_SUSPENDABLE) {
susp = false;
} else if (st == null) {
db.log(LogLevel.WARNING, "Method not found in class - assuming suspendable: %s#%s%s (at %s:%s#%s)", min.owner, min.name, min.desc, sourceName, className, mn.name);
susp = true;
} else if (st != SuspendableType.SUSPENDABLE_SUPER) {
db.log(LogLevel.DEBUG, "Method call at instruction %d to %s#%s%s is suspendable", i, min.owner, min.name, min.desc);
}
if (st == SuspendableType.SUSPENDABLE_SUPER) {
db.log(LogLevel.DEBUG, "Method call at instruction %d to %s#%s%s to suspendable-super (instrumentation for proxy support will be enabled)", i, min.owner, min.name, min.desc);
this.callsSuspendableSupers = true;
}
}
} else if (in.getType() == AbstractInsnNode.INVOKE_DYNAMIC_INSN) {
// invoke dynamic
final InvokeDynamicInsnNode idin = (InvokeDynamicInsnNode) in;
if (idin.bsm.getOwner().equals("java/lang/invoke/LambdaMetafactory")) {
// lambda
db.log(LogLevel.DEBUG, "Lambda at instruction %d", i);
susp = false;
} else
db.log(LogLevel.DEBUG, "InvokeDynamic Method call at instruction %d to is assumed suspendable", i);
}
if (susp) {
FrameInfo fi = addCodeBlock(f, i);
splitTryCatch(fi);
} else if (in.getType() == AbstractInsnNode.METHOD_INSN) {
// not invokedynamic
// noinspection ConstantConditions
final MethodInsnNode min = (MethodInsnNode) in;
db.log(LogLevel.DEBUG, "Method call at instruction %d to %s#%s%s is not suspendable", i, min.owner, min.name, min.desc);
possiblyWarnAboutBlocking(min);
}
}
}
}
addCodeBlock(null, numIns);
}
use of org.objectweb.asm.tree.InvokeDynamicInsnNode in project phosphor by gmu-swe.
the class InstMethodSinkInterpreter method naryOperation.
@Override
public BasicValue naryOperation(AbstractInsnNode insn, List values) throws AnalyzerException {
if (insn instanceof MethodInsnNode) {
MethodInsnNode min = (MethodInsnNode) insn;
// System.out.println(min.name+min.desc);
Type retType = Type.getReturnType(min.desc);
if (TaintUtils.isPrimitiveOrPrimitiveArrayType(retType)) {
SinkableArrayValue ret = new SinkableArrayValue(retType);
ret.setSrc(insn);
// System.out.println(ret);
return ret;
} else if (min.name.equals("clone") && min.desc.equals("()Ljava/lang/Object;") && values.get(0) instanceof SinkableArrayValue) {
SinkableArrayValue ret = new SinkableArrayValue(retType);
ret.setSrc(insn);
ret.addDep((SinkableArrayValue) values.get(0));
// System.out.println(ret);
return ret;
}
} else if (insn instanceof InvokeDynamicInsnNode) {
InvokeDynamicInsnNode min = (InvokeDynamicInsnNode) insn;
// System.out.println(min.name+min.desc);
Type retType = Type.getReturnType(min.desc);
if (TaintUtils.isPrimitiveOrPrimitiveArrayType(retType)) {
SinkableArrayValue ret = new SinkableArrayValue(retType);
ret.setSrc(insn);
return ret;
}
}
return super.naryOperation(insn, values);
}
Aggregations