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

Comparing jsr166/src/extra166y/CustomConcurrentHashMap.java (file contents):
Revision 1.6 by dl, Sun Nov 1 22:14:39 2009 UTC vs.
Revision 1.36 by jsr166, Sun Jan 18 20:17:32 2015 UTC

# Line 1 | Line 1
1   /*
2   * Written by Doug Lea with assistance from members of JCP JSR-166
3   * Expert Group and released to the public domain, as explained at
4 < * http://creativecommons.org/licenses/publicdomain
4 > * http://creativecommons.org/publicdomain/zero/1.0/
5   */
6  
7   package extra166y;
8 +
9   import java.lang.ref.*;
10   import java.lang.reflect.*;
11   import java.io.*;
# Line 25 | Line 26 | import sun.misc.Unsafe;
26   *   <li> {@linkplain SoftReference Soft}, {@linkplain
27   *        WeakReference weak} or strong (regular) keys and values.
28   *
29 < *   <li> User-definable <code>MappingFunctions</code> that may be
29 > *   <li> User-definable {@code MappingFunctions} that may be
30   *        used in method {@link
31   *        CustomConcurrentHashMap#computeIfAbsent} to atomically
32   *        establish a computed value, along with
33 < *        <code>RemappingFunctions</code> that can be used in method
33 > *        {@code RemappingFunctions} that can be used in method
34   *        {@link CustomConcurrentHashMap#compute} to atomically
35   *        replace values.
36   *
37 < *    <li>Factory methods returning specialized forms for <tt>int</tt>
37 > *    <li>Factory methods returning specialized forms for {@code int}
38   *        keys and/or values, that may be more space-efficient
39   *
40   * </ul>
# Line 53 | Line 54 | import sun.misc.Unsafe;
54   *     (STRONG,
55   *      new Equivalence<Person>() {
56   *          public boolean equal(Person k, Object x) {
57 < *            return x instanceOf Person && k.name.equals(((Person)x).name);
57 > *            return x instanceof Person && k.name.equals(((Person)x).name);
58   *          }
59   *          public int hash(Object x) {
60 < *             return (x instanceOf Person)? ((Person)x).name.hashCode() : 0;
60 > *             return (x instanceof Person) ? ((Person)x).name.hashCode() : 0;
61   *          }
62   *        },
63   *      STRONG, EQUALS, 0);
# Line 72 | Line 73 | import sun.misc.Unsafe;
73   *
74   * <p>This class also includes nested class {@link KeySet}
75   * that provides space-efficient Set views of maps, also supporting
76 < * method <code>intern</code>, which may be of use in canonicalizing
76 > * method {@code intern}, which may be of use in canonicalizing
77   * elements.
78   *
79   * <p>When used with (Weak or Soft) Reference keys and/or values,
80 < * elements that have asynchronously become <code>null</code> are
80 > * elements that have asynchronously become {@code null} are
81   * treated as absent from the map and (eventually) removed from maps
82   * via a background thread common across all maps. Because of the
83   * potential for asynchronous clearing of References, methods such as
84 < * <code>containsValue</code> have weaker guarantees than you might
84 > * {@code containsValue} have weaker guarantees than you might
85   * expect even in the absence of other explicitly concurrent
86 < * operations. For example <code>containsValue(value)</code> may
87 < * return true even if <code>value</code> is no longer available upon
86 > * operations. For example {@code containsValue(value)} may
87 > * return true even if {@code value} is no longer available upon
88   * return from the method.
89   *
90   * <p>When Equivalences other than equality are used, the returned
91 < * collections may violate the specifications of <tt>Map</tt> and/or
92 < * <tt>Set</tt> interfaces, which mandate the use of the
93 < * <tt>equals</tt> method when comparing objects.  The methods of this
91 > * collections may violate the specifications of {@code Map} and/or
92 > * {@code Set} interfaces, which mandate the use of the
93 > * {@code equals} method when comparing objects.  The methods of this
94   * class otherwise have properties similar to those of {@link
95   * java.util.ConcurrentHashMap} under its default settings.  To
96   * adaptively maintain semantics and performance under varying
# Line 110 | Line 111 | import sun.misc.Unsafe;
111   * @param <K> the type of keys maintained by this map
112   * @param <V> the type of mapped values
113   */
114 < public class CustomConcurrentHashMap<K, V> extends AbstractMap<K, V>
115 <    implements ConcurrentMap<K, V>, Serializable {
114 > public class CustomConcurrentHashMap<K,V> extends AbstractMap<K,V>
115 >    implements ConcurrentMap<K,V>, Serializable {
116      private static final long serialVersionUID = 7249069246764182397L;
117  
118      /*
# Line 165 | Line 166 | public class CustomConcurrentHashMap<K,
166       * An object performing equality comparisons, along with a hash
167       * function consistent with this comparison.  The type signatures
168       * of the methods of this interface reflect those of {@link
169 <     * java.util.Map}: While only elements of <code>K</code> may be
170 <     * entered into a Map, any <code>Object</code> may be tested for
169 >     * java.util.Map}: While only elements of {@code K} may be
170 >     * entered into a Map, any {@code Object} may be tested for
171       * membership. Note that the performance of hash maps is heavily
172       * dependent on the quality of hash functions.
173       */
# Line 224 | Line 225 | public class CustomConcurrentHashMap<K,
225  
226      /**
227       * A function computing a mapping from the given key to a value,
228 <     *  or <code>null</code> if there is no mapping.
228 >     * or {@code null} if there is no mapping.
229       */
230 <    public static interface MappingFunction<K, V> {
230 >    public static interface MappingFunction<K,V> {
231          /**
232           * Returns a value for the given key, or null if there is no
233           * mapping. If this function throws an (unchecked) exception,
# Line 236 | Line 237 | public class CustomConcurrentHashMap<K,
237           * simple. The most common usage is to construct a new object
238           * serving as an initial mapped value.
239           *
240 <         * @param key the (nonnull) key
240 >         * @param key the (non-null) key
241           * @return a value, or null if none
242           */
243          V map(K key);
# Line 244 | Line 245 | public class CustomConcurrentHashMap<K,
245  
246      /**
247       * A function computing a new mapping from the given key and its
248 <     * current value to a new value, or <code>null</code> if there is
249 <     * no mapping
248 >     * current value to a new value, or {@code null} if there is
249 >     * no mapping.
250       */
251 <    public static interface RemappingFunction<K, V> {
251 >    public static interface RemappingFunction<K,V> {
252          /**
253           * Returns a new value for the given key and its current, or
254           * null if there is no mapping.
# Line 320 | Line 321 | public class CustomConcurrentHashMap<K,
321           * Returns the value established during the creation of this
322           * node or, if since updated, the value set by the most
323           * recent call to setValue, or throws an exception if
324 <         * value could not be computed
324 >         * value could not be computed.
325           * @return the value
326           * @throws RuntimeException or Error if computeValue failed
327           */
# Line 344 | Line 345 | public class CustomConcurrentHashMap<K,
345           * Records the linkage to be returned by the next call to getLinkage.
346           * @param linkage the linkage
347           */
348 <        void setLinkage(Node r);
348 >        void setLinkage(Node linkage);
349      }
350  
351      /**
352       * Each Segment holds a count and table corresponding to a segment
353       * of the table. This class contains only those methods for
354       * directly assigning these fields, which must only be called
355 <     * while holding locks
355 >     * while holding locks.
356       */
357      static final class Segment extends ReentrantLock {
358          volatile Node[] table;
# Line 386 | Line 387 | public class CustomConcurrentHashMap<K,
387          }
388  
389          /**
390 <         * See the similar code in ConcurrentHashMap for explanation
390 >         * See the similar code in ConcurrentHashMap for explanation.
391           */
392          final Node[] resizeTable(CustomConcurrentHashMap cchm) {
393              Node[] oldTable = table;
394              if (oldTable == null)
395 <                return table = (Node[])
395 <                    new Node[cchm.initialSegmentCapacity];
395 >                return table = new Node[cchm.initialSegmentCapacity];
396  
397              int oldCapacity = oldTable.length;
398              if (oldCapacity >= MAX_SEGMENT_CAPACITY)
399                  return oldTable;
400 <            Node[] newTable =
401 <                (Node[])new Node[oldCapacity<<1];
400 >            Node[] newTable = new Node[oldCapacity<<1];
401              int sizeMask = newTable.length - 1;
402              NodeFactory fac = cchm.factory;
403              for (int i = 0; i < oldCapacity ; i++) {
# Line 533 | Line 532 | public class CustomConcurrentHashMap<K,
532              int sc = (int)((1L + (4L * es) / 3) >>> SEGMENT_BITS);
533              if (sc < MIN_SEGMENT_CAPACITY)
534                  sc = MIN_SEGMENT_CAPACITY;
535 <            else if (sc > MAX_SEGMENT_CAPACITY)
536 <                sc = MAX_SEGMENT_CAPACITY;
537 <            this.initialSegmentCapacity = sc;
535 >            int capacity = MIN_SEGMENT_CAPACITY; // ensure power of two
536 >            while (capacity < sc)
537 >                capacity <<= 1;
538 >            if (capacity > MAX_SEGMENT_CAPACITY)
539 >                capacity = MAX_SEGMENT_CAPACITY;
540 >            this.initialSegmentCapacity = capacity;
541          }
542 <        this.segments = (Segment[])new Segment[NSEGMENTS];
542 >        this.segments = new Segment[NSEGMENTS];
543      }
544  
545      /**
546 <     * Creates a new CustomConcurrentHashMap with the given parameters
546 >     * Creates a new CustomConcurrentHashMap with the given parameters.
547       * @param keyStrength the strength for keys
548       * @param keyEquivalence the Equivalence to use for keys
549       * @param valueStrength the strength for values
# Line 570 | Line 572 | public class CustomConcurrentHashMap<K,
572  
573      /**
574       * Returns a new map using Integer keys and the given value
575 <     * parameters
575 >     * parameters.
576       * @param valueStrength the strength for values
577       * @param valueEquivalence the Equivalence to use for values
578       * @param expectedSize an estimate of the number of elements
# Line 588 | Line 590 | public class CustomConcurrentHashMap<K,
590      }
591  
592      /**
593 <     * Returns a new map using the given key parameters and Integer values
593 >     * Returns a new map using the given key parameters and Integer values.
594       * @param keyStrength the strength for keys
595       * @param keyEquivalence the Equivalence to use for keys
596       * @param expectedSize an estimate of the number of elements
# Line 606 | Line 608 | public class CustomConcurrentHashMap<K,
608      }
609  
610      /**
611 <     * Returns a new map using Integer keys and values
611 >     * Returns a new map using Integer keys and values.
612       * @param expectedSize an estimate of the number of elements
613       * that will be held in the map. If no estimate is known,
614       * zero is an acceptable value.
# Line 620 | Line 622 | public class CustomConcurrentHashMap<K,
622      }
623  
624      /**
625 <     * Returns the segment for traversing table for key with given hash
625 >     * Returns the segment for traversing table for key with given hash.
626       * @param hash the hash code for the key
627       * @return the segment, or null if not yet initialized
628       */
# Line 639 | Line 641 | public class CustomConcurrentHashMap<K,
641          int index = (hash >>> SEGMENT_SHIFT) & SEGMENT_MASK;
642          Segment seg = segs[index];
643          if (seg == null) {
644 <            synchronized(segs) {
644 >            synchronized (segs) {
645                  seg = segs[index];
646                  if (seg == null) {
647                      seg = new Segment();
# Line 653 | Line 655 | public class CustomConcurrentHashMap<K,
655      }
656  
657      /**
658 <     * Returns node for key, or null if none
658 >     * Returns node for key, or null if none.
659       */
660      final Node findNode(Object key, int hash, Segment seg) {
661          if (seg != null) {
# Line 675 | Line 677 | public class CustomConcurrentHashMap<K,
677      }
678  
679      /**
680 <     * Returns <tt>true</tt> if this map contains a key equivalent to
680 >     * Returns {@code true} if this map contains a key equivalent to
681       * the given key with respect to this map's key Equivalence.
682       *
683 <     * @param  key   possible key
684 <     * @return <tt>true</tt> if this map contains the specified key
683 >     * @param  key possible key
684 >     * @return {@code true} if this map contains the specified key
685       * @throws NullPointerException if the specified key is null
686       */
687      public boolean containsKey(Object key) {
# Line 694 | Line 696 | public class CustomConcurrentHashMap<K,
696      /**
697       * Returns the value associated with a key equivalent to the given
698       * key with respect to this map's key Equivalence, or {@code null}
699 <     * if no such mapping exists
699 >     * if no such mapping exists.
700       *
701 <     * @param  key   possible key
702 <     * @return the value associated with the key or <tt>null</tt> if
703 <     * there is no mapping.
701 >     * @param  key possible key
702 >     * @return the value associated with the key, or {@code null} if
703 >     * there is no mapping
704       * @throws NullPointerException if the specified key is null
705       */
706      public V get(Object key) {
# Line 749 | Line 751 | public class CustomConcurrentHashMap<K,
751       *
752       * @param key key with which the specified value is to be associated
753       * @param value value to be associated with the specified key
754 <     * @return the previous value associated with <tt>key</tt>, or
755 <     *         <tt>null</tt> if there was no mapping for <tt>key</tt>
754 >     * @return the previous value associated with {@code key}, or
755 >     *         {@code null} if there was no mapping for {@code key}
756       * @throws NullPointerException if the specified key or value is null
757       */
758      public V put(K key, V value) {
# Line 761 | Line 763 | public class CustomConcurrentHashMap<K,
763       * {@inheritDoc}
764       *
765       * @return the previous value associated with the specified key,
766 <     *         or <tt>null</tt> if there was no mapping for the key
766 >     *         or {@code null} if there was no mapping for the key
767       * @throws NullPointerException if the specified key or value is null
768       */
769      public V putIfAbsent(K key, V value) {
# Line 810 | Line 812 | public class CustomConcurrentHashMap<K,
812       * {@inheritDoc}
813       *
814       * @return the previous value associated with the specified key,
815 <     *         or <tt>null</tt> if there was no mapping for the key
815 >     *         or {@code null} if there was no mapping for the key
816       * @throws NullPointerException if the specified key or value is null
817       */
818      public boolean replace(K key, V oldValue, V newValue) {
# Line 842 | Line 844 | public class CustomConcurrentHashMap<K,
844       * Removes the mapping for the specified key.
845       *
846       * @param  key the key to remove
847 <     * @return the previous value associated with <tt>key</tt>, or
848 <     *         <tt>null</tt> if there was no mapping for <tt>key</tt>
847 >     * @return the previous value associated with {@code key}, or
848 >     *         {@code null} if there was no mapping for {@code key}
849       * @throws NullPointerException if the specified key is null
850       */
851      public V remove(Object key) {
# Line 939 | Line 941 | public class CustomConcurrentHashMap<K,
941      }
942  
943      /**
944 <     * Remove node if its key or value are null
944 >     * Removes node if its key or value are null.
945       */
946      final void removeIfReclaimed(Node r) {
947          int hash = r.getLocator();
# Line 976 | Line 978 | public class CustomConcurrentHashMap<K,
978      }
979  
980      /**
981 <     * Returns <tt>true</tt> if this map contains no key-value mappings.
981 >     * Returns {@code true} if this map contains no key-value mappings.
982       *
983 <     * @return <tt>true</tt> if this map contains no key-value mappings
983 >     * @return {@code true} if this map contains no key-value mappings
984       */
985      public final boolean isEmpty() {
986          final Segment[] segs = this.segments;
# Line 994 | Line 996 | public class CustomConcurrentHashMap<K,
996  
997      /**
998       * Returns the number of key-value mappings in this map.  If the
999 <     * map contains more than <tt>Integer.MAX_VALUE</tt> elements, returns
1000 <     * <tt>Integer.MAX_VALUE</tt>.
999 >     * map contains more than {@code Integer.MAX_VALUE} elements, returns
1000 >     * {@code Integer.MAX_VALUE}.
1001       *
1002       * @return the number of key-value mappings in this map
1003       */
# Line 1007 | Line 1009 | public class CustomConcurrentHashMap<K,
1009              if (seg != null && seg.getTableForTraversal() != null)
1010                  sum += seg.count;
1011          }
1012 <        return sum >= Integer.MAX_VALUE? Integer.MAX_VALUE : (int)sum;
1012 >        return (sum >= Integer.MAX_VALUE) ? Integer.MAX_VALUE : (int) sum;
1013      }
1014  
1015      /**
1016 <     * Returns <tt>true</tt> if this map maps one or more keys to a
1016 >     * Returns {@code true} if this map maps one or more keys to a
1017       * value equivalent to the given value with respect to this map's
1018       * value Equivalence.  Note: This method requires a full internal
1019       * traversal of the hash table, and so is much slower than method
1020 <     * <tt>containsKey</tt>.
1020 >     * {@code containsKey}.
1021       *
1022       * @param value value whose presence in this map is to be tested
1023 <     * @return <tt>true</tt> if this map maps one or more keys to the
1023 >     * @return {@code true} if this map maps one or more keys to the
1024       *         specified value
1025       * @throws NullPointerException if the specified value is null
1026       */
# Line 1066 | Line 1068 | public class CustomConcurrentHashMap<K,
1068      /**
1069       * If the specified key is not already associated with a value,
1070       * computes its value using the given mappingFunction, and if
1071 <     * nonnull, enters it into the map.  This is equivalent to
1071 >     * non-null, enters it into the map.  This is equivalent to
1072       *
1073       * <pre>
1074       *   if (map.containsKey(key))
# Line 1088 | Line 1090 | public class CustomConcurrentHashMap<K,
1090       * @param key key with which the specified value is to be associated
1091       * @param mappingFunction the function to compute a value
1092       * @return the current (existing or computed) value associated with
1093 <     *         the specified key, or <tt>null</tt> if the computation
1094 <     *         returned <tt>null</tt>.
1093 >     *         the specified key, or {@code null} if the computation
1094 >     *         returned {@code null}
1095       * @throws NullPointerException if the specified key or mappingFunction
1096 <     *         is null,
1096 >     *         is null
1097       * @throws RuntimeException or Error if the mappingFunction does so,
1098 <     *         in which case the mapping is left unestablished.
1098 >     *         in which case the mapping is left unestablished
1099       */
1100      public V computeIfAbsent(K key, MappingFunction<? super K, ? extends V> mappingFunction) {
1101          if (key == null || mappingFunction == null)
# Line 1155 | Line 1157 | public class CustomConcurrentHashMap<K,
1157       * <pre>
1158       * map.compute(word, new RemappingFunction&lt;String,Integer&gt;() {
1159       *   public Integer remap(String k, Integer v) {
1160 <     *     return v == null? 1 : v + 1;
1160 >     *     return (v == null) ? 1 : v + 1;
1161       *   }});
1162       * </pre>
1163       *
1164       * @param key key with which the specified value is to be associated
1165       * @param remappingFunction the function to compute a value
1166       * @return the updated value or
1167 <     *         <tt>null</tt> if the computation returned <tt>null</tt>
1167 >     *         {@code null} if the computation returned {@code null}
1168       * @throws NullPointerException if the specified key or remappingFunction
1169 <     *         is null,
1169 >     *         is null
1170       * @throws RuntimeException or Error if the remappingFunction does so,
1171       *         in which case the mapping is left in its previous state
1172       */
# Line 1411 | Line 1413 | public class CustomConcurrentHashMap<K,
1413              if (!(o instanceof Map.Entry))
1414                  return false;
1415              Map.Entry<?,?> e = (Map.Entry<?,?>)o;
1416 <            return CustomConcurrentHashMap.this.remove(e.getKey(), e.getValue());
1416 >            return CustomConcurrentHashMap.this.remove(e.getKey(),
1417 >                                                       e.getValue());
1418          }
1419          public int size() {
1420              return CustomConcurrentHashMap.this.size();
# Line 1429 | Line 1432 | public class CustomConcurrentHashMap<K,
1432       * The set is backed by the map, so changes to the map are
1433       * reflected in the set, and vice-versa.  The set supports element
1434       * removal, which removes the corresponding mapping from this map,
1435 <     * via the <tt>Iterator.remove</tt>, <tt>Set.remove</tt>,
1436 <     * <tt>removeAll</tt>, <tt>retainAll</tt>, and <tt>clear</tt>
1437 <     * operations.  It does not support the <tt>add</tt> or
1438 <     * <tt>addAll</tt> operations.
1435 >     * via the {@code Iterator.remove}, {@code Set.remove},
1436 >     * {@code removeAll}, {@code retainAll}, and {@code clear}
1437 >     * operations.  It does not support the {@code add} or
1438 >     * {@code addAll} operations.
1439       *
1440 <     * <p>The view's <tt>iterator</tt> is a "weakly consistent" iterator
1440 >     * <p>The view's {@code iterator} is a "weakly consistent" iterator
1441       * that will never throw {@link ConcurrentModificationException},
1442       * and guarantees to traverse elements as they existed upon
1443       * construction of the iterator, and may (but is not guaranteed to)
# Line 1450 | Line 1453 | public class CustomConcurrentHashMap<K,
1453       * The collection is backed by the map, so changes to the map are
1454       * reflected in the collection, and vice-versa.  The collection
1455       * supports element removal, which removes the corresponding
1456 <     * mapping from this map, via the <tt>Iterator.remove</tt>,
1457 <     * <tt>Collection.remove</tt>, <tt>removeAll</tt>,
1458 <     * <tt>retainAll</tt>, and <tt>clear</tt> operations.  It does not
1459 <     * support the <tt>add</tt> or <tt>addAll</tt> operations.
1456 >     * mapping from this map, via the {@code Iterator.remove},
1457 >     * {@code Collection.remove}, {@code removeAll},
1458 >     * {@code retainAll}, and {@code clear} operations.  It does not
1459 >     * support the {@code add} or {@code addAll} operations.
1460       *
1461 <     * <p>The view's <tt>iterator</tt> is a "weakly consistent" iterator
1461 >     * <p>The view's {@code iterator} is a "weakly consistent" iterator
1462       * that will never throw {@link ConcurrentModificationException},
1463       * and guarantees to traverse elements as they existed upon
1464       * construction of the iterator, and may (but is not guaranteed to)
# Line 1471 | Line 1474 | public class CustomConcurrentHashMap<K,
1474       * The set is backed by the map, so changes to the map are
1475       * reflected in the set, and vice-versa.  The set supports element
1476       * removal, which removes the corresponding mapping from the map,
1477 <     * via the <tt>Iterator.remove</tt>, <tt>Set.remove</tt>,
1478 <     * <tt>removeAll</tt>, <tt>retainAll</tt>, and <tt>clear</tt>
1479 <     * operations.  It does not support the <tt>add</tt> or
1480 <     * <tt>addAll</tt> operations.
1477 >     * via the {@code Iterator.remove}, {@code Set.remove},
1478 >     * {@code removeAll}, {@code retainAll}, and {@code clear}
1479 >     * operations.  It does not support the {@code add} or
1480 >     * {@code addAll} operations.
1481       *
1482 <     * <p>The view's <tt>iterator</tt> is a "weakly consistent" iterator
1482 >     * <p>The view's {@code iterator} is a "weakly consistent" iterator
1483       * that will never throw {@link ConcurrentModificationException},
1484       * and guarantees to traverse elements as they existed upon
1485       * construction of the iterator, and may (but is not guaranteed to)
# Line 1491 | Line 1494 | public class CustomConcurrentHashMap<K,
1494  
1495      /**
1496       * Compares the specified object with this map for equality.
1497 <     * Returns <tt>true</tt> if the given object is also a map of the
1497 >     * Returns {@code true} if the given object is also a map of the
1498       * same size, holding keys that are equal using this Map's key
1499       * Equivalence, and which map to values that are equal according
1500       * to this Map's value equivalence.
1501       *
1502       * @param o object to be compared for equality with this map
1503 <     * @return <tt>true</tt> if the specified object is equal to this map
1503 >     * @return {@code true} if the specified object is equal to this map
1504       */
1505      public boolean equals(Object o) {
1506          if (o == this)
# Line 1534 | Line 1537 | public class CustomConcurrentHashMap<K,
1537  
1538      /**
1539       * Returns the sum of the hash codes of each entry in this map's
1540 <     * <tt>entrySet()</tt> view, which in turn are the hash codes
1540 >     * {@code entrySet()} view, which in turn are the hash codes
1541       * computed using key and value Equivalences for this Map.
1542       * @return the hash code
1543       */
# Line 1547 | Line 1550 | public class CustomConcurrentHashMap<K,
1550      }
1551  
1552      /**
1553 <     * Save the state of the instance to a stream (i.e., serialize
1554 <     * it).
1553 >     * Saves the state of the instance to a stream (i.e., serializes it).
1554 >     *
1555       * @param s the stream
1556       * @serialData
1557       * the key (Object) and value (Object)
1558       * for each key-value mapping, followed by a null pair.
1559       * The key-value mappings are emitted in no particular order.
1560       */
1561 <    private void writeObject(java.io.ObjectOutputStream s) throws IOException  {
1561 >    private void writeObject(java.io.ObjectOutputStream s) throws IOException {
1562          s.defaultWriteObject();
1563          for (Map.Entry<K,V> e : entrySet()) {
1564              s.writeObject(e.getKey());
# Line 1566 | Line 1569 | public class CustomConcurrentHashMap<K,
1569      }
1570  
1571      /**
1572 <     * Reconstitute the instance from a stream (i.e., deserialize it).
1572 >     * Reconstitutes the instance from a stream (that is, deserializes it).
1573       * @param s the stream
1574       */
1575      private void readObject(java.io.ObjectInputStream s)
1576 <        throws IOException, ClassNotFoundException  {
1576 >        throws IOException, ClassNotFoundException {
1577          s.defaultReadObject();
1578 <        this.segments = (Segment[])(new Segment[NSEGMENTS]);
1578 >        this.segments = new Segment[NSEGMENTS];
1579          for (;;) {
1580              K key = (K) s.readObject();
1581              V value = (V) s.readObject();
# Line 1584 | Line 1587 | public class CustomConcurrentHashMap<K,
1587  
1588      /**
1589       * A hash-based set with properties identical to those of
1590 <     * <code>Collections.newSetFromMap</code> applied to a
1591 <     * <code>CustomConcurrentHashMap</code>, but possibly more
1590 >     * {@code Collections.newSetFromMap} applied to a
1591 >     * {@code CustomConcurrentHashMap}, but possibly more
1592       * space-efficient.  The set does not permit null elements. The
1593       * set is serializable; however, serializing a set that uses soft
1594       * or weak references can give unpredictable results.
# Line 1596 | Line 1599 | public class CustomConcurrentHashMap<K,
1599          final CustomConcurrentHashMap<K,K> cchm;
1600  
1601          /**
1602 <         * Creates a set with the given parameters
1602 >         * Creates a set with the given parameters.
1603           * @param strength the strength of elements
1604           * @param equivalence the Equivalence to use
1605           * @param expectedSize an estimate of the number of elements
# Line 1617 | Line 1620 | public class CustomConcurrentHashMap<K,
1620           * exists, else adds and returns the given element.
1621           *
1622           * @param e the element
1623 <         * @return e, or an element equivalent to e.
1623 >         * @return e, or an element equivalent to e
1624           */
1625          public K intern(K e) {
1626              K oldElement = cchm.doPut(e, e, true);
# Line 1625 | Line 1628 | public class CustomConcurrentHashMap<K,
1628          }
1629  
1630          /**
1631 <         * Returns <tt>true</tt> if this set contains an
1631 >         * Returns {@code true} if this set contains an
1632           * element equivalent to the given element with respect
1633           * to this set's Equivalence.
1634           * @param o element whose presence in this set is to be tested
1635 <         * @return <tt>true</tt> if this set contains the specified element
1635 >         * @return {@code true} if this set contains the specified element
1636           */
1637          public boolean contains(Object o) {
1638              return cchm.containsKey(o);
# Line 1652 | Line 1655 | public class CustomConcurrentHashMap<K,
1655           * respect to this set's Equivalence.
1656           *
1657           * @param e element to be added to this set
1658 <         * @return <tt>true</tt> if this set did not already contain
1658 >         * @return {@code true} if this set did not already contain
1659           * the specified element
1660           */
1661          public boolean add(K e) {
# Line 1664 | Line 1667 | public class CustomConcurrentHashMap<K,
1667           * respect to this set's Equivalence, if one is present.
1668           *
1669           * @param o object to be removed from this set, if present
1670 <         * @return <tt>true</tt> if the set contained the specified element
1670 >         * @return {@code true} if the set contained the specified element
1671           */
1672          public boolean remove(Object o) {
1673              return cchm.remove(o) != null;
1674          }
1675  
1676          /**
1677 <         * Returns <tt>true</tt> if this set contains no elements.
1677 >         * Returns {@code true} if this set contains no elements.
1678           *
1679 <         * @return <tt>true</tt> if this set contains no elements
1679 >         * @return {@code true} if this set contains no elements
1680           */
1681          public boolean isEmpty() {
1682              return cchm.isEmpty();
# Line 1718 | Line 1721 | public class CustomConcurrentHashMap<K,
1721       * to {@link java.lang.ref.Reference} constructors to arrange
1722       * removal of reclaimed nodes from maps via a background thread.
1723       * @return the reference queue associated with the background
1724 <     * cleanup thread.
1724 >     * cleanup thread
1725       */
1726      static ReferenceQueue<Object> getReclamationQueue() {
1727          ReferenceQueue<Object> q = refQueue;
# Line 1789 | Line 1792 | public class CustomConcurrentHashMap<K,
1792  
1793      // Strong Keys
1794  
1795 <    static abstract class StrongKeyNode implements Node {
1795 >    abstract static class StrongKeyNode implements Node {
1796          final Object key;
1797          final int locator;
1798          StrongKeyNode(int locator, Object key) {
# Line 1801 | Line 1804 | public class CustomConcurrentHashMap<K,
1804      }
1805  
1806  
1807 <    static abstract class StrongKeySelfValueNode
1807 >    abstract static class StrongKeySelfValueNode
1808          extends StrongKeyNode {
1809          StrongKeySelfValueNode(int locator, Object key) {
1810              super(locator, key);
# Line 1817 | Line 1820 | public class CustomConcurrentHashMap<K,
1820              super(locator, key);
1821          }
1822          public final Node getLinkage() { return null; }
1823 <        public final void setLinkage(Node r) { }
1823 >        public final void setLinkage(Node linkage) { }
1824      }
1825  
1826      static final class LinkedStrongKeySelfValueNode
# Line 1829 | Line 1832 | public class CustomConcurrentHashMap<K,
1832              this.linkage = linkage;
1833          }
1834          public final Node getLinkage() { return linkage; }
1835 <        public final void setLinkage(Node r) { linkage = r; }
1835 >        public final void setLinkage(Node linkage) { this.linkage = linkage; }
1836      }
1837  
1838      static final class StrongKeySelfValueNodeFactory
# Line 1848 | Line 1851 | public class CustomConcurrentHashMap<K,
1851          }
1852      }
1853  
1854 <    static abstract class StrongKeyStrongValueNode
1854 >    abstract static class StrongKeyStrongValueNode
1855          extends StrongKeyNode {
1856          volatile Object value;
1857          StrongKeyStrongValueNode(int locator, Object key, Object value) {
# Line 1867 | Line 1870 | public class CustomConcurrentHashMap<K,
1870              super(locator, key, value);
1871          }
1872          public final Node getLinkage() { return null; }
1873 <        public final void setLinkage(Node r) { }
1873 >        public final void setLinkage(Node linkage) { }
1874      }
1875  
1876      static final class LinkedStrongKeyStrongValueNode
# Line 1880 | Line 1883 | public class CustomConcurrentHashMap<K,
1883              this.linkage = linkage;
1884          }
1885          public final Node getLinkage() { return linkage; }
1886 <        public final void setLinkage(Node r) { linkage = r; }
1886 >        public final void setLinkage(Node linkage) { this.linkage = linkage; }
1887      }
1888  
1889      static final class StrongKeyStrongValueNodeFactory
# Line 1901 | Line 1904 | public class CustomConcurrentHashMap<K,
1904  
1905      // ...
1906  
1907 <    static abstract class StrongKeyIntValueNode
1907 >    abstract static class StrongKeyIntValueNode
1908          extends StrongKeyNode {
1909          volatile int value;
1910          StrongKeyIntValueNode(int locator, Object key, Object value) {
# Line 1922 | Line 1925 | public class CustomConcurrentHashMap<K,
1925              super(locator, key, value);
1926          }
1927          public final Node getLinkage() { return null; }
1928 <        public final void setLinkage(Node r) { }
1928 >        public final void setLinkage(Node linkage) { }
1929      }
1930  
1931      static final class LinkedStrongKeyIntValueNode
# Line 1935 | Line 1938 | public class CustomConcurrentHashMap<K,
1938              this.linkage = linkage;
1939          }
1940          public final Node getLinkage() { return linkage; }
1941 <        public final void setLinkage(Node r) { linkage = r; }
1941 >        public final void setLinkage(Node linkage) { this.linkage = linkage; }
1942      }
1943  
1944      static final class StrongKeyIntValueNodeFactory
# Line 1956 | Line 1959 | public class CustomConcurrentHashMap<K,
1959  
1960      // ...
1961  
1962 <    static abstract class StrongKeyWeakValueNode
1962 >    abstract static class StrongKeyWeakValueNode
1963          extends StrongKeyNode {
1964          volatile EmbeddedWeakReference valueRef;
1965          final CustomConcurrentHashMap cchm;
# Line 1972 | Line 1975 | public class CustomConcurrentHashMap<K,
1975          }
1976          public final Object getValue() {
1977              EmbeddedWeakReference vr = valueRef;
1978 <            return vr == null? null : vr.get();
1978 >            return (vr == null) ? null : vr.get();
1979          }
1980          public final void setValue(Object value) {
1981              if (value == null)
# Line 1990 | Line 1993 | public class CustomConcurrentHashMap<K,
1993              super(locator, key, value, cchm);
1994          }
1995          public final Node getLinkage() { return null; }
1996 <        public final void setLinkage(Node r) { }
1996 >        public final void setLinkage(Node linkage) { }
1997      }
1998  
1999      static final class LinkedStrongKeyWeakValueNode
# Line 2004 | Line 2007 | public class CustomConcurrentHashMap<K,
2007              this.linkage = linkage;
2008          }
2009          public final Node getLinkage() { return linkage; }
2010 <        public final void setLinkage(Node r) { linkage = r; }
2010 >        public final void setLinkage(Node linkage) { this.linkage = linkage; }
2011      }
2012  
2013      static final class StrongKeyWeakValueNodeFactory
# Line 2024 | Line 2027 | public class CustomConcurrentHashMap<K,
2027      }
2028  
2029  
2030 <    static abstract class StrongKeySoftValueNode
2030 >    abstract static class StrongKeySoftValueNode
2031          extends StrongKeyNode {
2032          volatile EmbeddedSoftReference valueRef;
2033          final CustomConcurrentHashMap cchm;
# Line 2040 | Line 2043 | public class CustomConcurrentHashMap<K,
2043          }
2044          public final Object getValue() {
2045              EmbeddedSoftReference vr = valueRef;
2046 <            return vr == null? null : vr.get();
2046 >            return (vr == null) ? null : vr.get();
2047          }
2048          public final void setValue(Object value) {
2049              if (value == null)
# Line 2058 | Line 2061 | public class CustomConcurrentHashMap<K,
2061              super(locator, key, value, cchm);
2062          }
2063          public final Node getLinkage() { return null; }
2064 <        public final void setLinkage(Node r) { }
2064 >        public final void setLinkage(Node linkage) { }
2065      }
2066  
2067      static final class LinkedStrongKeySoftValueNode
# Line 2072 | Line 2075 | public class CustomConcurrentHashMap<K,
2075              this.linkage = linkage;
2076          }
2077          public final Node getLinkage() { return linkage; }
2078 <        public final void setLinkage(Node r) { linkage = r; }
2078 >        public final void setLinkage(Node linkage) { this.linkage = linkage; }
2079      }
2080  
2081      static final class StrongKeySoftValueNodeFactory
# Line 2093 | Line 2096 | public class CustomConcurrentHashMap<K,
2096  
2097      // Weak keys
2098  
2099 <    static abstract class WeakKeyNode extends WeakReference
2099 >    abstract static class WeakKeyNode extends WeakReference
2100          implements Node {
2101          final int locator;
2102          final CustomConcurrentHashMap cchm;
2103          WeakKeyNode(int locator, Object key, CustomConcurrentHashMap cchm) {
2104 <            super(key);
2104 >            super(key, getReclamationQueue());
2105              this.locator = locator;
2106              this.cchm = cchm;
2107          }
# Line 2109 | Line 2112 | public class CustomConcurrentHashMap<K,
2112          }
2113      }
2114  
2115 <    static abstract class WeakKeySelfValueNode
2115 >    abstract static class WeakKeySelfValueNode
2116          extends WeakKeyNode {
2117 <        WeakKeySelfValueNode(int locator, Object key, CustomConcurrentHashMap cchm) {
2117 >        WeakKeySelfValueNode(int locator, Object key,
2118 >                             CustomConcurrentHashMap cchm) {
2119              super(locator, key, cchm);
2120          }
2121          public final Object getValue() { return get(); }
# Line 2120 | Line 2124 | public class CustomConcurrentHashMap<K,
2124  
2125      static final class TerminalWeakKeySelfValueNode
2126          extends WeakKeySelfValueNode {
2127 <        TerminalWeakKeySelfValueNode(int locator, Object key, CustomConcurrentHashMap cchm) {
2127 >        TerminalWeakKeySelfValueNode(int locator, Object key,
2128 >                                     CustomConcurrentHashMap cchm) {
2129              super(locator, key, cchm);
2130          }
2131          public final Node getLinkage() { return null; }
2132 <        public final void setLinkage(Node r) { }
2132 >        public final void setLinkage(Node linkage) { }
2133      }
2134  
2135      static final class LinkedWeakKeySelfValueNode
2136          extends WeakKeySelfValueNode {
2137          volatile Node linkage;
2138 <        LinkedWeakKeySelfValueNode(int locator, Object key, CustomConcurrentHashMap cchm,
2138 >        LinkedWeakKeySelfValueNode(int locator, Object key,
2139 >                                   CustomConcurrentHashMap cchm,
2140                                     Node linkage) {
2141              super(locator, key, cchm);
2142              this.linkage = linkage;
2143          }
2144          public final Node getLinkage() { return linkage; }
2145 <        public final void setLinkage(Node r) { linkage = r; }
2145 >        public final void setLinkage(Node linkage) { this.linkage = linkage; }
2146      }
2147  
2148      static final class WeakKeySelfValueNodeFactory
# Line 2156 | Line 2162 | public class CustomConcurrentHashMap<K,
2162      }
2163  
2164  
2165 <    static abstract class WeakKeyStrongValueNode
2165 >    abstract static class WeakKeyStrongValueNode
2166          extends WeakKeyNode {
2167          volatile Object value;
2168 <        WeakKeyStrongValueNode(int locator, Object key, Object value, CustomConcurrentHashMap cchm) {
2168 >        WeakKeyStrongValueNode(int locator, Object key, Object value,
2169 >                               CustomConcurrentHashMap cchm) {
2170              super(locator, key, cchm);
2171              this.value = value;
2172          }
# Line 2170 | Line 2177 | public class CustomConcurrentHashMap<K,
2177      static final class TerminalWeakKeyStrongValueNode
2178          extends WeakKeyStrongValueNode {
2179          TerminalWeakKeyStrongValueNode(int locator,
2180 <                                       Object key, Object value, CustomConcurrentHashMap cchm) {
2180 >                                       Object key, Object value,
2181 >                                       CustomConcurrentHashMap cchm) {
2182              super(locator, key, value, cchm);
2183          }
2184          public final Node getLinkage() { return null; }
2185 <        public final void setLinkage(Node r) { }
2185 >        public final void setLinkage(Node linkage) { }
2186      }
2187  
2188      static final class LinkedWeakKeyStrongValueNode
2189          extends WeakKeyStrongValueNode {
2190          volatile Node linkage;
2191          LinkedWeakKeyStrongValueNode(int locator,
2192 <                                     Object key, Object value, CustomConcurrentHashMap cchm,
2192 >                                     Object key, Object value,
2193 >                                     CustomConcurrentHashMap cchm,
2194                                       Node linkage) {
2195              super(locator, key, value, cchm);
2196              this.linkage = linkage;
2197          }
2198          public final Node getLinkage() { return linkage; }
2199 <        public final void setLinkage(Node r) { linkage = r; }
2199 >        public final void setLinkage(Node linkage) { this.linkage = linkage; }
2200      }
2201  
2202      static final class WeakKeyStrongValueNodeFactory
# Line 2206 | Line 2215 | public class CustomConcurrentHashMap<K,
2215          }
2216      }
2217  
2218 <    static abstract class WeakKeyIntValueNode
2218 >    abstract static class WeakKeyIntValueNode
2219          extends WeakKeyNode {
2220          volatile int value;
2221          WeakKeyIntValueNode(int locator, Object key, Object value,
# Line 2228 | Line 2237 | public class CustomConcurrentHashMap<K,
2237              super(locator, key, value, cchm);
2238          }
2239          public final Node getLinkage() { return null; }
2240 <        public final void setLinkage(Node r) { }
2240 >        public final void setLinkage(Node linkage) { }
2241      }
2242  
2243      static final class LinkedWeakKeyIntValueNode
# Line 2242 | Line 2251 | public class CustomConcurrentHashMap<K,
2251              this.linkage = linkage;
2252          }
2253          public final Node getLinkage() { return linkage; }
2254 <        public final void setLinkage(Node r) { linkage = r; }
2254 >        public final void setLinkage(Node linkage) { this.linkage = linkage; }
2255      }
2256  
2257      static final class WeakKeyIntValueNodeFactory
# Line 2261 | Line 2270 | public class CustomConcurrentHashMap<K,
2270          }
2271      }
2272  
2273 <    static abstract class WeakKeyWeakValueNode
2273 >    abstract static class WeakKeyWeakValueNode
2274          extends WeakKeyNode {
2275          volatile EmbeddedWeakReference valueRef;
2276          WeakKeyWeakValueNode(int locator, Object key, Object value,
# Line 2272 | Line 2281 | public class CustomConcurrentHashMap<K,
2281          }
2282          public final Object getValue() {
2283              EmbeddedWeakReference vr = valueRef;
2284 <            return vr == null? null : vr.get();
2284 >            return (vr == null) ? null : vr.get();
2285          }
2286          public final void setValue(Object value) {
2287              if (value == null)
# Line 2290 | Line 2299 | public class CustomConcurrentHashMap<K,
2299              super(locator, key, value, cchm);
2300          }
2301          public final Node getLinkage() { return null; }
2302 <        public final void setLinkage(Node r) { }
2302 >        public final void setLinkage(Node linkage) { }
2303      }
2304  
2305      static final class LinkedWeakKeyWeakValueNode
# Line 2304 | Line 2313 | public class CustomConcurrentHashMap<K,
2313              this.linkage = linkage;
2314          }
2315          public final Node getLinkage() { return linkage; }
2316 <        public final void setLinkage(Node r) { linkage = r; }
2316 >        public final void setLinkage(Node linkage) { this.linkage = linkage; }
2317      }
2318  
2319      static final class WeakKeyWeakValueNodeFactory
# Line 2324 | Line 2333 | public class CustomConcurrentHashMap<K,
2333      }
2334  
2335  
2336 <    static abstract class WeakKeySoftValueNode
2336 >    abstract static class WeakKeySoftValueNode
2337          extends WeakKeyNode {
2338          volatile EmbeddedSoftReference valueRef;
2339          WeakKeySoftValueNode(int locator, Object key, Object value,
# Line 2335 | Line 2344 | public class CustomConcurrentHashMap<K,
2344          }
2345          public final Object getValue() {
2346              EmbeddedSoftReference vr = valueRef;
2347 <            return vr == null? null : vr.get();
2347 >            return (vr == null) ? null : vr.get();
2348          }
2349          public final void setValue(Object value) {
2350              if (value == null)
# Line 2353 | Line 2362 | public class CustomConcurrentHashMap<K,
2362              super(locator, key, value, cchm);
2363          }
2364          public final Node getLinkage() { return null; }
2365 <        public final void setLinkage(Node r) { }
2365 >        public final void setLinkage(Node linkage) { }
2366      }
2367  
2368      static final class LinkedWeakKeySoftValueNode
# Line 2367 | Line 2376 | public class CustomConcurrentHashMap<K,
2376              this.linkage = linkage;
2377          }
2378          public final Node getLinkage() { return linkage; }
2379 <        public final void setLinkage(Node r) { linkage = r; }
2379 >        public final void setLinkage(Node linkage) { this.linkage = linkage; }
2380      }
2381  
2382      static final class WeakKeySoftValueNodeFactory
# Line 2388 | Line 2397 | public class CustomConcurrentHashMap<K,
2397  
2398      // Soft keys
2399  
2400 <    static abstract class SoftKeyNode extends SoftReference
2400 >    abstract static class SoftKeyNode extends SoftReference
2401          implements Node {
2402          final int locator;
2403          final CustomConcurrentHashMap cchm;
2404          SoftKeyNode(int locator, Object key, CustomConcurrentHashMap cchm) {
2405 <            super(key);
2405 >            super(key, getReclamationQueue());
2406              this.locator = locator;
2407              this.cchm = cchm;
2408          }
# Line 2404 | Line 2413 | public class CustomConcurrentHashMap<K,
2413          }
2414      }
2415  
2416 <    static abstract class SoftKeySelfValueNode
2416 >    abstract static class SoftKeySelfValueNode
2417          extends SoftKeyNode {
2418 <        SoftKeySelfValueNode(int locator, Object key, CustomConcurrentHashMap cchm) {
2418 >        SoftKeySelfValueNode(int locator, Object key,
2419 >                             CustomConcurrentHashMap cchm) {
2420              super(locator, key, cchm);
2421          }
2422          public final Object getValue() { return get(); }
# Line 2415 | Line 2425 | public class CustomConcurrentHashMap<K,
2425  
2426      static final class TerminalSoftKeySelfValueNode
2427          extends SoftKeySelfValueNode {
2428 <        TerminalSoftKeySelfValueNode(int locator, Object key, CustomConcurrentHashMap cchm) {
2428 >        TerminalSoftKeySelfValueNode(int locator, Object key,
2429 >                                     CustomConcurrentHashMap cchm) {
2430              super(locator, key, cchm);
2431          }
2432          public final Node getLinkage() { return null; }
2433 <        public final void setLinkage(Node r) { }
2433 >        public final void setLinkage(Node linkage) { }
2434      }
2435  
2436      static final class LinkedSoftKeySelfValueNode
2437          extends SoftKeySelfValueNode {
2438          volatile Node linkage;
2439 <        LinkedSoftKeySelfValueNode(int locator, Object key, CustomConcurrentHashMap cchm,
2439 >        LinkedSoftKeySelfValueNode(int locator, Object key,
2440 >                                   CustomConcurrentHashMap cchm,
2441                                     Node linkage) {
2442              super(locator, key, cchm);
2443              this.linkage = linkage;
2444          }
2445          public final Node getLinkage() { return linkage; }
2446 <        public final void setLinkage(Node r) { linkage = r; }
2446 >        public final void setLinkage(Node linkage) { this.linkage = linkage; }
2447      }
2448  
2449      static final class SoftKeySelfValueNodeFactory
# Line 2451 | Line 2463 | public class CustomConcurrentHashMap<K,
2463      }
2464  
2465  
2466 <    static abstract class SoftKeyStrongValueNode
2466 >    abstract static class SoftKeyStrongValueNode
2467          extends SoftKeyNode {
2468          volatile Object value;
2469 <        SoftKeyStrongValueNode(int locator, Object key, Object value, CustomConcurrentHashMap cchm) {
2469 >        SoftKeyStrongValueNode(int locator, Object key, Object value,
2470 >                               CustomConcurrentHashMap cchm) {
2471              super(locator, key, cchm);
2472              this.value = value;
2473          }
# Line 2465 | Line 2478 | public class CustomConcurrentHashMap<K,
2478      static final class TerminalSoftKeyStrongValueNode
2479          extends SoftKeyStrongValueNode {
2480          TerminalSoftKeyStrongValueNode(int locator,
2481 <                                       Object key, Object value, CustomConcurrentHashMap cchm) {
2481 >                                       Object key, Object value,
2482 >                                       CustomConcurrentHashMap cchm) {
2483              super(locator, key, value, cchm);
2484          }
2485          public final Node getLinkage() { return null; }
2486 <        public final void setLinkage(Node r) { }
2486 >        public final void setLinkage(Node linkage) { }
2487      }
2488  
2489      static final class LinkedSoftKeyStrongValueNode
2490          extends SoftKeyStrongValueNode {
2491          volatile Node linkage;
2492          LinkedSoftKeyStrongValueNode(int locator,
2493 <                                     Object key, Object value, CustomConcurrentHashMap cchm,
2493 >                                     Object key, Object value,
2494 >                                     CustomConcurrentHashMap cchm,
2495                                       Node linkage) {
2496              super(locator, key, value, cchm);
2497              this.linkage = linkage;
2498          }
2499          public final Node getLinkage() { return linkage; }
2500 <        public final void setLinkage(Node r) { linkage = r; }
2500 >        public final void setLinkage(Node linkage) { this.linkage = linkage; }
2501      }
2502  
2503      static final class SoftKeyStrongValueNodeFactory
# Line 2501 | Line 2516 | public class CustomConcurrentHashMap<K,
2516          }
2517      }
2518  
2519 <    static abstract class SoftKeyIntValueNode
2519 >    abstract static class SoftKeyIntValueNode
2520          extends SoftKeyNode {
2521          volatile int value;
2522          SoftKeyIntValueNode(int locator, Object key, Object value,
# Line 2523 | Line 2538 | public class CustomConcurrentHashMap<K,
2538              super(locator, key, value, cchm);
2539          }
2540          public final Node getLinkage() { return null; }
2541 <        public final void setLinkage(Node r) { }
2541 >        public final void setLinkage(Node linkage) { }
2542      }
2543  
2544      static final class LinkedSoftKeyIntValueNode
# Line 2537 | Line 2552 | public class CustomConcurrentHashMap<K,
2552              this.linkage = linkage;
2553          }
2554          public final Node getLinkage() { return linkage; }
2555 <        public final void setLinkage(Node r) { linkage = r; }
2555 >        public final void setLinkage(Node linkage) { this.linkage = linkage; }
2556      }
2557  
2558      static final class SoftKeyIntValueNodeFactory
# Line 2556 | Line 2571 | public class CustomConcurrentHashMap<K,
2571          }
2572      }
2573  
2574 <    static abstract class SoftKeyWeakValueNode
2574 >    abstract static class SoftKeyWeakValueNode
2575          extends SoftKeyNode {
2576          volatile EmbeddedWeakReference valueRef;
2577          SoftKeyWeakValueNode(int locator, Object key, Object value,
# Line 2567 | Line 2582 | public class CustomConcurrentHashMap<K,
2582          }
2583          public final Object getValue() {
2584              EmbeddedWeakReference vr = valueRef;
2585 <            return vr == null? null : vr.get();
2585 >            return (vr == null) ? null : vr.get();
2586          }
2587          public final void setValue(Object value) {
2588              if (value == null)
# Line 2585 | Line 2600 | public class CustomConcurrentHashMap<K,
2600              super(locator, key, value, cchm);
2601          }
2602          public final Node getLinkage() { return null; }
2603 <        public final void setLinkage(Node r) { }
2603 >        public final void setLinkage(Node linkage) { }
2604      }
2605  
2606      static final class LinkedSoftKeyWeakValueNode
# Line 2599 | Line 2614 | public class CustomConcurrentHashMap<K,
2614              this.linkage = linkage;
2615          }
2616          public final Node getLinkage() { return linkage; }
2617 <        public final void setLinkage(Node r) { linkage = r; }
2617 >        public final void setLinkage(Node linkage) { this.linkage = linkage; }
2618      }
2619  
2620      static final class SoftKeyWeakValueNodeFactory
# Line 2619 | Line 2634 | public class CustomConcurrentHashMap<K,
2634      }
2635  
2636  
2637 <    static abstract class SoftKeySoftValueNode
2637 >    abstract static class SoftKeySoftValueNode
2638          extends SoftKeyNode {
2639          volatile EmbeddedSoftReference valueRef;
2640          SoftKeySoftValueNode(int locator, Object key, Object value,
# Line 2630 | Line 2645 | public class CustomConcurrentHashMap<K,
2645          }
2646          public final Object getValue() {
2647              EmbeddedSoftReference vr = valueRef;
2648 <            return vr == null? null : vr.get();
2648 >            return (vr == null) ? null : vr.get();
2649          }
2650          public final void setValue(Object value) {
2651              if (value == null)
# Line 2648 | Line 2663 | public class CustomConcurrentHashMap<K,
2663              super(locator, key, value, cchm);
2664          }
2665          public final Node getLinkage() { return null; }
2666 <        public final void setLinkage(Node r) { }
2666 >        public final void setLinkage(Node linkage) { }
2667      }
2668  
2669      static final class LinkedSoftKeySoftValueNode
# Line 2662 | Line 2677 | public class CustomConcurrentHashMap<K,
2677              this.linkage = linkage;
2678          }
2679          public final Node getLinkage() { return linkage; }
2680 <        public final void setLinkage(Node r) { linkage = r; }
2680 >        public final void setLinkage(Node linkage) { this.linkage = linkage; }
2681      }
2682  
2683      static final class SoftKeySoftValueNodeFactory
# Line 2681 | Line 2696 | public class CustomConcurrentHashMap<K,
2696          }
2697      }
2698  
2699 <    static abstract class IntKeyNode implements Node {
2699 >    abstract static class IntKeyNode implements Node {
2700          final int key;
2701          IntKeyNode(int locator, Object key) {
2702              this.key = ((Integer)key).intValue();
# Line 2691 | Line 2706 | public class CustomConcurrentHashMap<K,
2706      }
2707  
2708  
2709 <    static abstract class IntKeySelfValueNode
2709 >    abstract static class IntKeySelfValueNode
2710          extends IntKeyNode {
2711          IntKeySelfValueNode(int locator, Object key) {
2712              super(locator, key);
# Line 2707 | Line 2722 | public class CustomConcurrentHashMap<K,
2722              super(locator, key);
2723          }
2724          public final Node getLinkage() { return null; }
2725 <        public final void setLinkage(Node r) { }
2725 >        public final void setLinkage(Node linkage) { }
2726      }
2727  
2728      static final class LinkedIntKeySelfValueNode
# Line 2719 | Line 2734 | public class CustomConcurrentHashMap<K,
2734              this.linkage = linkage;
2735          }
2736          public final Node getLinkage() { return linkage; }
2737 <        public final void setLinkage(Node r) { linkage = r; }
2737 >        public final void setLinkage(Node linkage) { this.linkage = linkage; }
2738      }
2739  
2740      static final class IntKeySelfValueNodeFactory
# Line 2738 | Line 2753 | public class CustomConcurrentHashMap<K,
2753          }
2754      }
2755  
2756 <    static abstract class IntKeyStrongValueNode
2756 >    abstract static class IntKeyStrongValueNode
2757          extends IntKeyNode {
2758          volatile Object value;
2759          IntKeyStrongValueNode(int locator, Object key, Object value) {
# Line 2757 | Line 2772 | public class CustomConcurrentHashMap<K,
2772              super(locator, key, value);
2773          }
2774          public final Node getLinkage() { return null; }
2775 <        public final void setLinkage(Node r) { }
2775 >        public final void setLinkage(Node linkage) { }
2776      }
2777  
2778      static final class LinkedIntKeyStrongValueNode
# Line 2770 | Line 2785 | public class CustomConcurrentHashMap<K,
2785              this.linkage = linkage;
2786          }
2787          public final Node getLinkage() { return linkage; }
2788 <        public final void setLinkage(Node r) { linkage = r; }
2788 >        public final void setLinkage(Node linkage) { this.linkage = linkage; }
2789      }
2790  
2791      static final class IntKeyStrongValueNodeFactory
# Line 2789 | Line 2804 | public class CustomConcurrentHashMap<K,
2804          }
2805      }
2806  
2807 <    static abstract class IntKeyIntValueNode
2807 >    abstract static class IntKeyIntValueNode
2808          extends IntKeyNode {
2809          volatile int value;
2810          IntKeyIntValueNode(int locator, Object key, Object value) {
# Line 2810 | Line 2825 | public class CustomConcurrentHashMap<K,
2825              super(locator, key, value);
2826          }
2827          public final Node getLinkage() { return null; }
2828 <        public final void setLinkage(Node r) { }
2828 >        public final void setLinkage(Node linkage) { }
2829      }
2830  
2831      static final class LinkedIntKeyIntValueNode
# Line 2823 | Line 2838 | public class CustomConcurrentHashMap<K,
2838              this.linkage = linkage;
2839          }
2840          public final Node getLinkage() { return linkage; }
2841 <        public final void setLinkage(Node r) { linkage = r; }
2841 >        public final void setLinkage(Node linkage) { this.linkage = linkage; }
2842      }
2843  
2844      static final class IntKeyIntValueNodeFactory
# Line 2842 | Line 2857 | public class CustomConcurrentHashMap<K,
2857          }
2858      }
2859  
2860 <    static abstract class IntKeyWeakValueNode
2860 >    abstract static class IntKeyWeakValueNode
2861          extends IntKeyNode {
2862          volatile EmbeddedWeakReference valueRef;
2863          final CustomConcurrentHashMap cchm;
# Line 2858 | Line 2873 | public class CustomConcurrentHashMap<K,
2873          }
2874          public final Object getValue() {
2875              EmbeddedWeakReference vr = valueRef;
2876 <            return vr == null? null : vr.get();
2876 >            return (vr == null) ? null : vr.get();
2877          }
2878          public final void setValue(Object value) {
2879              if (value == null)
# Line 2876 | Line 2891 | public class CustomConcurrentHashMap<K,
2891              super(locator, key, value, cchm);
2892          }
2893          public final Node getLinkage() { return null; }
2894 <        public final void setLinkage(Node r) { }
2894 >        public final void setLinkage(Node linkage) { }
2895      }
2896  
2897      static final class LinkedIntKeyWeakValueNode
# Line 2890 | Line 2905 | public class CustomConcurrentHashMap<K,
2905              this.linkage = linkage;
2906          }
2907          public final Node getLinkage() { return linkage; }
2908 <        public final void setLinkage(Node r) { linkage = r; }
2908 >        public final void setLinkage(Node linkage) { this.linkage = linkage; }
2909      }
2910  
2911      static final class IntKeyWeakValueNodeFactory
# Line 2910 | Line 2925 | public class CustomConcurrentHashMap<K,
2925      }
2926  
2927  
2928 <    static abstract class IntKeySoftValueNode
2928 >    abstract static class IntKeySoftValueNode
2929          extends IntKeyNode {
2930          volatile EmbeddedSoftReference valueRef;
2931          final CustomConcurrentHashMap cchm;
2932          IntKeySoftValueNode(int locator, Object key, Object value,
2933 <                               CustomConcurrentHashMap cchm) {
2933 >                            CustomConcurrentHashMap cchm) {
2934              super(locator, key);
2935              this.cchm = cchm;
2936              if (value != null)
# Line 2926 | Line 2941 | public class CustomConcurrentHashMap<K,
2941          }
2942          public final Object getValue() {
2943              EmbeddedSoftReference vr = valueRef;
2944 <            return vr == null? null : vr.get();
2944 >            return (vr == null) ? null : vr.get();
2945          }
2946          public final void setValue(Object value) {
2947              if (value == null)
# Line 2944 | Line 2959 | public class CustomConcurrentHashMap<K,
2959              super(locator, key, value, cchm);
2960          }
2961          public final Node getLinkage() { return null; }
2962 <        public final void setLinkage(Node r) { }
2962 >        public final void setLinkage(Node linkage) { }
2963      }
2964  
2965      static final class LinkedIntKeySoftValueNode
# Line 2958 | Line 2973 | public class CustomConcurrentHashMap<K,
2973              this.linkage = linkage;
2974          }
2975          public final Node getLinkage() { return linkage; }
2976 <        public final void setLinkage(Node r) { linkage = r; }
2976 >        public final void setLinkage(Node linkage) { this.linkage = linkage; }
2977      }
2978  
2979      static final class IntKeySoftValueNodeFactory
# Line 2981 | Line 2996 | public class CustomConcurrentHashMap<K,
2996  
2997      // Temporary Unsafe mechanics for preliminary release
2998  
2999 <    static final Unsafe _unsafe;
2999 >    static final Unsafe UNSAFE;
3000      static final long tableBase;
3001      static final int tableShift;
3002      static final long segmentsBase;
3003      static final int segmentsShift;
3004  
2990    private static Unsafe getUnsafe() throws Throwable {
2991        try {
2992            return Unsafe.getUnsafe();
2993        } catch (SecurityException se) {
2994            try {
2995                return java.security.AccessController.doPrivileged
2996                    (new java.security.PrivilegedExceptionAction<Unsafe>() {
2997                        public Unsafe run() throws Exception {
2998                            return getUnsafePrivileged();
2999                        }});
3000            } catch (java.security.PrivilegedActionException e) {
3001                throw e.getCause();
3002            }
3003        }
3004    }
3005
3006    private static Unsafe getUnsafePrivileged()
3007        throws NoSuchFieldException, IllegalAccessException {
3008        Field f = Unsafe.class.getDeclaredField("theUnsafe");
3009        f.setAccessible(true);
3010        return (Unsafe) f.get(null);
3011    }
3012
3005      static {
3006          try {
3007 <            _unsafe = getUnsafe();
3008 <            tableBase = _unsafe.arrayBaseOffset(Node[].class);
3009 <            int s = _unsafe.arrayIndexScale(Node[].class);
3010 <            if ((s & (s-1)) != 0)
3007 >            UNSAFE = getUnsafe();
3008 >            tableBase = UNSAFE.arrayBaseOffset(Node[].class);
3009 >            int scale = UNSAFE.arrayIndexScale(Node[].class);
3010 >            if ((scale & (scale - 1)) != 0)
3011                  throw new Error("data type scale not a power of two");
3012 <            tableShift = 31 - Integer.numberOfLeadingZeros(s);
3013 <            segmentsBase = _unsafe.arrayBaseOffset(Segment[].class);
3014 <            s = _unsafe.arrayIndexScale(Segment[].class);
3015 <            if ((s & (s-1)) != 0)
3012 >            tableShift = 31 - Integer.numberOfLeadingZeros(scale);
3013 >            segmentsBase = UNSAFE.arrayBaseOffset(Segment[].class);
3014 >            scale = UNSAFE.arrayIndexScale(Segment[].class);
3015 >            if ((scale & (scale - 1)) != 0)
3016                  throw new Error("data type scale not a power of two");
3017 <            segmentsShift = 31 - Integer.numberOfLeadingZeros(s);
3017 >            segmentsShift = 31 - Integer.numberOfLeadingZeros(scale);
3018          } catch (Throwable e) {
3019              throw new RuntimeException("Could not initialize intrinsics", e);
3020          }
3021      }
3022  
3023      // Fenced store into segment table array. Unneeded when we have Fences
3024 <    static final  void storeNode(Node[] table,
3025 <                                 int i, Node r) {
3024 >    static final void storeNode(Node[] table,
3025 >                                int i, Node r) {
3026          long nodeOffset = ((long) i << tableShift) + tableBase;
3027 <        _unsafe.putOrderedObject(table, nodeOffset, r);
3027 >        UNSAFE.putOrderedObject(table, nodeOffset, r);
3028      }
3029  
3030 <    static final  void storeSegment(Segment[] segs,
3031 <                                    int i, Segment s) {
3030 >    static final void storeSegment(Segment[] segs,
3031 >                                   int i, Segment s) {
3032          long segmentOffset = ((long) i << segmentsShift) + segmentsBase;
3033 <        _unsafe.putOrderedObject(segs, segmentOffset, s);
3033 >        UNSAFE.putOrderedObject(segs, segmentOffset, s);
3034      }
3035  
3036 <
3036 >    /**
3037 >     * Returns a sun.misc.Unsafe.  Suitable for use in a 3rd party package.
3038 >     * Replace with a simple call to Unsafe.getUnsafe when integrating
3039 >     * into a jdk.
3040 >     *
3041 >     * @return a sun.misc.Unsafe
3042 >     */
3043 >    private static sun.misc.Unsafe getUnsafe() {
3044 >        try {
3045 >            return sun.misc.Unsafe.getUnsafe();
3046 >        } catch (SecurityException tryReflectionInstead) {}
3047 >        try {
3048 >            return java.security.AccessController.doPrivileged
3049 >            (new java.security.PrivilegedExceptionAction<sun.misc.Unsafe>() {
3050 >                public sun.misc.Unsafe run() throws Exception {
3051 >                    Class<sun.misc.Unsafe> k = sun.misc.Unsafe.class;
3052 >                    for (java.lang.reflect.Field f : k.getDeclaredFields()) {
3053 >                        f.setAccessible(true);
3054 >                        Object x = f.get(null);
3055 >                        if (k.isInstance(x))
3056 >                            return k.cast(x);
3057 >                    }
3058 >                    throw new NoSuchFieldError("the Unsafe");
3059 >                }});
3060 >        } catch (java.security.PrivilegedActionException e) {
3061 >            throw new RuntimeException("Could not initialize intrinsics",
3062 >                                       e.getCause());
3063 >        }
3064 >    }
3065   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines