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

Per Minborg pminborg at openjdk.org
Thu Feb 16 15:04:34 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 372:

> 370:         private Node<T> node;
> 371: 
> 372:         @SuppressWarnings("unused") private volatile ForEachOrderedTask<S, T> next; // Only accessed through the NEXT VarHandle

I think the variable can be declared without `volatile` as the operations on the `VarHandle` will determine the memory semantics used regardless? So, the `NEXT.set()` at L431 might also be replaced with `NEXT.setVolatile()`

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

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


More information about the core-libs-dev mailing list