jdk 11 引入了 低开销的 Heap Profiling
具体api如下The user facing API for the heap sampling feature proposed here consists of an extension to JVMTI that allows for heap profiling. The following systems rely on an event notification system that would provide a callback such as:
void JNICALL
SampledObjectAlloc(jvmtiEnv *jvmti_env,
JNIEnv* jni_env,
jthread thread,
jobject object,
jclass object_klass,
jlong size)
where:
thread is the thread allocating the jobject,
object is the reference to the sampled jobject,
object_klass is the class for the jobject, and
size is the size of the allocation.
JEP 331: Low-Overhead Heap Profiling
jdk11前开发的话成本比较高,需要从jmx端口映射jvm手动做监控,实现成本相对高。