开发者

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

  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 cl开发者_如何学编程ass in the PermGen. Is it nearly proportional to the size of the bytecode file?


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.


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


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


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜