title: Java G1GC is never collecting Old Gen
body: <p>I was running my surefire tests and it got me into GC Overhead limit. However, after analyzing memory statistics and snapshots I realized that almost 800 MB was wasted in String Duplication. </p>
  
  <p>Looking more into VM arguments and other runtime parameters, I realized that the GC used was PS (Parallel Scavenger - The default one from JVM).</p>
  
  <p>I modified the surefire argLine to use </p>
  
  <pre><code>-XX:+UseG1GC -XX:+UseStringDeduplication -XX:+PrintStringDeduplicationStatistics
  </code></pre>
  
  <p>Now my test-runs are using the G1GC.</p>
  
  <p>Below is a comparison of before and after switching GC</p>
  
  <p><a href="https://i.stack.imgur.com/7RoRl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7RoRl.png" alt="enter image description here"></a></p>
  
  <p>If you are interested in the deduplication stats. Here it is:
  <a href="https://i.stack.imgur.com/DkCWf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DkCWf.png" alt="enter image description here"></a></p>
  
  <p><strong>My question</strong> : Why is G1GC using so much of Old Gen and it is not being collected over the life of the test-run. It keeps on growing.</p>
  
  <p>The rest of the environment and arguments and everything else remains same. The only thing changes is the GC algorithm and the Deduplication.</p>
  
  <p>I have been looking at these related threads as well</p>
  
  <p><a href="https://stackoverflow.com/questions/40680344/jvm-g1gcs-mixed-gc-not-collecting-much-old-regions">JVM G1GC&#39;s mixed gc not collecting much old regions</a></p>
  
  <p><a href="https://stackoverflow.com/questions/27949213/string-deduplication-feature-of-java-8">String Deduplication feature of Java 8</a></p>
  
  <p><a href="https://openjdk.java.net/jeps/192" rel="nofollow noreferrer">https://openjdk.java.net/jeps/192</a></p>