JDK-8211150 : G1 Full GC not purging code root memory and hence causing memory leak
  • Type: Bug
  • Component: hotspot
  • Sub-Component: gc
  • Affected Version: 12
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2018-09-26
  • Updated: 2021-02-22
  • Resolved: 2018-10-03
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 11 JDK 12 JDK 8
11.0.11Fixed 12 b14Fixed 8u202Fixed
Description
G1 Full GC does not purge code root memory, and that causes a memory leak. The leak is illustrated in the attached file after_8141421_fix.png. 

I made the following simple change that purges the code root memory
in the Full GC control path. With this change this leak goes away. (see attached file after_purge_fix.png)
--- a/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp 
+++ b/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp 
@@ -1423,6 +1423,7 @@ 
         hot_card_cache->reset_card_counts(); 
         hot_card_cache->reset_hot_cache(); 
       } 
+      purge_code_root_memory(); 
  
       // Rebuild remembered sets of all regions. 
       if (G1CollectedHeap::use_parallel_gc_threads()) {

We currently purge code root memory in VM_G1IncCollectionPause operation but not in VM_G1CollectFull which is causing this leak.
Comments
Fix Request (11u) (Amusingly, this was backported to 8u a long time ago, but it missed 11u!) This patch fixes G1 memory leak. Patch applies cleanly to 11u, passes tier{1,2,3}.
15-02-2021

I think it is only a memory leak in case there are nothing but full gcs. The next young gc should clean out the purge list again. It is still good that full gc cleans out this data though.
26-09-2018