b69 regression: concat(parallel, infinite).sequential().iterator() -> OOM

Paul Sandoz paul.sandoz at oracle.com
Wed Dec 19 03:53:29 PST 2012


Hi,

I suspect previously that the concat operation resulted in a sequential stream, or one that delayed doing anything until Iterator.hasNext/next was called.

Now, since one of the streams is a parallel stream the concatenated stream is taken to be a parallel stream too. The idea being we try to squeeze as much parallelism as we possibly can.

sequential() is a barrier when the upstream is parallel, so it is always gonna barf when given infinite input (as will be the case for any non-short-circuiting terminal operation).

Try:

  Streams.concat(parallel, infinite).limit(10).sequential().iterator();

Paul.

On Dec 19, 2012, at 12:10 PM, Dmitry Bessonov <dmitry.bessonov at oracle.com> wrote:

> Hello,
> 
> A regression has been noticed in b69.
> The following code leads basically to OOM with b69.
> 
> --------------
> import java.util.Arrays;
> import java.util.Iterator;
> import java.util.stream.Stream;
> import java.util.stream.Streams;
> 
> public class ConcatParallelAndInfinite {
> 
>    public static void main(String[] args) {
>        Stream<String> parallel = Arrays.asList("a", "b").parallelStream();
>        Stream<String> infinite = Streams.repeat("x");
>        Iterator<String> iterator = Streams.concat(parallel, infinite).sequential().iterator();
>        System.out.println("iterator = " + iterator);
>    }
> }
> --------------
> 
> the output will be something like:
> 
> Exception in thread "ForkJoinPool.commonPool-worker-7" Exception in thread "ForkJoinPool.commonPool-worker-7" Exception in thread "ForkJoinPool.commonPool-worker-1" Exception in thread "ForkJoinPool.commonPool-worker-11" Exception in thread "ForkJoinPool.commonPool-worker-1" Exception in thread "ForkJoinPool.commonPool-worker-9" Exception in thread "ForkJoinPool.commonPool-worker-15" java.lang.OutOfMemoryError: Java heap space
> java.lang.OutOfMemoryError: Java heap space
> Exception in thread "ForkJoinPool.commonPool-worker-13" java.lang.OutOfMemoryError: Java heap space
> Exception in thread "ForkJoinPool.commonPool-worker-11" Exception in thread "ForkJoinPool.commonPool-worker-5"
> 
> 
> With b68 code above works just fine
> (assuming .parallelStream() renamed back to .parallel())
> printing out the iterator instance.
> 
> 
> -Dmitry
> <ConcatParallelAndInfinite.java>



More information about the lambda-dev mailing list