List of usage examples for org.objectweb.asm Opcodes IRETURN
int IRETURN
To view the source code for org.objectweb.asm Opcodes IRETURN.
Click Source Link
From source file:org.actorsguildframework.internal.codegenerator.ActorProxyCreator.java
License:Apache License
/** * Creates a synchronized delegate method for a message method. * @param actorClass the actor class/*from w w w .j a v a2s .co m*/ * @param classNameDescriptor the descriptor of the resulting class * @param cw the class writer to write to * @param method the method being invoked * @param simpleDescriptor the descriptor of the method * @param genericSignature the generic signature of the method * @param isSynchronized true to make the method synchronized, false otherwise */ private static void writeSuperProxyMethod(Class<?> actorClass, String classNameDescriptor, ClassWriter cw, Method method, String simpleDescriptor, String genericSignature, boolean isSynchronized) throws NoSuchMethodException { MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC + (isSynchronized ? Opcodes.ACC_SYNCHRONIZED : 0), String.format(SUPER_CALLER_NAME_FORMAT, method.getName()), simpleDescriptor, genericSignature, null); mv.visitCode(); Label l0 = new Label(); mv.visitLabel(l0); mv.visitVarInsn(Opcodes.ALOAD, 0); for (int j = 0; j < method.getParameterTypes().length; j++) mv.visitVarInsn(Type.getType(method.getParameterTypes()[j]).getOpcode(Opcodes.ILOAD), j + 1); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(actorClass), method.getName(), simpleDescriptor); mv.visitInsn(Type.getType(method.getReturnType()).getOpcode(Opcodes.IRETURN)); Label l1 = new Label(); mv.visitLabel(l1); mv.visitLocalVariable("this", classNameDescriptor, null, l0, l1, 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, l1, j + 1); mv.visitMaxs(0, 0); mv.visitEnd(); }
From source file:org.actorsguildframework.internal.codegenerator.BeanCreator.java
License:Apache License
/** * Writes the accessor methods for @Prop generated properties. * @param bcd the class descriptor//ww w . j a va2 s . c om * @param classNameInternal the internal name of this class * @param cw the ClassWriter to write to */ public static void writePropAccessors(BeanClassDescriptor bcd, String classNameInternal, ClassWriter cw) { String classNameDescriptor = "L" + classNameInternal + ";"; MethodVisitor mv; for (int i = 0; i < bcd.getPropertyCount(); i++) { PropertyDescriptor pd = bcd.getProperty(i); if (!pd.getPropertySource().isGenerating()) continue; { Type t = Type.getType(pd.getPropertyClass()); Method orig = pd.getGetter(); mv = cw.visitMethod( GenerationUtils.convertAccessModifiers(orig.getModifiers()) + (bcd.isThreadSafe() ? Opcodes.ACC_SYNCHRONIZED : 0), orig.getName(), Type.getMethodDescriptor(orig), GenericTypeHelper.getSignature(orig), null); mv.visitCode(); Label l0 = new Label(); mv.visitLabel(l0); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, classNameInternal, String.format(PROP_FIELD_NAME_TEMPLATE, pd.getName()), Type.getDescriptor(pd.getPropertyClass())); mv.visitInsn(t.getOpcode(Opcodes.IRETURN)); Label l1 = new Label(); mv.visitLabel(l1); mv.visitLocalVariable("this", classNameDescriptor, null, l0, l1, 0); mv.visitMaxs(0, 0); mv.visitEnd(); } if (pd.getAccess().isWritable()) { Type t = Type.getType(pd.getPropertyClass()); Method orig = pd.getSetter(); mv = cw.visitMethod( GenerationUtils.convertAccessModifiers(orig.getModifiers()) + (bcd.isThreadSafe() ? Opcodes.ACC_SYNCHRONIZED : 0), orig.getName(), Type.getMethodDescriptor(orig), GenericTypeHelper.getSignature(orig), null); mv.visitCode(); Label l0 = new Label(); mv.visitLabel(l0); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitVarInsn(t.getOpcode(Opcodes.ILOAD), 1); mv.visitFieldInsn(Opcodes.PUTFIELD, classNameInternal, String.format(PROP_FIELD_NAME_TEMPLATE, pd.getName()), Type.getDescriptor(pd.getPropertyClass())); mv.visitInsn(Opcodes.RETURN); Label l1 = new Label(); mv.visitLabel(l1); mv.visitLocalVariable("this", classNameDescriptor, null, l0, l1, 0); mv.visitLocalVariable("value", Type.getDescriptor(pd.getPropertyClass()), null, l0, l1, 1); mv.visitMaxs(0, 0); mv.visitEnd(); } } }
From source file:org.apache.cxf.jaxws.WrapperClassGenerator.java
License:Apache License
private void generateMessagePart(ClassWriter cw, MessagePartInfo mpi, Method method, String className) { if (Boolean.TRUE.equals(mpi.getProperty(ReflectionServiceFactoryBean.HEADER))) { return;/*from w w w . jav a 2 s .com*/ } String classFileName = periodToSlashes(className); String name = mpi.getName().getLocalPart(); Class clz = mpi.getTypeClass(); Object obj = mpi.getProperty(ReflectionServiceFactoryBean.RAW_CLASS); if (obj != null) { clz = (Class) obj; } Type genericType = (Type) mpi.getProperty(ReflectionServiceFactoryBean.GENERIC_TYPE); if (genericType instanceof ParameterizedType) { ParameterizedType tp = (ParameterizedType) genericType; if (tp.getRawType() instanceof Class && Holder.class.isAssignableFrom((Class) tp.getRawType())) { genericType = tp.getActualTypeArguments()[0]; } } String classCode = getClassCode(clz); String fieldDescriptor = null; if (genericType instanceof ParameterizedType) { if (Collection.class.isAssignableFrom(clz) || clz.isArray()) { ParameterizedType ptype = (ParameterizedType) genericType; Type[] types = ptype.getActualTypeArguments(); // TODO: more complex Parameterized type if (types.length > 0) { if (types[0] instanceof Class) { fieldDescriptor = getClassCode(genericType); } else if (types[0] instanceof GenericArrayType) { fieldDescriptor = getClassCode(genericType); } else if (types[0] instanceof ParameterizedType) { classCode = getClassCode(((ParameterizedType) types[0]).getRawType()); fieldDescriptor = getClassCode(genericType); } } } else { classCode = getClassCode(((ParameterizedType) genericType).getRawType()); fieldDescriptor = getClassCode(genericType); } } String fieldName = JavaUtils.isJavaKeyword(name) ? JavaUtils.makeNonJavaKeyword(name) : name; FieldVisitor fv = cw.visitField(Opcodes.ACC_PRIVATE, fieldName, classCode, fieldDescriptor, null); AnnotationVisitor av0 = fv.visitAnnotation("Ljavax/xml/bind/annotation/XmlElement;", true); av0.visit("name", name); if (factory.isWrapperPartQualified(mpi)) { av0.visit("namespace", mpi.getConcreteName().getNamespaceURI()); } if (factory.isWrapperPartNillable(mpi)) { av0.visit("nillable", Boolean.TRUE); } if (factory.getWrapperPartMinOccurs(mpi) == 1) { av0.visit("required", Boolean.TRUE); } av0.visitEnd(); List<Annotation> jaxbAnnos = getJaxbAnnos(mpi); addJAXBAnnotations(fv, jaxbAnnos); fv.visitEnd(); String methodName = JAXBUtils.nameToIdentifier(name, JAXBUtils.IdentifierType.GETTER); MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, methodName, "()" + classCode, fieldDescriptor == null ? null : "()" + fieldDescriptor, null); mv.visitCode(); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, classFileName, fieldName, classCode); mv.visitInsn(org.objectweb.asm.Type.getType(classCode).getOpcode(Opcodes.IRETURN)); mv.visitMaxs(0, 0); mv.visitEnd(); methodName = JAXBUtils.nameToIdentifier(name, JAXBUtils.IdentifierType.SETTER); mv = cw.visitMethod(Opcodes.ACC_PUBLIC, methodName, "(" + classCode + ")V", fieldDescriptor == null ? null : "(" + fieldDescriptor + ")V", null); mv.visitCode(); mv.visitVarInsn(Opcodes.ALOAD, 0); org.objectweb.asm.Type setType = org.objectweb.asm.Type.getType(classCode); mv.visitVarInsn(setType.getOpcode(Opcodes.ILOAD), 1); mv.visitFieldInsn(Opcodes.PUTFIELD, className, fieldName, classCode); mv.visitInsn(Opcodes.RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); }
From source file:org.apache.felix.ipojo.composite.service.provides.POJOWriter.java
License:Apache License
/** * Generate on method./* w w w. ja va2s. c om*/ * @param cw : class writer * @param className : the current class name * @param method : the method to generate * @param sign : method signature to generate * @param delegator : the field on which delegate * @param handler : the handler (used to acess the logger) */ private static void generateMethod(ClassWriter cw, String className, MethodMetadata method, Method sign, FieldMetadata delegator, Handler handler) { String desc = Type.getMethodDescriptor(sign); String name = sign.getName(); String[] exc = new String[sign.getExceptionTypes().length]; for (int i = 0; i < sign.getExceptionTypes().length; i++) { exc[i] = Type.getType(sign.getExceptionTypes()[i]).getInternalName(); } MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, name, desc, null, exc); if (delegator.isOptional()) { if (!delegator.isAggregate()) { generateOptionalCase(mv, delegator, className); } if (delegator.isAggregate() /*&& method.getPolicy() == MethodMetadata.ONE_POLICY*/) { generateOptionalAggregateCase(mv, delegator, className); } } if (delegator.isAggregate()) { if (method.getPolicy() == MethodMetadata.ONE_POLICY) { // Aggregate and One Policy mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, className, delegator.getName(), "[L" + delegator.getSpecification().getName().replace('.', '/') + ";"); mv.visitInsn(ICONST_0); // Use the first one mv.visitInsn(AALOAD); loadArgs(mv, ACC_PUBLIC, Type.getArgumentTypes(desc)); // Invoke mv.visitMethodInsn(INVOKEINTERFACE, delegator.getSpecification().getName().replace('.', '/'), name, desc); // Return mv.visitInsn(Type.getReturnType(desc).getOpcode(Opcodes.IRETURN)); } else { // All policy if (Type.getReturnType(desc).getSort() != Type.VOID) { handler.error("All policy cannot be used on method which does not return void"); } Type[] args = Type.getArgumentTypes(desc); int index = args.length + 1; // Init mv.visitInsn(ICONST_0); mv.visitVarInsn(ISTORE, index); Label l1b = new Label(); mv.visitLabel(l1b); Label l2b = new Label(); mv.visitJumpInsn(GOTO, l2b); // Loop Label l3b = new Label(); mv.visitLabel(l3b); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, className, delegator.getName(), "[L" + delegator.getSpecification().getName().replace('.', '/') + ";"); mv.visitVarInsn(ILOAD, index); mv.visitInsn(AALOAD); loadArgs(mv, ACC_PUBLIC, Type.getArgumentTypes(desc)); mv.visitMethodInsn(INVOKEINTERFACE, delegator.getSpecification().getName().replace('.', '/'), name, desc); Label l4b = new Label(); mv.visitLabel(l4b); mv.visitIincInsn(index, 1); // i++; // Condition mv.visitLabel(l2b); mv.visitVarInsn(ILOAD, index); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, className, delegator.getName(), "[L" + delegator.getSpecification().getName().replace('.', '/') + ";"); mv.visitInsn(ARRAYLENGTH); mv.visitJumpInsn(IF_ICMPLT, l3b); Label l5b = new Label(); mv.visitLabel(l5b); mv.visitInsn(RETURN); } } else { mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, className, delegator.getName(), "L" + delegator.getSpecification().getName().replace('.', '/') + ";"); loadArgs(mv, ACC_PUBLIC, Type.getArgumentTypes(desc)); // Invoke if (delegator.getSpecification().isInterface()) { mv.visitMethodInsn(INVOKEINTERFACE, delegator.getSpecification().getName().replace('.', '/'), name, desc); } else { mv.visitMethodInsn(INVOKEVIRTUAL, delegator.getSpecification().getName().replace('.', '/'), name, desc); } // Return mv.visitInsn(Type.getReturnType(desc).getOpcode(IRETURN)); } mv.visitMaxs(0, 0); mv.visitEnd(); }
From source file:org.apache.sling.metrics.impl.ReturnAdapter.java
License:Apache License
@Override protected void onMethodExit(int opcode) { switch (opcode) { case Opcodes.IRETURN: case Opcodes.LRETURN: case Opcodes.FRETURN: case Opcodes.DRETURN: case Opcodes.ARETURN: try {/* w w w. j a va 2 s .c o m*/ addReturnMetric(opcode); } catch (Exception e) { e.printStackTrace(); } } super.onMethodExit(opcode); }
From source file:org.apache.tuscany.sca.interfacedef.java.jaxrs.CodeGenerationHelper.java
License:Apache License
public static int getReturnOPCode(String signature) { if ("Z".equals(signature) || "B".equals(signature) || "C".equals(signature) || "S".equals(signature) || "I".equals(signature)) { return Opcodes.IRETURN; }/*from w ww . jav a 2 s . c o m*/ if ("J".equals(signature)) { return Opcodes.LRETURN; } if ("F".equals(signature)) { return Opcodes.FRETURN; } if ("D".equals(signature)) { return Opcodes.DRETURN; } if ("V".equals(signature)) { return Opcodes.RETURN; } return Opcodes.ARETURN; }
From source file:org.batoo.jpa.core.impl.instance.Enhancer.java
License:Open Source License
private static void createMethodIsInitialized(final String enhancedClassName, final String descEnhancer, final ClassWriter cw) { final MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, Enhancer.METHOD_ENHANCED_IS_INITIALIZED, Enhancer.makeDescription(Boolean.TYPE), null, null); mv.visitCode();// www. ja v a 2 s . c o m final Label l0 = new Label(); mv.visitLabel(l0); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, enhancedClassName, Enhancer.FIELD_ENHANCED_INITIALIZED, Enhancer.DESCRIPTOR_BOOLEAN); mv.visitInsn(Opcodes.IRETURN); final Label l1 = new Label(); mv.visitLabel(l1); mv.visitLocalVariable(Enhancer.THIS, descEnhancer, null, l0, l1, 0); mv.visitMaxs(0, 0); mv.visitEnd(); }
From source file:org.batoo.jpa.core.impl.instance.Enhancer.java
License:Open Source License
private static int getReturnType(Class<?> paramClass) { if (!paramClass.isPrimitive() || paramClass.isArray()) { return Opcodes.ARETURN; }//from w ww . j a v a 2 s.c o m if (Long.TYPE == paramClass) { return Opcodes.LRETURN; } if (Float.TYPE == paramClass) { return Opcodes.FRETURN; } if (Double.TYPE == paramClass) { return Opcodes.DRETURN; } return Opcodes.IRETURN; }
From source file:org.brutusin.instrumentation.Instrumentator.java
License:Apache License
private void addTraceReturn() { InsnList il = this.mn.instructions; Iterator<AbstractInsnNode> it = il.iterator(); while (it.hasNext()) { AbstractInsnNode abstractInsnNode = it.next(); switch (abstractInsnNode.getOpcode()) { case Opcodes.RETURN: il.insertBefore(abstractInsnNode, getVoidReturnTraceInstructions()); break; case Opcodes.IRETURN: case Opcodes.LRETURN: case Opcodes.FRETURN: case Opcodes.ARETURN: case Opcodes.DRETURN: il.insertBefore(abstractInsnNode, getReturnTraceInstructions()); }/*w w w . j a v a 2 s.c o m*/ } }
From source file:org.cacheonix.impl.transformer.ByteInstruction.java
License:LGPL
/** * Returns the Opcode for the specific return type * * @param desc method description// w w w .j a va 2 s. c o m * @return Opcode for the specific return type */ public static int getReturnCode(final String desc) { final Type t = Type.getReturnType(desc); return t.getOpcode(Opcodes.IRETURN); }