Java Magazine, March/April 2016
ORACLE COM JAVAMAGAZINE MARCH APRIL 2016 23 inside java Shenandoah compacts the data concurrently The sharpeyed among you will have noticed that this means it might need to move objects around while the application is trying to read them or write to them dont worry Ill come to that in a second As a consequence Shenandoah doesnt need to limit the number of regions it collects in order to minimize application pause times Instead it picks all the most fruitful regions that is regions that have very few live objects or conversely a lot of dead space The only steps that introduce pauses are those associated with certain bookkeeping tasks performed at the beginning and end of scanning The key dificulty with Shenandoahs concurrent copying is that the GC threads doing the copying work and the Java threads accessing the heap need to agree on an objects address This address might be stored in several places and the update to the address must appear to happen simultaneously Like most thorny problems in computer science the solution is to add a level of indirection Objects are allocated with extra space for an indirection pointer When the Java threads access the object they first read the indirection pointer to see whether the object has moved When the garbage collector moves an object it updates the indirection pointer to point to the new location New objects are allocated with an indirection pointer that points to themselves Only when an object is copied during GC will the indirection pointer point to somewhere else This indirection pointer is not free It has a cost in both space and time to read the pointer and find the current location of the object These costs are less than you might think Spacewise Shenandoah does not need the of heap data structures used to support partial collections like the card table and the into remembered sets Timewise there are various strategies to eliminate read barriers The optimizing JIT compiler can realize that the program is accessing an immutable field such as an array size Its correct in those cases to read either the old or the new copy of the object so no indirection read is required In addition if the Java program reads multiple fields from the same object the JIT may recognize this and remove the subsequent reads of the forwarding pointer If the Java program writes to an object that Shenandoah is copying a race condition occurs This is solved by having the Java threads cooperate with the GC threads If the Java threads are about to write to an object that has been targeted for copying the Java thread will first copy the object to its own allocation area check to see that it was the first to copy the object and then perform the write If the GC thread copied the object first then the Java thread can unwind its allocation and use the GC copy Shenandoah eliminates the need to pause during the copying of live objects thus providing much shorter pause times Conclusion If you are interested in the best end to end throughput you will probably want to use the parallel garbage collector that currently ships in the JDK If you want a good compromise between pause times and throughput the new G1 garbage collector will work well for you Shenandoah will be an attractive option for response time critical applications running with large more than 20 GB heaps such as financial trading ecommerce and other interactive applications in which the user would be irritated by noticeable GC delays article Christine H Flood is a principal software engineer for the Java platform at Red Hat where she works on Shenandoah learn more A 2014 presentation about Shenandoah by the author Oracle tutorial on garbage collection in the JVM
You must have JavaScript enabled to view digital editions.