How to ensure that the JVM starts with an Xms value

When I run a Java program with an initial 3G heap size (set by the VM argument -Xms3072m), the JVM does not start from that size. It starts at 400 meters or so, and then continues to acquire more memory as needed.

This is a serious problem for me. I know that after a while the JVM will be needed. And when the JVM increases its memory as needed, it slows down. During the time when the JVM acquires more memory, a significant amount of time is spent on garbage collection. And I believe that acquiring memory is an expensive task.

How to ensure that the JVM really takes into account the start heap size parameter?

Update: This application creates many objects, most of which die quickly. Some resulting objects must remain in memory (which are passed from the young heap). During this operation, all of these objects must be in memory. After the operation, I see that all objects in the young heap are successfully declared. Thus, there are no memory leaks.

The same operation runs smoothly when the heap size reaches 3G. This clearly indicates that the extra time spent on acquiring memory,

This is Sun JDK 5.

+3
source share
4 answers

, Java . , 3 Xms, Java , , ... ( ). .

JVM Xms , . GC . GC , GC, Xms Xmx, , , Xmx.

, , ... 1 -XX: NewSize = 1g, "" "" . , , JVM , , , , . , , , -...

!

+3

, , .

, GC, . .

, , , .

- GC.

-Xms ( JVM, ). , , .

+2

sun vm 14 , . , xms xmx amt, .. -Xms3072m -Xmx3072m

0

, ? , 400 , , .

, . 400 , ? , , , :

, , , , . , "" . , , ..

. . . , , .

, . ( gc). , "" . , . .

, gc , , , -. ,

  Runtime r = Runtime.getRuntime();
  r.gc();

This is just for debugging purposes. Gc does a great job most of the time, so it should not be necessary to invoke gc yourself.

0
source

Source: https://habr.com/ru/post/1708326/


All Articles