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.4 by jsr166, Wed Aug 12 04:02:45 2009 UTC vs.
Revision 1.10 by dl, Fri Feb 12 12:38:25 2010 UTC

# Line 53 | Line 53 | import sun.misc.Unsafe;
53   *     (STRONG,
54   *      new Equivalence<Person>() {
55   *          public boolean equal(Person k, Object x) {
56 < *            return x instanceOf Person && k.name.equals(((Person)x).name);
56 > *            return x instanceof Person && k.name.equals(((Person)x).name);
57   *          }
58   *          public int hash(Object x) {
59 < *             return (x instanceOf Person)? ((Person)x).name.hashCode() : 0;
59 > *             return (x instanceof Person)? ((Person)x).name.hashCode() : 0;
60   *          }
61   *        },
62   *      STRONG, EQUALS, 0);
# Line 533 | Line 533 | public class CustomConcurrentHashMap<K,
533              int sc = (int)((1L + (4L * es) / 3) >>> SEGMENT_BITS);
534              if (sc < MIN_SEGMENT_CAPACITY)
535                  sc = MIN_SEGMENT_CAPACITY;
536 <            else if (sc > MAX_SEGMENT_CAPACITY)
537 <                sc = MAX_SEGMENT_CAPACITY;
538 <            this.initialSegmentCapacity = sc;
536 >            int capacity = MIN_SEGMENT_CAPACITY; // ensure power of two
537 >            while (capacity < sc)
538 >                capacity <<= 1;
539 >            if (capacity > MAX_SEGMENT_CAPACITY)
540 >                capacity = MAX_SEGMENT_CAPACITY;
541 >            this.initialSegmentCapacity = capacity;
542          }
543          this.segments = (Segment[])new Segment[NSEGMENTS];
544      }
# Line 956 | Line 959 | public class CustomConcurrentHashMap<K,
959                      while (p != null) {
960                          Node n = p.getLinkage();
961                          if (p.get() != null && p.getValue() != null) {
962 +                            pred = p;
963 +                            p = n;
964 +                        }
965 +                        else {
966                              if (pred == null)
967                                  tab[i] = n;
968                              else
# Line 963 | Line 970 | public class CustomConcurrentHashMap<K,
970                              seg.decrementCount();
971                              p = n;
972                          }
966                        else {
967                            pred = p;
968                            p = n;
969                        }
973                      }
974                  }
975              } finally {
# Line 2098 | Line 2101 | public class CustomConcurrentHashMap<K,
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 2393 | Line 2396 | public class CustomConcurrentHashMap<K,
2396          final int locator;
2397          final CustomConcurrentHashMap cchm;
2398          SoftKeyNode(int locator, Object key, CustomConcurrentHashMap cchm) {
2399 <            super(key);
2399 >            super(key, getReclamationQueue());
2400              this.locator = locator;
2401              this.cchm = cchm;
2402          }
# Line 3031 | Line 3034 | public class CustomConcurrentHashMap<K,
3034      // Fenced store into segment table array. Unneeded when we have Fences
3035      static final  void storeNode(Node[] table,
3036                                   int i, Node r) {
3037 <        _unsafe.putOrderedObject(table, (i << tableShift) + tableBase, r);
3037 >        long nodeOffset = ((long) i << tableShift) + tableBase;
3038 >        _unsafe.putOrderedObject(table, nodeOffset, r);
3039      }
3040  
3041      static final  void storeSegment(Segment[] segs,
3042                                      int i, Segment s) {
3043 <        _unsafe.putOrderedObject(segs, (i << segmentsShift) + segmentsBase, s);
3043 >        long segmentOffset = ((long) i << segmentsShift) + segmentsBase;
3044 >        _unsafe.putOrderedObject(segs, segmentOffset, s);
3045      }
3046  
3047  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines