List of usage examples for org.objectweb.asm MethodVisitor visitIntInsn
public void visitIntInsn(final int opcode, final int operand)
From source file:org.adjective.stout.instruction.IntInstruction.java
License:Apache License
public void accept(MethodVisitor visitor) { visitor.visitIntInsn(getOpCode(), _arg); }
From source file:org.alkemy.instr.ConstructorWriter.java
License:Open Source License
private static void visitInStack(int i, MethodVisitor mv) { if (i == 0) { mv.visitInsn(ICONST_0);// ww w.j a v a 2s . co m } else if (i == 1) { mv.visitInsn(ICONST_1); } else if (i == 2) { mv.visitInsn(ICONST_2); } else if (i == 3) { mv.visitInsn(ICONST_3); } else if (i == 4) { mv.visitInsn(ICONST_4); } else if (i == 5) { mv.visitInsn(ICONST_5); } else if (i <= 127) { mv.visitIntInsn(BIPUSH, i); } else { mv.visitIntInsn(SIPUSH, i); } }
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();/*from w w w . j av a2 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); // }/* ww w . j a v 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.directmemory.lightning.internal.generator.BytecodeMarshallerGenerator.java
License:Apache License
private void createConstructor(ClassWriter cw, String className, List<PropertyDescriptor> propertyDescriptors) { MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "<init>", MARSHALLER_CONSTRUCTOR_SIGNATURE, null, null); mv.visitCode();/*from ww w . ja va2 s . c o m*/ // Load this mv.visitVarInsn(ALOAD, 0); // Load first parameter type (Class) mv.visitVarInsn(ALOAD, 1); // Load second parameter type (Map) mv.visitVarInsn(ALOAD, 2); // Load third parameter type (ClassDescriptorAwaySerializer) mv.visitVarInsn(ALOAD, 3); // Load fourth parameter type (ObjenesisSerializer) mv.visitVarInsn(ALOAD, 4); // Call super(Class, Map) mv.visitMethodInsn(INVOKESPECIAL, SUPER_CLASS_INTERNAL_TYPE, "<init>", MARSHALLER_SUPER_CONSTRUCTOR_SIGNATURE); // Fill fields with marshallers for (int i = 0; i < propertyDescriptors.size(); i++) { PropertyDescriptor propertyDescriptor = propertyDescriptors.get(i); String fieldName = toFinalFieldName("marshaller", propertyDescriptor); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 0); // Load property type mv.visitVarInsn(ALOAD, 5); mv.visitIntInsn(BIPUSH, i); mv.visitMethodInsn(INVOKEINTERFACE, LIST_CLASS_INTERNAL_TYPE, "get", "(I)Ljava/lang/Object;"); // Store PropertyDescriptor mv.visitTypeInsn(CHECKCAST, PROPERTYDESCRIPTOR_CLASS_INTERNAL_TYPE); mv.visitFieldInsn(PUTFIELD, className, toFinalFieldName("descriptor", propertyDescriptor), PROPERTYDESCRIPTOR_CLASS_DESCRIPTOR); if (propertyDescriptor.getType().isArray() && !propertyDescriptor.getType().getComponentType().isPrimitive()) { Label labelNonNull = new Label(); // Get type from PropertyAccessor mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, className, toFinalFieldName("descriptor", propertyDescriptor), PROPERTYDESCRIPTOR_CLASS_DESCRIPTOR); mv.visitMethodInsn(INVOKEINTERFACE, PROPERTYDESCRIPTOR_CLASS_INTERNAL_TYPE, "getType", "()Ljava/lang/Class;"); // Get array component type mv.visitMethodInsn(INVOKEVIRTUAL, CLASS_CLASS_INTERNAL_TYPE, "getComponentType", CLASS_GET_COMPONENT_TYPE); mv.visitVarInsn(ASTORE, 9); // Generate cheating PropertyDescriptor for component type mv.visitVarInsn(ALOAD, 0); mv.visitTypeInsn(NEW, CHEATINGPROPERTYDESCRIPTOR_CLASS_INTERNAL_TYPE); mv.visitInsn(DUP); mv.visitLdcInsn(propertyDescriptor.getPropertyName() + "Element"); mv.visitVarInsn(ALOAD, 9); mv.visitInsn(ACONST_NULL); mv.visitMethodInsn(INVOKESPECIAL, CHEATINGPROPERTYDESCRIPTOR_CLASS_INTERNAL_TYPE, "<init>", CHEATINGPROPERTYDESCRIPTOR_CONSTRUCTOR); mv.visitFieldInsn(PUTFIELD, className, toFinalFieldName("component", propertyDescriptor), CHEATINGPROPERTYDESCRIPTOR_CLASS_DESCRIPTOR); // Search marshaller by using interal ones mv.visitVarInsn(ALOAD, 6); mv.visitVarInsn(ALOAD, 9); mv.visitInsn(ACONST_NULL); mv.visitMethodInsn(INVOKEINTERFACE, MARSHALLERSTRATEGY_CLASS_INTERNAL_TYPE, "getMarshaller", MARSHALLERSTRATEGY_GET_MARSHALLER_SIGNATURE); mv.visitVarInsn(ASTORE, 8); mv.visitVarInsn(ALOAD, 8); // Search marshaller for property type mv.visitJumpInsn(IFNONNULL, labelNonNull); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, className, toFinalFieldName("component", propertyDescriptor), CHEATINGPROPERTYDESCRIPTOR_CLASS_DESCRIPTOR); mv.visitMethodInsn(INVOKEVIRTUAL, SUPER_CLASS_INTERNAL_TYPE, "findMarshaller", MARSHALLER_FIND_MARSHALLER_SIGNATURE); mv.visitVarInsn(ASTORE, 8); // Save marshaller to field mv.visitLabel(labelNonNull); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 8); mv.visitFieldInsn(PUTFIELD, className, toFinalFieldName("marshaller", propertyDescriptor), MARSHALLER_CLASS_DESCRIPTOR); } else { // Check if marshaller is defined mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, className, toFinalFieldName("descriptor", propertyDescriptor), PROPERTYDESCRIPTOR_CLASS_DESCRIPTOR); mv.visitMethodInsn(INVOKEVIRTUAL, SUPER_CLASS_INTERNAL_TYPE, "findMarshaller", MARSHALLER_FIND_MARSHALLER_SIGNATURE); mv.visitFieldInsn(PUTFIELD, className, fieldName, MARSHALLER_CLASS_DESCRIPTOR); } // Load this to method stack mv.visitVarInsn(ALOAD, 0); mv.visitInsn(DUP); // Load property accessor mv.visitFieldInsn(GETFIELD, className, toFinalFieldName("descriptor", propertyDescriptor), PROPERTYDESCRIPTOR_CLASS_DESCRIPTOR); mv.visitMethodInsn(INVOKEINTERFACE, PROPERTYDESCRIPTOR_CLASS_INTERNAL_TYPE, "getPropertyAccessor", PROPERTY_DESCRIPTOR_GET_PROPERTYACCESSOR_SIGNATURE); // Save PropertyAccessor to field mv.visitFieldInsn(PUTFIELD, className, toFinalFieldName("accessor", propertyDescriptor), PROPERTYACCESSOR_CLASS_DESCRIPTOR); } mv.visitInsn(RETURN); mv.visitMaxs(-1, 12); mv.visitEnd(); }
From source file:org.ballerinalang.nativeimpl.jvm.methodvisitor.VisitIntInsn.java
License:Open Source License
public static void visitIntInsn(Strand strand, ObjectValue oMv, long opCode, long operand) { MethodVisitor mv = ASMUtil.getRefArgumentNativeData(oMv); mv.visitIntInsn((int) opCode, (int) operand); }
From source file:org.cacheonix.impl.transformer.CacheonixMethodGenerator.java
License:LGPL
/** * Generates the byte instructions for the Aggregate key generated to be used by the Cacheonix cache * * @param mv MethodVisitor that writes byte instructions * @param types array of Method arguments Types * @param stackFrame Contains the offset for the local variables in the generated method * @param list/*from w w w . ja v a2s.co m*/ * @param strSyntheticKey */ private static void generateKeyAggregationSequence(final MethodVisitor mv, final Type[] types, final LocalStackUtil stackFrame, final String strSyntheticKey, final List<Integer> list) { final String strGeneratorKey = "org/cacheonix/impl/transformer/GeneratedKey"; mv.visitTypeInsn(NEW, strGeneratorKey); mv.visitInsn(DUP); int keyElements = 1; //For Synthetic key keyElements += list.size(); mv.visitIntInsn(BIPUSH, keyElements); mv.visitTypeInsn(ANEWARRAY, "java/lang/Object"); //Add Synthetic key to the GeneratorKey mv.visitInsn(DUP); mv.visitIntInsn(BIPUSH, 0); final Type tpString = Type.getType(String.class); mv.visitLdcInsn(strSyntheticKey); // Call function String argDescriptor = getKeyGenArgumentDescrStr(tpString); mv.visitMethodInsn(INVOKESTATIC, strGeneratorKey, "addKeyElement", argDescriptor); // Push (store) result to the stack mv.visitInsn(AASTORE); for (int i = 0, j = 1; i < list.size(); ++i, ++j) { //Get the argument index which is marked with @CacheKey final int argTypeIndex = list.get(i).intValue(); mv.visitInsn(DUP); mv.visitIntInsn(BIPUSH, j); final ByteInstruction bi = ByteInstruction.getByteInstructionAt(argTypeIndex, types); mv.visitVarInsn(bi.code, bi.stackIndex); // Call function argDescriptor = getKeyGenArgumentDescrStr(types[argTypeIndex]); mv.visitMethodInsn(INVOKESTATIC, strGeneratorKey, "addKeyElement", argDescriptor); // Push (store) result to the stack mv.visitInsn(AASTORE); // --- } // Call Constructor function with array of arguments mv.visitMethodInsn(INVOKESPECIAL, strGeneratorKey, "<init>", "([Ljava/lang/Object;)V"); // Store new GeneratedKey to Local () mv.visitVarInsn(ASTORE, stackFrame.getKeyGenLocalStackPos()); }
From source file:org.chromium.bytecode.CustomResourcesClassAdapter.java
License:Open Source License
/** * Generates://from ww w.j a v a 2s . c o m * * <pre> * public Context createConfigurationContext(Configuration configuration) { * // createConfigurationContext does not exist before API level 17. * if (Build.VERSION.SDK_INT < 17) return null; * if (!BuildHooksAndroid.isEnabled()) return super.createConfigurationContext(configuration); * return BuildHooksAndroid.createConfigurationContext( * super.createConfigurationContext(configuration)); * } * </pre> * } */ private void delegateCreateConfigurationContext() { String methodName = "createConfigurationContext"; String methodDescriptor = TypeUtils.getMethodDescriptor(CONTEXT, CONFIGURATION); MethodVisitor mv = super.visitMethod(ACC_PUBLIC, methodName, methodDescriptor, null, null); mv.visitCode(); mv.visitFieldInsn(GETSTATIC, "android/os/Build$VERSION", "SDK_INT", INT); mv.visitIntInsn(BIPUSH, 17); Label l0 = new Label(); mv.visitJumpInsn(IF_ICMPGE, l0); mv.visitInsn(ACONST_NULL); mv.visitInsn(ARETURN); mv.visitLabel(l0); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitMethodInsn(INVOKESTATIC, BUILD_HOOKS_ANDROID, IS_ENABLED_METHOD, IS_ENABLED_DESCRIPTOR, false); Label l1 = new Label(); mv.visitJumpInsn(IFNE, l1); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 1); mv.visitMethodInsn(INVOKESPECIAL, mSuperClassName, methodName, methodDescriptor, false); mv.visitInsn(ARETURN); mv.visitLabel(l1); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 1); mv.visitMethodInsn(INVOKESPECIAL, mSuperClassName, methodName, methodDescriptor, false); mv.visitMethodInsn(INVOKESTATIC, BUILD_HOOKS_ANDROID, methodName, TypeUtils.getMethodDescriptor(CONTEXT, CONTEXT), false); mv.visitInsn(ARETURN); mv.visitMaxs(2, 2); mv.visitEnd(); }
From source file:org.codehaus.aspectwerkz.transform.inlining.AsmHelper.java
License:Open Source License
/** * Creates and adds the correct parameter index for integer types. * * @param cv/* w w w .j a v a2 s . c o m*/ * @param index */ public static void loadIntegerConstant(final MethodVisitor cv, final int index) { switch (index) { case 0: cv.visitInsn(ICONST_0); break; case 1: cv.visitInsn(ICONST_1); break; case 2: cv.visitInsn(ICONST_2); break; case 3: cv.visitInsn(ICONST_3); break; case 4: cv.visitInsn(ICONST_4); break; case 5: cv.visitInsn(ICONST_5); break; default: cv.visitIntInsn(BIPUSH, index); break; } }
From source file:org.codehaus.groovy.classgen.asm.BytecodeHelper.java
License:Apache License
public static void pushConstant(MethodVisitor mv, int value) { switch (value) { case 0:// ww w . j a va 2s . c o m mv.visitInsn(ICONST_0); break; case 1: mv.visitInsn(ICONST_1); break; case 2: mv.visitInsn(ICONST_2); break; case 3: mv.visitInsn(ICONST_3); break; case 4: mv.visitInsn(ICONST_4); break; case 5: mv.visitInsn(ICONST_5); break; default: if (value >= Byte.MIN_VALUE && value <= Byte.MAX_VALUE) { mv.visitIntInsn(BIPUSH, value); } else if (value >= Short.MIN_VALUE && value <= Short.MAX_VALUE) { mv.visitIntInsn(SIPUSH, value); } else { mv.visitLdcInsn(value); } } }