jvm simple to understand

java virtual machine jvm

jvm is jre part of

When data is placed in JVM time, the data is decomposed into different positions

 

java runtime memory division

Thread shares:

Heap and method area

Thread the private area:

VM stack, native method stacks and program counter

Heap put real object

VM stack put java method

Native method stacks put native method

Methods district put class information, constants, static variables

The program counter  thread execution to the first few lines

 

 

 

Heap points

Newborn, old age, permanent behalf

Neonatal divided into Eden S0 S1. 8 : . 1 : . 1

 

Common garbage collector

 

 

 

Serial Collector: threaded   it will only use a CPU or a collection thread to complete the collection, and during all other work must be halted thread garbage collection until the end of the collection.

 

parNew Collector: Multithreading can be considered a serial multi-threaded version

 

CMS collector: a pause for the shortest recovery time objectives collector algorithm based on clear labeling

 

G1 Collector: for the garbage collector server is the Oracle JDK 9 after the default GC options

Advantages: Parallel and concurrent, generational collection, Spatial Integration, predictable pause

 

Garbage collection algorithm:

Replication algorithm

Mark - sweep algorithm

Tags to organize - Algorithm

 

JVM Tuning

 

Class life cycle:

Load connection (verify  prepare  analytical) initialization using the uninstall

 

Load: The .class file is read from disk into memory

Verify: verify the correctness of the bytecodes

Preparation: static variables to allocate memory class and given a default value

Analysis: All other class loader loads a class referenced

 

Type class loader

Start class loader

Responsible for loading the JRE core class libraries, such as rt.jar under JRE goal, charsets.jar and so on.

Extension class loader

Responsible for loading jre directory extension ext in the jar

System class loader

Responsible for loading the class package in the classpath

Custom loader

It is responsible for loading the user-defined class package path

 

Relationship class loader: up relations commission

Overall responsibility delegation mechanism

When a ClassLoader loading a class, unless another display ClassLoader, and such depends also referenced classes loaded by the ClassLoader .

Parents delegate mechanism (model )

Refers to entrust the parent class loader to find the target, find and load the target class in their path in the case can not be found

 

JVM tuning monitor command

Garbage collection to reclaim space in heap, stack memory space with the demise of thread and die , not subject to jvm garbage collection jurisdiction!

jps: by jps query process id pid

jinfo: View running java extension program parameters

View JVM parameters

jinfo -flags 11740

 

 

 

 

 

.Tuning

JVM tuning is the adjustment of the following two main indicators

Dwell time : garbage collector to do garbage collection interrupt the execution time of the application. -XX: MaxGCPauseMillis

Throughput : proportion of time and the total time of garbage collection: . 1 / (n-+. 1), the throughput of 1-1 / (1 + n). -XX: GCTimeRatio = n

GC tuning step

1. Print GC logs

-XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintGCDateStamps -Xloggc:c:/log/gc.log

Tomcat can be loaded directly JAVA_OPTS variable

2. Analysis of the log to get key indicators

3. GC analysis of the reasons, optimize the JVM arguments

Parallel Scavenge collector (default)

Log analysis:

First tuning provided Metaspace size: increasing the size of the space element () -XX: MetaspaceSize = 64M -XX : MaxMetaspaceSize = 64M

Second tuning, dynamic expansion increases the young generation increment (default is 20%) can be reduced YGC: -XX: YoungGenerationSizeIncrement = 30

Merge Tuning

-XX:+PrintGCDetails -XX:MetaspaceSize=64M -XX:MaxMetaspaceSize=64M -XX:YoungGenerationSizeIncrement=30 -XX:+PrintGCTimeStamps -XX:+PrintGCDateStamps -Xloggc:c:/log/gc-2.log

 

 

 

Use G1 collector collects logs

-XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintGCDateStamps -XX:+UseG1GC -Xloggc:./log/gc-g1.log

 

Guess you like

Origin www.cnblogs.com/lkc123/p/11461483.html