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.26 by jsr166, Wed Jan 16 00:51:11 2013 UTC vs.
Revision 1.29 by jsr166, Sat Jan 19 21:37:46 2013 UTC

# Line 391 | Line 391 | public class CustomConcurrentHashMap<K,
391          final Node[] resizeTable(CustomConcurrentHashMap cchm) {
392              Node[] oldTable = table;
393              if (oldTable == null)
394 <                return table = (Node[])
395 <                    new Node[cchm.initialSegmentCapacity];
394 >                return table = new Node[cchm.initialSegmentCapacity];
395  
396              int oldCapacity = oldTable.length;
397              if (oldCapacity >= MAX_SEGMENT_CAPACITY)
398                  return oldTable;
399 <            Node[] newTable =
401 <                (Node[])new Node[oldCapacity<<1];
399 >            Node[] newTable = new Node[oldCapacity<<1];
400              int sizeMask = newTable.length - 1;
401              NodeFactory fac = cchm.factory;
402              for (int i = 0; i < oldCapacity ; i++) {
# Line 540 | Line 538 | public class CustomConcurrentHashMap<K,
538                  capacity = MAX_SEGMENT_CAPACITY;
539              this.initialSegmentCapacity = capacity;
540          }
541 <        this.segments = (Segment[])new Segment[NSEGMENTS];
541 >        this.segments = new Segment[NSEGMENTS];
542      }
543  
544      /**
# Line 1576 | Line 1574 | public class CustomConcurrentHashMap<K,
1574      private void readObject(java.io.ObjectInputStream s)
1575          throws IOException, ClassNotFoundException {
1576          s.defaultReadObject();
1577 <        this.segments = (Segment[])(new Segment[NSEGMENTS]);
1577 >        this.segments = new Segment[NSEGMENTS];
1578          for (;;) {
1579              K key = (K) s.readObject();
1580              V value = (V) s.readObject();
# Line 1793 | Line 1791 | public class CustomConcurrentHashMap<K,
1791  
1792      // Strong Keys
1793  
1794 <    static abstract class StrongKeyNode implements Node {
1794 >    abstract static class StrongKeyNode implements Node {
1795          final Object key;
1796          final int locator;
1797          StrongKeyNode(int locator, Object key) {
# Line 1805 | Line 1803 | public class CustomConcurrentHashMap<K,
1803      }
1804  
1805  
1806 <    static abstract class StrongKeySelfValueNode
1806 >    abstract static class StrongKeySelfValueNode
1807          extends StrongKeyNode {
1808          StrongKeySelfValueNode(int locator, Object key) {
1809              super(locator, key);
# Line 1852 | Line 1850 | public class CustomConcurrentHashMap<K,
1850          }
1851      }
1852  
1853 <    static abstract class StrongKeyStrongValueNode
1853 >    abstract static class StrongKeyStrongValueNode
1854          extends StrongKeyNode {
1855          volatile Object value;
1856          StrongKeyStrongValueNode(int locator, Object key, Object value) {
# Line 1905 | Line 1903 | public class CustomConcurrentHashMap<K,
1903  
1904      // ...
1905  
1906 <    static abstract class StrongKeyIntValueNode
1906 >    abstract static class StrongKeyIntValueNode
1907          extends StrongKeyNode {
1908          volatile int value;
1909          StrongKeyIntValueNode(int locator, Object key, Object value) {
# Line 1960 | Line 1958 | public class CustomConcurrentHashMap<K,
1958  
1959      // ...
1960  
1961 <    static abstract class StrongKeyWeakValueNode
1961 >    abstract static class StrongKeyWeakValueNode
1962          extends StrongKeyNode {
1963          volatile EmbeddedWeakReference valueRef;
1964          final CustomConcurrentHashMap cchm;
# Line 2028 | Line 2026 | public class CustomConcurrentHashMap<K,
2026      }
2027  
2028  
2029 <    static abstract class StrongKeySoftValueNode
2029 >    abstract static class StrongKeySoftValueNode
2030          extends StrongKeyNode {
2031          volatile EmbeddedSoftReference valueRef;
2032          final CustomConcurrentHashMap cchm;
# Line 2097 | Line 2095 | public class CustomConcurrentHashMap<K,
2095  
2096      // Weak keys
2097  
2098 <    static abstract class WeakKeyNode extends WeakReference
2098 >    abstract static class WeakKeyNode extends WeakReference
2099          implements Node {
2100          final int locator;
2101          final CustomConcurrentHashMap cchm;
# Line 2113 | Line 2111 | public class CustomConcurrentHashMap<K,
2111          }
2112      }
2113  
2114 <    static abstract class WeakKeySelfValueNode
2114 >    abstract static class WeakKeySelfValueNode
2115          extends WeakKeyNode {
2116          WeakKeySelfValueNode(int locator, Object key,
2117                               CustomConcurrentHashMap cchm) {
# Line 2163 | Line 2161 | public class CustomConcurrentHashMap<K,
2161      }
2162  
2163  
2164 <    static abstract class WeakKeyStrongValueNode
2164 >    abstract static class WeakKeyStrongValueNode
2165          extends WeakKeyNode {
2166          volatile Object value;
2167          WeakKeyStrongValueNode(int locator, Object key, Object value,
# Line 2216 | Line 2214 | public class CustomConcurrentHashMap<K,
2214          }
2215      }
2216  
2217 <    static abstract class WeakKeyIntValueNode
2217 >    abstract static class WeakKeyIntValueNode
2218          extends WeakKeyNode {
2219          volatile int value;
2220          WeakKeyIntValueNode(int locator, Object key, Object value,
# Line 2271 | Line 2269 | public class CustomConcurrentHashMap<K,
2269          }
2270      }
2271  
2272 <    static abstract class WeakKeyWeakValueNode
2272 >    abstract static class WeakKeyWeakValueNode
2273          extends WeakKeyNode {
2274          volatile EmbeddedWeakReference valueRef;
2275          WeakKeyWeakValueNode(int locator, Object key, Object value,
# Line 2334 | Line 2332 | public class CustomConcurrentHashMap<K,
2332      }
2333  
2334  
2335 <    static abstract class WeakKeySoftValueNode
2335 >    abstract static class WeakKeySoftValueNode
2336          extends WeakKeyNode {
2337          volatile EmbeddedSoftReference valueRef;
2338          WeakKeySoftValueNode(int locator, Object key, Object value,
# Line 2398 | Line 2396 | public class CustomConcurrentHashMap<K,
2396  
2397      // Soft keys
2398  
2399 <    static abstract class SoftKeyNode extends SoftReference
2399 >    abstract static class SoftKeyNode extends SoftReference
2400          implements Node {
2401          final int locator;
2402          final CustomConcurrentHashMap cchm;
# Line 2414 | Line 2412 | public class CustomConcurrentHashMap<K,
2412          }
2413      }
2414  
2415 <    static abstract class SoftKeySelfValueNode
2415 >    abstract static class SoftKeySelfValueNode
2416          extends SoftKeyNode {
2417          SoftKeySelfValueNode(int locator, Object key,
2418                               CustomConcurrentHashMap cchm) {
# Line 2464 | Line 2462 | public class CustomConcurrentHashMap<K,
2462      }
2463  
2464  
2465 <    static abstract class SoftKeyStrongValueNode
2465 >    abstract static class SoftKeyStrongValueNode
2466          extends SoftKeyNode {
2467          volatile Object value;
2468          SoftKeyStrongValueNode(int locator, Object key, Object value,
# Line 2517 | Line 2515 | public class CustomConcurrentHashMap<K,
2515          }
2516      }
2517  
2518 <    static abstract class SoftKeyIntValueNode
2518 >    abstract static class SoftKeyIntValueNode
2519          extends SoftKeyNode {
2520          volatile int value;
2521          SoftKeyIntValueNode(int locator, Object key, Object value,
# Line 2572 | Line 2570 | public class CustomConcurrentHashMap<K,
2570          }
2571      }
2572  
2573 <    static abstract class SoftKeyWeakValueNode
2573 >    abstract static class SoftKeyWeakValueNode
2574          extends SoftKeyNode {
2575          volatile EmbeddedWeakReference valueRef;
2576          SoftKeyWeakValueNode(int locator, Object key, Object value,
# Line 2635 | Line 2633 | public class CustomConcurrentHashMap<K,
2633      }
2634  
2635  
2636 <    static abstract class SoftKeySoftValueNode
2636 >    abstract static class SoftKeySoftValueNode
2637          extends SoftKeyNode {
2638          volatile EmbeddedSoftReference valueRef;
2639          SoftKeySoftValueNode(int locator, Object key, Object value,
# Line 2697 | Line 2695 | public class CustomConcurrentHashMap<K,
2695          }
2696      }
2697  
2698 <    static abstract class IntKeyNode implements Node {
2698 >    abstract static class IntKeyNode implements Node {
2699          final int key;
2700          IntKeyNode(int locator, Object key) {
2701              this.key = ((Integer)key).intValue();
# Line 2707 | Line 2705 | public class CustomConcurrentHashMap<K,
2705      }
2706  
2707  
2708 <    static abstract class IntKeySelfValueNode
2708 >    abstract static class IntKeySelfValueNode
2709          extends IntKeyNode {
2710          IntKeySelfValueNode(int locator, Object key) {
2711              super(locator, key);
# Line 2754 | Line 2752 | public class CustomConcurrentHashMap<K,
2752          }
2753      }
2754  
2755 <    static abstract class IntKeyStrongValueNode
2755 >    abstract static class IntKeyStrongValueNode
2756          extends IntKeyNode {
2757          volatile Object value;
2758          IntKeyStrongValueNode(int locator, Object key, Object value) {
# Line 2805 | Line 2803 | public class CustomConcurrentHashMap<K,
2803          }
2804      }
2805  
2806 <    static abstract class IntKeyIntValueNode
2806 >    abstract static class IntKeyIntValueNode
2807          extends IntKeyNode {
2808          volatile int value;
2809          IntKeyIntValueNode(int locator, Object key, Object value) {
# Line 2858 | Line 2856 | public class CustomConcurrentHashMap<K,
2856          }
2857      }
2858  
2859 <    static abstract class IntKeyWeakValueNode
2859 >    abstract static class IntKeyWeakValueNode
2860          extends IntKeyNode {
2861          volatile EmbeddedWeakReference valueRef;
2862          final CustomConcurrentHashMap cchm;
# Line 2926 | Line 2924 | public class CustomConcurrentHashMap<K,
2924      }
2925  
2926  
2927 <    static abstract class IntKeySoftValueNode
2927 >    abstract static class IntKeySoftValueNode
2928          extends IntKeyNode {
2929          volatile EmbeddedSoftReference valueRef;
2930          final CustomConcurrentHashMap cchm;
# Line 3007 | Line 3005 | public class CustomConcurrentHashMap<K,
3005          try {
3006              UNSAFE = getUnsafe();
3007              tableBase = UNSAFE.arrayBaseOffset(Node[].class);
3008 <            int s = UNSAFE.arrayIndexScale(Node[].class);
3009 <            if ((s & (s-1)) != 0)
3008 >            int scale = UNSAFE.arrayIndexScale(Node[].class);
3009 >            if ((scale & (scale - 1)) != 0)
3010                  throw new Error("data type scale not a power of two");
3011 <            tableShift = 31 - Integer.numberOfLeadingZeros(s);
3011 >            tableShift = 31 - Integer.numberOfLeadingZeros(scale);
3012              segmentsBase = UNSAFE.arrayBaseOffset(Segment[].class);
3013 <            s = UNSAFE.arrayIndexScale(Segment[].class);
3014 <            if ((s & (s-1)) != 0)
3013 >            scale = UNSAFE.arrayIndexScale(Segment[].class);
3014 >            if ((scale & (scale - 1)) != 0)
3015                  throw new Error("data type scale not a power of two");
3016 <            segmentsShift = 31 - Integer.numberOfLeadingZeros(s);
3016 >            segmentsShift = 31 - Integer.numberOfLeadingZeros(scale);
3017          } catch (Throwable e) {
3018              throw new RuntimeException("Could not initialize intrinsics", e);
3019          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines