如何查找哪些对象正在创建最多的垃圾 [英] How to find which objects are creating the most garbage

查看:50
本文介绍了如何查找哪些对象正在创建最多的垃圾的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含80个不同类的80个实例的应用程序.由于我的应用程序是实时的,因此这些类的某些子集生成的垃圾数量是不可接受的,并且停止世界暂停的时间太长.

I have an application with about 80 instances of 80 different classes. The amount of garbage generated by some subset of these classes is unacceptable and stop the world pauses are too long, since my application is real time.

我要查找的是哪些类负责创建堆上最大数量的对象(不是集合大小,而是对象的原始数量),因为这是导致世界停顿的原因花这么长时间.

What I want to find is which classes are responsible for creating the largest number of objects on heap (not aggregate size, but raw number of objects), since this is what causes stop the world pauses to take so long.

我如何找到这个?

如果需要JVisualVM,我有这个.

If JVisualVM is required, I have this.

推荐答案

一种非常轻量级的方法来查看每个类的对象数是类直方图.

A very lightweight approach to look at the number of objects per class is Class Histogram.

只需通过jmap -histo <PID>生成类直方图即可.

Just generate class histogram by jmap -histo <PID>.

发生世界停顿暂停时,使用-XX:+PrintClassHistogramBeforeFullGC-XX:+PrintClassHistogramAfterFullGC查看班级直方图.您可以比较快照前后的快照,以了解在世界停顿期间收集了哪些类实例.

Use -XX:+PrintClassHistogramBeforeFullGC, -XX:+PrintClassHistogramAfterFullGC to see class histograms when your stop-the-world pause occurs. You can compare the snapshot before/after to see which class instances get collected during the stop-the-world pause.

有关详细信息,请参见按类分析垃圾收集对象实例的数量.

See more details in Profiling number of garbage-collected object instances per class.

这篇关于如何查找哪些对象正在创建最多的垃圾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆