0

Is it possible to retrieve the current jobject when the method entry or method exit event is triggered? I would like to tag the jobjects which are entered on certain methods. Currently I can only retrieve the method defining class, but not the object.

In the JVMTI API I don't find anything similiar.

I could iterate over all instances of the method definining class in the heap, this would, however, not give me any information on which object exactly the method was called.

Konrad Reiche
  • 27,743
  • 15
  • 106
  • 143

1 Answers1

0

Use BCI to insert JNI calls to your agent, as demonstrated in the heapProfiler example included with JVMTI. You can pass the object as a parameter to your method (1); this way you don't have to listen to every method call.

MethodEntry events occur for static and native methods, so it's not reasonable for them to include an instance object, plus JVMTI discourages the use of MethodEntry due to its terrible performance.

If you really must use MethodEntry, then you could obtain the object by accessing it as a local variable (GetLocalObject). It should be in slot 0 (check using the local variables table).


(1) You can't access objects which have not been initialized, so you need to insert your call after super if you're profiling constructor methods.

Stephen Nelson
  • 939
  • 1
  • 7
  • 22