RFR: JDK-8302666: Replace CHM with VarHandle in ForeachOrderedTask

Paul Sandoz psandoz at openjdk.org
Thu Feb 16 17:13:29 UTC 2023


On Tue, 31 Jan 2023 10:57:58 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.

src/java.base/share/classes/java/util/stream/ForEachOps.java line 431:

> 429:                 // leftChild and rightChild were just created and not fork():ed
> 430:                 // yet so no need for a volatile write
> 431:                 NEXT.set(leftChild, rightChild);

Make `next` a plain field and shuffle up the assignment (`leftChild.next = rightChild`) to occur immediately after construction of the right child task? (FWIW `addToPendingCount` operates on a volatile field of `CountedCompleter`).

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

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


More information about the core-libs-dev mailing list