IntelliJ IDEA: Operation Method for setting JVM running parameters. intellijjvm
Open the IDEA installation directory, and you will see a bin directory. There are two vmoptions files, which need to be configured for different JDK:
32-bit: 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
Which of the following statements is as follows:idea64.exe.vmoptionsYou can modify the default content as needed.
The meanings of parameters are as follows:
1. Set JVM memory settings
1. Four JVM memory parameters are set:
-The maximum value of Xmx Java Heap. The default value is 1/4 of the physical memory. The optimal value depends on the physical memory size and other memory overhead in the computer;
-The initial value of Xms Java Heap. It is best to set-Xms and-Xmx to the same value on the Server JVM. The default value can be retained on the JVM of the development and testing machine;
-The size of the Xmn Java Heap Young area. If you are not familiar with it, keep the default value;
-The Stack size of each Xss thread. It is best to keep the default value if you are not familiar with it;
2. How to Set JVM memory allocation:
(1) When starting and using JVM at a command prompt (only effective for the currently running class Test ):
java -Xmx128m -Xms64m -Xmn32m -Xss16m Test
(2) When JVM is started and used in an integrated development environment (such as eclipse:
A. Open eclipse. ini in the eclipse root directory. The default content is (the JVM memory allocation for running the current development tool is set here ):
-Vmargs indicates the following virtual machine setting parameters. You can modify the parameter values or add-Xmn and-Xss. In addition, eclipse. you can also set non-heap memory in ini, for example,-XX: PermSize = 56 m,-XX: MaxPermSize = 128 m.
The parameter values set here can be displayed in the development tool's status bar through the following Configuration:
Create the options file in the eclipse root directory. The file content is:org.eclipse.ui/perf/showHeapStatus=true
Modify the eclipse. ini file under the eclipse root directory and add the following content at the beginning:
- -Debug
- Options
- -Vm
- Javaw.exe
Restart eclipse to view more JVM information in the following status.
B. Open eclipse-window-preference-Java-installed JRE (for all java programs running in the current development environment)
Edit the currently used JRE and enter-Xmx128m-Xms64m-Xmn32m-Xss16m in the default VM parameters.
C. Open eclipse-run-Java application (only effective for the configured java class)
Select the class-independent variable for memory allocation, and enter-Xmx128m-Xms64m-Xmn32m-Xss16m In the VM independent variable.
NOTE: If both B and c are set in the same development environment, the B setting takes effect and the c setting is invalid, for example:
The development environment is set to-Xmx256m, and the Test class is set to-Xmx128m-Xms64m. The settings that take effect when Test is run are:
-Xmx256m -Xms64m
(3) When JVM is started and used in a server environment (such as Tomcat) (This takes effect for the Java program in the current server environment ):
A. Set environment variables:
Variable name: CATALINA_OPTS
Variable value:-Xmx128m-Xms64m-Xmn32m-Xss16m
B. Open the bin folder under the Tomcat root directory, edit catalina. bat, and replace "TALINA_OPTS %" with "-Xmx128m-Xms64m-Xmn32m-Xss16m ".
Ii. View JVM memory settings
Runtime. getRuntime (). maxMemory (); // maximum available memory, corresponding to-Xmx
Runtime. getRuntime (). freeMemory (); // The current JVM idle memory.
Runtime. getRuntime (). totalMemory (); // The total memory occupied by the current JVM. The value is equivalent to the total memory used by the current JVM and freemory ().
About maxMemory (), freeMemory () and totalMemory ():
MaxMemory () is the maximum available memory of JVM. It can be set through-Xmx. The default value is 1/4 of the physical memory, and the value cannot be higher than the physical memory of the computer;
TotalMemory () is the total memory occupied by the current JVM. Its value is equivalent to the total memory used by the current JVM and the total number of freemory (). It will increase with the increase of memory usage by the JVM;
FreeMemory () is the idle memory of the current JVM. Because the JVM only occupies physical memory when the memory is needed, the value of freeMemory () is usually small, the actual available memory of JVM is not equal to freeMemory (), but maxMemory ()-totalMemory () + freeMemory (). And configure JVM memory allocation.
For official documents, see:
Http://docs.sun.com/source/819-0084/pt_tuningjava.html
Java startup parameters are divided into three types;
The first is standard parameters (-). All JVM implementations must implement the functions of these parameters and are backward compatible;
The second is non-standard parameters (-X). By default, jvm implements the functions of these parameters, but it does not guarantee that all jvm implementations are satisfied, and backward compatibility is not guaranteed;
The third parameter is the non-Stable parameter (-XX). The implementation of these parameters varies by jvm and may be canceled at any time in the future. You must use them with caution;
Useful in standard parameters:
Verbose
-Verbose: class
Output Information about the jvm loaded class. This can be diagnosed when the jvm report says no class or class conflict is found.
-Verbose: gc
Output related information about each GC.
-Verbose: jni
Outputs Information about native method calls. It is generally used to diagnose jni call errors.
A non-standard parameter is also called an extension parameter.
The most commonly used is
-Set JVM to 512 MB for Xms512m. This value can be set to the same as-Xmx to avoid JVM re-allocating memory after each garbage collection.
-Xmx512m: Set the JVM maximum available memory to 512 MB.
-Xmn200m: Set the young generation to 200 M. Total heap size = size of the young generation + size of the old generation + size of the persistent generation. The permanent generation usually has a fixed size of 64 m. Therefore, increasing the size of the young generation will reduce the size of the old generation. This value has a great impact on the system performance. Sun officially recommends 3/8 of the total heap configuration.
-Xss128k:
Set the stack size for each thread. After JDK 256, the size of each thread stack is 1 MB, and the size of each previous thread stack is K. The memory size required for more application threads is adjusted. Reduce this value to generate more threads under the same physical memory. However, the operating system still has a limit on the number of threads in a process. It cannot be generated infinitely. The experience is between 3000 and ~ About 5000.
-Xloggc: file
Similar to the-verbose: gc function, it only records the status of each GC event to a file. It is best to place the file locally to avoid potential network problems,
If the command and the verbose command appear in the command line at the same time, the-Xloggc prevails.
-Xprof
Tracks running programs and outputs tracing data in standard output; suitable for debugging in the development environment.
The parameter list prefixed with-XX may not be robust in jvm, and SUN is not recommended. It may be canceled without notice in the future; however, many of these parameters are useful to us, such as-XX: PermSize,-XX: MaxPermSize, and so on;
First, we will introduce the behavior parameters:
| Parameters and Their default values |
Description |
| -XX:-DisableExplicitGC |
Disable calling System. gc (). However, the jvm gc is still valid. |
| -XX: + MaxFDLimit |
Maximum number of file descriptors |
| -XX: + ScavengeBeforeFullGC |
The new generation GC takes precedence over Full GC. |
| -XX: + UseGCOverheadLimit |
Limit the time ratio of jvm to GC before OOM is thrown. |
| -XX:-UseConcMarkSweepGC |
GC for the old generation using the concurrent tag switching algorithm |
| -XX:-UseParallelGC |
Enable parallel GC |
| -XX:-UseParallelOldGC |
Enable parallel for Full GC. This option is automatically enabled when-XX:-UseParallelGC is enabled. |
| -XX:-UseSerialGC |
Enable serial GC |
| -XX: + UseThreadPriorities |
Enable local thread priority |
The three parameters in the above table represent the GC execution in jvm.
Three methods of row, namely serial, parallel, and concurrent;
SerialGC is the default GC method of jvm. It is generally applicable to small applications and single processors. The algorithm is simple and the GC efficiency is high, but it may bring a pause to the application;
Parallel (ParallelGC) means that the GC runtime has no impact on the application program running, and the GC and app threads are concurrently executed, so that the app running can be minimized;
ConcMarkSweepGC refers to the concurrent execution of GC by multiple threads. It is generally applicable to multi-processor systems and can improve GC efficiency, but the algorithm is complicated and the system consumes a lot;
Performance Tuning Parameter List:
| Parameters and Their default values |
Description |
| -XX: LargePageSizeInBytes = 4 m |
Set the large page size for Java heap |
| -XX: MaxHeapFreeRatio = 70 |
The largest percentage of free space in the java heap after GC |
| -XX: MaxNewSize = size |
Maximum memory occupied by the new pair |
| -XX: MaxPermSize = 64 m |
Maximum memory usage of old generation objects |
| -XX: MinHeapFreeRatio = 40 |
Minimum Percentage of free space in the java heap after GC |
| -XX: NewRatio = 2 |
Ratio of memory capacity of the new generation to memory capacity of the old generation |
| -XX: NewSize = 2.125 m |
Default memory usage when new generation objects are generated |
| -XX: ReservedCodeCacheSize = 32 m |
Reserve the memory used by the code |
| -XX: thread stacksize = 512 |
Sets the thread stack size. If it is 0, the default value is used. |
| -XX: + UseLargePages |
Use large page memory |
We basically use the above attributes in daily performance tuning;
Debugging parameter list:
| Parameters and Their default values |
Description |
| -XX:-CITime |
Print the time consumed by JIT compilation |
| -XX: ErrorFile =./hs_err_pid <pid>. log |
Save error logs or data to a file |
| -XX:-ExtendedDTraceProbes |
Enable the dtrace probe unique to solaris |
| -XX: HeapDumpPath =./java_pid <pid>. hprof |
Specifies the path or file name for exporting heap Information |
| -XX:-HeapDumpOnOutOfMemoryError |
When OOM is first encountered, export the relevant information in the heap. |
| -XX: |
Run the custom command after a fatal ERROR occurs. |
| -XX: OnOutOfMemoryError = "<cmd args>; <cmd args>" |
Execute custom commands When OOM is first encountered |
| -XX:-PrintClassHistogram |
Print the column information of the class instance after Ctrl-Break, which is the same as that of jmap-histo. |
| -XX:-PrintConcurrentLocks |
Print the information about the concurrent lock after encountering Ctrl-Break, which is the same as the jstack-l function. |
| -XX:-PrintCommandLineFlags |
Print the mark that appears in the command line |
| -XX:-PrintCompilation |
Print related information when a method is compiled. |
| -XX:-PrintGC |
Print related information during each GC |
| -XX:-PrintGC Details |
Print detailed information for each GC |
| -XX:-PrintGCTimeStamps |
Print the timestamp of each GC |
| -XX:-TraceClassLoading |
Tracking class loading information |
| -XX:-TraceClassLoadingPreorder |
Tracks the loading information of all referenced classes. |
| -XX:-TraceClassResolution |
Tracking constant pool |
| -XX:-TraceClassUnloading |
Unload information of the trace class |
| -XX:-TraceLoaderConstraints |
Tracking Information about the constraints of the Class Loader |
Summary
The preceding section describes how to set JVM runtime parameters in IntelliJ IDEA. I hope it will be helpful to you. If you have any questions, please leave a message, the editor will reply to you in a timely manner. Thank you very much for your support for the help House website!