“This is the 26th day of my participation in the August More Text Challenge.

🔉 introduction

Today came back early, the mood is also good, WHEN I am happy, I hope to be happy with you, WHEN I am sad, I do not want you to be sad, because I will not tell you 🙀, less gossip, start today’s topic.

🌲 Shenandoah collector

❤️ Workflow

Today, we will talk about its workflow. The content is from Shenandoah’s paper in 2016. The workflow can be roughly divided into 9 stages:

  • Initial flag (initial Marking)
  • Concurrent token (Concurrent Marking)
  • Final mark (Final Marking)
  • Concurrent cleanup (Concurrent Cleanup)
  • Concurrent collection (Concurrent Evacation)
  • Initial reference update (initial Update Reference
  • Concurrent reference update (Concurrent Update Reference)
  • Final reference update (Final Update Reference)
  • Concurrent cleanup (Concurrent Cleanup)

MyGOd, so many, how to do? The Shenandoah collector is not the G1’s successor, so it must be the same. Wait, can I say I haven’t learned the G1 yet? Well, why don’t you start memorizing G1? Ah, the first three stages are the same ah, then briefly talk about it.

🌟 Initial tag

Initial tagging mainly marks objects that can be directly associated with GCRoots. This phase takes a short time and requires the thread to pause. The pause time is not related to the heap size but to the number of GCRoots.

🌟 Concurrent markup

Starting from GCRoots, the reachability analysis of objects in the heap is performed and the live objects are marked. This phase is time-consuming and can be performed concurrently with user threads, depending on the number of live objects in the heap and the complexity of the object graph.

🌟 Final tag

A simple pause is performed on the user thread to process the small number of SATB records that remain after the end of the concurrent phase. The Region with the highest Collection value is counted and the multiple regions are combined into a Collection Set.

🌟 Concurrent Cleanup

In this phase, the first step is to kill a Region that has no living objects. Hurry up and make room.

🌟 Concurrent reclamation

And then, what do we do? Well, there is no object of survival of the Region make finished, the next object should be live bai, hey hey, not a back in front of the collection, for you, the first set of live objects inside the memory, a copy of the unused in the Region, it is not moving objects, move this thing, if it is suspended user thread that is simpler, I looked at whether concurrent, unexpectedly is concurrent I breath in a gasp, concurrent words is bad, because mobile is a one-time process, after moving, reference address will change, this time to object access will be: more troublesome, and one-time reference address update also is very difficult.

So how does Shenandoah play? It relies on a read barrier and Brooks Pointers for forwarding. For forwarding Pointers, click not to list, but since you’re dealing with a back collection, the length of time depends on the size of the back collection.

🌟 Initial reference updated

Reference update is done at this stage, but this stage is just an initialization stage, it does not do any specific processing, just to set up a thread collection point, to make sure that all concurrent collection threads have completed their tasks, what task? It is the task assigned by the object (this object, not that object oh 😜), the initial reference update time is very short, also produces a very short pause.

🌟 Concurrent reference update

This stage is the real working stage. Concurrent with the user thread is the work of modifying the value, so the length of time depends on the number of references. Different from concurrent marking, there is no need to search according to the object graph, but only need to search the reference type linearly according to the order of the physical address of memory, and then change the value.

🌟 final reference update

The heap reference update is done, but the GCRoots reference is not done yet, so the pause time is related to the number of GCRoots, and this is Shenandoah’s last pause.

🌟 Concurrent Cleanup

After all the preparation work is done, we can ensure that there are no living objects in the collected Region. Then we can reclaim the Region for future allocation of new objects.

Combined with the picture will be better, the picture is as follows:

📝 digression

There are those who feel the meaninglessness of human desires and purposes, while nature and the world of thought reveal sublime and wondrous order. His personal existence felt like a prison to him, and he wanted to experience the universe as a unified and meaningful whole. This cosmic religious sentiment was already evident in the early stages of human development, in the psalms of David and in the prophets. There is a stronger element of this cosmic religious sentiment in Buddhism, which can be felt in Schopenhauer’s wonderful writings.

Tell me out loud: Do you know Schopenhauer?