JAVA Stop the World section eighth
Small partners remember the last one of the questions we left? What is a pause type! After a few chapters of learning, we know that garbage collection is first marked. After the object is marked, different collection methods are used depending on the region. The one thing that looks perfect is actually not.
Have you ever thought about one thing, when the virtual machine finishes two tokens, it confirms the objects that can be recycled . However, garbage collection does not block the thread of our program, which is executed concurrently with the current program . So the problem here is that when a GC thread marks an object, the thread of our program then re-joins the object in the "network" , and when the two tokens are executed, the object does not rewrite the Finalize () method. As a result, the object that should not be recycled is recycled.
The solution to a virtual machine is to set some "security points" at certain command locations, and when the program runs to these "safe points" it pauses all currently running threads (Stop the world is called STW), pauses and then finds the "GC Roots" to build the relationship, In turn, flag and purge are performed.
These specific command locations are mainly:
1, the end of the loop
2. Method Pro returns the call instruction of the method before/
3, may throw the abnormal position
It also takes a long time to find "GC Roots", but there is a new solution here, which is to record the surviving "GC Roots" in the system by using a oopmap data structure, and when the class loading is complete, The virtual machine calculates what type of data in the object's offset is stored in oopmap, and by interpreting Oopmap, you can find the objects in the heap, which are GC Roots. Instead of needing a single one to determine if the value of a memory location is a reference. This method is also called accurate GC.
Back to the beginning of the question, the type of pause is just the STW, as for GC and full GC, and full GC (System). Personally, it is considered that the time of STW is mostly full GC, which is a long time relative to GC because the full GC is for the whole heap and for the permanent generation, so the whole range of GC is greatly increased, and his recovery algorithm is the "mark-clear-tidy" that we said earlier, and it will take some time. So when we optimize the JVM, the number of full GC reductions is also a common approach.
This article is short, for the next chapter to tell the collector to lay the cornerstone, you just know the GC before there is STW this step and know the existence of oopmap and security points.
JAVA Stop the World section eighth