JVMTM Tool Interface
Heap Monitoring functions:
Set Heap Sampling Rate
SampledObjectAlloc event when objects are allocated.
Each thread keeps a counter of bytes allocated. The event will only be generated
when that counter exceeds an average of
since the last sample.
sampling_rate to 0 will cause an event to be
generated by each allocation supported by the system.
The sampling rate in bytes. The sampler uses a statistical approach to
generate an event, on average, once for every
sampling_rate bytes of
memory allocated by a given thread.
Passing 0 as a sampling rate generates a sample for every allocation.
Note: The overhead of this feature is directly correlated with the sampling rate.
A high sampling rate, such as 1024 bytes, will incur a high overhead.
A lower rate, such as 1024KB, will have a much lower overhead. Sampling should only
be used with an understanding that it may impact performance.
Sampled Object Allocation
Sent when an allocated object is sampled.
By default, the sampling rate is a geometric variable with a 512KB mean.
Each thread tracks how many bytes it has allocated since it sent the last event.
When the number of bytes exceeds the sampling rate, it will send another event.
This implies that, on average, one object will be sampled every time a thread has
allocated 512KB bytes since the last sample.
Note that this is a geometric variable: it will not sample every 512KB precisely.
The goal of this is to ensure high quality sampling even if allocation is
happening in a fixed pattern (i.e., the same set of objects are being allocated
If another sampling rate is required, the user can call
SetHeapSamplingRate with a strictly positive integer value, representing
the new sampling rate.
This event is sent once the sampled allocation has been performed. It provides the object, stack trace
of the allocation, the thread allocating, the size of allocation, and the object's class.
A typical use case of this system is to determine where heap allocations originate.
In conjunction with weak references and the function
GetStackTrace, a user can track which objects were allocated from which
stack trace, and which are still live during the execution of the program.
The JNI environment of the event (current) thread.
Thread allocating the object.
JNI local reference to the object that was allocated.
JNI local reference to the class of the object
Size of the object (in bytes). See