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 are the four GC algorithms of JVM?

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

Share

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

This article is to share with you what the four GC algorithms of JVM are, the editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.

In the process of running the program, it will produce a lot of memory garbage (some memory objects that do not have a reference point to belong to memory garbage, because these objects can no longer be accessed, the program can not use them, and they have died for the program). In order to ensure the performance of the program, the java virtual machine continues to carry out automatic garbage collection (GC) while the program is running.

Dark Horse programmer combines theory with practice to decrypt jvm: http://yun.itheima.com/course/584.html?1912zzp

There are four main GC algorithms about JVM: 1. Citation counting algorithm (Reference counting)

When each object is created, a counter is bound to the object. Whenever there is a reference to the object, the counter is incremented by one; whenever a reference to it is deleted, the counter is minus one. In this way, when no reference points to the object, the object dies and the counter is 0, and the object should be garbage collected. 2. Mark-clear algorithm (Mark-Sweep)

Stores a tag bit for each object to record the state of the object (alive or dead).

It is divided into two stages, one is the marking phase, in which the tag bits are updated for each object to check whether the object is dead; the second stage is the cleanup phase, which clears the dead objects and performs GC operations. 3. Marking-finishing algorithm

The mark-finishing method is an improved version of the mark-removal method. Similarly, in the marking phase, the algorithm marks all objects as alive and dead; the difference is that in the second stage, the algorithm does not directly clean up the dead objects, but organizes all the living objects. put it in another space, and then clear all the remaining objects. In this way, the purpose of marking-finishing is achieved. 4. Replication algorithm

The algorithm divides the memory into two parts on average, and then uses only one part of the memory at a time. When this part of the memory is full, all the living objects in the memory are copied to another memory, and then the previous memory is emptied, using only this part of the memory. Loop.

The difference between this algorithm and the tag-collation algorithm is that instead of replicating in the same area, all living objects are copied to another region. 5. Different versions of JVM have different garbage collection mechanisms, and there is a difference between the new and old versions of jdk1.7 and 1.8.

Jdk1.7 and 1.8 older versions of Parallel Old, (old years)

Jdk1.7 and new version 1.8Parallel Scavenge, (Cenozoic)

Parallel Old collector

The older version of the Parallel Scavenge collector uses multithreading and mark-up algorithms. This collector was not available in jdk1.6 until the emergence of the Parallel Old collector, the "throughput first" collector finally has a more veritable application combination, in the case of throughput and CPU resource sensitivity, Parallel Scavenge plus Parallel Old collector can be given priority.

Parallel Scavenge collector

Parallel Scavenge collector is a new generation of hand machine, which uses the collector of replication algorithm, and it is also a multithreaded collector. Parallel Scavenge collector, which aims to achieve a controllable throughput, uses the-XX:MaxGCPauseMillus parameter to control the garbage pause time, and uses the-XX:GCTimeRatio parameter to control the throughput. The Parallel Scavenge collector sets the-XX:UseAdaptiveSizePolicy parameter, and the virtual machine collects performance monitoring information based on the current system performance, and dynamically adjusts these parameters to provide the most appropriate pause time or maximum throughput (the tuning policy used by GC).

Adaptive adjustment strategy is also an important difference between Parallel Scavenge collector and ParNew collector.

These are the four GC algorithms of JVM. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

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

Development

Wechat

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

12
Report