In G1 we have a facility to dump (to standard output or to a file) the objects that are considered reachable (either above TAMS, or marked explicitly). Currently, this is used to optionally dump the live objects when heap verification fails and it was very helpful when debugging the marking bug in CR 6847956.
This CR revamps this facility in a few ways:
- The current version only uses the "previous" marking information to determine whether an object is live or not. This was acceptable before, as we only did heap verification based on the "previous" marking information. However, CR 6850846 extended heap verification to also used the "next" marking information when necessary (in particular: at the end of remark). So, it is helpful to extend the reachable object dump to be able to use either the "previous" or "next" marking information as necessary. The method is renamed to the more reasonable print_reachable().
- Change print_reachable() to only dump to files and never on tty / gclog_or_tty. The dumps tend to be quite large, even for small-ish heaps, so it's counter productive to do them on tty. There might be several places where we call print_reachble() during a marking cycle (we currently have two, see below). The output files would have the same prefix and a suffix that depends on the point when they were taken (see below).
- There is currently an ad-hoc facility that dumps the reachble objects at the initial mark pause. This is very helpful in order to compare what was reachable at the beginning of the marking cycle with what is reachable at the end of the marking cycle (typically: when verification failed). However, it's best to remove the ad-hoc code in favor of re-using print_reachable().
- Three developer arguments drive print_reachable()
* G1PrintReachableBaseFile : The base file name for the heap dump file. A suffix will be appended to that depending from where print_reachable() was called.
* G1PrintReachableAtInitialMark : It dumps the reachable objects at initial mark. The suffix for these files is ".before".
* G1VerifyDuringGCPrintReachable : It dumps the reachable objects when heap verification fails. The suffix for these files is ".failed-verification'.
- Exclude the reachable object dump code from product builds, as the arguments that enable it are developer arguments.