private static int getNumArgs(MethodInsnNode m) { int ret = TypeDesc.getNumArgumentTypes(m.desc); if (m.getOpcode() != INVOKESTATIC) ret++; return ret; }
final boolean isStaticCall() { return getMethodInsn().getOpcode() == INVOKESTATIC; }
/** * Intercepts the method using the invokedynamic bytecode instruction available in Java 7+. * Should be called through interceptInvokeVirtualMethod, not directly. */ private void interceptInvokeVirtualMethodWithInvokeDynamic( ListIterator<AbstractInsnNode> instructions, MethodInsnNode targetMethod) { instructions.remove(); // remove the method invocation 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)); } }
static String getDescriptionForMethodInsnNode(MethodInsnNode methodInstr) { if (methodInstr.getOpcode() == Opcodes.INVOKESPECIAL && methodInstr.name.equals("<init>")) { return "new " + Util.extractSimpleName(methodInstr.owner, "/") + "()"; } else { Type methodType = Type.getMethodType(methodInstr.desc); int retSize = methodType.getArgumentsAndReturnSizes() & 0x03; if (retSize > 0) { return methodInstr.name + Util.getArgumentsInformation(methodInstr.desc); } } return ""; }
boolean isStatic = targetMethod.getOpcode() == Opcodes.INVOKESTATIC;
private void convertMethodInsn(MethodInsnNode insn) { int op = insn.getOpcode(); boolean instance = op != INVOKESTATIC; StackFrame frame = getFrame(insn);
/** * Intercepts the method using the invokedynamic bytecode instruction available in Java 7+. * Should be called through interceptInvokeVirtualMethod, not directly */ private void interceptInvokeVirtualMethodWithInvokeDynamic(ListIterator<AbstractInsnNode> instructions, MethodInsnNode targetMethod) { instructions.remove(); // remove the method invocation Type type = Type.getObjectType(targetMethod.owner); String description = targetMethod.desc; String owner = type.getClassName(); if (targetMethod.getOpcode() != INVOKESTATIC) { String thisType = type.getDescriptor(); description = "(" + thisType + description.substring(1, description.length()); } instructions.add(new InvokeDynamicInsnNode(targetMethod.name, description, BOOTSTRAP_INTRINSIC, owner)); } }
/** * We try to detect such a last 2 instructions and extract the enum signature. */ private String tryToFindSignatureOfConditionEnum() { // mv.visitMethodInsn(INVOKESTATIC, "net/sourceforge/cobertura/instrument/FindTouchPointsMethodAdapter", "$SWITCH_TABLE$net$sourceforge$cobertura$instrument$FindTouchPointsMethodAdapter$Abc", "()[I"); // mv.visitVarInsn(ALOAD, 1); // mv.visitMethodInsn(INVOKEVIRTUAL, "net/sourceforge/cobertura/instrument/FindTouchPointsMethodAdapter$Abc", "ordinal", "()I"); // mv.visitInsn(IALOAD); if (backlog == null || backlog.size() < 4) return null; int last = backlog.size() - 1; if ((backlog.get(last) instanceof InsnNode) && (backlog.get(last - 1) instanceof MethodInsnNode) && (backlog.get(last - 2) instanceof VarInsnNode)) { VarInsnNode i2 = (VarInsnNode) backlog.get(last - 2); MethodInsnNode i3 = (MethodInsnNode) backlog.get(last - 1); InsnNode i4 = (InsnNode) backlog.get(last); if ((i2.getOpcode() == Opcodes.ALOAD) && (i3.getOpcode() == Opcodes.INVOKEVIRTUAL && i3.name .equals("ordinal")) && (i4.getOpcode() == Opcodes.IALOAD)) { return i3.owner; } } return null; }
/** * We try to detect such a last 2 instructions and extract the enum signature. */ private String tryToFindSignatureOfConditionEnum() { // mv.visitMethodInsn(INVOKESTATIC, "net/sourceforge/cobertura/instrument/FindTouchPointsMethodAdapter", "$SWITCH_TABLE$net$sourceforge$cobertura$instrument$FindTouchPointsMethodAdapter$Abc", "()[I"); // mv.visitVarInsn(ALOAD, 1); // mv.visitMethodInsn(INVOKEVIRTUAL, "net/sourceforge/cobertura/instrument/FindTouchPointsMethodAdapter$Abc", "ordinal", "()I"); // mv.visitInsn(IALOAD); if (backlog == null || backlog.size() < 4) return null; int last = backlog.size() - 1; if ((backlog.get(last) instanceof InsnNode) && (backlog.get(last - 1) instanceof MethodInsnNode) && (backlog.get(last - 2) instanceof VarInsnNode)) { VarInsnNode i2 = (VarInsnNode) backlog.get(last - 2); MethodInsnNode i3 = (MethodInsnNode) backlog.get(last - 1); InsnNode i4 = (InsnNode) backlog.get(last); if ((i2.getOpcode() == Opcodes.ALOAD) && (i3.getOpcode() == Opcodes.INVOKEVIRTUAL && i3.name .equals("ordinal")) && (i4.getOpcode() == Opcodes.IALOAD)) { return i3.owner; } } return null; }
private static void handleMethodCall(Set<CalledMethod> thisCalls, int lineNumber, MethodInsnNode insn) { boolean isStatic; switch (insn.getOpcode()) { case Opcodes.INVOKEVIRTUAL: case Opcodes.INVOKEINTERFACE: isStatic = false; break; case Opcodes.INVOKESPECIAL: isStatic = false; break; case Opcodes.INVOKESTATIC: isStatic = true; break; default: throw new RuntimeException("Unexpected method call opcode: " + insn.getOpcode()); } if (insn.owner.charAt(0) != '[') { thisCalls.add(new CalledMethodBuilder() .owner(TypeDescriptors.fromClassName(insn.owner)) .descriptor(MethodDescriptors.fromDesc(insn.desc, insn.name)) .isStatic(isStatic) .lineNumber(lineNumber) .build()); } }
/** * Descend into a static method call * */ private static void handleMethodInsnNode(GetStaticGraph staticUsageTree, ClassNode cn, MethodNode mn, MethodInsnNode methodCall, int depth) { // Skip if method call is not static if (methodCall.getOpcode() != Opcodes.INVOKESTATIC) { return; } // Only collect relations for instrumentable classes String calleeClassName = methodCall.owner.replaceAll("/", "."); if (BytecodeInstrumentation.checkIfCanInstrument(calleeClassName)) { logger.debug("Handling method: " + methodCall.name); handleClassInitializer(staticUsageTree, cn, mn, methodCall.owner, depth); if (!staticUsageTree.hasStaticMethodCall(cn.name, mn.name + mn.desc, methodCall.owner, methodCall.name + methodCall.desc)) { // Add call from mn to methodCall to callgraph staticUsageTree.addStaticMethodCall(cn.name, mn.name + mn.desc, methodCall.owner, methodCall.name + methodCall.desc); handle(staticUsageTree, methodCall.owner, methodCall.name + methodCall.desc, depth); } } }
static int transformMethodCall(final InsnList instructions, int i, final Map<AbstractInsnNode, Frame<BasicValue>> frameMap, final MethodInsnNode methodInsn, final MappedSubtypeInfo mappedType, final Map<Integer, MappedSubtypeInfo> arrayVars) { switch ( methodInsn.getOpcode() ) { case INVOKEVIRTUAL: if ( "asArray".equals(methodInsn.name) && methodInsn.desc.equals("()[L" + MAPPED_OBJECT_JVM + ";") ) {
protected Result findMatchingCallSite(MethodInsnNode m, List<LocalVariableAnnotationNode> varAnnotations, Map<Integer, List<AnnotationNode>> paramAnnotations) { int opcode = m.getOpcode();
private Result findMatchingCallSite(MethodInsnNode m, List<LocalVariableAnnotationNode> varAnnotations, Map<Integer, List<AnnotationNode>> paramAnnotations) { int opcode = m.getOpcode();
protected Result findMatchingCallSite(MethodInsnNode m, List<LocalVariableAnnotationNode> varAnnotations, Map<Integer, List<AnnotationNode>> paramAnnotations) { int opcode = m.getOpcode();
if (insn instanceof MethodInsnNode && insn.getOpcode() != INVOKESPECIAL) { MethodInsnNode methodInsnNode = (MethodInsnNode) insn; boolean isStatic = (methodInsnNode.getOpcode() == Opcodes.INVOKESTATIC);
if (insn instanceof MethodInsnNode && insn.getOpcode() != INVOKESPECIAL) { MethodInsnNode methodInsnNode = (MethodInsnNode) insn; boolean isStatic = (methodInsnNode.getOpcode() == Opcodes.INVOKESTATIC);
|| methodInsnNode.getOpcode() == INVOKESPECIAL;
if (in.getType() == AbstractInsnNode.METHOD_INSN) { MethodInsnNode min = (MethodInsnNode) in; int opcode = min.getOpcode(); if (db.isMethodSuspendable(min.owner, min.name, min.desc, opcode == Opcodes.INVOKEVIRTUAL || opcode == Opcodes.INVOKESTATIC)) {