diff options
Diffstat (limited to 'src/share/classes/java/util/stream/AbstractTask.java')
-rw-r--r-- | src/share/classes/java/util/stream/AbstractTask.java | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/src/share/classes/java/util/stream/AbstractTask.java b/src/share/classes/java/util/stream/AbstractTask.java index 33de7d5c52..8c5be49aff 100644 --- a/src/share/classes/java/util/stream/AbstractTask.java +++ b/src/share/classes/java/util/stream/AbstractTask.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -27,6 +27,7 @@ package java.util.stream; import java.util.Spliterator; import java.util.concurrent.CountedCompleter; import java.util.concurrent.ForkJoinPool; +import java.util.concurrent.ForkJoinWorkerThread; /** * Abstract base class for most fork-join tasks used to implement stream ops. @@ -88,13 +89,7 @@ abstract class AbstractTask<P_IN, P_OUT, R, K extends AbstractTask<P_IN, P_OUT, R, K>> extends CountedCompleter<R> { - /** - * Default target factor of leaf tasks for parallel decomposition. - * To allow load balancing, we over-partition, currently to approximately - * four tasks per processor, which enables others to help out - * if leaf tasks are uneven or some processors are otherwise busy. - */ - static final int LEAF_TARGET = ForkJoinPool.getCommonPoolParallelism() << 2; + private static final int LEAF_TARGET = ForkJoinPool.getCommonPoolParallelism() << 2; /** The pipeline helper, common to all tasks in a computation */ protected final PipelineHelper<P_OUT> helper; @@ -157,6 +152,22 @@ abstract class AbstractTask<P_IN, P_OUT, R, } /** + * Default target of leaf tasks for parallel decomposition. + * To allow load balancing, we over-partition, currently to approximately + * four tasks per processor, which enables others to help out + * if leaf tasks are uneven or some processors are otherwise busy. + */ + public static int getLeafTarget() { + Thread t = Thread.currentThread(); + if (t instanceof ForkJoinWorkerThread) { + return ((ForkJoinWorkerThread) t).getPool().getParallelism() << 2; + } + else { + return LEAF_TARGET; + } + } + + /** * Constructs a new node of type T whose parent is the receiver; must call * the AbstractTask(T, Spliterator) constructor with the receiver and the * provided Spliterator. @@ -181,7 +192,7 @@ abstract class AbstractTask<P_IN, P_OUT, R, * @return suggested target leaf size */ public static long suggestTargetSize(long sizeEstimate) { - long est = sizeEstimate / LEAF_TARGET; + long est = sizeEstimate / getLeafTarget(); return est > 0L ? est : 1L; } |