The first three are already on the street, so I won’t write them here. Click on the blue font to see related blog posts

JVM memory model

The JVM algorithm

JVM garbage collector

The JVM tuning

Check the parameters

The first:

View the process number: JPS -l

Jinfo-flag Indicates the number of a Java process

Jinfo-flags Specifies a parameter

 

The second:

Check the JVM factory defaults: Java -xx :+PrintFlagsInitial

Java -xx :+PrintFlagsFinal -version

Check the default garbage collector: Java -xx :+PrintCommandLineFlags -version

 

Common parameters:

-xmx (-xx :MaxHeapSize) : Initial size Memory: The initialized value is one fourth of the physical memory

-xMS (-xx :InitialHeapSize) : Maximum allocated memory: The initialized value is 1/64 of the physical memory

-xss (-xx :ThreadStackSize) : Sets the size of a single thread stack. The default value is 512K to 1024K

-Xmn: Sets the size of the young generation

MetaspaceSize MetaspaceSize MetaspaceSize MetaspaceSize MetaspaceSize MetaspaceSize MetaspaceSize MetaspaceSize MetaspaceSize MetaspaceSize MetaspaceSize MetaspaceSize MetaspaceSize The difference between a meta-space and a permanent generation, however, is that the meta-space is not in the VIRTUAL machine. It is in local memory, and by default, the size of the meta-space is limited only by local memory.

 

-Xms 128m -Xmx4096m -Xss1024k -XX:MetaspaceSize=512m -XX:+PrintCommandLineFlags -XX:+PrintGCDetails -XX:+UseSerialGC

-Xms 128 MB: the initial memory is 128 MB

-XMX4096M: The maximum heap memory is 4G

-Xss1024k: indicates the initial stack size of 1024K

-xx :MetaspaceSize= 512M: indicates that the MetaspaceSize is 512M

-xx :+PrintCommandLineFlags: Prints the default parameters

-xx :+PrintGCDetails: Prints the details of GC collection

-xx :+UseSerialGC: serial garbage collector

-xx :+PrintGCDetails

Case: blog.csdn.net/java_wxid/a…

-xx :SurvivorRatio: sets the ratio of Eden and S0/S1 Spaces in the new generation.

Default: -xx :SurvivorRatio=8,Eden:S0:S1=8:1:1;

If – XX: SurvivorRatio = 4, Eden: S0: S1 = 4:1:1. The value of SurvivorRatio is set to the proportion of Eden going,S0 is the same as S1

-xx :NewRatio: Configures the ratio of the young band to the old band in the heap.

Default: -xx :NewRatio=2 Cenozoic era 1, old age 2, the young zone accounts for 1/3 of the whole heap. If: -xx :NewRatio=4 The Cenozoic era accounts for 1, the old age accounts for 4, and the young belt accounts for 1/5 of the whole heap. The value of NewRatio is set to the ratio of the old to the new, and 1 to the new.

-xx :MaxTenuringThreshold: sets the maximum age of garbage

After java8, this value can be set to a maximum of 15 and a minimum of 0

Landing implementation:

Mopping implementation case:

The big four references

Strong Reference(default supported mode)

For example: Book Book = new Book();

Theory:

Practical:

Soft reference SoftReference

Theory:

Practical:

When memory is sufficient:

Out of memory:

A weak reference WeakReference

Theory:

Practical:

Soft and weak references are used in the following scenarios:

Actual combat: The use of WeakHashMap

Phantom reference PhantomReference

Theory:

Practical:

Weak references and reference queues

Virtual references and reference queues:

Common JVM exceptions

StackOverflowError: Thread stack space is exhausted and not enough resources are allocated to the newly created stack frame

OutofMemoryError: Java Heap Space There is not enough memory in the heap to hold newly created objects

OutOfMemoryError: GC overhead limit exceeded 98% of time spent doing GC and reclaimed less than 2% of heap memory

OutOfMemoryError: Direct Buffer Memory Memory outside the heap

OutofMemoryError: Unable to create a new native thread

Solution:

OutOfMemoryError: Metaspace metadata area is full

Solution: -xx :MaxMetaspaceSize= 512MB

Class loading mechanism (parental delegation)

Bootstrap C++ Extension class loader Java application class loader Java AppClassLoader

The parent delegation model works: if a class loader receives a request for a class load, it first does not try to load the class itself. Instead, it delegates the request to the parent class loader. This is true for every classloader, and only if the parent cannot find the specified class in its search scope (that is, ClassNotFoundException) will the child loader attempt to load it itself.

Create an object. How is this object allocated in memory?

www.zhihu.com/question/55…