Fully featured low overhead profiler for Java EE and Java SE platforms.
Easy to use performance and memory .NET profiler for Windows and Linux.
Performance monitoring and profiling of Jenkins, Bamboo, TeamCity, Gradle, Maven, Ant and JUnit.

Callback method parameter annotation @ClassRef

Callback parameter annotated with @ClassRef will be assigned with a reference to the class where the method being executed is defined.

Declaration type

Callback parameter annotated with @ClassRef should be declared as java.lang.Class.

In which callbacks can be used

Parameter annotated with @ClassRef can be used in any callback.

Notes on using @ClassRef vs @This

Use @ClassRef when applying probe to static methods, because @This is null in that case.

When applying probe to non-static methods, you can either use @ClassRef or call getClass() method of the object passed via @This.

However, please note the difference: the class returned by getClass() method will be the actual class of the object whose method is running, while @ClassRef will give the class where the method is defined. The result will be different if the method is defined in a base class and is not overridden in derived classes.

Example:

package com.foo;

class Base {
  void f() {...}
  void g() {...}
}

class Derived extends Base {
 // f() is overridden, g() is not overridden
 void f() {...}
}

...

@MethodPattern("foo.bar.*:*(*)")
public class MyProbe {
  public static void onEnter(@This Base _this, @ClassRef Class _class) {
    System.out.println(_this.getClass());
    System.out.println(_class);
  }
}

...

Derived obj = new Derived();

// Applying MyProbe to this call will print:
// class com.foo.Derived
// class com.foo.Derived
obj.f();

// Applying MyProbe to this call will print:
// class com.foo.Derived
// class com.foo.Base
obj.g();

YourKit uses cookies and other tracking technologies to improve your browsing experience on our website, to show you personalized content and targeted ads, to analyze our website traffic, and to understand where our visitors are coming from.

By browsing our website, you consent to our use of cookies and other tracking technologies in accordance with the Privacy Policy.