当前位置:网站首页>JVM Foundation
JVM Foundation
2022-07-25 01:41:00 【Pig enlightenment】
JVM Basics
One 、GC Object recovery judgment
1. Recovery judgment
1. Reference counting : Each object has a reference count property , New reference +1, Release -1, Count as 0 Recycling is allowed when advantage : Efficient shortcoming : When referring to each other , Even if two objects are not used , But it can't be recycled 2. Accessibility analysis : from GC ROOT Start looking down , Objects in the reference chain are not recyclable , That is, an object from GC ROOT Unreachable GC ROOT: Virtual machine stack ( Local variables in stack frames ) Object referenced in Object referenced by a static property in a method area The object referenced by a constant in the method area In local method JNI(Native) Referenced object example : A method , In the active stack , Then the object created inside , It's just one. GC ROOT Such as add(){
User user = new User()} In execution user
Recycling process :
① Object is not reachable , Mark for the first time
② Automatically created by virtual machine Finalizer The queue determines whether to execute finalize() Method
After the object is unreachable ,GC Determine whether it covers finalize Method , If it is not covered, it will be recycled directly ; Otherwise, if the object has not been executed finalize Method , Put it in F-Queue queue , Executed by a low priority thread
Row of objects in the queue finalize Method , After execution ,GC Again, judge whether the object is reachable , If not, recycle , Otherwise, the object “ resurrection ”
Each object can only be triggered once finalize() Method : Generally, do not duplicate this method
2. Garbage collector
GC Algorithm focus and JVM tuning , Is to reduce STW state
STW: Stop-The-World In the process of recycling , Need to put JVM A state in which memory is frozen . stay STW State, ,JAVA All threads ( except GC) All stop ;native Method can execute , But you can't
And JVM Interaction
1. Generational algorithm

Serial: Serial GC Threads are interleaved between worker threads ,GC During this period, other threads are equivalent to pausing
Early single CPU Recycling mode under the framework , Only applicable to tens of megabytes of memory space ; many CPU Severe performance degradation under
Parallel: parallel Multiple GC Threads are interleaved between worker threads
PS+PO The combination is Jdk1.8 Default garbage collector , many CPU The performance under the architecture is better than Serial Much higher
CMS: Concurrent Mark Sweep The core idea : take STW Upset , Let part GC Threads execute concurrently with user threads
1. Initial marker :STW Only the objects directly referenced by the root object are marked
2. Concurrent Tags : Continue marking other objects , And execute concurrently with the worker thread
3. Re label :STW Relabel the objects in the concurrent execution stage
4. Concurrent elimination : Parallel with worker threads , Remove the generated garbage . The newly generated garbage in this process is called floating garbage , Next GC Middle clearance

2.G1 GarbageFirst
His memory model is actually generational , But logically, it is generational
In the in memory model , Heap memory is no longer divided into young generations 、 Old age , Instead, it is divided into small memory blocks , be called Region, Every Regio It can belong to different ages
GC There are four stages
1. Initial marker : STW Only the objects directly referenced by the root object are marked
2. Mark Region: adopt RSet Mark what was marked in the previous stage Region Reference to Old District Region
3. Concurrent Tags : And CMS similar , The traversal range is no longer the whole Old District , It is marked in the second step of traversal Region
4. Re label : And CMS Relabel similar
5. rubbish : And CMS The difference is ,G1 Copy algorithm can be used , Direct the whole Region Copy the object in to another Region And this stage G1 Choose only those with more garbage Region To clean up , It's not over
Clean it up
Two 、Java Class loading process
JAVA Class loader ( Inherit ):AppClassloader,ExtClassloader -> URLClassloader -> SecureClassloader -> Classloader
JAVA Class loader (Parent attribute ):AppClassloader -> ExtClassloader -> BootstrapClassloader
Each kind of loader , Each has its own loading directory
AppClassloader:classpath
ExtClassloader:java.ext.dirs
BootstrapClassloader:%JAVA_HOME%/lib
Each class loader is responsible for the classes it has loaded , There is a cache
Class loading process : load 》 Connect 》 initialization
load : hold JAVA Byte code loaded into JVM In memory , And map it to JVM Approved data structures
Connect : It is divided into three small stages
① verification : Check whether the loaded file conforms to JAVA standard
② Get ready : Create a static variable of a class or interface , And assign initialization value
③ analysis : Turn symbolic references into direct references
initialization : User defined logic
Parent delegate mechanism :
effect : Protect the underlying classes from being overwritten by user classes ( For example, the user defined java.lang.String, When the class is loaded, the upward delegation will get the underlying String class , Not user-defined )
3、 ... and 、JVM Memory model

边栏推荐
- Scientific data center resources and user access control system
- Harbor installation
- [25. Hash table]
- Thinkphp5.0.24 deserialization chain analysis
- Leetcode - number of palindromes
- 【Appium】Failed to create session. An unknown server-side error occurred while processing the command
- 2022.7.20 linear table
- Latest information of 2022 cloud computing skills competition
- [27. Expression evaluation (infix expression)]
- MySQL series | log module
猜你喜欢

Human cell prosci 4-1BB ligand recombinant protein scheme

DotNetCore. Cap notes

Worthington cytochrome c digestion study carboxypeptidase B scheme
![[recognize cloud Nativity] Chapter 4 cloud network section 4.9.4.3 - smart network card usage scenario - network acceleration implementation](/img/9a/b69036bf920706360d8b293dad2a89.png)
[recognize cloud Nativity] Chapter 4 cloud network section 4.9.4.3 - smart network card usage scenario - network acceleration implementation

Web Security Foundation - file upload

1260. Two dimensional grid migration: simple construction simulation problem

Peripherals: interrupt system of keys and CPU

7.18 - daily question - 408

On let variable promotion

Pychart exits pytest mode (run pytest in mode)
随机推荐
Worthington cytochrome c digestion study carboxypeptidase B scheme
Upgrade the leapfrog products again, and the 2023 Geely Xingrui will be sold from 113700 yuan
Custom type
Some of my understanding about anti shake and throttling
Several application scenarios of NAT
Yolov7:oserror: [winerror 1455] the page file is too small to complete the final solution of the operation
Multi species tissue slide prosci pancreatic tissue solution
[27. Expression evaluation (infix expression)]
Fabric. JS centered element
After burning up 130 billion yuan in ten years, vertical e-commerce will eventually enter the dust of history
Amd epyc 9654 Genoa CPU cache test exposure L1 bandwidth up to 30tb/s
Inventory of well-known source code mall systems at home and abroad
What is iftmcs indicating contract status message?
The difference between sigsuspend and sigwait
C#/VB. Net insert watermark in word
[summer daily question] output of Luogu p1157 combination
[FAQ of waiting insurance] can the waiting insurance evaluation organization help with the waiting insurance rectification?
WhatsApp web for usability testing of software testing technology
Peripherals: interrupt system of keys and CPU
Pychart exits pytest mode (run pytest in mode)