Root node enumeration

1. The root node is also called (GC Roots). Up to now, all collectors have had to pause The user thread when enumerating at The root node, thus causing The user thread to “Stop The Word” for a short time.

2. Mainstream Java virtual machines use precise garbage collection, which does not require the JVM to check all execution contexts and global reference locations when the user thread pauses. Instead, a set of data structures called Oop (Ordinary Object Pointer) maps are used for fast scanning.

Safe Point

1, due to the HotSpot is not generated for each instruction OopMap, so you need to in the “specific location” record these important information, and the position is what we usually call security, security point, determine the user program executes the instruction stream any position in the code is not able to pauses to garbage collection, Instead, it mandates that execution must reach a safe point before it can be paused.

2. In order to make all threads run to the nearest safe point when garbage collection occurs, there are currently two methods: a. Tackling type interrupt The interrupt mode does not require threads execute code initiative to cooperate, in garbage collection occurs, the system first to interrupt all user threads, if it is found that the user thread interrupt place not on the safety point, restore the thread execution, let him break again after a while, until run to a safe point (in this way there is basic no virtual machine b. In this mode, when garbage collection needs to interrupt the thread, it does not operate directly on the thread, but simply sets a flag bit. During the execution of each thread, it will actively train this flag. Once the interrupt flag is found to be true, it will actively interrupt and suspend the thread at the nearest safe point.

The safety area

Concept: safety program mainly for the “no”, didn’t get the processor allocation of time, lead to can’t go to a safe point and set a regional security area refers to guarantee in a code fragment, citing relationship will not change, therefore, any place in this area began to garbage collection is safe, A safety zone can be viewed as a point of safety that has been stretched

Concurrency accessibility analysis

The purpose of concurrent reachability analysis is to solve or reduce pauses in user threads. Tricolor marking

White: indicates that the object has not been accessed by the garbage collector. Obviously, at the beginning of the reachability analysis, all objects are white. If at the end of the analysis, all objects are still white, that is, they are unreachable

Black: Indicates that the object has been accessed by the garbage collector and that all references to the object have been recently scanned. The black object indicates that it has been scanned, and it is safe to survive. If there is another object reference pointing to the black object, there is no need to scan again. The black object cannot point directly to a white object

Gray: Indicates that the object has been accessed by the garbage collector, but at least one reference to the object has not been scanned