ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/concurrent/ConcurrentHashMap.java
(Generate patch)

Comparing jsr166/src/main/java/util/concurrent/ConcurrentHashMap.java (file contents):
Revision 1.137 by dl, Sun Oct 28 22:35:55 2012 UTC vs.
Revision 1.138 by dl, Tue Oct 30 14:23:07 2012 UTC

# Line 4924 | Line 4924 | public class ConcurrentHashMap<K, V>
4924              }
4925          }
4926  
4927        // FJ methods
4928
4929        /**
4930         * Propagates completion. Note that all reduce actions
4931         * bypass this method to combine while completing.
4932         */
4933        final void tryComplete() {
4934            BulkTask<K,V,?> a = this, s = a;
4935            for (int c;;) {
4936                if ((c = a.pending) == 0) {
4937                    if ((a = (s = a).parent) == null) {
4938                        s.quietlyComplete();
4939                        break;
4940                    }
4941                }
4942                else if (U.compareAndSwapInt(a, PENDING, c, c - 1))
4943                    break;
4944            }
4945        }
4946
4927          /**
4928           * Forces root task to complete.
4929           * @param ex if null, complete normally, else exceptionally
# Line 5022 | Line 5002 | public class ConcurrentHashMap<K, V>
5002          }
5003      }
5004  
5005 +    /**
5006 +     * Base class for non-reductive actions
5007 +     */
5008 +    @SuppressWarnings("serial") static abstract class BulkAction<K,V,R> extends BulkTask<K,V,R> {
5009 +        BulkAction<K,V,?> nextTask;
5010 +        BulkAction(ConcurrentHashMap<K,V> map, BulkTask<K,V,?> parent,
5011 +                   int batch, BulkAction<K,V,?> nextTask) {
5012 +            super(map, parent, batch);
5013 +            this.nextTask = nextTask;
5014 +        }
5015 +
5016 +        /**
5017 +         * Try to complete task and upward parents. Upon hitting
5018 +         * non-completed parent, if a non-FJ task, try to help out the
5019 +         * computation.
5020 +         */
5021 +        final void tryComplete(BulkAction<K,V,?> subtasks) {
5022 +            BulkTask<K,V,?> a = this, s = a;
5023 +            for (int c;;) {
5024 +                if ((c = a.pending) == 0) {
5025 +                    if ((a = (s = a).parent) == null) {
5026 +                        s.quietlyComplete();
5027 +                        break;
5028 +                    }
5029 +                }
5030 +                else if (a.casPending(c, c - 1)) {
5031 +                    if (subtasks != null && !inForkJoinPool()) {
5032 +                        while ((s = a.parent) != null)
5033 +                            a = s;
5034 +                        while (!a.isDone()) {
5035 +                            BulkAction<K,V,?> next = subtasks.nextTask;
5036 +                            if (subtasks.tryUnfork())
5037 +                                subtasks.exec();
5038 +                            if ((subtasks = next) == null)
5039 +                                break;
5040 +                        }
5041 +                    }
5042 +                    break;
5043 +                }
5044 +            }
5045 +        }
5046 +
5047 +    }
5048 +
5049      /*
5050       * Task classes. Coded in a regular but ugly format/style to
5051       * simplify checks that each variant differs in the right way from
# Line 5029 | Line 5053 | public class ConcurrentHashMap<K, V>
5053       */
5054  
5055      @SuppressWarnings("serial") static final class ForEachKeyTask<K,V>
5056 <        extends BulkTask<K,V,Void> {
5056 >        extends BulkAction<K,V,Void> {
5057          final Action<K> action;
5034        ForEachKeyTask<K,V> nextRight;
5058          ForEachKeyTask
5059              (ConcurrentHashMap<K,V> m, BulkTask<K,V,?> p, int b,
5060 <             ForEachKeyTask<K,V> nextRight,
5060 >             ForEachKeyTask<K,V> nextTask,
5061               Action<K> action) {
5062 <            super(m, p, b);
5040 <            this.nextRight = nextRight;
5062 >            super(m, p, b, nextTask);
5063              this.action = action;
5064          }
5065          @SuppressWarnings("unchecked") public final boolean exec() {
5066              final Action<K> action = this.action;
5067              if (action == null)
5068                  return abortOnNullFunction();
5069 <            ForEachKeyTask<K,V> rights = null;
5069 >            ForEachKeyTask<K,V> subtasks = null;
5070              try {
5071                  int b = batch(), c;
5072                  while (b > 1 && baseIndex != baseLimit) {
5073                      do {} while (!casPending(c = pending, c+1));
5074 <                    (rights = new ForEachKeyTask<K,V>
5075 <                     (map, this, b >>>= 1, rights, action)).fork();
5074 >                    (subtasks = new ForEachKeyTask<K,V>
5075 >                     (map, this, b >>>= 1, subtasks, action)).fork();
5076                  }
5077                  while (advance() != null)
5078                      action.apply((K)nextKey);
5057                tryComplete();
5079              } catch (Throwable ex) {
5080                  return tryCompleteComputation(ex);
5081              }
5082 <            while (rights != null && rights.tryUnfork()) {
5062 <                rights.exec();
5063 <                rights = rights.nextRight;
5064 <            }
5082 >            tryComplete(subtasks);
5083              return false;
5084          }
5085      }
5086  
5087      @SuppressWarnings("serial") static final class ForEachValueTask<K,V>
5088 <        extends BulkTask<K,V,Void> {
5071 <        ForEachValueTask<K,V> nextRight;
5088 >        extends BulkAction<K,V,Void> {
5089          final Action<V> action;
5090          ForEachValueTask
5091              (ConcurrentHashMap<K,V> m, BulkTask<K,V,?> p, int b,
5092 <             ForEachValueTask<K,V> nextRight,
5092 >             ForEachValueTask<K,V> nextTask,
5093               Action<V> action) {
5094 <            super(m, p, b);
5078 <            this.nextRight = nextRight;
5094 >            super(m, p, b, nextTask);
5095              this.action = action;
5096          }
5097          @SuppressWarnings("unchecked") public final boolean exec() {
5098              final Action<V> action = this.action;
5099              if (action == null)
5100                  return abortOnNullFunction();
5101 <            ForEachValueTask<K,V> rights = null;
5101 >            ForEachValueTask<K,V> subtasks = null;
5102              try {
5103                  int b = batch(), c;
5104                  while (b > 1 && baseIndex != baseLimit) {
5105                      do {} while (!casPending(c = pending, c+1));
5106 <                    (rights = new ForEachValueTask<K,V>
5107 <                     (map, this, b >>>= 1, rights, action)).fork();
5106 >                    (subtasks = new ForEachValueTask<K,V>
5107 >                     (map, this, b >>>= 1, subtasks, action)).fork();
5108                  }
5109                  Object v;
5110                  while ((v = advance()) != null)
5111                      action.apply((V)v);
5096                tryComplete();
5112              } catch (Throwable ex) {
5113                  return tryCompleteComputation(ex);
5114              }
5115 <            while (rights != null && rights.tryUnfork()) {
5101 <                rights.exec();
5102 <                rights = rights.nextRight;
5103 <            }
5115 >            tryComplete(subtasks);
5116              return false;
5117          }
5118      }
5119  
5120      @SuppressWarnings("serial") static final class ForEachEntryTask<K,V>
5121 <        extends BulkTask<K,V,Void> {
5110 <        ForEachEntryTask<K,V> nextRight;
5121 >        extends BulkAction<K,V,Void> {
5122          final Action<Entry<K,V>> action;
5123          ForEachEntryTask
5124              (ConcurrentHashMap<K,V> m, BulkTask<K,V,?> p, int b,
5125 <             ForEachEntryTask<K,V> nextRight,
5125 >             ForEachEntryTask<K,V> nextTask,
5126               Action<Entry<K,V>> action) {
5127 <            super(m, p, b);
5117 <            this.nextRight = nextRight;
5127 >            super(m, p, b, nextTask);
5128              this.action = action;
5129          }
5130          @SuppressWarnings("unchecked") public final boolean exec() {
5131              final Action<Entry<K,V>> action = this.action;
5132              if (action == null)
5133                  return abortOnNullFunction();
5134 <            ForEachEntryTask<K,V> rights = null;
5134 >            ForEachEntryTask<K,V> subtasks = null;
5135              try {
5136                  int b = batch(), c;
5137                  while (b > 1 && baseIndex != baseLimit) {
5138                      do {} while (!casPending(c = pending, c+1));
5139 <                    (rights = new ForEachEntryTask<K,V>
5140 <                     (map, this, b >>>= 1, rights, action)).fork();
5139 >                    (subtasks = new ForEachEntryTask<K,V>
5140 >                     (map, this, b >>>= 1, subtasks, action)).fork();
5141                  }
5142                  Object v;
5143                  while ((v = advance()) != null)
5144                      action.apply(entryFor((K)nextKey, (V)v));
5135                tryComplete();
5145              } catch (Throwable ex) {
5146                  return tryCompleteComputation(ex);
5147              }
5148 <            while (rights != null && rights.tryUnfork()) {
5140 <                rights.exec();
5141 <                rights = rights.nextRight;
5142 <            }
5148 >            tryComplete(subtasks);
5149              return false;
5150          }
5151      }
5152  
5153      @SuppressWarnings("serial") static final class ForEachMappingTask<K,V>
5154 <        extends BulkTask<K,V,Void> {
5149 <        ForEachMappingTask<K,V> nextRight;
5154 >        extends BulkAction<K,V,Void> {
5155          final BiAction<K,V> action;
5156          ForEachMappingTask
5157              (ConcurrentHashMap<K,V> m, BulkTask<K,V,?> p, int b,
5158 <             ForEachMappingTask<K,V> nextRight,
5158 >             ForEachMappingTask<K,V> nextTask,
5159               BiAction<K,V> action) {
5160 <            super(m, p, b);
5156 <            this.nextRight = nextRight;
5160 >            super(m, p, b, nextTask);
5161              this.action = action;
5162          }
5163          @SuppressWarnings("unchecked") public final boolean exec() {
5164              final BiAction<K,V> action = this.action;
5165              if (action == null)
5166                  return abortOnNullFunction();
5167 <            ForEachMappingTask<K,V> rights = null;
5167 >            ForEachMappingTask<K,V> subtasks = null;
5168              try {
5169                  int b = batch(), c;
5170                  while (b > 1 && baseIndex != baseLimit) {
5171                      do {} while (!casPending(c = pending, c+1));
5172 <                    (rights = new ForEachMappingTask<K,V>
5173 <                     (map, this, b >>>= 1, rights, action)).fork();
5172 >                    (subtasks = new ForEachMappingTask<K,V>
5173 >                     (map, this, b >>>= 1, subtasks, action)).fork();
5174                  }
5175                  Object v;
5176                  while ((v = advance()) != null)
5177                      action.apply((K)nextKey, (V)v);
5174                tryComplete();
5178              } catch (Throwable ex) {
5179                  return tryCompleteComputation(ex);
5180              }
5181 <            while (rights != null && rights.tryUnfork()) {
5179 <                rights.exec();
5180 <                rights = rights.nextRight;
5181 <            }
5181 >            tryComplete(subtasks);
5182              return false;
5183          }
5184      }
5185  
5186      @SuppressWarnings("serial") static final class ForEachTransformedKeyTask<K,V,U>
5187 <        extends BulkTask<K,V,Void> {
5188 <        ForEachTransformedKeyTask<K,V,U> nextRight;
5187 >        extends BulkAction<K,V,Void> {
5188          final Fun<? super K, ? extends U> transformer;
5189          final Action<U> action;
5190          ForEachTransformedKeyTask
5191              (ConcurrentHashMap<K,V> m, BulkTask<K,V,?> p, int b,
5192 <             ForEachTransformedKeyTask<K,V,U> nextRight,
5192 >             ForEachTransformedKeyTask<K,V,U> nextTask,
5193               Fun<? super K, ? extends U> transformer,
5194               Action<U> action) {
5195 <            super(m, p, b);
5197 <            this.nextRight = nextRight;
5195 >            super(m, p, b, nextTask);
5196              this.transformer = transformer;
5197              this.action = action;
5198  
# Line 5205 | Line 5203 | public class ConcurrentHashMap<K, V>
5203              final Action<U> action = this.action;
5204              if (transformer == null || action == null)
5205                  return abortOnNullFunction();
5206 <            ForEachTransformedKeyTask<K,V,U> rights = null;
5206 >            ForEachTransformedKeyTask<K,V,U> subtasks = null;
5207              try {
5208                  int b = batch(), c;
5209                  while (b > 1 && baseIndex != baseLimit) {
5210                      do {} while (!casPending(c = pending, c+1));
5211 <                    (rights = new ForEachTransformedKeyTask<K,V,U>
5212 <                     (map, this, b >>>= 1, rights, transformer, action)).fork();
5211 >                    (subtasks = new ForEachTransformedKeyTask<K,V,U>
5212 >                     (map, this, b >>>= 1, subtasks, transformer, action)).fork();
5213                  }
5214                  U u;
5215                  while (advance() != null) {
5216                      if ((u = transformer.apply((K)nextKey)) != null)
5217                          action.apply(u);
5218                  }
5221                tryComplete();
5219              } catch (Throwable ex) {
5220                  return tryCompleteComputation(ex);
5221              }
5222 <            while (rights != null && rights.tryUnfork()) {
5226 <                rights.exec();
5227 <                rights = rights.nextRight;
5228 <            }
5222 >            tryComplete(subtasks);
5223              return false;
5224          }
5225      }
5226  
5227      @SuppressWarnings("serial") static final class ForEachTransformedValueTask<K,V,U>
5228 <        extends BulkTask<K,V,Void> {
5235 <        ForEachTransformedValueTask<K,V,U> nextRight;
5228 >        extends BulkAction<K,V,Void> {
5229          final Fun<? super V, ? extends U> transformer;
5230          final Action<U> action;
5231          ForEachTransformedValueTask
5232              (ConcurrentHashMap<K,V> m, BulkTask<K,V,?> p, int b,
5233 <             ForEachTransformedValueTask<K,V,U> nextRight,
5233 >             ForEachTransformedValueTask<K,V,U> nextTask,
5234               Fun<? super V, ? extends U> transformer,
5235               Action<U> action) {
5236 <            super(m, p, b);
5244 <            this.nextRight = nextRight;
5236 >            super(m, p, b, nextTask);
5237              this.transformer = transformer;
5238              this.action = action;
5239  
# Line 5252 | Line 5244 | public class ConcurrentHashMap<K, V>
5244              final Action<U> action = this.action;
5245              if (transformer == null || action == null)
5246                  return abortOnNullFunction();
5247 <            ForEachTransformedValueTask<K,V,U> rights = null;
5247 >            ForEachTransformedValueTask<K,V,U> subtasks = null;
5248              try {
5249                  int b = batch(), c;
5250                  while (b > 1 && baseIndex != baseLimit) {
5251                      do {} while (!casPending(c = pending, c+1));
5252 <                    (rights = new ForEachTransformedValueTask<K,V,U>
5253 <                     (map, this, b >>>= 1, rights, transformer, action)).fork();
5252 >                    (subtasks = new ForEachTransformedValueTask<K,V,U>
5253 >                     (map, this, b >>>= 1, subtasks, transformer, action)).fork();
5254                  }
5255                  Object v; U u;
5256                  while ((v = advance()) != null) {
5257                      if ((u = transformer.apply((V)v)) != null)
5258                          action.apply(u);
5259                  }
5268                tryComplete();
5260              } catch (Throwable ex) {
5261                  return tryCompleteComputation(ex);
5262              }
5263 <            while (rights != null && rights.tryUnfork()) {
5273 <                rights.exec();
5274 <                rights = rights.nextRight;
5275 <            }
5263 >            tryComplete(subtasks);
5264              return false;
5265          }
5266      }
5267  
5268      @SuppressWarnings("serial") static final class ForEachTransformedEntryTask<K,V,U>
5269 <        extends BulkTask<K,V,Void> {
5282 <        ForEachTransformedEntryTask<K,V,U> nextRight;
5269 >        extends BulkAction<K,V,Void> {
5270          final Fun<Map.Entry<K,V>, ? extends U> transformer;
5271          final Action<U> action;
5272          ForEachTransformedEntryTask
5273              (ConcurrentHashMap<K,V> m, BulkTask<K,V,?> p, int b,
5274 <             ForEachTransformedEntryTask<K,V,U> nextRight,
5274 >             ForEachTransformedEntryTask<K,V,U> nextTask,
5275               Fun<Map.Entry<K,V>, ? extends U> transformer,
5276               Action<U> action) {
5277 <            super(m, p, b);
5291 <            this.nextRight = nextRight;
5277 >            super(m, p, b, nextTask);
5278              this.transformer = transformer;
5279              this.action = action;
5280  
# Line 5299 | Line 5285 | public class ConcurrentHashMap<K, V>
5285              final Action<U> action = this.action;
5286              if (transformer == null || action == null)
5287                  return abortOnNullFunction();
5288 <            ForEachTransformedEntryTask<K,V,U> rights = null;
5288 >            ForEachTransformedEntryTask<K,V,U> subtasks = null;
5289              try {
5290                  int b = batch(), c;
5291                  while (b > 1 && baseIndex != baseLimit) {
5292                      do {} while (!casPending(c = pending, c+1));
5293 <                    (rights = new ForEachTransformedEntryTask<K,V,U>
5294 <                     (map, this, b >>>= 1, rights, transformer, action)).fork();
5293 >                    (subtasks = new ForEachTransformedEntryTask<K,V,U>
5294 >                     (map, this, b >>>= 1, subtasks, transformer, action)).fork();
5295                  }
5296                  Object v; U u;
5297                  while ((v = advance()) != null) {
5298                      if ((u = transformer.apply(entryFor((K)nextKey, (V)v))) != null)
5299                          action.apply(u);
5300                  }
5315                tryComplete();
5301              } catch (Throwable ex) {
5302                  return tryCompleteComputation(ex);
5303              }
5304 <            while (rights != null && rights.tryUnfork()) {
5320 <                rights.exec();
5321 <                rights = rights.nextRight;
5322 <            }
5304 >            tryComplete(subtasks);
5305              return false;
5306          }
5307      }
5308  
5309      @SuppressWarnings("serial") static final class ForEachTransformedMappingTask<K,V,U>
5310 <        extends BulkTask<K,V,Void> {
5329 <        ForEachTransformedMappingTask<K,V,U> nextRight;
5310 >        extends BulkAction<K,V,Void> {
5311          final BiFun<? super K, ? super V, ? extends U> transformer;
5312          final Action<U> action;
5313          ForEachTransformedMappingTask
5314              (ConcurrentHashMap<K,V> m, BulkTask<K,V,?> p, int b,
5315 <             ForEachTransformedMappingTask<K,V,U> nextRight,
5315 >             ForEachTransformedMappingTask<K,V,U> nextTask,
5316               BiFun<? super K, ? super V, ? extends U> transformer,
5317               Action<U> action) {
5318 <            super(m, p, b);
5338 <            this.nextRight = nextRight;
5318 >            super(m, p, b, nextTask);
5319              this.transformer = transformer;
5320              this.action = action;
5321  
# Line 5346 | Line 5326 | public class ConcurrentHashMap<K, V>
5326              final Action<U> action = this.action;
5327              if (transformer == null || action == null)
5328                  return abortOnNullFunction();
5329 <            ForEachTransformedMappingTask<K,V,U> rights = null;
5329 >            ForEachTransformedMappingTask<K,V,U> subtasks = null;
5330              try {
5331                  int b = batch(), c;
5332                  while (b > 1 && baseIndex != baseLimit) {
5333                      do {} while (!casPending(c = pending, c+1));
5334 <                    (rights = new ForEachTransformedMappingTask<K,V,U>
5335 <                     (map, this, b >>>= 1, rights, transformer, action)).fork();
5334 >                    (subtasks = new ForEachTransformedMappingTask<K,V,U>
5335 >                     (map, this, b >>>= 1, subtasks, transformer, action)).fork();
5336                  }
5337                  Object v; U u;
5338                  while ((v = advance()) != null) {
5339                      if ((u = transformer.apply((K)nextKey, (V)v)) != null)
5340                          action.apply(u);
5341                  }
5362                tryComplete();
5342              } catch (Throwable ex) {
5343                  return tryCompleteComputation(ex);
5344              }
5345 <            while (rights != null && rights.tryUnfork()) {
5367 <                rights.exec();
5368 <                rights = rights.nextRight;
5369 <            }
5345 >            tryComplete(subtasks);
5346              return false;
5347          }
5348      }
5349  
5350      @SuppressWarnings("serial") static final class SearchKeysTask<K,V,U>
5351 <        extends BulkTask<K,V,U> {
5376 <        SearchKeysTask<K,V,U> nextRight;
5351 >        extends BulkAction<K,V,U> {
5352          final Fun<? super K, ? extends U> searchFunction;
5353          final AtomicReference<U> result;
5354          SearchKeysTask
5355              (ConcurrentHashMap<K,V> m, BulkTask<K,V,?> p, int b,
5356 <             SearchKeysTask<K,V,U> nextRight,
5356 >             SearchKeysTask<K,V,U> nextTask,
5357               Fun<? super K, ? extends U> searchFunction,
5358               AtomicReference<U> result) {
5359 <            super(m, p, b);
5385 <            this.nextRight = nextRight;
5359 >            super(m, p, b, nextTask);
5360              this.searchFunction = searchFunction; this.result = result;
5361          }
5362          @SuppressWarnings("unchecked") public final boolean exec() {
# Line 5391 | Line 5365 | public class ConcurrentHashMap<K, V>
5365                  this.searchFunction;
5366              if (searchFunction == null || result == null)
5367                  return abortOnNullFunction();
5368 <            SearchKeysTask<K,V,U> rights = null;
5368 >            SearchKeysTask<K,V,U> subtasks = null;
5369              try {
5370                  int b = batch(), c;
5371                  while (b > 1 && baseIndex != baseLimit && result.get() == null) {
5372                      do {} while (!casPending(c = pending, c+1));
5373 <                    (rights = new SearchKeysTask<K,V,U>
5374 <                     (map, this, b >>>= 1, rights, searchFunction, result)).fork();
5373 >                    (subtasks = new SearchKeysTask<K,V,U>
5374 >                     (map, this, b >>>= 1, subtasks, searchFunction, result)).fork();
5375                  }
5376                  U u;
5377                  while (result.get() == null && advance() != null) {
# Line 5407 | Line 5381 | public class ConcurrentHashMap<K, V>
5381                          break;
5382                      }
5383                  }
5410                tryComplete();
5384              } catch (Throwable ex) {
5385                  return tryCompleteComputation(ex);
5386              }
5387 <            while (rights != null && result.get() == null && rights.tryUnfork()) {
5415 <                rights.exec();
5416 <                rights = rights.nextRight;
5417 <            }
5387 >            tryComplete(subtasks);
5388              return false;
5389          }
5390          public final U getRawResult() { return result.get(); }
5391      }
5392  
5393      @SuppressWarnings("serial") static final class SearchValuesTask<K,V,U>
5394 <        extends BulkTask<K,V,U> {
5425 <        SearchValuesTask<K,V,U> nextRight;
5394 >        extends BulkAction<K,V,U> {
5395          final Fun<? super V, ? extends U> searchFunction;
5396          final AtomicReference<U> result;
5397          SearchValuesTask
5398              (ConcurrentHashMap<K,V> m, BulkTask<K,V,?> p, int b,
5399 <             SearchValuesTask<K,V,U> nextRight,
5399 >             SearchValuesTask<K,V,U> nextTask,
5400               Fun<? super V, ? extends U> searchFunction,
5401               AtomicReference<U> result) {
5402 <            super(m, p, b);
5434 <            this.nextRight = nextRight;
5402 >            super(m, p, b, nextTask);
5403              this.searchFunction = searchFunction; this.result = result;
5404          }
5405          @SuppressWarnings("unchecked") public final boolean exec() {
# Line 5440 | Line 5408 | public class ConcurrentHashMap<K, V>
5408                  this.searchFunction;
5409              if (searchFunction == null || result == null)
5410                  return abortOnNullFunction();
5411 <            SearchValuesTask<K,V,U> rights = null;
5411 >            SearchValuesTask<K,V,U> subtasks = null;
5412              try {
5413                  int b = batch(), c;
5414                  while (b > 1 && baseIndex != baseLimit && result.get() == null) {
5415                      do {} while (!casPending(c = pending, c+1));
5416 <                    (rights = new SearchValuesTask<K,V,U>
5417 <                     (map, this, b >>>= 1, rights, searchFunction, result)).fork();
5416 >                    (subtasks = new SearchValuesTask<K,V,U>
5417 >                     (map, this, b >>>= 1, subtasks, searchFunction, result)).fork();
5418                  }
5419                  Object v; U u;
5420                  while (result.get() == null && (v = advance()) != null) {
# Line 5456 | Line 5424 | public class ConcurrentHashMap<K, V>
5424                          break;
5425                      }
5426                  }
5459                tryComplete();
5427              } catch (Throwable ex) {
5428                  return tryCompleteComputation(ex);
5429              }
5430 <            while (rights != null && result.get() == null && rights.tryUnfork()) {
5464 <                rights.exec();
5465 <                rights = rights.nextRight;
5466 <            }
5430 >            tryComplete(subtasks);
5431              return false;
5432          }
5433          public final U getRawResult() { return result.get(); }
5434      }
5435  
5436      @SuppressWarnings("serial") static final class SearchEntriesTask<K,V,U>
5437 <        extends BulkTask<K,V,U> {
5474 <        SearchEntriesTask<K,V,U> nextRight;
5437 >        extends BulkAction<K,V,U> {
5438          final Fun<Entry<K,V>, ? extends U> searchFunction;
5439          final AtomicReference<U> result;
5440          SearchEntriesTask
5441              (ConcurrentHashMap<K,V> m, BulkTask<K,V,?> p, int b,
5442 <             SearchEntriesTask<K,V,U> nextRight,
5442 >             SearchEntriesTask<K,V,U> nextTask,
5443               Fun<Entry<K,V>, ? extends U> searchFunction,
5444               AtomicReference<U> result) {
5445 <            super(m, p, b);
5483 <            this.nextRight = nextRight;
5445 >            super(m, p, b, nextTask);
5446              this.searchFunction = searchFunction; this.result = result;
5447          }
5448          @SuppressWarnings("unchecked") public final boolean exec() {
# Line 5489 | Line 5451 | public class ConcurrentHashMap<K, V>
5451                  this.searchFunction;
5452              if (searchFunction == null || result == null)
5453                  return abortOnNullFunction();
5454 <            SearchEntriesTask<K,V,U> rights = null;
5454 >            SearchEntriesTask<K,V,U> subtasks = null;
5455              try {
5456                  int b = batch(), c;
5457                  while (b > 1 && baseIndex != baseLimit && result.get() == null) {
5458                      do {} while (!casPending(c = pending, c+1));
5459 <                    (rights = new SearchEntriesTask<K,V,U>
5460 <                     (map, this, b >>>= 1, rights, searchFunction, result)).fork();
5459 >                    (subtasks = new SearchEntriesTask<K,V,U>
5460 >                     (map, this, b >>>= 1, subtasks, searchFunction, result)).fork();
5461                  }
5462                  Object v; U u;
5463                  while (result.get() == null && (v = advance()) != null) {
# Line 5505 | Line 5467 | public class ConcurrentHashMap<K, V>
5467                          break;
5468                      }
5469                  }
5508                tryComplete();
5470              } catch (Throwable ex) {
5471                  return tryCompleteComputation(ex);
5472              }
5473 <            while (rights != null && result.get() == null && rights.tryUnfork()) {
5513 <                rights.exec();
5514 <                rights = rights.nextRight;
5515 <            }
5473 >            tryComplete(subtasks);
5474              return false;
5475          }
5476          public final U getRawResult() { return result.get(); }
5477      }
5478  
5479      @SuppressWarnings("serial") static final class SearchMappingsTask<K,V,U>
5480 <        extends BulkTask<K,V,U> {
5523 <        SearchMappingsTask<K,V,U> nextRight;
5480 >        extends BulkAction<K,V,U> {
5481          final BiFun<? super K, ? super V, ? extends U> searchFunction;
5482          final AtomicReference<U> result;
5483          SearchMappingsTask
5484              (ConcurrentHashMap<K,V> m, BulkTask<K,V,?> p, int b,
5485 <             SearchMappingsTask<K,V,U> nextRight,
5485 >             SearchMappingsTask<K,V,U> nextTask,
5486               BiFun<? super K, ? super V, ? extends U> searchFunction,
5487               AtomicReference<U> result) {
5488 <            super(m, p, b);
5532 <            this.nextRight = nextRight;
5488 >            super(m, p, b, nextTask);
5489              this.searchFunction = searchFunction; this.result = result;
5490          }
5491          @SuppressWarnings("unchecked") public final boolean exec() {
# Line 5538 | Line 5494 | public class ConcurrentHashMap<K, V>
5494                  this.searchFunction;
5495              if (searchFunction == null || result == null)
5496                  return abortOnNullFunction();
5497 <            SearchMappingsTask<K,V,U> rights = null;
5497 >            SearchMappingsTask<K,V,U> subtasks = null;
5498              try {
5499                  int b = batch(), c;
5500                  while (b > 1 && baseIndex != baseLimit && result.get() == null) {
5501                      do {} while (!casPending(c = pending, c+1));
5502 <                    (rights = new SearchMappingsTask<K,V,U>
5503 <                     (map, this, b >>>= 1, rights, searchFunction, result)).fork();
5502 >                    (subtasks = new SearchMappingsTask<K,V,U>
5503 >                     (map, this, b >>>= 1, subtasks, searchFunction, result)).fork();
5504                  }
5505                  Object v; U u;
5506                  while (result.get() == null && (v = advance()) != null) {
# Line 5554 | Line 5510 | public class ConcurrentHashMap<K, V>
5510                          break;
5511                      }
5512                  }
5557                tryComplete();
5513              } catch (Throwable ex) {
5514                  return tryCompleteComputation(ex);
5515              }
5516 <            while (rights != null && result.get() == null && rights.tryUnfork()) {
5562 <                rights.exec();
5563 <                rights = rights.nextRight;
5564 <            }
5516 >            tryComplete(subtasks);
5517              return false;
5518          }
5519          public final U getRawResult() { return result.get(); }
# Line 5616 | Line 5568 | public class ConcurrentHashMap<K, V>
5568              } catch (Throwable ex) {
5569                  return tryCompleteComputation(ex);
5570              }
5571 <            for (ReduceKeysTask<K,V> s = rights; s != null && s.tryUnfork(); s = s.nextRight)
5572 <                s.exec();
5571 >            ReduceKeysTask<K,V> s = rights;
5572 >            if (s != null && !inForkJoinPool()) {
5573 >                do  {
5574 >                    if (s.tryUnfork())
5575 >                        s.exec();
5576 >                } while ((s = s.nextRight) != null);
5577 >            }
5578              return false;
5579          }
5580          public final K getRawResult() { return result; }
# Line 5673 | Line 5630 | public class ConcurrentHashMap<K, V>
5630              } catch (Throwable ex) {
5631                  return tryCompleteComputation(ex);
5632              }
5633 <            for (ReduceValuesTask<K,V> s = rights; s != null && s.tryUnfork(); s = s.nextRight)
5634 <                s.exec();
5633 >            ReduceValuesTask<K,V> s = rights;
5634 >            if (s != null && !inForkJoinPool()) {
5635 >                do  {
5636 >                    if (s.tryUnfork())
5637 >                        s.exec();
5638 >                } while ((s = s.nextRight) != null);
5639 >            }
5640              return false;
5641          }
5642          public final V getRawResult() { return result; }
# Line 5730 | Line 5692 | public class ConcurrentHashMap<K, V>
5692              } catch (Throwable ex) {
5693                  return tryCompleteComputation(ex);
5694              }
5695 <            for (ReduceEntriesTask<K,V> s = rights; s != null && s.tryUnfork(); s = s.nextRight)
5696 <                s.exec();
5695 >            ReduceEntriesTask<K,V> s = rights;
5696 >            if (s != null && !inForkJoinPool()) {
5697 >                do  {
5698 >                    if (s.tryUnfork())
5699 >                        s.exec();
5700 >                } while ((s = s.nextRight) != null);
5701 >            }
5702              return false;
5703          }
5704          public final Map.Entry<K,V> getRawResult() { return result; }
# Line 5791 | Line 5758 | public class ConcurrentHashMap<K, V>
5758              } catch (Throwable ex) {
5759                  return tryCompleteComputation(ex);
5760              }
5761 <            for (MapReduceKeysTask<K,V,U> s = rights; s != null && s.tryUnfork(); s = s.nextRight)
5762 <                s.exec();
5761 >            MapReduceKeysTask<K,V,U> s = rights;
5762 >            if (s != null && !inForkJoinPool()) {
5763 >                do  {
5764 >                    if (s.tryUnfork())
5765 >                        s.exec();
5766 >                } while ((s = s.nextRight) != null);
5767 >            }
5768              return false;
5769          }
5770          public final U getRawResult() { return result; }
# Line 5853 | Line 5825 | public class ConcurrentHashMap<K, V>
5825              } catch (Throwable ex) {
5826                  return tryCompleteComputation(ex);
5827              }
5828 <            for (MapReduceValuesTask<K,V,U> s = rights; s != null && s.tryUnfork(); s = s.nextRight)
5829 <                s.exec();
5828 >            MapReduceValuesTask<K,V,U> s = rights;
5829 >            if (s != null && !inForkJoinPool()) {
5830 >                do  {
5831 >                    if (s.tryUnfork())
5832 >                        s.exec();
5833 >                } while ((s = s.nextRight) != null);
5834 >            }
5835              return false;
5836          }
5837          public final U getRawResult() { return result; }
# Line 5915 | Line 5892 | public class ConcurrentHashMap<K, V>
5892              } catch (Throwable ex) {
5893                  return tryCompleteComputation(ex);
5894              }
5895 <            for (MapReduceEntriesTask<K,V,U> s = rights; s != null && s.tryUnfork(); s = s.nextRight)
5896 <                s.exec();
5895 >            MapReduceEntriesTask<K,V,U> s = rights;
5896 >            if (s != null && !inForkJoinPool()) {
5897 >                do  {
5898 >                    if (s.tryUnfork())
5899 >                        s.exec();
5900 >                } while ((s = s.nextRight) != null);
5901 >            }
5902              return false;
5903          }
5904          public final U getRawResult() { return result; }
# Line 5977 | Line 5959 | public class ConcurrentHashMap<K, V>
5959              } catch (Throwable ex) {
5960                  return tryCompleteComputation(ex);
5961              }
5962 <            for (MapReduceMappingsTask<K,V,U> s = rights; s != null && s.tryUnfork(); s = s.nextRight)
5963 <                s.exec();
5962 >            MapReduceMappingsTask<K,V,U> s = rights;
5963 >            if (s != null && !inForkJoinPool()) {
5964 >                do  {
5965 >                    if (s.tryUnfork())
5966 >                        s.exec();
5967 >                } while ((s = s.nextRight) != null);
5968 >            }
5969              return false;
5970          }
5971          public final U getRawResult() { return result; }
# Line 6037 | Line 6024 | public class ConcurrentHashMap<K, V>
6024              } catch (Throwable ex) {
6025                  return tryCompleteComputation(ex);
6026              }
6027 <            for (MapReduceKeysToDoubleTask<K,V> s = rights; s != null && s.tryUnfork(); s = s.nextRight)
6028 <                s.exec();
6027 >            MapReduceKeysToDoubleTask<K,V> s = rights;
6028 >            if (s != null && !inForkJoinPool()) {
6029 >                do  {
6030 >                    if (s.tryUnfork())
6031 >                        s.exec();
6032 >                } while ((s = s.nextRight) != null);
6033 >            }
6034              return false;
6035          }
6036          public final Double getRawResult() { return result; }
# Line 6098 | Line 6090 | public class ConcurrentHashMap<K, V>
6090              } catch (Throwable ex) {
6091                  return tryCompleteComputation(ex);
6092              }
6093 <            for (MapReduceValuesToDoubleTask<K,V> s = rights; s != null && s.tryUnfork(); s = s.nextRight)
6094 <                s.exec();
6093 >            MapReduceValuesToDoubleTask<K,V> s = rights;
6094 >            if (s != null && !inForkJoinPool()) {
6095 >                do  {
6096 >                    if (s.tryUnfork())
6097 >                        s.exec();
6098 >                } while ((s = s.nextRight) != null);
6099 >            }
6100              return false;
6101          }
6102          public final Double getRawResult() { return result; }
# Line 6159 | Line 6156 | public class ConcurrentHashMap<K, V>
6156              } catch (Throwable ex) {
6157                  return tryCompleteComputation(ex);
6158              }
6159 <            for (MapReduceEntriesToDoubleTask<K,V> s = rights; s != null && s.tryUnfork(); s = s.nextRight)
6160 <                s.exec();
6159 >            MapReduceEntriesToDoubleTask<K,V> s = rights;
6160 >            if (s != null && !inForkJoinPool()) {
6161 >                do  {
6162 >                    if (s.tryUnfork())
6163 >                        s.exec();
6164 >                } while ((s = s.nextRight) != null);
6165 >            }
6166              return false;
6167          }
6168          public final Double getRawResult() { return result; }
# Line 6220 | Line 6222 | public class ConcurrentHashMap<K, V>
6222              } catch (Throwable ex) {
6223                  return tryCompleteComputation(ex);
6224              }
6225 <            for (MapReduceMappingsToDoubleTask<K,V> s = rights; s != null && s.tryUnfork(); s = s.nextRight)
6226 <                s.exec();
6225 >            MapReduceMappingsToDoubleTask<K,V> s = rights;
6226 >            if (s != null && !inForkJoinPool()) {
6227 >                do  {
6228 >                    if (s.tryUnfork())
6229 >                        s.exec();
6230 >                } while ((s = s.nextRight) != null);
6231 >            }
6232              return false;
6233          }
6234          public final Double getRawResult() { return result; }
# Line 6280 | Line 6287 | public class ConcurrentHashMap<K, V>
6287              } catch (Throwable ex) {
6288                  return tryCompleteComputation(ex);
6289              }
6290 <            for (MapReduceKeysToLongTask<K,V> s = rights; s != null && s.tryUnfork(); s = s.nextRight)
6291 <                s.exec();
6290 >            MapReduceKeysToLongTask<K,V> s = rights;
6291 >            if (s != null && !inForkJoinPool()) {
6292 >                do  {
6293 >                    if (s.tryUnfork())
6294 >                        s.exec();
6295 >                } while ((s = s.nextRight) != null);
6296 >            }
6297              return false;
6298          }
6299          public final Long getRawResult() { return result; }
# Line 6341 | Line 6353 | public class ConcurrentHashMap<K, V>
6353              } catch (Throwable ex) {
6354                  return tryCompleteComputation(ex);
6355              }
6356 <            for (MapReduceValuesToLongTask<K,V> s = rights; s != null && s.tryUnfork(); s = s.nextRight)
6357 <                s.exec();
6356 >            MapReduceValuesToLongTask<K,V> s = rights;
6357 >            if (s != null && !inForkJoinPool()) {
6358 >                do  {
6359 >                    if (s.tryUnfork())
6360 >                        s.exec();
6361 >                } while ((s = s.nextRight) != null);
6362 >            }
6363              return false;
6364          }
6365          public final Long getRawResult() { return result; }
# Line 6402 | Line 6419 | public class ConcurrentHashMap<K, V>
6419              } catch (Throwable ex) {
6420                  return tryCompleteComputation(ex);
6421              }
6422 <            for (MapReduceEntriesToLongTask<K,V> s = rights; s != null && s.tryUnfork(); s = s.nextRight)
6423 <                s.exec();
6422 >            MapReduceEntriesToLongTask<K,V> s = rights;
6423 >            if (s != null && !inForkJoinPool()) {
6424 >                do  {
6425 >                    if (s.tryUnfork())
6426 >                        s.exec();
6427 >                } while ((s = s.nextRight) != null);
6428 >            }
6429              return false;
6430          }
6431          public final Long getRawResult() { return result; }
# Line 6463 | Line 6485 | public class ConcurrentHashMap<K, V>
6485              } catch (Throwable ex) {
6486                  return tryCompleteComputation(ex);
6487              }
6488 <            for (MapReduceMappingsToLongTask<K,V> s = rights; s != null && s.tryUnfork(); s = s.nextRight)
6489 <                s.exec();
6488 >            MapReduceMappingsToLongTask<K,V> s = rights;
6489 >            if (s != null && !inForkJoinPool()) {
6490 >                do  {
6491 >                    if (s.tryUnfork())
6492 >                        s.exec();
6493 >                } while ((s = s.nextRight) != null);
6494 >            }
6495              return false;
6496          }
6497          public final Long getRawResult() { return result; }
# Line 6523 | Line 6550 | public class ConcurrentHashMap<K, V>
6550              } catch (Throwable ex) {
6551                  return tryCompleteComputation(ex);
6552              }
6553 <            for (MapReduceKeysToIntTask<K,V> s = rights; s != null && s.tryUnfork(); s = s.nextRight)
6554 <                s.exec();
6553 >            MapReduceKeysToIntTask<K,V> s = rights;
6554 >            if (s != null && !inForkJoinPool()) {
6555 >                do  {
6556 >                    if (s.tryUnfork())
6557 >                        s.exec();
6558 >                } while ((s = s.nextRight) != null);
6559 >            }
6560              return false;
6561          }
6562          public final Integer getRawResult() { return result; }
# Line 6584 | Line 6616 | public class ConcurrentHashMap<K, V>
6616              } catch (Throwable ex) {
6617                  return tryCompleteComputation(ex);
6618              }
6619 <            for (MapReduceValuesToIntTask<K,V> s = rights; s != null && s.tryUnfork(); s = s.nextRight)
6620 <                s.exec();
6619 >            MapReduceValuesToIntTask<K,V> s = rights;
6620 >            if (s != null && !inForkJoinPool()) {
6621 >                do  {
6622 >                    if (s.tryUnfork())
6623 >                        s.exec();
6624 >                } while ((s = s.nextRight) != null);
6625 >            }
6626              return false;
6627          }
6628          public final Integer getRawResult() { return result; }
# Line 6645 | Line 6682 | public class ConcurrentHashMap<K, V>
6682              } catch (Throwable ex) {
6683                  return tryCompleteComputation(ex);
6684              }
6685 <            for (MapReduceEntriesToIntTask<K,V> s = rights; s != null && s.tryUnfork(); s = s.nextRight)
6686 <                s.exec();
6685 >            MapReduceEntriesToIntTask<K,V> s = rights;
6686 >            if (s != null && !inForkJoinPool()) {
6687 >                do  {
6688 >                    if (s.tryUnfork())
6689 >                        s.exec();
6690 >                } while ((s = s.nextRight) != null);
6691 >            }
6692              return false;
6693          }
6694          public final Integer getRawResult() { return result; }
# Line 6706 | Line 6748 | public class ConcurrentHashMap<K, V>
6748              } catch (Throwable ex) {
6749                  return tryCompleteComputation(ex);
6750              }
6751 <            for (MapReduceMappingsToIntTask<K,V> s = rights; s != null && s.tryUnfork(); s = s.nextRight)
6752 <                s.exec();
6751 >            MapReduceMappingsToIntTask<K,V> s = rights;
6752 >            if (s != null && !inForkJoinPool()) {
6753 >                do  {
6754 >                    if (s.tryUnfork())
6755 >                        s.exec();
6756 >                } while ((s = s.nextRight) != null);
6757 >            }
6758              return false;
6759          }
6760          public final Integer getRawResult() { return result; }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines