srajan
srajan

Reputation: 205

Will GC run if permgen fills up?

I have an application which on startup runs two or three full GC. There is lot of heap space and there is no need to run any GC(minor or full). However on gc log, i can see the permgen getting filled up and immediately after that a full GC is run.After this, there is an increase in permgen space. Eventually , once all classes are loaded, there is no full GC any more.

My question is if permgen gets filled up, does the VM run GC to claim some memory from heap and add extra memory to permgen? or does it throw OutOfMemory-permgen?

Upvotes: 2

Views: 2141

Answers (2)

Stephen C
Stephen C

Reputation: 719396

My question is if permgen gets filled up, does the VM run GC to claim some memory from heap and add extra memory to permgen? or does it throw OutOfMemory-permgen?

The GC will run a full GC in an attempt to free up some memory in the permgen space. If that fails to free up enough space, a OOME will be thrown saying the permgen is full.

No current or past HotSpot JVMs will attempt to increase permgen beyond its prescribed limit, whether or not there is normal heap space to allow this.


The reasons that a full GC needs to happen before the OOME (permgen) are:

  • There may have been references to permgen objects in non-permgen space. Running a full GC checks for this.
  • (AFAIK) GC'ing the permgen is normally tied to a full GC anyway ... presumably for the same reason. It is typically references from the normal heap and the GC "roots" that keep permgen objects reachable.

Permgen objects are (AFAIK) usually immutable, so changes in reachability due to permgen object mutation are unlikely.

Upvotes: 3

Adam Adamaszek
Adam Adamaszek

Reputation: 4054

It will throw OOM-permgen if the PermGen size hits your -XX:MaxPermGen limit (or the default).

Upvotes: 0

Related Questions