interviewer Let's talk today CMS Garbage collector ?

candidates : Yeah ...

candidates : If you use Seria and Parallel A series of garbage collectors : During garbage collection , All user threads stop completely , Until the garbage collection is over !

candidates :CMS Full name :Concurrent Mark Sweep, Which translates to 「 Concurrent tag removal 」

candidates : use CMS Compare the garbage collector above (Seria and Parallel and parNew): Its biggest difference is 「 Concurrent 」: stay GC When threads work , User threads 「 It won't stop completely 」, User thread in 「 In some scenes 」 And GC Threads execute concurrently .

candidates : however , To understand is , No matter what the garbage collector is ,Stop The World It must be inevitable !

candidates :CMS It's just 「 part 」 Of GC You can make GC Threads execute concurrently with user threads

candidates :CMS Our design goal is to avoid 「 Old age GC」 appear 「 Long-term 」 Carlton of (Stop The World)

interviewer Then you know CMS Your workflow ?

candidates : Only know a little , No more .

candidates :CMS It can be simply divided into 5 A step : Initial marker 、 Concurrent Tags 、 Concurrent pre cleanup 、 Retag and concurrent cleanup

candidates : It is not difficult to see from the steps ,CMS Mainly achieved 「 Mark clear 」 Garbage collection algorithm

interviewer : Um. ... Yes

candidates : I'm from 「 Initial marker 」 Let's get started

candidates :「 Initial marker 」 Will mark GCRoots「 Directly related 」 And 「 The younger generation 」 Point to 「 Old age 」 The object of

candidates :「 Initial marker 」 This process will happen Stop The World Of . But the speed of this stage is very fast , Because no 「 Back down 」( Mark only one layer )

candidates : stay 「 Initial marker 」 After that , It's in 「 Concurrent Tags 」 Stage

candidates :「 Concurrent Tags 」 This process does not stop the user thread ( Not going to happen Stop The World). This stage is mainly from GC Roots Down 「 trace 」, Mark all reachable objects .

candidates :「 Concurrent Tags 」 stay GC From the point of view , It's more time consuming ( Need to trace )

candidates :「 Concurrent Tags 」 After this stage is finished , That's it 「 Concurrent preprocessing 」 Stage

candidates :「 Concurrent preprocessing 」 What I want to do at this stage : Hope to reduce the next stage 「 Re label 」 The time it takes

candidates : Because the next stage 「 Re label 」 Is the need to Stop The World Of

interviewer : Um. ...

candidates :「 Concurrent Tags 」 At this stage, because the user thread is not suspended , So the object is likely to change

candidates : There may be some objects , From the new generation to the old age . There may be some objects , Directly allocated to the old age ( Big object ). Maybe the object references of the old or new generation have changed ...

interviewer So this question , How to solve it ?

candidates : For the elderly , In fact, you can still use classes card table The storage ( Mark the card page corresponding to the change of the old age object as dirty)

candidates : therefore 「 Concurrent preprocessing 」 This phase will be scanned, possibly due to 「 Concurrent Tags 」 The objects that cause changes in the elderly generation , It will be scanned again and marked as dirty Card page

interviewer : Um. ...

candidates : For the new generation of objects , We still have to traverse the Cenozoic to see where 「 Concurrent Tags 」 Is there any object in the process that references the old age ..

candidates : however JVM It provides us with a lot of 「 Parameters 」, It is possible to trigger once in this process minor GC( Triggered minor GC It means less traversal of the new generation of objects )

candidates :「 Concurrent preprocessing 」 At the end of this phase , That's it 「 Re label 」 Stage

candidates :「 Re label 」 Stage meeting Stop The World, The pause time of this process actually depends largely on the above 「 Concurrent preprocessing 」 Stage ( You can find , This is a catch-up process : While marking the living object , While the user thread is executing, it generates garbage )

candidates : The last is 「 Concurrent elimination 」 Stage , Can't Stop The World

candidates : While the user thread is executing , On one side GC The thread is reclaiming unreachable objects

candidates : This process , It is still possible that user threads are constantly generating garbage , But only for the next time GC processed , The waste produced is called “ Floating garbage ”

candidates : It will reset when it is finished CMS Algorithm related internal data , For the next time GC Prepare for the cycle

interviewer : Um. ,CMS The recycling process , I know the

interviewer Listen , In fact, it is the process of garbage collection to " To subdivide " 了 , Then, at some stage, the user thread can not be stopped , While recycling garbage , While processing the request , To reduce each garbage collection Stop The World Time for

interviewer : Of course! , A lot of optimization has also been done in the middle (dirty card Mark 、 May trigger... Halfway minor gc wait , In my understanding , These should all provide CMS Related parameter configuration of )

interviewer however , I think many enterprises are using G1 了 , Then you think CMS What are the disadvantages ?

candidates :1. Space needs to be reserved :CMS The garbage collector can collect garbage at the same time , While processing user threads , It is necessary to ensure that there is sufficient memory space for users in this process .

candidates : If CMS There is not enough space reserved during operation , Will report a mistake (Concurrent Mode Failure), This will start Serial Old The garbage collector carries out garbage collection in the old days , It will cause a long pause .

candidates : Obviously , How much space is reserved , There must be parameter configuration

candidates :2. Memory fragmentation problem :CMS In essence, it realizes 「 Tag clearing algorithm 」 The collector of ( From the process, we can see ), This would mean memory fragmentation

candidates : Because there are too many pieces , It may also be triggered by insufficient memory space full GC,CMS It usually triggers full GC This process defragments

candidates : Sorting involves 「 Move 」/「 Mark 」, Then this process will Stop The World Of , If memory is large enough ( It means that there may be enough objects loaded ), Then this process will take some time .

interviewer : Um. ...

candidates : Use CMS The disadvantage of is like a dead circle :

candidates :1. Too many memory fragments , Resulting in reduced space utilization .

candidates :2. Space itself needs to be reserved for user threads , Now fragmented memory exacerbates the problem of space , This may cause the garbage collector to be downgraded to Serial Old, Caton takes longer .

candidates :3. To deal with memory fragmentation ( Arrangement ), It will also get stuck

candidates : however , Technology implementation is a kind of trade-off( Balance ), You can't do everything perfectly

candidates : Understand the process , It's very interesting

interviewer : that G1 Garbage collector, do you know

candidates : Only know a little , No more

candidates : however , Save it for next time , Let you digest , Otherwise I'm afraid you can't hold it .

This paper summarizes

  • CMS The garbage collector is designed for : for fear of 「 Old age GC」 appear 「 Long-term 」 Carlton of (Stop The World)

  • CMS Garbage collector recycling process : Initial marker 、 Concurrent Tags 、 Concurrent preprocessing 、 Retag and concurrent cleanup . Initial marking and re marking will Stop The World

  • CMS The disadvantages of garbage collector : Memory fragmentation will occur && Space reservation is required : The pause time is unpredictable

Welcome to my WeChat official account. 【Java3y】 To have a chat Java interview , The online interviewer series is continuously updated !

【 On line interviewers - Mobile 】 series Two continuous updates a week !

【 On line interviewers - Computer terminal 】 series Two continuous updates a week !

Originality is not easy. !! Ask for three company !!

The steady ! I prepared 1 Last night CMS More articles on garbage collectors

  1. JVM Getting started with performance tuning

    1. background Although most applications use JVM The default settings will work well , There are still many applications to JVM Additional configuration is required to meet its expected performance requirements . Now? JVM In order to meet the needs of various applications , It provides a lot of... For program operation JVM ...

  2. JVM Parameter optimization ( The basic chapter )

    original text :https://www.howardliu.cn/java/jvm-tuning-basic/ These days, the pressure measurement pre production environment , Find out TPS All kinds of instability . Because it's a reconfigurable system , It is said that the original system has no problem when it is highly concurrent ...

  3. java Basic knowledge of + Frequently asked questions

    Prepare for the interview Java piece One . Java SE part 1.1 Java Basics 1. Please explain Object If not rewritten hashCode() Words ,hashCode() How to calculate ? Object Of hash ...

  4. Distracted intermediate Android Engineer job hopping experience sharing

    These experiences are my last four months , Sweat and tears from preparing for an interview to finding the right job , I hope it can help you ! define job-hopping What to think about before changing jobs How to do if the money is not in place How to deal with the grievance of the heart Thinking before leaving office Make sure you're ready to go How is the market ...

  5. Python Crawling CSDN Blog posts

    0 url :http://blog.csdn.net/youyou1543724847/article/details/52818339Redis A little basic catalogue of things 1. The underlying data structure 2.win ...

  6. [ job-hunting ] 2019 Autumn recruit | From spring to autumn ,Java Summary of post experience ( Harvest AT)

    from ( There are more ) https://blog.csdn.net/zj15527620802/article/month/2018/10 Preface Looking for a job is a hard and unforgettable journey . Experienced anxiety . wait for . hope , We are the most ...

  7. Ali Java Daquan of facial scriptures ( Integrated version )

    The content of Mianjing in this article is all from niuke.com , As a preparation for autumn recruitment, it is used when reviewing and checking deficiencies . Some of them have my comments and ideas , And part of the answer , Not necessarily right , You can inquire and supplement . Alibaba , On three sides ,java Internship Last night, 11 I'll call you at seven , ask ...

  8. Meituan internship Java Kong Mian Jing , Have to take offer

    author :icysnowgx link :https://www.nowcoder.com/discuss/71954?type=2&order=3&pos=10&page=1 source : cattle ...

  9. A summary of 20000 words , carding Java The things about entry and advancement

    Hello everyone , I'm a programmer, Xiao Yue , One has written in the workplace 6 I'm an old programmer of computer programs , From the beginning of chrysanthemum factory Android Developed by a game company Java Back end architecture , Yes Java I know a lot about it . About half a year ago , There is a close friend in Zhihu ...

  10. C/C++ Pen test

    ///// from http://blog.csdn.net/suxinpingtao51/article/details/8015147#userconsent# Microsoft Asia Technology Center interview questions !!! 1. process ...

Random recommendation

  1. Android Lieutenant general xml The layout file is converted to View Process analysis of tree ( Next )-- LayoutInflater Source code analysis

    stay Android In order to inflate A layout file , It's about 2 Ways of planting , As shown below : // 1. get a instance of LayoutInflater, then do whatever yo ...

  2. Norton ghost Backup recovery system or partition

    One Norton ghost brief introduction 1, You can clone partitions You can also clone disks 2, Cloned into img Or disk content 3, Disk partition --img--- Disk partition disk --- disk   Two Operation steps For the system that's carved The whole idea : 1,A Is a template ...

  3. shared pool Detailed explanation

    Shared pool shared pool The concept of user submitted commands : analysis . The process of executing the parsing of user commands is quite complex , It should consider various possible exceptions, such as SQL The object involved in the statement does not exist . The submitted user does not have permission and so on, but also needs to test ...

  4. window.history.go(-1) Go back and refresh the page

    windows Window object ( history )history.go(),history.back(),history.forward(). because windows Object references are not required . therefore windows.history.g ...

  5. Use certificates to create request request

    The program I wrote before , It's all ordinary http request. This is the first time to use , Record . private static X509Certificate2 GetCert(string certId,StoreLo ...

  6. RabbitMQ Open the service but can't log in

    I changed my computer name when I was bored , I found out later that my rabbitmq The service cannot be turned on , Later, I changed the computer name back, but I still can't , I read a lot of tutorials from the Internet, but they didn't succeed , Later I saw this method , The source forgot , sorry , Send it out and remember package ...

  7. jQuery Basic grammar knowledge

    One .attr() attr() Method to set or return the properties of an element . attr( Property name ): Get the value of the element attribute name . attr( Property name , Property value ): Set the value of the element property name . Example : <a href=”http://12 ...

  8. DNS Summary of agreement

    1.DNS Used to return... According to the domain name ip Address . 2. In general ,DNS-server It is through UDP The interaction between the protocol and the client ,UDP The port number is 53. Particular attention .DNS Sometimes I use TCP 53 The port interacts with the client , therefore , ...

  9. asp Compress and decompress files online ( Folder )

    <%'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'\\'\\ 1. c:\windows\system32\cmd.e ...

  10. tensorflow note 6:tf.nn.dynamic_rnn and bidirectional_dynamic_rnn: Output ,output and state, And how to do it decoder The input of

    One .tf.nn.dynamic_rnn : Function usage and output Official website :https://www.tensorflow.org/api_docs/python/tf/nn/dynamic_rnn Instructions : A ...