RFR: 8275527: Separate/refactor forward pointer access
Albert Mingkun Yang
ayang at openjdk.java.net
Wed Oct 20 11:33:06 UTC 2021
On Thu, 14 Oct 2021 16:37:02 GMT, Roman Kennke <rkennke at openjdk.org> wrote:
> sometimes is_forwarded() is determined by forwardee() == NULL checks (and crude overrides to prepare non-forwarded headers to return NULL in such checks, see g1Full* source files).
Overriding the markword to return null for non-forwarded objs is indeed a bit hacky. However, from a caller's perspective, this is the most intuitive one.
Taking `G1FullGCCompactTask::G1CompactRegionClosure::apply` as an example:
HeapWord* destination = cast_from_oop<HeapWord*>(obj->forwardee());
if (destination == NULL) {
// Object not moving
return size;
}
...
Copy::aligned_conjoint_words(obj_addr, destination, size);
`destination` is either null (obj is not moved) or the new location after moving; rather smooth and straightforward control flow.
I wonder if we can use this pattern without overriding the markdown. Here's a straw man proposal.
oop oopDesc::forwardee() const {
auto mark_word = mark();
bool is_forwarded = mark_word.is_marked();
if (!is_forwarded) {
return nullptr;
}
return cast_to_oop(mark_word.decode_pointer());
}
The intention is to load the markword only once. Additionally, callers can continue using the `is_forwarded() / forwardee()` pair, or switch to the `forwardee() == nullptr` pattern on a case-by-case basis if desired.
-------------
PR: https://git.openjdk.java.net/jdk/pull/5955
More information about the shenandoah-dev
mailing list