开发者

Thread-aware heap allocation tracking with JVMTI

开发者 https://www.devze.com 2023-03-13 18:52 出处:网络
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 h

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 V开发者_JAVA百科M 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?


A quick glance into the _new implementation of the Hotspot VM (templateTable_x86_64.cpp) seems to indicate, that _new doesn't offer any hooks for JVMTI (not even in the slow case it seems). So if your trick doesn't work, I don't see any other possibility - but I'm by no means an expert for JVMTI.

I assume compiling your own Hotspot VM with a small patch isn't especially useful for you?


This heapTracker demo illustrates you how to track all the objects in the heap. Because the VMObjectAlloc Event is sent only when reflection occurs, the demo uses ByteCodeInstrument to track new object allocation.


You can use getCurrentThread function to know which thread the object is belong to.


Is there some reason you can't call GetObjectSize from the MethodEntry event for a constructor?

If you're interested in executing code before a method returns, then you can listen for the MethodEntry event, and if the method is named <init>, you can call NotifyFramePop to listen for the FramePop event for the current frame. This event is similar to the MethodExit event, but occurs before the method returns so you can still get the this object.

0

精彩评论

暂无评论...
验证码 换一张
取 消