List of usage examples for org.objectweb.asm Opcodes INVOKEINTERFACE
int INVOKEINTERFACE
To view the source code for org.objectweb.asm Opcodes INVOKEINTERFACE.
Click Source Link
From source file:net.sourceforge.cobertura.instrument.pass3.AbstractCodeProvider.java
License:GNU General Public License
/** * {@inheritDoc}<br/><br/>/*from ww w .j a va 2 s. c om*/ * <p/> * Generates method (named {@link #COBERTURA_CLASSMAP_METHOD_NAME}) with such a signature: * __cobertura_classmap( {@link LightClassmapListener} listener).</br> * <p/> * The method informs the listener about all lines, jumps and switches found, and about all counters tracking * the constructions. */ public void generateCoberturaClassMapMethod(ClassVisitor cv, ClassMap classMap) { LinkedList<TouchPointDescriptor> touchPointDescriptors = new LinkedList<TouchPointDescriptor>( classMap.getTouchPointsInLineOrder()); int parts = 0; for (int j = 0; touchPointDescriptors.size() > 0; j++) { List<TouchPointDescriptor> bufor = new LinkedList<TouchPointDescriptor>(); for (int i = 0; i < 1000 && touchPointDescriptors.size() > 0; i++) { bufor.add(touchPointDescriptors.removeFirst()); } classMapContent(cv, j, bufor); parts++; } MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, COBERTURA_CLASSMAP_METHOD_NAME, "(" + Type.getType(LightClassmapListener.class).toString() + ")V", null, null); mv.visitCode(); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitInsn(Opcodes.DUP); mv.visitLdcInsn(classMap.getClassName()); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, CLASSMAP_LISTENER_INTERNALNAME, "setClazz", "(Ljava/lang/String;)V"); if (classMap.getSource() != null) { mv.visitInsn(Opcodes.DUP); mv.visitLdcInsn(classMap.getSource()); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, CLASSMAP_LISTENER_INTERNALNAME, "setSource", "(Ljava/lang/String;)V"); } for (int i = 0; i < parts; i++) { mv.visitInsn(Opcodes.DUP); mv.visitMethodInsn(Opcodes.INVOKESTATIC, classMap.getClassName(), COBERTURA_CLASSMAP_METHOD_NAME + "_" + i, "(" + Type.getType(LightClassmapListener.class).toString() + ")V"); } mv.visitInsn(Opcodes.POP); mv.visitInsn(Opcodes.RETURN); mv.visitMaxs(0, 0);//will be recalculated by writer mv.visitEnd(); }
From source file:net.sourceforge.cobertura.instrument.pass3.AbstractCodeProvider.java
License:GNU General Public License
private void classMapContent(ClassVisitor cv, int nr, List<TouchPointDescriptor> touchPointDescriptors) { MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, COBERTURA_CLASSMAP_METHOD_NAME + "_" + nr, "(" + Type.getType(LightClassmapListener.class).toString() + ")V", null, null); mv.visitCode();// ww w .ja v a2s . co m mv.visitVarInsn(Opcodes.ALOAD, 0); for (TouchPointDescriptor tpd : touchPointDescriptors) { mv.visitInsn(Opcodes.DUP); mv.visitLdcInsn(tpd.getLineNumber()); if (tpd instanceof LineTouchPointDescriptor) { mv.visitLdcInsn(((LineTouchPointDescriptor) tpd).getCounterId()); mv.visitLdcInsn(((LineTouchPointDescriptor) tpd).getMethodName()); mv.visitLdcInsn(((LineTouchPointDescriptor) tpd).getMethodSignature()); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, CLASSMAP_LISTENER_INTERNALNAME, "putLineTouchPoint", "(IILjava/lang/String;Ljava/lang/String;)V"); } else if (tpd instanceof JumpTouchPointDescriptor) { mv.visitLdcInsn(((JumpTouchPointDescriptor) tpd).getCounterIdForTrue()); mv.visitLdcInsn(((JumpTouchPointDescriptor) tpd).getCounterIdForFalse()); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, CLASSMAP_LISTENER_INTERNALNAME, "putJumpTouchPoint", "(III)V"); } else if (tpd instanceof SwitchTouchPointDescriptor) { SwitchTouchPointDescriptor stpd = (SwitchTouchPointDescriptor) tpd; final String enum_sign = ((SwitchTouchPointDescriptor) tpd).getEnumType(); if (enum_sign == null) { mv.visitLdcInsn(Integer.MAX_VALUE); } else { mv.visitMethodInsn(Opcodes.INVOKESTATIC, enum_sign, "values", "()[L" + enum_sign + ";"); mv.visitInsn(Opcodes.ARRAYLENGTH); } Collection<Integer> ci = stpd.getCountersForLabels(); mv.visitLdcInsn(ci.size());//Size of a new table mv.visitIntInsn(Opcodes.NEWARRAY, Opcodes.T_INT); int i = 0; for (Integer counterId : ci) { mv.visitInsn(Opcodes.DUP); //First for addition of items, second ad putSwitchTouchPoint parameter (or next loop iteration) mv.visitLdcInsn(i); mv.visitLdcInsn(counterId); mv.visitInsn(Opcodes.IASTORE); i++; } mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, CLASSMAP_LISTENER_INTERNALNAME, "putSwitchTouchPoint", "(II[I)V"); } } mv.visitInsn(Opcodes.POP); mv.visitInsn(Opcodes.RETURN); mv.visitMaxs(0, 0);//will be recalculated by writer mv.visitEnd(); }
From source file:org.adjective.stout.operation.InvokeVirtualOperation.java
License:Apache License
public void getInstructions(ExecutionStack stack, InstructionCollector collector) { if (_target == null) { ThisExpression.INSTANCE.getInstructions(stack, collector); } else {//from www .j av a 2 s .c o m _target.getInstructions(stack, collector); } for (Expression expression : _arguments) { expression.getInstructions(stack, collector); } UnresolvedType targetType = _targetType == null ? stack.currentClass() : _targetType; int opCode = targetType.getSort() == Sort.INTERFACE ? Opcodes.INVOKEINTERFACE : Opcodes.INVOKEVIRTUAL; collector.add(new MethodInstruction(opCode, targetType.getInternalName(), _method)); }
From source file:org.adjective.stout.tools.StackVisualiserMethodVisitor.java
License:Apache License
public void visitMethodInsn(int opcode, String owner, String name, String desc) { Type[] argumentTypes = Type.getArgumentTypes(desc); Type returnType = Type.getReturnType(desc); StringBuilder args = new StringBuilder(); for (int i = argumentTypes.length; i > 0; i--) { args.insert(0, pop(argumentTypes[i - 1]).description + ","); }/* w w w.j a v a 2s . c o m*/ switch (opcode) { case Opcodes.INVOKESTATIC: break; case Opcodes.INVOKEINTERFACE: case Opcodes.INVOKEVIRTUAL: case Opcodes.INVOKESPECIAL: pop(Type.getObjectType(owner)); break; default: throw new IllegalArgumentException("Unsupported opcode " + OPCODES[opcode]); } String description = simpleName(owner) + "." + name + "(" + args + ")"; if (!returnType.equals(Type.VOID_TYPE)) { push(description, returnType); } print(opcode, description + " {" + desc + "}"); }
From source file:org.apache.commons.javaflow.bytecode.transformation.asm.ContinuationMethodAnalyzer.java
License:Apache License
boolean needsFrameGuard(int opcode, String owner, String name, String desc) { /* TODO: need to customize a way enchancer skips classes/methods if (owner.startsWith("java/")) {// w w w . ja v a 2s.co m System.out.println("SKIP:: " + owner + "." + name + desc); return false; } */ if (opcode == Opcodes.INVOKEINTERFACE || (opcode == Opcodes.INVOKESPECIAL && !"<init>".equals(name)) || opcode == Opcodes.INVOKESTATIC || opcode == Opcodes.INVOKEVIRTUAL) { return true; } return false; }
From source file:org.apache.commons.javaflow.providers.asm3.ContinuableMethodNode.java
License:Apache License
boolean needsFrameGuard(int opcode, String owner, String name, String desc) { if (owner.startsWith("java/") || owner.startsWith("javax/")) { //System.out.println("SKIP:: " + owner + "." + name + desc); return false; }// w w w .ja va 2 s . com // Always create save-point before Continuation methods (like suspend) if (CONTINUATION_CLASS_INTERNAL_NAME.equals(owner)) { return CONTINUATION_CLASS_CONTINUABLE_METHODS.contains(name); } // No need to create save-point before constructors -- it's forbidden to suspend in constructors anyway if (opcode == Opcodes.INVOKESPECIAL && "<init>".equals(name)) { return false; } if (opcode == Opcodes.INVOKEINTERFACE || opcode == Opcodes.INVOKESPECIAL || opcode == Opcodes.INVOKESTATIC || opcode == Opcodes.INVOKEVIRTUAL) { final ContinuableClassInfo classInfo; try { classInfo = cciResolver.resolve(owner); } catch (final IOException ex) { throw new RuntimeException(ex); } return null != classInfo && classInfo.isContinuableMethod(opcode, name, desc, desc); } return false; }
From source file:org.apache.commons.javaflow.providers.asm4.ContinuableMethodNode.java
License:Apache License
boolean needsFrameGuard(int opcode, String owner, String name, String desc) { if (owner.startsWith("java/") || owner.startsWith("javax/")) { //System.out.println("SKIP:: " + owner + "." + name + desc); return false; }/*from w ww . j a v a 2s . co m*/ // Always create save-point before Continuation methods (like suspend) if (CONTINUATION_CLASS_INTERNAL_NAME.equals(owner)) { return CONTINUATION_CLASS_CONTINUABLE_METHODS.contains(name); } // No need to create save-point before constructors -- it's forbidden to suspend in constructors anyway if (opcode == Opcodes.INVOKESPECIAL && "<init>".equals(name)) { return false; } if (opcode == Opcodes.INVOKEDYNAMIC) { // TODO verify CallSite to be continuable? return true; } if (opcode == Opcodes.INVOKEINTERFACE || opcode == Opcodes.INVOKESPECIAL || opcode == Opcodes.INVOKESTATIC || opcode == Opcodes.INVOKEVIRTUAL) { final ContinuableClassInfo classInfo; try { classInfo = cciResolver.resolve(owner); } catch (final IOException ex) { throw new RuntimeException(ex); } return null != classInfo && classInfo.isContinuableMethod(opcode, name, desc, desc); } return false; }
From source file:org.apache.commons.javaflow.providers.asm5.ContinuableMethodNode.java
License:Apache License
public void visitMethodInsn(int opcode, String owner, String name, String desc) { visitMethodInsn(opcode, owner, name, desc, opcode == Opcodes.INVOKEINTERFACE); }
From source file:org.apache.cxf.binding.corba.utils.CorbaAnyHelper.java
License:Apache License
private static void addReadOverride(ClassWriter cw) { MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "read_value", "(Lorg/omg/CORBA/portable/InputStream;Lorg/omg/CORBA/TypeCode;)V", null, null); mv.visitCode();// ww w . ja v a 2 s . co m Label l0 = new Label(); mv.visitLabel(l0); mv.visitLineNumber(54, l0); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, "org/apache/cxf/binding/corba/utils/FixedAnyImpl", "obj", "Lorg/omg/CORBA/portable/Streamable;"); Label l1 = new Label(); mv.visitJumpInsn(Opcodes.IFNULL, l1); Label l2 = new Label(); mv.visitLabel(l2); mv.visitLineNumber(55, l2); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, "org/apache/cxf/binding/corba/utils/FixedAnyImpl", "obj", "Lorg/omg/CORBA/portable/Streamable;"); mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "org/omg/CORBA/portable/Streamable", "_read", "(Lorg/omg/CORBA/portable/InputStream;)V"); Label l3 = new Label(); mv.visitJumpInsn(Opcodes.GOTO, l3); mv.visitLabel(l1); mv.visitLineNumber(57, l1); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitVarInsn(Opcodes.ALOAD, 2); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "com/sun/corba/se/impl/corba/AnyImpl", "read_value", "(Lorg/omg/CORBA/portable/InputStream;Lorg/omg/CORBA/TypeCode;)V"); mv.visitLabel(l3); mv.visitLineNumber(59, l3); mv.visitInsn(Opcodes.RETURN); Label l4 = new Label(); mv.visitLabel(l4); mv.visitLocalVariable("this", "Lorg/apache/cxf/binding/corba/utils/FixedAnyImpl;", null, l0, l4, 0); mv.visitLocalVariable("is", "Lorg/omg/CORBA/portable/InputStream;", null, l0, l4, 1); mv.visitLocalVariable("t", "Lorg/omg/CORBA/TypeCode;", null, l0, l4, 2); mv.visitMaxs(3, 3); mv.visitEnd(); }
From source file:org.apache.cxf.binding.corba.utils.CorbaAnyHelper.java
License:Apache License
private static void addWriteOverride(ClassWriter cw) { MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "write_value", "(Lorg/omg/CORBA/portable/OutputStream;)V", null, null); mv.visitCode();//from ww w . j a v a 2s . co m Label l0 = new Label(); mv.visitLabel(l0); mv.visitLineNumber(61, l0); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, "org/apache/cxf/binding/corba/utils/FixedAnyImpl", "obj", "Lorg/omg/CORBA/portable/Streamable;"); Label l1 = new Label(); mv.visitJumpInsn(Opcodes.IFNULL, l1); Label l2 = new Label(); mv.visitLabel(l2); mv.visitLineNumber(62, l2); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, "org/apache/cxf/binding/corba/utils/FixedAnyImpl", "obj", "Lorg/omg/CORBA/portable/Streamable;"); mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "org/omg/CORBA/portable/Streamable", "_write", "(Lorg/omg/CORBA/portable/OutputStream;)V"); Label l3 = new Label(); mv.visitJumpInsn(Opcodes.GOTO, l3); mv.visitLabel(l1); mv.visitLineNumber(64, l1); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "com/sun/corba/se/impl/corba/AnyImpl", "write_value", "(Lorg/omg/CORBA/portable/OutputStream;)V"); mv.visitLabel(l3); mv.visitLineNumber(66, l3); mv.visitInsn(Opcodes.RETURN); Label l4 = new Label(); mv.visitLabel(l4); mv.visitLocalVariable("this", "Lorg/apache/cxf/binding/corba/utils/FixedAnyImpl;", null, l0, l4, 0); mv.visitLocalVariable("os", "Lorg/omg/CORBA/portable/OutputStream;", null, l0, l4, 1); mv.visitMaxs(2, 2); mv.visitEnd(); }