RFR: JDK-8302666: Replace CHM with VarHandle in ForeachOrderedTask [v4]
ExE Boss
duke at openjdk.org
Tue Feb 28 09:11:19 UTC 2023
On Mon, 27 Feb 2023 09:14:56 GMT, Viktor Klang <duke at openjdk.org> wrote:
>> I noticed when looking at the code that there was no real need to use a CHM to perform the tracking of activation in an ordered fashion on ForEachOrderedTask, but instead a VarHandle can be used, reducing allocations and indirection.
>
> Viktor Klang has updated the pull request with a new target base due to a merge or a rebase. The pull request now contains three commits:
>
> - Updating copyright header of ForEachOps.java and removing unnecessary suppression of an unchecked cast.
> - Write the initial value of the next reference without using the VarHandle
> - JDK-8302666: Replace CHM with VarHandle in ForeachOrderedTask
src/java.base/share/classes/java/util/stream/ForEachOps.java line 513:
> 511: // of right subtree (if any, which can be this task's right sibling)
> 512: //
> 513: var leftDescendant = (ForEachOrderedTask<S, T>)NEXT.getAndSet(this, null);
Casting the `null` is required for the resolved method descriptor to be `(ForEachOrderedTask, ForEachOrderedTask)ForEachOrderedTask` instead of `(ForEachOrderedTask, Object)ForEachOrderedTask`, which prevents unnecessary type conversion `LambdaForm`s from being introduced and allows [`VarHandle::withInvokeExactBehavior`] to be used:
Suggestion:
var leftDescendant = (ForEachOrderedTask<S, T>) NEXT.getAndSet(this, (ForEachOrderedTask<S, T>) null);
[`VarHandle::withInvokeExactBehavior`]: https://docs.oracle.com/en/java/javase/19/docs/api/java.base/java/lang/invoke/VarHandle.html#withInvokeExactBehavior()
-------------
PR: https://git.openjdk.org/jdk/pull/12320
More information about the core-libs-dev
mailing list