mirror of https://github.com/apache/openjpa.git
OPENJPA-2911 addManagedFieldCountMethod in ASM
This commit is contained in:
parent
972b5d0e62
commit
6164d355a6
|
@ -1341,12 +1341,14 @@ public class PCEnhancer {
|
||||||
*/
|
*/
|
||||||
private void addPCMethods(ClassNodeTracker classNodeTracker) throws NoSuchMethodException {
|
private void addPCMethods(ClassNodeTracker classNodeTracker) throws NoSuchMethodException {
|
||||||
addClearFieldsMethod(classNodeTracker.getClassNode());
|
addClearFieldsMethod(classNodeTracker.getClassNode());
|
||||||
|
|
||||||
addNewInstanceMethod(classNodeTracker.getClassNode(), true);
|
addNewInstanceMethod(classNodeTracker.getClassNode(), true);
|
||||||
addNewInstanceMethod(classNodeTracker.getClassNode(), false);
|
addNewInstanceMethod(classNodeTracker.getClassNode(), false);
|
||||||
|
|
||||||
|
addManagedFieldCountMethod(classNodeTracker.getClassNode());
|
||||||
|
|
||||||
AsmHelper.readIntoBCClass(classNodeTracker, _pc);
|
AsmHelper.readIntoBCClass(classNodeTracker, _pc);
|
||||||
|
|
||||||
addManagedFieldCountMethod();
|
|
||||||
addReplaceFieldsMethods();
|
addReplaceFieldsMethods();
|
||||||
addProvideFieldsMethods();
|
addProvideFieldsMethods();
|
||||||
addCopyFieldsMethod();
|
addCopyFieldsMethod();
|
||||||
|
@ -1512,19 +1514,18 @@ public class PCEnhancer {
|
||||||
instructions.add(new VarInsnNode(Opcodes.ALOAD, newPcVarPos));
|
instructions.add(new VarInsnNode(Opcodes.ALOAD, newPcVarPos));
|
||||||
instructions.add(new InsnNode(Opcodes.ARETURN));
|
instructions.add(new InsnNode(Opcodes.ARETURN));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds the <code>protected static int pcGetManagedFieldCount ()</code>
|
* Adds the <code>protected static int pcGetManagedFieldCount ()</code>
|
||||||
* method to the bytecode, returning the inherited field count added
|
* method to the bytecode, returning the inherited field count added
|
||||||
* to the number of managed fields in the current PersistenceCapable class.
|
* to the number of managed fields in the current PersistenceCapable class.
|
||||||
*/
|
*/
|
||||||
private void addManagedFieldCountMethod() {
|
private void addManagedFieldCountMethod(ClassNode classNode) {
|
||||||
// protected static int pcGetManagedFieldCount ()
|
MethodNode getFieldCountMeth = new MethodNode(Opcodes.ACC_PROTECTED | Opcodes.ACC_STATIC,
|
||||||
BCMethod method = _pc.declareMethod(PRE + "GetManagedFieldCount",
|
PRE + "GetManagedFieldCount",
|
||||||
int.class, null);
|
Type.getMethodDescriptor(Type.INT_TYPE),
|
||||||
method.setStatic(true);
|
null, null);
|
||||||
method.makeProtected();
|
classNode.methods.add(getFieldCountMeth);
|
||||||
Code code = method.getCode(true);
|
|
||||||
|
|
||||||
// return <fields> + pcInheritedFieldCount
|
// return <fields> + pcInheritedFieldCount
|
||||||
// awhite: the above should work, but I'm seeing a messed up situation
|
// awhite: the above should work, but I'm seeing a messed up situation
|
||||||
|
@ -1532,18 +1533,21 @@ public class PCEnhancer {
|
||||||
// happens before <clinit> is ever invoked, and so our
|
// happens before <clinit> is ever invoked, and so our
|
||||||
// pcInheritedFieldCount field isn't initialized! so instead,
|
// pcInheritedFieldCount field isn't initialized! so instead,
|
||||||
// return <fields> + <superclass>.pcGetManagedFieldCount ()
|
// return <fields> + <superclass>.pcGetManagedFieldCount ()
|
||||||
code.constant().setValue(_meta.getDeclaredFields().length);
|
final InsnList instructions = getFieldCountMeth.instructions;
|
||||||
|
instructions.add(new LdcInsnNode(_meta.getDeclaredFields().length));
|
||||||
if (_meta.getPCSuperclass() != null) {
|
if (_meta.getPCSuperclass() != null) {
|
||||||
Class superClass = getType(_meta.getPCSuperclassMetaData());
|
Class superClass = getType(_meta.getPCSuperclassMetaData());
|
||||||
String superName = getCreateSubclass() ?
|
String superName = getCreateSubclass() ?
|
||||||
PCEnhancer.toPCSubclassName(superClass) :
|
PCEnhancer.toPCSubclassName(superClass).replace(".", "/") :
|
||||||
superClass.getName();
|
Type.getInternalName(superClass);
|
||||||
code.invokestatic().setMethod(superName,
|
instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC,
|
||||||
PRE + "GetManagedFieldCount", int.class.getName(), null);
|
superName,
|
||||||
code.iadd();
|
PRE + "GetManagedFieldCount",
|
||||||
|
Type.getMethodDescriptor(Type.INT_TYPE)));
|
||||||
|
instructions.add(new InsnNode(Opcodes.IADD));
|
||||||
}
|
}
|
||||||
code.ireturn();
|
|
||||||
code.calculateMaxStack();
|
instructions.add(new InsnNode(Opcodes.IRETURN));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue