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.86 by jsr166, Sun Jan 6 20:05:51 2013 UTC vs.
Revision 1.96 by jsr166, Mon Feb 11 17:40:59 2013 UTC

# 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 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 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> {
4581 >    abstract static class CHMView<K, V> {
4582          final ConcurrentHashMapV8<K, V> map;
4583          CHMView(ConcurrentHashMapV8<K, V> map)  { this.map = map; }
4584  
# 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>
# 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 4783 | Line 4784 | public class ConcurrentHashMapV8<K, V>
4784      /**
4785       * A view of a ConcurrentHashMapV8 as a {@link Collection} of
4786       * values, in which additions are disabled. This class cannot be
4787 <     * directly instantiated. See {@link #values},
4787 >     * directly instantiated. See {@link #values()}.
4788       *
4789       * <p>The view's {@code iterator} is a "weakly consistent" iterator
4790       * that will never throw {@link ConcurrentModificationException},
# Line 4833 | Line 4834 | public class ConcurrentHashMapV8<K, V>
4834      /**
4835       * A view of a ConcurrentHashMapV8 as a {@link Set} of (key, value)
4836       * entries.  This class cannot be directly instantiated. See
4837 <     * {@link #entrySet}.
4837 >     * {@link #entrySet()}.
4838       */
4839      public static final class EntrySetView<K,V> extends CHMView<K,V>
4840          implements Set<Map.Entry<K,V>> {
# Line 4970 | Line 4971 | public class ConcurrentHashMapV8<K, V>
4971           * @param map the map
4972           * @param transformer a function returning the transformation
4973           * for an element, or null if there is no transformation (in
4974 <         * which case it is not combined).
4974 >         * which case it is not combined)
4975           * @param reducer a commutative associative combining function
4976           * @return the task
4977           */
# Line 5137 | Line 5138 | public class ConcurrentHashMapV8<K, V>
5138           * @param map the map
5139           * @param transformer a function returning the transformation
5140           * for an element, or null if there is no transformation (in
5141 <         * which case it is not combined).
5141 >         * which case it is not combined)
5142           * @param reducer a commutative associative combining function
5143           * @return the task
5144           */
# Line 5303 | Line 5304 | public class ConcurrentHashMapV8<K, V>
5304           * @param map the map
5305           * @param transformer a function returning the transformation
5306           * for an element, or null if there is no transformation (in
5307 <         * which case it is not combined).
5307 >         * which case it is not combined)
5308           * @param reducer a commutative associative combining function
5309           * @return the task
5310           */
# Line 5469 | Line 5470 | public class ConcurrentHashMapV8<K, V>
5470           * @param map the map
5471           * @param transformer a function returning the transformation
5472           * for an element, or null if there is no transformation (in
5473 <         * which case it is not combined).
5473 >         * which case it is not combined)
5474           * @param reducer a commutative associative combining function
5475           * @return the task
5476           */
# Line 6804 | Line 6805 | public class ConcurrentHashMapV8<K, V>
6805      private static final int ASHIFT;
6806  
6807      static {
6807        int ss;
6808          try {
6809              U = getUnsafe();
6810              Class<?> k = ConcurrentHashMapV8.class;
# Line 6823 | Line 6823 | public class ConcurrentHashMapV8<K, V>
6823                  (ck.getDeclaredField("value"));
6824              Class<?> sc = Node[].class;
6825              ABASE = U.arrayBaseOffset(sc);
6826 <            ss = U.arrayIndexScale(sc);
6827 <            ASHIFT = 31 - Integer.numberOfLeadingZeros(ss);
6826 >            int scale = U.arrayIndexScale(sc);
6827 >            if ((scale & (scale - 1)) != 0)
6828 >                throw new Error("data type scale not a power of two");
6829 >            ASHIFT = 31 - Integer.numberOfLeadingZeros(scale);
6830          } catch (Exception e) {
6831              throw new Error(e);
6832          }
6831        if ((ss & (ss-1)) != 0)
6832            throw new Error("data type scale not a power of two");
6833      }
6834  
6835      /**
# Line 6842 | Line 6842 | public class ConcurrentHashMapV8<K, V>
6842      private static sun.misc.Unsafe getUnsafe() {
6843          try {
6844              return sun.misc.Unsafe.getUnsafe();
6845 <        } catch (SecurityException se) {
6846 <            try {
6847 <                return java.security.AccessController.doPrivileged
6848 <                    (new java.security
6849 <                     .PrivilegedExceptionAction<sun.misc.Unsafe>() {
6850 <                        public sun.misc.Unsafe run() throws Exception {
6851 <                            java.lang.reflect.Field f = sun.misc
6852 <                                .Unsafe.class.getDeclaredField("theUnsafe");
6853 <                            f.setAccessible(true);
6854 <                            return (sun.misc.Unsafe) f.get(null);
6855 <                        }});
6856 <            } catch (java.security.PrivilegedActionException e) {
6857 <                throw new RuntimeException("Could not initialize intrinsics",
6858 <                                           e.getCause());
6859 <            }
6845 >        } catch (SecurityException tryReflectionInstead) {}
6846 >        try {
6847 >            return java.security.AccessController.doPrivileged
6848 >            (new java.security.PrivilegedExceptionAction<sun.misc.Unsafe>() {
6849 >                public sun.misc.Unsafe run() throws Exception {
6850 >                    Class<sun.misc.Unsafe> k = sun.misc.Unsafe.class;
6851 >                    for (java.lang.reflect.Field f : k.getDeclaredFields()) {
6852 >                        f.setAccessible(true);
6853 >                        Object x = f.get(null);
6854 >                        if (k.isInstance(x))
6855 >                            return k.cast(x);
6856 >                    }
6857 >                    throw new NoSuchFieldError("the Unsafe");
6858 >                }});
6859 >        } catch (java.security.PrivilegedActionException e) {
6860 >            throw new RuntimeException("Could not initialize intrinsics",
6861 >                                       e.getCause());
6862          }
6863      }
6864   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines