use of org.datanucleus.enhancer.asm.Label in project datanucleus-core by datanucleus.
the class GetViaCheck 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);
visitor.visitFieldInsn(Opcodes.GETFIELD, getClassEnhancer().getASMClassName(), getNamer().getFlagsFieldName(), "B");
Label l1 = new Label();
visitor.visitJumpInsn(Opcodes.IFLE, l1);
visitor.visitVarInsn(Opcodes.ALOAD, 0);
visitor.visitFieldInsn(Opcodes.GETFIELD, getClassEnhancer().getASMClassName(), getNamer().getStateManagerFieldName(), "L" + getNamer().getStateManagerAsmClassName() + ";");
visitor.visitJumpInsn(Opcodes.IFNULL, l1);
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.visitMethodInsn(Opcodes.INVOKEINTERFACE, getNamer().getStateManagerAsmClassName(), "isLoaded", "(L" + getNamer().getPersistableAsmClassName() + ";I)Z");
visitor.visitJumpInsn(Opcodes.IFNE, l1);
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);
String dnMethodName = "get" + EnhanceUtils.getTypeNameForPersistableMethod(fmd.getType()) + "Field";
String argTypeDesc = fieldTypeDesc;
if (dnMethodName.equals("getObjectField")) {
argTypeDesc = EnhanceUtils.CD_Object;
}
visitor.visitMethodInsn(Opcodes.INVOKEINTERFACE, getNamer().getStateManagerAsmClassName(), dnMethodName, "(L" + getNamer().getPersistableAsmClassName() + ";I" + argTypeDesc + ")" + argTypeDesc);
if (dnMethodName.equals("getObjectField")) {
// Cast any object fields to the correct type
visitor.visitTypeInsn(Opcodes.CHECKCAST, fmd.getTypeName().replace('.', '/'));
}
EnhanceUtils.addReturnForType(visitor, fmd.getType());
visitor.visitLabel(l1);
visitor.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
if (enhancer.getClassMetaData().isDetachable()) {
// "if (objPC.dnIsDetached() != false && ((BitSet) objPC.dnDetachedState[2]).get(5) != true)"
visitor.visitVarInsn(Opcodes.ALOAD, 0);
visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, getClassEnhancer().getASMClassName(), getNamer().getIsDetachedMethodName(), "()Z");
Label l4 = new Label();
visitor.visitJumpInsn(Opcodes.IFEQ, l4);
visitor.visitVarInsn(Opcodes.ALOAD, 0);
visitor.visitFieldInsn(Opcodes.GETFIELD, getClassEnhancer().getASMClassName(), getNamer().getDetachedStateFieldName(), "[Ljava/lang/Object;");
visitor.visitInsn(Opcodes.ICONST_2);
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", "get", "(I)Z");
visitor.visitJumpInsn(Opcodes.IFNE, l4);
if (enhancer.hasOption(ClassEnhancer.OPTION_GENERATE_DETACH_LISTENER)) {
visitor.visitMethodInsn(Opcodes.INVOKESTATIC, getNamer().getDetachListenerAsmClassName(), "getInstance", "()L" + getNamer().getDetachListenerAsmClassName() + ";");
visitor.visitVarInsn(Opcodes.ALOAD, 0);
visitor.visitLdcInsn(fmd.getName());
visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, getNamer().getDetachListenerAsmClassName(), "undetachedFieldAccess", "(Ljava/lang/Object;Ljava/lang/String;)V");
} else {
// "throw new DetachedFieldAccessException(...)"
visitor.visitTypeInsn(Opcodes.NEW, getNamer().getDetachedFieldAccessExceptionAsmClassName());
visitor.visitInsn(Opcodes.DUP);
visitor.visitLdcInsn(Localiser.msg("005025", fmd.getName()));
visitor.visitMethodInsn(Opcodes.INVOKESPECIAL, getNamer().getDetachedFieldAccessExceptionAsmClassName(), "<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, 0);
visitor.visitFieldInsn(Opcodes.GETFIELD, getClassEnhancer().getASMClassName(), fmd.getName(), fieldTypeDesc);
EnhanceUtils.addReturnForType(visitor, fmd.getType());
Label endLabel = new Label();
visitor.visitLabel(endLabel);
visitor.visitLocalVariable(argNames[0], getClassEnhancer().getClassDescriptor(), null, startLabel, endLabel, 0);
visitor.visitMaxs(4, 1);
visitor.visitEnd();
}
use of org.datanucleus.enhancer.asm.Label in project datanucleus-core by datanucleus.
the class GetViaMediate 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);
visitor.visitFieldInsn(Opcodes.GETFIELD, getClassEnhancer().getASMClassName(), getNamer().getStateManagerFieldName(), "L" + getNamer().getStateManagerAsmClassName() + ";");
Label l1 = new Label();
visitor.visitJumpInsn(Opcodes.IFNULL, l1);
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.visitMethodInsn(Opcodes.INVOKEINTERFACE, getNamer().getStateManagerAsmClassName(), "isLoaded", "(L" + getNamer().getPersistableAsmClassName() + ";I)Z");
visitor.visitJumpInsn(Opcodes.IFNE, l1);
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);
String dnMethodName = "get" + EnhanceUtils.getTypeNameForPersistableMethod(fmd.getType()) + "Field";
String argTypeDesc = fieldTypeDesc;
if (dnMethodName.equals("getObjectField")) {
argTypeDesc = EnhanceUtils.CD_Object;
}
visitor.visitMethodInsn(Opcodes.INVOKEINTERFACE, getNamer().getStateManagerAsmClassName(), dnMethodName, "(L" + getNamer().getPersistableAsmClassName() + ";I" + argTypeDesc + ")" + argTypeDesc);
if (dnMethodName.equals("getObjectField")) {
// Cast any object fields to the correct type
visitor.visitTypeInsn(Opcodes.CHECKCAST, fmd.getTypeName().replace('.', '/'));
}
EnhanceUtils.addReturnForType(visitor, fmd.getType());
visitor.visitLabel(l1);
visitor.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
if (enhancer.getClassMetaData().isDetachable()) {
// "if (objPC.dnIsDetached() != false && ((BitSet) objPC.dnDetachedState[2]).get(5) != true)"
visitor.visitVarInsn(Opcodes.ALOAD, 0);
visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, getClassEnhancer().getASMClassName(), getNamer().getIsDetachedMethodName(), "()Z");
Label l4 = new Label();
visitor.visitJumpInsn(Opcodes.IFEQ, l4);
visitor.visitVarInsn(Opcodes.ALOAD, 0);
visitor.visitFieldInsn(Opcodes.GETFIELD, getClassEnhancer().getASMClassName(), getNamer().getDetachedStateFieldName(), "[Ljava/lang/Object;");
visitor.visitInsn(Opcodes.ICONST_2);
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", "get", "(I)Z");
visitor.visitJumpInsn(Opcodes.IFNE, l4);
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", "get", "(I)Z");
visitor.visitJumpInsn(Opcodes.IFNE, l4);
if (enhancer.hasOption(ClassEnhancer.OPTION_GENERATE_DETACH_LISTENER)) {
visitor.visitMethodInsn(Opcodes.INVOKESTATIC, getNamer().getDetachListenerAsmClassName(), "getInstance", "()L" + getNamer().getDetachListenerAsmClassName() + ";");
visitor.visitVarInsn(Opcodes.ALOAD, 0);
visitor.visitLdcInsn(fmd.getName());
visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, getNamer().getDetachListenerAsmClassName(), "undetachedFieldAccess", "(Ljava/lang/Object;Ljava/lang/String;)V");
} else {
// "throw new DetachedFieldAccessException(...)"
visitor.visitTypeInsn(Opcodes.NEW, getNamer().getDetachedFieldAccessExceptionAsmClassName());
visitor.visitInsn(Opcodes.DUP);
visitor.visitLdcInsn(Localiser.msg("005025", fmd.getName()));
visitor.visitMethodInsn(Opcodes.INVOKESPECIAL, getNamer().getDetachedFieldAccessExceptionAsmClassName(), "<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, 0);
visitor.visitFieldInsn(Opcodes.GETFIELD, getClassEnhancer().getASMClassName(), fmd.getName(), fieldTypeDesc);
EnhanceUtils.addReturnForType(visitor, fmd.getType());
Label endLabel = new Label();
visitor.visitLabel(endLabel);
visitor.visitLocalVariable(argNames[0], getClassEnhancer().getClassDescriptor(), null, startLabel, endLabel, 0);
visitor.visitMaxs(4, 1);
visitor.visitEnd();
}
use of org.datanucleus.enhancer.asm.Label in project datanucleus-core by datanucleus.
the class SetViaCheck 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.dnFlags != 0 && objPC.dnStateManager != null)"
visitor.visitVarInsn(Opcodes.ALOAD, 0);
visitor.visitFieldInsn(Opcodes.GETFIELD, getClassEnhancer().getASMClassName(), getNamer().getFlagsFieldName(), "B");
Label l1 = new Label();
visitor.visitJumpInsn(Opcodes.IFEQ, l1);
visitor.visitVarInsn(Opcodes.ALOAD, 0);
visitor.visitFieldInsn(Opcodes.GETFIELD, getClassEnhancer().getASMClassName(), getNamer().getStateManagerFieldName(), "L" + getNamer().getStateManagerAsmClassName() + ";");
visitor.visitJumpInsn(Opcodes.IFNULL, l1);
// "objPC.dnStateManager.setYYYField(objPC, 8, objPC.ZZZ, val);"
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");
Label l3 = new Label();
visitor.visitJumpInsn(Opcodes.GOTO, l3);
// "objPC.text = val;"
visitor.visitLabel(l1);
visitor.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
visitor.visitVarInsn(Opcodes.ALOAD, 0);
EnhanceUtils.addLoadForType(visitor, fmd.getType(), 1);
visitor.visitFieldInsn(Opcodes.PUTFIELD, getClassEnhancer().getASMClassName(), fmd.getName(), fieldTypeDesc);
if (enhancer.getClassMetaData().isDetachable()) {
// "if (objPC.dnIsDetached() == true) ((BitSet) objPC.dnDetachedState[3]).set(8);"
visitor.visitVarInsn(Opcodes.ALOAD, 0);
visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, getClassEnhancer().getASMClassName(), getNamer().getIsDetachedMethodName(), "()Z");
visitor.visitJumpInsn(Opcodes.IFEQ, l3);
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(l3);
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();
}
use of org.datanucleus.enhancer.asm.Label in project datanucleus-core by datanucleus.
the class SuperClone method execute.
/**
* Method to add the contents of the class method.
*/
public void execute() {
visitor.visitCode();
Label l0 = new Label();
visitor.visitLabel(l0);
visitor.visitVarInsn(Opcodes.ALOAD, 0);
visitor.visitMethodInsn(Opcodes.INVOKESPECIAL, EnhanceUtils.ACN_Object, "clone", "()" + EnhanceUtils.CD_Object);
visitor.visitTypeInsn(Opcodes.CHECKCAST, getClassEnhancer().getASMClassName());
visitor.visitVarInsn(Opcodes.ASTORE, 1);
Label l1 = new Label();
visitor.visitLabel(l1);
visitor.visitVarInsn(Opcodes.ALOAD, 1);
visitor.visitInsn(Opcodes.ICONST_0);
visitor.visitFieldInsn(Opcodes.PUTFIELD, getClassEnhancer().getASMClassName(), getNamer().getFlagsFieldName(), "B");
visitor.visitVarInsn(Opcodes.ALOAD, 1);
visitor.visitInsn(Opcodes.ACONST_NULL);
visitor.visitFieldInsn(Opcodes.PUTFIELD, getClassEnhancer().getASMClassName(), getNamer().getStateManagerFieldName(), getNamer().getStateManagerDescriptor());
visitor.visitVarInsn(Opcodes.ALOAD, 1);
visitor.visitInsn(Opcodes.ARETURN);
Label l4 = new Label();
visitor.visitLabel(l4);
visitor.visitLocalVariable("this", getClassEnhancer().getClassDescriptor(), null, l0, l4, 0);
visitor.visitLocalVariable("o", getClassEnhancer().getClassDescriptor(), null, l1, l4, 1);
visitor.visitMaxs(2, 2);
visitor.visitEnd();
}
use of org.datanucleus.enhancer.asm.Label in project datanucleus-core by datanucleus.
the class WriteObject 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.visitMethodInsn(Opcodes.INVOKEVIRTUAL, getClassEnhancer().getASMClassName(), getNamer().getPreSerializeMethodName(), "()V");
visitor.visitVarInsn(Opcodes.ALOAD, 1);
visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/io/ObjectOutputStream", "defaultWriteObject", "()V");
visitor.visitInsn(Opcodes.RETURN);
Label endLabel = new Label();
visitor.visitLabel(endLabel);
visitor.visitLocalVariable("this", getClassEnhancer().getClassDescriptor(), null, startLabel, endLabel, 0);
visitor.visitLocalVariable(argNames[0], "Ljava/io/ObjectOutputStream;", null, startLabel, endLabel, 1);
visitor.visitMaxs(1, 2);
visitor.visitEnd();
}
Aggregations