{"id":2747,"date":"2011-11-03T18:44:26","date_gmt":"2011-11-03T13:44:26","guid":{"rendered":"http:\/\/aasims.wordpress.com\/?p=2747"},"modified":"2025-05-05T11:49:28","modified_gmt":"2025-05-05T11:49:28","slug":"java-1-7-g1-garbage-collector","status":"publish","type":"post","link":"https:\/\/aasimnaseem.com\/blog\/java-1-7-g1-garbage-collector\/","title":{"rendered":"Java 1.7 G1 Garbage Collector"},"content":{"rendered":"<p>Hi all,<br \/>\nHope everything is going good at your desks;<\/p>\n<p>Last night, I was reading new features in Java 1.7 and found some updates in garbage collection mechanism; There are many updates in 1.7 ranges from core vm, i18n, Nimbus for Swings and other enhancements. We have already discussed the updates in GC for Java SE 6 Update 14; You can <a title=\"G1: Java\u2019s Garbage First Garbage\u00a0Collector\" href=\"https:\/\/AasimNaseem.com\/wp-content\/uploads\/2009\/10\/01\/g1-javas-garbage-first-garbage-collector\/\" target=\"_blank\" rel=\"noopener\">find them here<\/a>; In Java 1.7 has a new garbage collection strategy called G1, which is short for Garbage First. It has been experimentally launched in the Java 1.6 update 14 to replace the <a title=\"G1: Java\u2019s Garbage First Garbage\u00a0Collector\" href=\"https:\/\/AasimNaseem.com\/wp-content\/uploads\/2009\/10\/01\/g1-javas-garbage-first-garbage-collector\/\" target=\"_blank\" rel=\"noopener\">regular Concurrent Mark and Sweep Garbage Collectors\u00a0<\/a><a title=\"G1: Java\u2019s Garbage First Garbage\u00a0Collector\" href=\"https:\/\/AasimNaseem.com\/wp-content\/uploads\/2009\/10\/01\/g1-javas-garbage-first-garbage-collector\/\" target=\"_blank\" rel=\"noopener\">with increased performance<\/a>.<\/p>\n<p><!--more--><\/p>\n<p>G1 is considered &#8220;server-centric&#8221; with the following attributes.<\/p>\n<ul>\n<li>G1 uses parallelism which are mostly used in hardware today.The main advantage of G1 is designed in such a way to make use of all available CPU&#8217;s and utilize the processing power of all CPU&#8217;s and increase the performance and speed in Garbage Collection.<\/li>\n<li>Concurrency feature of G1 allows to run Java threads to minimize the heap operations at stop pauses.<\/li>\n<li>Next feature which plays a key role in increasing the Garbage Collection is treating the young objects(newly created) and the old objects(which lived for some time) differently.G1 mainly focuses on young objects as they can be reclaimable when traversing the old objects.<\/li>\n<li>Heap compaction is done to eliminate fragmentation problems.<\/li>\n<li>G1 can be more predictable when compared to CMS.<\/li>\n<\/ul>\n<p><strong>Features of G1\u00a0Garbage Collector<\/strong><\/p>\n<ul>\n<li>A single contiguous heap which is split into same-sized regions. No separation between younger and older regions.<\/li>\n<li>G1 uses evacuation pauses.Evacuation pauses are done in parallel by using all the available processors.<\/li>\n<li>G1 uses a\u00a0pause\u00a0prediction model to meet user-defined\u00a0pause\u00a0time targets<\/li>\n<li>Like CMS,G1 also periodically performs a concurrent marking phase.<\/li>\n<li>Unlike CMS, G1 does not perform a concurrent sweeping phase.<\/li>\n<\/ul>\n<div>Here are some elaborated details<\/div>\n<div>\n<ul>\n<li><strong>Parallelism and Concurrency<\/strong>. G1 takes advantage of the parallelism that exists in hardware today. It uses all available CPUs (cores, hardware threads, etc.) to speed up its \u201cstop-the-world\u201d pauses when an application&#8217;s Java threads are stopped to enable GC. It also works concurrently with running Java threads to minimize whole-heap operations during stop-the-world pauses.<\/li>\n<li><strong>Generational<\/strong>. Like the other HotSpot GC&#8217;s, G1 is generational, meaning it treats newly-allocated (aka\u00a0<em>young<\/em>) objects and objects that have lived for some time (aka\u00a0<em>old<\/em>) differently. It concentrates garbage collection activity on young objects, as they are the ones most likely to be reclaimable, while visiting old objects infrequently. For most Java applications, generational garbage collection has major efficiency advantages over alternative schemes.<\/li>\n<li><strong>Compaction<\/strong>. Unlike CMS, G1 performs heap compaction over time. Compaction eliminates potential fragmentation problems to ensure smooth and consistent long-running operation.<\/li>\n<li><strong>Predictability<\/strong>. G1 is expected to be more predictable than CMS. This is largely due to the elimination of fragmentation issues that can negatively affect stop-the-world pause times in CMS. Additionally, G1 has a pause prediction model that, in many situations, allows it to often meet (or rarely exceed) a pause time target.<\/li>\n<\/ul>\n<\/div>\n<p><img decoding=\"async\" src=\"http:\/\/s10.flagcounter.com\/count\/N95\/bg_FFFFFF\/txt_000000\/border_FFFFFF\/columns_6\/maxflags_248\/viewers_0\/labels_1\/pageviews_1\/flags_1\/\" alt=\"free counters\" border=\"0\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi all, Hope everything is going good at your desks; Last night, I was reading new features in Java 1.7 and found some updates in garbage collection mechanism; There are many updates in 1.7 ranges from core vm, i18n, Nimbus for Swings and other enhancements. We have already discussed the&#8230;<\/p>\n","protected":false},"author":1,"featured_media":5271,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1154],"tags":[399,580,582,583,584,1089,1090],"class_list":["post-2747","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java","tag-garbage-collector","tag-jav","tag-java-1-7","tag-java-1-7-g1-garbage-collector","tag-java-7","tag-whats-new-in-java-1-7","tag-whats-new-in-java-7"],"_links":{"self":[{"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/posts\/2747","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/comments?post=2747"}],"version-history":[{"count":3,"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/posts\/2747\/revisions"}],"predecessor-version":[{"id":5273,"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/posts\/2747\/revisions\/5273"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/media\/5271"}],"wp:attachment":[{"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/media?parent=2747"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/categories?post=2747"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/tags?post=2747"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}