RFR: 8324513: Inline ContiguousSpace::object_iterate_from

Stefan Karlsson stefank at openjdk.org
Tue Jan 23 13:16:30 UTC 2024


On Tue, 23 Jan 2024 10:34:04 GMT, Albert Mingkun Yang <ayang at openjdk.org> wrote:

> Trivial refactoring of inlining a method.

Changes requested by stefank (Reviewer).

src/hotspot/share/gc/shared/space.cpp line 156:

> 154:     addr += obj->size();
> 155:   }
> 156: }

Given that this function now grows beyond a small two-liner implementation, I would prefer if the `is_empty`check was separated from the rest of the code. Something like this:

void ContiguousSpace::object_iterate(ObjectClosure* blk) {
  if (is_empty()) {
    return;
  }
  
  HeapWord* addr = bottom();
  while (addr < top()) {
    oop obj = cast_to_oop(addr);
    blk->do_object(obj);
    addr += obj->size();
  }
}


With that said, it seems like the `is_empty()` boils down to a comparison between `bottom()` and `top()`. If that is the case, then we could just remove the `is_empty()` check and let that be handled by the while loop.

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

PR Review: https://git.openjdk.org/jdk/pull/17531#pullrequestreview-1838764054
PR Review Comment: https://git.openjdk.org/jdk/pull/17531#discussion_r1463265111


More information about the hotspot-gc-dev mailing list