10

I was expecting Runtime.maxMemory() to return exactly the -Xmx but it returns a lower value. So what does it return?

3 Answers 3

5

The interpretation of the -Xmx flag is VM-dependent. Some VMs, including HotSpot, enforce a lower bound on the effective value of this option. The CCC proposal should not have mentioned the -Xmx flag in this way.

Reference

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

Comments

4

Returns the maximum amount of memory that the Java virtual machine will attempt to use, jvm may not use all the memory you have defined as -Xmx parameter for just heap.

3 Comments

Can you give a more in-depth description? Is it because "maxMemory() should return (an approximation of) the memory that is usable for 'normal' objects, and should not include the extra space needed by the garbage collector (e.g., an extra survivor space) and should not include the permanent generation." bugs.sun.com/bugdatabase/view_bug.do?bug_id=4505762
@LostInComputer: Heap is divided into 3 spaces (Changes based on jvm implementation), young, survivor and permanent. young is the place where new objects will be created and move to survivor on first GC. Read this documenation oracle.com/technetwork/java/gc-tuning-5-138395.html
My understanding is that the link you provided discussing about which of these 3 generations need to be taken into consideration while reporting maxMemory().
1

-Xmxn

Specify the maximum size, in bytes, of the memory allocation pool. This value must a multiple of 1024 greater than 2MB. Append the letter k or K to indicate kilobytes, or m or M to indicate megabytes. The default value is 64MB. The upper limit for this value will be approximately 4000m on Solaris 7 and Solaris 8 SPARC platforms and 2000m on Solaris 2.6 and x86 platforms, minus overhead amounts. Examples:

       -Xmx83886080
       -Xmx81920k
       -Xmx80m

maxMemory()

Returns the maximum amount of memory that the Java virtual machine will attempt to use. If there is no inherent limit then the value Long.MAX_VALUE will be returned.

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.