protected void instrumentSetClassName(ClassReader cr,MethodVisitor mv){ mv.visitFieldInsn(Opcodes.GETSTATIC, cr.getClassName(), "className", "Ljava/lang/ThreadLocal;"); mv.visitLdcInsn(cr.getClassName().replace('/', '.')); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/ThreadLocal", "set", "(Ljava/lang/Object;)V",false); }
/** * Visits an annotation of this method. * * @param desc * the class descriptor of the annotation class. * @param visible * <tt>true</tt> if the annotation is visible at runtime. * @return a visitor to visit the annotation values, or <tt>null</tt> if * this visitor is not interested in visiting this annotation. */ public AnnotationVisitor visitAnnotation(String desc, boolean visible) { if (mv != null) { return mv.visitAnnotation(desc, visible); } return null; }
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(); }
public void aconst(final Object cst) { if (cst == null) { mv.visitInsn(Opcodes.ACONST_NULL); } else { mv.visitLdcInsn(cst); } }
public void iconst(final int cst) { if (cst >= -1 && cst <= 5) { mv.visitInsn(Opcodes.ICONST_0 + cst); } else if (cst >= Byte.MIN_VALUE && cst <= Byte.MAX_VALUE) { mv.visitIntInsn(Opcodes.BIPUSH, cst); } else if (cst >= Short.MIN_VALUE && cst <= Short.MAX_VALUE) { mv.visitIntInsn(Opcodes.SIPUSH, cst); } else { mv.visitLdcInsn(new Integer(cst)); } }
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 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.visitTableSwitchInsn(0, labels.length - 1, defaultLabel, labels); mv.visitLabel(labels[i]); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitVarInsn(ALOAD, 1); mv.visitTypeInsn(CHECKCAST, classNameInternal); mv.visitFieldInsn(Opcodes.GETSTATIC, classNameInternal, field.getName(), Type.getDescriptor(field.getType())); }else{ mv.visitFieldInsn(GETFIELD, classNameInternal, field.getName(), Type.getDescriptor(field.getType())); switch (fieldType.getSort()) { case Type.BOOLEAN: mv.visitMethodInsn(INVOKESTATIC, "java/lang/Boolean", "valueOf", "(Z)Ljava/lang/Boolean;"); break; case Type.BYTE: mv.visitMethodInsn(INVOKESTATIC, "java/lang/Byte", "valueOf", "(B)Ljava/lang/Byte;"); break; case Type.CHAR: mv.visitMethodInsn(INVOKESTATIC, "java/lang/Character", "valueOf", "(C)Ljava/lang/Character;"); break; case Type.SHORT: mv.visitMethodInsn(INVOKESTATIC, "java/lang/Short", "valueOf", "(S)Ljava/lang/Short;"); break; case Type.INT:
Label handler = readLabel(readUnsignedShort(u + 6), labels); String type = readUTF8(items[readUnsignedShort(u + 8)], c); mv.visitTryCatchBlock(start, end, handler, type); u += 8; mv.visitLabel(l); if ((context.flags & SKIP_DEBUG) == 0 && l.line > 0) { mv.visitLineNumber(l.line, l); mv.visitFrame(Opcodes.F_NEW, frame.localCount, frame.local, frame.stackCount, frame.stack); } else { mv.visitFrame(frame.mode, frame.localDiff, frame.local, frame.stackCount, frame.stack); switch (ClassWriter.TYPE[opcode]) { case ClassWriter.NOARG_INSN: mv.visitInsn(opcode); u += 1; break; if (opcode > Opcodes.ISTORE) { opcode -= 59; // ISTORE_0 mv.visitVarInsn(Opcodes.ISTORE + (opcode >> 2), opcode & 0x3); } else { opcode -= 26; // ILOAD_0 mv.visitVarInsn(Opcodes.ILOAD + (opcode >> 2), opcode & 0x3);
mv.visitCode(); Label l0 = new Label(); mv.visitLabel(l0); mv.visitVarInsn(ALOAD, 1); mv.visitTypeInsn(CHECKCAST, "[" + primitiveInternalName); mv.visitInsn(Opcodes.ARRAYLENGTH); mv.visitInsn(Opcodes.IRETURN); Label l1 = new Label(); mv.visitLabel(l1); mv.visitLocalVariable("this", A_CLASS_NAME, null, l0, l1, 0); mv.visitLocalVariable("array", "Ljava/lang/Object;", null, l0, l1, 1); mv.visitMaxs(1, 2); mv.visitEnd(); }else{ mv.visitCode(); Label l0 = new Label(); mv.visitLabel(l0); mv.visitVarInsn(ALOAD, 1); mv.visitTypeInsn(CHECKCAST, "[Ljava/lang/Object;"); mv.visitInsn(Opcodes.ARRAYLENGTH); mv.visitInsn(Opcodes.IRETURN); Label l1 = new Label(); mv.visitLabel(l1); mv.visitLocalVariable("this", A_CLASS_NAME, null, l0, l1, 0); mv.visitLocalVariable("array", "Ljava/lang/Object;", null, l0, l1, 1); mv.visitMaxs(1, 2); mv.visitEnd();
for (i = 0; i < n; i++) { ParameterNode parameter = parameters.get(i); mv.visitParameter(parameter.name, parameter.access); AnnotationVisitor av = mv.visitAnnotationDefault(); AnnotationNode.accept(av, null, annotationDefault); if (av != null) { for (i = 0; i < n; ++i) { AnnotationNode an = visibleAnnotations.get(i); an.accept(mv.visitAnnotation(an.desc, true)); an.accept(mv.visitAnnotation(an.desc, false)); an.accept(mv.visitTypeAnnotation(an.typeRef, an.typePath, an.desc, true)); for (i = 0; i < n; ++i) { TypeAnnotationNode an = invisibleTypeAnnotations.get(i); an.accept(mv.visitTypeAnnotation(an.typeRef, an.typePath, an.desc, false)); an.accept(mv.visitParameterAnnotation(i, an.desc, true)); an.accept(mv.visitParameterAnnotation(i, an.desc, false)); mv.visitAttribute(attrs.get(i)); mv.visitCode();
@Override public void accept(final MethodVisitor mv) { mv.visitMethodInsn(opcode, owner, name, desc, itf); }
public void putstatic(final String owner, final String name, final String desc) { mv.visitFieldInsn(Opcodes.PUTSTATIC, owner, name, desc); }
mv.visitInsn(Opcodes.ACONST_NULL); } else { switch (value.getSort()) { case Type.BOOLEAN: mv.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/Boolean", "TYPE", CLDESC); break; case Type.CHAR: mv.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/Character", "TYPE", CLDESC); break; case Type.BYTE: mv.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/Byte", "TYPE", CLDESC); break; case Type.SHORT: mv.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/Short", "TYPE", CLDESC); break; case Type.INT: mv.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/Integer", "TYPE", CLDESC); break; case Type.FLOAT: mv.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/Float", "TYPE", CLDESC); break; case Type.LONG: mv.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/Long", "TYPE",
mv.visitParameter(readUTF8(v, c), readUnsignedShort(v + 2)); AnnotationVisitor dv = mv.visitAnnotationDefault(); readAnnotationValue(dann, c, null, dv); if (dv != null) { for (int i = readUnsignedShort(anns), v = anns + 2; i > 0; --i) { v = readAnnotationValues(v + 2, c, true, mv.visitAnnotation(readUTF8(v, c), true)); for (int i = readUnsignedShort(ianns), v = ianns + 2; i > 0; --i) { v = readAnnotationValues(v + 2, c, true, mv.visitAnnotation(readUTF8(v, c), false)); v = readAnnotationTarget(context, v); v = readAnnotationValues(v + 2, c, true, mv.visitTypeAnnotation(context.typeRef, context.typePath, readUTF8(v, c), true)); v = readAnnotationTarget(context, v); v = readAnnotationValues(v + 2, c, true, mv.visitTypeAnnotation(context.typeRef, context.typePath, readUTF8(v, c), false)); Attribute attr = attributes.next; attributes.next = null; mv.visitAttribute(attributes); attributes = attr;
/** * Generates the instruction to push a handle on the stack. * * @param handle * the handle to be pushed on the stack. */ public void push(final Handle handle) { mv.visitLdcInsn(handle); }
@Override public void visitCode() { super.visitCode(); mv.visitLdcInsn(PROVIDER_TYPE); mv.visitMethodInsn(Opcodes.INVOKESTATIC, "leap/lang/Factory", "getInstance", "(Ljava/lang/Class;)Ljava/lang/Object;", false); checkCast(PROVIDER_TYPE); putStatic(type, PROVIDER_FIELD, PROVIDER_TYPE); } }
protected void instrumentRemoveClassName(ClassReader cr,MethodVisitor mv){ mv.visitFieldInsn(Opcodes.GETSTATIC, cr.getClassName(), "className", "Ljava/lang/ThreadLocal;"); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/ThreadLocal", "remove", "()V",false); }
/** * 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); }
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); } }
/** * Marks the current code position with the given label. * * @param label * a label. */ public void mark(final Label label) { mv.visitLabel(label); }