Heap dumps offer the ability to exclude unreachable objects, but they actually 
still include GC filler objects/arrays (see 
https://tschatzl.github.io/2022/09/26/jdk-vm-internal-fillerarray.html for more 
on fillers).

If the user requests to exclude unreachable objects/include only live objects, 
heap dump triggers a full GC before dumping, so in theory only live objects 
remain. But filler objects can 'survive' a full GC even though they are 
unreachable by definition. They waste space, and cause confusion. If using a 
tool like MAT, they will show as unreachable - why are unreachable objects in 
my live heap dump? If using something like JOL to show a histogram, 
reachability is not assessed and the user may not notice that unreachable 
objects are influencing the results. They show as `int[]`, so their provenance 
is not obvious.

So, exclude them explicitly if the user requested only live objects. This does 
not affect non-live dumps (discussion for that in  
[JDK-8372389](https://bugs.openjdk.org/browse/JDK-8372389)).


$ ls -lah
1.5G Sep 14 13:30 live-after-fix.hprof
2.6G Sep 14 13:30 live-before-fix.hprof

$ java -jar jol-cli.jar heapdump-stats live-before-fix.hprof

       INSTANCES            SIZE        SUM SIZE    CLASS
------------------------------------------------------------------------------------------------
               5     236,870,896   1,184,354,480    int[59217720]  <--- filler 
arrays!


---------
- [x] I confirm that I make this contribution in accordance with the [OpenJDK 
Interim AI Policy](https://openjdk.org/legal/ai).

-------------

Commit messages:
 - 8392345: Omit filler objects in 'live' heap dump

Changes: https://git.openjdk.org/jdk/pull/32860/files
  Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=32860&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8392345
  Stats: 10 lines in 1 file changed: 7 ins; 0 del; 3 mod
  Patch: https://git.openjdk.org/jdk/pull/32860.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/32860/head:pull/32860

PR: https://git.openjdk.org/jdk/pull/32860

Reply via email to