简体   繁体   中英

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 ? I know about 'jmap -permstat' but that's not available on 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
  • 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

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:

    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.

See my blog post about thr permsize of Eclipse

In short the Memory Analyzer can doit, but you need the 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. Since classes are loaded to the permgen, this can help in certain circumstances.

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.

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...

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.

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,

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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