Search in sources :

Example 1 with Label

use of org.datanucleus.enhancer.asm.Label in project datanucleus-core by datanucleus.

the class EnhancerPropertyGetterAdapter method generateGetXXXMethod.

/**
 * Convenience method to use the MethodVisitor to generate the code for the method getXXX() for the property with the specified MetaData.
 * @param mv MethodVisitor
 * @param mmd MetaData for the property
 * @param asmClassName ASM class name for the owning class
 * @param asmClassDesc ASM descriptor for the owning class
 * @param detachListener true if the generate code must support DetachListener
 * @param namer Namer for methods etc
 */
public static void generateGetXXXMethod(MethodVisitor mv, AbstractMemberMetaData mmd, String asmClassName, String asmClassDesc, boolean detachListener, EnhancementNamer namer) {
    String[] argNames = new String[] { "this" };
    String fieldTypeDesc = Type.getDescriptor(mmd.getType());
    mv.visitCode();
    AbstractClassMetaData cmd = mmd.getAbstractClassMetaData();
    if ((mmd.getPersistenceFlags() & Persistable.MEDIATE_READ) == Persistable.MEDIATE_READ) {
        // MEDIATE_READ - see method GetViaMediate
        Label startLabel = new Label();
        mv.visitLabel(startLabel);
        mv.visitVarInsn(Opcodes.ALOAD, 0);
        mv.visitFieldInsn(Opcodes.GETFIELD, asmClassName, namer.getStateManagerFieldName(), "L" + namer.getStateManagerAsmClassName() + ";");
        Label l1 = new Label();
        mv.visitJumpInsn(Opcodes.IFNULL, l1);
        mv.visitVarInsn(Opcodes.ALOAD, 0);
        mv.visitFieldInsn(Opcodes.GETFIELD, asmClassName, namer.getStateManagerFieldName(), "L" + namer.getStateManagerAsmClassName() + ";");
        mv.visitVarInsn(Opcodes.ALOAD, 0);
        EnhanceUtils.addBIPUSHToMethod(mv, mmd.getFieldId());
        if (cmd.getPersistableSuperclass() != null) {
            mv.visitFieldInsn(Opcodes.GETSTATIC, asmClassName, namer.getInheritedFieldCountFieldName(), "I");
            mv.visitInsn(Opcodes.IADD);
        }
        mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, namer.getStateManagerAsmClassName(), "isLoaded", "(L" + namer.getPersistableAsmClassName() + ";I)Z");
        mv.visitJumpInsn(Opcodes.IFNE, l1);
        mv.visitVarInsn(Opcodes.ALOAD, 0);
        mv.visitFieldInsn(Opcodes.GETFIELD, asmClassName, namer.getStateManagerFieldName(), "L" + namer.getStateManagerAsmClassName() + ";");
        mv.visitVarInsn(Opcodes.ALOAD, 0);
        EnhanceUtils.addBIPUSHToMethod(mv, mmd.getFieldId());
        if (cmd.getPersistableSuperclass() != null) {
            mv.visitFieldInsn(Opcodes.GETSTATIC, asmClassName, namer.getInheritedFieldCountFieldName(), "I");
            mv.visitInsn(Opcodes.IADD);
        }
        mv.visitVarInsn(Opcodes.ALOAD, 0);
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, asmClassName, namer.getGetMethodPrefixMethodName() + mmd.getName(), "()" + fieldTypeDesc);
        String methodName = "get" + EnhanceUtils.getTypeNameForPersistableMethod(mmd.getType()) + "Field";
        String argTypeDesc = fieldTypeDesc;
        if (methodName.equals("getObjectField")) {
            argTypeDesc = EnhanceUtils.CD_Object;
        }
        mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, namer.getStateManagerAsmClassName(), methodName, "(L" + namer.getPersistableAsmClassName() + ";I" + argTypeDesc + ")" + argTypeDesc);
        if (methodName.equals("getObjectField")) {
            // Cast any object fields to the correct type
            mv.visitTypeInsn(Opcodes.CHECKCAST, mmd.getTypeName().replace('.', '/'));
        }
        EnhanceUtils.addReturnForType(mv, mmd.getType());
        mv.visitLabel(l1);
        mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
        if (cmd.isDetachable()) {
            // "if (objPC.dnIsDetached() != false && ((BitSet) objPC.dnDetachedState[2]).get(5) != true)"
            mv.visitVarInsn(Opcodes.ALOAD, 0);
            mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, asmClassName, namer.getIsDetachedMethodName(), "()Z");
            Label l4 = new Label();
            mv.visitJumpInsn(Opcodes.IFEQ, l4);
            mv.visitVarInsn(Opcodes.ALOAD, 0);
            mv.visitFieldInsn(Opcodes.GETFIELD, asmClassName, namer.getDetachedStateFieldName(), "[Ljava/lang/Object;");
            mv.visitInsn(Opcodes.ICONST_2);
            mv.visitInsn(Opcodes.AALOAD);
            mv.visitTypeInsn(Opcodes.CHECKCAST, "java/util/BitSet");
            EnhanceUtils.addBIPUSHToMethod(mv, mmd.getFieldId());
            if (cmd.getPersistableSuperclass() != null) {
                mv.visitFieldInsn(Opcodes.GETSTATIC, asmClassName, namer.getInheritedFieldCountFieldName(), "I");
                mv.visitInsn(Opcodes.IADD);
            }
            mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/util/BitSet", "get", "(I)Z");
            mv.visitJumpInsn(Opcodes.IFNE, l4);
            mv.visitVarInsn(Opcodes.ALOAD, 0);
            mv.visitFieldInsn(Opcodes.GETFIELD, asmClassName, namer.getDetachedStateFieldName(), "[Ljava/lang/Object;");
            mv.visitInsn(Opcodes.ICONST_3);
            mv.visitInsn(Opcodes.AALOAD);
            mv.visitTypeInsn(Opcodes.CHECKCAST, "java/util/BitSet");
            EnhanceUtils.addBIPUSHToMethod(mv, mmd.getFieldId());
            if (cmd.getPersistableSuperclass() != null) {
                mv.visitFieldInsn(Opcodes.GETSTATIC, asmClassName, namer.getInheritedFieldCountFieldName(), "I");
                mv.visitInsn(Opcodes.IADD);
            }
            mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/util/BitSet", "get", "(I)Z");
            mv.visitJumpInsn(Opcodes.IFNE, l4);
            if (detachListener) {
                mv.visitMethodInsn(Opcodes.INVOKESTATIC, namer.getDetachListenerAsmClassName(), "getInstance", "()L" + namer.getDetachListenerAsmClassName() + ";");
                mv.visitVarInsn(Opcodes.ALOAD, 0);
                mv.visitLdcInsn(mmd.getName());
                mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, namer.getDetachListenerAsmClassName(), "undetachedFieldAccess", "(Ljava/lang/Object;Ljava/lang/String;)V");
            } else {
                // "throw new JDODetachedFieldAccessException(...)"
                mv.visitTypeInsn(Opcodes.NEW, namer.getDetachedFieldAccessExceptionAsmClassName());
                mv.visitInsn(Opcodes.DUP);
                mv.visitLdcInsn(Localiser.msg("005026", mmd.getName()));
                mv.visitMethodInsn(Opcodes.INVOKESPECIAL, namer.getDetachedFieldAccessExceptionAsmClassName(), "<init>", "(Ljava/lang/String;)V");
                mv.visitInsn(Opcodes.ATHROW);
            }
            mv.visitLabel(l4);
            mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
        }
        mv.visitVarInsn(Opcodes.ALOAD, 0);
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, asmClassName, namer.getGetMethodPrefixMethodName() + mmd.getName(), "()" + fieldTypeDesc);
        EnhanceUtils.addReturnForType(mv, mmd.getType());
        Label endLabel = new Label();
        mv.visitLabel(endLabel);
        mv.visitLocalVariable(argNames[0], asmClassDesc, null, startLabel, endLabel, 0);
        mv.visitMaxs(4, 1);
    } else if ((mmd.getPersistenceFlags() & Persistable.CHECK_READ) == Persistable.CHECK_READ) {
        // CHECK_READ - see method GetViaCheck
        Label startLabel = new Label();
        mv.visitLabel(startLabel);
        mv.visitVarInsn(Opcodes.ALOAD, 0);
        mv.visitFieldInsn(Opcodes.GETFIELD, asmClassName, namer.getFlagsFieldName(), "B");
        Label l1 = new Label();
        mv.visitJumpInsn(Opcodes.IFLE, l1);
        mv.visitVarInsn(Opcodes.ALOAD, 0);
        mv.visitFieldInsn(Opcodes.GETFIELD, asmClassName, namer.getStateManagerFieldName(), "L" + namer.getStateManagerAsmClassName() + ";");
        mv.visitJumpInsn(Opcodes.IFNULL, l1);
        mv.visitVarInsn(Opcodes.ALOAD, 0);
        mv.visitFieldInsn(Opcodes.GETFIELD, asmClassName, namer.getStateManagerFieldName(), "L" + namer.getStateManagerAsmClassName() + ";");
        mv.visitVarInsn(Opcodes.ALOAD, 0);
        EnhanceUtils.addBIPUSHToMethod(mv, mmd.getFieldId());
        if (cmd.getPersistableSuperclass() != null) {
            mv.visitFieldInsn(Opcodes.GETSTATIC, asmClassName, namer.getInheritedFieldCountFieldName(), "I");
            mv.visitInsn(Opcodes.IADD);
        }
        mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, namer.getStateManagerAsmClassName(), "isLoaded", "(L" + namer.getPersistableAsmClassName() + ";I)Z");
        mv.visitJumpInsn(Opcodes.IFNE, l1);
        mv.visitVarInsn(Opcodes.ALOAD, 0);
        mv.visitFieldInsn(Opcodes.GETFIELD, asmClassName, namer.getStateManagerFieldName(), "L" + namer.getStateManagerAsmClassName() + ";");
        mv.visitVarInsn(Opcodes.ALOAD, 0);
        EnhanceUtils.addBIPUSHToMethod(mv, mmd.getFieldId());
        if (cmd.getPersistableSuperclass() != null) {
            mv.visitFieldInsn(Opcodes.GETSTATIC, asmClassName, namer.getInheritedFieldCountFieldName(), "I");
            mv.visitInsn(Opcodes.IADD);
        }
        mv.visitVarInsn(Opcodes.ALOAD, 0);
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, asmClassName, namer.getGetMethodPrefixMethodName() + mmd.getName(), "()" + fieldTypeDesc);
        String methodName = "get" + EnhanceUtils.getTypeNameForPersistableMethod(mmd.getType()) + "Field";
        String argTypeDesc = fieldTypeDesc;
        if (methodName.equals("getObjectField")) {
            argTypeDesc = EnhanceUtils.CD_Object;
        }
        mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, namer.getStateManagerAsmClassName(), methodName, "(L" + namer.getPersistableAsmClassName() + ";I" + argTypeDesc + ")" + argTypeDesc);
        if (methodName.equals("getObjectField")) {
            // Cast any object fields to the correct type
            mv.visitTypeInsn(Opcodes.CHECKCAST, mmd.getTypeName().replace('.', '/'));
        }
        EnhanceUtils.addReturnForType(mv, mmd.getType());
        mv.visitLabel(l1);
        mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
        if (cmd.isDetachable()) {
            // "if (objPC.dnIsDetached() != false && ((BitSet) objPC.dnDetachedState[2]).get(5) != true)"
            mv.visitVarInsn(Opcodes.ALOAD, 0);
            mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, asmClassName, namer.getIsDetachedMethodName(), "()Z");
            Label l4 = new Label();
            mv.visitJumpInsn(Opcodes.IFEQ, l4);
            mv.visitVarInsn(Opcodes.ALOAD, 0);
            mv.visitFieldInsn(Opcodes.GETFIELD, asmClassName, namer.getDetachedStateFieldName(), "[Ljava/lang/Object;");
            mv.visitInsn(Opcodes.ICONST_2);
            mv.visitInsn(Opcodes.AALOAD);
            mv.visitTypeInsn(Opcodes.CHECKCAST, "java/util/BitSet");
            EnhanceUtils.addBIPUSHToMethod(mv, mmd.getFieldId());
            if (cmd.getPersistableSuperclass() != null) {
                mv.visitFieldInsn(Opcodes.GETSTATIC, asmClassName, namer.getInheritedFieldCountFieldName(), "I");
                mv.visitInsn(Opcodes.IADD);
            }
            mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/util/BitSet", "get", "(I)Z");
            mv.visitJumpInsn(Opcodes.IFNE, l4);
            if (detachListener) {
                mv.visitMethodInsn(Opcodes.INVOKESTATIC, namer.getDetachListenerAsmClassName(), "getInstance", "()L" + namer.getDetachListenerAsmClassName() + ";");
                mv.visitVarInsn(Opcodes.ALOAD, 0);
                mv.visitLdcInsn(mmd.getName());
                mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, namer.getDetachListenerAsmClassName(), "undetachedFieldAccess", "(Ljava/lang/Object;Ljava/lang/String;)V");
            } else {
                // "throw new JDODetachedFieldAccessException(...)"
                mv.visitTypeInsn(Opcodes.NEW, namer.getDetachedFieldAccessExceptionAsmClassName());
                mv.visitInsn(Opcodes.DUP);
                mv.visitLdcInsn(Localiser.msg("005026", mmd.getName()));
                mv.visitMethodInsn(Opcodes.INVOKESPECIAL, namer.getDetachedFieldAccessExceptionAsmClassName(), "<init>", "(Ljava/lang/String;)V");
                mv.visitInsn(Opcodes.ATHROW);
            }
            mv.visitLabel(l4);
            mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
        }
        mv.visitVarInsn(Opcodes.ALOAD, 0);
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, asmClassName, namer.getGetMethodPrefixMethodName() + mmd.getName(), "()" + fieldTypeDesc);
        EnhanceUtils.addReturnForType(mv, mmd.getType());
        Label endLabel = new Label();
        mv.visitLabel(endLabel);
        mv.visitLocalVariable(argNames[0], asmClassDesc, null, startLabel, endLabel, 0);
        mv.visitMaxs(4, 1);
    } else {
        // NORMAL - see method GetNormal
        Label startLabel = new Label();
        mv.visitLabel(startLabel);
        mv.visitVarInsn(Opcodes.ALOAD, 0);
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, asmClassName, namer.getGetMethodPrefixMethodName() + mmd.getName(), "()" + fieldTypeDesc);
        EnhanceUtils.addReturnForType(mv, mmd.getType());
        Label endLabel = new Label();
        mv.visitLabel(endLabel);
        mv.visitLocalVariable(argNames[0], asmClassDesc, null, startLabel, endLabel, 0);
        mv.visitMaxs(1, 1);
    }
    mv.visitEnd();
}
Also used : Label(org.datanucleus.enhancer.asm.Label) AbstractClassMetaData(org.datanucleus.metadata.AbstractClassMetaData)

Example 2 with Label

use of org.datanucleus.enhancer.asm.Label in project datanucleus-core by datanucleus.

the class EnhancerPropertySetterAdapter method generateSetXXXMethod.

/**
 * Convenience method to use the MethodVisitor to generate the code for the method setXXX() for the property with the specified MetaData.
 * @param mv MethodVisitor
 * @param mmd MetaData for the property
 * @param asmClassName ASM class name for the owning class
 * @param asmClassDesc ASM descriptor for the owning class
 * @param namer Namer for methods etc
 */
public static void generateSetXXXMethod(MethodVisitor mv, AbstractMemberMetaData mmd, String asmClassName, String asmClassDesc, EnhancementNamer namer) {
    String[] argNames = new String[] { "this", "val" };
    String fieldTypeDesc = Type.getDescriptor(mmd.getType());
    mv.visitCode();
    AbstractClassMetaData cmd = mmd.getAbstractClassMetaData();
    if ((mmd.getPersistenceFlags() & Persistable.MEDIATE_WRITE) == Persistable.MEDIATE_WRITE) {
        // MEDIATE_WRITE - see method SetViaMediate
        Label startLabel = new Label();
        mv.visitLabel(startLabel);
        // "if (objPC.dnStateManager == null) objPC.ZZZ = zzz;"
        mv.visitVarInsn(Opcodes.ALOAD, 0);
        mv.visitFieldInsn(Opcodes.GETFIELD, asmClassName, namer.getStateManagerFieldName(), "L" + namer.getStateManagerAsmClassName() + ";");
        Label l1 = new Label();
        mv.visitJumpInsn(Opcodes.IFNONNULL, l1);
        mv.visitVarInsn(Opcodes.ALOAD, 0);
        EnhanceUtils.addLoadForType(mv, mmd.getType(), 1);
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, asmClassName, namer.getSetMethodPrefixMethodName() + mmd.getName(), "(" + fieldTypeDesc + ")V");
        Label l3 = new Label();
        mv.visitJumpInsn(Opcodes.GOTO, l3);
        mv.visitLabel(l1);
        // "else objPC.dnStateManager.setYYYField(objPC, 0, objPC.ZZZ, zzz);"
        mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
        mv.visitVarInsn(Opcodes.ALOAD, 0);
        mv.visitFieldInsn(Opcodes.GETFIELD, asmClassName, namer.getStateManagerFieldName(), "L" + namer.getStateManagerAsmClassName() + ";");
        mv.visitVarInsn(Opcodes.ALOAD, 0);
        EnhanceUtils.addBIPUSHToMethod(mv, mmd.getFieldId());
        if (cmd.getPersistableSuperclass() != null) {
            mv.visitFieldInsn(Opcodes.GETSTATIC, asmClassName, namer.getInheritedFieldCountFieldName(), "I");
            mv.visitInsn(Opcodes.IADD);
        }
        mv.visitVarInsn(Opcodes.ALOAD, 0);
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, asmClassName, namer.getGetMethodPrefixMethodName() + mmd.getName(), "()" + fieldTypeDesc);
        EnhanceUtils.addLoadForType(mv, mmd.getType(), 1);
        String methodName = "set" + EnhanceUtils.getTypeNameForPersistableMethod(mmd.getType()) + "Field";
        String argTypeDesc = fieldTypeDesc;
        if (methodName.equals("setObjectField")) {
            argTypeDesc = EnhanceUtils.CD_Object;
        }
        mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, namer.getStateManagerAsmClassName(), methodName, "(L" + namer.getPersistableAsmClassName() + ";I" + argTypeDesc + argTypeDesc + ")V");
        mv.visitLabel(l3);
        mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
        if (cmd.isDetachable()) {
            // "if (objPC.dnIsDetached() == true)"
            mv.visitVarInsn(Opcodes.ALOAD, 0);
            mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, asmClassName, namer.getIsDetachedMethodName(), "()Z");
            Label l6 = new Label();
            mv.visitJumpInsn(Opcodes.IFEQ, l6);
            // "((BitSet) objPC.dnDetachedState[3]).set(0);"
            mv.visitVarInsn(Opcodes.ALOAD, 0);
            mv.visitFieldInsn(Opcodes.GETFIELD, asmClassName, namer.getDetachedStateFieldName(), "[Ljava/lang/Object;");
            mv.visitInsn(Opcodes.ICONST_3);
            mv.visitInsn(Opcodes.AALOAD);
            mv.visitTypeInsn(Opcodes.CHECKCAST, "java/util/BitSet");
            EnhanceUtils.addBIPUSHToMethod(mv, mmd.getFieldId());
            if (cmd.getPersistableSuperclass() != null) {
                mv.visitFieldInsn(Opcodes.GETSTATIC, asmClassName, namer.getInheritedFieldCountFieldName(), "I");
                mv.visitInsn(Opcodes.IADD);
            }
            mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/util/BitSet", "set", "(I)V");
            mv.visitLabel(l6);
            mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
        }
        mv.visitInsn(Opcodes.RETURN);
        Label endLabel = new Label();
        mv.visitLabel(endLabel);
        mv.visitLocalVariable(argNames[0], asmClassDesc, null, startLabel, endLabel, 0);
        mv.visitLocalVariable(argNames[1], fieldTypeDesc, null, startLabel, endLabel, 1);
        mv.visitMaxs(5, 2);
    } else if ((mmd.getPersistenceFlags() & Persistable.CHECK_WRITE) == Persistable.CHECK_WRITE) {
        // CHECK_WRITE - see method SetViaCheck
        Label startLabel = new Label();
        mv.visitLabel(startLabel);
        // "if (objPC.dnFlags != 0 && objPC.dnStateManager != null)"
        mv.visitVarInsn(Opcodes.ALOAD, 0);
        mv.visitFieldInsn(Opcodes.GETFIELD, asmClassName, namer.getFlagsFieldName(), "B");
        Label l1 = new Label();
        mv.visitJumpInsn(Opcodes.IFEQ, l1);
        mv.visitVarInsn(Opcodes.ALOAD, 0);
        mv.visitFieldInsn(Opcodes.GETFIELD, asmClassName, namer.getStateManagerFieldName(), "L" + namer.getStateManagerAsmClassName() + ";");
        mv.visitJumpInsn(Opcodes.IFNULL, l1);
        // "objPC.dnStateManager.setYYYField(objPC, 8, objPC.ZZZ, val);"
        mv.visitVarInsn(Opcodes.ALOAD, 0);
        mv.visitFieldInsn(Opcodes.GETFIELD, asmClassName, namer.getStateManagerFieldName(), "L" + namer.getStateManagerAsmClassName() + ";");
        mv.visitVarInsn(Opcodes.ALOAD, 0);
        EnhanceUtils.addBIPUSHToMethod(mv, mmd.getFieldId());
        if (cmd.getPersistableSuperclass() != null) {
            mv.visitFieldInsn(Opcodes.GETSTATIC, asmClassName, namer.getInheritedFieldCountFieldName(), "I");
            mv.visitInsn(Opcodes.IADD);
        }
        mv.visitVarInsn(Opcodes.ALOAD, 0);
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, asmClassName, namer.getGetMethodPrefixMethodName() + mmd.getName(), "()" + fieldTypeDesc);
        EnhanceUtils.addLoadForType(mv, mmd.getType(), 1);
        String methodName = "set" + EnhanceUtils.getTypeNameForPersistableMethod(mmd.getType()) + "Field";
        String argTypeDesc = fieldTypeDesc;
        if (methodName.equals("setObjectField")) {
            argTypeDesc = EnhanceUtils.CD_Object;
        }
        mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, namer.getStateManagerAsmClassName(), methodName, "(L" + namer.getPersistableAsmClassName() + ";I" + argTypeDesc + argTypeDesc + ")V");
        Label l3 = new Label();
        mv.visitJumpInsn(Opcodes.GOTO, l3);
        mv.visitLabel(l1);
        // "objPC.text = val;"
        mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
        mv.visitVarInsn(Opcodes.ALOAD, 0);
        EnhanceUtils.addLoadForType(mv, mmd.getType(), 1);
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, asmClassName, namer.getSetMethodPrefixMethodName() + mmd.getName(), "(" + fieldTypeDesc + ")V");
        if (cmd.isDetachable()) {
            // "if (objPC.dnIsDetached() == true)  ((BitSet) objPC.dnDetachedState[3]).set(8);"
            mv.visitVarInsn(Opcodes.ALOAD, 0);
            mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, asmClassName, namer.getIsDetachedMethodName(), "()Z");
            mv.visitJumpInsn(Opcodes.IFEQ, l3);
            mv.visitVarInsn(Opcodes.ALOAD, 0);
            mv.visitFieldInsn(Opcodes.GETFIELD, asmClassName, namer.getDetachedStateFieldName(), "[Ljava/lang/Object;");
            mv.visitInsn(Opcodes.ICONST_3);
            mv.visitInsn(Opcodes.AALOAD);
            mv.visitTypeInsn(Opcodes.CHECKCAST, "java/util/BitSet");
            EnhanceUtils.addBIPUSHToMethod(mv, mmd.getFieldId());
            if (cmd.getPersistableSuperclass() != null) {
                mv.visitFieldInsn(Opcodes.GETSTATIC, asmClassName, namer.getInheritedFieldCountFieldName(), "I");
                mv.visitInsn(Opcodes.IADD);
            }
            mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/util/BitSet", "set", "(I)V");
        }
        mv.visitLabel(l3);
        mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
        mv.visitInsn(Opcodes.RETURN);
        Label endLabel = new Label();
        mv.visitLabel(endLabel);
        mv.visitLocalVariable(argNames[0], asmClassDesc, null, startLabel, endLabel, 0);
        mv.visitLocalVariable(argNames[1], fieldTypeDesc, null, startLabel, endLabel, 1);
        mv.visitMaxs(5, 2);
    } else {
        // NORMAL - see method SetNormal
        Label startLabel = new Label();
        mv.visitLabel(startLabel);
        mv.visitVarInsn(Opcodes.ALOAD, 0);
        EnhanceUtils.addLoadForType(mv, mmd.getType(), 1);
        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, asmClassName, namer.getSetMethodPrefixMethodName() + mmd.getName(), "(" + fieldTypeDesc + ")V");
        mv.visitInsn(Opcodes.RETURN);
        Label endLabel = new Label();
        mv.visitLabel(endLabel);
        mv.visitLocalVariable(argNames[0], asmClassDesc, null, startLabel, endLabel, 0);
        mv.visitLocalVariable(argNames[1], fieldTypeDesc, null, startLabel, endLabel, 1);
        mv.visitMaxs(2, 2);
    }
    mv.visitEnd();
}
Also used : Label(org.datanucleus.enhancer.asm.Label) AbstractClassMetaData(org.datanucleus.metadata.AbstractClassMetaData)

Example 3 with Label

use of org.datanucleus.enhancer.asm.Label in project datanucleus-core by datanucleus.

the class ImplementationGenerator method createSetter.

/**
 * Create a setter method for a property.
 * @param mmd MetaData for the property
 */
protected void createSetter(AbstractMemberMetaData mmd) {
    String setterName = ClassUtils.getJavaBeanSetterName(mmd.getName());
    String dnSetterName = namer.getSetMethodPrefixMethodName() + mmd.getName();
    if (inputCmd instanceof InterfaceMetaData) {
        // Interface so generate setXXX
        String fieldDesc = Type.getDescriptor(mmd.getType());
        MethodVisitor visitor = writer.visitMethod(Opcodes.ACC_PUBLIC, setterName, "(" + fieldDesc + ")V", null, null);
        visitor.visitCode();
        Label l0 = new Label();
        visitor.visitLabel(l0);
        visitor.visitVarInsn(Opcodes.ALOAD, 0);
        EnhanceUtils.addLoadForType(visitor, mmd.getType(), 1);
        visitor.visitFieldInsn(Opcodes.PUTFIELD, asmClassName, mmd.getName(), fieldDesc);
        visitor.visitInsn(Opcodes.RETURN);
        Label l2 = new Label();
        visitor.visitLabel(l2);
        visitor.visitLocalVariable("this", asmTypeDescriptor, null, l0, l2, 0);
        visitor.visitLocalVariable("val", fieldDesc, null, l0, l2, 1);
        visitor.visitMaxs(2, 2);
        visitor.visitEnd();
    } else {
        // Abstract class so generate setXXX
        String fieldDesc = Type.getDescriptor(mmd.getType());
        int setAccess = (mmd.isPublic() ? Opcodes.ACC_PUBLIC : 0) | (mmd.isProtected() ? Opcodes.ACC_PROTECTED : 0) | (mmd.isPrivate() ? Opcodes.ACC_PRIVATE : 0);
        MethodVisitor setVisitor = writer.visitMethod(setAccess, setterName, "(" + fieldDesc + ")V", null, null);
        EnhancerPropertySetterAdapter.generateSetXXXMethod(setVisitor, mmd, asmClassName, asmTypeDescriptor, namer);
        // Abstract class so generate dnSetXXX
        int access = (mmd.isPublic() ? Opcodes.ACC_PUBLIC : 0) | (mmd.isProtected() ? Opcodes.ACC_PROTECTED : 0) | (mmd.isPrivate() ? Opcodes.ACC_PRIVATE : 0);
        MethodVisitor visitor = writer.visitMethod(access, dnSetterName, "(" + fieldDesc + ")V", null, null);
        visitor.visitCode();
        Label l0 = new Label();
        visitor.visitLabel(l0);
        visitor.visitVarInsn(Opcodes.ALOAD, 0);
        EnhanceUtils.addLoadForType(visitor, mmd.getType(), 1);
        visitor.visitFieldInsn(Opcodes.PUTFIELD, asmClassName, mmd.getName(), fieldDesc);
        visitor.visitInsn(Opcodes.RETURN);
        Label l2 = new Label();
        visitor.visitLabel(l2);
        visitor.visitLocalVariable("this", asmTypeDescriptor, null, l0, l2, 0);
        visitor.visitLocalVariable("val", fieldDesc, null, l0, l2, 1);
        visitor.visitMaxs(2, 2);
        visitor.visitEnd();
    }
}
Also used : Label(org.datanucleus.enhancer.asm.Label) InterfaceMetaData(org.datanucleus.metadata.InterfaceMetaData) MethodVisitor(org.datanucleus.enhancer.asm.MethodVisitor)

Example 4 with Label

use of org.datanucleus.enhancer.asm.Label in project datanucleus-core by datanucleus.

the class ImplementationGenerator method createGetter.

/**
 * Create a getter method for a /property.
 * @param mmd MetaData for the property
 */
protected void createGetter(AbstractMemberMetaData mmd) {
    boolean isBoolean = mmd.getTypeName().equals("boolean");
    String getterName = ClassUtils.getJavaBeanGetterName(mmd.getName(), isBoolean);
    String dnGetterName = namer.getGetMethodPrefixMethodName() + mmd.getName();
    if (inputCmd instanceof InterfaceMetaData) {
        // Interface so generate getXXX
        String fieldDesc = Type.getDescriptor(mmd.getType());
        MethodVisitor visitor = writer.visitMethod(Opcodes.ACC_PUBLIC, getterName, "()" + fieldDesc, null, null);
        visitor.visitCode();
        Label l0 = new Label();
        visitor.visitLabel(l0);
        visitor.visitVarInsn(Opcodes.ALOAD, 0);
        visitor.visitFieldInsn(Opcodes.GETFIELD, asmClassName, mmd.getName(), fieldDesc);
        EnhanceUtils.addReturnForType(visitor, mmd.getType());
        Label l1 = new Label();
        visitor.visitLabel(l1);
        visitor.visitLocalVariable("this", asmTypeDescriptor, null, l0, l1, 0);
        visitor.visitMaxs(1, 1);
        visitor.visitEnd();
    } else {
        // Abstract class so generate getXXX
        String fieldDesc = Type.getDescriptor(mmd.getType());
        int getAccess = (mmd.isPublic() ? Opcodes.ACC_PUBLIC : 0) | (mmd.isProtected() ? Opcodes.ACC_PROTECTED : 0) | (mmd.isPrivate() ? Opcodes.ACC_PRIVATE : 0);
        MethodVisitor getVisitor = writer.visitMethod(getAccess, getterName, "()" + fieldDesc, null, null);
        EnhancerPropertyGetterAdapter.generateGetXXXMethod(getVisitor, mmd, asmClassName, asmTypeDescriptor, false, namer);
        // Abstract class so generate dnGetXXX
        int access = (mmd.isPublic() ? Opcodes.ACC_PUBLIC : 0) | (mmd.isProtected() ? Opcodes.ACC_PROTECTED : 0) | (mmd.isPrivate() ? Opcodes.ACC_PRIVATE : 0);
        MethodVisitor visitor = writer.visitMethod(access, dnGetterName, "()" + fieldDesc, null, null);
        visitor.visitCode();
        Label l0 = new Label();
        visitor.visitLabel(l0);
        visitor.visitVarInsn(Opcodes.ALOAD, 0);
        visitor.visitFieldInsn(Opcodes.GETFIELD, asmClassName, mmd.getName(), fieldDesc);
        EnhanceUtils.addReturnForType(visitor, mmd.getType());
        Label l1 = new Label();
        visitor.visitLabel(l1);
        visitor.visitLocalVariable("this", asmTypeDescriptor, null, l0, l1, 0);
        visitor.visitMaxs(1, 1);
        visitor.visitEnd();
    }
}
Also used : Label(org.datanucleus.enhancer.asm.Label) InterfaceMetaData(org.datanucleus.metadata.InterfaceMetaData) MethodVisitor(org.datanucleus.enhancer.asm.MethodVisitor)

Example 5 with Label

use of org.datanucleus.enhancer.asm.Label in project datanucleus-core by datanucleus.

the class CopyKeyFieldsFromObjectId2 method execute.

/**
 * Method to add the contents of the class method.
 */
public void execute() {
    visitor.visitCode();
    ClassMetaData cmd = enhancer.getClassMetaData();
    if (cmd.getIdentityType() == IdentityType.APPLICATION) {
        // application identity
        if (!cmd.isInstantiable()) {
            // Application identity but mapped-superclass with no PK defined, so just "return"
            Label startLabel = new Label();
            visitor.visitLabel(startLabel);
            visitor.visitInsn(Opcodes.RETURN);
            Label endLabel = new Label();
            visitor.visitLabel(endLabel);
            visitor.visitLocalVariable("this", getClassEnhancer().getClassDescriptor(), null, startLabel, endLabel, 0);
            visitor.visitLocalVariable(argNames[0], EnhanceUtils.CD_Object, null, startLabel, endLabel, 1);
            visitor.visitMaxs(0, 2);
        } else {
            String objectIdClass = cmd.getObjectidClass();
            String ACN_objectIdClass = objectIdClass.replace('.', '/');
            int[] pkFieldNums = enhancer.getClassMetaData().getPKMemberPositions();
            if (IdentityUtils.isSingleFieldIdentityClass(objectIdClass)) {
                // SingleFieldIdentity
                Label startLabel = new Label();
                visitor.visitLabel(startLabel);
                // if (!(oid instanceof LongIdentity)) throw new ClassCastException("...")
                visitor.visitVarInsn(Opcodes.ALOAD, 1);
                visitor.visitTypeInsn(Opcodes.INSTANCEOF, ACN_objectIdClass);
                Label l1 = new Label();
                visitor.visitJumpInsn(Opcodes.IFNE, l1);
                visitor.visitTypeInsn(Opcodes.NEW, "java/lang/ClassCastException");
                visitor.visitInsn(Opcodes.DUP);
                visitor.visitLdcInsn("key class is not " + objectIdClass + " or null");
                visitor.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/ClassCastException", "<init>", "(Ljava/lang/String;)V");
                visitor.visitInsn(Opcodes.ATHROW);
                // XXXIdentity o = (XXXIdentity) oid;
                visitor.visitLabel(l1);
                visitor.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
                visitor.visitVarInsn(Opcodes.ALOAD, 1);
                visitor.visitTypeInsn(Opcodes.CHECKCAST, ACN_objectIdClass);
                visitor.visitVarInsn(Opcodes.ASTORE, 2);
                // id = o.getKey();
                Label l5 = new Label();
                visitor.visitLabel(l5);
                visitor.visitVarInsn(Opcodes.ALOAD, 0);
                AbstractMemberMetaData fmd = enhancer.getClassMetaData().getMetaDataForManagedMemberAtAbsolutePosition(pkFieldNums[0]);
                Class primitiveType = ClassUtils.getPrimitiveTypeForType(fmd.getType());
                if (primitiveType != null) {
                    // The PK field is a primitive wrapper so create wrapper from getKey()
                    String ACN_fieldType = fmd.getTypeName().replace('.', '/');
                    String getKeyReturnDesc = Type.getDescriptor(primitiveType);
                    visitor.visitVarInsn(Opcodes.ALOAD, 2);
                    visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, ACN_objectIdClass, "getKey", "()" + getKeyReturnDesc);
                    visitor.visitMethodInsn(Opcodes.INVOKESTATIC, ACN_fieldType, "valueOf", "(" + getKeyReturnDesc + ")L" + ACN_fieldType + ";");
                } else {
                    // PK field isn't a primitive wrapper
                    visitor.visitVarInsn(Opcodes.ALOAD, 2);
                    visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, ACN_objectIdClass, "getKey", "()" + getNamer().getTypeDescriptorForSingleFieldIdentityGetKey(objectIdClass));
                    if (objectIdClass.equals(getNamer().getObjectIdentityClass().getName())) {
                        // Cast to the right type
                        visitor.visitTypeInsn(Opcodes.CHECKCAST, fmd.getTypeName().replace('.', '/'));
                    }
                }
                if (fmd instanceof PropertyMetaData) {
                    // Persistent property so use dnSetXXX(...)
                    visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, getClassEnhancer().getASMClassName(), getNamer().getSetMethodPrefixMethodName() + fmd.getName(), "(" + Type.getDescriptor(fmd.getType()) + ")V");
                } else {
                    // Persistent field so use xxx = ...
                    visitor.visitFieldInsn(Opcodes.PUTFIELD, getClassEnhancer().getASMClassName(), fmd.getName(), Type.getDescriptor(fmd.getType()));
                }
                visitor.visitInsn(Opcodes.RETURN);
                Label l7 = new Label();
                visitor.visitLabel(l7);
                visitor.visitLocalVariable("this", getClassEnhancer().getClassDescriptor(), null, startLabel, l7, 0);
                visitor.visitLocalVariable(argNames[0], EnhanceUtils.CD_Object, null, startLabel, l7, 1);
                visitor.visitLocalVariable("o", getNamer().getSingleFieldIdentityDescriptor(objectIdClass), null, l5, l7, 2);
                visitor.visitMaxs(3, 3);
            } else {
                // User-provided app identity, and compound identity
                // Put try-catch around the field setting (for reflection cases)
                Label l0 = new Label();
                Label l1 = new Label();
                Label l2 = new Label();
                visitor.visitTryCatchBlock(l0, l1, l2, "java/lang/Exception");
                Label startLabel = new Label();
                visitor.visitLabel(startLabel);
                visitor.visitVarInsn(Opcodes.ALOAD, 1);
                visitor.visitTypeInsn(Opcodes.INSTANCEOF, ACN_objectIdClass);
                Label l4 = new Label();
                visitor.visitJumpInsn(Opcodes.IFNE, l4);
                visitor.visitTypeInsn(Opcodes.NEW, "java/lang/ClassCastException");
                visitor.visitInsn(Opcodes.DUP);
                visitor.visitLdcInsn("key class is not " + objectIdClass + " or null");
                visitor.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/ClassCastException", "<init>", "(Ljava/lang/String;)V");
                visitor.visitInsn(Opcodes.ATHROW);
                visitor.visitLabel(l4);
                visitor.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
                visitor.visitVarInsn(Opcodes.ALOAD, 1);
                visitor.visitTypeInsn(Opcodes.CHECKCAST, ACN_objectIdClass);
                visitor.visitVarInsn(Opcodes.ASTORE, 2);
                visitor.visitLabel(l0);
                // Copy the PK members using the appropriate method for each field/property
                Label reflectionFieldStart = null;
                for (int i = 0; i < pkFieldNums.length; i++) {
                    AbstractMemberMetaData fmd = enhancer.getClassMetaData().getMetaDataForManagedMemberAtAbsolutePosition(pkFieldNums[i]);
                    String fieldTypeDesc = Type.getDescriptor(fmd.getType());
                    String fieldTypeName = fmd.getTypeName().replace('.', '/');
                    int pkFieldModifiers = ClassUtils.getModifiersForFieldOfClass(enhancer.getClassLoaderResolver(), objectIdClass, fmd.getName());
                    // Check if the PK field type is a PC (CompoundIdentity)
                    AbstractClassMetaData acmd = enhancer.getMetaDataManager().getMetaDataForClass(fmd.getType(), enhancer.getClassLoaderResolver());
                    if (acmd != null && acmd.getIdentityType() != IdentityType.NONDURABLE) {
                        // CompoundIdentity, this field of the PK is a PC
                        visitor.visitVarInsn(Opcodes.ALOAD, 0);
                        visitor.visitVarInsn(Opcodes.ALOAD, 0);
                        visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, getClassEnhancer().getASMClassName(), getNamer().getGetExecutionContextMethodName(), "()L" + getNamer().getExecutionContextAsmClassName() + ";");
                        visitor.visitVarInsn(Opcodes.ALOAD, 2);
                        // TODO Cater for property/private field cases
                        visitor.visitFieldInsn(Opcodes.GETFIELD, ACN_objectIdClass, fmd.getName(), "L" + acmd.getObjectidClass().replace('.', '/') + ";");
                        visitor.visitInsn(Opcodes.ICONST_0);
                        visitor.visitMethodInsn(Opcodes.INVOKEINTERFACE, getNamer().getExecutionContextAsmClassName(), "findObject", "(Ljava/lang/Object;Z)Ljava/lang/Object;");
                        visitor.visitTypeInsn(Opcodes.CHECKCAST, fieldTypeName);
                        if (fmd instanceof PropertyMetaData) {
                            // Persistent property so use dnSetXXX(...)
                            visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, getClassEnhancer().getASMClassName(), getNamer().getSetMethodPrefixMethodName() + fmd.getName(), "(" + Type.getDescriptor(fmd.getType()) + ")V");
                        } else if (Modifier.isPublic(pkFieldModifiers)) {
                            // Persistent field that is public so use "xxx = ..."
                            visitor.visitFieldInsn(Opcodes.PUTFIELD, getClassEnhancer().getASMClassName(), fmd.getName(), Type.getDescriptor(fmd.getType()));
                        } else {
                            // Persistent field that is protected/private so use reflection
                            // TODO Use reflection rather than "xxx = ..."
                            visitor.visitFieldInsn(Opcodes.PUTFIELD, getClassEnhancer().getASMClassName(), fmd.getName(), Type.getDescriptor(fmd.getType()));
                        }
                    } else {
                        // Standard application-identity
                        if (fmd instanceof PropertyMetaData) {
                            // Field in PK is property, hence use getXXX in PK to access value
                            visitor.visitVarInsn(Opcodes.ALOAD, 0);
                            visitor.visitVarInsn(Opcodes.ALOAD, 2);
                            visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, ACN_objectIdClass, ClassUtils.getJavaBeanGetterName(fmd.getName(), fmd.getTypeName().equals("boolean")), "()" + Type.getDescriptor(fmd.getType()));
                            visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, getClassEnhancer().getASMClassName(), getNamer().getSetMethodPrefixMethodName() + fmd.getName(), "(" + Type.getDescriptor(fmd.getType()) + ")V");
                        } else if (Modifier.isPublic(pkFieldModifiers)) {
                            // Field in PK is public so access directly
                            visitor.visitVarInsn(Opcodes.ALOAD, 0);
                            visitor.visitVarInsn(Opcodes.ALOAD, 2);
                            visitor.visitFieldInsn(Opcodes.GETFIELD, ACN_objectIdClass, fmd.getName(), fieldTypeDesc);
                            visitor.visitFieldInsn(Opcodes.PUTFIELD, getClassEnhancer().getASMClassName(), fmd.getName(), fieldTypeDesc);
                        } else {
                            // Field in PK is protected/private so use reflection, generating
                            // "Field field = o.getClass().getDeclaredField("pmIDFloat");"
                            // "field.setAccessible(true);"
                            // "pmIDFloat = (Float) field.get(o);"
                            visitor.visitVarInsn(Opcodes.ALOAD, 2);
                            visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Object", "getClass", "()Ljava/lang/Class;");
                            visitor.visitLdcInsn(fmd.getName());
                            visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Class", "getDeclaredField", "(Ljava/lang/String;)Ljava/lang/reflect/Field;");
                            visitor.visitVarInsn(Opcodes.ASTORE, 3);
                            if (reflectionFieldStart == null) {
                                reflectionFieldStart = new Label();
                                visitor.visitLabel(reflectionFieldStart);
                            }
                            visitor.visitVarInsn(Opcodes.ALOAD, 3);
                            visitor.visitInsn(Opcodes.ICONST_1);
                            visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/reflect/Field", "setAccessible", "(Z)V");
                            visitor.visitVarInsn(Opcodes.ALOAD, 0);
                            visitor.visitVarInsn(Opcodes.ALOAD, 3);
                            visitor.visitVarInsn(Opcodes.ALOAD, 2);
                            if (fmd.getTypeName().equals("boolean")) {
                                visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/reflect/Field", "getBoolean", "(Ljava/lang/Object;)Z");
                            } else if (fmd.getTypeName().equals("byte")) {
                                visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/reflect/Field", "getByte", "(Ljava/lang/Object;)B");
                            } else if (fmd.getTypeName().equals("char")) {
                                visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/reflect/Field", "getChar", "(Ljava/lang/Object;)C");
                            } else if (fmd.getTypeName().equals("double")) {
                                visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/reflect/Field", "getDouble", "(Ljava/lang/Object;)D");
                            } else if (fmd.getTypeName().equals("float")) {
                                visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/reflect/Field", "getFloat", "(Ljava/lang/Object;)F");
                            } else if (fmd.getTypeName().equals("int")) {
                                visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/reflect/Field", "getInt", "(Ljava/lang/Object;)I");
                            } else if (fmd.getTypeName().equals("long")) {
                                visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/reflect/Field", "getLong", "(Ljava/lang/Object;)L");
                            } else if (fmd.getTypeName().equals("short")) {
                                visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/reflect/Field", "getShort", "(Ljava/lang/Object;)S");
                            } else if (fmd.getTypeName().equals("java.lang.String")) {
                                visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/reflect/Field", "get", "(Ljava/lang/Object;)Ljava/lang/Object;");
                                visitor.visitTypeInsn(Opcodes.CHECKCAST, "java/lang/String");
                            } else {
                                visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/reflect/Field", "get", "(Ljava/lang/Object;)Ljava/lang/Object;");
                                visitor.visitTypeInsn(Opcodes.CHECKCAST, fieldTypeName);
                            }
                            visitor.visitFieldInsn(Opcodes.PUTFIELD, getClassEnhancer().getASMClassName(), fmd.getName(), fieldTypeDesc);
                        }
                    }
                }
                // catch of the try-catch
                visitor.visitLabel(l1);
                Label l16 = new Label();
                visitor.visitJumpInsn(Opcodes.GOTO, l16);
                visitor.visitLabel(l2);
                visitor.visitFrame(Opcodes.F_FULL, 3, new Object[] { getClassEnhancer().getASMClassName(), "java/lang/Object", ACN_objectIdClass }, 1, new Object[] { "java/lang/Exception" });
                visitor.visitVarInsn(Opcodes.ASTORE, 3);
                visitor.visitLabel(l16);
                visitor.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
                visitor.visitInsn(Opcodes.RETURN);
                Label endLabel = new Label();
                visitor.visitLabel(endLabel);
                visitor.visitLocalVariable("this", getClassEnhancer().getClassDescriptor(), null, startLabel, endLabel, 0);
                visitor.visitLocalVariable(argNames[0], EnhanceUtils.CD_Object, null, startLabel, endLabel, 1);
                visitor.visitLocalVariable("o", "L" + ACN_objectIdClass + ";", null, l0, endLabel, 2);
                if (reflectionFieldStart != null) {
                    visitor.visitLocalVariable("field", "Ljava/lang/reflect/Field;", null, reflectionFieldStart, l2, 3);
                    visitor.visitMaxs(3, 4);
                } else {
                    visitor.visitMaxs(3, 3);
                }
            }
        }
    } else {
        // datastore/nondurable identity
        Label startLabel = new Label();
        visitor.visitLabel(startLabel);
        visitor.visitInsn(Opcodes.RETURN);
        Label l1 = new Label();
        visitor.visitLabel(l1);
        visitor.visitLocalVariable("this", getClassEnhancer().getClassDescriptor(), null, startLabel, l1, 0);
        visitor.visitLocalVariable(argNames[0], EnhanceUtils.CD_Object, null, startLabel, l1, 1);
        visitor.visitMaxs(0, 2);
    }
    visitor.visitEnd();
}
Also used : Label(org.datanucleus.enhancer.asm.Label) PropertyMetaData(org.datanucleus.metadata.PropertyMetaData) AbstractMemberMetaData(org.datanucleus.metadata.AbstractMemberMetaData) AbstractClassMetaData(org.datanucleus.metadata.AbstractClassMetaData) ClassMetaData(org.datanucleus.metadata.ClassMetaData) AbstractClassMetaData(org.datanucleus.metadata.AbstractClassMetaData)

Aggregations

Label (org.datanucleus.enhancer.asm.Label)48 AbstractMemberMetaData (org.datanucleus.metadata.AbstractMemberMetaData)13 MethodVisitor (org.datanucleus.enhancer.asm.MethodVisitor)9 PropertyMetaData (org.datanucleus.metadata.PropertyMetaData)8 AbstractClassMetaData (org.datanucleus.metadata.AbstractClassMetaData)7 ClassMetaData (org.datanucleus.metadata.ClassMetaData)6 Date (java.util.Date)2 TimeZone (java.util.TimeZone)2 InterfaceMetaData (org.datanucleus.metadata.InterfaceMetaData)2 ClassWriter (org.datanucleus.enhancer.asm.ClassWriter)1 FieldVisitor (org.datanucleus.enhancer.asm.FieldVisitor)1