use of org.datanucleus.enhancer.asm.Label in project datanucleus-core by datanucleus.
the class ReplaceStateManager 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.IFNULL, l1);
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, 1);
visitor.visitMethodInsn(Opcodes.INVOKEINTERFACE, getNamer().getStateManagerAsmClassName(), "replacingStateManager", "(" + getNamer().getPersistableDescriptor() + getNamer().getStateManagerDescriptor() + ")" + getNamer().getStateManagerDescriptor());
visitor.visitFieldInsn(Opcodes.PUTFIELD, getClassEnhancer().getASMClassName(), getNamer().getStateManagerFieldName(), getNamer().getStateManagerDescriptor());
Label l3 = new Label();
visitor.visitJumpInsn(Opcodes.GOTO, l3);
visitor.visitLabel(l1);
visitor.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
visitor.visitVarInsn(Opcodes.ALOAD, 1);
visitor.visitMethodInsn(Opcodes.INVOKESTATIC, getNamer().getImplHelperAsmClassName(), "checkAuthorizedStateManager", "(L" + getNamer().getStateManagerAsmClassName() + ";)V");
visitor.visitVarInsn(Opcodes.ALOAD, 0);
visitor.visitVarInsn(Opcodes.ALOAD, 1);
visitor.visitFieldInsn(Opcodes.PUTFIELD, getClassEnhancer().getASMClassName(), getNamer().getStateManagerFieldName(), getNamer().getStateManagerDescriptor());
visitor.visitVarInsn(Opcodes.ALOAD, 0);
visitor.visitInsn(Opcodes.ICONST_1);
visitor.visitFieldInsn(Opcodes.PUTFIELD, getClassEnhancer().getASMClassName(), getNamer().getFlagsFieldName(), "B");
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("this", getClassEnhancer().getClassDescriptor(), null, startLabel, endLabel, 0);
visitor.visitLocalVariable(argNames[0], getNamer().getStateManagerDescriptor(), null, startLabel, endLabel, 1);
visitor.visitMaxs(4, 2);
visitor.visitEnd();
}
use of org.datanucleus.enhancer.asm.Label in project datanucleus-core by datanucleus.
the class CopyFields 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.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, 2);
Label l3 = new Label();
visitor.visitJumpInsn(Opcodes.IFNONNULL, l3);
visitor.visitTypeInsn(Opcodes.NEW, "java/lang/IllegalStateException");
visitor.visitInsn(Opcodes.DUP);
visitor.visitLdcInsn("fieldNumbers is null");
visitor.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/IllegalStateException", "<init>", "(Ljava/lang/String;)V");
visitor.visitInsn(Opcodes.ATHROW);
visitor.visitLabel(l3);
visitor.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
visitor.visitVarInsn(Opcodes.ALOAD, 1);
visitor.visitTypeInsn(Opcodes.INSTANCEOF, getClassEnhancer().getASMClassName());
Label l5 = new Label();
visitor.visitJumpInsn(Opcodes.IFNE, l5);
visitor.visitTypeInsn(Opcodes.NEW, "java/lang/IllegalArgumentException");
visitor.visitInsn(Opcodes.DUP);
visitor.visitLdcInsn("object is not an object of type " + getClassEnhancer().getASMClassName().replace('/', '.'));
visitor.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/IllegalArgumentException", "<init>", "(Ljava/lang/String;)V");
visitor.visitInsn(Opcodes.ATHROW);
visitor.visitLabel(l5);
visitor.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
visitor.visitVarInsn(Opcodes.ALOAD, 1);
visitor.visitTypeInsn(Opcodes.CHECKCAST, getClassEnhancer().getASMClassName());
visitor.visitVarInsn(Opcodes.ASTORE, 3);
Label l9 = new Label();
visitor.visitLabel(l9);
visitor.visitVarInsn(Opcodes.ALOAD, 0);
visitor.visitFieldInsn(Opcodes.GETFIELD, getClassEnhancer().getASMClassName(), getNamer().getStateManagerFieldName(), getNamer().getStateManagerDescriptor());
visitor.visitVarInsn(Opcodes.ALOAD, 3);
visitor.visitFieldInsn(Opcodes.GETFIELD, getClassEnhancer().getASMClassName(), getNamer().getStateManagerFieldName(), getNamer().getStateManagerDescriptor());
Label l10 = new Label();
visitor.visitJumpInsn(Opcodes.IF_ACMPEQ, l10);
visitor.visitTypeInsn(Opcodes.NEW, "java/lang/IllegalArgumentException");
visitor.visitInsn(Opcodes.DUP);
visitor.visitLdcInsn("state managers do not match");
visitor.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/IllegalArgumentException", "<init>", "(Ljava/lang/String;)V");
visitor.visitInsn(Opcodes.ATHROW);
visitor.visitLabel(l10);
visitor.visitFrame(Opcodes.F_APPEND, 1, new Object[] { getClassEnhancer().getASMClassName() }, 0, null);
visitor.visitVarInsn(Opcodes.ALOAD, 2);
visitor.visitInsn(Opcodes.ARRAYLENGTH);
visitor.visitInsn(Opcodes.ICONST_1);
visitor.visitInsn(Opcodes.ISUB);
visitor.visitVarInsn(Opcodes.ISTORE, 4);
Label l12 = new Label();
visitor.visitLabel(l12);
visitor.visitVarInsn(Opcodes.ILOAD, 4);
Label l13 = new Label();
visitor.visitJumpInsn(Opcodes.IFLT, l13);
Label l14 = new Label();
visitor.visitLabel(l14);
visitor.visitFrame(Opcodes.F_APPEND, 1, new Object[] { Opcodes.INTEGER }, 0, null);
visitor.visitVarInsn(Opcodes.ALOAD, 0);
visitor.visitVarInsn(Opcodes.ALOAD, 3);
visitor.visitVarInsn(Opcodes.ALOAD, 2);
visitor.visitVarInsn(Opcodes.ILOAD, 4);
visitor.visitInsn(Opcodes.IALOAD);
visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, getClassEnhancer().getASMClassName(), getNamer().getCopyFieldMethodName(), "(" + getClassEnhancer().getClassDescriptor() + "I)V");
visitor.visitIincInsn(4, -1);
visitor.visitVarInsn(Opcodes.ILOAD, 4);
visitor.visitJumpInsn(Opcodes.IFGE, l14);
visitor.visitLabel(l13);
visitor.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
visitor.visitInsn(Opcodes.RETURN);
Label l16 = new Label();
visitor.visitLabel(l16);
visitor.visitLocalVariable("this", getClassEnhancer().getClassDescriptor(), null, l0, l16, 0);
visitor.visitLocalVariable(argNames[0], EnhanceUtils.CD_Object, null, l0, l16, 1);
visitor.visitLocalVariable(argNames[1], "[I", null, l0, l16, 2);
visitor.visitLocalVariable("other", getClassEnhancer().getClassDescriptor(), null, l9, l16, 3);
visitor.visitLocalVariable("i", "I", null, l12, l16, 4);
visitor.visitMaxs(4, 5);
visitor.visitEnd();
}
use of org.datanucleus.enhancer.asm.Label in project datanucleus-core by datanucleus.
the class CopyKeyFieldsFromObjectId 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], getNamer().getObjectIdFieldConsumerDescriptor(), null, startLabel, endLabel, 1);
visitor.visitLocalVariable(argNames[1], EnhanceUtils.CD_Object, null, startLabel, endLabel, 2);
visitor.visitMaxs(0, 3);
} else {
int[] pkFieldNums = cmd.getPKMemberPositions();
String objectIdClass = cmd.getObjectidClass();
String ACN_objectIdClass = objectIdClass.replace('.', '/');
if (IdentityUtils.isSingleFieldIdentityClass(objectIdClass)) {
// SingleFieldIdentity
Label startLabel = new Label();
visitor.visitLabel(startLabel);
// if (fc == null) throw new IllegalArgumentException("...");
visitor.visitVarInsn(Opcodes.ALOAD, 1);
Label l1 = new Label();
visitor.visitJumpInsn(Opcodes.IFNONNULL, l1);
visitor.visitTypeInsn(Opcodes.NEW, "java/lang/IllegalArgumentException");
visitor.visitInsn(Opcodes.DUP);
visitor.visitLdcInsn("ObjectIdFieldConsumer is null");
visitor.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/IllegalArgumentException", "<init>", "(Ljava/lang/String;)V");
visitor.visitInsn(Opcodes.ATHROW);
// if (!(oid instanceof LongIdentity)) throw new ClassCastException("...");
visitor.visitLabel(l1);
visitor.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
visitor.visitVarInsn(Opcodes.ALOAD, 2);
visitor.visitTypeInsn(Opcodes.INSTANCEOF, ACN_objectIdClass);
Label l5 = new Label();
visitor.visitJumpInsn(Opcodes.IFNE, l5);
visitor.visitTypeInsn(Opcodes.NEW, "java/lang/ClassCastException");
visitor.visitInsn(Opcodes.DUP);
visitor.visitLdcInsn("oid is not instanceof " + objectIdClass);
visitor.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/ClassCastException", "<init>", "(Ljava/lang/String;)V");
visitor.visitInsn(Opcodes.ATHROW);
// XXXIdentity o = (XXXIdentity) oid;
visitor.visitLabel(l5);
visitor.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
visitor.visitVarInsn(Opcodes.ALOAD, 2);
visitor.visitTypeInsn(Opcodes.CHECKCAST, ACN_objectIdClass);
visitor.visitVarInsn(Opcodes.ASTORE, 3);
// fc.storeXXXField(1, o.getKey());
Label l9 = new Label();
visitor.visitLabel(l9);
visitor.visitVarInsn(Opcodes.ALOAD, 1);
EnhanceUtils.addBIPUSHToMethod(visitor, pkFieldNums[0]);
AbstractMemberMetaData fmd = cmd.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, 3);
visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, ACN_objectIdClass, "getKey", "()" + getKeyReturnDesc);
visitor.visitMethodInsn(Opcodes.INVOKESTATIC, ACN_fieldType, "valueOf", "(" + getKeyReturnDesc + ")L" + ACN_fieldType + ";");
visitor.visitMethodInsn(Opcodes.INVOKEINTERFACE, getNamer().getObjectIdFieldConsumerAsmClassName(), "storeObjectField", "(I" + EnhanceUtils.CD_Object + ")V");
} else {
// PK field isn't a primitive wrapper
visitor.visitVarInsn(Opcodes.ALOAD, 3);
visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, ACN_objectIdClass, "getKey", "()" + getNamer().getTypeDescriptorForSingleFieldIdentityGetKey(objectIdClass));
visitor.visitMethodInsn(Opcodes.INVOKEINTERFACE, getNamer().getObjectIdFieldConsumerAsmClassName(), "store" + getNamer().getTypeNameForUseWithSingleFieldIdentity(objectIdClass) + "Field", "(I" + getNamer().getTypeDescriptorForSingleFieldIdentityGetKey(objectIdClass) + ")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], getNamer().getObjectIdFieldConsumerDescriptor(), null, startLabel, endLabel, 1);
visitor.visitLocalVariable(argNames[1], EnhanceUtils.CD_Object, null, startLabel, endLabel, 2);
visitor.visitLocalVariable("o", getNamer().getSingleFieldIdentityDescriptor(objectIdClass), null, l9, endLabel, 3);
visitor.visitMaxs(3, 4);
} 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);
Label l4 = new Label();
visitor.visitJumpInsn(Opcodes.IFNONNULL, l4);
visitor.visitTypeInsn(Opcodes.NEW, "java/lang/IllegalArgumentException");
visitor.visitInsn(Opcodes.DUP);
visitor.visitLdcInsn("ObjectIdFieldConsumer is null");
visitor.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/IllegalArgumentException", "<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, 2);
visitor.visitTypeInsn(Opcodes.INSTANCEOF, ACN_objectIdClass);
Label l5 = new Label();
visitor.visitJumpInsn(Opcodes.IFNE, l5);
visitor.visitTypeInsn(Opcodes.NEW, "java/lang/ClassCastException");
visitor.visitInsn(Opcodes.DUP);
visitor.visitLdcInsn("oid is not instanceof " + objectIdClass);
visitor.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/ClassCastException", "<init>", "(Ljava/lang/String;)V");
visitor.visitInsn(Opcodes.ATHROW);
visitor.visitLabel(l5);
visitor.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
visitor.visitVarInsn(Opcodes.ALOAD, 2);
visitor.visitTypeInsn(Opcodes.CHECKCAST, ACN_objectIdClass);
visitor.visitVarInsn(Opcodes.ASTORE, 3);
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 typeMethodName = EnhanceUtils.getTypeNameForPersistableMethod(fmd.getType());
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, 1);
EnhanceUtils.addBIPUSHToMethod(visitor, fmd.getFieldId());
visitor.visitVarInsn(Opcodes.ALOAD, 0);
visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, getClassEnhancer().getASMClassName(), getNamer().getGetExecutionContextMethodName(), "()L" + getNamer().getExecutionContextAsmClassName() + ";");
visitor.visitVarInsn(Opcodes.ALOAD, 3);
// TODO Cater for property, or 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.visitMethodInsn(Opcodes.INVOKEINTERFACE, getNamer().getObjectIdFieldConsumerAsmClassName(), "storeObjectField", "(ILjava/lang/Object;)V");
} else {
// Standard application-identity
if (fmd instanceof PropertyMetaData) {
// Field in PK is property, hence use getXXX in PK
visitor.visitVarInsn(Opcodes.ALOAD, 1);
EnhanceUtils.addBIPUSHToMethod(visitor, fmd.getFieldId());
visitor.visitVarInsn(Opcodes.ALOAD, 3);
visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, ACN_objectIdClass, ClassUtils.getJavaBeanGetterName(fmd.getName(), fmd.getTypeName().equals("boolean")), "()" + Type.getDescriptor(fmd.getType()));
visitor.visitMethodInsn(Opcodes.INVOKEINTERFACE, getNamer().getObjectIdFieldConsumerAsmClassName(), "store" + typeMethodName + "Field", "(I" + EnhanceUtils.getTypeDescriptorForEnhanceMethod(fmd.getType()) + ")V");
} else if (Modifier.isPublic(pkFieldModifiers)) {
// Field in PK is public so access directly
visitor.visitVarInsn(Opcodes.ALOAD, 1);
EnhanceUtils.addBIPUSHToMethod(visitor, fmd.getFieldId());
visitor.visitVarInsn(Opcodes.ALOAD, 3);
visitor.visitFieldInsn(Opcodes.GETFIELD, ACN_objectIdClass, fmd.getName(), fieldTypeDesc);
visitor.visitMethodInsn(Opcodes.INVOKEINTERFACE, getNamer().getObjectIdFieldConsumerAsmClassName(), "store" + typeMethodName + "Field", "(I" + EnhanceUtils.getTypeDescriptorForEnhanceMethod(fmd.getType()) + ")V");
} else {
// Field in PK is protected/private so use reflection, generating
// "Field field = o.getClass().getDeclaredField("pmIDFloat");"
// "field.setAccessible(true);"
// "fc.storeObjectField(1, field.get(o));"
visitor.visitVarInsn(Opcodes.ALOAD, 3);
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, 4);
if (reflectionFieldStart == null) {
reflectionFieldStart = new Label();
visitor.visitLabel(reflectionFieldStart);
}
visitor.visitVarInsn(Opcodes.ALOAD, 4);
visitor.visitInsn(Opcodes.ICONST_1);
visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/reflect/Field", "setAccessible", "(Z)V");
visitor.visitVarInsn(Opcodes.ALOAD, 1);
EnhanceUtils.addBIPUSHToMethod(visitor, fmd.getFieldId());
visitor.visitVarInsn(Opcodes.ALOAD, 4);
visitor.visitVarInsn(Opcodes.ALOAD, 3);
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.visitMethodInsn(Opcodes.INVOKEINTERFACE, getNamer().getObjectIdFieldConsumerAsmClassName(), "store" + typeMethodName + "Field", "(I" + EnhanceUtils.getTypeDescriptorForEnhanceMethod(fmd.getType()) + ")V");
}
}
}
// catch of the try-catch
visitor.visitLabel(l1);
Label l20 = new Label();
visitor.visitJumpInsn(Opcodes.GOTO, l20);
visitor.visitLabel(l2);
visitor.visitFrame(Opcodes.F_FULL, 4, new Object[] { getClassEnhancer().getASMClassName(), getClassEnhancer().getNamer().getObjectIdFieldConsumerAsmClassName(), "java/lang/Object", ACN_objectIdClass }, 1, new Object[] { "java/lang/Exception" });
visitor.visitVarInsn(Opcodes.ASTORE, 4);
visitor.visitLabel(l20);
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], getNamer().getObjectIdFieldConsumerDescriptor(), null, startLabel, endLabel, 1);
visitor.visitLocalVariable(argNames[1], EnhanceUtils.CD_Object, null, startLabel, endLabel, 2);
visitor.visitLocalVariable("o", "L" + ACN_objectIdClass + ";", null, l0, endLabel, 3);
if (reflectionFieldStart != null) {
visitor.visitLocalVariable("field", "Ljava/lang/reflect/Field;", null, reflectionFieldStart, l2, 4);
visitor.visitMaxs(4, 5);
} else {
visitor.visitMaxs(4, 4);
}
}
}
} else {
// datastore/nondurable identity
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], "L" + getNamer().getObjectIdFieldConsumerAsmClassName() + ";", null, startLabel, endLabel, 1);
visitor.visitLocalVariable(argNames[1], EnhanceUtils.CD_Object, null, startLabel, endLabel, 2);
visitor.visitMaxs(0, 3);
}
visitor.visitEnd();
}
use of org.datanucleus.enhancer.asm.Label in project datanucleus-core by datanucleus.
the class IsDirty method execute.
/**
* Method to add the contents of the class method.
*/
public void execute() {
visitor.visitCode();
boolean detachable = enhancer.getClassMetaData().isDetachable();
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.IFNULL, l1);
Label l2 = new Label();
visitor.visitLabel(l2);
visitor.visitVarInsn(Opcodes.ALOAD, 0);
visitor.visitFieldInsn(Opcodes.GETFIELD, getClassEnhancer().getASMClassName(), getNamer().getStateManagerFieldName(), getNamer().getStateManagerDescriptor());
visitor.visitVarInsn(Opcodes.ALOAD, 0);
visitor.visitMethodInsn(Opcodes.INVOKEINTERFACE, getNamer().getStateManagerAsmClassName(), "isDirty", "(" + getNamer().getPersistableDescriptor() + ")Z");
visitor.visitInsn(Opcodes.IRETURN);
visitor.visitLabel(l1);
visitor.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
if (!detachable) {
visitor.visitInsn(Opcodes.ICONST_0);
visitor.visitInsn(Opcodes.IRETURN);
} else {
visitor.visitVarInsn(Opcodes.ALOAD, 0);
visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, getClassEnhancer().getASMClassName(), getNamer().getIsDetachedMethodName(), "()Z");
Label l3 = new Label();
visitor.visitJumpInsn(Opcodes.IFNE, l3);
visitor.visitInsn(Opcodes.ICONST_0);
visitor.visitInsn(Opcodes.IRETURN);
visitor.visitLabel(l3);
visitor.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
visitor.visitVarInsn(Opcodes.ALOAD, 0);
visitor.visitFieldInsn(Opcodes.GETFIELD, getClassEnhancer().getASMClassName(), getNamer().getDetachedStateFieldName(), "[" + EnhanceUtils.CD_Object);
visitor.visitInsn(Opcodes.ICONST_3);
visitor.visitInsn(Opcodes.AALOAD);
visitor.visitTypeInsn(Opcodes.CHECKCAST, "java/util/BitSet");
visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/util/BitSet", "length", "()I");
Label l5 = new Label();
visitor.visitJumpInsn(Opcodes.IFGT, l5);
visitor.visitInsn(Opcodes.ICONST_0);
visitor.visitInsn(Opcodes.IRETURN);
visitor.visitLabel(l5);
visitor.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
visitor.visitInsn(Opcodes.ICONST_1);
visitor.visitInsn(Opcodes.IRETURN);
}
Label endLabel = new Label();
visitor.visitLabel(endLabel);
visitor.visitLocalVariable("this", getClassEnhancer().getClassDescriptor(), null, startLabel, endLabel, 0);
visitor.visitMaxs(2, 1);
visitor.visitEnd();
}
use of org.datanucleus.enhancer.asm.Label in project datanucleus-core by datanucleus.
the class IsXXX method execute.
/**
* Method to add the contents of the class method.
* Creates the method as follows
* <pre>
* return dnStateManager != null ? dnStateManager.isXXX(this) : false;
* </pre>
* where "isXXX" is replaced by the output of "getStateManagerIsMethod"
*/
public void execute() {
visitor.visitCode();
Label l0 = new Label();
visitor.visitLabel(l0);
visitor.visitVarInsn(Opcodes.ALOAD, 0);
visitor.visitFieldInsn(Opcodes.GETFIELD, getClassEnhancer().getASMClassName(), getNamer().getStateManagerFieldName(), getNamer().getStateManagerDescriptor());
Label l1 = new Label();
visitor.visitJumpInsn(Opcodes.IFNULL, l1);
visitor.visitVarInsn(Opcodes.ALOAD, 0);
visitor.visitFieldInsn(Opcodes.GETFIELD, getClassEnhancer().getASMClassName(), getNamer().getStateManagerFieldName(), getNamer().getStateManagerDescriptor());
visitor.visitVarInsn(Opcodes.ALOAD, 0);
visitor.visitMethodInsn(Opcodes.INVOKEINTERFACE, getNamer().getStateManagerAsmClassName(), getStateManagerIsMethod(), "(" + getNamer().getPersistableDescriptor() + ")Z");
Label l2 = new Label();
visitor.visitJumpInsn(Opcodes.GOTO, l2);
visitor.visitLabel(l1);
visitor.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
visitor.visitInsn(Opcodes.ICONST_0);
visitor.visitLabel(l2);
visitor.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { Opcodes.INTEGER });
visitor.visitInsn(Opcodes.IRETURN);
Label l3 = new Label();
visitor.visitLabel(l3);
visitor.visitLocalVariable("this", getClassEnhancer().getClassDescriptor(), null, l0, l3, 0);
visitor.visitMaxs(2, 1);
visitor.visitEnd();
}
Aggregations