For example if I run/debug simple spring boot app from IDE without definitions, what size of initial heap size, max heap size and stack size (-Xms, -Xmx, -Xss) will be set?
The flag Xmx specifies the maximum memory allocation pool for a Java virtual machine (JVM), while Xms specifies the initial memory allocation pool. The Xms flag has no default value, and Xmx typically has a default value of 256 MB.
The Java™ virtual machine (JVM) heap size setting directly relates to how many server instances can be started within a dynamic cluster on a specific node. You might need to modify the JVM heap size setting based on your environment configuration. The default value is 256 MB.
The Spring Boot autoconfiguration premium, measured this way, is about 1MB heap and 4MB non-heap.
We can view how much of memory consumption in spring boot app, in this way. Now open the CMD and type jconsole and hit enter. Now you can see a window like below and it will appear application that previously ran in Local Process section. Select springboot-example.
By default Spring Boot app will use JVM default memory settings.
Default heap size
In case your physical memory size is up to 192 megabytes (MB) then default maximum heap size is half of the physical memory.
In case your physical memory size is more than 192 megabytes then default maximum heap size is one fourth of the physical memory.
For example, if your computer has 128 MB of physical memory, then the maximum heap size is 64 MB, and greater than or equal to 1 GB of physical memory results in a maximum heap size of 256 MB.
The maximum heap size is not actually used by the JVM unless your program creates enough objects to require it. A much smaller amount, called the initial heap size, is allocated during JVM initialization. This amount is at least 8 MB and otherwise 1/64th of physical memory up to a physical memory size of 1 GB.
The maximum amount of space allocated to the young generation is one third of the total heap size.
You can check default values specific to you machine with the following command
Linux:
java -XX:+PrintFlagsFinal -version | grep HeapSize
Windows:
java -XX:+PrintFlagsFinal -version | findstr HeapSize
Reference:https://docs.oracle.com/javase/8/docs/technotes/guides/vm/gctuning/parallel.html#default_heap_size
Default thread stack size
The default thread stack size varies with JVM, OS and environment variables.
To find out what your default thread stack size is on your platform, use
In Linux:
java -XX:+PrintFlagsFinal -version | grep ThreadStackSize
In Windows:
java -XX:+PrintFlagsFinal -version | findstr ThreadStackSize
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With