当前位置:网站首页>Connor learns from JVM - the method of judging garbage collection
Connor learns from JVM - the method of judging garbage collection
2022-07-20 19:24:00 【ConnorYan】
Learn && Live
Wasted time duckweed in the world , Study hard and think hard until you die
Preface
Hey, Welcome to Connor learn JVM series , This series records my JVM Basic knowledge learning 、 The double check process , Welcome everyone to read axzheng ! Originality is not easy. , Reprint please indicate the source :http://t.csdn.cn/l2sBr, Without much to say, we'll start right away !
Judge the method of garbage collection
1. Reference counting algorithm
Add a reference counter to the object
(1) Whenever there's a place to quote it , Counter value + 1
(2) When the reference fails , Counter value - 1
(3) The counter at any time is 0 It is impossible to use the object of
Under special circumstances, a lot of extra processing is required to ensure correct work , For example, a single reference count is difficult to solve the problem of mutual reference between objects
2. Reachability analysis algorithm
Through a series of GC Roots The root object serves as the starting node set , Start with these nodes , Search down... Based on reference relationships , The path the search process takes is called a chain of references , If an object arrives at GC Roots There is no chain of references between , From GC Roots Not reachable to this object , It is proved that this object can no longer be used
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-hpzoIiot-1658108100814)(F:\yhy925\dailylife\Work\1.Java\JVM\Resources\3. Garbage collector \1. Accessibility analysis .png)]
Accessibility analysis and finalize()
But such objects are still in “ Probation ” Stage
(1) After the accessibility analysis, it is found that the object is not related to GC Roots The linked chain of references , Then it will be marked for the first time
(2) Make a screening , Depending on whether the object overrides finalize() Method or finalize() Method has been called by the virtual machine , To determine whether it needs to be implemented finalize()
- No need to execute , That is, the object is not covered finalize() Method or finalize() Method has been called by the virtual machine
- You need to perform , Place the object in F-Queue In line , And later, a virtual machine automatically establishes 、 Low scheduling priority Finalizer Execute in thread finalize() Method . The execution here only refers to calling the method , There is no guarantee of waiting for it to finish , in case finalize() Slow execution leads to system crash
(3) The collector will respond to F-Queue The objects in are marked a second time , If the object is to be finalize() To save yourself —— Re associate with any object on the reference chain , Such as the this Assign to a class variable or a member variable of an object , Then it will be removed on the second mark “ About to be recycled ” Set , Otherwise, it will still be recycled
but finalize() High operation cost , High uncertainty , The order in which the individual objects are invoked cannot be guaranteed , It is not recommended to use
Can be used as GC Roots The object of
(1) The object referenced in the local variable table of the stack frame , Such as method parameters 、 Local variables, etc
(2) In the method area, the class static Property reference object , Such as reference type static Variable
(3) Objects referenced by constants in the method area , Such as the reference in the string constant pool
(4) In the local method stack JNI Referenced object
(5)JVM Internal references , For example, the basic data type corresponds to Class object 、 system class loader 、 Some resident exception objects (NPE、OOM)
(6) All objects held by synchronous locks
边栏推荐
- MySQL数据库
- 标准C语言8 9
- stm32——RTC实时时钟
- Orthanc set up IP access
- [problem solving] uncaught typeerror: cannot read property 'addListener' of undefined when wechat developer tools introduce components
- C语言-C51编译警告“*** WARNING L1: UNRESOLVED EXTERNAL SYMBOL” 及extern
- STM32F103C8T6 操作矩阵键盘
- 桥接模式 和 享元模式 介绍
- 医疗PACS DICOM 存储 开源商业软件 Orthanc
- 百度贴吧爬虫获取网页
猜你喜欢
Build yourself an extremely simple but easy-to-use shame map station
Kyligence李栋:从数据湖到指标中台,提升数据分析ROI
JZ2440开发板-TFT LCD实验
易基因|ChIP-seq分析方法:实用的工作流程和高级应用
Avalonia—netcore 图片处理
MLX90640 红外热成像仪测温模块开发笔记(一)
Invalid values in MATLAB fill image
Stm32f103c8t6 operation matrix keyboard
The industry's first "best practice map of live video technology" was released!
WPF MVVM下 关闭窗体 并打开新窗体
随机推荐
WPF 自定义控件 实践
WPF 密码框 密码可见切换
Leetcode 115.不同的子序列
math.random()随机函数实例演示
JSON、
jlink 烧写可执行bin程序到mini2440
Connor学JVM - 判断垃圾回收的方法
通俗易懂:MOS管基本知识
【Codeforces1706A】 Another String Minimization Problem
lpad()函数和(row_number()over( order by )+ ...)
Query whether the port is occupied and closed
HTX00001_Keil51-串口解析遇到的Bug
tst、cmp、bne、beq指令
面试了一个37 岁的程序员 有一些感悟
WPF MVVM下 关闭窗体 并打开新窗体
好用的 代码统计工具
S3C2440 U-Boot移植--Norflash驱动支持- S29AL016U-Boot版本:2008.10 开发板:Mini2440
【CANN训练营】玩转CANN目标检测与识别一站式方案——学习笔记一(初体验)
"Error in enabling windows function netfx3" (error cause, detailed analysis and solution) and installation on windows server2012 occur during the installation of SQL Server 2012 NET Framework 3
MCU debugging - the use of event recorder