Java – JVM – Proportion/distribution of new and old generations

JVM – Proportion/distribution of new and old generations… here is a solution to the problem.

JVM – Proportion/distribution of new and old generations

I’m allocating up to 8GB of memory for an application written in Java. Out of memory. I believe that by default, the new generation is always smaller than the old one (1/4 of the heap). And Eden/survivor 1,2 are in the younger generation. I believe that the new object was created in the space of Eden.

Even if the old age is not full, but the younger generation is full, are Java applications still running out of memory?

If there are more short-lived objects than long-lived objects, can I allocate more memory or at least 50% of the heap to younger generations? Or should it always be 1/4 of the heap due to jvm maintenance?

Solution

First, 1/4 seems like something else. That’s the amount of memory allocated to the heap, unless you specify -Xmx (when you’re in a container and the enabled flag is a bit different).

Does the java application still go out of memory even though the old generation is not full, but the young generation is completely full?

No. Activity objects from that region are moved to Survivor when the young Eden is full, and when objects from the Survivor have “survived” enough GC cycles, they are moved to the old region (by XX:MaxTenuringThreshold). IHOP in G1), the GC cycle that touches the old generation occurs. Some more details here .

If there are more short-lived objects than long-lived objects, is it ok to allocate more memory to the young generation or at least 50% of the heap to the young generation?

The larger the young area, the longer the pause. Young GC cycles always stop world events, so it’s not good to make them too big. In addition to this, this will affect your -XX: MaxGCPauseMillis; And don’t do it yourself: by default G1 GC will adjust regions as it finds most appropriate to .

Related Problems and Solutions