简体   繁体   English

如何找到哪个类导致JVM的OutOfMemory?

[英]How to find which Class is causing OutOfMemory for the JVM?

Oflate our Weblogic server is frequently crashing with OutOfMemory error. 我们的Weblogic服务器经常崩溃,出现OutOfMemory错误。 Is there any way I can monitor the JVM to find out which Classes are are hogging the memory and have the maximum number of objects? 有什么方法可以监视JVM以找出哪些类正在占用内存并拥有最大数量的对象?

yes. 是。 The way I did it was to configure the jvm to create a heap dump on OOM, then I pulled the heap down and ran it thru jvisualvm. 我这样做的方法是配置jvm以在OOM上创建堆转储,然后我将堆拉下来并通过jvisualvm运行它。 You can compute the retained sizes (took a long time) but it will be very clear what the offender is. 你可以计算保留的大小(花了很长时间),但非常清楚罪犯是什么。

You can also attach jvisualvm to a running instance, but you need to configure the jvm to accept the connection. 您还可以将jvisualvm附加到正在运行的实例,但是您需要配置jvm以接受连接。 That way you can watch the heap grow in real time. 这样你就可以看到堆实时增长。 See this; 看到这个; its for jboss but should be very similar: https://wiki.projectbamboo.org/display/BTECH/VisualVM+Profiler 它的jboss但应该非常相似: https//wiki.projectbamboo.org/display/BTECH/VisualVM+Profiler

I think it is easier to get to the answer after you have a heap dump though, as when you watch it in real time things get garbage collected and whatnot. 我认为在你有一个堆转储之后找到答案会更容易,因为当你实时观察它时会收集垃圾和诸如此类的东西。

EDIT -- here are my startup configs. 编辑 - 这是我的启动配置。

-XX:+PrintGCDetails -XX:+PrintGCTimeStamps  
-Xloggc:/path/to/memlogs/memlog.txt -XX:+PrintTenuringDistribution   
-Xms1024m -Xmx2048m -XX:MaxPermSize=128m   
-server -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=xxxx   
-Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false   
-Djava.rmi.server.hostname=<ip-address> -XX:+HeapDumpOnOutOfMemoryError   
-XX:HeapDumpPath=/path/to/heapdumps/ -XX:+CMSClassUnloadingEnabled   
-XX:+CMSPermGenSweepingEnabled -XX:+UseConcMarkSweepGC  

because I configured it to drop memory logs, I can tail the memlog.txt file in real time to see what happened. 因为我将它配置为删除内存日志,我可以实时查看memlog.txt文件,看看发生了什么。 I can connect to the jvm if I want, but like I said I will just analyze the heap after a crash to see what the issue is, because after the fact its really clear.... 如果我愿意,我可以连接到jvm,但就像我说的那样,我会在崩溃后分析堆,看看问题是什么,因为事实之后它真的很清楚......

从JDK 1.5开始有JConsole (或5.0,如果你进入那个)。

There are a number of tools out there but I use Eclipse's Memory Analysis Toolkit. 有很多工具,但我使用的是Eclipse的Memory Analysis Toolkit。 You can download it as a standalone tool and it will let you do heap analysis and even connect to a JVM and analyze there. 您可以将其作为独立工具下载,它可以让您进行堆分析甚至连接到JVM并在那里进行分析。

除了JConsole,jRat是一款优秀的免费啤酒分析器,YourKit是另一款出色的商业产品。

From some other Questions I came to know about jhat and jmap. 我从其他一些问题中了解了jhat和jmap。 These are already available in JDK packages. 这些已经在JDK包中提供。 Also the below link provides a good list on which tool to use in which scenarios:- 此外,以下链接提供了一个很好的列表,列出了在哪些情况下使用的工具: -

http://java.sun.com/developer/technicalArticles/J2SE/monitoring/ http://java.sun.com/developer/technicalArticles/J2SE/monitoring/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM