Class MethodWeaver

  • All Implemented Interfaces:
    org.eclipse.persistence.internal.libraries.asm.Opcodes

    public class MethodWeaver
    extends org.eclipse.persistence.internal.libraries.asm.EclipseLinkMethodVisitor
    implements org.eclipse.persistence.internal.libraries.asm.Opcodes
    Processes all the methods of a class to weave in persistence code such as, lazy value holder, change tracking and fetch groups. For FIELD access, changes references to GETFIELD and PUTFIELD to call weaved get/set methods. For Property access, modifies the getters and setters.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected String methodDescriptor  
      protected String methodName  
      protected boolean methodStarted
      Determines if we are at the first line of a method.
      protected ClassWeaver tcw  
      • Fields inherited from class org.eclipse.persistence.internal.libraries.asm.MethodVisitor

        api, mv
      • Fields inherited from interface org.eclipse.persistence.internal.libraries.asm.Opcodes

        AALOAD, AASTORE, ACC_ABSTRACT, ACC_ANNOTATION, ACC_BRIDGE, ACC_DEPRECATED, ACC_ENUM, ACC_FINAL, ACC_INTERFACE, ACC_MANDATED, ACC_MODULE, ACC_NATIVE, ACC_OPEN, ACC_PRIVATE, ACC_PROTECTED, ACC_PUBLIC, ACC_RECORD, ACC_STATIC, ACC_STATIC_PHASE, ACC_STRICT, ACC_SUPER, ACC_SYNCHRONIZED, ACC_SYNTHETIC, ACC_TRANSIENT, ACC_TRANSITIVE, ACC_VARARGS, ACC_VOLATILE, ACONST_NULL, ALOAD, ANEWARRAY, ARETURN, ARRAYLENGTH, ASM10_EXPERIMENTAL, ASM4, ASM5, ASM6, ASM7, ASM8, ASM9, ASTORE, ATHROW, BALOAD, BASTORE, BIPUSH, CALOAD, CASTORE, CHECKCAST, D2F, D2I, D2L, DADD, DALOAD, DASTORE, DCMPG, DCMPL, DCONST_0, DCONST_1, DDIV, DLOAD, DMUL, DNEG, DOUBLE, DREM, DRETURN, DSTORE, DSUB, DUP, DUP_X1, DUP_X2, DUP2, DUP2_X1, DUP2_X2, F_APPEND, F_CHOP, F_FULL, F_NEW, F_SAME, F_SAME1, F2D, F2I, F2L, FADD, FALOAD, FASTORE, FCMPG, FCMPL, FCONST_0, FCONST_1, FCONST_2, FDIV, FLOAD, FLOAT, FMUL, FNEG, FREM, FRETURN, FSTORE, FSUB, GETFIELD, GETSTATIC, GOTO, H_GETFIELD, H_GETSTATIC, H_INVOKEINTERFACE, H_INVOKESPECIAL, H_INVOKESTATIC, H_INVOKEVIRTUAL, H_NEWINVOKESPECIAL, H_PUTFIELD, H_PUTSTATIC, I2B, I2C, I2D, I2F, I2L, I2S, IADD, IALOAD, IAND, IASTORE, ICONST_0, ICONST_1, ICONST_2, ICONST_3, ICONST_4, ICONST_5, ICONST_M1, IDIV, IF_ACMPEQ, IF_ACMPNE, IF_ICMPEQ, IF_ICMPGE, IF_ICMPGT, IF_ICMPLE, IF_ICMPLT, IF_ICMPNE, IFEQ, IFGE, IFGT, IFLE, IFLT, IFNE, IFNONNULL, IFNULL, IINC, ILOAD, IMUL, INEG, INSTANCEOF, INTEGER, INVOKEDYNAMIC, INVOKEINTERFACE, INVOKESPECIAL, INVOKESTATIC, INVOKEVIRTUAL, IOR, IREM, IRETURN, ISHL, ISHR, ISTORE, ISUB, IUSHR, IXOR, JSR, L2D, L2F, L2I, LADD, LALOAD, LAND, LASTORE, LCMP, LCONST_0, LCONST_1, LDC, LDIV, LLOAD, LMUL, LNEG, LONG, LOOKUPSWITCH, LOR, LREM, LRETURN, LSHL, LSHR, LSTORE, LSUB, LUSHR, LXOR, MONITORENTER, MONITOREXIT, MULTIANEWARRAY, NEW, NEWARRAY, NOP, NULL, POP, POP2, PUTFIELD, PUTSTATIC, RET, RETURN, SALOAD, SASTORE, SIPUSH, SOURCE_DEPRECATED, SOURCE_MASK, SWAP, T_BOOLEAN, T_BYTE, T_CHAR, T_DOUBLE, T_FLOAT, T_INT, T_LONG, T_SHORT, TABLESWITCH, TOP, UNINITIALIZED_THIS, V_PREVIEW, V1_1, V1_2, V1_3, V1_4, V1_5, V1_6, V1_7, V1_8, V10, V11, V12, V13, V14, V15, V16, V17, V18, V19, V20, V21, V22, V9
    • Constructor Summary

      Constructors 
      Constructor Description
      MethodWeaver​(ClassWeaver tcw, String methodName, String methodDescriptor, org.eclipse.persistence.internal.libraries.asm.MethodVisitor mv)  
    • Field Detail

      • methodName

        protected String methodName
      • methodDescriptor

        protected String methodDescriptor
      • methodStarted

        protected boolean methodStarted
        Determines if we are at the first line of a method.
    • Constructor Detail

      • MethodWeaver

        public MethodWeaver​(ClassWeaver tcw,
                            String methodName,
                            String methodDescriptor,
                            org.eclipse.persistence.internal.libraries.asm.MethodVisitor mv)
    • Method Detail

      • visitInsn

        public void visitInsn​(int opcode)
        Overrides:
        visitInsn in class org.eclipse.persistence.internal.libraries.asm.MethodVisitor
      • visitIntInsn

        public void visitIntInsn​(int opcode,
                                 int operand)
        Overrides:
        visitIntInsn in class org.eclipse.persistence.internal.libraries.asm.MethodVisitor
      • visitVarInsn

        public void visitVarInsn​(int opcode,
                                 int var)
        Overrides:
        visitVarInsn in class org.eclipse.persistence.internal.libraries.asm.MethodVisitor
      • visitTypeInsn

        public void visitTypeInsn​(int opcode,
                                  String desc)
        Overrides:
        visitTypeInsn in class org.eclipse.persistence.internal.libraries.asm.MethodVisitor
      • visitFieldInsn

        public void visitFieldInsn​(int opcode,
                                   String owner,
                                   String name,
                                   String desc)
        Overrides:
        visitFieldInsn in class org.eclipse.persistence.internal.libraries.asm.MethodVisitor
      • visitMethodInsn

        public void visitMethodInsn​(int opcode,
                                    String owner,
                                    String name,
                                    String desc,
                                    boolean intf)
        Overrides:
        visitMethodInsn in class org.eclipse.persistence.internal.libraries.asm.MethodVisitor
      • visitJumpInsn

        public void visitJumpInsn​(int opcode,
                                  org.eclipse.persistence.internal.libraries.asm.Label label)
        Overrides:
        visitJumpInsn in class org.eclipse.persistence.internal.libraries.asm.MethodVisitor
      • visitLabel

        public void visitLabel​(org.eclipse.persistence.internal.libraries.asm.Label label)
        Overrides:
        visitLabel in class org.eclipse.persistence.internal.libraries.asm.MethodVisitor
      • visitLdcInsn

        public void visitLdcInsn​(Object cst)
        Overrides:
        visitLdcInsn in class org.eclipse.persistence.internal.libraries.asm.MethodVisitor
      • visitIincInsn

        public void visitIincInsn​(int var,
                                  int increment)
        Overrides:
        visitIincInsn in class org.eclipse.persistence.internal.libraries.asm.MethodVisitor
      • visitTableSwitchInsn

        public void visitTableSwitchInsn​(int min,
                                         int max,
                                         org.eclipse.persistence.internal.libraries.asm.Label dflt,
                                         org.eclipse.persistence.internal.libraries.asm.Label... labels)
        Overrides:
        visitTableSwitchInsn in class org.eclipse.persistence.internal.libraries.asm.MethodVisitor
      • visitLookupSwitchInsn

        public void visitLookupSwitchInsn​(org.eclipse.persistence.internal.libraries.asm.Label dflt,
                                          int[] keys,
                                          org.eclipse.persistence.internal.libraries.asm.Label[] labels)
        Overrides:
        visitLookupSwitchInsn in class org.eclipse.persistence.internal.libraries.asm.MethodVisitor
      • visitMultiANewArrayInsn

        public void visitMultiANewArrayInsn​(String desc,
                                            int dims)
        Overrides:
        visitMultiANewArrayInsn in class org.eclipse.persistence.internal.libraries.asm.MethodVisitor
      • visitTryCatchBlock

        public void visitTryCatchBlock​(org.eclipse.persistence.internal.libraries.asm.Label start,
                                       org.eclipse.persistence.internal.libraries.asm.Label end,
                                       org.eclipse.persistence.internal.libraries.asm.Label handler,
                                       String type)
        Overrides:
        visitTryCatchBlock in class org.eclipse.persistence.internal.libraries.asm.MethodVisitor
      • visitMaxs

        public void visitMaxs​(int maxStack,
                              int maxLocals)
        Overrides:
        visitMaxs in class org.eclipse.persistence.internal.libraries.asm.MethodVisitor
      • visitLocalVariable

        public void visitLocalVariable​(String name,
                                       String desc,
                                       String signature,
                                       org.eclipse.persistence.internal.libraries.asm.Label start,
                                       org.eclipse.persistence.internal.libraries.asm.Label end,
                                       int index)
        Overrides:
        visitLocalVariable in class org.eclipse.persistence.internal.libraries.asm.MethodVisitor
      • visitLineNumber

        public void visitLineNumber​(int line,
                                    org.eclipse.persistence.internal.libraries.asm.Label start)
        Overrides:
        visitLineNumber in class org.eclipse.persistence.internal.libraries.asm.MethodVisitor
      • visitAttribute

        public void visitAttribute​(org.eclipse.persistence.internal.libraries.asm.Attribute attr)
        Overrides:
        visitAttribute in class org.eclipse.persistence.internal.libraries.asm.MethodVisitor
      • weaveAttributesIfRequired

        public void weaveAttributesIfRequired​(int opcode,
                                              String owner,
                                              String name,
                                              String desc)
        Change GETFIELD and PUTFIELD for fields that use attribute access to make use of new convenience methods. A GETFIELD for an attribute named 'variableName' will be replaced by a call to: _persistence_get_variableName() A PUTFIELD for an attribute named 'variableName' will be replaced by a call to: _persistence_set_variableName(variableName)
      • weaveBeginningOfMethodIfRequired

        public void weaveBeginningOfMethodIfRequired()
        Makes modifications to the beginning of a method. 1. Modifies getter method for attributes using property access In a getter method for 'attributeName', the following lines are added at the beginning of the method _persistence_checkFetched("attributeName"); _persistence_initialize_attributeName_vh(); if (!_persistence_attributeName_vh.isInstantiated()) { PropertyChangeListener temp_persistence_listener = _persistence_listener; _persistence_listener = null; setAttributeName((AttributeType)_persistence_attributeName_vh.getValue()); _persistence_listener = temp_persistence_listener; } 2. Modifies setter methods to store old value of attribute If weaving for fetch groups: // if weaving for change tracking: if(_persistence_listener != null) // for Objects AttributeType oldAttribute = getAttribute() // for primitives AttributeWrapperType oldAttribute = new AttributeWrapperType(getAttribute()); e.g. Double oldAttribute = Double.valueOf(getAttribute()); else _persistence_checkFetchedForSet("attributeName"); _persistence_propertyChange("attributeName", oldAttribute, argument); otherwise (not weaving for fetch groups): // for Objects AttributeType oldAttribute = getAttribute() // for primitives AttributeWrapperType oldAttribute = new AttributeWrapperType(getAttribute()); e.g. Double oldAttribute = Double.valueOf(getAttribute()); _persistence_propertyChange("attributeName", oldAttribute, argument); // if not weaving for change tracking, but for fetch groups only: _persistence_checkFetchedForSet("attributeName"); 3. Modifies getter Method for attributes using virtual access add: _persistence_checkFetched(name); 4. Modifies setter Method for attributes using virtual access add code of the following form: Object obj = null; if(_persistence_listener != null){ obj = get(name); } else { _persistence_checkFetchedForSet(name); } _persistence_propertyChange(name, obj, value); _persistence_checkFetchedForSet(name) call will be excluded if weaving of fetch groups is not enabled _persistence_propertyChange(name, obj, value); will be excluded if weaving of change tracking is not enabled
      • weaveEndOfMethodIfRequired

        public void weaveEndOfMethodIfRequired()
        Modifies methods just before the return. In a setter method for a LAZY mapping, for 'attributeName', the following lines are added at the end of the method. _persistence_initialize_attributeName_vh(); _persistence_attributeName_vh.setValue(argument); _persistence_attributeName_vh.setIsCoordinatedWithProperty(true); In a setter method for a non-LAZY mapping, the followings lines are added if change tracking is activated: _persistence_propertyChange("attributeName", oldAttribute, argument); Note: This code will wrap primitives by adding a call to the primitive constructor.