Search in sources :

Example 36 with Label

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

the class ReplaceDetachedState method execute.

/**
 * Method to add the contents of the class method.
 */
public void execute() {
    visitor.visitCode();
    Label startLabel = new Label();
    visitor.visitLabel(startLabel);
    visitor.visitVarInsn(Opcodes.ALOAD, 0);
    visitor.visitFieldInsn(Opcodes.GETFIELD, getClassEnhancer().getASMClassName(), getNamer().getStateManagerFieldName(), getNamer().getStateManagerDescriptor());
    Label l1 = new Label();
    visitor.visitJumpInsn(Opcodes.IFNONNULL, l1);
    visitor.visitTypeInsn(Opcodes.NEW, "java/lang/IllegalStateException");
    visitor.visitInsn(Opcodes.DUP);
    visitor.visitLdcInsn("state manager is null");
    visitor.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/IllegalStateException", "<init>", "(Ljava/lang/String;)V");
    visitor.visitInsn(Opcodes.ATHROW);
    visitor.visitLabel(l1);
    visitor.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
    visitor.visitVarInsn(Opcodes.ALOAD, 0);
    visitor.visitVarInsn(Opcodes.ALOAD, 0);
    visitor.visitFieldInsn(Opcodes.GETFIELD, getClassEnhancer().getASMClassName(), getNamer().getStateManagerFieldName(), getNamer().getStateManagerDescriptor());
    visitor.visitVarInsn(Opcodes.ALOAD, 0);
    visitor.visitVarInsn(Opcodes.ALOAD, 0);
    visitor.visitFieldInsn(Opcodes.GETFIELD, getClassEnhancer().getASMClassName(), getNamer().getDetachedStateFieldName(), "[" + EnhanceUtils.CD_Object);
    visitor.visitMethodInsn(Opcodes.INVOKEINTERFACE, getNamer().getStateManagerAsmClassName(), "replacingDetachedState", "(L" + getNamer().getDetachableAsmClassName() + ";[" + EnhanceUtils.CD_Object + ")[" + EnhanceUtils.CD_Object);
    visitor.visitFieldInsn(Opcodes.PUTFIELD, getClassEnhancer().getASMClassName(), getNamer().getDetachedStateFieldName(), "[" + EnhanceUtils.CD_Object);
    visitor.visitInsn(Opcodes.RETURN);
    Label endLabel = new Label();
    visitor.visitLabel(endLabel);
    visitor.visitLocalVariable("this", getClassEnhancer().getClassDescriptor(), null, startLabel, endLabel, 0);
    visitor.visitMaxs(4, 1);
    visitor.visitEnd();
}
Also used : Label(org.datanucleus.enhancer.asm.Label)

Example 37 with Label

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

the class SetNormal method execute.

/**
 * Method to add the contents of the class method.
 */
public void execute() {
    visitor.visitCode();
    String fieldTypeDesc = Type.getDescriptor(fmd.getType());
    Label startLabel = new Label();
    visitor.visitLabel(startLabel);
    visitor.visitVarInsn(Opcodes.ALOAD, 0);
    EnhanceUtils.addLoadForType(visitor, fmd.getType(), 1);
    visitor.visitFieldInsn(Opcodes.PUTFIELD, getClassEnhancer().getASMClassName(), fmd.getName(), fieldTypeDesc);
    visitor.visitInsn(Opcodes.RETURN);
    Label endLabel = new Label();
    visitor.visitLabel(endLabel);
    visitor.visitLocalVariable(argNames[0], getClassEnhancer().getClassDescriptor(), null, startLabel, endLabel, 0);
    visitor.visitLocalVariable(argNames[1], fieldTypeDesc, null, startLabel, endLabel, 1);
    visitor.visitMaxs(2, 2);
    visitor.visitEnd();
}
Also used : Label(org.datanucleus.enhancer.asm.Label)

Example 38 with Label

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

the class SetViaMediate method execute.

/**
 * Method to add the contents of the class method.
 */
public void execute() {
    visitor.visitCode();
    String fieldTypeDesc = Type.getDescriptor(fmd.getType());
    Label startLabel = new Label();
    visitor.visitLabel(startLabel);
    // "if (objPC.dnStateManager == null) objPC.ZZZ = zzz;"
    visitor.visitVarInsn(Opcodes.ALOAD, 0);
    visitor.visitFieldInsn(Opcodes.GETFIELD, getClassEnhancer().getASMClassName(), getNamer().getStateManagerFieldName(), "L" + getNamer().getStateManagerAsmClassName() + ";");
    Label l1 = new Label();
    visitor.visitJumpInsn(Opcodes.IFNONNULL, l1);
    visitor.visitVarInsn(Opcodes.ALOAD, 0);
    EnhanceUtils.addLoadForType(visitor, fmd.getType(), 1);
    visitor.visitFieldInsn(Opcodes.PUTFIELD, getClassEnhancer().getASMClassName(), fmd.getName(), fieldTypeDesc);
    Label l3 = new Label();
    visitor.visitJumpInsn(Opcodes.GOTO, l3);
    // "else objPC.dnStateManager.setYYYField(objPC, 0, objPC.ZZZ, zzz);"
    visitor.visitLabel(l1);
    visitor.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
    visitor.visitVarInsn(Opcodes.ALOAD, 0);
    visitor.visitFieldInsn(Opcodes.GETFIELD, getClassEnhancer().getASMClassName(), getNamer().getStateManagerFieldName(), "L" + getNamer().getStateManagerAsmClassName() + ";");
    visitor.visitVarInsn(Opcodes.ALOAD, 0);
    EnhanceUtils.addBIPUSHToMethod(visitor, fmd.getFieldId());
    if (enhancer.getClassMetaData().getPersistableSuperclass() != null) {
        visitor.visitFieldInsn(Opcodes.GETSTATIC, getClassEnhancer().getASMClassName(), getNamer().getInheritedFieldCountFieldName(), "I");
        visitor.visitInsn(Opcodes.IADD);
    }
    visitor.visitVarInsn(Opcodes.ALOAD, 0);
    visitor.visitFieldInsn(Opcodes.GETFIELD, getClassEnhancer().getASMClassName(), fmd.getName(), fieldTypeDesc);
    EnhanceUtils.addLoadForType(visitor, fmd.getType(), 1);
    String dnMethodName = "set" + EnhanceUtils.getTypeNameForPersistableMethod(fmd.getType()) + "Field";
    String argTypeDesc = fieldTypeDesc;
    if (dnMethodName.equals("setObjectField")) {
        argTypeDesc = EnhanceUtils.CD_Object;
    }
    visitor.visitMethodInsn(Opcodes.INVOKEINTERFACE, getNamer().getStateManagerAsmClassName(), dnMethodName, "(L" + getNamer().getPersistableAsmClassName() + ";I" + argTypeDesc + argTypeDesc + ")V");
    visitor.visitLabel(l3);
    visitor.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
    if (enhancer.getClassMetaData().isDetachable()) {
        // "if (objPC.dnIsDetached() == true)"
        visitor.visitVarInsn(Opcodes.ALOAD, 0);
        visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, getClassEnhancer().getASMClassName(), getNamer().getIsDetachedMethodName(), "()Z");
        Label l6 = new Label();
        visitor.visitJumpInsn(Opcodes.IFEQ, l6);
        // "((BitSet) objPC.dnDetachedState[3]).set(0);"
        visitor.visitVarInsn(Opcodes.ALOAD, 0);
        visitor.visitFieldInsn(Opcodes.GETFIELD, getClassEnhancer().getASMClassName(), getNamer().getDetachedStateFieldName(), "[Ljava/lang/Object;");
        visitor.visitInsn(Opcodes.ICONST_3);
        visitor.visitInsn(Opcodes.AALOAD);
        visitor.visitTypeInsn(Opcodes.CHECKCAST, "java/util/BitSet");
        EnhanceUtils.addBIPUSHToMethod(visitor, fmd.getFieldId());
        if (enhancer.getClassMetaData().getPersistableSuperclass() != null) {
            visitor.visitFieldInsn(Opcodes.GETSTATIC, getClassEnhancer().getASMClassName(), getNamer().getInheritedFieldCountFieldName(), "I");
            visitor.visitInsn(Opcodes.IADD);
        }
        visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/util/BitSet", "set", "(I)V");
        visitor.visitLabel(l6);
        visitor.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
    }
    visitor.visitInsn(Opcodes.RETURN);
    Label endLabel = new Label();
    visitor.visitLabel(endLabel);
    visitor.visitLocalVariable(argNames[0], getClassEnhancer().getClassDescriptor(), null, startLabel, endLabel, 0);
    visitor.visitLocalVariable(argNames[1], fieldTypeDesc, null, startLabel, endLabel, 1);
    visitor.visitMaxs(5, 2);
    visitor.visitEnd();
}
Also used : Label(org.datanucleus.enhancer.asm.Label)

Example 39 with Label

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

the class ImplementationGenerator method createDefaultConstructor.

/**
 * Create a default constructor, assuming that there is no persistent superclass.
 */
protected void createDefaultConstructor() {
    MethodVisitor visitor = writer.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null);
    visitor.visitCode();
    Label l0 = new Label();
    visitor.visitLabel(l0);
    visitor.visitVarInsn(Opcodes.ALOAD, 0);
    visitor.visitMethodInsn(Opcodes.INVOKESPECIAL, fullSuperclassName.replace('.', '/'), "<init>", "()V");
    visitor.visitInsn(Opcodes.RETURN);
    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) MethodVisitor(org.datanucleus.enhancer.asm.MethodVisitor)

Example 40 with Label

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

the class PrimaryKeyGenerator method addMethodEquals.

/**
 * Method to add an equals() method.
 * @param cw The ClassWriter to use
 */
protected void addMethodEquals(ClassWriter cw) {
    if (DataNucleusEnhancer.LOGGER.isDebugEnabled()) {
        DataNucleusEnhancer.LOGGER.debug(Localiser.msg("005019", "boolean " + pkClassName + ".equals(Object obj)"));
    }
    MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "equals", "(Ljava/lang/Object;)Z", null, null);
    mv.visitCode();
    Label startLabel = new Label();
    mv.visitLabel(startLabel);
    // if (obj == this) {return true;}
    mv.visitVarInsn(Opcodes.ALOAD, 1);
    mv.visitVarInsn(Opcodes.ALOAD, 0);
    Label l1 = new Label();
    mv.visitJumpInsn(Opcodes.IF_ACMPNE, l1);
    mv.visitInsn(Opcodes.ICONST_1);
    mv.visitInsn(Opcodes.IRETURN);
    mv.visitLabel(l1);
    // if (!(obj instanceof ThePK)) {return false;}
    mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
    mv.visitVarInsn(Opcodes.ALOAD, 1);
    mv.visitTypeInsn(Opcodes.INSTANCEOF, className_ASM);
    Label l3 = new Label();
    mv.visitJumpInsn(Opcodes.IFNE, l3);
    mv.visitInsn(Opcodes.ICONST_0);
    mv.visitInsn(Opcodes.IRETURN);
    mv.visitLabel(l3);
    // ThePK other = (ThePK)obj;
    mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
    mv.visitVarInsn(Opcodes.ALOAD, 1);
    mv.visitTypeInsn(Opcodes.CHECKCAST, className_ASM);
    mv.visitVarInsn(Opcodes.ASTORE, 2);
    Label compareStartLabel = new Label();
    mv.visitLabel(compareStartLabel);
    int[] pkPositions = cmd.getPKMemberPositions();
    Label compareSepLabel = null;
    for (int i = 0; i < pkPositions.length; i++) {
        AbstractMemberMetaData mmd = cmd.getMetaDataForManagedMemberAtRelativePosition(pkPositions[i]);
        if (mmd.getType() == long.class) {
            // "fieldX == other.fieldX"
            mv.visitVarInsn(Opcodes.ALOAD, 0);
            mv.visitFieldInsn(Opcodes.GETFIELD, className_ASM, mmd.getName(), EnhanceUtils.getTypeDescriptorForType(mmd.getTypeName()));
            mv.visitVarInsn(Opcodes.ALOAD, 2);
            mv.visitFieldInsn(Opcodes.GETFIELD, className_ASM, mmd.getName(), EnhanceUtils.getTypeDescriptorForType(mmd.getTypeName()));
            mv.visitInsn(Opcodes.LCMP);
            if (i == 0) {
                compareSepLabel = new Label();
            }
            mv.visitJumpInsn(Opcodes.IFNE, compareSepLabel);
        } else if (mmd.getType() == int.class || mmd.getType() == short.class || mmd.getType() == char.class) {
            // "fieldX == other.fieldX"
            mv.visitVarInsn(Opcodes.ALOAD, 0);
            mv.visitFieldInsn(Opcodes.GETFIELD, className_ASM, mmd.getName(), EnhanceUtils.getTypeDescriptorForType(mmd.getTypeName()));
            mv.visitVarInsn(Opcodes.ALOAD, 2);
            mv.visitFieldInsn(Opcodes.GETFIELD, className_ASM, mmd.getName(), EnhanceUtils.getTypeDescriptorForType(mmd.getTypeName()));
            if (i == 0) {
                compareSepLabel = new Label();
            }
            mv.visitJumpInsn(Opcodes.IF_ICMPNE, compareSepLabel);
        } else {
            // "fieldX.equals(other.fieldX)"
            String typeName = getTypeNameForField(mmd);
            String typeName_ASM = typeName.replace('.', '/');
            String typeNameDesc = "L" + typeName_ASM + ";";
            mv.visitVarInsn(Opcodes.ALOAD, 0);
            mv.visitFieldInsn(Opcodes.GETFIELD, className_ASM, mmd.getName(), typeNameDesc);
            mv.visitVarInsn(Opcodes.ALOAD, 2);
            mv.visitFieldInsn(Opcodes.GETFIELD, className_ASM, mmd.getName(), typeNameDesc);
            mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, typeName_ASM, "equals", "(Ljava/lang/Object;)Z");
            if (i == 0) {
                compareSepLabel = new Label();
            }
            mv.visitJumpInsn(Opcodes.IFEQ, compareSepLabel);
        }
    }
    mv.visitInsn(Opcodes.ICONST_1);
    mv.visitInsn(Opcodes.IRETURN);
    mv.visitLabel(compareSepLabel);
    mv.visitFrame(Opcodes.F_APPEND, 1, new Object[] { className_ASM }, 0, null);
    mv.visitInsn(Opcodes.ICONST_0);
    mv.visitInsn(Opcodes.IRETURN);
    Label endLabel = new Label();
    mv.visitLabel(endLabel);
    mv.visitLocalVariable("this", className_DescName, null, startLabel, endLabel, 0);
    mv.visitLocalVariable("obj", "Ljava/lang/Object;", null, startLabel, endLabel, 1);
    mv.visitLocalVariable("other", className_DescName, null, compareStartLabel, endLabel, 2);
    // TODO Can be (2, 3) in some situations, e.g if char is one of PK fields?
    mv.visitMaxs(4, 3);
    mv.visitEnd();
}
Also used : Label(org.datanucleus.enhancer.asm.Label) AbstractMemberMetaData(org.datanucleus.metadata.AbstractMemberMetaData) MethodVisitor(org.datanucleus.enhancer.asm.MethodVisitor)

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