Java : how to check current Perm / PermGen Size?

梦想与她 提交于 2019-12-02 18:44:30

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

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

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

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

You can use jmap at here, it's 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).5900 is the process id of Java.

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.

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.

Another way to get PermGen information is:

kill -3 JAVA_PID

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

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

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

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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!