Open the IDEA installation directory and see that there is a bin directory with two vmoptions files, which need to be configured for different JDKs:
32 bits: idea.exe.vmoptions
64 bit: idea64.exe.vmoptions
-Xms512m -Xmx1024m -XX:MaxPermSize=512m -XX:ReservedCodeCacheSize=225m -XX:+UseConcMarkSweepGC -XX:SoftRefLRUPolicyMSPerMB=50 -ea -Dsun.io.useCanonCaches=false -Djava.net.preferIPv4Stack=true
The above list is the default content of idea64.exe.vmoptions , which we can modify as needed.
The meanings of each parameter are:
1. Set JVM memory settings
1. There are four parameters for setting JVM memory:
-Xmx Java Heap maximum value, the default value is 1/4 of physical memory. The optimal setting value should depend on the physical memory size and other memory overhead in the computer;
-Xms Java Heap initial value. It is best for the server JVM to set -Xms and -Xmx to the same value. The JVM of the development and testing machine can retain the default value;
-Xmn Java Heap Young area size, it is best to keep the default value if you are not familiar with it;
-Xss The Stack size of each thread, it is best to keep the default value if you are not familiar with it;
2. How to set up JVM memory allocation:
(1) When starting and using the JVM at the command prompt (only effective for the currently running class Test):
java -Xmx128m -Xms64m -Xmn32m -Xss16m Test
(2) When starting and using JVM in an integrated development environment (such as eclipse):
a. Open eclipse.ini in the root directory of eclipse, and the default content is (the JVM memory allocation is set here to run the current development tool):
-vmargs means that the following are virtual machine settings parameters. You can modify the parameter values in it, or add -Xmn and -Xss. In addition, non-heap memory can be set in eclipse.ini, such as: -XX:PermSize=56m, -XX:MaxPermSize=128m.
The parameter values set here can be displayed in the status bar of the development tool through the following configuration:
Create file options in the eclipse root directory, the file content is: org.eclipse.ui/perf/showHeapStatus=true
Modify the eclipse.ini file in the root directory of eclipse and add the following content at the beginning:
Restart eclipse and you can see that there are more JVM information in the status bar below.
b. Open eclipse-window-preferences-Java-installed JRE (effective for all java programs running in the current development environment)
Edit the currently used JRE, enter: -Xmx128m -Xms64m -Xmn32m -Xss16m
c. Open eclipse-run-run-Java application (only effective for the set java classes)
Select the class to set memory allocation - argument, enter in the VM argument: -Xmx128m -Xms64m -Xmn32m -Xss16m
Note: If b and c are set at the same time in the same development environment, the b setting takes effect and the c setting is invalid, such as:
The setting of the development environment is: -Xmx256m, and the setting of the class Test is: -Xmx128m -Xms64m, the setting that takes effect when running Test is:
-Xmx256m -Xms64m
(3) When starting and using JVM in a server environment (such as Tomcat) (so Java programs take effect in the current server environment):
a. Set environment variables:
Variable name: CATALINA_OPTS
Variable value: -Xmx128m -Xms64m -Xmn32m -Xss16m
b. Open the bin folder in the root directory of Tomcat, edit catalina.bat, and replace the �TALINA_OPTS% (four places in total) with: -Xmx128m -Xms64m -Xmn32m -Xss16m
2. Check the JVM memory information
Runtime.getRuntime().maxMemory(); //Maximum available memory, corresponding to -Xmx
Runtime.getRuntime().freeMemory(); //The current JVM free memory
Runtime.getRuntime().totalMemory(); //The total memory occupied by the current JVM is equivalent to the sum of the memory used by the current JVM and freeMemory()
About maxMemory(), freeMemory() and totalMemory():
maxMemory() is the maximum available memory of the JVM, which can be set through -Xmx. The default value is 1/4 of the physical memory, and the set value cannot be higher than the computer's physical memory;
totalMemory() is the total memory occupied by the current JVM, and its value is equivalent to the sum of the memory used by the current JVM and freeMemory(), which will increase as the JVM uses memory increases;
freeMemory() is the current JVM free memory. Because the JVM only occupies physical memory when memory is needed, the value of freeMemory() is generally very small. The actual available memory of JVM is not equal to freeMemory(), but should be equal to maxMemory()-totalMemory()+freeMemory(). It sets JVM memory allocation.
See the official documentation:
http://docs.sun.com/source/819-0084/pt_tuningjava.html
Java startup parameters are divided into three categories;
One is the standard parameters (-), all JVM implementations must implement the functions of these parameters and are backward compatible;
The second is non-standard parameters (-X). The default jvm implements the functions of these parameters, but it does not guarantee that all jvm implementations are satisfied and are not guaranteed to be backward compatibility;
The third is non-Stable parameters (-XX). Each jvm implementation of such parameters will be different and may be cancelled at any time in the future. It needs to be used with caution;
More useful among standard parameters:
verbose
-verbose:class
Output the relevant information of jvm loading the class, and this can be used for diagnosis when jvm reports that the class cannot be found or class conflicts.
-verbose:gc
Output the relevant situation of each GC.
-verbose:jni
The outputs the relevant situation of native method calls, which is generally used to diagnose jni call error information.
Non-standard parameters are also called extended parameters
The most commonly used is
-Xms512m Set the JVM to cause the memory to be 512m. This value can be set the same as -Xmx to avoid the JVM reallocating memory every time the garbage collection is complete.
-Xmx512m , set the maximum available memory of JVM to 512M.
-Xmn200m: Set the size of the young generation to 200M. Whole heap size = Young Generation Size + Old Generation Size + Persistent Generation Size. The permanent generation is generally fixed in size of 64m, so after increasing the younger generation, the size of the older generation will be reduced. This value has a great impact on system performance, and Sun officially recommends configuration as 3/8 of the entire heap.
-Xss128k:
Sets the stack size for each thread. After JDK5.0, the stack size of each thread is 1M, and in the past, the stack size of each thread is 256K. More application threads require memory size to adjust. In the same physical memory, reducing this value can generate more threads. However, the operating system still has a limit on the number of threads in a process and cannot be generated infinitely, with experience values ranging from about 3000 to 5000.
-Xloggc:file
Similar to the -verbose:gc function, it only records the relevant situation of each GC event into a file. The location of the file is best local to avoid potential problems of the network.
If the verbose command appears on the command line at the same time, -Xloggc shall prevail.
-Xprof
Tracks running programs and outputs the tracking data at standard output; suitable for development environment debugging.
The parameter list with -XX as the prefix may be unsolicited in jvm, and SUN is not recommended, and it may be cancelled without notification in the future; however, many of these parameters are indeed very useful to us, such as -XX:PermSize, -XX:MaxPermSize, etc. that we often see;
First, let’s introduce behavioral parameters:
| Parameters and their default values | describe |
| -XX:-DisableExplicitGC | System.gc() is prohibited; but jvm's gc is still valid |
| -XX:+MaxFDLimit | Maximize the limit on the number of file descriptors |
| -XX:+ScavengeBeforeFullGC | The next generation of GCs takes precedence over Full GC execution |
| -XX:+UseGCOverheadLimit | Limit the proportion of time spent on GC by jvm before throwing OOM |
| -XX:-UseConcMarkSweepGC | GC for the older generation using concurrent mark exchange algorithm |
| -XX:-UseParallelGC | Enable parallel GC |
| -XX:-UseParallelOldGC | Enable parallelism for Full GC, and this item is automatically enabled when -XX:-UseParallelGC is enabled. |
| -XX:-UseSerialGC | Enable serial GC |
| -XX:+UseThreadPriorities | Enable local thread priority |
The three parameters of bold in the above table represent GC execution in jvm
There are three ways to line, namely serial, parallel, and concurrency;
SerialGC is the default GC method of jvm. It is generally suitable for small applications and single processors. The algorithm is relatively simple and the GC efficiency is high, but it may cause pauses to the application;
ParallelGC refers to the GC runtime, which has no impact on the operation of the application. The threads of GC and app are executed concurrently, so that the operation of the app is not affected to the maximum extent;
Concurrency (ConcMarkSweepGC) refers to multiple threads that execute GC concurrently. It is generally suitable for multi-processor systems. It can improve the efficiency of GC, but the algorithm is complex and the system consumes a lot;
Performance Tuning Parameter List:
| Parameters and their default values | describe |
| -XX:LargePageSizeInBytes=4m | Set large page size for Java heap |
| -XX:MaxHeapFreeRatio=70 | The largest proportion of idle amount in the java heap after GC |
| -XX:MaxNewSize=size | The maximum memory value that the newly generated object can occupy |
| -XX:MaxPermSize=64m | The maximum memory value that older generation objects can occupy |
| -XX:MinHeapFreeRatio=40 | The minimum proportion of idle amount in the java heap after GC |
| -XX:NewRatio=2 | The ratio of memory capacity of the new generation to memory capacity of the old generation |
| -XX:NewSize=2.125m | The default value of memory occupies when new generation objects are generated |
| -XX: ReservedCodeCacheSize=32m | Keep the memory capacity occupied by the code |
| -XX:ThreadStackSize=512 | Set the thread stack size. If it is 0, use the system default value. |
| -XX:+UseLargePages | Use large page memory |
In our daily performance tuning, we will basically use these attributes of the above bold;
Debug parameter list:
| Parameters and their default values | describe |
| -XX:-CITime | Printing consumes time in JIT compilation |
| -XX:ErrorFile=./hs_err_pid<pid>.log | Save error logs or data into files |
| -XX:-ExtendedDTraceProbes | Turn on the solaris-specific dtrace probe |
| -XX:HeapDumpPath=./java_pid<pid>.hprof | Specify the path or file name when exporting heap information |
| -XX:-HeapDumpOnOutOfMemoryError | Export relevant information in the heap when encountering OOM for the first time |
| -XX: | Run custom commands after a fatal ERROR appears |
| -XX:OnOutOfMemoryError="<cmd args>;<cmd args>" | Execute custom commands when encountering OOM for the first time |
| -XX:-PrintClassHistogram | Print columnar information of class instance after encountering Ctrl-Break, the same as jmap -histo function |
| -XX:-PrintConcurrentLocks | Print the relevant information about the concurrent lock after encountering Ctrl-Break, the same function as jstack -l |
| -XX:-PrintCommandLineFlags | Print the mark that appears on the command line |
| -XX:-PrintCompilation | Print relevant information when a method is compiled |
| -XX:-PrintGC | Print relevant information every time GC |
| -XX:-PrintGC Details | Print details every time GC |
| -XX:-PrintGCTimeStamps | Print the timestamp of each GC |
| -XX:-TraceClassLoading | Track the loading information of the class |
| -XX:-TraceClassLoadingPreorder | Track the loading information of all classes referenced to |
| -XX:-TraceClassResolution | Tracking constant pool |
| -XX:-TraceClassUnloading | Tracking class uninstall information |
| -XX:-TraceLoaderConstraints | Tracking information about class loader constraints |
Summarize
The above is the operation method of setting JVM running parameters of IntelliJ IDEA introduced to you. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support to Wulin.com website!