ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/jsr166e/ConcurrentHashMapV8.java
(Generate patch)

Comparing jsr166/src/jsr166e/ConcurrentHashMapV8.java (file contents):
Revision 1.87 by jsr166, Wed Jan 9 02:51:36 2013 UTC vs.
Revision 1.99 by jsr166, Fri Feb 15 22:20:46 2013 UTC

# Line 212 | Line 212 | import java.io.Serializable;
212   * @param <K> the type of keys maintained by this map
213   * @param <V> the type of mapped values
214   */
215 < public class ConcurrentHashMapV8<K, V>
216 <    implements ConcurrentMap<K, V>, Serializable {
215 > public class ConcurrentHashMapV8<K,V>
216 >    implements ConcurrentMap<K,V>, Serializable {
217      private static final long serialVersionUID = 7249069246763182397L;
218  
219      /**
# Line 1785 | Line 1785 | public class ConcurrentHashMapV8<K, V>
1785                              }
1786                          }
1787                          if (len != 0) {
1788 <                            if (len > 1)
1788 >                            if (len > 1) {
1789                                  addCount(delta, len);
1790 +                                delta = 0L;
1791 +                            }
1792                              break;
1793                          }
1794                      }
# Line 1975 | Line 1977 | public class ConcurrentHashMapV8<K, V>
1977          }
1978      }
1979  
1980 <    /*
1980 >    /**
1981       * Moves and/or copies the nodes in each bin to new table. See
1982       * above for explanation.
1983       */
# Line 2277 | Line 2279 | public class ConcurrentHashMapV8<K, V>
2279       */
2280      @SuppressWarnings("serial") static class Traverser<K,V,R>
2281          extends CountedCompleter<R> {
2282 <        final ConcurrentHashMapV8<K, V> map;
2282 >        final ConcurrentHashMapV8<K,V> map;
2283          Node<V> next;        // the next entry to use
2284          Object nextKey;      // cached key field of next
2285          V nextVal;           // cached val field of next
# Line 2289 | Line 2291 | public class ConcurrentHashMapV8<K, V>
2291          int batch;           // split control
2292  
2293          /** Creates iterator for all entries in the table. */
2294 <        Traverser(ConcurrentHashMapV8<K, V> map) {
2294 >        Traverser(ConcurrentHashMapV8<K,V> map) {
2295              this.map = map;
2296          }
2297  
# Line 2321 | Line 2323 | public class ConcurrentHashMapV8<K, V>
2323                  if (e != null)                  // advance past used/skipped node
2324                      e = e.next;
2325                  while (e == null) {             // get to next non-null bin
2326 <                    ConcurrentHashMapV8<K, V> m;
2326 >                    ConcurrentHashMapV8<K,V> m;
2327                      Node<V>[] t; int b, i, n; Object ek; //  must use locals
2328                      if ((t = tab) != null)
2329                          n = t.length;
# Line 2374 | Line 2376 | public class ConcurrentHashMapV8<K, V>
2376           * anyway.
2377           */
2378          final int preSplit() {
2379 <            ConcurrentHashMapV8<K, V> m; int b; Node<V>[] t;  ForkJoinPool pool;
2379 >            ConcurrentHashMapV8<K,V> m; int b; Node<V>[] t;  ForkJoinPool pool;
2380              if ((b = batch) < 0 && (m = map) != null) { // force initialization
2381                  if ((t = tab) == null && (t = tab = m.table) != null)
2382                      baseLimit = baseSize = t.length;
# Line 2685 | Line 2687 | public class ConcurrentHashMapV8<K, V>
2687       * memoized result, as in:
2688       *
2689       *  <pre> {@code
2690 <     * map.computeIfAbsent(key, new Fun<K, V>() {
2690 >     * map.computeIfAbsent(key, new Fun<K,V>() {
2691       *   public V map(K k) { return new Value(f(k)); }});}</pre>
2692       *
2693       * @param key key with which the specified value is to be associated
# Line 2892 | Line 2894 | public class ConcurrentHashMapV8<K, V>
2894       * course only appropriate if it is acceptable to use the same
2895       * value for all additions from this view.
2896       *
2897 <     * @param mappedValue the mapped value to use for any
2896 <     * additions.
2897 >     * @param mappedValue the mapped value to use for any additions
2898       * @return the set view
2899       * @throws NullPointerException if the mappedValue is null
2900       */
# Line 3067 | Line 3068 | public class ConcurrentHashMapV8<K, V>
3068      @SuppressWarnings("serial") static final class KeyIterator<K,V>
3069          extends Traverser<K,V,Object>
3070          implements Spliterator<K>, Enumeration<K> {
3071 <        KeyIterator(ConcurrentHashMapV8<K, V> map) { super(map); }
3072 <        KeyIterator(ConcurrentHashMapV8<K, V> map, Traverser<K,V,Object> it) {
3071 >        KeyIterator(ConcurrentHashMapV8<K,V> map) { super(map); }
3072 >        KeyIterator(ConcurrentHashMapV8<K,V> map, Traverser<K,V,Object> it) {
3073              super(map, it, -1);
3074          }
3075          public KeyIterator<K,V> split() {
# Line 3090 | Line 3091 | public class ConcurrentHashMapV8<K, V>
3091      @SuppressWarnings("serial") static final class ValueIterator<K,V>
3092          extends Traverser<K,V,Object>
3093          implements Spliterator<V>, Enumeration<V> {
3094 <        ValueIterator(ConcurrentHashMapV8<K, V> map) { super(map); }
3095 <        ValueIterator(ConcurrentHashMapV8<K, V> map, Traverser<K,V,Object> it) {
3094 >        ValueIterator(ConcurrentHashMapV8<K,V> map) { super(map); }
3095 >        ValueIterator(ConcurrentHashMapV8<K,V> map, Traverser<K,V,Object> it) {
3096              super(map, it, -1);
3097          }
3098          public ValueIterator<K,V> split() {
# Line 3114 | Line 3115 | public class ConcurrentHashMapV8<K, V>
3115      @SuppressWarnings("serial") static final class EntryIterator<K,V>
3116          extends Traverser<K,V,Object>
3117          implements Spliterator<Map.Entry<K,V>> {
3118 <        EntryIterator(ConcurrentHashMapV8<K, V> map) { super(map); }
3119 <        EntryIterator(ConcurrentHashMapV8<K, V> map, Traverser<K,V,Object> it) {
3118 >        EntryIterator(ConcurrentHashMapV8<K,V> map) { super(map); }
3119 >        EntryIterator(ConcurrentHashMapV8<K,V> map, Traverser<K,V,Object> it) {
3120              super(map, it, -1);
3121          }
3122          public EntryIterator<K,V> split() {
# Line 3137 | Line 3138 | public class ConcurrentHashMapV8<K, V>
3138      /**
3139       * Exported Entry for iterators
3140       */
3141 <    static final class MapEntry<K,V> implements Map.Entry<K, V> {
3141 >    static final class MapEntry<K,V> implements Map.Entry<K,V> {
3142          final K key; // non-null
3143          V val;       // non-null
3144 <        final ConcurrentHashMapV8<K, V> map;
3145 <        MapEntry(K key, V val, ConcurrentHashMapV8<K, V> map) {
3144 >        final ConcurrentHashMapV8<K,V> map;
3145 >        MapEntry(K key, V val, ConcurrentHashMapV8<K,V> map) {
3146              this.key = key;
3147              this.val = val;
3148              this.map = map;
# Line 3371 | Line 3372 | public class ConcurrentHashMapV8<K, V>
3372       * of each (key, value).
3373       *
3374       * @param transformer a function returning the transformation
3375 <     * for an element, or null of there is no transformation (in
3376 <     * which case the action is not applied).
3375 >     * for an element, or null if there is no transformation (in
3376 >     * which case the action is not applied)
3377       * @param action the action
3378       */
3379      @SuppressWarnings("unchecked") public <U> void forEachSequentially
# Line 3415 | Line 3416 | public class ConcurrentHashMapV8<K, V>
3416       * combine values, or null if none.
3417       *
3418       * @param transformer a function returning the transformation
3419 <     * for an element, or null of there is no transformation (in
3420 <     * which case it is not combined).
3419 >     * for an element, or null if there is no transformation (in
3420 >     * which case it is not combined)
3421       * @param reducer a commutative associative combining function
3422       * @return the result of accumulating the given transformation
3423       * of all (key, value) pairs
# Line 3528 | Line 3529 | public class ConcurrentHashMapV8<K, V>
3529       * of each key.
3530       *
3531       * @param transformer a function returning the transformation
3532 <     * for an element, or null of there is no transformation (in
3533 <     * which case the action is not applied).
3532 >     * for an element, or null if there is no transformation (in
3533 >     * which case the action is not applied)
3534       * @param action the action
3535       */
3536      @SuppressWarnings("unchecked") public <U> void forEachKeySequentially
# Line 3593 | Line 3594 | public class ConcurrentHashMapV8<K, V>
3594       * null if none.
3595       *
3596       * @param transformer a function returning the transformation
3597 <     * for an element, or null of there is no transformation (in
3598 <     * which case it is not combined).
3597 >     * for an element, or null if there is no transformation (in
3598 >     * which case it is not combined)
3599       * @param reducer a commutative associative combining function
3600       * @return the result of accumulating the given transformation
3601       * of all keys
# Line 3706 | Line 3707 | public class ConcurrentHashMapV8<K, V>
3707       * of each value.
3708       *
3709       * @param transformer a function returning the transformation
3710 <     * for an element, or null of there is no transformation (in
3711 <     * which case the action is not applied).
3710 >     * for an element, or null if there is no transformation (in
3711 >     * which case the action is not applied)
3712       */
3713      public <U> void forEachValueSequentially
3714          (Fun<? super V, ? extends U> transformer,
# Line 3766 | Line 3767 | public class ConcurrentHashMapV8<K, V>
3767       * null if none.
3768       *
3769       * @param transformer a function returning the transformation
3770 <     * for an element, or null of there is no transformation (in
3771 <     * which case it is not combined).
3770 >     * for an element, or null if there is no transformation (in
3771 >     * which case it is not combined)
3772       * @param reducer a commutative associative combining function
3773       * @return the result of accumulating the given transformation
3774       * of all values
# Line 3880 | Line 3881 | public class ConcurrentHashMapV8<K, V>
3881       * of each entry.
3882       *
3883       * @param transformer a function returning the transformation
3884 <     * for an element, or null of there is no transformation (in
3885 <     * which case the action is not applied).
3884 >     * for an element, or null if there is no transformation (in
3885 >     * which case the action is not applied)
3886       * @param action the action
3887       */
3888      @SuppressWarnings("unchecked") public <U> void forEachEntrySequentially
# Line 3943 | Line 3944 | public class ConcurrentHashMapV8<K, V>
3944       * or null if none.
3945       *
3946       * @param transformer a function returning the transformation
3947 <     * for an element, or null of there is no transformation (in
3948 <     * which case it is not combined).
3947 >     * for an element, or null if there is no transformation (in
3948 >     * which case it is not combined)
3949       * @param reducer a commutative associative combining function
3950       * @return the result of accumulating the given transformation
3951       * of all entries
# Line 4055 | Line 4056 | public class ConcurrentHashMapV8<K, V>
4056       * of each (key, value).
4057       *
4058       * @param transformer a function returning the transformation
4059 <     * for an element, or null of there is no transformation (in
4060 <     * which case the action is not applied).
4059 >     * for an element, or null if there is no transformation (in
4060 >     * which case the action is not applied)
4061       * @param action the action
4062       */
4063      public <U> void forEachInParallel
# Line 4090 | Line 4091 | public class ConcurrentHashMapV8<K, V>
4091       * combine values, or null if none.
4092       *
4093       * @param transformer a function returning the transformation
4094 <     * for an element, or null of there is no transformation (in
4095 <     * which case it is not combined).
4094 >     * for an element, or null if there is no transformation (in
4095 >     * which case it is not combined)
4096       * @param reducer a commutative associative combining function
4097       * @return the result of accumulating the given transformation
4098       * of all (key, value) pairs
# Line 4178 | Line 4179 | public class ConcurrentHashMapV8<K, V>
4179       * of each key.
4180       *
4181       * @param transformer a function returning the transformation
4182 <     * for an element, or null of there is no transformation (in
4183 <     * which case the action is not applied).
4182 >     * for an element, or null if there is no transformation (in
4183 >     * which case the action is not applied)
4184       * @param action the action
4185       */
4186      public <U> void forEachKeyInParallel
# Line 4227 | Line 4228 | public class ConcurrentHashMapV8<K, V>
4228       * null if none.
4229       *
4230       * @param transformer a function returning the transformation
4231 <     * for an element, or null of there is no transformation (in
4232 <     * which case it is not combined).
4231 >     * for an element, or null if there is no transformation (in
4232 >     * which case it is not combined)
4233       * @param reducer a commutative associative combining function
4234       * @return the result of accumulating the given transformation
4235       * of all keys
# Line 4315 | Line 4316 | public class ConcurrentHashMapV8<K, V>
4316       * of each value.
4317       *
4318       * @param transformer a function returning the transformation
4319 <     * for an element, or null of there is no transformation (in
4320 <     * which case the action is not applied).
4319 >     * for an element, or null if there is no transformation (in
4320 >     * which case the action is not applied)
4321       */
4322      public <U> void forEachValueInParallel
4323          (Fun<? super V, ? extends U> transformer,
# Line 4362 | Line 4363 | public class ConcurrentHashMapV8<K, V>
4363       * null if none.
4364       *
4365       * @param transformer a function returning the transformation
4366 <     * for an element, or null of there is no transformation (in
4367 <     * which case it is not combined).
4366 >     * for an element, or null if there is no transformation (in
4367 >     * which case it is not combined)
4368       * @param reducer a commutative associative combining function
4369       * @return the result of accumulating the given transformation
4370       * of all values
# Line 4450 | Line 4451 | public class ConcurrentHashMapV8<K, V>
4451       * of each entry.
4452       *
4453       * @param transformer a function returning the transformation
4454 <     * for an element, or null of there is no transformation (in
4455 <     * which case the action is not applied).
4454 >     * for an element, or null if there is no transformation (in
4455 >     * which case the action is not applied)
4456       * @param action the action
4457       */
4458      public <U> void forEachEntryInParallel
# Line 4498 | Line 4499 | public class ConcurrentHashMapV8<K, V>
4499       * or null if none.
4500       *
4501       * @param transformer a function returning the transformation
4502 <     * for an element, or null of there is no transformation (in
4503 <     * which case it is not combined).
4502 >     * for an element, or null if there is no transformation (in
4503 >     * which case it is not combined)
4504       * @param reducer a commutative associative combining function
4505       * @return the result of accumulating the given transformation
4506       * of all entries
# Line 4577 | Line 4578 | public class ConcurrentHashMapV8<K, V>
4578      /**
4579       * Base class for views.
4580       */
4581 <    static abstract class CHMView<K, V> {
4582 <        final ConcurrentHashMapV8<K, V> map;
4583 <        CHMView(ConcurrentHashMapV8<K, V> map)  { this.map = map; }
4581 >    abstract static class CHMView<K,V> {
4582 >        final ConcurrentHashMapV8<K,V> map;
4583 >        CHMView(ConcurrentHashMapV8<K,V> map)  { this.map = map; }
4584  
4585          /**
4586           * Returns the map backing this view.
# Line 4593 | Line 4594 | public class ConcurrentHashMapV8<K, V>
4594          public final void clear()               { map.clear(); }
4595  
4596          // implementations below rely on concrete classes supplying these
4597 <        abstract public Iterator<?> iterator();
4598 <        abstract public boolean contains(Object o);
4599 <        abstract public boolean remove(Object o);
4597 >        public abstract Iterator<?> iterator();
4598 >        public abstract boolean contains(Object o);
4599 >        public abstract boolean remove(Object o);
4600  
4601          private static final String oomeMsg = "Required array size too large";
4602  
# Line 4714 | Line 4715 | public class ConcurrentHashMapV8<K, V>
4715       * A view of a ConcurrentHashMapV8 as a {@link Set} of keys, in
4716       * which additions may optionally be enabled by mapping to a
4717       * common value.  This class cannot be directly instantiated. See
4718 <     * {@link #keySet}, {@link #keySet(Object)}, {@link #newKeySet()},
4718 >     * {@link #keySet()}, {@link #keySet(Object)}, {@link #newKeySet()},
4719       * {@link #newKeySet(int)}.
4720       */
4721      public static class KeySetView<K,V> extends CHMView<K,V>
4722          implements Set<K>, java.io.Serializable {
4723          private static final long serialVersionUID = 7249069246763182397L;
4724          private final V value;
4725 <        KeySetView(ConcurrentHashMapV8<K, V> map, V value) {  // non-public
4725 >        KeySetView(ConcurrentHashMapV8<K,V> map, V value) {  // non-public
4726              super(map);
4727              this.value = value;
4728          }
# Line 4731 | Line 4732 | public class ConcurrentHashMapV8<K, V>
4732           * or {@code null} if additions are not supported.
4733           *
4734           * @return the default mapped value for additions, or {@code null}
4735 <         * if not supported.
4735 >         * if not supported
4736           */
4737          public V getMappedValue() { return value; }
4738  
# Line 4755 | Line 4756 | public class ConcurrentHashMapV8<K, V>
4756              V v;
4757              if ((v = value) == null)
4758                  throw new UnsupportedOperationException();
4758            if (e == null)
4759                throw new NullPointerException();
4759              return map.internalPut(e, v, true) == null;
4760          }
4761          public boolean addAll(Collection<? extends K> c) {
# Line 4765 | Line 4764 | public class ConcurrentHashMapV8<K, V>
4764              if ((v = value) == null)
4765                  throw new UnsupportedOperationException();
4766              for (K e : c) {
4768                if (e == null)
4769                    throw new NullPointerException();
4767                  if (map.internalPut(e, v, true) == null)
4768                      added = true;
4769              }
# Line 4783 | Line 4780 | public class ConcurrentHashMapV8<K, V>
4780      /**
4781       * A view of a ConcurrentHashMapV8 as a {@link Collection} of
4782       * values, in which additions are disabled. This class cannot be
4783 <     * directly instantiated. See {@link #values},
4783 >     * directly instantiated. See {@link #values()}.
4784       *
4785       * <p>The view's {@code iterator} is a "weakly consistent" iterator
4786       * that will never throw {@link ConcurrentModificationException},
# Line 4793 | Line 4790 | public class ConcurrentHashMapV8<K, V>
4790       */
4791      public static final class ValuesView<K,V> extends CHMView<K,V>
4792          implements Collection<V> {
4793 <        ValuesView(ConcurrentHashMapV8<K, V> map)   { super(map); }
4793 >        ValuesView(ConcurrentHashMapV8<K,V> map)   { super(map); }
4794          public final boolean contains(Object o) { return map.containsValue(o); }
4795          public final boolean remove(Object o) {
4796              if (o != null) {
# Line 4833 | Line 4830 | public class ConcurrentHashMapV8<K, V>
4830      /**
4831       * A view of a ConcurrentHashMapV8 as a {@link Set} of (key, value)
4832       * entries.  This class cannot be directly instantiated. See
4833 <     * {@link #entrySet}.
4833 >     * {@link #entrySet()}.
4834       */
4835      public static final class EntrySetView<K,V> extends CHMView<K,V>
4836          implements Set<Map.Entry<K,V>> {
4837 <        EntrySetView(ConcurrentHashMapV8<K, V> map) { super(map); }
4837 >        EntrySetView(ConcurrentHashMapV8<K,V> map) { super(map); }
4838          public final boolean contains(Object o) {
4839              Object k, v, r; Map.Entry<?,?> e;
4840              return ((o instanceof Map.Entry) &&
# Line 4869 | Line 4866 | public class ConcurrentHashMapV8<K, V>
4866          }
4867  
4868          public final boolean add(Entry<K,V> e) {
4869 <            K key = e.getKey();
4873 <            V value = e.getValue();
4874 <            if (key == null || value == null)
4875 <                throw new NullPointerException();
4876 <            return map.internalPut(key, value, false) == null;
4869 >            return map.internalPut(e.getKey(), e.getValue(), false) == null;
4870          }
4871          public final boolean addAll(Collection<? extends Entry<K,V>> c) {
4872              boolean added = false;
# Line 4970 | Line 4963 | public class ConcurrentHashMapV8<K, V>
4963           * @param map the map
4964           * @param transformer a function returning the transformation
4965           * for an element, or null if there is no transformation (in
4966 <         * which case it is not combined).
4966 >         * which case it is not combined)
4967           * @param reducer a commutative associative combining function
4968           * @return the task
4969           */
# Line 5137 | Line 5130 | public class ConcurrentHashMapV8<K, V>
5130           * @param map the map
5131           * @param transformer a function returning the transformation
5132           * for an element, or null if there is no transformation (in
5133 <         * which case it is not combined).
5133 >         * which case it is not combined)
5134           * @param reducer a commutative associative combining function
5135           * @return the task
5136           */
# Line 5303 | Line 5296 | public class ConcurrentHashMapV8<K, V>
5296           * @param map the map
5297           * @param transformer a function returning the transformation
5298           * for an element, or null if there is no transformation (in
5299 <         * which case it is not combined).
5299 >         * which case it is not combined)
5300           * @param reducer a commutative associative combining function
5301           * @return the task
5302           */
# Line 5469 | Line 5462 | public class ConcurrentHashMapV8<K, V>
5462           * @param map the map
5463           * @param transformer a function returning the transformation
5464           * for an element, or null if there is no transformation (in
5465 <         * which case it is not combined).
5465 >         * which case it is not combined)
5466           * @param reducer a commutative associative combining function
5467           * @return the task
5468           */
# Line 6804 | Line 6797 | public class ConcurrentHashMapV8<K, V>
6797      private static final int ASHIFT;
6798  
6799      static {
6807        int ss;
6800          try {
6801              U = getUnsafe();
6802              Class<?> k = ConcurrentHashMapV8.class;
# Line 6823 | Line 6815 | public class ConcurrentHashMapV8<K, V>
6815                  (ck.getDeclaredField("value"));
6816              Class<?> sc = Node[].class;
6817              ABASE = U.arrayBaseOffset(sc);
6818 <            ss = U.arrayIndexScale(sc);
6819 <            ASHIFT = 31 - Integer.numberOfLeadingZeros(ss);
6818 >            int scale = U.arrayIndexScale(sc);
6819 >            if ((scale & (scale - 1)) != 0)
6820 >                throw new Error("data type scale not a power of two");
6821 >            ASHIFT = 31 - Integer.numberOfLeadingZeros(scale);
6822          } catch (Exception e) {
6823              throw new Error(e);
6824          }
6831        if ((ss & (ss-1)) != 0)
6832            throw new Error("data type scale not a power of two");
6825      }
6826  
6827      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines