List of usage examples for org.objectweb.asm Opcodes BIPUSH
int BIPUSH
To view the source code for org.objectweb.asm Opcodes BIPUSH.
Click Source Link
From source file:org.actorsguildframework.internal.codegenerator.ActorProxyCreator.java
License:Apache License
/** * Create or get a MessageCaller implementation for the given method. * @param ownerClass the class that owns the message * @param method the method to invoke//from ww w.j a v a2 s. c om * @return the message caller * @throws NoSuchMethodException * @throws SecurityException */ @SuppressWarnings("unchecked") public static Class<MessageCaller<?>> createMessageCaller(Class<?> ownerClass, Method method) throws SecurityException, NoSuchMethodException { String className = String.format("%s_%s_%d__MESSAGECALLER", ownerClass.getName(), method.getName(), getMethodNumber(method)); String classNameInternal = className.replace('.', '/'); java.lang.reflect.Type fullReturnType = method.getGenericReturnType(); if ((!(fullReturnType instanceof ParameterizedType)) && AsyncResult.class.isAssignableFrom(((Class) ((ParameterizedType) fullReturnType).getRawType()))) throw new RuntimeException("Something's wrong here: should not be called for such a method"); String returnSignature = GenericTypeHelper .getSignature(((ParameterizedType) fullReturnType).getActualTypeArguments()[0]); ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES); MethodVisitor mv; cw.visit(codeVersion, Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL + Opcodes.ACC_SUPER + Opcodes.ACC_SYNTHETIC, classNameInternal, "L" + classNameInternal + "<" + returnSignature + ">;", "org/actorsguildframework/internal/MessageCaller", null); cw.visitSource(null, null); { mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null); mv.visitCode(); Label l0 = new Label(); mv.visitLabel(l0); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "org/actorsguildframework/internal/MessageCaller", "<init>", "()V"); mv.visitInsn(Opcodes.RETURN); Label l1 = new Label(); mv.visitLabel(l1); mv.visitLocalVariable("this", "L" + classNameInternal + ";", null, l0, l1, 0); mv.visitMaxs(1, 1); mv.visitEnd(); } { mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "invoke", "(Lorg/actorsguildframework/Actor;[Ljava/lang/Object;)Lorg/actorsguildframework/AsyncResult;", "(Lorg/actorsguildframework/Actor;[Ljava/lang/Object;)Lorg/actorsguildframework/AsyncResult<" + returnSignature + ">;", null); mv.visitCode(); Label l0 = new Label(); mv.visitLabel(l0); mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitTypeInsn(Opcodes.CHECKCAST, Type.getInternalName(method.getDeclaringClass()) + "__ACTORPROXY"); int idx = 0; for (Class<?> t : method.getParameterTypes()) { mv.visitVarInsn(Opcodes.ALOAD, 2); mv.visitIntInsn(Opcodes.BIPUSH, idx); mv.visitInsn(Opcodes.AALOAD); if (t.isPrimitive()) { String wrapperDescr = GenerationUtils.getWrapperInternalName(t); mv.visitTypeInsn(Opcodes.CHECKCAST, wrapperDescr); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, wrapperDescr, t.getName() + "Value", "()" + Type.getDescriptor(t)); } else { if (isArgumentFreezingRequired(method, idx, t)) { mv.visitTypeInsn(Opcodes.CHECKCAST, Type.getInternalName(SerializableFreezer.class)); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(SerializableFreezer.class), "get", Type.getMethodDescriptor(SerializableFreezer.class.getMethod("get"))); } if (!t.equals(Object.class)) mv.visitTypeInsn(Opcodes.CHECKCAST, Type.getInternalName(t)); } idx++; } mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(method.getDeclaringClass()) + "__ACTORPROXY", String.format(SUPER_CALLER_NAME_FORMAT, method.getName()), Type.getMethodDescriptor(method)); mv.visitInsn(Opcodes.ARETURN); Label l2 = new Label(); mv.visitLabel(l2); mv.visitLocalVariable("this", "L" + classNameInternal + ";", null, l0, l2, 0); mv.visitLocalVariable("instance", "Lorg/actorsguildframework/Actor;", null, l0, l2, 1); mv.visitLocalVariable("arguments", "[Ljava/lang/Object;", null, l0, l2, 2); mv.visitMaxs(0, 0); mv.visitEnd(); } { mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "getMessageName", "()Ljava/lang/String;", null, null); mv.visitCode(); Label l0 = new Label(); mv.visitLabel(l0); mv.visitLdcInsn(method.getName()); mv.visitInsn(Opcodes.ARETURN); Label l1 = new Label(); mv.visitLabel(l1); mv.visitLocalVariable("this", "L" + classNameInternal + ";", null, l0, l1, 0); mv.visitMaxs(0, 0); mv.visitEnd(); } cw.visitEnd(); return (Class<MessageCaller<?>>) GenerationUtils.loadClass(className, cw.toByteArray()); }
From source file:org.actorsguildframework.internal.codegenerator.ActorProxyCreator.java
License:Apache License
/** * Writes a proxy method for messages.//from w ww . j a va2 s.com * @param classNameInternal the internal class name * @param classNameDescriptor the class name descriptor * @param cw the ClassWriter * @param index the message index * @param type the ActorState type to use * @param concurrencyModel the concurrency model of the message * @param messageDescriptor the message's descriptor * @param method the method to override * @param simpleDescriptor a simple descriptor of the message * @param genericSignature the signature of the message */ private static void writeProxyMethod(String classNameInternal, String classNameDescriptor, ClassWriter cw, int index, Type actorState, ConcurrencyModel concurrencyModel, MessageImplDescriptor messageDescriptor, Method method, String simpleDescriptor, String genericSignature) throws NoSuchMethodException { MethodVisitor mv; { mv = cw.visitMethod(Opcodes.ACC_PUBLIC, method.getName(), simpleDescriptor, genericSignature, null); mv.visitCode(); Label l0 = new Label(); mv.visitLabel(l0); mv.visitIntInsn(Opcodes.BIPUSH, method.getParameterTypes().length); mv.visitTypeInsn(Opcodes.ANEWARRAY, "java/lang/Object"); for (int j = 0; j < method.getParameterTypes().length; j++) { mv.visitInsn(Opcodes.DUP); mv.visitIntInsn(Opcodes.BIPUSH, j); Class<?> paraType = method.getParameterTypes()[j]; if (paraType.isPrimitive()) { String wrapperClass = GenerationUtils.getWrapperInternalName(paraType); Type primType = Type.getType(paraType); mv.visitVarInsn(primType.getOpcode(Opcodes.ILOAD), j + 1); mv.visitMethodInsn(Opcodes.INVOKESTATIC, wrapperClass, "valueOf", "(" + primType.getDescriptor() + ")" + "L" + wrapperClass + ";"); } else if (isArgumentFreezingRequired(method, j, paraType)) { mv.visitVarInsn(Opcodes.ALOAD, j + 1); mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(SerializableFreezer.class), "freeze", Type.getMethodDescriptor(SerializableFreezer.class.getMethod("freeze", Object.class))); } else if (paraType.isInterface()) { mv.visitVarInsn(Opcodes.ALOAD, j + 1); mv.visitInsn(Opcodes.DUP); mv.visitTypeInsn(Opcodes.INSTANCEOF, "org/actorsguildframework/Actor"); Label lEndif = new Label(); mv.visitJumpInsn(Opcodes.IFNE, lEndif); mv.visitTypeInsn(Opcodes.NEW, Type.getInternalName(ActorRuntimeException.class)); mv.visitInsn(Opcodes.DUP); mv.visitLdcInsn(String.format( "Argument %d is an non-Serializable interface, but you did not give an Actor. If a message's argument type is an interface that does not extend Serializable, only Actors are acceptable as argument.", j)); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(ActorRuntimeException.class), "<init>", "(Ljava/lang/String;)V"); mv.visitInsn(Opcodes.ATHROW); mv.visitLabel(lEndif); } else mv.visitVarInsn(Opcodes.ALOAD, j + 1); mv.visitInsn(Opcodes.AASTORE); } Label l1 = new Label(); mv.visitLabel(l1); mv.visitVarInsn(Opcodes.ASTORE, method.getParameterTypes().length + 1); // method.getParameterTypes().length+1 ==> 'args' local variable mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, classNameInternal, "actorState__ACTORPROXY", actorState.getDescriptor()); mv.visitFieldInsn(Opcodes.GETSTATIC, classNameInternal, String.format(MESSAGE_CALLER_NAME_FORMAT, index), "Lorg/actorsguildframework/internal/MessageCaller;"); mv.visitFieldInsn(Opcodes.GETSTATIC, "org/actorsguildframework/annotations/ThreadUsage", messageDescriptor.getThreadUsage().name(), "Lorg/actorsguildframework/annotations/ThreadUsage;"); mv.visitVarInsn(Opcodes.ALOAD, method.getParameterTypes().length + 1); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, actorState.getInternalName(), "queueMessage", "(Lorg/actorsguildframework/internal/MessageCaller;Lorg/actorsguildframework/annotations/ThreadUsage;[Ljava/lang/Object;)Lorg/actorsguildframework/internal/AsyncResultImpl;"); mv.visitInsn(Opcodes.ARETURN); Label l4 = new Label(); mv.visitLabel(l4); mv.visitLocalVariable("this", classNameDescriptor, null, l0, l4, 0); for (int j = 0; j < method.getParameterTypes().length; j++) mv.visitLocalVariable("arg" + j, Type.getDescriptor(method.getParameterTypes()[j]), GenericTypeHelper.getSignatureIfGeneric(method.getGenericParameterTypes()[j]), l0, l4, j + 1); mv.visitLocalVariable("args", "[Ljava/lang/Object;", null, l1, l4, method.getParameterTypes().length + 1); mv.visitMaxs(0, 0); mv.visitEnd(); } }
From source file:org.adjective.stout.operation.ConstantIntegerExpression.java
License:Apache License
public static Instruction getInstruction(int value) { if (value >= -1 && value <= 5) { return new GenericInstruction(Opcodes.ICONST_0 + value); }/*w w w .j a va 2 s. co m*/ if (value >= -128 && value < 127) { return new IntInstruction(Opcodes.BIPUSH, value); } if (value >= -32768 && value < 32767) { return new IntInstruction(Opcodes.SIPUSH, value); } return new LoadConstantInstruction(new Integer(value)); }
From source file:org.apache.cxf.jaxb.WrapperHelperCompiler.java
License:Apache License
private boolean addCreateWrapperObject(String newClassName, Class<?> objectFactoryClass) { MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "createWrapperObject", "(Ljava/util/List;)Ljava/lang/Object;", "(Ljava/util/List<*>;)Ljava/lang/Object;", new String[] { "org/apache/cxf/interceptor/Fault" }); mv.visitCode();/* ww w . ja v a 2 s .c o m*/ Label lBegin = new Label(); mv.visitLabel(lBegin); mv.visitLineNumber(104, lBegin); mv.visitTypeInsn(Opcodes.NEW, periodToSlashes(wrapperType.getName())); mv.visitInsn(Opcodes.DUP); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, periodToSlashes(wrapperType.getName()), "<init>", "()V"); mv.visitVarInsn(Opcodes.ASTORE, 2); for (int x = 0; x < setMethods.length; x++) { if (getMethods[x] == null) { if (setMethods[x] == null && fields[x] == null) { // null placeholder continue; } else { return false; } } Class<?> tp = getMethods[x].getReturnType(); mv.visitVarInsn(Opcodes.ALOAD, 2); if (List.class.isAssignableFrom(tp)) { doCollection(mv, x); } else { if (JAXBElement.class.isAssignableFrom(tp)) { mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, periodToSlashes(newClassName), "factory", "L" + periodToSlashes(objectFactoryClass.getName()) + ";"); } mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitIntInsn(Opcodes.BIPUSH, x); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/List", "get", "(I)Ljava/lang/Object;"); if (tp.isPrimitive()) { mv.visitTypeInsn(Opcodes.CHECKCAST, NONPRIMITIVE_MAP.get(tp)); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, NONPRIMITIVE_MAP.get(tp), tp.getName() + "Value", "()" + PRIMITIVE_MAP.get(tp)); } else if (JAXBElement.class.isAssignableFrom(tp)) { mv.visitTypeInsn(Opcodes.CHECKCAST, periodToSlashes(jaxbMethods[x].getParameterTypes()[0].getName())); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, periodToSlashes(objectFactoryClass.getName()), jaxbMethods[x].getName(), getMethodSignature(jaxbMethods[x])); } else if (tp.isArray()) { mv.visitTypeInsn(Opcodes.CHECKCAST, getClassCode(tp)); } else { mv.visitTypeInsn(Opcodes.CHECKCAST, periodToSlashes(tp.getName())); } mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, periodToSlashes(wrapperType.getName()), setMethods[x].getName(), "(" + getClassCode(tp) + ")V"); } } mv.visitVarInsn(Opcodes.ALOAD, 2); mv.visitInsn(Opcodes.ARETURN); Label lEnd = new Label(); mv.visitLabel(lEnd); mv.visitLocalVariable("this", "L" + newClassName + ";", null, lBegin, lEnd, 0); mv.visitLocalVariable("lst", "Ljava/util/List;", "Ljava/util/List<*>;", lBegin, lEnd, 1); mv.visitLocalVariable("ok", "L" + periodToSlashes(wrapperType.getName()) + ";", null, lBegin, lEnd, 2); mv.visitMaxs(0, 0); mv.visitEnd(); return true; }
From source file:org.apache.cxf.jaxb.WrapperHelperCompiler.java
License:Apache License
private void doCollection(MethodVisitor mv, int x) { // List aVal = obj.getA(); // List newA = (List)lst.get(99); // if (aVal == null) { // obj.setA(newA); // } else if (newA != null) { // aVal.addAll(newA); // }/*from w ww. j av a 2 s . c o m*/ Label l3 = new Label(); mv.visitLabel(l3); mv.visitLineNumber(114, l3); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, periodToSlashes(wrapperType.getName()), getMethods[x].getName(), getMethodSignature(getMethods[x])); mv.visitVarInsn(Opcodes.ASTORE, 3); mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitIntInsn(Opcodes.BIPUSH, x); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/List", "get", "(I)Ljava/lang/Object;"); mv.visitTypeInsn(Opcodes.CHECKCAST, "java/util/List"); mv.visitVarInsn(Opcodes.ASTORE, 4); mv.visitVarInsn(Opcodes.ALOAD, 3); Label nonNullLabel = new Label(); mv.visitJumpInsn(Opcodes.IFNONNULL, nonNullLabel); if (setMethods[x] == null) { mv.visitTypeInsn(Opcodes.NEW, "java/lang/RuntimeException"); mv.visitInsn(Opcodes.DUP); mv.visitLdcInsn(getMethods[x].getName() + " returned null and there isn't a set method."); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/RuntimeException", "<init>", "(Ljava/lang/String;)V"); mv.visitInsn(Opcodes.ATHROW); } else { mv.visitVarInsn(Opcodes.ALOAD, 2); mv.visitVarInsn(Opcodes.ALOAD, 4); mv.visitTypeInsn(Opcodes.CHECKCAST, getMethods[x].getReturnType().getName().replace('.', '/')); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, periodToSlashes(wrapperType.getName()), setMethods[x].getName(), getMethodSignature(setMethods[x])); } Label jumpOverLabel = new Label(); mv.visitJumpInsn(Opcodes.GOTO, jumpOverLabel); mv.visitLabel(nonNullLabel); mv.visitLineNumber(106, nonNullLabel); mv.visitVarInsn(Opcodes.ALOAD, 4); mv.visitJumpInsn(Opcodes.IFNULL, jumpOverLabel); mv.visitVarInsn(Opcodes.ALOAD, 3); mv.visitVarInsn(Opcodes.ALOAD, 4); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/List", "addAll", "(Ljava/util/Collection;)Z"); mv.visitInsn(Opcodes.POP); mv.visitLabel(jumpOverLabel); mv.visitLineNumber(107, jumpOverLabel); }
From source file:org.apache.maven.shared.dependency.analyzer.asm.DependencyVisitorTest.java
License:Apache License
public void testVisitIntInsn() { visitor.visitIntInsn(Opcodes.BIPUSH, 0); assertNoClasses(); }
From source file:org.boretti.drools.integration.drools5.DroolsAbstractMethodVisitor.java
License:Open Source License
private void addCondition(boolean preCondition, String type, String resourceName, Type error) { droolsGoalExecutionLog.getLogs()// ww w . j a v a 2s . c o m .add(new DroolsGoalExecutionLog(droolsGoalExecutionLog.getFileName(), droolsGoalExecutionLog.getAction(), "Method instrumentalization for " + ((preCondition) ? "pre" : "post") + "-condition " + name + "/" + desc)); visitor.setMethodChange(true); Type types[] = Type.getArgumentTypes(super.methodDesc); //runPreCondition this.visitVarInsn(Opcodes.ALOAD, 0); this.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getObjectType(parent).getInternalName(), "getClass", "()Ljava/lang/Class;"); if (type == null) type = "COMPILED"; this.visitFieldInsn(Opcodes.GETSTATIC, Type.getInternalName(DroolsServiceType.class), type, Type.getDescriptor(DroolsServiceType.class)); this.visitLdcInsn(resourceName); this.visitLdcInsn(error); this.visitVarInsn(Opcodes.ALOAD, 0); this.visitIntInsn(Opcodes.BIPUSH, types.length); this.visitTypeInsn(Opcodes.ANEWARRAY, "java/lang/Object"); int position = 1; for (int i = 0; i < types.length; i++) { this.visitInsn(Opcodes.DUP); this.visitIntInsn(Opcodes.BIPUSH, i); if (types[i].equals(Type.BOOLEAN_TYPE)) { this.visitVarInsn(Opcodes.ILOAD, position); this.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(Boolean.class), "valueOf", "(Z)Ljava/lang/Boolean;"); position += 1; } else if (types[i].equals(Type.BYTE_TYPE)) { this.visitTypeInsn(Opcodes.NEW, "java/lang/Byte"); this.visitInsn(Opcodes.DUP); this.visitVarInsn(Opcodes.ILOAD, position); this.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Byte.class), "<init>", "(B)V"); position += 1; } else if (types[i].equals(Type.CHAR_TYPE)) { this.visitTypeInsn(Opcodes.NEW, "java/lang/Character"); this.visitInsn(Opcodes.DUP); this.visitVarInsn(Opcodes.ILOAD, position); this.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Character.class), "<init>", "(C)V"); position += 1; } else if (types[i].equals(Type.DOUBLE_TYPE)) { this.visitTypeInsn(Opcodes.NEW, "java/lang/Double"); this.visitInsn(Opcodes.DUP); this.visitVarInsn(Opcodes.DLOAD, position); this.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Double.class), "<init>", "(D)V"); position += 2; } else if (types[i].equals(Type.FLOAT_TYPE)) { this.visitTypeInsn(Opcodes.NEW, "java/lang/Float"); this.visitInsn(Opcodes.DUP); this.visitVarInsn(Opcodes.FLOAD, position); this.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Float.class), "<init>", "(F)V"); position += 1; } else if (types[i].equals(Type.INT_TYPE)) { this.visitTypeInsn(Opcodes.NEW, "java/lang/Integer"); this.visitInsn(Opcodes.DUP); this.visitVarInsn(Opcodes.ILOAD, position); this.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Integer.class), "<init>", "(I)V"); position += 1; } else if (types[i].equals(Type.LONG_TYPE)) { this.visitTypeInsn(Opcodes.NEW, "java/lang/Long"); this.visitInsn(Opcodes.DUP); this.visitVarInsn(Opcodes.LLOAD, position); this.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Long.class), "<init>", "(J)V"); position += 2; } else if (types[i].equals(Type.SHORT_TYPE)) { this.visitTypeInsn(Opcodes.NEW, "java/lang/Short"); this.visitInsn(Opcodes.DUP); this.visitVarInsn(Opcodes.ILOAD, position); this.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Short.class), "<init>", "(S)V"); position += 1; } else { this.visitVarInsn(Opcodes.ALOAD, position); position += 1; } this.visitInsn(Opcodes.AASTORE); } if (preCondition) this.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(DroolsProvider.class), "runPreCondition", "(Ljava/lang/Class;Lorg/boretti/drools/integration/drools5/DroolsServiceType;Ljava/lang/String;Ljava/lang/Class;Ljava/lang/Object;[Ljava/lang/Object;)V"); else this.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(DroolsProvider.class), "runPostCondition", "(Ljava/lang/Class;Lorg/boretti/drools/integration/drools5/DroolsServiceType;Ljava/lang/String;Ljava/lang/Class;Ljava/lang/Object;[Ljava/lang/Object;)V"); }
From source file:org.brutusin.instrumentation.utils.TreeInstructions.java
License:Apache License
public static AbstractInsnNode getPushInstruction(int value) { if (value == -1) { return new InsnNode(Opcodes.ICONST_M1); } else if (value == 0) { return new InsnNode(Opcodes.ICONST_0); } else if (value == 1) { return new InsnNode(Opcodes.ICONST_1); } else if (value == 2) { return new InsnNode(Opcodes.ICONST_2); } else if (value == 3) { return new InsnNode(Opcodes.ICONST_3); } else if (value == 4) { return new InsnNode(Opcodes.ICONST_4); } else if (value == 5) { return new InsnNode(Opcodes.ICONST_5); } else if ((value >= -128) && (value <= 127)) { return new IntInsnNode(Opcodes.BIPUSH, value); } else if ((value >= -32768) && (value <= 32767)) { return new IntInsnNode(Opcodes.SIPUSH, value); } else {//from ww w .j av a 2 s .c o m return new LdcInsnNode(value); } }
From source file:org.compass.core.util.reflection.asm.AsmReflectionMethodGenerator.java
License:Apache License
/** * Creates the method invoking wrapper method. *///from w ww . jav a 2 s . com private static void createMethod(Class clazz, String name, Method refMethod, ClassWriter cw, String methodName, String desc, boolean argsParams, boolean returnValue, Class... parameterTypes) { MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_VARARGS, methodName, desc, null, null); boolean isStatic = Modifier.isStatic(refMethod.getModifiers()); boolean isInteface = Modifier.isInterface(refMethod.getDeclaringClass().getModifiers()); final int invokeCode; if (isStatic) { invokeCode = Opcodes.INVOKESTATIC; } else { invokeCode = isInteface ? Opcodes.INVOKEINTERFACE : Opcodes.INVOKEVIRTUAL; mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitTypeInsn(Opcodes.CHECKCAST, Type.getInternalName(clazz)); } if (argsParams) { for (int i = 0; i < parameterTypes.length; ++i) { mv.visitVarInsn(Opcodes.ALOAD, 2); mv.visitIntInsn(Opcodes.BIPUSH, i); mv.visitInsn(Opcodes.AALOAD); prepareParameter(mv, Type.getType(parameterTypes[i])); } } else { for (int i = 0; i < parameterTypes.length; ++i) { mv.visitVarInsn(Opcodes.ALOAD, i + 2); prepareParameter(mv, Type.getType(parameterTypes[i])); } } mv.visitMethodInsn(invokeCode, Type.getInternalName(clazz), name, Type.getMethodDescriptor(refMethod)); if (returnValue) { prepareResult(mv, refMethod); mv.visitInsn(Opcodes.ARETURN); } else { mv.visitInsn(Opcodes.RETURN); } mv.visitMaxs(1, 1); // ignored since ClassWriter set as ClassWriter.COMPUTE_MAXS mv.visitEnd(); }
From source file:org.decojer.cavaj.readers.asm.ReadMethodVisitor.java
License:Open Source License
@Override public void visitIntInsn(final int opcode, final int operand) { switch (opcode) { /********/*from www . j a va 2s . c o m*/ * PUSH * ********/ case Opcodes.BIPUSH: case Opcodes.SIPUSH: add(new PUSH(this.ops.size(), opcode, this.line, T.getJvmIntT(operand), operand)); break; /************ * NEWARRAY * ************/ case Opcodes.NEWARRAY: { final T t = T.TYPES[operand]; assert t != null; add(new NEWARRAY(this.ops.size(), opcode, this.line, getDu().getArrayT(t), 1)); break; } default: log.warn(getM() + ": Unknown int insn opcode '" + opcode + "'!"); } }