changeset 6368:cb5a68c2e6cf

Move Spliterator.shouldNotSplit to ParallelPipelineHelper.suggestSplit ensuring that Spliterator is only about splitting and element access. ParallelPipelineHelper is in a better position to centralize the suggestion that a split should be peformed given information on spliterator and properties both static and dynamic of the F/J pool and platform.
author psandoz
date Mon, 05 Nov 2012 14:28:29 +0100
parents ecf2a2d21af8
children 33e0259f7495
files src/share/classes/java/util/streams/AbstractPipeline.java src/share/classes/java/util/streams/ParallelPipelineHelper.java src/share/classes/java/util/streams/Spliterator.java src/share/classes/java/util/streams/ops/AbstractTask.java src/share/classes/java/util/streams/ops/CumulateOp.java src/share/classes/java/util/streams/ops/TreeUtils.java
diffstat 6 files changed, 22 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/util/streams/AbstractPipeline.java	Sat Nov 03 20:12:39 2012 +0100
+++ b/src/share/classes/java/util/streams/AbstractPipeline.java	Mon Nov 05 14:28:29 2012 +0100
@@ -380,6 +380,12 @@
         }
 
         @Override
+        public boolean suggestSplit(Spliterator<P_IN> spliterator) {
+            int remaining = spliterator.estimateSize();
+            return (remaining > targetSize || remaining < 0) && spliterator.getNaturalSplits() > 0;
+        }
+
+        @Override
         public <FJ_R> FJ_R invoke(ForkJoinTask<FJ_R> task) {
             return task.invoke();
         }
--- a/src/share/classes/java/util/streams/ParallelPipelineHelper.java	Sat Nov 03 20:12:39 2012 +0100
+++ b/src/share/classes/java/util/streams/ParallelPipelineHelper.java	Mon Nov 05 14:28:29 2012 +0100
@@ -44,6 +44,18 @@
     long suggestTargetSize();
 
     /**
+     * Suggest if a spliterator should be split further or not.
+     *
+     * <p>Information such as the target size (see {@link #suggestTargetSize()} and size of the
+     * spliterator are factors that are utilized to evaluate whether further splitting is
+     * suggested.</p>
+     *
+     * @param spliterator the spliterator to be split or not.
+     * @return return true if the spliterator should be split further, otherwise false.
+     */
+    boolean suggestSplit(Spliterator<P_IN> spliterator);
+
+    /**
      * Get the spliterator for the stream accessor that inputs elements to the pipeline.
      *
      * @return the spliterator.
--- a/src/share/classes/java/util/streams/Spliterator.java	Sat Nov 03 20:12:39 2012 +0100
+++ b/src/share/classes/java/util/streams/Spliterator.java	Mon Nov 05 14:28:29 2012 +0100
@@ -127,17 +127,6 @@
     boolean isPredictableSplits();
 
     /**
-     * Ascertain if the spliterator should be split further or not, based on a target leaf size.
-     *
-     * @param targetSize the suggested target size for a spliterator to not be further split.
-     * @return return true if the spliterator should not be further split, otherwise false.
-     */
-    boolean shouldNotSplit(long targetSize) default {
-        int remaining = estimateSize();
-        return (remaining <= targetSize && remaining >= 0) || (getNaturalSplits() == 0);
-    }
-
-    /**
      * A Spliterator that can only be used to sequentially traverse a source.
      * @param <T>
      */
@@ -157,9 +146,5 @@
             return false;
         }
 
-        @Override
-        boolean shouldNotSplit(long targetSize) default {
-            return true;
-        }
     }
 }
--- a/src/share/classes/java/util/streams/ops/AbstractTask.java	Sat Nov 03 20:12:39 2012 +0100
+++ b/src/share/classes/java/util/streams/ops/AbstractTask.java	Mon Nov 05 14:28:29 2012 +0100
@@ -85,7 +85,7 @@
 
     @Override
     public void compute() {
-        isLeaf = spliterator.shouldNotSplit(helper.suggestTargetSize());
+        isLeaf = !helper.suggestSplit(spliterator);
         if (isLeaf) {
             setRawResult(doLeaf());
             helpComplete();
--- a/src/share/classes/java/util/streams/ops/CumulateOp.java	Sat Nov 03 20:12:39 2012 +0100
+++ b/src/share/classes/java/util/streams/ops/CumulateOp.java	Mon Nov 05 14:28:29 2012 +0100
@@ -178,7 +178,7 @@
         protected Node<T> compute() {
             switch (problem.pass) {
                 case 0:
-                    isLeaf = spliterator.shouldNotSplit(problem.helper.suggestTargetSize());
+                    isLeaf = !problem.helper.suggestSplit(spliterator);
                     if (!isLeaf) {
                         left = new CumulateTask<>(spliterator.split(), problem);
                         right = new CumulateTask<>(spliterator, problem);
--- a/src/share/classes/java/util/streams/ops/TreeUtils.java	Sat Nov 03 20:12:39 2012 +0100
+++ b/src/share/classes/java/util/streams/ops/TreeUtils.java	Mon Nov 05 14:28:29 2012 +0100
@@ -52,8 +52,7 @@
     public static <P_IN, P_OUT> Node<P_OUT> collect(ParallelPipelineHelper<P_IN, P_OUT> helper,
                                                     boolean flattenTree) {
         Spliterator<P_IN> spliterator = helper.spliterator();
-        boolean noSplit = spliterator.shouldNotSplit(helper.suggestTargetSize());
-        if (noSplit) {
+        if (!helper.suggestSplit(spliterator)) {
             return collectSequentially(helper, spliterator);
         } else {
             int size = spliterator.getSizeIfKnown();
@@ -159,8 +158,7 @@
 
         @Override
         public void compute() {
-            boolean isLeaf = spliterator.shouldNotSplit(helper.suggestTargetSize());
-            if (isLeaf) {
+            if (!helper.suggestSplit(spliterator)) {
                 OpUtils.intoUnwrapped(helper, spliterator, Arrays.sink(array, offset, length));
                 helpComplete();
             }