Home Java javaTutorial Hotspot--garbage collector (JVM) explained in detail

Hotspot--garbage collector (JVM) explained in detail

Jul 17, 2017 am 11:51 AM
hotspot Recycle Rubbish

The first two articles "Introduction to JVM - Runtime Data Area" and "JVM Common Garbage Collection Algorithms" mentioned the actual JVM specifications and commonly used garbage collection algorithms, specificallyJVMThere is actually more than one implementation, there are JRockit, J9 waiting, of course The most famous one is HotSpot JVM. The following is the overall architecture diagram of HotSpot JVM. This article focuses on the garbage collector (Garbage in HotSpot Collector).

The existing HotSpot garbage collectors and their relationships and application scope are as shown below Shown:

Among them, G1 GC is very conspicuously located between the new generation and the old generation. , it can be guessed that this G1 GC can be used in both the new generation and the old generation. It can indeed be said that G1 is an epoch-making new conceptGC.

Before introducing the above garbage collector, we must first explain the JVM virtual machine’s Client mode and Server mode, JavaThe first thing that can be done is to be a client. Simply speaking, it isGUIDesktop application, second, can be used as server side. Two modes: Client mode starts quickly and has poor performance after startup; Server mode starts slowly and has higher performance after startup.

Serial GC(-XX:+UseSerialGC, copy algorithm, new generation)

## This is a relatively old garbage collector, I understand it as

Simple and crude, simple and crude methods can often deal with simple environments. In fact, Serial GCThis is exactly the case in Client mode. It is a serial garbage collector. Serial means that even a multi-core processor will not have multiple threads to collect in parallel. While serial, other normal working threads must also stop working, which is called “Stop the world”. This is actually easy to understand. When you are cleaning the garbage, you don’t want someone to throw away garbage at the same time. Of course, Serial GC is almost in today’s HotSpot JVMServer mode. Abandoned. Also, it works using garbage collection's "copy algorithm"works inJavaThe new generation of the heap.

ParNew GC-XX:+Use ParNewGC, Copy algorithm,New generation

 ParNew GC is actually a multi-threaded version of Serial GC. As mentioned above, Serial GC even in a multi-core CPU environment uses a single thread to recycle garbage memory. This garbage collector side can recycle garbage memory in a multi-threaded environment. This multi-thread is only a multi-thread of garbage collection, rather than executing concurrently with user threads. And only it can be used with the old generation garbage collector of CMS, and CMS is exactly the epoch-making garbage collector. , so when the old generation garbage collector of JVM is CMS, the new generation garbage collector is usually ParNew GC.

Parallel GC-XX:+UseParallelGC, replication algorithm, new generation)

It is somewhat similar to ParaNew GC. Judging from the name, it is also a parallel multi-threaded collector. We have mentioned before that during the process of GC#"Stop the world", the shorter the pause time, the better. , many garbage collectors (including the first two) focus on how to improve the pause time. And Parallel GC focuses on throughput. It focuses on the overall time-consuming of garbage collection. If the overall time-consuming of garbage collection is shorter, the throughput is high, and CPU can spend more time on it. The execution of the task ,(throughput = task running time / (task running time + Garbage collection time)).

Serial Old GC-XX:+UseSerialOldGC, tag -Compression algorithm, old generation)

It is the old generation version of Serial GC. It is also single-threaded and can also be used with Parallel GC is used in conjunction with its old generation GC.

Parallel Old GC-XX+UseParallelOldGC, tags -Compression algorithm, old generation)

In order to avoid the dilemma of choosing Parallel GC in the new generation and only choosing Serial Old GC in the old generation, ## appeared The old version of #Parallel GC——Parallel Old GC. Therefore, if you use the combination of Parallel GC and Parallel Old GC for some constants that require high throughput, it will be a good choice. .

##☆Concurrent Mark Sweep(CMS) GC -XX:+UseConcMarkSweepGC, mark-Clear algorithm, old generation) CMS GC

almost occupies

JVMHalf of the old generation garbage collector, its epoch-making significance is that the garbage collection thread can almost work at the same time as the user thread. "Almost"It's because it still can't be done at all."Stop the world", but it shortens the pause time as much as possible. Its entire garbage collection process can be divided into the following

4

steps:

    Initial mark
  1. Concurrent Marking
  2. Remarking
  3. Concurrent Cleanup
  4.  These
4

steps"Initial mark"andRemarkRequires a short period of time“Stop the world”, the process of concurrent marking is actually The above is to work with the user thread at the same time, that is"throwing away garbage and cleaning at the same time", this will cause a problem , if the generation of garbage occurs after marking, then the garbage will have to wait until next time for recycling. Of course, after the marking is completed, the garbage will naturally not conflict with the user thread, and the cleaning process can be processed at the same time as the user thread. One of the more obvious and unavoidable problems with this garbage collector is that it uses "mark-clearance algorithm, that is to say, it will compress the surviving objects differently, which will bring about the problem of memory space fragmentation. If there is a need to allocate a continuous larger memory space, then Can only trigger Full GC once. In the previous article "Common Garbage Collection Algorithms for JVM", it was mentioned that the garbage collection in the new generation is called "Minor GC" , and the garbage collection in the old generation is called "Major GC", and "Full GC" triggers a garbage collection on the entire heap. It can be imagined that the cost will be quite high, and At this time, the user thread has to be suspended, and it can only be adjusted and optimized according to the specific usage scenario by adjusting the parameters of CMS GC.

##☆

Garbage-First(G1) GC (-XX:+UseG1GC)

G1 GC is different from all previous garbage collectors. As can be seen from the second picture at the beginning, it covers the new generation and the old generation, or it is just logically Keep "New Generation" and "Old GenerationIn fact, memory generation no longer exists. It is only an experimental version in JDK6. In JDK7u4 will not be officially commercialized until later. I will explain this garbage collector separately. In addition, its paper address is: http://citeseerx.ist.psu.edu/ viewdoc/download?doi=10.1.1.63.6386&rep=rep1&type=pdf.

The above is the detailed content of Hotspot--garbage collector (JVM) explained in detail. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
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

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 ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to set up win7 as a wifi hotspot How to set up win7 as a wifi hotspot Dec 31, 2023 pm 10:14 PM

The win7 system is a high-performance system recognized by users. Recently, many Win7 friends are asking how to make a wifi hotspot in Win7? Today, the editor will bring you how to open and set up the win7 Wifi hotspot. Let’s take a look. How to set up wifi hotspot in win7: 1. To turn on wifi hotspot, you must first have a wireless network card. The laptop comes with it. If you have a PC, you can buy a portable wifi to share wifi, which will not be described here; first press the keyboard Press the Windows key on the computer to open the "Start Menu", enter "cmd" in the search bar below it and click the magnifying glass icon to search; 2. After finding the CMD program in the search results, right-click to open the menu and select "

Step-by-step tutorial on how to clean up system junk in Windows 10 Step-by-step tutorial on how to clean up system junk in Windows 10 Jul 13, 2023 pm 09:53 PM

When some users use computers, Win10 system cleans up junk. When encountering Win10 system cleaning up junk, how should we solve it? Nowadays, there are still many users who don’t know how to deal with the situation of cleaning up garbage in Win10 system, so let’s take a look at the step-by-step tutorial on cleaning up system junk in Win10. Let’s take a look. 1. On the computer desktop, click "This PC" and manage. 2. Select Disk Management 3. Select the disk you want to clean, right-click and select Properties. 4. Click the "Disk Cleanup" button at the bottom of the page. 5. In the interface that appears, select the files you want to clean, click "OK", and click "Delete Files". The above is a step-by-step tutorial on how to clean up system junk in Windows 10. I hope

How to clean up junk files in win10. Teach you how to clean up and repair junk files. How to clean up junk files in win10. Teach you how to clean up and repair junk files. Jan 12, 2024 am 08:18 AM

As the computer is used for a long time, there are more and more junk files in the C drive. The existence of junk files will affect the running speed of the system to a certain extent, so the computer will feel slower and slower. In order to make the computer run smoothly, it is not necessary to It affects the normal operation. Below, the editor will show you how to clean up the garbage in Win10. Win10 is a new system. Many users have already installed the official version of Win10. However, recently many friends have reported that after installing Win10, the system disk has become too crowded, causing the system to run slower and slower. So how to clean up Win10 What about system garbage? Below, the editor will share with you how to completely clean up your win10 system. How to clean up junk on Windows 10 desktop

Teach you in detail how to clean up junk files on D drive in win11 Teach you in detail how to clean up junk files on D drive in win11 Jan 05, 2024 pm 11:53 PM

Every user basically has his own D drive for downloading software, but in the latest win11 system, many still don’t know how to clean up the garbage in it, so today I will bring you a detailed tutorial on how to clean up the D drive garbage in Win11. , come and learn how to operate it together. How to clean up D drive junk in win11: 1. First enter This Computer on the desktop, and then right-click on your D drive. 2. Then click "Properties" settings in the menu. 3. Afterwards you can see the "Disk Cleanup" function under General Tools. 4. Finally, click "Clean System Files" that appears to solve all problems.

How to ensure that the normal operation of the system is not affected when cleaning the C drive garbage in win7 How to ensure that the normal operation of the system is not affected when cleaning the C drive garbage in win7 Dec 28, 2023 am 09:54 AM

C drive usually contains some important files of our computer. If accidentally deleted, it will directly affect the use of our computer. So under win7 system, how to clean up the garbage on C drive so as not to delete system files by mistake? Woolen cloth? Let’s take a look together now. How to clean up C drive junk in win7 without affecting the system 1. Double-click the computer icon to enter the resource manager. 2. Right-click the C drive and select Properties 3. Click General and click Disk Cleanup. 4. Check the files that need to be cleaned and click OK.

Rookie's green recycling activity has been upgraded, and you can receive 0.1 yuan in recycling money each time Rookie's green recycling activity has been upgraded, and you can receive 0.1 yuan in recycling money each time Oct 31, 2023 pm 06:29 PM

This website reported on October 31 that Cainiao will upgrade its green recycling during Double 11 this year. In addition to the express packaging recycling that has been carried out in previous years, clothing, shoes, used books and other categories can be recycled. On the basis of returning to the box to exchange eggs in the previous two years, rookies have upgraded to participate in activities to receive recycling funds. From November 1st to 20th, consumers can receive recycling money by leaving the express packaging after picking up the package at Cainiao Station, and then scanning the code on site or promising to return the box in the Cainiao App, or making an appointment online to recycle used clothes, etc. . The recycled express packaging will be used for secondary shipping or recycling. This site noticed that recycling gold activities are divided into three types: return boxes, recycling and sharing. Return boxes (express cartons): 0.1 yuan/time, with a maximum return limit of 4 times per user per day. Price for recycling (old clothes and other items)

Detailed explanation of Java garbage collection mechanism and detailed explanation of performance optimization. Detailed explanation of Java garbage collection mechanism and detailed explanation of performance optimization. Feb 19, 2024 pm 07:40 PM

Java's garbage collection mechanism is a key function of the JVM's automatic memory management. Below are detailed instructions on Java garbage collection and performance optimization. Garbage collection mechanism: Life cycle of objects: In Java, when objects are created, they are allocated in heap memory. Objects become unreachable when they are no longer referenced. The garbage collection mechanism is responsible for identifying and cleaning up these unreachable objects to reclaim memory space. Garbage collection algorithm: Java's garbage collection algorithm is mainly divided into two types: mark-sweep algorithm and copy algorithm. The mark-sweep algorithm marks and cleans unreachable objects, but may cause memory fragmentation. The copy algorithm divides the memory into two areas. When one area is full, the surviving objects are copied to the other area and the original area is cleared.

How to clean up C drive junk How to clean up C drive junk Jan 12, 2024 pm 05:07 PM

Methods to clean up C drive junk: 1. Turn off the hibernation function; 2. Clean up temporary files; 3. Transfer software to other disks; 4. Uninstall unnecessary applications; 5. Clean up temporary Internet files; 6. Change the desktop storage location; 7. Use disk cleaning tools; 8. Back up important data regularly. Detailed introduction: 1. Turn off the hibernation function. The hibernation function will save the data in the memory to the hard disk, occupying a lot of space. You can turn off the hibernation function to free up space; 2. Clean up temporary files. Temporary files are also a factor that takes up space on the C drive. etc.

See all articles