当前位置:网站首页>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)
边栏推荐
- Software testing is so hard to find, only outsourcing offers, should I go?
- GoLand 2021.1: rename the go project
- [技術發展-24]:現有物聯網通信技術特點
- Metal organic framework (MOFs) antitumor drug carrier | pcn-223 loaded with metronidazole | uio-66 loaded with ciprofloxacin hydrochloride( Stack application (balancer)
- 软件测试工作那么难找,只有外包offer,我该去么?
- Unable to stop it, domestic chips have made another breakthrough, and some links have reached 4nm
- MySQL 数据处理值增删改
- MySQL data processing value addition, deletion and modification
- 全局事件总线
猜你喜欢

交联环糊精金属有机骨架负载甲氨蝶呤缓释微粒|金属-有机多孔材料UiO-66负载黄酮苷类药物|齐岳

GoLand 2021.2 configure go (go1.17.6)
![[机缘参悟-37]:人感官系统的结构决定了人类是以自我为中心](/img/06/b71b505c7072d540955fda6da1dc1b.jpg)
[机缘参悟-37]:人感官系统的结构决定了人类是以自我为中心

核酸修饰的金属有机框架药物载体|PCN-223金属有机骨架包载Ad金刚烷|ZIF-8包裹阿霉素(DOX)

jvm-运行时数据区

Nucleic acid modified metal organic framework drug carrier | pcn-223 metal organic framework encapsulated ad adamantane | zif-8 encapsulated adriamycin (DOX)

QT learning 20 standard dialog box in QT (middle)

UiO-66-COOH装载苯达莫司汀|羟基磷灰石( HA) 包裹MIL-53(Fe)纳米粒子|装载黄芩苷锰基金属有机骨架材料

Ocean CMS vulnerability - search php

Use vscode to view hex or UTF-8 codes
随机推荐
树的深入和广度优先遍历(不考虑二叉树)
Another industry has been broken by Chinese chips. No wonder the leading analog chip companies in the United States have cut prices and sold off
核酸修饰的金属有机框架药物载体|PCN-223金属有机骨架包载Ad金刚烷|ZIF-8包裹阿霉素(DOX)
3D vision - 2 Introduction to pose estimation - openpose includes installation, compilation and use (single frame, real-time video)
php 迷宫游戏
全局事件总线
Use docker to build sqli lab environment and upload labs environment, and the operation steps are provided with screenshots.
NFT新的契机,多媒体NFT聚合平台OKALEIDO即将上线
QT learning 19 standard dialog box in QT (top)
Qt学习23 布局管理器(二)
可编程逻辑器件软件测试
Metal organic framework MOFs loaded with non steroidal anti-inflammatory drugs | zif-8 wrapped Prussian blue loaded quercetin (preparation method)
Golang — template
Comprehensive case of MySQL data addition, deletion, modification and query
Selenium browser (1)
SQL Injection (GET/Select)
Dynamic programming 01 knapsack and complete knapsack
Use and design of Muduo buffer class
jvm-类加载
28:第三章:开发通行证服务:11:在配置文件中定义属性,然后在代码中去获取;