RFR: 8337995: ZUtils::fill uses std::fill_n

Stefan Karlsson stefank at openjdk.org
Wed Dec 11 10:13:39 UTC 2024


On Tue, 10 Dec 2024 16:37:43 GMT, Kim Barrett <kbarrett at openjdk.org> wrote:

> Please review this change to zUtils.cpp to use a for-loop to fill a block of
> memory rather than using the std::fill_n algorithm. Use of <algorithm> is
> currently not permitted in HotSpot.
> 
> Testing: mach5 tier1

I don't really see the need to forbid `std::fill_n`, so I would have preferred an update to the style guide. However, if we really need to remove it then I would prefer style modification to the explicit loop.

src/hotspot/share/gc/z/zUtils.cpp line 41:

> 39:   for (uintptr_t* end = addr + count; addr < end; ++addr) {
> 40:     *addr = value;
> 41:   }

I tend to avoid changing values of the input arguments, so I would like to see that changed. Unless there's a problem with the below code I would like to see this changed to this:

  for (uintptr_t* current = addr; current < addr + count; ++current) {
    *current = value;
  }


Or maybe even:

  for (size_t i = 0; i < count; ++i) {
    *(addr + i) = value;
  }

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

Changes requested by stefank (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/22667#pullrequestreview-2495009553
PR Review Comment: https://git.openjdk.org/jdk/pull/22667#discussion_r1879762974


More information about the hotspot-gc-dev mailing list