Ron Amir
Ron Amir

Reputation: 27

Java’s survivor space when full

What happens when Java’s survivor space is full but the Eden’s space has free memory? Does the survivor space uses the Eden’s space?

Upvotes: 0

Views: 311

Answers (1)

Stephen C
Stephen C

Reputation: 719346

What happens when Java’s Survivor space is full but the Eden’s space has free memory?

It will depend on the GC. And it also, on whether the Survivor space is at the max (as distinct from just being full). But shrinking Eden space to allow the Survivor space to grow is one possible strategy.

Note: shrinking Eden space won't be good for performance. It is liable to increase the rate of minor GCs, and ultimately major GCs.


I took a brief look at the source code for the G1 collector in JDK 17. It appears1 that G1GC has no provision for shrinking Eden space. (Look at the file "/src/hotspot/share/gc/g1/g1HeapSizingPolicy.cpp")


1 - Caveat: the context of the code I looked at is complicated, and I could easily have misunderstood it. YMMV.

Upvotes: 1

Related Questions