RFR: JDK-8302666: Replace CHM with VarHandle in ForeachOrderedTask [v5]

Viktor Klang duke at openjdk.org
Thu Mar 2 11:15:17 UTC 2023


On Tue, 28 Feb 2023 16:11:25 GMT, Paul Sandoz <psandoz at openjdk.org> wrote:

>> 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.

@PaulSandoz Ah, that's great wisdom right there. I'll remove the cast on the argument. 👍

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

PR: https://git.openjdk.org/jdk/pull/12320


More information about the core-libs-dev mailing list