2

We have a desktop Java Swing application. For shipping it, we need to specify the minimum memory requirements for deploying this application. In the JVM parameters we specify 2GB as max heap size.

Is there any tool for a Windows based machine which can quantify the requirements?

Also, as follow-up question, I would like to know: If we do not specify the max heap size in Java 7, does the JVM still automatically adjust the heap size on the fly before throwing an OutOfMemoryError?

Markus Weninger
  • 11,931
  • 7
  • 64
  • 137
user3526364
  • 31
  • 1
  • 6

2 Answers2

2

Possible approach:

If you specify your own product to work with at max. 2GB of heap, you also have to consider the other parts of memory, allocated within the Java virtual machine:

JVM memory

To find out your memory consumption, I suggest you to test your application with MemoryMXBean. This includes methods such as getHeapMemoryUsage() and getNonHeapMemoryUsage().

Then stress-test your applications and periodically check these properties. This way you should get a feeling for how much memory your application consumes.

Additionally to that, Windows specifies 2GB as minimum RAM for Windows 10.

So, your final minimum requirements should be Minimum = MaximumHeap (2GB) + StressTestNonHeap (?) + WindowsMinimum (2GB) + SomeSecurityThreshold (~1GB).

Further approaches:

You could also use VisualVM to check your memory consumption.

Another possibility is to use Java HotSpot Native Memory Tracking (NMT), for which I posted an example on Stack Overflow.

Anything that also informs you about non-heap memory useage is applicable.

Max heap limits:

Regarding your question

Also on another note just wanted to know if we do not specify the max heap limits with Java 7, does the JVM automatically allocates heap on the fly to adjust before throwing out of memory.

If you do not specify the max heap size, the JVM will set it automatically depending on the used GC (in Java 7 this should be UseParallelOldGC) and your system. To test this, run java -XX:+PrintVMOptions -XX:+AggressiveOpts -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+PrintFlagsFinal -version and check what values are set for MaxHeapSize and UseParallelOldGC.

GC considerations:

Also: You probably want to consider using the garbage first (G1) GC, which will be the default GC in Java 9. In this question I show that the G1 GC also re-shrinks the heap if it thinks it is pratical. This may be useful if your application has memory-intensive and non-memory-intensive parts. This way, the heap may shrink during the non-memory-intensive parts, which most probably won't happen with the ParallelOldGC.

Community
  • 1
  • 1
Markus Weninger
  • 11,931
  • 7
  • 64
  • 137
  • I have to admit that it is not my own, but from [WikiMedia](https://commons.wikimedia.org/wiki/File:JvmSpec7.png), linked on the Wikipedia page for JVM. Yet I really like it, because it explains the JVMs memory well in a short overview. – Markus Weninger Feb 22 '16 at 15:53
  • Thanks for details, I will use this information and the formula mentioned herein to arrive at a figure. – user3526364 Feb 23 '16 at 13:31
  • @user3526364: Great that I could help. :) Since this information was useful to you, it would be nice of you to upvote it / accept it as answer. Thanks :) – Markus Weninger Feb 23 '16 at 14:48
0

When you run the JVM without the maximum heap size for the server JVM it uses 1/4 of main memory up to 32 GB. If you use the 32-bit windows client VM, it uses 64MB or 128MB.

The best way to determine the required memory consumption is to test you application with different memory sizes. The minimum memory is the lowest memory size you are willing to support. Only you know what you are comfortable supporting.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130