JVM

1. jvm Principle:

Reference: https://baijiahao.baidu.com/s? Id=1606480770208000096& wfr=spider& for=pc

Description: JVM tuning is mainly to optimize Heap heap and Method Area method area.

Heap heap

The heap is the largest area in the JVM. The object and data of the application are in this area. This area is also shared by threads. It is also the main recovery area of gc. A JVM instance has only one heap class memory. The size of the heap memory can be adjusted. The class loader reads the class file and needs to do so.To put classes, methods, and constants in the heap memory for easy execution by the executor, the heap memory is divided into three parts:

① New Area

The new area is the birth, growth and extinction of the region, where a class is generated, applied, and finally collected by the garbage collector, ending life. The newborn area is divided into two parts: Eden space and Survivor space, all of which are in Iraq.The area was new. There are two surviving areas: 0 districts (Survivor 0 space) and 1 districts (Survivor 1 space). When the Garden of Eden runs out of space, the program needs to create objects, and the JVM garbage collector will collect garbage from the Garden of Eden.(Minor GC) moved the remaining objects in the garden of Eden to the 0 surviving area. If the 0 surviving area is full, garbage collection will be carried out in the area and then moved to area 1. What if 1 goes full? And move to the pension area. If the pension area is full, it will produce Major GC at this time.(FullGCC) carry out memory clearance in the pension area. If an old-age area finds that it is still unable to save objects after Full GC is executed, an OOM exception “Out of Memory Error” will occur.

If a java. lang. OutOfMemoryError: Java heap space exception occurs, the heap memory of the Java virtual machine is insufficient. There are two reasons:

a.JavaThe heap memory of the virtual machine is not set enough, and can be adjusted by parameters -Xms and -Xmx.

b.Large numbers of large objects are created in the code and cannot be collected (referenced) by the garbage collector for a long time.

② Pension area

Pension zones are used to hold JAVA objects filtered from newborn zones, where pool objects are generally active.

③ Permanent area

Permanent storage area is a resident memory area used to store the CLASS, Interface metadata that the JDK itself carries, that is, it stores the class information necessary for the running environment. The data loaded into this area will not be recycled by the garbage collector. Close the JVMIt will release the memory occupied by this area.

If a java. lang. OutOfMemoryError: PermGen space appears, it means that the Java virtual machine does not have enough memory settings for permanent perm. There are two reasons:

a. Program startup requires loading a large number of third party jar packages. For example, there are too many applications in the lower part of a Tomcat.

b. A large number of dynamic reflection generated classes are constantly loaded, resulting in Perm area occupied.

Explain:

Jdk1.6And before: constant pool allocation in permanent generation.

Jdk1.7:Yes, but it has gradually “gone forever”.

Jdk1.8And then: none (java. lang. OutOfMemoryError: PermGen space, which will not appear in JDK 1.8).

Explanation: Objection in method area and heap memory:

Actually, the method area, like the heap, is the memory area shared by the threads that stores the loaded virtual machine: class information + normal constants + static constants + compiled code, and so on. Although the JVM specification describes the method area as a logical part of the heap, it has an alias called NoN-Heap (non heap) is designed to separate from heap.

For HotSpot virtual machines, many developers are accustomed to calling the method area “Parmanent Gen.” But strictly speaking, the two are different in nature, or using permanent generations to implement the method area. Permanent generations are an implementation of the method area, in the version of jdk1.7The string constant pool that was originally placed on the permanent generation has been removed.

Constant pool is a part of method area. Class file contains not only the description information of class version, field, method and interface, but also the constant pool, which is stored in the runtime constant pool when the class loads into the method area.

2. jvm Parameter adjustment

Leave a Reply

Your email address will not be published. Required fields are marked *