Java:如何检查当前的 Perm / PermGen 大小?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3722920/
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-08-14 03:55:33  来源:igfitidea点击:

Java : how to check current Perm / PermGen Size?

javajvmjvm-crash

提问by Michael Mao

Yesterday when I was running the WebLogic Application Server 11g installer, I encountered a OutOfMemory error, so I Googled for the answer:

昨天我在运行 WebLogic Application Server 11g 安装程序时,遇到了 OutOfMemory 错误,所以我搜索了答案:

java -Xms256m -Xmx512m -XX:PermSize=128m -XX:MaxPermSize=256m -jar wls1032_generic.jar

Everything worked :)

一切正常:)

However, when I think twice about the solution, I might have made a mistake: How could I know the current settings of those? I certainly need to check their values before overriding them, right?

然而,当我仔细考虑解决方案时,我可能犯了一个错误:我怎么知道那些的当前设置?我当然需要在覆盖它们之前检查它们的值,对吗?

Any thoughts?

有什么想法吗?

Related link:People in another thread on SOsuggested trial and error approach, which is not ideal.

相关链接:SO 上另一个线程中的人们建议采用试错法,这并不理想。

Many thanks in advance.

提前谢谢了。

采纳答案by Strelok

You can check the values of any JVM flags of a running JVM by using the jinfo.exeutility.

您可以使用该jinfo.exe实用程序检查正在运行的 JVM 的任何 JVM 标志的值。

%JAVA_HOME%\bin\jinfo.exe -flag <flagName> <pid>

%JAVA_HOME%\bin\jinfo.exe -flag <flagName> <pid>

so to check the value of -XX:PermSizeJVM option you can run

所以要检查-XX:PermSizeJVM选项的值,您可以运行

%JAVA_HOME%\bin\jinfo.exe -flag PermSize <pid>

%JAVA_HOME%\bin\jinfo.exe -flag PermSize <pid>

回答by James Black

You can use something like VisualVM, http://java.dzone.com/articles/best-kept-secret-jdk-visualvm&default=false&zid=159&browser=16&mid=0&refresh=0, to monitor your memory usage and you will see the max by where it peaks, and it will give you specific info as to which part of memory is actually full, so you can better optimize your environment.

您可以使用 VisualVM 之类的东西,http://java.dzone.com/articles/best-kept-secret-jdk-visualvm&default=false&zid=159&browser=16&mid=0&refresh=0来监控您的内存使用情况,您将看到最大通过它达到峰值的位置,它将为您提供有关哪部分内存实际已满的具体信息,以便您可以更好地优化您的环境。

You may find that some part of memory that you don't think about is actually filling up, and by monitoring it you can see what you need to do to get better performance.

您可能会发现某些您没有想到的内存部分实际上已被填满,通过监控它,您可以了解需要做什么才能获得更好的性能。

回答by Jacek

Another way to get PermGen information is:

另一种获取 PermGen 信息的方法是:

kill -3 JAVA_PID

It gets thread dump and memory information (including PermGen). Example output:

它获取线程转储和内存信息(包括 PermGen)。示例输出:

PSPermGen       total 68864K, used 68808K [0x000000009c600000, 0x00000000a0940000, 0x00000000a1800000)

For some reason jinfodid not work when I needed it. It returned:

由于某种原因jinfo在我需要时不起作用。它返回:

Unable to open socket file: target process not responding or HotSpot VM not loaded

There are few possible causes of the above and one of them may be explicit declaration of the java.io.tmpdiras described at https://www.permeance.com.au/web/terry.mueller/home/-/blogs/unable-to-open-socket-file-target-process-not-responding-or-hotspot-vm-not-loaded

上述情况的可能原因很少,其中之一可能是java.io.tmpdir 的显式声明,如https://www.permeance.com.au/web/terry.mueller/home/-/blogs/ 所述无法打开套接字文件目标进程未响应或热点虚拟机未加载

回答by Alan

You can use jmapat here, it's JVM Heap Dump Tool.

你可以jmap这里使用,它是 JVM Heap Dump Tool。

for example:

例如:

jmap -heap 5900

It will print:

它会打印:

Heap Configuration:
   MinHeapFreeRatio = 40
   MaxHeapFreeRatio = 70
   MaxHeapSize      = 989855744 (944.0MB)
   NewSize          = 1310720 (1.25MB)
   MaxNewSize       = 17592186044415 MB
   OldSize          = 5439488 (5.1875MB)
   NewRatio         = 2
   SurvivorRatio    = 8
   PermSize         = 21757952 (20.75MB)
   MaxPermSize      = 85983232 (82.0MB)

Heap Usage:
PS Young Generation
Eden Space:
   capacity = 242352128 (231.125MB)
   used     = 9196056 (8.770042419433594MB)
   free     = 233156072 (222.3549575805664MB)
   3.79450185805672% used
From Space:
   capacity = 41877504 (39.9375MB)
   used     = 0 (0.0MB)
   free     = 41877504 (39.9375MB)
   0.0% used
To Space:
   capacity = 42663936 (40.6875MB)
   used     = 0 (0.0MB)
   free     = 42663936 (40.6875MB)
   0.0% used
PS Old Generation
   capacity = 80609280 (76.875MB)
   used     = 34187936 (32.604156494140625MB)
   free     = 46421344 (44.270843505859375MB)
   42.41191088668699% used
PS Perm Generation
   capacity = 85393408 (81.4375MB)
   used     = 63472624 (60.53221130371094MB)
   free     = 21920784 (20.905288696289062MB)
   74.32965317416539% used

It gets memory information (including PermGen).5900is the process id of Java.

它获取内存信息(包括 PermGen)。5900是Java的进程ID。