0

I want to make a btrace script to profile object creation and destruction. For that I need to know Which Java methods are called when creating or deleting an Object or a Class?

Thanks in advance.

neo
  • 111
  • 12

1 Answers1

1

For the object construction you would use the constructor methods

@OnMethod(clazz="class.name", method="<init>")
...

Tracing destruction is more difficult - you can't hook into the finalize method because it is not mandatory for an object to provide one.

Right now you would need to run BTrace in unsafe mode and provide your own logic using eg. PhantomReference to get notification when an instance will just have been garbage collected ('destructed').

JB-
  • 2,615
  • 18
  • 17