11

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.

Tom
  • 55,743
  • 3
  • 27
  • 35
  • Not answering your question, but perhaps giving an answer to you problem - Sun JVM has a permgen, but there are other JVMs that do not suffer from this. – Tnilsson Oct 14 '08 at 11:27
  • 3
    The problem here is that the permgen (or the equivalent in other JVMs) is not exposed by the JVMTI interface, and so tools have no means to introspect it. It's a major issue with tool vendors. – skaffman May 14 '09 at 09:56
  • 1
    please state the java version. in earlier sun jvm's, gc was finicky about collecting classes. also, if you get a heapdump you can guess at whether interned strings are your problem. – Ron Sep 02 '10 at 21:40

8 Answers8

1

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

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
laszlot
  • 91
  • 3
  • This reply is incomplete: we currently have an app that is leaking permgen memory and the number of loaded classes is absolutely constant. Both facts can be seen by using JConsole. We suffer from the same problem as the original poster in that we have no way to analyze the permgen in detail. – Boris Terzic Jun 24 '09 at 07:08
1

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.

David Tinker
  • 9,383
  • 9
  • 66
  • 98
0

See my blog post about thr permsize of Eclipse

In short the Memory Analyzer can doit, but you need the SAP JVM.

kohlerm
  • 2,596
  • 1
  • 17
  • 22
0

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.

Bobby
  • 1,666
  • 3
  • 16
  • 27
0

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.

Dave H
  • 547
  • 1
  • 5
  • 16
0

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

ReneS
  • 3,535
  • 2
  • 26
  • 35
0

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.

StaxMan
  • 113,358
  • 34
  • 211
  • 239
-1

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,

anjanb
  • 12,999
  • 18
  • 77
  • 106
  • I am looking specifically for which objects are in the permanent generation. These tools will not answer that question. – Tom Oct 11 '08 at 18:30
  • Hi Tom, MAT can answer your question but you would have to use the SAP JVM, which is unfortunately at the moment a little bit difficult to get. You would need to get NW CE from https://www.sdn.sap.com/irj/sdn/nw-ce – kohlerm Nov 24 '08 at 08:12