/** * Generates a RET instruction. * * @param local * a local variable identifier, as returned by * {@link LocalVariablesSorter#newLocal(Type) newLocal()}. */ public void ret(final int local) { mv.visitVarInsn(Opcodes.RET, local); }
@Override public void visitVarInsn(final int opcode, final int var) { if (var < 4 && opcode != RET) { minSize += 1; maxSize += 1; } else if (var >= 256) { minSize += 4; maxSize += 4; } else { minSize += 2; maxSize += 2; } if (mv != null) { mv.visitVarInsn(opcode, var); } }
public void ret(final int var) { mv.visitVarInsn(Opcodes.RET, var); }
/** * Visits a local variable instruction. A local variable instruction is an * instruction that loads or stores the value of a local variable. * * @param opcode * the opcode of the local variable instruction to be visited. * This opcode is either ILOAD, LLOAD, FLOAD, DLOAD, ALOAD, * ISTORE, LSTORE, FSTORE, DSTORE, ASTORE or RET. * @param var * the operand of the instruction to be visited. This operand is * the index of a local variable. */ public void visitVarInsn(int opcode, int var) { if (mv != null) { mv.visitVarInsn(opcode, var); } }
/** * Generates the instruction to load 'this' on the stack. */ public void loadThis() { if ((access & Opcodes.ACC_STATIC) != 0) { throw new IllegalStateException( "no 'this' pointer within static method"); } mv.visitVarInsn(Opcodes.ALOAD, 0); }
@Override public void visitVarInsn(final int opcode, final int var) { if (mv != null) { mv.visitVarInsn(opcode, var); } execute(opcode, var, null); }
/** * Generates the instruction to push a local variable on the stack. * * @param type * the type of the local variable to be loaded. * @param index * an index in the frame's local variables array. */ private void loadInsn(final Type type, final int index) { mv.visitVarInsn(type.getOpcode(Opcodes.ILOAD), index); }
/** * Generates the instruction to store the top stack value in a local * variable. * * @param type * the type of the local variable to be stored. * @param index * an index in the frame's local variables array. */ private void storeInsn(final Type type, final int index) { mv.visitVarInsn(type.getOpcode(Opcodes.ISTORE), index); }
@Override public void visitVarInsn(final int opcode, final int var) { p.visitVarInsn(opcode, var); super.visitVarInsn(opcode, var); }
@Override public void accept(final MethodVisitor mv) { mv.visitVarInsn(opcode, var); acceptAnnotations(mv); }
public void load(final int var, final Type type) { mv.visitVarInsn(type.getOpcode(Opcodes.ILOAD), var); }
public void store(final int var, final Type type) { mv.visitVarInsn(type.getOpcode(Opcodes.ISTORE), var); }
@Override public void visitVarInsn(final int opcode, final int var) { Type type; switch (opcode) { case Opcodes.LLOAD: case Opcodes.LSTORE: type = Type.LONG_TYPE; break; case Opcodes.DLOAD: case Opcodes.DSTORE: type = Type.DOUBLE_TYPE; break; case Opcodes.FLOAD: case Opcodes.FSTORE: type = Type.FLOAT_TYPE; break; case Opcodes.ILOAD: case Opcodes.ISTORE: type = Type.INT_TYPE; break; default: // case Opcodes.ALOAD: // case Opcodes.ASTORE: // case RET: type = OBJECT_TYPE; break; } mv.visitVarInsn(opcode, remap(var, type)); }
protected void getTransactionManager() { if(!methodBodyOnly) { mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(GETFIELD, type.getInternalName(), MANAGER_FIELD, MANAGER_TYPE.getDescriptor()); }else{ invokeStatic(TxInst.TYPE,TxInst.MANAGER); } }
private static void defineAccessorConstructor(String accessorClassNameInternal,ClassWriter cw){ cw.visit(V1_6, ACC_PUBLIC, accessorClassNameInternal, null, CLASS_NAME, null); MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, CLASS_NAME, "<init>", "()V"); mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); }
private static void defineNewArray(Class<?> clazz, String classNameInternal,ClassWriter cw){ MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "newArray", "(I)Ljava/lang/Object;", null, null); Label l0 = new Label(); mv.visitLabel(l0); mv.visitVarInsn(ILOAD, 1); if(clazz.isPrimitive()){ mv.visitIntInsn(Opcodes.NEWARRAY,getPrimitiveTypeCode(clazz)); }else{ mv.visitTypeInsn(ANEWARRAY, classNameInternal); } mv.visitInsn(ARETURN); Label l1 = new Label(); mv.visitLabel(l1); mv.visitLocalVariable("this", A_CLASS_NAME, null, l0, l1, 0); mv.visitLocalVariable("length", "I", null, l0, l1, 1); mv.visitMaxs(1, 2); mv.visitEnd(); }
Label l0 = new Label(); mv.visitLabel(l0); mv.visitVarInsn(ALOAD, 1); mv.visitTypeInsn(CHECKCAST, "[" + primitiveInternalName); mv.visitVarInsn(ILOAD, 2); mv.visitVarInsn(ALOAD, 3); mv.visitTypeInsn(CHECKCAST, wraperTypeInternalName); mv.visitMethodInsn(INVOKEVIRTUAL, wraperTypeInternalName, unboxMethodName, "()" + primitiveInternalName); Label l0 = new Label(); mv.visitLabel(l0); mv.visitVarInsn(ALOAD, 1); mv.visitTypeInsn(CHECKCAST, "[Ljava/lang/Object;"); mv.visitVarInsn(ILOAD, 2); mv.visitVarInsn(ALOAD, 3); mv.visitInsn(Opcodes.AASTORE); Label l1 = new Label();
private static void defineGetField(String classNameInternal,Field[] fields, ClassWriter cw){ MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "getFieldValue", "(Ljava/lang/Object;I)Ljava/lang/Object;", null, null); mv.visitCode(); mv.visitVarInsn(ILOAD, 2); mv.visitVarInsn(ALOAD, 1); mv.visitTypeInsn(CHECKCAST, classNameInternal); mv.visitLdcInsn("Field not found: "); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/StringBuilder", "<init>", "(Ljava/lang/String;)V"); mv.visitVarInsn(ILOAD, 2); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(I)Ljava/lang/StringBuilder;"); mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "toString", "()Ljava/lang/String;");
Label l0 = new Label(); mv.visitLabel(l0); mv.visitVarInsn(ALOAD, 1); mv.visitTypeInsn(CHECKCAST, "[" + primitiveInternalName); mv.visitVarInsn(ILOAD, 2); mv.visitInsn(opcode); mv.visitMethodInsn(INVOKESTATIC, wraperTypeInternalName, "valueOf", "(" + primitiveInternalName + ")L" + wraperTypeInternalName + ";"); Label l0 = new Label(); mv.visitLabel(l0); mv.visitVarInsn(ALOAD, 1); mv.visitTypeInsn(CHECKCAST, "[Ljava/lang/Object;"); mv.visitVarInsn(ILOAD, 2); mv.visitInsn(AALOAD); mv.visitInsn(ARETURN);
Label l0 = new Label(); mv.visitLabel(l0); mv.visitVarInsn(ALOAD, 1); mv.visitTypeInsn(CHECKCAST, "[" + primitiveInternalName); mv.visitInsn(Opcodes.ARRAYLENGTH); Label l0 = new Label(); mv.visitLabel(l0); mv.visitVarInsn(ALOAD, 1); mv.visitTypeInsn(CHECKCAST, "[Ljava/lang/Object;"); mv.visitInsn(Opcodes.ARRAYLENGTH);