Java Profiler 9.0 Help
Probes: extendable profiling and monitoring
Monitoring method invocation events
Callback method parameter annotation @This
Callback parameter annotated with @This
will be assigned with a reference to the object whose method is being executed.
Declaration type
Callback parameter annotated with @This
should be declared as a reference type,
capable to store a reference to the objects whose method(s) the probe is applied to.
To make the probe applicable to any method (even static!),
declare the callback parameter as java.lang.Object.
If needed, cast the value to appropriate class in the callback body.
If the callback parameter
is declared as some reference type T other than java.lang.Object,
the probe callbacks will only be called for methods of class T
or of a class which extends T or implements T.
In particular this means that callback with parameter annotated with @This
declared as T != java.lang.Object will never be called for a static method.
In which callbacks can be used
Parameter annotated with @This can be used in any callback.
However, if more than one probe callback
has parameters annotated with @This,
all of them must be declared as same type.
@MethodPattern("*:findPerson(*)")
public class GoodProbe1 {
public static void onEnter() {/*....*/} // will only be called to methods of Person (because of onReturn()'s parameter)
public static void onReturn(@This Person person) {/*...*/} // will only be called to methods of Person
}
@MethodPattern("*:foo(*)")
public class GoodProbe2 {
public static void onEnter(@This Object _this) {/*....*/} // will be called to any methods matching the pattern
public static void onReturn(@This Object _this) {/*...*/} // will be called to any methods matching the pattern
}
@MethodPattern("*:bar(*)")
public class BadProbe2 { // the probe is invalid - @This type mismatch
public static void onEnter(@This Object _this) {/*....*/}
public static void onUncaughtException(@This String _this) {/*...*/}
}
Special notes on instrumenting a static method
If callback is applied to a static method,
parameter annotated with @This will be null.
Special notes on instrumenting a constructor
Parameter annotated with @This will be null
if it is used in onEnter() callback applied to a constructor.
Please find detail here.