search
HomeJavajavaTutorialJVM Advanced Features-3. Garbage Collection Determining Object Survival Algorithm
JVM Advanced Features-3. Garbage Collection Determining Object Survival AlgorithmJun 26, 2017 am 11:34 AM
judgmentRubbishcollectcharacteristicadvanced

1. Overview

In the runtime data area, the program counter, virtual machine stack, and local method stack are all created and destroyed with the thread. ’s

Therefore, their memory allocation and recycling is deterministic, and they are recycled when the method or thread ends. The Java heap and method area are uncertain. The size of the objects created during the running of the program is uncertain. The size of the required memory can only be known when the program is running.

2. "Survival Algorithm"

To determine whether an object is alive, there are two main algorithms: reference counting Method and reachability analysis algorithm

Reference counting method
  • Reference counting method is to add a reference to the object Counter, every time the object is referenced once, the counter value is incremented by 1, and the reference expiry is decremented by 1. If the counter is 0, it means it will not be used again.

reachability analysis algorithm

  • The reachability analysis algorithm is a mainstream implementation , this algorithm uses the node that becomes GC ROOT as the root node, Searches downward from the root node, if there is no reference chain connecting the object to GC ROOT (that is, it is unreachable), it means that

  • The object is not available

The objects that can be used as GC ROOT are:

  • ##Virtual machine stack The reference object in the local variable table


  • The class static property reference in the method is exclusive
    • The transparent object in the method
    • Reference object in local method

    • At present, the reachability analysis algorithm has become the mainstream algorithm. The reason is that the reference counter algorithm cannot solve the problem of

      objects referencing each other

    reachability Analysis and Judgment Process

    •  After conducting the reachability analysis on the object, it is found that it does not have any reference chain connected to it, so it is marked for the first time. And perform a screening,

      The filtering condition is whether the finalize() method needs to be executed. When the object does not cover the finalize method or the finalize method has been called,
    It is considered that there is no need to execute it. If If it is judged that it is necessary to execute, it will be put into a queue called F-Queue. Later, JVM

    will automatically create a low-priority finalizer thread to execute the finalize method of these objects, and then GC will The object

    in F-QUEUE will be marked for the second time. If the object cannot escape at this time, it will be recycled.

    finalize() method

    • ## 

      The finalize method is mentioned many times above, please pay attention to it , the object's finalize method will only be automatically called once by the system. It is not recommended that you use this method. Its function can be completed with try-finally instead

        

    The above is the detailed content of JVM Advanced Features-3. Garbage Collection Determining Object Survival Algorithm. For more information, please follow other related articles on the PHP Chinese website!

    Statement
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
    PHP邮件检测:判断邮件是否已发送成功。PHP邮件检测:判断邮件是否已发送成功。Sep 19, 2023 am 09:16 AM

    PHP邮件检测:判断邮件是否已发送成功。在开发Web应用程序时,经常需要发送电子邮件来与用户进行沟通,无论是注册确认、密码重置还是发送通知,邮件功能都是不可或缺的一部分。但是,有时候我们无法确保邮件是否真正发送成功,因此我们需要进行邮件检测以及判断邮件是否已成功发送。本文将介绍如何使用PHP来实现这个功能。一、使用SMTP服务器发送邮件首先,我们需要使用SM

    使用java的File.isDirectory()函数判断文件是否存在且为目录类型使用java的File.isDirectory()函数判断文件是否存在且为目录类型Jul 24, 2023 pm 06:57 PM

    使用java的File.isDirectory()函数判断文件是否存在且为目录类型在Java编程中,经常会遇到需要判断一个文件是否存在且为目录类型的情况。Java提供了File类来操作文件和目录,其中的isDirectory()函数可以帮助我们判断一个文件是否是目录类型。File.isDirectory()函数是File类中的一个方法,其作用是判断当前Fil

    使用java的Character.isDigit()函数判断字符是否为数字使用java的Character.isDigit()函数判断字符是否为数字Jul 27, 2023 am 09:32 AM

    使用Java的Character.isDigit()函数判断字符是否为数字字符在计算机内部以ASCII码的形式表示,每个字符都有一个对应的ASCII码。其中,数字字符0到9分别对应的ASCII码值为48到57。要判断一个字符是否为数字,可以使用Java中的Character类提供的isDigit()方法进行判断。isDigit()方法是Character类的

    如何使用Double类的isInfinite()方法判断一个数是否为无穷大如何使用Double类的isInfinite()方法判断一个数是否为无穷大Jul 24, 2023 am 10:10 AM

    如何使用Double类的isInfinite()方法判断一个数是否为无穷大在Java中,Double类是用来表示浮点数的包装类。该类提供了一系列方法,可以方便地对浮点数进行操作。其中,isInfinite()方法就是用来判断一个浮点数是否为无穷大的方法。无穷大是指大到超出了浮点数所能表示的范围的正无穷和负无穷。在计算机中,浮点数的最大值可以通过Double类

    jQuery使用实践:判断变量是否为空的几种方式jQuery使用实践:判断变量是否为空的几种方式Feb 27, 2024 pm 04:12 PM

    jQuery是一个广泛应用于Web开发中的JavaScript库,它提供了许多简洁方便的方法来操作网页元素和处理事件。在实际开发中,经常会遇到需要判断变量是否为空的情况。本文将介绍使用jQuery判断变量是否为空的几种常用方法,并附上具体的代码示例。方法一:使用if语句判断varstr="";if(str){co

    Go语言中如何判断日期是否为前一天?Go语言中如何判断日期是否为前一天?Mar 24, 2024 am 10:09 AM

    题目:Go语言中如何判断日期是否为前一天?在日常开发中,经常会遇到需要判断日期是否为前一天的情况。在Go语言中,我们可以通过时间计算来实现这个功能。下面将结合具体的代码示例来演示如何在Go语言中判断日期是否为前一天。首先,我们需要导入Go语言中的时间包,代码如下:import("time")接着,我们定义一个函数IsYest

    PHP中如何判断字段是否为空?PHP中如何判断字段是否为空?Mar 20, 2024 pm 03:09 PM

    PHP是一种广泛应用于网站开发的脚本语言,对于开发者们来说,常常需要判断字段是否为空。在PHP中,判断字段是否为空可以通过一些简单的方法来实现。本文将介绍在PHP中如何判断字段是否为空,并提供具体的代码示例供大家参考。在PHP中,通常可以使用empty()函数或者isset()函数来判断字段是否为空。接下来我们分别介绍这两个函数的用法。使用empty()函数

    PHP 判断字符串中文和数字的简单实现PHP 判断字符串中文和数字的简单实现Mar 08, 2024 am 09:18 AM

    PHP是一种被广泛应用的服务器端脚本语言,具有灵活、强大和易学的特点。在使用PHP进行字符串处理的过程中,判断字符串中是否包含中文和数字是一种常见需求。本文将介绍如何在PHP中实现简单的判断字符串中是否包含中文和数字的功能,并附带具体的代码示例。首先,我们来看一下如何判断一个字符串中是否包含中文。中文在字符编码中的范围是:[x{4e00}-x{9fa5}]。

    See all articles

    Hot AI Tools

    Undresser.AI Undress

    Undresser.AI Undress

    AI-powered app for creating realistic nude photos

    AI Clothes Remover

    AI Clothes Remover

    Online AI tool for removing clothes from photos.

    Undress AI Tool

    Undress AI Tool

    Undress images for free

    Clothoff.io

    Clothoff.io

    AI clothes remover

    AI Hentai Generator

    AI Hentai Generator

    Generate AI Hentai for free.

    Hot Article

    R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
    2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
    Repo: How To Revive Teammates
    4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
    Hello Kitty Island Adventure: How To Get Giant Seeds
    3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

    Hot Tools

    SublimeText3 Mac version

    SublimeText3 Mac version

    God-level code editing software (SublimeText3)

    SublimeText3 Linux new version

    SublimeText3 Linux new version

    SublimeText3 Linux latest version

    SecLists

    SecLists

    SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

    WebStorm Mac version

    WebStorm Mac version

    Useful JavaScript development tools

    SublimeText3 English version

    SublimeText3 English version

    Recommended: Win version, supports code prompts!