How can I figure out if this memory consumption is Normal or High.
It is not possible to "figure it out". Memory consumption depends on what your application is, what it does, and the strategies it uses.
For example, an application may use a lot of the memory:
- because it employs algorithms that require a large in-memory data structures, or
- because it gets a significant performance benefit by caching things in memory, or
- because it is poorly designed / implemented; e.g. it has memory leaks, uses too many threads, unnecessarily creates large in-memory data structure, and so on.
So Normal vs High is highly context dependent. And a matter of opinion.
Is it recommended to use Xmx
and Xms
values?
It depends on the application. For example, if you don't specify the Xmx
value, a platform-specific formula is used to calculate a default value; see How is the default max Java heap size determined?. That default can be appropriate.
If yes, how to calculate those values?
Empirically. You try different values and observe what happens.
It is worth noting that the JVM needs a proportion of "extra" space so that the GC can work efficiently1. So even if it was possible to calculate the aggregate of the sizes of all of the application's objects, the JVM needs substantially more memory than that for efficiency.
1 - Garbage collectors work by "marking" the heap to determine what is reachable, and then reclaiming the objects that are not reachable. The work of marking is proportional to the number of reachable objects and references. When the heap is close to full of reachable objects, the GC will spend lots of time marking, and not find many objects that can be deleted. Clearly, the GC will be more efficient if it can finds lots of actual garbage to reclaim each time it runs. This implies that the heap needs to be large enough to hold lots of garbage in addition to all of the reachable objects.