1

I have a simple java program that I run with -Xms=512mb and -Xmx=512mb arguments. So the initial heap is 512 Mb, which means that my JVM must request my OS to allocate at least 512mb for the program when I start it. If I open jconsole, then I see 524Mb for max heap size(JVM itself needs some extra memory), 524 for committed memory(the amount of memory guaranteed to be available for use by the Java VM). But if I execute tasklist | find {my_pid}

then I see

java.exe 7700 Console 1 145 272 КБ

I'm confused. How can it be less than 512Mb?

Tony
  • 459
  • 1
  • 5
  • 18
  • Does this answer your question? [What are the -Xms and -Xmx parameters when starting JVM?](https://stackoverflow.com/questions/14763079/what-are-the-xms-and-xmx-parameters-when-starting-jvm) – javadev Jan 24 '21 at 07:15
  • You asked how can your app's heap take less than 512MB. This thread answers why Xms is not always the Min heap size of the application. – javadev Jan 24 '21 at 07:19
  • @javadev it wasn't me – Tony Jan 24 '21 at 07:20
  • 1
    Does this answer your question? [Why does the JVM consume less memory than -Xms specified?](https://stackoverflow.com/questions/12108706/why-does-the-jvm-consume-less-memory-than-xms-specified) – fuggerjaki61 Jan 24 '21 at 11:44

1 Answers1

1

The following line shows you the current state, not the maximum/minimum range:

java.exe                      7700 Console                    1   145 272 КБ

Execute some memory-intensive program in your JVM and you will get a different result on executing tasklist | find {my_pid}.

Note that Xms guarantees that if the OS does not have this much memory (plus some additional memory) left, the OS will not start java.exe. However, once java.exe is started, the OS may optimize the allocation of the memory based on the usage e.g. if java.exe becomes idle, OS may allocate it a memory < Xms. Moreover, the information provided by tasklist is for end-users and may not closely relate to the internal stats. Please check this discussion to for some more insight.

Arvind Kumar Avinash
  • 71,965
  • 6
  • 74
  • 110
  • What do you mean by "current state"? – Tony Jan 24 '21 at 07:22
  • @Tony - It is showing you how much memory the process, `java.exe` is consuming currently. – Arvind Kumar Avinash Jan 24 '21 at 07:24
  • And why the usage is less than Xms? Doesn't the JVM consume that memory from the beginning for use in the future? – Tony Jan 24 '21 at 07:27
  • @Tony - The OS may optimize the allocation of the memory based on the usage e.g. if `java.exe` becomes idle, OS may assign it a memory < `Xms`. – Arvind Kumar Avinash Jan 24 '21 at 07:31
  • Maybe I'm wrong, but I thought that JVM takes some memory from the start(which makes it unavailable for use for other processes) and then uses that memory for my app's heap. The memory taken on the start must be considered as "consumed" even if my app(not JVM) doesn't really use it(for example, if it's a hello world programm). Am I wrong? – Tony Jan 24 '21 at 07:31
  • @Tony - OS can optimize the allocation of memory based on many factors (I've mentioned one of them, above). – Arvind Kumar Avinash Jan 24 '21 at 07:35
  • What Xms can guarantee then? – Tony Jan 24 '21 at 07:35
  • @Tony - It guarantees that if the OS does not have this much memory left, it will not start this process. – Arvind Kumar Avinash Jan 24 '21 at 07:37
  • If you add these details to the answer and provide some helpful links, then I will select your answer. – Tony Jan 24 '21 at 07:41