我如何发现永久代中有什么
给定一个堆转储或一个正在运行的虚拟机,我如何发现永久代的内容是什么? 我知道“jmap -permstat”,但它在 Windows 上不可用。
Given a heapdump or a running VM, how do I discover what the contents of the permanent generation is ? I know about 'jmap -permstat' but that's not available on Windows.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
本文使用 Java SE 5 进行内存监控介绍了如何以编程方式发现堆使用情况、内存池(包括永久代空间)等信息。 它非常简单:
在我对 OSX (Sun VM) 的测试中,“非堆内存使用”与为 permgen 池返回的值紧密匹配,并且可能会对没有 permgen 的 VM 执行一些有用的操作。
This article Memory Monitoring with Java SE 5 describes how to programmatically discover information on heap usage, memory pools (including permgen space) and so on. Its very simple:
In my testing on OSX (Sun VM) "non heap memory usage" matches the values returned for the permgen pool closely and presumably will do something useful on VMs that don't have permgen.
永久代包含类对象。
因此,您应该检查堆转储或其他形式的类对象列表。
如果您对永久代的大小有问题,通常是由两个原因引起的:
以查看这是您的情况,请检查较长时期内永久代的大小。
关于永久代的一个很好的概述:
http://blogs.oracle.com/jonthecollector/entry/呈现_永久_一代
The permanent generation contains the class object.
So you should check the heap dump or other form of object list for classes.
If you have problem with the size of permanent generation usually it is caused by two reason:
To see which is your case check the size of the permanent generation over a larger period.
And a good overview about permanent generation:
http://blogs.oracle.com/jonthecollector/entry/presenting_the_permanent_generation
请参阅我关于 Eclipse 的 thr permsize 的博客文章
简而言之,内存分析器可以做到,但你需要 SAP JVM。
See my blog post about thr permsize of Eclipse
In short the Memory Analyzer can doit, but you need the SAP JVM.
您有具体问题需要解决吗? String.intern() 的使用是永久生成问题的典型原因之一。 此外,具有大量类的项目也存在永久生成问题。
我不知道如何进入永久区并看看那里有什么......
Do you have a specific problem to solve? The use of String.intern() is one of the typical causes for permgen problems. Additionally projects with a lot of classes also have permgen problems.
I do not know how to get into the permgen and see what it is there...
永久代实际上只包含两种东西:类定义和内部字符串。 后者很少会给你带来问题,但它经常被指责为问题的根源。 更常见的是,由于代码生成和部分热重加载(悬空引用),前者会产生问题。
与名称所暗示的不同,permgen 最终也会被 GC 处理,只是不是常规 GC 周期的一部分。 因此,未引用的内部字符串和未使用的类确实会被清理。
但 permgen 也不会动态增长,这意味着有时需要手动调整 JVM 启动设置的大小。
Permanent generation really only contains two kinds of things: Class definitions and interned strings. Latter very rarely gives you problems, but it is often blamed for problems. More often former is the one giving problems, due to code generation and partial hot reloading (dangling references).
Unlike name suggests, permgen does eventually get GC'ed too, just not part of regular GC cycle. Hence unreferenced interned Strings and unused classes do get cleaned up.
But permgen also does not grow dynamically which means that it is sometimes necessary to manually resize its settings for JVM start.
我正在研究同样的事情,但由于嵌入式平台的内存限制。
看一下jmap的代码,只有当sun.jvm.hotspot.tools.HeapSummary类可用时,permstat工具才可用。 此类是可服务性代理的一部分。 根据 OpenJDK 文档 (http://openjdk.java.net/groups/serviceability/svcjdk.html#bsa):
可服务性代理组件是作为 HotSpot 存储库标准构建的一部分构建的。 这些组件是:
-libsaproc.so:这是 SA 的本机代码组件。
-sa-jdi.jar:它包含 SA 的 Java 类。 它包括 JDI 的实现,允许 JDI 客户端对核心文件和挂起进程进行只读调试。
SA 由 jinfo、jmap、jstack 使用
注意:Serviceability Agent 及其使用的技术当前未包含在 Windows 平台上的 JDK 版本中。
Oracle JDK 似乎也是如此。 我正在寻找修改 jmap 工具以获取更多信息。
I'm looking into the same thing but due to memory constraints of an embedded platform.
Look at the code for jmap, the permstat tool is only available if the sun.jvm.hotspot.tools.HeapSummary class is available. This class is part of the serviceability agent. According to OpenJDK documentation (http://openjdk.java.net/groups/serviceability/svcjdk.html#bsa):
Serviceability Agent components are built as part of the standard build of the HotSpot repository. These components are:
-libsaproc.so: this is the native code component of SA.
-sa-jdi.jar: This is contains the Java classes of SA. It includes an implementation of JDI which allows JDI clients to do read-only debugging on core files and hung processes.
SA is used by jinfo, jmap, jstack
NOTE: The Serviceability Agent and the technologies that use it are not currently included in JDK releases on the Windows platforms.
Looks to be the case for Oracle JDK as well. I'm looking to modify the jmap tool to get more info.
对我有帮助的一项技术是使用
-verbose:class
java 的命令行选项,您将获得日志输出,告诉您类已加载/卸载。 由于类被加载到永久代,这在某些情况下会有所帮助。One technique that helped me was to use the
-verbose:class
command-line option to java, and you'll get log output telling you as classes are loaded/unloaded. Since classes are loaded to the permgen, this can help in certain circumstances.您可以使用 JConsole 或 jvisualvm.exe(使用 jdk 1.6 7)来查找什么在哪里。 如果您想了解所有对象如何相互关联以及对象树如何关联,那么您可能需要尝试 Eclipse Memory Analyzer -- http://www.eclipse.org/mat/。
总之,您将从“http://www.eclipse.org/mat/”。
祝你好运,
you can use JConsole or jvisualvm.exe(with jdk 1.6 7) to find what is where. If you want to know how all of your objects are related to each other and tree of objects, then you might want to try Eclipse Memory Analyzer -- http://www.eclipse.org/mat/.
IN summary, you will get want you want from "http://www.eclipse.org/mat/".
Good luck,