Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8010491

.sequential().iterator().hasNext() called on a parallel stream leads to OOM

XMLWordPrintable

      For example the following code will lead to OOM with JDK8b82-lambda:

      import java.util.stream.Streams;

      public class SequentialOnParallelStream {
          public static void main(String[] args) {
              Streams.generate(() -> "abc").parallel().sequential().iterator().hasNext();
          }
      }


      Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
      at java.util.stream.SpinedBuffer.ensureCapacity(SpinedBuffer.java:137)
      at java.util.stream.SpinedBuffer.increaseCapacity(SpinedBuffer.java:146)
      at java.util.stream.SpinedBuffer.accept(SpinedBuffer.java:238)
      at java.util.stream.Nodes$SpinedNodeBuilder.accept(Nodes.java:1206)
      at java.util.Spliterators$IteratorSpliterator.forEach(Spliterators.java:1008)
      at java.util.stream.AbstractPipeline$PipelineHelperImpl.intoWrapped(AbstractPipeline.java:599)
      at java.util.stream.AbstractPipeline$PipelineHelperImpl.into(AbstractPipeline.java:589)
      at java.util.stream.NodeUtils$CollectorTask.doLeaf(NodeUtils.java:325)
      at java.util.stream.NodeUtils$CollectorTask.doLeaf(NodeUtils.java:303)
      at java.util.stream.AbstractTask.doCompute(AbstractTask.java:283)
      at java.util.stream.AbstractTask.compute(AbstractTask.java:256)
      at java.util.concurrent.CountedCompleter.exec(CountedCompleter.java:710)
      at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:260)
      at java.util.concurrent.ForkJoinTask.doInvoke(ForkJoinTask.java:356)
      at java.util.concurrent.ForkJoinTask.invoke(ForkJoinTask.java:688)
      at java.util.stream.NodeUtils.collect(NodeUtils.java:78)
      at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:87)
      at java.util.stream.AbstractPipeline$PipelineHelperImpl.collectOutput(AbstractPipeline.java:684)
      at java.util.stream.AbstractPipeline$3.evaluateParallel(AbstractPipeline.java:318)
      at java.util.stream.AbstractPipeline$1.getNode(AbstractPipeline.java:189)
      at java.util.stream.AbstractPipeline$NodeSpliteratorSupplier.get(AbstractPipeline.java:522)
      at java.util.stream.AbstractPipeline$UpstreamSpliteratorSupplier.get(AbstractPipeline.java:510)
      at java.util.stream.AbstractPipeline$UpstreamSpliteratorSupplier.get(AbstractPipeline.java:503)
      at java.util.stream.StreamSpliterators$DelegatingSpliterator.get(StreamSpliterators.java:355)
      at java.util.stream.StreamSpliterators$DelegatingSpliterator.tryAdvance(StreamSpliterators.java:367)
      at java.util.Spliterators$1Adapter.hasNext(Spliterators.java:394)
      at SequentialOnParallelStream.main(SequentialOnParallelStream.java:5)


            psandoz Paul Sandoz
            dbessono Dmitry Bessonov
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: