RFR: 8327997: G1: Move G1ScanClosureBase::reference_iteration_mode to subclass

Thomas Schatzl tschatzl at openjdk.org
Thu Mar 14 09:37:41 UTC 2024


On Tue, 12 Mar 2024 16:38:36 GMT, Albert Mingkun Yang <ayang at openjdk.org> wrote:

> Simple moving a method from super class to sub class and some documentation.

src/hotspot/share/gc/g1/g1OopClosures.hpp line 77:

> 75:   // iteration mode to skip the known null-check in
> 76:   // InstanceRefKlass::try_discover.
> 77:   virtual ReferenceIterationMode reference_iteration_mode() { return DO_FIELDS; }

I think the comment is okay, but maybe should put more emphasis on that specifying this iteration mode allows _the compiler_ to (more easily) compile out the check in `try_discover`.

Also since this isn't the only place this (and similar) optimizations are made elsewhere too using this getter, I kind of agree with @lgxbslgx that the impact of the selection should probably be documented at the enum level (the move of the override into the leaf class here is fine with me).

Just something like "// Selection of one or the other option helps the compiler to remove unnecessary, known beforehand behavior for a given oop closure at compile time" seems sufficient to me there instead of this fairly long comment.
The exact changes can be easily gathered by searching the usages of the enum.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/18244#discussion_r1524532934


More information about the hotspot-gc-dev mailing list