JVM以编程方式获取分配调用堆栈
JVM getting allocation call stacks programmatically
这是
的后续问题
因此,我一直从“编程访问”的角度探索现代分析器的功能,并且遇到了一些超出我理解的事情。
这次我偶然发现了 JProfiler 中的“分配调用树”功能:
我确实看到,为了获得此类信息,我必须默认以 1/10 的比率触发抽样分配,然后指定(最好)分配的包 classed 将被记录。
步骤 1
步骤 2
但后来我真的不明白有关调用堆栈的信息如何与有关分配的对象的信息“匹配”。
当然我的问题不是关于 JProfiler 的实现细节,我理解它是一个商业工具,代码和一切都很接近,而是关于如何检索这种信息的一般理解。
我最初的猜测是它以某种方式“检测”已经加载的 class 文件以“拦截”这些对象的每一次分配(采样率不会减慢进程太多)但是然后呢?它会调用类似 Thread.currentThread().getStackTrace()
的东西并记录导致分配的实际堆栈跟踪吗?
另一方面,它在“采样模式”(与仪器相反)中激活 + 存在性能问题 - 这听起来非常昂贵(阅读,不应在生产中使用)对我来说,但我可能是错的,所以任何建议将不胜感激。
My initial guess is that it somehow "instruments" the already-loaded class files to
"intercept" each and every allocation for these objects
自 Java 11 次交付 JEP 331 it uses these capabilities in the native JVMTI in order to sample allocations. Before Java 11, it instruments the java.lang.Object
constructor. As for the call stacks, it depends on whether instrumentation or sampling is used. For instrumentation, it uses the call stack that is already built by the instrumentation. For sampling, the call stack built by sampling is not precise enough, so it queries the call stack through JVMTI。
Does it call something like Thread.currentThread().getStackTrace()
采样有点像那样,但在 Java 中进行采样会产生巨大的开销,因为有许多二次分配。 JVMTI 是本机接口,可以更有效地执行此操作。
这是
因此,我一直从“编程访问”的角度探索现代分析器的功能,并且遇到了一些超出我理解的事情。
这次我偶然发现了 JProfiler 中的“分配调用树”功能:
我确实看到,为了获得此类信息,我必须默认以 1/10 的比率触发抽样分配,然后指定(最好)分配的包 classed 将被记录。
步骤 1
步骤 2
但后来我真的不明白有关调用堆栈的信息如何与有关分配的对象的信息“匹配”。
当然我的问题不是关于 JProfiler 的实现细节,我理解它是一个商业工具,代码和一切都很接近,而是关于如何检索这种信息的一般理解。
我最初的猜测是它以某种方式“检测”已经加载的 class 文件以“拦截”这些对象的每一次分配(采样率不会减慢进程太多)但是然后呢?它会调用类似 Thread.currentThread().getStackTrace()
的东西并记录导致分配的实际堆栈跟踪吗?
另一方面,它在“采样模式”(与仪器相反)中激活 + 存在性能问题 - 这听起来非常昂贵(阅读,不应在生产中使用)对我来说,但我可能是错的,所以任何建议将不胜感激。
My initial guess is that it somehow "instruments" the already-loaded class files to "intercept" each and every allocation for these objects
自 Java 11 次交付 JEP 331 it uses these capabilities in the native JVMTI in order to sample allocations. Before Java 11, it instruments the java.lang.Object
constructor. As for the call stacks, it depends on whether instrumentation or sampling is used. For instrumentation, it uses the call stack that is already built by the instrumentation. For sampling, the call stack built by sampling is not precise enough, so it queries the call stack through JVMTI。
Does it call something like Thread.currentThread().getStackTrace()
采样有点像那样,但在 Java 中进行采样会产生巨大的开销,因为有许多二次分配。 JVMTI 是本机接口,可以更有效地执行此操作。