Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 class in the PermGen. Is it nearly proportional to the size of the bytecode file?

like image 205
s106mo Avatar asked Nov 01 '10 17:11

s106mo


People also ask

What is PermGen size?

PermGen is the memory area for storing class data like static variable,byte code and etc. By default 64 Mb is allocated for PermGen.

What is PermGen space in Java?

lang. OutOfMemoryError: PermGen Space is a runtime error in Java which occurs when the permanent generation (PermGen) area in memory is exhausted. The PermGen area of the Java heap is used to store metadata such as class declarations, methods and object arrays.

How can you control size of PermGen space?

To fix it, increase the PermGen memory settings by using the following Java VM options. -XX:PermSize<size> - Set initial PermGen Size. -XX:MaxPermSize<size> - Set the maximum PermGen Size. In the next step, we will show you how to set the VM options in Tomcat, under Windows and Linux environment.

Is method area and PermGen same?

Method Area is a part of space in the PermGen and it is used to store the class structure and the code for methods and constructors. The biggest disadvantage of PermGen is that it contains a limited size which leads to an OutOfMemoryError.


2 Answers

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.

like image 110
Aravind Yarram Avatar answered Sep 27 '22 17:09

Aravind Yarram


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

like image 21
Eugene Kuleshov Avatar answered Sep 27 '22 18:09

Eugene Kuleshov