Please enable JavaScript.
Coggle requires JavaScript to display documents.
JVM - Coggle Diagram
JVM
handling OOM
HeapDumpOnOutOfMemoryError instructs the JVM to dump heap into physical file in case of OutOfMemoryError
HeapDumpPath denotes the path where the file is to be written; any filename can be given; however, if JVM finds a <pid> tag in the name, the process id of the current process causing the out of memory error will be appended to the file name with .hprof format
OnOutOfMemoryError is used to issue emergency commands to be executed in case of out of memory error; proper command should be used in the space of cmd args. For example, if we want to restart the server as soon as out of memory occur, we can set the parameter:
-
UseGCOverheadLimit is a policy that limits the proportion of the VM's time that is spent in GC before an OutOfMemory error is thrown
strings
-XX:+UseStringDeduplication: Java 8u20 has introduced this JVM parameter for reducing the unnecessary use of memory by creating too many instances of the same String; this optimizes the heap memory by reducing duplicate String values to a single global char[] array
-
-XX:+UseCompressedStrings: use a byte[] type for String objects which can be represented in pure ASCII format
-
heap
heap size
Units can be marked as ‘g' for GB, ‘m' for MB and ‘k' for KB.
-
-
GC
-
monitoring
To strictly monitor the application health, we should always check the JVM's Garbage Collection performance. The easiest way to do this is to log the GC activity in human readable format.
-XX:+UseGCLogFileRotation
-XX:NumberOfGCLogFiles=< number of log files >
-XX:GCLogFileSize=< file size >[ unit ]
-Xloggc:/path/to/gc.log
UseGCLogFileRotation specifies the log file rolling policy, much like log4j, s4lj, etc. NumberOfGCLogFiles denotes the max number of log files that can be written for a single application life cycle. GCLogFileSize specifies the max size of the file. Finally, loggc denotes its location.
32/64 Bit
In the OS environment where both 32 and 64-bit packages are installed, the JVM automatically chooses 32-bit environmental packages. If we want to set the environment to 64 bit manually, we can do so using below parameter:
-d<OS bit>
young generation
after total available memory, the second most influential factor is the proportion of the heap reserved for the Young Generation. By default, the minimum size of the YG is 1310 MB, and maximum size is unlimited.
We can assign them explicitly:
-XX:NewSize=<young size>[unit]
-XX:MaxNewSize=<young size>[unit]
metaspace
Starting with Java 8, the size of Metaspace is not defined. Once it reaches the global limit, JVM automatically increases it, However, to overcome any unnecessary instability, we can set Metaspace size with:
-XX:MaxMetaspaceSize=<metaspace size>[unit]
threads
-XX:+UseLWPSynchronization: sets LWP (Light Weight Process) – based synchronization policy instead of thread-based synchronization
eden/survivor space
-XX:SurvivorRatio: Ratio of eden/survivor space size – for example, -XX:SurvivorRatio=6 sets the ratio between each survivor space and eden space to be 1:6,
-
-
-
-