List of usage examples for org.objectweb.asm Opcodes ILOAD
int ILOAD
To view the source code for org.objectweb.asm Opcodes ILOAD.
Click Source Link
From source file:org.apache.felix.scrplugin.helper.ClassModifier.java
License:Apache License
private static void createMethod(final ClassWriter cw, final String className, final String referenceName, final String fieldName, final String typeName, final boolean bind) { final org.objectweb.asm.Type type = org.objectweb.asm.Type.getType("L" + typeName.replace('.', '/') + ";"); final String methodName = (bind ? "" : "un") + "bind" + referenceName.substring(0, 1).toUpperCase() + referenceName.substring(1); final MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PROTECTED, methodName, "(" + type.toString() + ")V", null, null);/*from ww w .j ava 2 s . c o m*/ mv.visitVarInsn(Opcodes.ALOAD, 0); if (bind) { mv.visitVarInsn(type.getOpcode(Opcodes.ILOAD), 1); mv.visitFieldInsn(Opcodes.PUTFIELD, className.replace('.', '/'), fieldName, type.toString()); } else { mv.visitFieldInsn(Opcodes.GETFIELD, className.replace('.', '/'), fieldName, type.toString()); mv.visitVarInsn(Opcodes.ALOAD, 1); final Label jmpLabel = new Label(); mv.visitJumpInsn(Opcodes.IF_ACMPNE, jmpLabel); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitInsn(Opcodes.ACONST_NULL); mv.visitFieldInsn(Opcodes.PUTFIELD, className.replace('.', '/'), fieldName, type.toString()); mv.visitLabel(jmpLabel); } mv.visitInsn(Opcodes.RETURN); mv.visitMaxs(2, 2); }
From source file:org.apache.felix.scrplugin.tags.qdox.QDoxJavaClassDescription.java
License:Apache License
protected void createMethod(ClassWriter cw, String propertyName, String typeName, boolean bind) { final org.objectweb.asm.Type type = org.objectweb.asm.Type.getType("L" + typeName.replace('.', '/') + ";"); final String methodName = (bind ? "" : "un") + "bind" + propertyName.substring(0, 1).toUpperCase() + propertyName.substring(1); MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PROTECTED, methodName, "(" + type.toString() + ")V", null, null);/* www. ja va2 s . co m*/ mv.visitVarInsn(Opcodes.ALOAD, 0); if (bind) { mv.visitVarInsn(type.getOpcode(Opcodes.ILOAD), 1); mv.visitFieldInsn(Opcodes.PUTFIELD, this.getName().replace('.', '/'), propertyName, type.toString()); } else { mv.visitFieldInsn(Opcodes.GETFIELD, this.getName().replace('.', '/'), propertyName, type.toString()); mv.visitVarInsn(Opcodes.ALOAD, 1); final Label jmpLabel = new Label(); mv.visitJumpInsn(Opcodes.IF_ACMPNE, jmpLabel); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitInsn(Opcodes.ACONST_NULL); mv.visitFieldInsn(Opcodes.PUTFIELD, this.getName().replace('.', '/'), propertyName, type.toString()); mv.visitLabel(jmpLabel); } mv.visitInsn(Opcodes.RETURN); mv.visitMaxs(2, 2); // add to qdox final JavaParameter param = new JavaParameter(new Type(typeName), "param"); final JavaParameter[] params = new JavaParameter[] { param }; final com.thoughtworks.qdox.model.JavaMethod meth = new com.thoughtworks.qdox.model.JavaMethod(); meth.setName(methodName); for (int i = 0; i < params.length; i++) { meth.addParameter(params[i]); } meth.setModifiers(new String[] { "protected" }); this.javaClass.addMethod(meth); }
From source file:org.apache.maven.shared.dependency.analyzer.asm.DependencyVisitorTest.java
License:Apache License
public void testVisitVarInsn() { visitor.visitVarInsn(Opcodes.ILOAD, 0); assertNoClasses(); }
From source file:org.apache.tuscany.sca.interfacedef.java.jaxrs.CodeGenerationHelper.java
License:Apache License
public static int getLoadOPCode(String signature) { if ("Z".equals(signature) || "B".equals(signature) || "C".equals(signature) || "S".equals(signature) || "I".equals(signature)) { return Opcodes.ILOAD; }/* w w w .j av a 2 s. c o m*/ if ("J".equals(signature)) { return Opcodes.LLOAD; } if ("F".equals(signature)) { return Opcodes.FLOAD; } if ("D".equals(signature)) { return Opcodes.DLOAD; } return Opcodes.ALOAD; }
From source file:org.batoo.jpa.core.impl.instance.Enhancer.java
License:Open Source License
private static void createContainerConstructor(final String enhancingClassName, final String enhancedClassName, final String descEnhancer, final ClassWriter cw) { final MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, Enhancer.CONSTRUCTOR_INIT, Enhancer.makeDescription(Void.TYPE, Class.class, SessionImpl.class, Object.class, Boolean.TYPE), null, null);// w ww . j a v a2 s .c o m mv.visitCode(); final Label l0 = new Label(); mv.visitLabel(l0); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, enhancingClassName, Enhancer.CONSTRUCTOR_INIT, Enhancer.makeDescription(Void.TYPE)); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitFieldInsn(Opcodes.PUTFIELD, enhancedClassName, Enhancer.FIELD_ENHANCED_TYPE, Enhancer.DESCRIPTOR_CLASS); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitVarInsn(Opcodes.ALOAD, 2); mv.visitFieldInsn(Opcodes.PUTFIELD, enhancedClassName, Enhancer.FIELD_ENHANCED_SESSION, Enhancer.DESCRIPTOR_SESSION); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitVarInsn(Opcodes.ALOAD, 3); mv.visitFieldInsn(Opcodes.PUTFIELD, enhancedClassName, Enhancer.FIELD_ENHANCED_ID, Enhancer.DESCRIPTOR_OBJECT); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitVarInsn(Opcodes.ILOAD, 4); mv.visitFieldInsn(Opcodes.PUTFIELD, enhancedClassName, Enhancer.FIELD_ENHANCED_INITIALIZED, Enhancer.DESCRIPTOR_BOOLEAN); mv.visitInsn(Opcodes.RETURN); final Label l1 = new Label(); mv.visitLabel(l1); mv.visitLocalVariable(Enhancer.THIS, descEnhancer, null, l0, l1, 0); mv.visitLocalVariable("type", Enhancer.DESCRIPTOR_CLASS, null, l0, l1, 1); mv.visitLocalVariable("session", Enhancer.DESCRIPTOR_SESSION, null, l0, l1, 2); mv.visitLocalVariable("id", Enhancer.DESCRIPTOR_OBJECT, null, l0, l1, 3); mv.visitLocalVariable("initialized", Enhancer.DESCRIPTOR_BOOLEAN, null, l0, l1, 4); mv.visitMaxs(0, 0); mv.visitEnd(); }
From source file:org.batoo.jpa.core.impl.instance.Enhancer.java
License:Open Source License
private static void createMethodSetInternal(final String enhancedClassName, final String descEnhancer, final ClassWriter cw) { final MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, Enhancer.METHOD_ENHANCED_SET_INTERNAL, Enhancer.makeDescription(Void.TYPE, Boolean.TYPE), null, null); mv.visitCode();//from w w w . jav a2s.c o m final Label l0 = new Label(); mv.visitLabel(l0); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitVarInsn(Opcodes.ILOAD, 1); mv.visitFieldInsn(Opcodes.PUTFIELD, enhancedClassName, Enhancer.FIELD_ENHANCED_INTERNAL, Enhancer.DESCRIPTOR_BOOLEAN); mv.visitInsn(Opcodes.RETURN); final Label l1 = new Label(); mv.visitLabel(l1); mv.visitLocalVariable(Enhancer.THIS, descEnhancer, null, l0, l1, 0); mv.visitLocalVariable("internal", Enhancer.DESCRIPTOR_BOOLEAN, null, l0, l1, 1); mv.visitMaxs(0, 0); mv.visitEnd(); // final MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "__enhanced__$$__setInternalCall", "(Z)V", null, null); // mv.visitCode(); // final Label l0 = new Label(); // mv.visitLabel(l0); // mv.visitLineNumber(81, l0); // mv.visitVarInsn(Opcodes.ALOAD, 0); // mv.visitVarInsn(Opcodes.ILOAD, 1); // mv.visitFieldInsn(Opcodes.PUTFIELD, descEnhancer, Enhancer.FIELD_ENHANCED_INTERNAL, Enhancer.DESCRIPTOR_BOOLEAN); // final Label l1 = new Label(); // mv.visitLabel(l1); // mv.visitLineNumber(82, l1); // mv.visitInsn(Opcodes.RETURN); // final Label l2 = new Label(); // mv.visitLabel(l2); // mv.visitLocalVariable("this", descEnhancer, null, l0, l2, 0); // mv.visitLocalVariable("internal", "Z", null, l0, l2, 1); // mv.visitMaxs(2, 2); // mv.visitEnd(); }
From source file:org.batoo.jpa.core.impl.instance.Enhancer.java
License:Open Source License
private static int getLoadType(Class<?> paramClass) { if (!paramClass.isPrimitive() || paramClass.isArray()) { return Opcodes.ALOAD; }// w w w.j a v a 2 s .co m if (Long.TYPE == paramClass) { return Opcodes.LLOAD; } if (Float.TYPE == paramClass) { return Opcodes.FLOAD; } if (Double.TYPE == paramClass) { return Opcodes.DLOAD; } return Opcodes.ILOAD; }
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()/*from w w w . j av a 2s.co 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 VarInsnNode getLoadInst(Type type, int position) { int opCode = -1; switch (type.getDescriptor().charAt(0)) { case 'B': opCode = Opcodes.ILOAD; break;//from w ww . j a va 2 s . c o m case 'C': opCode = Opcodes.ILOAD; break; case 'D': opCode = Opcodes.DLOAD; break; case 'F': opCode = Opcodes.FLOAD; break; case 'I': opCode = Opcodes.ILOAD; break; case 'J': opCode = Opcodes.LLOAD; break; case 'L': opCode = Opcodes.ALOAD; break; case '[': opCode = Opcodes.ALOAD; break; case 'Z': opCode = Opcodes.ILOAD; break; case 'S': opCode = Opcodes.ILOAD; break; default: throw new ClassFormatError("Invalid method signature: " + type.getDescriptor()); } return new VarInsnNode(opCode, position); }
From source file:org.cacheonix.impl.transformer.ByteInstruction.java
License:LGPL
/** * Computes the Opcode instruction for a given Type <code><code>org.objectweb.asm.Type</code> * * @param bi ByteInstruction class that contains the ByteCode and StackIndex * @param t instruction for Type <code><code>org.objectweb.asm.Type</code> *//*from ww w . ja v a 2 s.co m*/ public static void getInstruction(final ByteInstruction bi, final Type t) { bi.code = t.getOpcode(Opcodes.ILOAD); bi.stackIndex = bi.nextStackIndex; bi.nextStackIndex += t.getSize(); }