Writing a profiling I would also implement the typical task of heap profiling. Specifically I would like to track, which thread has allocated how much data? Using JVMTI I thought it’s sufficient to hook to the events VM Object Allocation and Object Free. Sadly I read the first event is not triggered due to calls made to new.
The last idea I had was to check teh event MethodExit if its name is <init> and thus declare this call as an object allocation. However, within this event I cannot get the object and thus I cannot invoke GetObjectSize.
Simply iterating over the heap, bears no information regarding which object was allocated by which thread. Does anyone have an idea how to implement this?
Is there some reason you can’t call
GetObjectSizefrom theMethodEntryevent for a constructor?If you’re interested in executing code before a method returns, then you can listen for the
MethodEntryevent, and if the method is named<init>, you can callNotifyFramePopto listen for theFramePopevent for the current frame. This event is similar to theMethodExitevent, but occurs before the method returns so you can still get thethisobject.