How do I discover what is in the permanent generation
Asked Answered
C

8

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.

Corody answered 11/10, 2008 at 18:14 Comment(3)
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.Northernmost
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.Tiffa
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.Anglomania
O
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

Olnton answered 11/10, 2008 at 20:19 Comment(1)
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.Infrequent
H
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.

Horseflesh answered 22/12, 2011 at 6:51 Comment(0)
M
0

See my blog post about thr permsize of Eclipse

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

Madiemadigan answered 24/11, 2008 at 8:14 Comment(0)
G
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...

Grinnell answered 14/5, 2009 at 9:48 Comment(0)
H
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.

Hearing answered 15/5, 2009 at 3:44 Comment(0)
M
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.

Mushy answered 16/11, 2011 at 21:48 Comment(0)
N
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.

Noemi answered 28/9, 2015 at 21:37 Comment(0)
K
-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,

Kamilahkamillah answered 11/10, 2008 at 18:28 Comment(2)
I am looking specifically for which objects are in the permanent generation. These tools will not answer that question.Corody
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 sdn.sap.com/irj/sdn/nw-ceMadiemadigan

© 2022 - 2024 — McMap. All rights reserved.