mirror of https://github.com/apache/openjpa.git
OPENJPA-2911 AuxilaryEnhancer in ASM
This commit is contained in:
parent
fb20da5063
commit
0ab02d6965
|
@ -605,10 +605,9 @@ public class PCEnhancer {
|
|||
addAttachDetachCode();
|
||||
addSerializationCode();
|
||||
addCloningCode();
|
||||
runAuxiliaryEnhancers();
|
||||
|
||||
AsmHelper.readIntoBCClass(pc, _pc);
|
||||
|
||||
runAuxiliaryEnhancers();
|
||||
return ENHANCE_PC;
|
||||
}
|
||||
return ENHANCE_AWARE;
|
||||
|
@ -4209,7 +4208,7 @@ public class PCEnhancer {
|
|||
*/
|
||||
private void runAuxiliaryEnhancers() {
|
||||
for (AuxiliaryEnhancer auxEnhancer : _auxEnhancers) {
|
||||
auxEnhancer.run(_pc, _meta);
|
||||
auxEnhancer.run(pc.getClassNode(), _meta);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5747,10 +5746,7 @@ public class PCEnhancer {
|
|||
*/
|
||||
public interface AuxiliaryEnhancer
|
||||
{
|
||||
void run (BCClass bc, ClassMetaData meta);
|
||||
|
||||
@Deprecated
|
||||
boolean skipEnhance(BCMethod m);
|
||||
void run (ClassNode classNode, ClassMetaData meta);
|
||||
|
||||
boolean skipEnhance(MethodNode m);
|
||||
}
|
||||
|
|
|
@ -28,10 +28,13 @@ import org.apache.openjpa.meta.AccessCode;
|
|||
import org.apache.openjpa.meta.ClassMetaData;
|
||||
import org.apache.openjpa.meta.FieldMetaData;
|
||||
|
||||
import org.apache.openjpa.util.asm.AsmHelper;
|
||||
import org.apache.xbean.asm9.Opcodes;
|
||||
import org.apache.xbean.asm9.Type;
|
||||
import org.apache.xbean.asm9.tree.ClassNode;
|
||||
import org.apache.xbean.asm9.tree.InsnList;
|
||||
import org.apache.xbean.asm9.tree.MethodInsnNode;
|
||||
import org.apache.xbean.asm9.tree.MethodNode;
|
||||
import serp.bytecode.BCClass;
|
||||
import serp.bytecode.BCMethod;
|
||||
import serp.bytecode.Code;
|
||||
|
||||
/**
|
||||
* FetchStatisticsAuxEnhancer adds the call back function to each persistent fields in the persistent entity which
|
||||
|
@ -43,13 +46,8 @@ public class FetchStatisticsAuxEnhancer implements AuxiliaryEnhancer {
|
|||
+ "(pc(.)*DetachedState)?(pc(.)*EnhancementContractVersion)?(pc(.)*ManagedFieldCount)?(pc(.)*GetVersion)?";
|
||||
|
||||
@Override
|
||||
public void run(BCClass bcc, ClassMetaData cmd) {
|
||||
addEnhancement(bcc, cmd);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean skipEnhance(BCMethod arg0) {
|
||||
return false;
|
||||
public void run(ClassNode classNode, ClassMetaData cmd) {
|
||||
addEnhancement(classNode, cmd);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -57,21 +55,26 @@ public class FetchStatisticsAuxEnhancer implements AuxiliaryEnhancer {
|
|||
return false;
|
||||
}
|
||||
|
||||
private void addEnhancement(BCClass bcc, ClassMetaData cmd) {
|
||||
private void addEnhancement(ClassNode classNode, ClassMetaData cmd) {
|
||||
Log log = cmd.getRepository().getConfiguration().getLog(OpenJPAConfiguration.LOG_RUNTIME);
|
||||
FetchStatsCollector.setlogger(log);
|
||||
for (BCMethod meth : bcc.getMethods()) {
|
||||
String methodName = meth.getName();
|
||||
String className = classNode.name.replace("/", ".");
|
||||
for (MethodNode meth : classNode.methods) {
|
||||
String methodName = meth.name;
|
||||
FieldMetaData fmd = getFieldName(methodName, cmd);
|
||||
if (fmd != null && needsTracking(fmd, methodName, cmd)) {
|
||||
String fqn = bcc.getName() + "." + fmd.getName();
|
||||
String fqn = className + "." + fmd.getName();
|
||||
FetchStatsCollector.registerField(fqn);
|
||||
FetchStatsCollector.registerEntity(cmd);
|
||||
|
||||
Code code = meth.getCode(false);
|
||||
code.constant().setValue(fqn);
|
||||
code.invokestatic().setMethod(FetchStatsCollector.class, "hit", void.class,
|
||||
new Class[] { String.class });
|
||||
InsnList instructions = new InsnList();
|
||||
|
||||
instructions.add(AsmHelper.getLoadConstantInsn(fqn));
|
||||
instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC,
|
||||
Type.getInternalName(FetchStatsCollector.class),
|
||||
"hit",
|
||||
Type.getMethodDescriptor(Type.VOID_TYPE, Type.getType(String.class))));
|
||||
meth.instructions.insert(instructions);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue