2

I am playing around with Java, parameter -Xms and class Runtime.

I see that JVM allocates about 15% of the memory that is available - regardless how much it is.

Runtime rt Runtime.getRuntime ();
long total = rt.totalMemory ()
long free = rt.freeMemory ();

That is the case if I start my programm with paramter

-Xms4000m 

as well as with

-Xms90m

I see the difference of Xms in the result of totalMemory.

I understand the strategy of allocating more from the beginning to avoid expensive reallocation.

But I do not know if that is in place here AND how I can meter the real memory-consumption of my program.

3
  • 1
    gc logging is the easiest way Commented Sep 20, 2018 at 8:57
  • Did you mean to specify -Xmx instead? Commented Sep 20, 2018 at 9:03
  • no, Xms is the parameter that affects totalMemory Commented Sep 20, 2018 at 9:06

2 Answers 2

1

If your're using the Oracle JVM, you can use the command line tool jmap or the GUI tool jvisualvm to measure the heap consumption of your Java program.

Sign up to request clarification or add additional context in comments.

Comments

1

Get the PID of the application and you can use top command in the below way to print out the statistics.

top -b | grep PID

You can see how the memory is utilized over time.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.