如何确定 Java 应用程序中永久代的大小(即,以编程方式)?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4071440/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 04:39:39  来源:igfitidea点击:

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

javamemory-managementmemory-footprint

提问by s106mo

  1. Is there any way to measure the currently usedsize 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?

  1. 有什么方法可以测量我的 Java 应用程序中当前使用的永久代 (PermGen) 的大小?我不能使用外部分析工具,例如 VisualVM。

  2. 更好的是估计 PermGen 中 Java 类的内存消耗。它几乎与字节码文件的大小成正比吗?

回答by Aravind Yarram

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.

您可以使用 JDK 附带的 MemoryMXBean。但我认为没有办法从正在运行的应用程序中查询 permgen 的使用情况。关于MemoryMXBean 的文档。

回答by Eugene Kuleshov

You can use jvisualvmtool from JDK with Visual GCplugin to monitor all JVM heap areas including PermGen.

您可以使用JDK 中的jvisualvm工具和Visual GC插件来监控所有 JVM 堆区域,包括 PermGen。

回答by Damien

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

如果您不在 Windows 上,您可以尝试使用 JDK 附带的jmap

回答by Avnish Kumar Singh

You can use the jmapcommand:

您可以使用以下jmap命令:

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)

jmap [选项](连接到正在运行的进程)

jmap [选项](连接到核心文件)

jmap [option] [server_id@](连接远程调试服务器)

where options is one of:

其中选项是以下之一:

-heap : to print java heap summary

-permstat : to print permanent generation statistics

-heap : 打印 java 堆摘要

-permstat : 打印永久代统计信息

回答by Amir Afghani

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:

PermGen 的大小与类文件的大小无关。根据 Sun 的说法,PermGen 的默认大小是 64 MB。如果您想增加它,您可以使用以下方法显式设置它:

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

在您的 Java 命令行或启动脚本中。这也是您无需依赖外部工具即可了解其设置的方式。

EDIT:

编辑:

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

阅读这篇文章以确定目前以编程方式使用的 PermGen 大约有多少(即没有外部工具):

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

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