How to determine the size of PermGen within a Java application (i.e., programmatically)?
Asked Answered
O

5

7
  1. Is there any way to measure the currently used size of permanent generation (PermGen) within my Java application? I cannot use external profiling tools such as VisualVM.

  2. Even better would be an estimation of the memory consumption of a Java class in the PermGen. Is it nearly proportional to the size of the bytecode file?

Obtest answered 1/11, 2010 at 17:34 Comment(0)
I
9

You could use MemoryMXBean that comes with JDK. But I don't think there is a way to query on the permgen usage from within a running application. Docs about MemoryMXBean.

Inclose answered 1/11, 2010 at 18:1 Comment(1)
Thanks! That answer helped me very much. I will vote your answer useful as soon as I have enough reputation! :)Obtest
H
2

You can use jvisualvm tool from JDK with Visual GC plugin to monitor all JVM heap areas including PermGen.

Hiroshige answered 1/11, 2010 at 17:47 Comment(0)
S
2

If you're not on Windows, you could try jmap which is shipped with the JDK.

Siegel answered 1/11, 2010 at 17:50 Comment(0)
M
1

You can use the jmap command:

jmap [option] (to connect to running process)

jmap [option] (to connect to a core file)

jmap [option] [server_id@] (to connect to remote debug server)

where options is one of:

-heap : to print java heap summary

-permstat : to print permanent generation statistics

Morganite answered 9/9, 2013 at 18:18 Comment(1)
thank you for your answer, however the decisive point of my question was that I wanted to measure the memory consumption within my application (i.e., programmatically) ... so the MemoryMXBean is the right way to goObtest
S
0

The size of PermGen has nothing to do with the size of your class files. The default size of PermGen according to Sun is 64 MB. If you wish to increase it you can set it explicitly using:

-XX:PermSize=164m

in your Java command line or startup script. This is also how you can know what it's set to without relying on an external tool.

EDIT:

Read this article to determine approximately how much PermGen is currently being used programmatically (i.e. no external tools):

http://frankkieviet.blogspot.com/2006/10/how-to-fix-dreaded-permgen-space.html

Sideshow answered 1/11, 2010 at 17:46 Comment(5)
The max size doesn't necessarily have anything to do with the size of any file. But stefan's looking for the current (used) size, not the max size.Incontestable
According to blogs.sun.com/jonthecollector/entry/…, e.g. the bytecodes of the class methods have an influence on the size of PermGen!Obtest
I did not specify the max size. The flag for the max perm size is MaxPermSizeSideshow
@stefan, you're confused. Read the document thoroughly. PermSize is where your class files are loaded yes, but the size of PermSize is not determined by your specific class files.Sideshow
Oh I see, you want to know how much of PermSpace is currently occupied. You should clarify that in your question.Sideshow

© 2022 - 2024 — McMap. All rights reserved.