当前位置:网站首页>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)
边栏推荐
- 3D视觉——2.人体姿态估计(Pose Estimation)入门——OpenPose含安装、编译、使用(单帧、实时视频)
- 太阳底下无新事,元宇宙能否更上层楼?
- [combinatorics] permutation and combination (two counting principles, examples of set permutation | examples of set permutation and circle permutation)
- Unity embeddedbrowser browser plug-in event communication
- How to promote the progress of project collaboration | community essay solicitation
- Go language unit test 3: go language uses gocovey library to do unit test
- Mysql:insert date:sql error [1292] [22001]: data truncation: incorrect date value:
- 掌握Cypress命令行选项,是真正掌握Cypress的基础
- Leetcode-1175. Prime Arrangements
- 消息订阅与发布
猜你喜欢
Go language web development series 29: Gin framework uses gin contrib / sessions library to manage sessions (based on cookies)
Comprehensively develop the main channel of digital economy and digital group, and actively promote the utonmos digital Tibet market
Mysql:insert date:SQL 错误 [1292] [22001]: Data truncation: Incorrect date value:
3D vision - 2 Introduction to pose estimation - openpose includes installation, compilation and use (single frame, real-time video)
Go language web development series 26: Gin framework: demonstrates the execution sequence of code when there are multiple middleware
Flutter dynamic | fair 2.5.0 new version features
小项目(servelt+jsp+mysql+EL+JSTL)完成一个登录功能的Servlet,具有增删改查的操作。实现登录身份验证,防止非法登录,防止多点登录,记住用户名密码功能。
UiO-66-COOH装载苯达莫司汀|羟基磷灰石( HA) 包裹MIL-53(Fe)纳米粒子|装载黄芩苷锰基金属有机骨架材料
可编程逻辑器件软件测试
Unable to stop it, domestic chips have made another breakthrough, and some links have reached 4nm
随机推荐
Use vscode to view hex or UTF-8 codes
Doxorubicin loaded on metal organic framework MIL-88 DOX | folic acid modified uio-66-nh2 doxorubicin loaded [email
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
消息订阅与发布
Sequence table (implemented in C language)
Uniapp tips - set background music
树的深入和广度优先遍历(不考虑二叉树)
Nucleic acid modified metal organic framework drug carrier | pcn-223 metal organic framework encapsulated ad adamantane | zif-8 encapsulated adriamycin (DOX)
Golang — 命令行工具cobra
Mysql:insert date:sql error [1292] [22001]: data truncation: incorrect date value:
Use and design of Muduo buffer class
jvm-类加载
SQL Injection (POST/Select)
Implementation of Muduo asynchronous logging
Qt学习22 布局管理器(一)
Unity Render Streaming通过Js与Unity自定义通讯
SQL Injection (POST/Search)
[understanding by chance-37]: the structure of human sensory system determines that human beings are self-centered
叶酸修饰的金属-有机骨架(ZIF-8)载黄芩苷|金属有机骨架复合磁性材料([email protected])|制备路线
小项目(servelt+jsp+mysql+EL+JSTL)完成一个登录功能的Servlet,具有增删改查的操作。实现登录身份验证,防止非法登录,防止多点登录,记住用户名密码功能。