jvm parameter settings

1. Trace trace parameters  

    1.1 Parameter configuration about GC

            -XX:+printGC Print brief information about GC

            -XX:+PrintGCDetails Print GC details

            -XX:+PrintGCTimeStamps Print the timestamp of CG occurrence

            -Xloggc:log/gc.log specifies the location of the GC log

            -XX:+PrintHeapAtGC Print heap information before and after every GC.

    1.2 Explanation of GC logs           

        [GC[DefNew: 4416K->0K(4928K), 0.0001897secs] 4790K->374K(15872K), 0.0002232 secs] [Times: user=0.00 sys=0.00,real=0.00 secs]

            The log above means: This is a new generation of GC. The meaning of "4416K->0K(4928K)" inside the square brackets is: "The used capacity of this memory area before GC -> the used capacity of this memory area after GC (total capacity of this memory area)". "4790K->374K(15872K)" outside the square brackets means "used capacity of Java heap before GC -> used capacity of Java heap after GC (total Java heap capacity)". Looking back, "0.0001897 secs" indicates the time occupied by the GC of this memory area, in seconds.       

            In the figure above, let's first look at the meaning of "[0x27e80000, 0x28d80000, 0x28d80000)" marked with a red box, which indicates the location of the new generation in memory: the first parameter is the applied starting position, the second The parameter is the end position applied for, and the third parameter indicates the position that can be applied for at most. The example in the above figure indicates that the new generation has applied for a 15M control, and this 15M is equal to: (12288K of eden space) + (1536K of from space) + (1536K of to space).

2. Parameter settings about the java heap

    2.1 Parameter configuration about java heap

        -Xmx –Xms specify max heap and initial heap

        -Xmn sets the young generation size

        -XX:NewRatio The ratio of the old generation (excluding the permanent area) to the young generation (eden+2*s)

        -XX:SurvivorRatio (survivor generation) The ratio of eden area to Survivor

            The default value of SurvivorRatio is 8, which means that the ratio of Edon and Survivor is 8:1:1.

        Different heap distributions will have a certain impact on system execution. The basic strategy is to reserve objects in the new generation as much as possible to reduce the number of GCs in the old generation.

    2.2 Configuration of processing parameters for heap overflow

        -XX:+HeapDumpOnOutOfMemoryError OOM (heap overflow) export the entire heap information to a file According to this file, we can see what happened when the system dumped.

        -XX:+HeapDumpPath can set the path to export heap information

3. About the parameter setting of the method area

    -XX:PermSize Set the initial space of the permanent area

     -XX:MaxPermSize  Sets the maximum space for the permanent area.

    That is to say, when the jvm starts, the permanent area occupies the space of PermSize size from the beginning. If the space is not enough, it can continue to expand, but it cannot exceed MaxPermSize, otherwise it will OOM (memory overflow).

    If the heap space is not used up and the OOM is thrown, it may be caused by the permanent area. The actual heap space is very small, but the overflow of the permanent area throws OOM.

4. Parameter settings about the java stack

    -Xss Set the size of the stack space. Usually only a few hundred K

  Determines the depth of function calls

  Each thread has its own stack space

  Local variables and parameters are allocated on the stack

5. JVM Server mode and client mode

    5.1 JVM Server Mode and Client Mode

        After our jdk is installed, enter java -version in the named line to see not only the jdk version related information, but also something like Java HotSpot(TM) 64-Bit Server VM (build 25.31-b07, mixed mode) information. One of the Server VMs (build 25.31-b07, mixed mode) actually represents the Server mode of the JVM. Of course, the JVM also has a Client mode.

    5.2 What is the difference between JVM Server mode and client mode startup?

    The main difference is: when the -Server mode starts, the speed is slower, but once it starts up, the performance will be greatly improved. The reason is: when the virtual machine runs in the -client mode, it uses a code name It is a lightweight compiler for C1, and the virtual machine started in -server mode uses a relatively heavyweight compiler, code-named C2. C2 is compiled relatively thoroughly than the C1 compiler, and after serving, the performance is higher. Therefore, it is usually used We use the server-side mode when doing the server. If your computer just runs the java program, the client-side mode is fine. Even though the server mode compiles more thoroughly and the garbage collection optimization is better, this of course eats more memory than the client mode.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325657267&siteId=291194637