RFR: JDK-8302666: Replace CHM with VarHandle in ForeachOrderedTask [v5]
Paul Sandoz
psandoz at openjdk.org
Tue Feb 28 16:13:51 UTC 2023
On Tue, 28 Feb 2023 11:09:37 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 refreshed the contents of this pull request, and previous commits have been removed. The incremental views will show differences compared to the previous content of the PR. The pull request contains one new commit since the last revision:
>
> Updating copyright header of ForEachOps.java and removing unnecessary suppression of an unchecked cast.
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, (ForEachOrderedTask<S, T>)null);
The reference cast on the argument is not required. `VarHandle`'s by default have `MethodHandle` invoke semantics (but without the throwing Throwable):
https://docs.oracle.com/en/java/javase/19/docs/api/java.base/java/lang/invoke/VarHandle.html#invoke
VarHandle's have been engineered so such reference casts on the arguments can be optimized away. This makes them much easier to use than MethodHandles.
-------------
PR: https://git.openjdk.org/jdk/pull/12320
More information about the core-libs-dev
mailing list