0

Is there a minimum -Xmx setting for Oracle's JVM? It looks like -Xmx2M does provide the application with more than 2 MB of heap size, as the Java Memory MX bean tells me it allocates like 10 MB...

Is there a minimum under which the JVM silently ignores the Xmx setting?

7
  • When the heap is small, it is a very small portion of the size of the JVM. I am not sure why this matters at that point. Commented Aug 13, 2013 at 18:20
  • I'm developing a framework with lazy loading (and unloading) in low-memory conditions, I want to test what the minimum Xmx settings are for my framework. Commented Aug 13, 2013 at 18:21
  • oracle.com/technetwork/java/javase/gc-tuning-6-140523.html Commented Aug 13, 2013 at 18:21
  • I know about this page but cannot find any documented minimum Xmx setting. Commented Aug 13, 2013 at 18:24
  • I would assume that a real application would do more than your framework does. If you can run with the minimum heap you can set I am not sure what the concern is. Commented Aug 13, 2013 at 18:25

2 Answers 2

2

If I run

public static void main(String[] args) {
    System.out.println("Heap size is " + Runtime.getRuntime().totalMemory() / 100000 / 10.0 + " MB");
}

with -mx8m on Java 7 update 25 64-bit I get

Heap size is 8.0 MB

but if I run with -mx2m I get

Heap size is 3.2 MB

So it does appear you get slightly more heap than you asked for for very small sizes. However, even for a small mobile device I wouldn't be worrying about every last MB because the JVM itself is much larger (can be over 100 MB of shared memory, thread etc)

i.e. if you can't spare a few MB, you won't be able to run the JVM anyway.

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

2 Comments

It is a little bit weird: minimum heap size seems to be 2M, otherwise the JVM won't start at all. However, if 2M is specified we get 3.2M instead. Is there n definitive answer to the question: Why is that so?
I can only guess it adds some to s you JVM can start, but I don't know for sure. Perhaps reading the source of OpenJDK would have a comment as to why this is done.
0

For jvm to start minimum 2mb of heapsize is required. You can set heap size to 0 bytes, but jvm will not start. And maximum heap size recommended is 1/4 of total ram.

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.