RFR: JDK-8319123 : Implementation of JEP-461: Stream Gatherers (Preview)

Viktor Klang vklang at openjdk.org
Wed Nov 8 15:41:27 UTC 2023


On Mon, 30 Oct 2023 15:38:35 GMT, Viktor Klang <vklang at openjdk.org> wrote:

> This is a Draft PR for [JEP-461](https://openjdk.org/jeps/461)

src/java.base/share/classes/java/util/stream/AbstractPipeline.java line 88:

> 86:      */
> 87:     @SuppressWarnings("rawtypes")
> 88:     protected final AbstractPipeline previousStage;

Making this accessible in subclasses allows to avoid having to store this reference twice, and since this value is passed in during ctor it doesn't expose something previously hidden.

src/java.base/share/classes/java/util/stream/AbstractPipeline.java line 223:

> 221:         previousStage.linkedOrConsumed = true;
> 222: 
> 223:         previousPreviousStage.nextStage = this;

This allows subclasses to replace the "end" of a pipeline with a new "end" presuming that the previous "end" is not linked nor consumed. As an example, it allows a GathererOp(gathererA) to be replaced with a GathererOp(gathererA.andThen(gathererB))

src/java.base/share/classes/java/util/stream/AbstractPipeline.java line 242:

> 240:     }
> 241: 
> 242:     // Terminal evaluation methods

This is needed in order to let subclasses override terminal operations such as, but not limited to, `collect`. (since a terminal operation needs to mark the entire pipeline as consumed).

src/java.base/share/classes/java/util/stream/AbstractPipeline.java line 444:

> 442:             spliterator = sourceStage.sourceSpliterator;
> 443:             sourceStage.sourceSpliterator = null;
> 444:         }

Needed to make this visible to subclasses in order to implement terminal-operations.

src/java.base/share/classes/java/util/stream/Gatherer.java line 171:

> 169:  *     parallelized by initializing each partition in separation, invoking
> 170:  *     the integrator until it returns {@code false}, and then joining each
> 171:  *     partitions state using the combiner, and then invoking the finalizer on

Suggestion:

 *     partitions state using the combiner, and then invoking the finisher on

src/java.base/share/classes/java/util/stream/ReferencePipeline.java line 692:

> 690:                 && (collector.characteristics().contains(Collector.Characteristics.CONCURRENT))
> 691:                 && (!isOrdered() || collector.characteristics().contains(Collector.Characteristics.UNORDERED))) {
> 692:             container = collector.supplier().get();

Un-final:ed to allow GathererOp to implement fusion of gather + collect

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

PR Review Comment: https://git.openjdk.org/jdk/pull/16420#discussion_r1377573665
PR Review Comment: https://git.openjdk.org/jdk/pull/16420#discussion_r1377572502
PR Review Comment: https://git.openjdk.org/jdk/pull/16420#discussion_r1377574668
PR Review Comment: https://git.openjdk.org/jdk/pull/16420#discussion_r1377575538
PR Review Comment: https://git.openjdk.org/jdk/pull/16420#discussion_r1378972593
PR Review Comment: https://git.openjdk.org/jdk/pull/16420#discussion_r1377576412


More information about the core-libs-dev mailing list