当前位置:网站首页>JVM object lifecycle
JVM object lifecycle
2022-07-03 14:00:00 【It's hard to choose a name】
List of articles
jvm The life cycle of the object in
Create a stage
(1) Allocate storage space for objects
(2) Start constructing objects
(3) From superclass to subclass pair static Members are initialized
(4) Superclass member variables are initialized in order , Recursively calls the constructor of the superclass
(5) Subclass member variables are initialized in order , Subclass construct method call , And once the object is created , And assigned to some variables
value , The shape of this object State switches to the application stage
Application stage
(1) The system maintains at least one strong reference to the object (Strong Reference)
(2) All references to this object are strong references ( Unless we explicitly use : Soft citation (Soft Reference)、
Weak reference (Weak Reference) Or virtual reference (Phantom Reference))
The definition of reference :
1. Our data type must be reference type
2. The data stored in our type of data must be the starting address of another piece of memory
Invisible stage
Objects in the invisible phase can no longer find direct or indirect strong references in the object root reference collection of the virtual machine , The most common is temporary variables in threads or functions . Programs no longer hold strong references to objects .( But static variables of some classes or JNI It is possible to hold )
Unreachable stage
It means that the object is no longer held by any strong reference ,GC It is found that the object is unreachable
The difference from the invisible stage is : Unreachable is after Algorithm
So what are the algorithms ?
Reference count :
Object has a reference to +1, Remove a reference and -1, When the number of references is 0 It is considered that there is no quotation , Recyclable
problem : Can't solve the problem of circular dependency
Accessibility analysis : adopt GC Root The object of , Start looking down , See if an object can reach
What can be regarded as GC ROOT: loader 、Thread、 Local variable table of virtual machine stack 、static member 、 const reference 、
Variables of the local method stack are essentially a set of active references
Collection phase
See whether the object needs to be executed finalize Method :
If you don't need to : Virtual machine has been called finalize Methods or objects are not overridden finalize Method , Then the object can be recycled
need : The virtual machine puts objects into F-queue, Create a low priority thread to execute the objects in the queue finalize Method
finalize Method to re establish the reference connection for the object
yes : The virtual machine moves the object out F-queue queue , Object returns to the application stage
no : Objects can be recycled
finalize Methods can affect JVM The object of the allocation and the recycling speed
finalize Methods may revive objects
The end stage
Object's finalize() After the function is executed , The object is still unreachable , This object is the process termination stage .
Object memory space reallocation phase
GC Reclaim or reallocate the memory space occupied by this object , The object disappeared completely
out of memory
1、 Heap memory overflow :java.lang.OutOfMemoryError: GC overhead limit exceeded
-Xmx20M : The maximum size that can be expanded when the program runs
-Xms20M: Initialize heap size
2、 Method area memory overflow :java.lang.OutOfMemoryError: Metaspace
-XX:MetaspaceSize: Initialize method area size
-XX:MaxMetaspaceSize: The maximum size that can be expanded when the program runs
3、 Occupy memory overflow :java.lang.StackOverflowError
-Xss: The size of the stack ( Default 1M)
边栏推荐
- Go 1.16.4: manage third-party libraries with Mod
- selenium 浏览器(1)
- 太阳底下无新事,元宇宙能否更上层楼?
- There is nothing new under the sun. Can the meta universe go higher?
- QT learning 19 standard dialog box in QT (top)
- Ocean CMS vulnerability - search php
- 怎样删除对象的某个属性或⽅法
- 消息订阅与发布
- Go: send the get request and parse the return JSON (go1.16.4)
- logback日志的整理
猜你喜欢
[bw16 application] instructions for firmware burning of Anxin Ke bw16 module and development board update
Installation impression notes
Mysql:insert date:sql error [1292] [22001]: data truncation: incorrect date value:
可编程逻辑器件软件测试
使用vscode查看Hex或UTF-8编码
[développement technologique - 24]: caractéristiques des technologies de communication Internet des objets existantes
Comprehensively develop the main channel of digital economy and digital group, and actively promote the utonmos digital Tibet market
GoLand 2021.1: rename the go project
[email protected]纳米粒子"/>
金属有机骨架MIL-88负载阿霉素DOX|叶酸修饰UiO-66-NH2负载阿霉素[email protected]纳米粒子
全面发展数字经济主航道 和数集团积极推动UTONMOS数藏市场
随机推荐
Software testing is so hard to find, only outsourcing offers, should I go?
Multi person collaborative data annotation based on Baidu brain easydata from scratch
[combinatorics] permutation and combination (examples of combinatorial number of multiple sets | three counting models | selection problem | combinatorial problem of multiple sets | nonnegative intege
[quantitative trading] permanent portfolio, turtle trading rules reading, back testing and discussion
Mysql:insert date:SQL 错误 [1292] [22001]: Data truncation: Incorrect date value:
【556. 下一个更大元素 III】
Analysis of the characteristics of page owner
[technology development-24]: characteristics of existing IOT communication technology
Shell timing script, starting from 0, CSV format data is regularly imported into PostgreSQL database shell script example
Leetcode-1175.Prime Arrangements
PhpMyAdmin stage file contains analysis traceability
[understanding by chance-37]: the structure of human sensory system determines that human beings are self-centered
Qt学习18 登录对话框实例分析
QT learning 17 dialog box and its types
FPGA测试方法以Mentor工具为例
JS new challenges
【吉林大学】考研初试复试资料分享
Unity embeddedbrowser browser plug-in event communication
Function calling convention
金属有机骨架MIL-88负载阿霉素DOX|叶酸修饰UiO-66-NH2负载阿霉素[email protected]纳米粒子