RFR: 8275527: Separate/refactor forward pointer access
Roman Kennke
rkennke at openjdk.java.net
Wed Oct 20 11:37:06 UTC 2021
On Tue, 19 Oct 2021 20:58:49 GMT, Stefan Karlsson <stefank at openjdk.org> wrote:
> I like how the mark/is_marked/decode_pointer code gets cleaned up. And having an OopForwading class probably makes sense for parts of the code.
>
> I'm less excited about the way the explicitly stack allocated OopForwarding objects make the code less readable. Take these two examples:
>
> ```
> assert(old->is_objArray(), "invariant");
> - assert(old->is_forwarded(), "invariant");
> + assert(OopForwarding(old).is_forwarded(), "invariant");
> ```
>
> ```
> oop new_obj = obj->is_forwarded() ? obj->forwardee()
> : _young_gen->copy_to_survivor_space(obj);
> OopForwarding fwd(obj);
> oop new_obj = fwd.is_forwarded() ? fwd.forwardee()
> : _young_gen->copy_to_survivor_space(obj);
> ```
>
> I think both snippets were nicer to read in the earlier code. And there's a lot of those kind of changes in this patch.
>
> Maybe there's a hybrid approach where we could still have oopDesc::is_forwarded, oopDesc::forwardee, etc. but also have OopForwarding objects for those places that really need them? And then minimize the amount of places we use `OopForwarding fwd(obj)` and `OopForwarding(obj)->forwardee()` in the code?
In the first snippet, there is only one usage of the mark-word, i.e. no problem to simplify that. However, in the 2nd snippet, the point is that we can avoid loading the mark-word twice, and if we want to do that, we need an enclosing scope. The alternative would be to do something like:
markWord mark = obj->mark();
oop fwd = mark->is_forwarded() ? mark->forwardee() : something_else();
... which is pretty much the same as what I proposed, except that the markWord and the logic is encapsulated in OopForwarding.
Notice that in some cases we actually already do that - those are the 'messy' cases where we deliberately load the mark-word once, and drag it through the code that needs it (sometimes not only for performance but also for correctness in the face of concurrency) - and the use is_marked() and decode_pointer() on it.
Given that I have not been able to show performance benefits, I could revert cases like you mentioned to their original form, and consolidate the implementation into markWord, unless we prefer the most efficient solution everywhere. ?
-------------
PR: https://git.openjdk.java.net/jdk/pull/5955
More information about the shenandoah-dev
mailing list