web123456

jvm memory configuration

The jvm is created when the java program is started and the operating system allocates memory to the jvm, this memory is the runtime data area of the jvm.

The runtime data area usually consists of these sections: Program Counter Register, Java Stack, Local Method Stack (Native Method Stack), Method Area (Method Area), Heap (Heap)

The main memory parameters that are frequently configured are the following:

  • Xss: stack size per thread (stack)
  • Xmx: the maximum value of JAVA HEAP, default is 1/4 of physical memory
  • Xms: the initial value of JAVA HEAP, server-side preferably Xms is the same as Xmx.
  • Xmn: the size of the JAVA HEAP young area (equivalent to setting -XX:newSize, -XX:MaxnewSize at the same time).
  • XX:PermSize: set the permanent storage area of memory (JDK7)
  • XX:MaxPermSize: set the maximum memory persistence area (JDK7)

existJDK1.8in which PermGen is eliminated and replaced by Metaspace, so the PermSize and MaxPermSize parameters are invalidated and replaced by the metaspace:.

-XX:MetaspaceSize
-XX:MaxMetaspaceSize

This time by configuring different parameters,utilizationjmapObservation of changes in parameters。

1、experimentalPrepare:

1.1 Operating system: win10, install jdk8

2.2 Make an executable jar package, this experiment uses spring boot to develop a web application .

3.3 If more than one version of jdk is installed, make sure that you are using the same version when experimenting

2, by configuring different memory parameters and sizes, use the jmap command to observe memory changes

2.1 Default memory (startup without any memory parameters)

Execute in a command line window: java -jar

Open a new command window and execute jmap -heap java process ID

        

2.2 Setting the Maximum Memory -Xmx

      java -Xmx20m -jar

      

2.3 Cenozoic

   java -Xmx20m -Xmn5m -jar

2.4 Meta-space size

java -Xmx20m -Xmn5m -XX:MetaspaceSize=512m -XX:MaxMetaspaceSize=512m -jar