mirror of
https://github.com/apache/openjpa.git
synced 2025-03-05 16:09:12 +00:00
OPENJPA-2911 isLoaded via ASM
This commit is contained in:
parent
a8cb9d9d3d
commit
71b0f0b2c6
@ -96,12 +96,12 @@ public class DataCachePCDataGenerator extends PCDataGenerator {
|
|||||||
enhanceToData(cnt);
|
enhanceToData(cnt);
|
||||||
enhanceToNestedData(cnt);
|
enhanceToNestedData(cnt);
|
||||||
replaceNewEmbeddedPCData(cnt);
|
replaceNewEmbeddedPCData(cnt);
|
||||||
|
addSynchronization(cnt);
|
||||||
|
|
||||||
//X TODO REMOVE
|
//X TODO REMOVE
|
||||||
BCClass _bc = new Project().loadClass(cnt.getClassNode().name.replace("/", "."));
|
BCClass _bc = new Project().loadClass(cnt.getClassNode().name.replace("/", "."));
|
||||||
AsmHelper.readIntoBCClass(cnt, _bc);
|
AsmHelper.readIntoBCClass(cnt, _bc);
|
||||||
|
|
||||||
addSynchronization(_bc);
|
|
||||||
addTimeout(_bc);
|
addTimeout(_bc);
|
||||||
|
|
||||||
cnt.setClassNode(AsmHelper.toClassNode(cnt.getProject(), _bc).getClassNode());
|
cnt.setClassNode(AsmHelper.toClassNode(cnt.getProject(), _bc).getClassNode());
|
||||||
@ -322,12 +322,12 @@ public class DataCachePCDataGenerator extends PCDataGenerator {
|
|||||||
code.calculateMaxLocals();
|
code.calculateMaxLocals();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addSynchronization(BCClass bc) {
|
private void addSynchronization(ClassNodeTracker cnt) {
|
||||||
BCMethod[] methods = bc.getDeclaredMethods();
|
final ClassNode classNode = cnt.getClassNode();
|
||||||
for (BCMethod bcMethod : methods) {
|
for (MethodNode m : classNode.methods) {
|
||||||
if (bcMethod.isPublic()
|
if ((m.access & Opcodes.ACC_PUBLIC) > 0 && _synchs.contains(m.name)) {
|
||||||
&& _synchs.contains(bcMethod.getName()))
|
m.access |= Opcodes.ACC_SYNCHRONIZED;
|
||||||
bcMethod.setSynchronized(true);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// add synchronized isLoaded call.
|
// add synchronized isLoaded call.
|
||||||
@ -335,17 +335,20 @@ public class DataCachePCDataGenerator extends PCDataGenerator {
|
|||||||
// {
|
// {
|
||||||
// return super.isLoaded (field);
|
// return super.isLoaded (field);
|
||||||
// }
|
// }
|
||||||
BCMethod method = bc.declareMethod("isLoaded", boolean.class,
|
MethodNode meth = new MethodNode(Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNCHRONIZED,
|
||||||
new Class[]{ int.class });
|
"isLoaded",
|
||||||
method.setSynchronized(true);
|
Type.getMethodDescriptor(Type.BOOLEAN_TYPE, Type.INT_TYPE),
|
||||||
Code code = method.getCode(true);
|
null, null);
|
||||||
code.aload().setThis();
|
classNode.methods.add(meth);
|
||||||
code.iload().setParam(0);
|
InsnList instructions = meth.instructions;
|
||||||
code.invokespecial().setMethod(AbstractPCData.class, "isLoaded",
|
|
||||||
boolean.class, new Class[]{ int.class });
|
instructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); // this
|
||||||
code.calculateMaxLocals();
|
instructions.add(new VarInsnNode(Opcodes.ILOAD, 1)); // 1st parameter int
|
||||||
code.calculateMaxStack();
|
instructions.add(new MethodInsnNode(Opcodes.INVOKESPECIAL,
|
||||||
code.ireturn();
|
Type.getInternalName(AbstractPCData.class),
|
||||||
|
"isLoaded",
|
||||||
|
Type.getMethodDescriptor(Type.BOOLEAN_TYPE, Type.INT_TYPE)));
|
||||||
|
instructions.add(new InsnNode(Opcodes.IRETURN));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user