Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is JVM's concept of GC collector

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

What is JVM's concept of GC collector? I believe many inexperienced people don't know what to do about it. Therefore, this article summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.

When java runs, the generated objects are stored in the heap. Some objects have a short life cycle and are useless after only a few lines of code have been run. After it is useless, he can not be left in the heap, to recycle, free up space for the object behind.

We often refer to cleaning the house as jvm cleaning the heap. Here, we not only have a house, we can also think bolder, a woman to be a wife, is the head of the family, in charge of the whole family. Soon, another big fat boy fell, the boy is independent, but also has his own small space. Then the knife will start cleaning and tidying up the house!

GC related Concepts STW (Stop the world)

In life, that is, I'm going to start cleaning. Don't move. Let me see what things women and boys are not in use and take up space outside. Of course, I dare not let them stop for too long. So when they stop, take a quick glance, write down the things they don't use on their hands, and then quickly let them continue to play.

In JVM, the application stops first, and then the GC worker thread scans it quickly to see which objects are still useful and which are useless

Safe point

There are actually two concepts, one is the safe point, the other is the safe zone. All describe the timing of STW. When STW occurs, the object reference relationship of the system will not change.

When I am about to stop the woman and the boy, if I yell, it is equivalent to pressing the timer and setting them all, then I find that the woman is still pouring water, which is not very good. I only unlock the lock of the woman and let her pour the water before stopping. This is a preemptive interruption in life, which is rare.

More of the scene is that their ears have been listening to me not to speak (polling status), and I yell stop. Then they quickly stop their work, either sit on the couch or lie in bed until they take the initiative to stop at the nearest safe point.

Safe zone: if the boy happens to be sleeping when I say stop (the thread is dormant, or blocked). Although I did not hear me say stop, but it is safe.

GCRoots

There is a saying that, to catch a thief and capture the king first, we must grasp the principal contradiction of things! When the things in the house are very messy, ask the woman and the boy what's going on. Take a look, boy, the woman is teaching the boy to read. Learn a word and find a corresponding object. At this time, Ben sweeps the floor as long as he takes a look at the small book and can find out what is needed and which is useless.

In JVM, there is a concept of root object, that is, what is related to them in the heap is to be used, and what is not related is recyclable. Let's classify memories like this.

First it is related to the class:

Class static objects referenced by class properties

Then there is the example-related:

Parameters, local variables, temporary variables used in the virtual stack

Objects referenced in JNI

And then at the JVM level:

An object referenced by a constant, such as a reference in a string constant pool.

All objects held by synchronized

References within the virtual machine, such as Class objects, memory-resident exception objects, system class loaders, etc.

RemberSet memory set

Throughout the current processing of a large amount of data, most of them are divided into different areas. It is impossible to check the whole area B in order to find some information in area A.

Such as Xiaodao, I work in Shanghai now, and the woman is in Chengdu. Then there will be a memory set in Shanghai, in which there is a citation relationship from so-and-so street in Chengdu (with different accuracy) to knife.

Well, one day when Shanghai needs statisticians, they come to find the knife. I said, where do I still have people in Chengdu? then the statisticians will check that area to see if I have lied. If there is indeed a citation relationship, well, there are still people who care about the knife, let him continue to work. If a check, found that there is no such quotation relationship, come on, no one wants a knife, can be locked in a small dark room ~!

After reading the above, have you mastered what JVM's GC collector concept is? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report