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.19 by jsr166, Tue Oct 25 18:46:37 2011 UTC vs.
Revision 1.25 by jsr166, Wed Jan 9 02:51:36 2013 UTC

# Line 320 | Line 320 | public class CustomConcurrentHashMap<K,
320           * Returns the value established during the creation of this
321           * node or, if since updated, the value set by the most
322           * recent call to setValue, or throws an exception if
323 <         * value could not be computed
323 >         * value could not be computed.
324           * @return the value
325           * @throws RuntimeException or Error if computeValue failed
326           */
# Line 544 | Line 544 | public class CustomConcurrentHashMap<K,
544      }
545  
546      /**
547 <     * Creates a new CustomConcurrentHashMap with the given parameters
547 >     * Creates a new CustomConcurrentHashMap with the given parameters.
548       * @param keyStrength the strength for keys
549       * @param keyEquivalence the Equivalence to use for keys
550       * @param valueStrength the strength for values
# Line 573 | Line 573 | public class CustomConcurrentHashMap<K,
573  
574      /**
575       * Returns a new map using Integer keys and the given value
576 <     * parameters
576 >     * parameters.
577       * @param valueStrength the strength for values
578       * @param valueEquivalence the Equivalence to use for values
579       * @param expectedSize an estimate of the number of elements
# Line 591 | Line 591 | public class CustomConcurrentHashMap<K,
591      }
592  
593      /**
594 <     * Returns a new map using the given key parameters and Integer values
594 >     * Returns a new map using the given key parameters and Integer values.
595       * @param keyStrength the strength for keys
596       * @param keyEquivalence the Equivalence to use for keys
597       * @param expectedSize an estimate of the number of elements
# Line 609 | Line 609 | public class CustomConcurrentHashMap<K,
609      }
610  
611      /**
612 <     * Returns a new map using Integer keys and values
612 >     * Returns a new map using Integer keys and values.
613       * @param expectedSize an estimate of the number of elements
614       * that will be held in the map. If no estimate is known,
615       * zero is an acceptable value.
# Line 623 | Line 623 | public class CustomConcurrentHashMap<K,
623      }
624  
625      /**
626 <     * Returns the segment for traversing table for key with given hash
626 >     * Returns the segment for traversing table for key with given hash.
627       * @param hash the hash code for the key
628       * @return the segment, or null if not yet initialized
629       */
# Line 656 | Line 656 | public class CustomConcurrentHashMap<K,
656      }
657  
658      /**
659 <     * Returns node for key, or null if none
659 >     * Returns node for key, or null if none.
660       */
661      final Node findNode(Object key, int hash, Segment seg) {
662          if (seg != null) {
# Line 697 | Line 697 | public class CustomConcurrentHashMap<K,
697      /**
698       * Returns the value associated with a key equivalent to the given
699       * key with respect to this map's key Equivalence, or {@code null}
700 <     * if no such mapping exists
700 >     * if no such mapping exists.
701       *
702       * @param  key   possible key
703       * @return the value associated with the key or <tt>null</tt> if
# Line 942 | Line 942 | public class CustomConcurrentHashMap<K,
942      }
943  
944      /**
945 <     * Remove node if its key or value are null
945 >     * Removes node if its key or value are null.
946       */
947      final void removeIfReclaimed(Node r) {
948          int hash = r.getLocator();
# Line 1600 | Line 1600 | public class CustomConcurrentHashMap<K,
1600          final CustomConcurrentHashMap<K,K> cchm;
1601  
1602          /**
1603 <         * Creates a set with the given parameters
1603 >         * Creates a set with the given parameters.
1604           * @param strength the strength of elements
1605           * @param equivalence the Equivalence to use
1606           * @param expectedSize an estimate of the number of elements
# Line 1621 | Line 1621 | public class CustomConcurrentHashMap<K,
1621           * exists, else adds and returns the given element.
1622           *
1623           * @param e the element
1624 <         * @return e, or an element equivalent to e.
1624 >         * @return e, or an element equivalent to e
1625           */
1626          public K intern(K e) {
1627              K oldElement = cchm.doPut(e, e, true);
# Line 3003 | Line 3003 | public class CustomConcurrentHashMap<K,
3003      static final long segmentsBase;
3004      static final int segmentsShift;
3005  
3006    private static Unsafe getUnsafe() throws Throwable {
3007        try {
3008            return Unsafe.getUnsafe();
3009        } catch (SecurityException se) {
3010            try {
3011                return java.security.AccessController.doPrivileged
3012                    (new java.security.PrivilegedExceptionAction<Unsafe>() {
3013                        public Unsafe run() throws Exception {
3014                            return getUnsafePrivileged();
3015                        }});
3016            } catch (java.security.PrivilegedActionException e) {
3017                throw e.getCause();
3018            }
3019        }
3020    }
3021
3022    private static Unsafe getUnsafePrivileged()
3023        throws NoSuchFieldException, IllegalAccessException {
3024        Field f = Unsafe.class.getDeclaredField("theUnsafe");
3025        f.setAccessible(true);
3026        return (Unsafe) f.get(null);
3027    }
3028
3006      static {
3007          try {
3008              UNSAFE = getUnsafe();
# Line 3045 | Line 3022 | public class CustomConcurrentHashMap<K,
3022      }
3023  
3024      // Fenced store into segment table array. Unneeded when we have Fences
3025 <    static final  void storeNode(Node[] table,
3026 <                                 int i, Node r) {
3025 >    static final void storeNode(Node[] table,
3026 >                                int i, Node r) {
3027          long nodeOffset = ((long) i << tableShift) + tableBase;
3028          UNSAFE.putOrderedObject(table, nodeOffset, r);
3029      }
3030  
3031 <    static final  void storeSegment(Segment[] segs,
3032 <                                    int i, Segment s) {
3031 >    static final void storeSegment(Segment[] segs,
3032 >                                   int i, Segment s) {
3033          long segmentOffset = ((long) i << segmentsShift) + segmentsBase;
3034          UNSAFE.putOrderedObject(segs, segmentOffset, s);
3035      }
3036  
3037 <
3037 >    /**
3038 >     * Returns a sun.misc.Unsafe.  Suitable for use in a 3rd party package.
3039 >     * Replace with a simple call to Unsafe.getUnsafe when integrating
3040 >     * into a jdk.
3041 >     *
3042 >     * @return a sun.misc.Unsafe
3043 >     */
3044 >    private static sun.misc.Unsafe getUnsafe() {
3045 >        try {
3046 >            return sun.misc.Unsafe.getUnsafe();
3047 >        } catch (SecurityException tryReflectionInstead) {}
3048 >        try {
3049 >            return java.security.AccessController.doPrivileged
3050 >            (new java.security.PrivilegedExceptionAction<sun.misc.Unsafe>() {
3051 >                public sun.misc.Unsafe run() throws Exception {
3052 >                    Class<sun.misc.Unsafe> k = sun.misc.Unsafe.class;
3053 >                    for (java.lang.reflect.Field f : k.getDeclaredFields()) {
3054 >                        f.setAccessible(true);
3055 >                        Object x = f.get(null);
3056 >                        if (k.isInstance(x))
3057 >                            return k.cast(x);
3058 >                    }
3059 >                    throw new NoSuchFieldError("the Unsafe");
3060 >                }});
3061 >        } catch (java.security.PrivilegedActionException e) {
3062 >            throw new RuntimeException("Could not initialize intrinsics",
3063 >                                       e.getCause());
3064 >        }
3065 >    }
3066   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines