简体   繁体   English

我如何发现永久世代中的东西

[英]How do I discover what is in the permanent generation

Given a heapdump or a running VM, how do I discover what the contents of the permanent generation is ? 给定堆转储或正在运行的VM,如何发现永久代的内容是什么? I know about 'jmap -permstat' but that's not available on Windows. 我知道'jmap -permstat'但是在Windows上不可用。

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: 如果你对永久代的大小有问题,通常是由两个原因引起的:

  • your program or a library you use creates classes dynamically and the default size of permanent generation is too small - simple increate the size with -XX:MaxPermSize=256m 您的程序或您使用的库动态创建类,永久生成的默认大小太小 - 使用-XX简单地增加大小:MaxPermSize = 256m
  • your program or a library you use creates new classes dynamically every time it is called, so the size of permanent generation increases non-stop - this is a programming error you should fix it (or search a fix/create a bug report) 您使用的程序或库每次调用时都会动态创建新类,因此永久生成的大小会不停增加 - 这是一个编程错误,您应该修复它(或搜索修复/创建错误报告)

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 http://blogs.oracle.com/jonthecollector/entry/presenting_the_permanent_generation

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. 本文使用Java SE 5进行内存监视介绍了如何以编程方式发现有关堆使用情况,内存池(包括permgen空间)等的信息。 Its very simple: 它非常简单:

    MemoryUsage usage = ManagementFactory.getMemoryMXBean().getNonHeapMemoryUsage();
    long nonHeapFree = usage.getMax() - usage.getUsed();
    long nonHeapTotal = usage.getMax();

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. 在我对OSX(Sun VM)的测试中,“非堆内存使用”与permgen池的返回值匹配,并且可能会对没有permgen的VM执行一些有用的操作。

See my blog post about thr permsize of Eclipse 请参阅我关于Eclipse的thr permsize的博客文章

In short the Memory Analyzer can doit, but you need the SAP JVM. 简而言之,Memory Analyzer可以做,但您需要SAP JVM。

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. 帮助我的一种技术是对java使用-verbose:class 命令行选项 ,并且您将获得日志输出,告诉您何时加载/卸载类。 Since classes are loaded to the permgen, this can help in certain circumstances. 由于类被加载到permgen,这在某些情况下会有所帮助。

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. 查看jmap的代码,permstat工具仅在sun.jvm.hotspot.tools.HeapSummary类可用时才可用。 This class is part of the serviceability agent. 此类是可维护性代理的一部分。 According to OpenJDK documentation (http://openjdk.java.net/groups/serviceability/svcjdk.html#bsa): 根据OpenJDK文档(http://openjdk.java.net/groups/serviceability/svcjdk.html#bsa):

Serviceability Agent components are built as part of the standard build of the HotSpot repository. 可维护性代理组件是作为HotSpot存储库的标准版本的一部分构建的。 These components are: 这些组件是:

-libsaproc.so: this is the native code component of SA. -libsaproc.so:这是SA的本机代码组件。

-sa-jdi.jar: This is contains the Java classes of SA. -sa-jdi.jar:这包含SA的Java类。 It includes an implementation of JDI which allows JDI clients to do read-only debugging on core files and hung processes. 它包括JDI的实现,它允许JDI客户端对核心文件和挂起进程进行只读调试。

SA is used by jinfo, jmap, jstack SA由jinfo,jmap,jstack使用

NOTE: The Serviceability Agent and the technologies that use it are not currently included in JDK releases on the Windows platforms. 注意:可维护性代理及其使用的技术当前未包含在Windows平台上的JDK版本中。

Looks to be the case for Oracle JDK as well. 看起来也是Oracle JDK的情况。 I'm looking to modify the jmap tool to get more info. 我想修改jmap工具以获取更多信息。

Do you have a specific problem to solve? 您有具体问题需要解决吗? The use of String.intern() is one of the typical causes for permgen problems. String.intern()的使用是permgen问题的典型原因之一。 Additionally projects with a lot of classes also have permgen problems. 此外,有很多课程的项目也存在permgen问题。

I do not know how to get into the permgen and see what it is there... 我不知道如何进入permgen,看看它是什么......

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. 与名称不同,permgen最终也会得到GC,而不是常规GC循环的一部分。 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. 但是permgen也没有动态增长,这意味着有时需要手动调整其JVM启动的设置。

you can use JConsole or jvisualvm.exe(with jdk 1.6 7) to find what is where. 您可以使用JConsole或jvisualvm.exe(使用jdk 1.6 7)来查找其中的内容。 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/ . 如果您想知道所有对象如何相互关联以及对象树,那么您可能想要尝试Eclipse Memory Analyzer - http://www.eclipse.org/mat/

IN summary, you will get want you want from " http://www.eclipse.org/mat/ ". 总而言之,您将从“ http://www.eclipse.org/mat/ ”获得您想要的。

Good luck, 祝好运,

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

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