Hello, today for everyone children’s shoes to share is JS, quickly take out a small notebook to write down

What is the JVM? Where is the JVM? What does the JVM do? Java Virtual MAchine

A Java VIRTUAL machine that runs on an operating system. The JRE contains the JVM, and the JRE is the runtime environment. Java classes into. Class bytecode, Java programs cross-platform.

Class loader?

Function: Loads a class file.

What is the parent delegate mechanism?

Vm built-in loader Startup class (root) loader (rt.jar) Extended class loader ExtClassLoader Application program loader AppClassLoader

APP —-> Ext —-> rt.jar —-> current application

Architecture of the JVM.

Java file —-> changed through javac. Class file —–> ClassLoader —–>JVMJVM contains method area, heap, Java stack, local method stack, program counter

The stack? Heap? Methods area?

Stack: A data structure, first in, last out, last in, first out. It is often compared to queues because queues have a first-in, first-out data structure.

The program starts the main method at the bottom of the stack, and then pulls out the contents of main and puts them on the stack layer by layer. The life cycle is synchronized with the thread. The stack memory starts when the thread starts and is released when the thread ends. So there is no garbage collection in the stack. Once the thread terminates, the stack is Over! Threads are private.

The stack holds Java8 big data types, object references, instance methods, and main methods

A JVM has only one Heap, and the size of the Heap can be adjusted.

The class loader reads the class file and puts the class instance (real object) and the variable assignment into the heap.

The heap memory is subdivided into three regions: newborn zone (Eden zone, Survivor 0 zone, survivor 1 zone), old zone, permanent zone (meta-space)

Method area: A method area is a small area of memory that belongs to the heap

Store static, final, Class templates, constant pools, static variables, constants, Class information (constructors, interface definitions), runtime constant pools

Stack, heap, method area interaction?

That’s the relationship of the new object

Native keywords?

In the local method stack.

Any method with the Native keyword indicates that the scope of Java is out of reach, calling the underlying C language library.

1. Access the Native Method Stack

2. Call the local method interface JNI (JNI’s role: to expand the use of Java, integration of different programming languages for Java. Native is C)

3. It specially opens up a marker area in the memory area Native Method Stack.

4. When finally executed, load the interface in the local method through JNI.

1.PC register?

Program counter: Each thread has a program counter, which is thread-private and is a pointer to the bytecode in the method area. The execution engine that reads the next instruction has a very small memory space.

2. What is OOM? What is stack overflow? How do you analyze it?

OOM heap overflows. Assigning values to variables indefinitely causes a heap overflow.

Stack overflow: An infinite recursive call to a method causes a stack overflow.

What are the common tuning parameters for the JVM? Heap memory tuning?

-XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=128m -Xms1024m -Xmx1024m -Xmn256m -Xss256k -XX:SurvivorRatio=8 -XX:+UseConcMarkSweepGC

The idea of adjusting the parameters of the virtual machine to add – Xms1m – Xmx8m – XX: + HeapDumpOnOutOfMemoeyError

The maximum memory size is 8 meters. If the memory size exceeds 8 meters, an OOM exception occurs. XMS Initial memory size 164 XMX Maximum memory size 1/4 by default

– XX: + PrintGCDetails print GC garbage collection information – XX: + HeapDumpOnOutOfMemoeyError

Heap overflow exception + stands for command

Why is there no garbage in the stack? And the garbage is in the pile?

Because the stack contains eight basic types, object references, and instance methods that cannot be garbage, there is no need to recycle them. The heap is divided into three regions: Cenozoic, old age and meta-space. The Cenozoic era is divided into Eden area, surviving 0 area, surviving 1 area. The JVM will only recycle the Eden park, survival zone, and old zone for CG. Most of the recycling is actually in Eden Park.

GC reference counter algorithm:

Object A refers to the counter once +1 object B refers to the counter twice +2 Object C refers to the counter zero times No reference counts 0 to clear garbage.

Replication algorithm:

1. Each GC moves live objects in Eden to the survivable zone. Once the Eden field is GC, it will be empty.

2. Assuming both extents have items, it copies items from the FROM region to to. When “from” is empty, it changes its identity to “to”. He who is empty is to

3. An object enters the old age after 15 (the default) GCS in the new age

Benefit: No memory fragmentation

Cons: Wasted memory space

Best use scenario: objects with low survival – > new area

Mark removal method:

Run the second scan: Remove the marked objects. Advantage: You don’t need any extra space. Disadvantage: Two scans waste time and generate memory fragmentation.

Mark compression method:

1. First scan: scan surviving objects and mark them. 2. Second scan: clear unmarked objects 3. Scan again. Put all living objects together in order. Advantages: Prevents memory fragmentation Disadvantages: Three scans waste time and generate memory fragmentation.

Mark clear compression:

Five light GC passes after mark clearing + compression

GC generation collection method

Young generation: low survival rate of replication algorithm old generation: mark clearing (memory fragmentation is not much)+ mark compression hybrid region large survival rate

JMMJava Memory Model The Java Memory Model integrates threading and multiprocessor technology. Contains stack, local method stack, program counter, heap, method area.

Java memory model partitioning?

Stack: Java8 Big data types, object references, main method local method stack: Nativa keyword. Java cannot scope the underlying, C++ code. Heap: class instances, variable assignments, method areas: class templates, constants, static keyword stuff

Heap partition? Cenozoic era, old age and meta-space Cenozoic era is divided into: Eden area, Surviving 0 area Form, surviving 1 area To

When will light GC and heavy GC occur?

GC:

Occurs in the nascent region, and a light GC is triggered when the nascent object cannot be created in the Eden region. Copy what survived in the surviving FROM region to the surviving TO region, and convert both regions from to to, and to to from. He who is empty is to.

GC:

An object that tries to create in Eden will trigger light GC, but after light GC is done Eden will still try to go straight to the old age. However, if the old age is not fit enough, it will trigger the regc to clean up the old age’s space

Well, this is the end of today’s article, I hope to help you confused in front of the screen