The case of @This at constructor entry point fixed
This commit is contained in:
+16
-7
@@ -324,7 +324,7 @@ public class InterceptionInstrumenter {
|
|||||||
if (enterDataWritten) return;
|
if (enterDataWritten) return;
|
||||||
enterDataWritten = true;
|
enterDataWritten = true;
|
||||||
for (MethodData methodData : enterData) {
|
for (MethodData methodData : enterData) {
|
||||||
invokeMethod(access, name, desc, getInstructionAdapter(), methodData);
|
invokeMethod(access, name, desc, getInstructionAdapter(), methodData, "<init>".equals(name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -340,7 +340,7 @@ public class InterceptionInstrumenter {
|
|||||||
case ARETURN:
|
case ARETURN:
|
||||||
case ATHROW:
|
case ATHROW:
|
||||||
for (MethodData methodData : exitData) {
|
for (MethodData methodData : exitData) {
|
||||||
invokeMethod(access, name, desc, getInstructionAdapter(), methodData);
|
invokeMethod(access, name, desc, getInstructionAdapter(), methodData, false);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -361,11 +361,11 @@ public class InterceptionInstrumenter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private TraceMethodVisitor getDumpingVisitorWrapper(MethodVisitor mv, final String name, final String desc) {
|
private TraceMethodVisitor getDumpingVisitorWrapper(MethodVisitor mv, final String methodName, final String methodDesc) {
|
||||||
return new TraceMethodVisitor(mv, new Textifier() {
|
return new TraceMethodVisitor(mv, new Textifier() {
|
||||||
@Override
|
@Override
|
||||||
public void visitMethodEnd() {
|
public void visitMethodEnd() {
|
||||||
System.out.println(cr.getClassName() + ":" + name + desc);
|
System.out.println(cr.getClassName() + ":" + methodName + methodDesc);
|
||||||
for (Object line : getText()) {
|
for (Object line : getText()) {
|
||||||
System.out.print(line);
|
System.out.print(line);
|
||||||
}
|
}
|
||||||
@@ -379,7 +379,14 @@ public class InterceptionInstrumenter {
|
|||||||
return cw.toByteArray();
|
return cw.toByteArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void invokeMethod(int access, String instrumentedMethodName, String instrumentedMethodDesc, InstructionAdapter ia, MethodData methodData) {
|
private static void invokeMethod(
|
||||||
|
int access,
|
||||||
|
String instrumentedMethodName,
|
||||||
|
String instrumentedMethodDesc,
|
||||||
|
InstructionAdapter ia,
|
||||||
|
MethodData methodData,
|
||||||
|
boolean constructorEntryPoint
|
||||||
|
) {
|
||||||
FieldData field = methodData.getOwnerField();
|
FieldData field = methodData.getOwnerField();
|
||||||
ia.getstatic(field.getDeclaringClass(), field.getName(), field.getDesc());
|
ia.getstatic(field.getDeclaringClass(), field.getName(), field.getDesc());
|
||||||
ia.checkcast(field.getRuntimeType());
|
ia.checkcast(field.getRuntimeType());
|
||||||
@@ -392,8 +399,10 @@ public class InterceptionInstrumenter {
|
|||||||
int parameterOffset = 0;
|
int parameterOffset = 0;
|
||||||
for (int i = 0; i < parameterCount; i++) {
|
for (int i = 0; i < parameterCount; i++) {
|
||||||
if (i == methodData.getThisParameterIndex()) {
|
if (i == methodData.getThisParameterIndex()) {
|
||||||
if (isStatic) {
|
if (isStatic || constructorEntryPoint) {
|
||||||
// static method, 'this' is null
|
// a) static method, 'this' is null
|
||||||
|
// b) At the very beginning of a constructor, i.e. before any super() call, 'this' is not available
|
||||||
|
// It's too hard to detect a place right after the super() call, so we just put null instead of 'this' in such cases
|
||||||
ia.aconst(null);
|
ia.aconst(null);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
Reference in New Issue
Block a user