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; |
31 |
|
* establish a computed value, along with |
32 |
|
* <code>RemappingFunctions</code> that can be used in method |
33 |
|
* {@link CustomConcurrentHashMap#compute} to atomically |
34 |
< |
* replace values. |
34 |
> |
* replace values. |
35 |
|
* |
36 |
|
* <li>Factory methods returning specialized forms for <tt>int</tt> |
37 |
|
* keys and/or values, that may be more space-efficient |
38 |
|
* |
39 |
|
* </ul> |
40 |
< |
* |
40 |
> |
* |
41 |
|
* Per-map settings are established in constructors, as in the |
42 |
|
* following usages (that assume static imports to simplify expression |
43 |
|
* of configuration parameters): |
44 |
< |
* |
44 |
> |
* |
45 |
|
* <pre> |
46 |
|
* {@code |
47 |
|
* identityMap = new CustomConcurrentHashMap<Person,Salary> |
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; |
58 |
> |
* public int hash(Object x) { |
59 |
> |
* return (x instanceof Person) ? ((Person)x).name.hashCode() : 0; |
60 |
|
* } |
61 |
|
* }, |
62 |
|
* STRONG, EQUALS, 0); |
69 |
|
* and identity-based equality for keys. The third usage |
70 |
|
* illustrates a map with a custom Equivalence that looks only at the |
71 |
|
* name field of a (fictional) Person class. |
72 |
< |
* |
72 |
> |
* |
73 |
|
* <p>This class also includes nested class {@link KeySet} |
74 |
|
* that provides space-efficient Set views of maps, also supporting |
75 |
|
* method <code>intern</code>, which may be of use in canonicalizing |
81 |
|
* via a background thread common across all maps. Because of the |
82 |
|
* potential for asynchronous clearing of References, methods such as |
83 |
|
* <code>containsValue</code> have weaker guarantees than you might |
84 |
< |
* expect even in the absence of other explicity concurrent |
84 |
> |
* expect even in the absence of other explicitly concurrent |
85 |
|
* operations. For example <code>containsValue(value)</code> may |
86 |
|
* return true even if <code>value</code> is no longer available upon |
87 |
|
* return from the method. |
126 |
|
* Additionally, because Reference keys/values may become null |
127 |
|
* asynchronously, we cannot ensure snapshot integrity in methods |
128 |
|
* such as containsValue, so do not try to obtain them (so, no |
129 |
< |
* modCounts etc). |
129 |
> |
* modCounts etc). |
130 |
|
* |
131 |
|
* Also, the volatility of Segment count vs table fields are |
132 |
|
* swapped, enabled by ensuring fences on new node assignments. |
138 |
|
* maps. strong denotes ordinary objects. weak and soft denote the |
139 |
|
* corresponding {@link java.lang.ref.Reference} types. |
140 |
|
*/ |
141 |
< |
public enum Strength { |
141 |
> |
public enum Strength { |
142 |
|
strong("Strong"), weak("Weak"), soft("Soft"); |
143 |
|
private final String name; |
144 |
|
Strength(String name) { this.name = name; } |
145 |
|
String getName() { return name; } |
146 |
|
}; |
147 |
|
|
148 |
< |
|
148 |
> |
|
149 |
|
/** The strength of ordinary references */ |
150 |
|
public static final Strength STRONG = Strength.strong; |
151 |
|
|
184 |
|
*/ |
185 |
|
boolean equal(K key, Object x); |
186 |
|
/** |
187 |
< |
* Returns a hash value such that equal(a, b) implies |
187 |
> |
* Returns a hash value such that equal(a, b) implies |
188 |
|
* hash(a)==hash(b). |
189 |
|
* @param x an object queried for membership |
190 |
|
* @return a hash value |
194 |
|
|
195 |
|
// builtin equivalences |
196 |
|
|
197 |
< |
static final class EquivalenceUsingIdentity |
197 |
> |
static final class EquivalenceUsingIdentity |
198 |
|
implements Equivalence<Object>, Serializable { |
199 |
|
private static final long serialVersionUID = 7259069246764182397L; |
200 |
|
public final boolean equal(Object a, Object b) { return a == b; } |
201 |
|
public final int hash(Object a) { return System.identityHashCode(a); } |
202 |
|
} |
203 |
|
|
204 |
< |
static final class EquivalenceUsingEquals |
204 |
> |
static final class EquivalenceUsingEquals |
205 |
|
implements Equivalence<Object>, Serializable { |
206 |
|
private static final long serialVersionUID = 7259069247764182397L; |
207 |
|
public final boolean equal(Object a, Object b) { return a.equals(b); } |
212 |
|
* An Equivalence object performing identity-based comparisons |
213 |
|
* and using {@link System#identityHashCode} for hashing |
214 |
|
*/ |
215 |
< |
public static final Equivalence<Object> IDENTITY = |
215 |
> |
public static final Equivalence<Object> IDENTITY = |
216 |
|
new EquivalenceUsingIdentity(); |
217 |
< |
|
217 |
> |
|
218 |
|
/** |
219 |
|
* An Equivalence object performing {@link Object#equals} based comparisons |
220 |
|
* and using {@link Object#hashCode} hashing |
221 |
|
*/ |
222 |
< |
public static final Equivalence<Object> EQUALS = |
222 |
> |
public static final Equivalence<Object> EQUALS = |
223 |
|
new EquivalenceUsingEquals(); |
224 |
|
|
225 |
|
/** |
226 |
|
* A function computing a mapping from the given key to a value, |
227 |
< |
* or <code>null</code> if there is no mapping. |
227 |
> |
* or <code>null</code> if there is no mapping. |
228 |
|
*/ |
229 |
|
public static interface MappingFunction<K, V> { |
230 |
|
/** |
236 |
|
* simple. The most common usage is to construct a new object |
237 |
|
* serving as an initial mapped value. |
238 |
|
* |
239 |
< |
* @param key the (nonnull) key |
239 |
> |
* @param key the (non-null) key |
240 |
|
* @return a value, or null if none |
241 |
|
*/ |
242 |
|
V map(K key); |
275 |
|
*/ |
276 |
|
static interface NodeFactory extends Serializable { |
277 |
|
/** |
278 |
< |
* Creates and returns a Node using the given parameters |
278 |
> |
* Creates and returns a Node using the given parameters. |
279 |
> |
* |
280 |
|
* @param locator an opaque immutable locator for this node |
281 |
< |
* @parem key the (nonnull) immutable key |
282 |
< |
* @parem value the (nonnull) volatile value; |
283 |
< |
* @param cchm the table creating this node. |
281 |
> |
* @param key the (non-null) immutable key |
282 |
> |
* @param value the (non-null) volatile value |
283 |
> |
* @param cchm the table creating this node |
284 |
|
* @param linkage an opaque volatile linkage for maintaining this node |
285 |
|
*/ |
286 |
< |
Node newNode(int locator, Object key, Object value, |
286 |
> |
Node newNode(int locator, Object key, Object value, |
287 |
|
CustomConcurrentHashMap cchm, Node linkage); |
288 |
|
} |
289 |
|
|
304 |
|
static interface Node extends Reclaimable { |
305 |
|
/** |
306 |
|
* Returns the key established during the creation of this node. |
307 |
< |
* Note: This method is named "get" rether than "getKey" |
307 |
> |
* Note: This method is named "get" rather than "getKey" |
308 |
|
* to simplify usage of Reference keys. |
309 |
|
* @return the key |
310 |
|
*/ |
333 |
|
void setValue(Object value); |
334 |
|
|
335 |
|
/** |
336 |
< |
* Returns the lonkage established during the creation of this |
336 |
> |
* Returns the linkage established during the creation of this |
337 |
|
* node or, if since updated, the linkage set by the most |
338 |
|
* recent call to setLinkage. |
339 |
|
* @return the linkage |
356 |
|
static final class Segment extends ReentrantLock { |
357 |
|
volatile Node[] table; |
358 |
|
int count; |
359 |
< |
|
359 |
> |
|
360 |
|
final void decrementCount() { |
361 |
|
if (--count == 0) |
362 |
|
table = null; |
397 |
|
int oldCapacity = oldTable.length; |
398 |
|
if (oldCapacity >= MAX_SEGMENT_CAPACITY) |
399 |
|
return oldTable; |
400 |
< |
Node[] newTable = |
400 |
> |
Node[] newTable = |
401 |
|
(Node[])new Node[oldCapacity<<1]; |
402 |
|
int sizeMask = newTable.length - 1; |
403 |
|
NodeFactory fac = cchm.factory; |
437 |
|
(pv = p.getValue()) == null) |
438 |
|
--count; |
439 |
|
else |
440 |
< |
newTable[k] = |
440 |
> |
newTable[k] = |
441 |
|
fac.newNode(ph, pk, pv, cchm, newTable[k]); |
442 |
|
} |
443 |
|
} |
478 |
|
* The segments, each of which acts as a hash table |
479 |
|
*/ |
480 |
|
transient volatile Segment[] segments; |
481 |
< |
|
481 |
> |
|
482 |
|
/** |
483 |
|
* The factory for this map |
484 |
|
*/ |
485 |
|
final NodeFactory factory; |
486 |
< |
|
486 |
> |
|
487 |
|
/** |
488 |
|
* Equivalence object for keys |
489 |
|
*/ |
490 |
|
final Equivalence<? super K> keyEquivalence; |
491 |
< |
|
491 |
> |
|
492 |
|
/** |
493 |
|
* Equivalence object for values |
494 |
|
*/ |
495 |
|
final Equivalence<? super V> valueEquivalence; |
496 |
< |
|
496 |
> |
|
497 |
|
/** |
498 |
|
* The initial size of Segment tables when they are first constructed |
499 |
|
*/ |
516 |
|
this.keyEquivalence = keq; |
517 |
|
this.valueEquivalence = veq; |
518 |
|
// Reflectively assemble factory name |
519 |
< |
String factoryName = |
520 |
< |
CustomConcurrentHashMap.class.getName() + "$" + |
521 |
< |
ks + "Key" + |
519 |
> |
String factoryName = |
520 |
> |
CustomConcurrentHashMap.class.getName() + "$" + |
521 |
> |
ks + "Key" + |
522 |
|
vs + "ValueNodeFactory"; |
523 |
|
try { |
524 |
|
this.factory = (NodeFactory) |
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 |
|
} |
558 |
|
Strength valueStrength, |
559 |
|
Equivalence<? super V> valueEquivalence, |
560 |
|
int expectedSize) { |
561 |
< |
this(keyStrength.getName(), keyEquivalence, |
561 |
> |
this(keyStrength.getName(), keyEquivalence, |
562 |
|
valueStrength.getName(), valueEquivalence, |
563 |
|
expectedSize); |
564 |
|
} |
604 |
|
Equivalence<? super KeyType> keyEquivalence, |
605 |
|
int expectedSize) { |
606 |
|
return new CustomConcurrentHashMap<KeyType, Integer> |
607 |
< |
(keyStrength.getName(), keyEquivalence, INT_STRING, EQUALS, |
607 |
> |
(keyStrength.getName(), keyEquivalence, INT_STRING, EQUALS, |
608 |
|
expectedSize); |
609 |
|
} |
610 |
|
|
618 |
|
public static CustomConcurrentHashMap<Integer, Integer> |
619 |
|
newIntKeyIntValueMap(int expectedSize) { |
620 |
|
return new CustomConcurrentHashMap<Integer, Integer> |
621 |
< |
(INT_STRING, EQUALS, INT_STRING, EQUALS, |
621 |
> |
(INT_STRING, EQUALS, INT_STRING, EQUALS, |
622 |
|
expectedSize); |
623 |
|
} |
624 |
|
|
633 |
|
|
634 |
|
/** |
635 |
|
* Returns the segment for possibly inserting into the table |
636 |
< |
* associated with given hash, constructing it if necesary. |
636 |
> |
* associated with given hash, constructing it if necessary. |
637 |
|
* @param hash the hash code for the key |
638 |
|
* @return the segment |
639 |
|
*/ |
642 |
|
int index = (hash >>> SEGMENT_SHIFT) & SEGMENT_MASK; |
643 |
|
Segment seg = segs[index]; |
644 |
|
if (seg == null) { |
645 |
< |
synchronized(segs) { |
645 |
> |
synchronized (segs) { |
646 |
|
seg = segs[index]; |
647 |
|
if (seg == null) { |
648 |
|
seg = new Segment(); |
666 |
|
while (p != null) { |
667 |
|
Object k = p.get(); |
668 |
|
if (k == key || |
669 |
< |
(k != null && |
670 |
< |
p.getLocator() == hash && |
669 |
> |
(k != null && |
670 |
> |
p.getLocator() == hash && |
671 |
|
keyEquivalence.equal((K)k, key))) |
672 |
|
return p; |
673 |
|
p = p.getLinkage(); |
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 kew or <tt>null</tt> if |
703 |
> |
* @return the value associated with the key or <tt>null</tt> if |
704 |
|
* there is no mapping. |
705 |
|
* @throws NullPointerException if the specified key is null |
706 |
|
*/ |
716 |
|
} |
717 |
|
|
718 |
|
/** |
719 |
< |
* Share dimplementation for put, putIfAbsent |
719 |
> |
* Shared implementation for put, putIfAbsent |
720 |
|
*/ |
721 |
|
final V doPut(K key, V value, boolean onlyIfNull) { |
722 |
|
if (key == null || value == null) |
828 |
|
Node r = findNode(key, hash, seg); |
829 |
|
if (r != null) { |
830 |
|
V v = (V)(r.getValue()); |
831 |
< |
if (v == oldValue || |
831 |
> |
if (v == oldValue || |
832 |
|
(v != null && valueEquivalence.equal(v, oldValue))) { |
833 |
|
r.setValue(newValue); |
834 |
|
replaced = true; |
868 |
|
Object k = p.get(); |
869 |
|
if (k == key || |
870 |
|
(k != null && |
871 |
< |
p.getLocator() == hash && |
871 |
> |
p.getLocator() == hash && |
872 |
|
keyEquivalence.equal((K)k, key))) { |
873 |
|
oldValue = (V)(p.getValue()); |
874 |
|
if (pred == null) |
875 |
< |
tab[i] = n; |
875 |
> |
tab[i] = n; |
876 |
|
else |
877 |
|
pred.setLinkage(n); |
878 |
|
seg.decrementCount(); |
915 |
|
Object k = p.get(); |
916 |
|
if (k == key || |
917 |
|
(k != null && |
918 |
< |
p.getLocator() == hash && |
918 |
> |
p.getLocator() == hash && |
919 |
|
keyEquivalence.equal((K)k, key))) { |
920 |
|
V v = (V)(p.getValue()); |
921 |
|
if (v == value || |
922 |
< |
(v != null && |
922 |
> |
(v != null && |
923 |
|
valueEquivalence.equal(v, value))) { |
924 |
|
if (pred == null) |
925 |
< |
tab[i] = n; |
925 |
> |
tab[i] = n; |
926 |
|
else |
927 |
|
pred.setLinkage(n); |
928 |
|
seg.decrementCount(); |
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(); |
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; |
967 |
> |
tab[i] = n; |
968 |
|
else |
969 |
|
pred.setLinkage(n); |
970 |
|
seg.decrementCount(); |
971 |
|
p = n; |
972 |
|
} |
965 |
– |
else { |
966 |
– |
pred = p; |
967 |
– |
p = n; |
968 |
– |
} |
973 |
|
} |
974 |
|
} |
975 |
|
} finally { |
987 |
|
final Segment[] segs = this.segments; |
988 |
|
for (int i = 0; i < segs.length; ++i) { |
989 |
|
Segment seg = segs[i]; |
990 |
< |
if (seg != null && |
991 |
< |
seg.getTableForTraversal() != null && |
990 |
> |
if (seg != null && |
991 |
> |
seg.getTableForTraversal() != null && |
992 |
|
seg.count != 0) |
993 |
|
return false; |
994 |
|
} |
1010 |
|
if (seg != null && seg.getTableForTraversal() != null) |
1011 |
|
sum += seg.count; |
1012 |
|
} |
1013 |
< |
return sum >= Integer.MAX_VALUE? Integer.MAX_VALUE : (int)sum; |
1013 |
> |
return (sum >= Integer.MAX_VALUE) ? Integer.MAX_VALUE : (int) sum; |
1014 |
|
} |
1015 |
|
|
1016 |
|
/** |
1034 |
|
Node[] tab; |
1035 |
|
if (seg != null && (tab = seg.getTableForTraversal()) != null) { |
1036 |
|
for (int j = 0; j < tab.length; ++j) { |
1037 |
< |
for (Node p = tab[j]; |
1038 |
< |
p != null; |
1037 |
> |
for (Node p = tab[j]; |
1038 |
> |
p != null; |
1039 |
|
p = p.getLinkage()) { |
1040 |
|
V v = (V)(p.getValue()); |
1041 |
|
if (v == value || |
1069 |
|
/** |
1070 |
|
* If the specified key is not already associated with a value, |
1071 |
|
* computes its value using the given mappingFunction, and if |
1072 |
< |
* nonnull, enters it into the map. This is equivalent to |
1072 |
> |
* non-null, enters it into the map. This is equivalent to |
1073 |
|
* |
1074 |
|
* <pre> |
1075 |
|
* if (map.containsKey(key)) |
1082 |
|
* </pre> |
1083 |
|
* |
1084 |
|
* except that the action is performed atomically. Some |
1085 |
< |
* attemmpted operations on this map by other threads may be |
1085 |
> |
* attempted operations on this map by other threads may be |
1086 |
|
* blocked while computation is in progress. Because this function |
1087 |
|
* is invoked within atomicity control, the computation should be |
1088 |
|
* short and simple. The most common usage is to construct a new |
1090 |
|
* |
1091 |
|
* @param key key with which the specified value is to be associated |
1092 |
|
* @param mappingFunction the function to compute a value |
1093 |
< |
* @return the current (existing or computed) value associated with |
1093 |
> |
* @return the current (existing or computed) value associated with |
1094 |
|
* the specified key, or <tt>null</tt> if the computation |
1095 |
|
* returned <tt>null</tt>. |
1096 |
< |
* @throws NullPointerException if the specified key or mappingFunction |
1096 |
> |
* @throws NullPointerException if the specified key or mappingFunction |
1097 |
|
* is null, |
1098 |
|
* @throws RuntimeException or Error if the mappingFunction does so, |
1099 |
|
* in which case the mapping is left unestablished. |
1115 |
|
// Map is OK if function throws exception |
1116 |
|
v = mappingFunction.map(key); |
1117 |
|
if (v != null) { |
1118 |
< |
if (r != null) |
1118 |
> |
if (r != null) |
1119 |
|
r.setValue(v); |
1120 |
|
else { |
1121 |
|
Node[] tab = seg.getTableForAdd(this); |
1148 |
|
* else |
1149 |
|
* return remove(key); |
1150 |
|
* </pre> |
1151 |
< |
* |
1152 |
< |
* except that the action is performed atomically. Some attemmpted |
1151 |
> |
* |
1152 |
> |
* except that the action is performed atomically. Some attempted |
1153 |
|
* operations on this map by other threads may be blocked while |
1154 |
|
* computation is in progress. |
1155 |
|
* |
1158 |
|
* <pre> |
1159 |
|
* map.compute(word, new RemappingFunction<String,Integer>() { |
1160 |
|
* public Integer remap(String k, Integer v) { |
1161 |
< |
* return v == null? 1 : v + 1; |
1161 |
> |
* return (v == null) ? 1 : v + 1; |
1162 |
|
* }}); |
1163 |
|
* </pre> |
1164 |
|
* |
1165 |
|
* @param key key with which the specified value is to be associated |
1166 |
|
* @param remappingFunction the function to compute a value |
1167 |
|
* @return the updated value or |
1168 |
< |
* <tt>null</tt> if the computation returned <tt>null</tt> |
1169 |
< |
* @throws NullPointerException if the specified key or remappingFunction |
1168 |
> |
* <tt>null</tt> if the computation returned <tt>null</tt> |
1169 |
> |
* @throws NullPointerException if the specified key or remappingFunction |
1170 |
|
* is null, |
1171 |
|
* @throws RuntimeException or Error if the remappingFunction does so, |
1172 |
|
* in which case the mapping is left in its previous state |
1187 |
|
K k = (K)(p.get()); |
1188 |
|
if (k == key || |
1189 |
|
(k != null && |
1190 |
< |
p.getLocator() == hash && |
1190 |
> |
p.getLocator() == hash && |
1191 |
|
keyEquivalence.equal(k, key))) { |
1192 |
|
value = (V)(p.getValue()); |
1193 |
|
break; |
1197 |
|
} |
1198 |
|
value = remappingFunction.remap(key, value); |
1199 |
|
if (p != null) { |
1200 |
< |
if (value != null) |
1200 |
> |
if (value != null) |
1201 |
|
p.setValue(value); |
1202 |
|
else { |
1203 |
|
Node n = p.getLinkage(); |
1204 |
|
if (pred == null) |
1205 |
< |
tab[i] = n; |
1205 |
> |
tab[i] = n; |
1206 |
|
else |
1207 |
|
pred.setLinkage(n); |
1208 |
|
seg.decrementCount(); |
1209 |
|
} |
1210 |
|
} |
1211 |
|
else if (value != null) { |
1212 |
< |
Node r = |
1212 |
> |
Node r = |
1213 |
|
factory.newNode(hash, key, value, this, tab[i]); |
1214 |
|
// Fences.preStoreFence(r); |
1215 |
|
// tab[i] = r; |
1258 |
|
else if (nextSegmentIndex >= 0) { |
1259 |
|
Segment seg = segments[nextSegmentIndex--]; |
1260 |
|
Node[] t; |
1261 |
< |
if (seg != null && |
1261 |
> |
if (seg != null && |
1262 |
|
(t = seg.getTableForTraversal()) != null) { |
1263 |
|
currentTable = t; |
1264 |
|
nextTableIndex = t.length - 1; |
1291 |
|
final Map.Entry<K,V> nextEntry() { |
1292 |
|
if (nextNode == null) |
1293 |
|
throw new NoSuchElementException(); |
1294 |
< |
WriteThroughEntry e = new WriteThroughEntry((K)nextKey, |
1294 |
> |
WriteThroughEntry e = new WriteThroughEntry((K)nextKey, |
1295 |
|
(V)nextValue); |
1296 |
|
advance(); |
1297 |
|
return e; |
1334 |
|
} |
1335 |
|
} |
1336 |
|
|
1337 |
< |
final class KeyIterator extends HashIterator |
1337 |
> |
final class KeyIterator extends HashIterator |
1338 |
|
implements Iterator<K> { |
1339 |
< |
public K next() { |
1340 |
< |
return super.nextKey(); |
1339 |
> |
public K next() { |
1340 |
> |
return super.nextKey(); |
1341 |
|
} |
1342 |
|
} |
1343 |
|
|
1345 |
|
return new KeyIterator(); |
1346 |
|
} |
1347 |
|
|
1348 |
< |
final class ValueIterator extends HashIterator |
1348 |
> |
final class ValueIterator extends HashIterator |
1349 |
|
implements Iterator<V> { |
1350 |
< |
public V next() { |
1351 |
< |
return super.nextValue(); |
1350 |
> |
public V next() { |
1351 |
> |
return super.nextValue(); |
1352 |
|
} |
1353 |
|
} |
1354 |
|
|
1355 |
< |
final class EntryIterator extends HashIterator |
1355 |
> |
final class EntryIterator extends HashIterator |
1356 |
|
implements Iterator<Map.Entry<K,V>> { |
1357 |
|
public Map.Entry<K,V> next() { |
1358 |
|
return super.nextEntry(); |
1407 |
|
return false; |
1408 |
|
Map.Entry<?,?> e = (Map.Entry<?,?>)o; |
1409 |
|
V v = CustomConcurrentHashMap.this.get(e.getKey()); |
1410 |
< |
return v != null && |
1410 |
> |
return v != null && |
1411 |
|
valueEquivalence.equal(v, e.getValue()); |
1412 |
|
} |
1413 |
|
public boolean remove(Object o) { |
1414 |
|
if (!(o instanceof Map.Entry)) |
1415 |
|
return false; |
1416 |
|
Map.Entry<?,?> e = (Map.Entry<?,?>)o; |
1417 |
< |
return CustomConcurrentHashMap.this.remove(e.getKey(), e.getValue()); |
1417 |
> |
return CustomConcurrentHashMap.this.remove(e.getKey(), |
1418 |
> |
e.getValue()); |
1419 |
|
} |
1420 |
|
public int size() { |
1421 |
|
return CustomConcurrentHashMap.this.size(); |
1506 |
|
public boolean equals(Object o) { |
1507 |
|
if (o == this) |
1508 |
|
return true; |
1509 |
< |
|
1509 |
> |
|
1510 |
|
if (!(o instanceof Map)) |
1511 |
|
return false; |
1512 |
|
Map<K,V> m = (Map<K,V>) o; |
1551 |
|
} |
1552 |
|
|
1553 |
|
/** |
1554 |
< |
* Save the state of the instance to a stream (i.e., serialize |
1555 |
< |
* it). |
1554 |
> |
* Saves the state of the instance to a stream (i.e., serializes it). |
1555 |
> |
* |
1556 |
|
* @param s the stream |
1557 |
|
* @serialData |
1558 |
|
* the key (Object) and value (Object) |
1559 |
|
* for each key-value mapping, followed by a null pair. |
1560 |
|
* The key-value mappings are emitted in no particular order. |
1561 |
|
*/ |
1562 |
< |
private void writeObject(java.io.ObjectOutputStream s) throws IOException { |
1562 |
> |
private void writeObject(java.io.ObjectOutputStream s) throws IOException { |
1563 |
|
s.defaultWriteObject(); |
1564 |
|
for (Map.Entry<K,V> e : entrySet()) { |
1565 |
|
s.writeObject(e.getKey()); |
1570 |
|
} |
1571 |
|
|
1572 |
|
/** |
1573 |
< |
* Reconstitute the instance from a stream (i.e., deserialize it). |
1573 |
> |
* Reconstitutes the instance from a stream (that is, deserializes it). |
1574 |
|
* @param s the stream |
1575 |
|
*/ |
1576 |
|
private void readObject(java.io.ObjectInputStream s) |
1577 |
< |
throws IOException, ClassNotFoundException { |
1577 |
> |
throws IOException, ClassNotFoundException { |
1578 |
|
s.defaultReadObject(); |
1579 |
|
this.segments = (Segment[])(new Segment[NSEGMENTS]); |
1580 |
|
for (;;) { |
1607 |
|
* that will be held in the set. If no estimate is known, zero |
1608 |
|
* is an acceptable value. |
1609 |
|
*/ |
1610 |
< |
public KeySet(Strength strength, |
1610 |
> |
public KeySet(Strength strength, |
1611 |
|
Equivalence<? super K> equivalence, |
1612 |
|
int expectedSize) { |
1613 |
|
this.cchm = new CustomConcurrentHashMap<K,K> |
1614 |
< |
(strength.getName(), equivalence, |
1614 |
> |
(strength.getName(), equivalence, |
1615 |
|
SELF_STRING, equivalence, expectedSize); |
1616 |
|
} |
1617 |
|
|
1619 |
|
* Returns an element equivalent to the given element with |
1620 |
|
* respect to this set's Equivalence, if such an element |
1621 |
|
* exists, else adds and returns the given element. |
1622 |
< |
* |
1622 |
> |
* |
1623 |
|
* @param e the element |
1624 |
|
* @return e, or an element equivalent to e. |
1625 |
|
*/ |
1626 |
|
public K intern(K e) { |
1627 |
|
K oldElement = cchm.doPut(e, e, true); |
1628 |
< |
return (oldElement != null) ? oldElement : e; |
1628 |
> |
return (oldElement != null) ? oldElement : e; |
1629 |
|
} |
1630 |
< |
|
1630 |
> |
|
1631 |
|
/** |
1632 |
|
* Returns <tt>true</tt> if this set contains an |
1633 |
|
* element equivalent to the given element with respect |
1638 |
|
public boolean contains(Object o) { |
1639 |
|
return cchm.containsKey(o); |
1640 |
|
} |
1641 |
< |
|
1641 |
> |
|
1642 |
|
/** |
1643 |
|
* Returns a <i>weakly consistent iterator</i> over the |
1644 |
|
* elements in this set, that may reflect some, all or none of |
1649 |
|
public Iterator<K> iterator() { |
1650 |
|
return cchm.keyIterator(); |
1651 |
|
} |
1652 |
< |
|
1652 |
> |
|
1653 |
|
/** |
1654 |
|
* Adds the specified element to this set if there is not |
1655 |
|
* already an element equivalent to the given element with |
1691 |
|
public int size() { |
1692 |
|
return cchm.size(); |
1693 |
|
} |
1694 |
< |
|
1694 |
> |
|
1695 |
|
/** |
1696 |
|
* Removes all of the elements from this set. |
1697 |
|
*/ |
1754 |
|
Reference<?> r = q.remove(); |
1755 |
|
if (r instanceof Reclaimable) |
1756 |
|
((Reclaimable)r).onReclamation(); |
1757 |
< |
} catch (InterruptedException e) { |
1758 |
< |
/* ignore */ |
1757 |
> |
} catch (InterruptedException e) { |
1758 |
> |
/* ignore */ |
1759 |
|
} |
1760 |
|
} |
1761 |
|
} |
1763 |
|
|
1764 |
|
// classes extending Weak/soft refs embedded in reclaimable nodes |
1765 |
|
|
1766 |
< |
static class EmbeddedWeakReference extends WeakReference |
1766 |
> |
static class EmbeddedWeakReference extends WeakReference |
1767 |
|
implements Reclaimable { |
1768 |
|
final Reclaimable outer; |
1769 |
|
EmbeddedWeakReference(Object x, Reclaimable outer) { |
1770 |
|
super(x, getReclamationQueue()); |
1771 |
|
this.outer = outer; |
1772 |
|
} |
1773 |
< |
public final void onReclamation() { |
1773 |
> |
public final void onReclamation() { |
1774 |
|
clear(); |
1775 |
< |
outer.onReclamation(); |
1775 |
> |
outer.onReclamation(); |
1776 |
|
} |
1777 |
|
} |
1778 |
|
|
1779 |
< |
static class EmbeddedSoftReference extends SoftReference |
1779 |
> |
static class EmbeddedSoftReference extends SoftReference |
1780 |
|
implements Reclaimable { |
1781 |
|
final Reclaimable outer; |
1782 |
|
EmbeddedSoftReference(Object x, Reclaimable outer) { |
1783 |
|
super(x, getReclamationQueue()); |
1784 |
|
this.outer = outer; |
1785 |
|
} |
1786 |
< |
public final void onReclamation() { |
1786 |
> |
public final void onReclamation() { |
1787 |
|
clear(); |
1788 |
< |
outer.onReclamation(); |
1788 |
> |
outer.onReclamation(); |
1789 |
|
} |
1790 |
|
} |
1791 |
|
|
1805 |
|
} |
1806 |
|
|
1807 |
|
|
1808 |
< |
static abstract class StrongKeySelfValueNode |
1808 |
> |
static abstract class StrongKeySelfValueNode |
1809 |
|
extends StrongKeyNode { |
1810 |
|
StrongKeySelfValueNode(int locator, Object key) { |
1811 |
|
super(locator, key); |
1815 |
|
public final void onReclamation() { } |
1816 |
|
} |
1817 |
|
|
1818 |
< |
static final class TerminalStrongKeySelfValueNode |
1818 |
> |
static final class TerminalStrongKeySelfValueNode |
1819 |
|
extends StrongKeySelfValueNode { |
1820 |
|
TerminalStrongKeySelfValueNode(int locator, Object key) { |
1821 |
|
super(locator, key); |
1824 |
|
public final void setLinkage(Node r) { } |
1825 |
|
} |
1826 |
|
|
1827 |
< |
static final class LinkedStrongKeySelfValueNode |
1827 |
> |
static final class LinkedStrongKeySelfValueNode |
1828 |
|
extends StrongKeySelfValueNode { |
1829 |
|
volatile Node linkage; |
1830 |
< |
LinkedStrongKeySelfValueNode(int locator, Object key, |
1830 |
> |
LinkedStrongKeySelfValueNode(int locator, Object key, |
1831 |
|
Node linkage) { |
1832 |
|
super(locator, key); |
1833 |
|
this.linkage = linkage; |
1840 |
|
implements NodeFactory, Serializable { |
1841 |
|
private static final long serialVersionUID = 7249069346764182397L; |
1842 |
|
public final Node newNode(int locator, |
1843 |
< |
Object key, Object value, |
1843 |
> |
Object key, Object value, |
1844 |
|
CustomConcurrentHashMap cchm, |
1845 |
|
Node linkage) { |
1846 |
|
if (linkage == null) |
1850 |
|
return new LinkedStrongKeySelfValueNode |
1851 |
|
(locator, key, linkage); |
1852 |
|
} |
1853 |
< |
} |
1853 |
> |
} |
1854 |
|
|
1855 |
< |
static abstract class StrongKeyStrongValueNode |
1855 |
> |
static abstract class StrongKeyStrongValueNode |
1856 |
|
extends StrongKeyNode { |
1857 |
|
volatile Object value; |
1858 |
|
StrongKeyStrongValueNode(int locator, Object key, Object value) { |
1864 |
|
public final void onReclamation() { } |
1865 |
|
} |
1866 |
|
|
1867 |
< |
static final class TerminalStrongKeyStrongValueNode |
1867 |
> |
static final class TerminalStrongKeyStrongValueNode |
1868 |
|
extends StrongKeyStrongValueNode { |
1869 |
|
TerminalStrongKeyStrongValueNode(int locator, |
1870 |
|
Object key, Object value) { |
1874 |
|
public final void setLinkage(Node r) { } |
1875 |
|
} |
1876 |
|
|
1877 |
< |
static final class LinkedStrongKeyStrongValueNode |
1877 |
> |
static final class LinkedStrongKeyStrongValueNode |
1878 |
|
extends StrongKeyStrongValueNode { |
1879 |
|
volatile Node linkage; |
1880 |
|
LinkedStrongKeyStrongValueNode(int locator, |
1881 |
< |
Object key, Object value, |
1881 |
> |
Object key, Object value, |
1882 |
|
Node linkage) { |
1883 |
|
super(locator, key, value); |
1884 |
|
this.linkage = linkage; |
1887 |
|
public final void setLinkage(Node r) { linkage = r; } |
1888 |
|
} |
1889 |
|
|
1890 |
< |
static final class StrongKeyStrongValueNodeFactory |
1890 |
> |
static final class StrongKeyStrongValueNodeFactory |
1891 |
|
implements NodeFactory, Serializable { |
1892 |
|
private static final long serialVersionUID = 7249069346764182397L; |
1893 |
|
public final Node newNode(int locator, |
1894 |
< |
Object key, Object value, |
1894 |
> |
Object key, Object value, |
1895 |
|
CustomConcurrentHashMap cchm, |
1896 |
|
Node linkage) { |
1897 |
|
if (linkage == null) |
1901 |
|
return new LinkedStrongKeyStrongValueNode |
1902 |
|
(locator, key, value, linkage); |
1903 |
|
} |
1904 |
< |
} |
1904 |
> |
} |
1905 |
|
|
1906 |
|
// ... |
1907 |
|
|
1908 |
< |
static abstract class StrongKeyIntValueNode |
1908 |
> |
static abstract class StrongKeyIntValueNode |
1909 |
|
extends StrongKeyNode { |
1910 |
|
volatile int value; |
1911 |
|
StrongKeyIntValueNode(int locator, Object key, Object value) { |
1913 |
|
this.value = ((Integer)value).intValue(); |
1914 |
|
} |
1915 |
|
public final Object getValue() { return Integer.valueOf(value); } |
1916 |
< |
public final void setValue(Object value) { |
1916 |
> |
public final void setValue(Object value) { |
1917 |
|
this.value = ((Integer)value).intValue(); |
1918 |
|
} |
1919 |
|
public final void onReclamation() { } |
1920 |
|
} |
1921 |
|
|
1922 |
< |
static final class TerminalStrongKeyIntValueNode |
1922 |
> |
static final class TerminalStrongKeyIntValueNode |
1923 |
|
extends StrongKeyIntValueNode { |
1924 |
|
TerminalStrongKeyIntValueNode(int locator, |
1925 |
|
Object key, Object value) { |
1929 |
|
public final void setLinkage(Node r) { } |
1930 |
|
} |
1931 |
|
|
1932 |
< |
static final class LinkedStrongKeyIntValueNode |
1932 |
> |
static final class LinkedStrongKeyIntValueNode |
1933 |
|
extends StrongKeyIntValueNode { |
1934 |
|
volatile Node linkage; |
1935 |
|
LinkedStrongKeyIntValueNode(int locator, |
1936 |
< |
Object key, Object value, |
1936 |
> |
Object key, Object value, |
1937 |
|
Node linkage) { |
1938 |
|
super(locator, key, value); |
1939 |
|
this.linkage = linkage; |
1942 |
|
public final void setLinkage(Node r) { linkage = r; } |
1943 |
|
} |
1944 |
|
|
1945 |
< |
static final class StrongKeyIntValueNodeFactory |
1945 |
> |
static final class StrongKeyIntValueNodeFactory |
1946 |
|
implements NodeFactory, Serializable { |
1947 |
|
private static final long serialVersionUID = 7249069346764182397L; |
1948 |
|
public final Node newNode(int locator, |
1949 |
< |
Object key, Object value, |
1949 |
> |
Object key, Object value, |
1950 |
|
CustomConcurrentHashMap cchm, |
1951 |
|
Node linkage) { |
1952 |
|
if (linkage == null) |
1956 |
|
return new LinkedStrongKeyIntValueNode |
1957 |
|
(locator, key, value, linkage); |
1958 |
|
} |
1959 |
< |
} |
1959 |
> |
} |
1960 |
|
|
1961 |
|
// ... |
1962 |
|
|
1963 |
< |
static abstract class StrongKeyWeakValueNode |
1963 |
> |
static abstract class StrongKeyWeakValueNode |
1964 |
|
extends StrongKeyNode { |
1965 |
|
volatile EmbeddedWeakReference valueRef; |
1966 |
|
final CustomConcurrentHashMap cchm; |
1967 |
< |
StrongKeyWeakValueNode(int locator, Object key, Object value, |
1967 |
> |
StrongKeyWeakValueNode(int locator, Object key, Object value, |
1968 |
|
CustomConcurrentHashMap cchm) { |
1969 |
|
super(locator, key); |
1970 |
|
this.cchm = cchm; |
1976 |
|
} |
1977 |
|
public final Object getValue() { |
1978 |
|
EmbeddedWeakReference vr = valueRef; |
1979 |
< |
return vr == null? null : vr.get(); |
1979 |
> |
return (vr == null) ? null : vr.get(); |
1980 |
|
} |
1981 |
|
public final void setValue(Object value) { |
1982 |
|
if (value == null) |
1986 |
|
} |
1987 |
|
} |
1988 |
|
|
1989 |
< |
static final class TerminalStrongKeyWeakValueNode |
1989 |
> |
static final class TerminalStrongKeyWeakValueNode |
1990 |
|
extends StrongKeyWeakValueNode { |
1991 |
|
TerminalStrongKeyWeakValueNode(int locator, |
1992 |
< |
Object key, Object value, |
1992 |
> |
Object key, Object value, |
1993 |
|
CustomConcurrentHashMap cchm) { |
1994 |
|
super(locator, key, value, cchm); |
1995 |
|
} |
1997 |
|
public final void setLinkage(Node r) { } |
1998 |
|
} |
1999 |
|
|
2000 |
< |
static final class LinkedStrongKeyWeakValueNode |
2000 |
> |
static final class LinkedStrongKeyWeakValueNode |
2001 |
|
extends StrongKeyWeakValueNode { |
2002 |
|
volatile Node linkage; |
2003 |
|
LinkedStrongKeyWeakValueNode(int locator, |
2004 |
< |
Object key, Object value, |
2004 |
> |
Object key, Object value, |
2005 |
|
CustomConcurrentHashMap cchm, |
2006 |
|
Node linkage) { |
2007 |
|
super(locator, key, value, cchm); |
2011 |
|
public final void setLinkage(Node r) { linkage = r; } |
2012 |
|
} |
2013 |
|
|
2014 |
< |
static final class StrongKeyWeakValueNodeFactory |
2014 |
> |
static final class StrongKeyWeakValueNodeFactory |
2015 |
|
implements NodeFactory, Serializable { |
2016 |
|
private static final long serialVersionUID = 7249069346764182397L; |
2017 |
< |
public final Node newNode(int locator, |
2018 |
< |
Object key, Object value, |
2017 |
> |
public final Node newNode(int locator, |
2018 |
> |
Object key, Object value, |
2019 |
|
CustomConcurrentHashMap cchm, |
2020 |
|
Node linkage) { |
2021 |
|
if (linkage == null) |
2025 |
|
return new LinkedStrongKeyWeakValueNode |
2026 |
|
(locator, key, value, cchm, linkage); |
2027 |
|
} |
2028 |
< |
} |
2028 |
> |
} |
2029 |
|
|
2030 |
|
|
2031 |
< |
static abstract class StrongKeySoftValueNode |
2031 |
> |
static abstract class StrongKeySoftValueNode |
2032 |
|
extends StrongKeyNode { |
2033 |
|
volatile EmbeddedSoftReference valueRef; |
2034 |
|
final CustomConcurrentHashMap cchm; |
2035 |
< |
StrongKeySoftValueNode(int locator, Object key, Object value, |
2035 |
> |
StrongKeySoftValueNode(int locator, Object key, Object value, |
2036 |
|
CustomConcurrentHashMap cchm) { |
2037 |
|
super(locator, key); |
2038 |
|
this.cchm = cchm; |
2044 |
|
} |
2045 |
|
public final Object getValue() { |
2046 |
|
EmbeddedSoftReference vr = valueRef; |
2047 |
< |
return vr == null? null : vr.get(); |
2047 |
> |
return (vr == null) ? null : vr.get(); |
2048 |
|
} |
2049 |
|
public final void setValue(Object value) { |
2050 |
|
if (value == null) |
2054 |
|
} |
2055 |
|
} |
2056 |
|
|
2057 |
< |
static final class TerminalStrongKeySoftValueNode |
2057 |
> |
static final class TerminalStrongKeySoftValueNode |
2058 |
|
extends StrongKeySoftValueNode { |
2059 |
|
TerminalStrongKeySoftValueNode(int locator, |
2060 |
< |
Object key, Object value, |
2060 |
> |
Object key, Object value, |
2061 |
|
CustomConcurrentHashMap cchm) { |
2062 |
|
super(locator, key, value, cchm); |
2063 |
|
} |
2065 |
|
public final void setLinkage(Node r) { } |
2066 |
|
} |
2067 |
|
|
2068 |
< |
static final class LinkedStrongKeySoftValueNode |
2068 |
> |
static final class LinkedStrongKeySoftValueNode |
2069 |
|
extends StrongKeySoftValueNode { |
2070 |
|
volatile Node linkage; |
2071 |
|
LinkedStrongKeySoftValueNode(int locator, |
2072 |
< |
Object key, Object value, |
2072 |
> |
Object key, Object value, |
2073 |
|
CustomConcurrentHashMap cchm, |
2074 |
|
Node linkage) { |
2075 |
|
super(locator, key, value, cchm); |
2079 |
|
public final void setLinkage(Node r) { linkage = r; } |
2080 |
|
} |
2081 |
|
|
2082 |
< |
static final class StrongKeySoftValueNodeFactory |
2082 |
> |
static final class StrongKeySoftValueNodeFactory |
2083 |
|
implements NodeFactory, Serializable { |
2084 |
|
private static final long serialVersionUID = 7249069346764182397L; |
2085 |
< |
public final Node newNode(int locator, |
2086 |
< |
Object key, Object value, |
2085 |
> |
public final Node newNode(int locator, |
2086 |
> |
Object key, Object value, |
2087 |
|
CustomConcurrentHashMap cchm, |
2088 |
|
Node linkage) { |
2089 |
|
if (linkage == null) |
2093 |
|
return new LinkedStrongKeySoftValueNode |
2094 |
|
(locator, key, value, cchm, linkage); |
2095 |
|
} |
2096 |
< |
} |
2096 |
> |
} |
2097 |
|
|
2098 |
|
// Weak keys |
2099 |
|
|
2102 |
|
final int locator; |
2103 |
|
final CustomConcurrentHashMap cchm; |
2104 |
|
WeakKeyNode(int locator, Object key, CustomConcurrentHashMap cchm) { |
2105 |
< |
super(key); |
2105 |
> |
super(key, getReclamationQueue()); |
2106 |
|
this.locator = locator; |
2107 |
|
this.cchm = cchm; |
2108 |
|
} |
2109 |
|
public final int getLocator() { return locator; } |
2110 |
< |
public final void onReclamation() { |
2110 |
> |
public final void onReclamation() { |
2111 |
|
clear(); |
2112 |
|
cchm.removeIfReclaimed(this); |
2113 |
|
} |
2114 |
|
} |
2115 |
|
|
2116 |
< |
static abstract class WeakKeySelfValueNode |
2116 |
> |
static abstract class WeakKeySelfValueNode |
2117 |
|
extends WeakKeyNode { |
2118 |
< |
WeakKeySelfValueNode(int locator, Object key, CustomConcurrentHashMap cchm) { |
2118 |
> |
WeakKeySelfValueNode(int locator, Object key, |
2119 |
> |
CustomConcurrentHashMap cchm) { |
2120 |
|
super(locator, key, cchm); |
2121 |
|
} |
2122 |
|
public final Object getValue() { return get(); } |
2123 |
|
public final void setValue(Object value) { } |
2124 |
|
} |
2125 |
|
|
2126 |
< |
static final class TerminalWeakKeySelfValueNode |
2126 |
> |
static final class TerminalWeakKeySelfValueNode |
2127 |
|
extends WeakKeySelfValueNode { |
2128 |
< |
TerminalWeakKeySelfValueNode(int locator, Object key, CustomConcurrentHashMap cchm) { |
2128 |
> |
TerminalWeakKeySelfValueNode(int locator, Object key, |
2129 |
> |
CustomConcurrentHashMap cchm) { |
2130 |
|
super(locator, key, cchm); |
2131 |
|
} |
2132 |
|
public final Node getLinkage() { return null; } |
2133 |
|
public final void setLinkage(Node r) { } |
2134 |
|
} |
2135 |
|
|
2136 |
< |
static final class LinkedWeakKeySelfValueNode |
2136 |
> |
static final class LinkedWeakKeySelfValueNode |
2137 |
|
extends WeakKeySelfValueNode { |
2138 |
|
volatile Node linkage; |
2139 |
< |
LinkedWeakKeySelfValueNode(int locator, Object key, CustomConcurrentHashMap cchm, |
2139 |
> |
LinkedWeakKeySelfValueNode(int locator, Object key, |
2140 |
> |
CustomConcurrentHashMap cchm, |
2141 |
|
Node linkage) { |
2142 |
|
super(locator, key, cchm); |
2143 |
|
this.linkage = linkage; |
2150 |
|
implements NodeFactory, Serializable { |
2151 |
|
private static final long serialVersionUID = 7249069346764182397L; |
2152 |
|
public final Node newNode(int locator, |
2153 |
< |
Object key, Object value, |
2153 |
> |
Object key, Object value, |
2154 |
|
CustomConcurrentHashMap cchm, |
2155 |
|
Node linkage) { |
2156 |
|
if (linkage == null) |
2160 |
|
return new LinkedWeakKeySelfValueNode |
2161 |
|
(locator, key, cchm, linkage); |
2162 |
|
} |
2163 |
< |
} |
2163 |
> |
} |
2164 |
|
|
2165 |
|
|
2166 |
< |
static abstract class WeakKeyStrongValueNode |
2166 |
> |
static abstract class WeakKeyStrongValueNode |
2167 |
|
extends WeakKeyNode { |
2168 |
|
volatile Object value; |
2169 |
< |
WeakKeyStrongValueNode(int locator, Object key, Object value, CustomConcurrentHashMap cchm) { |
2169 |
> |
WeakKeyStrongValueNode(int locator, Object key, Object value, |
2170 |
> |
CustomConcurrentHashMap cchm) { |
2171 |
|
super(locator, key, cchm); |
2172 |
|
this.value = value; |
2173 |
|
} |
2175 |
|
public final void setValue(Object value) { this.value = value; } |
2176 |
|
} |
2177 |
|
|
2178 |
< |
static final class TerminalWeakKeyStrongValueNode |
2178 |
> |
static final class TerminalWeakKeyStrongValueNode |
2179 |
|
extends WeakKeyStrongValueNode { |
2180 |
|
TerminalWeakKeyStrongValueNode(int locator, |
2181 |
< |
Object key, Object value, CustomConcurrentHashMap cchm) { |
2181 |
> |
Object key, Object value, |
2182 |
> |
CustomConcurrentHashMap cchm) { |
2183 |
|
super(locator, key, value, cchm); |
2184 |
|
} |
2185 |
|
public final Node getLinkage() { return null; } |
2186 |
|
public final void setLinkage(Node r) { } |
2187 |
|
} |
2188 |
|
|
2189 |
< |
static final class LinkedWeakKeyStrongValueNode |
2189 |
> |
static final class LinkedWeakKeyStrongValueNode |
2190 |
|
extends WeakKeyStrongValueNode { |
2191 |
|
volatile Node linkage; |
2192 |
|
LinkedWeakKeyStrongValueNode(int locator, |
2193 |
< |
Object key, Object value, CustomConcurrentHashMap cchm, |
2193 |
> |
Object key, Object value, |
2194 |
> |
CustomConcurrentHashMap cchm, |
2195 |
|
Node linkage) { |
2196 |
|
super(locator, key, value, cchm); |
2197 |
|
this.linkage = linkage; |
2200 |
|
public final void setLinkage(Node r) { linkage = r; } |
2201 |
|
} |
2202 |
|
|
2203 |
< |
static final class WeakKeyStrongValueNodeFactory |
2203 |
> |
static final class WeakKeyStrongValueNodeFactory |
2204 |
|
implements NodeFactory, Serializable { |
2205 |
|
private static final long serialVersionUID = 7249069346764182397L; |
2206 |
|
public final Node newNode(int locator, |
2207 |
< |
Object key, Object value, |
2207 |
> |
Object key, Object value, |
2208 |
|
CustomConcurrentHashMap cchm, |
2209 |
|
Node linkage) { |
2210 |
|
if (linkage == null) |
2214 |
|
return new LinkedWeakKeyStrongValueNode |
2215 |
|
(locator, key, value, cchm, linkage); |
2216 |
|
} |
2217 |
< |
} |
2217 |
> |
} |
2218 |
|
|
2219 |
< |
static abstract class WeakKeyIntValueNode |
2219 |
> |
static abstract class WeakKeyIntValueNode |
2220 |
|
extends WeakKeyNode { |
2221 |
|
volatile int value; |
2222 |
|
WeakKeyIntValueNode(int locator, Object key, Object value, |
2225 |
|
this.value = ((Integer)value).intValue(); |
2226 |
|
} |
2227 |
|
public final Object getValue() { return Integer.valueOf(value); } |
2228 |
< |
public final void setValue(Object value) { |
2228 |
> |
public final void setValue(Object value) { |
2229 |
|
this.value = ((Integer)value).intValue(); |
2230 |
|
} |
2231 |
|
} |
2232 |
|
|
2233 |
< |
static final class TerminalWeakKeyIntValueNode |
2233 |
> |
static final class TerminalWeakKeyIntValueNode |
2234 |
|
extends WeakKeyIntValueNode { |
2235 |
|
TerminalWeakKeyIntValueNode(int locator, |
2236 |
|
Object key, Object value, |
2241 |
|
public final void setLinkage(Node r) { } |
2242 |
|
} |
2243 |
|
|
2244 |
< |
static final class LinkedWeakKeyIntValueNode |
2244 |
> |
static final class LinkedWeakKeyIntValueNode |
2245 |
|
extends WeakKeyIntValueNode { |
2246 |
|
volatile Node linkage; |
2247 |
|
LinkedWeakKeyIntValueNode(int locator, |
2248 |
< |
Object key, Object value, |
2248 |
> |
Object key, Object value, |
2249 |
|
CustomConcurrentHashMap cchm, |
2250 |
|
Node linkage) { |
2251 |
|
super(locator, key, value, cchm); |
2255 |
|
public final void setLinkage(Node r) { linkage = r; } |
2256 |
|
} |
2257 |
|
|
2258 |
< |
static final class WeakKeyIntValueNodeFactory |
2258 |
> |
static final class WeakKeyIntValueNodeFactory |
2259 |
|
implements NodeFactory, Serializable { |
2260 |
|
private static final long serialVersionUID = 7249069346764182397L; |
2261 |
|
public final Node newNode(int locator, |
2262 |
< |
Object key, Object value, |
2262 |
> |
Object key, Object value, |
2263 |
|
CustomConcurrentHashMap cchm, |
2264 |
|
Node linkage) { |
2265 |
|
if (linkage == null) |
2269 |
|
return new LinkedWeakKeyIntValueNode |
2270 |
|
(locator, key, value, cchm, linkage); |
2271 |
|
} |
2272 |
< |
} |
2272 |
> |
} |
2273 |
|
|
2274 |
< |
static abstract class WeakKeyWeakValueNode |
2274 |
> |
static abstract class WeakKeyWeakValueNode |
2275 |
|
extends WeakKeyNode { |
2276 |
|
volatile EmbeddedWeakReference valueRef; |
2277 |
< |
WeakKeyWeakValueNode(int locator, Object key, Object value, |
2277 |
> |
WeakKeyWeakValueNode(int locator, Object key, Object value, |
2278 |
|
CustomConcurrentHashMap cchm) { |
2279 |
|
super(locator, key, cchm); |
2280 |
|
if (value != null) |
2282 |
|
} |
2283 |
|
public final Object getValue() { |
2284 |
|
EmbeddedWeakReference vr = valueRef; |
2285 |
< |
return vr == null? null : vr.get(); |
2285 |
> |
return (vr == null) ? null : vr.get(); |
2286 |
|
} |
2287 |
|
public final void setValue(Object value) { |
2288 |
|
if (value == null) |
2292 |
|
} |
2293 |
|
} |
2294 |
|
|
2295 |
< |
static final class TerminalWeakKeyWeakValueNode |
2295 |
> |
static final class TerminalWeakKeyWeakValueNode |
2296 |
|
extends WeakKeyWeakValueNode { |
2297 |
|
TerminalWeakKeyWeakValueNode(int locator, |
2298 |
< |
Object key, Object value, |
2298 |
> |
Object key, Object value, |
2299 |
|
CustomConcurrentHashMap cchm) { |
2300 |
|
super(locator, key, value, cchm); |
2301 |
|
} |
2303 |
|
public final void setLinkage(Node r) { } |
2304 |
|
} |
2305 |
|
|
2306 |
< |
static final class LinkedWeakKeyWeakValueNode |
2306 |
> |
static final class LinkedWeakKeyWeakValueNode |
2307 |
|
extends WeakKeyWeakValueNode { |
2308 |
|
volatile Node linkage; |
2309 |
|
LinkedWeakKeyWeakValueNode(int locator, |
2310 |
< |
Object key, Object value, |
2310 |
> |
Object key, Object value, |
2311 |
|
CustomConcurrentHashMap cchm, |
2312 |
|
Node linkage) { |
2313 |
|
super(locator, key, value, cchm); |
2317 |
|
public final void setLinkage(Node r) { linkage = r; } |
2318 |
|
} |
2319 |
|
|
2320 |
< |
static final class WeakKeyWeakValueNodeFactory |
2320 |
> |
static final class WeakKeyWeakValueNodeFactory |
2321 |
|
implements NodeFactory, Serializable { |
2322 |
|
private static final long serialVersionUID = 7249069346764182397L; |
2323 |
< |
public final Node newNode(int locator, |
2324 |
< |
Object key, Object value, |
2323 |
> |
public final Node newNode(int locator, |
2324 |
> |
Object key, Object value, |
2325 |
|
CustomConcurrentHashMap cchm, |
2326 |
|
Node linkage) { |
2327 |
|
if (linkage == null) |
2331 |
|
return new LinkedWeakKeyWeakValueNode |
2332 |
|
(locator, key, value, cchm, linkage); |
2333 |
|
} |
2334 |
< |
} |
2334 |
> |
} |
2335 |
|
|
2336 |
|
|
2337 |
< |
static abstract class WeakKeySoftValueNode |
2337 |
> |
static abstract class WeakKeySoftValueNode |
2338 |
|
extends WeakKeyNode { |
2339 |
|
volatile EmbeddedSoftReference valueRef; |
2340 |
< |
WeakKeySoftValueNode(int locator, Object key, Object value, |
2340 |
> |
WeakKeySoftValueNode(int locator, Object key, Object value, |
2341 |
|
CustomConcurrentHashMap cchm) { |
2342 |
|
super(locator, key, cchm); |
2343 |
|
if (value != null) |
2345 |
|
} |
2346 |
|
public final Object getValue() { |
2347 |
|
EmbeddedSoftReference vr = valueRef; |
2348 |
< |
return vr == null? null : vr.get(); |
2348 |
> |
return (vr == null) ? null : vr.get(); |
2349 |
|
} |
2350 |
|
public final void setValue(Object value) { |
2351 |
|
if (value == null) |
2355 |
|
} |
2356 |
|
} |
2357 |
|
|
2358 |
< |
static final class TerminalWeakKeySoftValueNode |
2358 |
> |
static final class TerminalWeakKeySoftValueNode |
2359 |
|
extends WeakKeySoftValueNode { |
2360 |
|
TerminalWeakKeySoftValueNode(int locator, |
2361 |
< |
Object key, Object value, |
2361 |
> |
Object key, Object value, |
2362 |
|
CustomConcurrentHashMap cchm) { |
2363 |
|
super(locator, key, value, cchm); |
2364 |
|
} |
2366 |
|
public final void setLinkage(Node r) { } |
2367 |
|
} |
2368 |
|
|
2369 |
< |
static final class LinkedWeakKeySoftValueNode |
2369 |
> |
static final class LinkedWeakKeySoftValueNode |
2370 |
|
extends WeakKeySoftValueNode { |
2371 |
|
volatile Node linkage; |
2372 |
|
LinkedWeakKeySoftValueNode(int locator, |
2373 |
< |
Object key, Object value, |
2373 |
> |
Object key, Object value, |
2374 |
|
CustomConcurrentHashMap cchm, |
2375 |
|
Node linkage) { |
2376 |
|
super(locator, key, value, cchm); |
2380 |
|
public final void setLinkage(Node r) { linkage = r; } |
2381 |
|
} |
2382 |
|
|
2383 |
< |
static final class WeakKeySoftValueNodeFactory |
2383 |
> |
static final class WeakKeySoftValueNodeFactory |
2384 |
|
implements NodeFactory, Serializable { |
2385 |
|
private static final long serialVersionUID = 7249069346764182397L; |
2386 |
< |
public final Node newNode(int locator, |
2387 |
< |
Object key, Object value, |
2386 |
> |
public final Node newNode(int locator, |
2387 |
> |
Object key, Object value, |
2388 |
|
CustomConcurrentHashMap cchm, |
2389 |
|
Node linkage) { |
2390 |
|
if (linkage == null) |
2394 |
|
return new LinkedWeakKeySoftValueNode |
2395 |
|
(locator, key, value, cchm, linkage); |
2396 |
|
} |
2397 |
< |
} |
2397 |
> |
} |
2398 |
|
|
2399 |
|
// Soft keys |
2400 |
|
|
2403 |
|
final int locator; |
2404 |
|
final CustomConcurrentHashMap cchm; |
2405 |
|
SoftKeyNode(int locator, Object key, CustomConcurrentHashMap cchm) { |
2406 |
< |
super(key); |
2406 |
> |
super(key, getReclamationQueue()); |
2407 |
|
this.locator = locator; |
2408 |
|
this.cchm = cchm; |
2409 |
|
} |
2410 |
|
public final int getLocator() { return locator; } |
2411 |
< |
public final void onReclamation() { |
2411 |
> |
public final void onReclamation() { |
2412 |
|
clear(); |
2413 |
|
cchm.removeIfReclaimed(this); |
2414 |
|
} |
2415 |
|
} |
2416 |
|
|
2417 |
< |
static abstract class SoftKeySelfValueNode |
2417 |
> |
static abstract class SoftKeySelfValueNode |
2418 |
|
extends SoftKeyNode { |
2419 |
< |
SoftKeySelfValueNode(int locator, Object key, CustomConcurrentHashMap cchm) { |
2419 |
> |
SoftKeySelfValueNode(int locator, Object key, |
2420 |
> |
CustomConcurrentHashMap cchm) { |
2421 |
|
super(locator, key, cchm); |
2422 |
|
} |
2423 |
|
public final Object getValue() { return get(); } |
2424 |
|
public final void setValue(Object value) { } |
2425 |
|
} |
2426 |
|
|
2427 |
< |
static final class TerminalSoftKeySelfValueNode |
2427 |
> |
static final class TerminalSoftKeySelfValueNode |
2428 |
|
extends SoftKeySelfValueNode { |
2429 |
< |
TerminalSoftKeySelfValueNode(int locator, Object key, CustomConcurrentHashMap cchm) { |
2429 |
> |
TerminalSoftKeySelfValueNode(int locator, Object key, |
2430 |
> |
CustomConcurrentHashMap cchm) { |
2431 |
|
super(locator, key, cchm); |
2432 |
|
} |
2433 |
|
public final Node getLinkage() { return null; } |
2434 |
|
public final void setLinkage(Node r) { } |
2435 |
|
} |
2436 |
|
|
2437 |
< |
static final class LinkedSoftKeySelfValueNode |
2437 |
> |
static final class LinkedSoftKeySelfValueNode |
2438 |
|
extends SoftKeySelfValueNode { |
2439 |
|
volatile Node linkage; |
2440 |
< |
LinkedSoftKeySelfValueNode(int locator, Object key, CustomConcurrentHashMap cchm, |
2440 |
> |
LinkedSoftKeySelfValueNode(int locator, Object key, |
2441 |
> |
CustomConcurrentHashMap cchm, |
2442 |
|
Node linkage) { |
2443 |
|
super(locator, key, cchm); |
2444 |
|
this.linkage = linkage; |
2451 |
|
implements NodeFactory, Serializable { |
2452 |
|
private static final long serialVersionUID = 7249069346764182397L; |
2453 |
|
public final Node newNode(int locator, |
2454 |
< |
Object key, Object value, |
2454 |
> |
Object key, Object value, |
2455 |
|
CustomConcurrentHashMap cchm, |
2456 |
|
Node linkage) { |
2457 |
|
if (linkage == null) |
2461 |
|
return new LinkedSoftKeySelfValueNode |
2462 |
|
(locator, key, cchm, linkage); |
2463 |
|
} |
2464 |
< |
} |
2464 |
> |
} |
2465 |
|
|
2466 |
|
|
2467 |
< |
static abstract class SoftKeyStrongValueNode |
2467 |
> |
static abstract class SoftKeyStrongValueNode |
2468 |
|
extends SoftKeyNode { |
2469 |
|
volatile Object value; |
2470 |
< |
SoftKeyStrongValueNode(int locator, Object key, Object value, CustomConcurrentHashMap cchm) { |
2470 |
> |
SoftKeyStrongValueNode(int locator, Object key, Object value, |
2471 |
> |
CustomConcurrentHashMap cchm) { |
2472 |
|
super(locator, key, cchm); |
2473 |
|
this.value = value; |
2474 |
|
} |
2476 |
|
public final void setValue(Object value) { this.value = value; } |
2477 |
|
} |
2478 |
|
|
2479 |
< |
static final class TerminalSoftKeyStrongValueNode |
2479 |
> |
static final class TerminalSoftKeyStrongValueNode |
2480 |
|
extends SoftKeyStrongValueNode { |
2481 |
|
TerminalSoftKeyStrongValueNode(int locator, |
2482 |
< |
Object key, Object value, CustomConcurrentHashMap cchm) { |
2482 |
> |
Object key, Object value, |
2483 |
> |
CustomConcurrentHashMap cchm) { |
2484 |
|
super(locator, key, value, cchm); |
2485 |
|
} |
2486 |
|
public final Node getLinkage() { return null; } |
2487 |
|
public final void setLinkage(Node r) { } |
2488 |
|
} |
2489 |
|
|
2490 |
< |
static final class LinkedSoftKeyStrongValueNode |
2490 |
> |
static final class LinkedSoftKeyStrongValueNode |
2491 |
|
extends SoftKeyStrongValueNode { |
2492 |
|
volatile Node linkage; |
2493 |
|
LinkedSoftKeyStrongValueNode(int locator, |
2494 |
< |
Object key, Object value, CustomConcurrentHashMap cchm, |
2494 |
> |
Object key, Object value, |
2495 |
> |
CustomConcurrentHashMap cchm, |
2496 |
|
Node linkage) { |
2497 |
|
super(locator, key, value, cchm); |
2498 |
|
this.linkage = linkage; |
2501 |
|
public final void setLinkage(Node r) { linkage = r; } |
2502 |
|
} |
2503 |
|
|
2504 |
< |
static final class SoftKeyStrongValueNodeFactory |
2504 |
> |
static final class SoftKeyStrongValueNodeFactory |
2505 |
|
implements NodeFactory, Serializable { |
2506 |
|
private static final long serialVersionUID = 7249069346764182397L; |
2507 |
|
public final Node newNode(int locator, |
2508 |
< |
Object key, Object value, |
2508 |
> |
Object key, Object value, |
2509 |
|
CustomConcurrentHashMap cchm, |
2510 |
|
Node linkage) { |
2511 |
|
if (linkage == null) |
2515 |
|
return new LinkedSoftKeyStrongValueNode |
2516 |
|
(locator, key, value, cchm, linkage); |
2517 |
|
} |
2518 |
< |
} |
2518 |
> |
} |
2519 |
|
|
2520 |
< |
static abstract class SoftKeyIntValueNode |
2520 |
> |
static abstract class SoftKeyIntValueNode |
2521 |
|
extends SoftKeyNode { |
2522 |
|
volatile int value; |
2523 |
|
SoftKeyIntValueNode(int locator, Object key, Object value, |
2526 |
|
this.value = ((Integer)value).intValue(); |
2527 |
|
} |
2528 |
|
public final Object getValue() { return Integer.valueOf(value); } |
2529 |
< |
public final void setValue(Object value) { |
2529 |
> |
public final void setValue(Object value) { |
2530 |
|
this.value = ((Integer)value).intValue(); |
2531 |
|
} |
2532 |
|
} |
2533 |
|
|
2534 |
< |
static final class TerminalSoftKeyIntValueNode |
2534 |
> |
static final class TerminalSoftKeyIntValueNode |
2535 |
|
extends SoftKeyIntValueNode { |
2536 |
|
TerminalSoftKeyIntValueNode(int locator, |
2537 |
|
Object key, Object value, |
2542 |
|
public final void setLinkage(Node r) { } |
2543 |
|
} |
2544 |
|
|
2545 |
< |
static final class LinkedSoftKeyIntValueNode |
2545 |
> |
static final class LinkedSoftKeyIntValueNode |
2546 |
|
extends SoftKeyIntValueNode { |
2547 |
|
volatile Node linkage; |
2548 |
|
LinkedSoftKeyIntValueNode(int locator, |
2549 |
< |
Object key, Object value, |
2549 |
> |
Object key, Object value, |
2550 |
|
CustomConcurrentHashMap cchm, |
2551 |
|
Node linkage) { |
2552 |
|
super(locator, key, value, cchm); |
2556 |
|
public final void setLinkage(Node r) { linkage = r; } |
2557 |
|
} |
2558 |
|
|
2559 |
< |
static final class SoftKeyIntValueNodeFactory |
2559 |
> |
static final class SoftKeyIntValueNodeFactory |
2560 |
|
implements NodeFactory, Serializable { |
2561 |
|
private static final long serialVersionUID = 7249069346764182397L; |
2562 |
|
public final Node newNode(int locator, |
2563 |
< |
Object key, Object value, |
2563 |
> |
Object key, Object value, |
2564 |
|
CustomConcurrentHashMap cchm, |
2565 |
|
Node linkage) { |
2566 |
|
if (linkage == null) |
2570 |
|
return new LinkedSoftKeyIntValueNode |
2571 |
|
(locator, key, value, cchm, linkage); |
2572 |
|
} |
2573 |
< |
} |
2573 |
> |
} |
2574 |
|
|
2575 |
< |
static abstract class SoftKeyWeakValueNode |
2575 |
> |
static abstract class SoftKeyWeakValueNode |
2576 |
|
extends SoftKeyNode { |
2577 |
|
volatile EmbeddedWeakReference valueRef; |
2578 |
< |
SoftKeyWeakValueNode(int locator, Object key, Object value, |
2578 |
> |
SoftKeyWeakValueNode(int locator, Object key, Object value, |
2579 |
|
CustomConcurrentHashMap cchm) { |
2580 |
|
super(locator, key, cchm); |
2581 |
|
if (value != null) |
2583 |
|
} |
2584 |
|
public final Object getValue() { |
2585 |
|
EmbeddedWeakReference vr = valueRef; |
2586 |
< |
return vr == null? null : vr.get(); |
2586 |
> |
return (vr == null) ? null : vr.get(); |
2587 |
|
} |
2588 |
|
public final void setValue(Object value) { |
2589 |
|
if (value == null) |
2593 |
|
} |
2594 |
|
} |
2595 |
|
|
2596 |
< |
static final class TerminalSoftKeyWeakValueNode |
2596 |
> |
static final class TerminalSoftKeyWeakValueNode |
2597 |
|
extends SoftKeyWeakValueNode { |
2598 |
|
TerminalSoftKeyWeakValueNode(int locator, |
2599 |
< |
Object key, Object value, |
2599 |
> |
Object key, Object value, |
2600 |
|
CustomConcurrentHashMap cchm) { |
2601 |
|
super(locator, key, value, cchm); |
2602 |
|
} |
2604 |
|
public final void setLinkage(Node r) { } |
2605 |
|
} |
2606 |
|
|
2607 |
< |
static final class LinkedSoftKeyWeakValueNode |
2607 |
> |
static final class LinkedSoftKeyWeakValueNode |
2608 |
|
extends SoftKeyWeakValueNode { |
2609 |
|
volatile Node linkage; |
2610 |
|
LinkedSoftKeyWeakValueNode(int locator, |
2611 |
< |
Object key, Object value, |
2611 |
> |
Object key, Object value, |
2612 |
|
CustomConcurrentHashMap cchm, |
2613 |
|
Node linkage) { |
2614 |
|
super(locator, key, value, cchm); |
2618 |
|
public final void setLinkage(Node r) { linkage = r; } |
2619 |
|
} |
2620 |
|
|
2621 |
< |
static final class SoftKeyWeakValueNodeFactory |
2621 |
> |
static final class SoftKeyWeakValueNodeFactory |
2622 |
|
implements NodeFactory, Serializable { |
2623 |
|
private static final long serialVersionUID = 7249069346764182397L; |
2624 |
< |
public final Node newNode(int locator, |
2625 |
< |
Object key, Object value, |
2624 |
> |
public final Node newNode(int locator, |
2625 |
> |
Object key, Object value, |
2626 |
|
CustomConcurrentHashMap cchm, |
2627 |
|
Node linkage) { |
2628 |
|
if (linkage == null) |
2632 |
|
return new LinkedSoftKeyWeakValueNode |
2633 |
|
(locator, key, value, cchm, linkage); |
2634 |
|
} |
2635 |
< |
} |
2635 |
> |
} |
2636 |
|
|
2637 |
|
|
2638 |
< |
static abstract class SoftKeySoftValueNode |
2638 |
> |
static abstract class SoftKeySoftValueNode |
2639 |
|
extends SoftKeyNode { |
2640 |
|
volatile EmbeddedSoftReference valueRef; |
2641 |
< |
SoftKeySoftValueNode(int locator, Object key, Object value, |
2641 |
> |
SoftKeySoftValueNode(int locator, Object key, Object value, |
2642 |
|
CustomConcurrentHashMap cchm) { |
2643 |
|
super(locator, key, cchm); |
2644 |
|
if (value != null) |
2646 |
|
} |
2647 |
|
public final Object getValue() { |
2648 |
|
EmbeddedSoftReference vr = valueRef; |
2649 |
< |
return vr == null? null : vr.get(); |
2649 |
> |
return (vr == null) ? null : vr.get(); |
2650 |
|
} |
2651 |
|
public final void setValue(Object value) { |
2652 |
|
if (value == null) |
2656 |
|
} |
2657 |
|
} |
2658 |
|
|
2659 |
< |
static final class TerminalSoftKeySoftValueNode |
2659 |
> |
static final class TerminalSoftKeySoftValueNode |
2660 |
|
extends SoftKeySoftValueNode { |
2661 |
|
TerminalSoftKeySoftValueNode(int locator, |
2662 |
< |
Object key, Object value, |
2662 |
> |
Object key, Object value, |
2663 |
|
CustomConcurrentHashMap cchm) { |
2664 |
|
super(locator, key, value, cchm); |
2665 |
|
} |
2667 |
|
public final void setLinkage(Node r) { } |
2668 |
|
} |
2669 |
|
|
2670 |
< |
static final class LinkedSoftKeySoftValueNode |
2670 |
> |
static final class LinkedSoftKeySoftValueNode |
2671 |
|
extends SoftKeySoftValueNode { |
2672 |
|
volatile Node linkage; |
2673 |
|
LinkedSoftKeySoftValueNode(int locator, |
2674 |
< |
Object key, Object value, |
2674 |
> |
Object key, Object value, |
2675 |
|
CustomConcurrentHashMap cchm, |
2676 |
|
Node linkage) { |
2677 |
|
super(locator, key, value, cchm); |
2681 |
|
public final void setLinkage(Node r) { linkage = r; } |
2682 |
|
} |
2683 |
|
|
2684 |
< |
static final class SoftKeySoftValueNodeFactory |
2684 |
> |
static final class SoftKeySoftValueNodeFactory |
2685 |
|
implements NodeFactory, Serializable { |
2686 |
|
private static final long serialVersionUID = 7249069346764182397L; |
2687 |
< |
public final Node newNode(int locator, |
2688 |
< |
Object key, Object value, |
2687 |
> |
public final Node newNode(int locator, |
2688 |
> |
Object key, Object value, |
2689 |
|
CustomConcurrentHashMap cchm, |
2690 |
|
Node linkage) { |
2691 |
|
if (linkage == null) |
2695 |
|
return new LinkedSoftKeySoftValueNode |
2696 |
|
(locator, key, value, cchm, linkage); |
2697 |
|
} |
2698 |
< |
} |
2698 |
> |
} |
2699 |
|
|
2700 |
|
static abstract class IntKeyNode implements Node { |
2701 |
|
final int key; |
2707 |
|
} |
2708 |
|
|
2709 |
|
|
2710 |
< |
static abstract class IntKeySelfValueNode |
2710 |
> |
static abstract class IntKeySelfValueNode |
2711 |
|
extends IntKeyNode { |
2712 |
|
IntKeySelfValueNode(int locator, Object key) { |
2713 |
|
super(locator, key); |
2717 |
|
public final void onReclamation() { } |
2718 |
|
} |
2719 |
|
|
2720 |
< |
static final class TerminalIntKeySelfValueNode |
2720 |
> |
static final class TerminalIntKeySelfValueNode |
2721 |
|
extends IntKeySelfValueNode { |
2722 |
|
TerminalIntKeySelfValueNode(int locator, Object key) { |
2723 |
|
super(locator, key); |
2726 |
|
public final void setLinkage(Node r) { } |
2727 |
|
} |
2728 |
|
|
2729 |
< |
static final class LinkedIntKeySelfValueNode |
2729 |
> |
static final class LinkedIntKeySelfValueNode |
2730 |
|
extends IntKeySelfValueNode { |
2731 |
|
volatile Node linkage; |
2732 |
< |
LinkedIntKeySelfValueNode(int locator, Object key, |
2732 |
> |
LinkedIntKeySelfValueNode(int locator, Object key, |
2733 |
|
Node linkage) { |
2734 |
|
super(locator, key); |
2735 |
|
this.linkage = linkage; |
2742 |
|
implements NodeFactory, Serializable { |
2743 |
|
private static final long serialVersionUID = 7249069346764182397L; |
2744 |
|
public final Node newNode(int locator, |
2745 |
< |
Object key, Object value, |
2745 |
> |
Object key, Object value, |
2746 |
|
CustomConcurrentHashMap cchm, |
2747 |
|
Node linkage) { |
2748 |
|
if (linkage == null) |
2752 |
|
return new LinkedIntKeySelfValueNode |
2753 |
|
(locator, key, linkage); |
2754 |
|
} |
2755 |
< |
} |
2755 |
> |
} |
2756 |
|
|
2757 |
< |
static abstract class IntKeyStrongValueNode |
2757 |
> |
static abstract class IntKeyStrongValueNode |
2758 |
|
extends IntKeyNode { |
2759 |
|
volatile Object value; |
2760 |
|
IntKeyStrongValueNode(int locator, Object key, Object value) { |
2766 |
|
public final void onReclamation() { } |
2767 |
|
} |
2768 |
|
|
2769 |
< |
static final class TerminalIntKeyStrongValueNode |
2769 |
> |
static final class TerminalIntKeyStrongValueNode |
2770 |
|
extends IntKeyStrongValueNode { |
2771 |
|
TerminalIntKeyStrongValueNode(int locator, |
2772 |
|
Object key, Object value) { |
2776 |
|
public final void setLinkage(Node r) { } |
2777 |
|
} |
2778 |
|
|
2779 |
< |
static final class LinkedIntKeyStrongValueNode |
2779 |
> |
static final class LinkedIntKeyStrongValueNode |
2780 |
|
extends IntKeyStrongValueNode { |
2781 |
|
volatile Node linkage; |
2782 |
|
LinkedIntKeyStrongValueNode(int locator, |
2783 |
< |
Object key, Object value, |
2783 |
> |
Object key, Object value, |
2784 |
|
Node linkage) { |
2785 |
|
super(locator, key, value); |
2786 |
|
this.linkage = linkage; |
2789 |
|
public final void setLinkage(Node r) { linkage = r; } |
2790 |
|
} |
2791 |
|
|
2792 |
< |
static final class IntKeyStrongValueNodeFactory |
2792 |
> |
static final class IntKeyStrongValueNodeFactory |
2793 |
|
implements NodeFactory, Serializable { |
2794 |
|
private static final long serialVersionUID = 7249069346764182397L; |
2795 |
|
public final Node newNode(int locator, |
2796 |
< |
Object key, Object value, |
2796 |
> |
Object key, Object value, |
2797 |
|
CustomConcurrentHashMap cchm, |
2798 |
|
Node linkage) { |
2799 |
|
if (linkage == null) |
2803 |
|
return new LinkedIntKeyStrongValueNode |
2804 |
|
(locator, key, value, linkage); |
2805 |
|
} |
2806 |
< |
} |
2806 |
> |
} |
2807 |
|
|
2808 |
< |
static abstract class IntKeyIntValueNode |
2808 |
> |
static abstract class IntKeyIntValueNode |
2809 |
|
extends IntKeyNode { |
2810 |
|
volatile int value; |
2811 |
|
IntKeyIntValueNode(int locator, Object key, Object value) { |
2813 |
|
this.value = ((Integer)value).intValue(); |
2814 |
|
} |
2815 |
|
public final Object getValue() { return Integer.valueOf(value); } |
2816 |
< |
public final void setValue(Object value) { |
2816 |
> |
public final void setValue(Object value) { |
2817 |
|
this.value = ((Integer)value).intValue(); |
2818 |
|
} |
2819 |
|
public final void onReclamation() { } |
2820 |
|
} |
2821 |
|
|
2822 |
< |
static final class TerminalIntKeyIntValueNode |
2822 |
> |
static final class TerminalIntKeyIntValueNode |
2823 |
|
extends IntKeyIntValueNode { |
2824 |
|
TerminalIntKeyIntValueNode(int locator, |
2825 |
|
Object key, Object value) { |
2829 |
|
public final void setLinkage(Node r) { } |
2830 |
|
} |
2831 |
|
|
2832 |
< |
static final class LinkedIntKeyIntValueNode |
2832 |
> |
static final class LinkedIntKeyIntValueNode |
2833 |
|
extends IntKeyIntValueNode { |
2834 |
|
volatile Node linkage; |
2835 |
|
LinkedIntKeyIntValueNode(int locator, |
2836 |
< |
Object key, Object value, |
2836 |
> |
Object key, Object value, |
2837 |
|
Node linkage) { |
2838 |
|
super(locator, key, value); |
2839 |
|
this.linkage = linkage; |
2842 |
|
public final void setLinkage(Node r) { linkage = r; } |
2843 |
|
} |
2844 |
|
|
2845 |
< |
static final class IntKeyIntValueNodeFactory |
2845 |
> |
static final class IntKeyIntValueNodeFactory |
2846 |
|
implements NodeFactory, Serializable { |
2847 |
|
private static final long serialVersionUID = 7249069346764182397L; |
2848 |
|
public final Node newNode(int locator, |
2849 |
< |
Object key, Object value, |
2849 |
> |
Object key, Object value, |
2850 |
|
CustomConcurrentHashMap cchm, |
2851 |
|
Node linkage) { |
2852 |
|
if (linkage == null) |
2856 |
|
return new LinkedIntKeyIntValueNode |
2857 |
|
(locator, key, value, linkage); |
2858 |
|
} |
2859 |
< |
} |
2859 |
> |
} |
2860 |
|
|
2861 |
< |
static abstract class IntKeyWeakValueNode |
2861 |
> |
static abstract class IntKeyWeakValueNode |
2862 |
|
extends IntKeyNode { |
2863 |
|
volatile EmbeddedWeakReference valueRef; |
2864 |
|
final CustomConcurrentHashMap cchm; |
2865 |
< |
IntKeyWeakValueNode(int locator, Object key, Object value, |
2865 |
> |
IntKeyWeakValueNode(int locator, Object key, Object value, |
2866 |
|
CustomConcurrentHashMap cchm) { |
2867 |
|
super(locator, key); |
2868 |
|
this.cchm = cchm; |
2874 |
|
} |
2875 |
|
public final Object getValue() { |
2876 |
|
EmbeddedWeakReference vr = valueRef; |
2877 |
< |
return vr == null? null : vr.get(); |
2877 |
> |
return (vr == null) ? null : vr.get(); |
2878 |
|
} |
2879 |
|
public final void setValue(Object value) { |
2880 |
|
if (value == null) |
2884 |
|
} |
2885 |
|
} |
2886 |
|
|
2887 |
< |
static final class TerminalIntKeyWeakValueNode |
2887 |
> |
static final class TerminalIntKeyWeakValueNode |
2888 |
|
extends IntKeyWeakValueNode { |
2889 |
|
TerminalIntKeyWeakValueNode(int locator, |
2890 |
< |
Object key, Object value, |
2890 |
> |
Object key, Object value, |
2891 |
|
CustomConcurrentHashMap cchm) { |
2892 |
|
super(locator, key, value, cchm); |
2893 |
|
} |
2895 |
|
public final void setLinkage(Node r) { } |
2896 |
|
} |
2897 |
|
|
2898 |
< |
static final class LinkedIntKeyWeakValueNode |
2898 |
> |
static final class LinkedIntKeyWeakValueNode |
2899 |
|
extends IntKeyWeakValueNode { |
2900 |
|
volatile Node linkage; |
2901 |
|
LinkedIntKeyWeakValueNode(int locator, |
2902 |
< |
Object key, Object value, |
2902 |
> |
Object key, Object value, |
2903 |
|
CustomConcurrentHashMap cchm, |
2904 |
|
Node linkage) { |
2905 |
|
super(locator, key, value, cchm); |
2909 |
|
public final void setLinkage(Node r) { linkage = r; } |
2910 |
|
} |
2911 |
|
|
2912 |
< |
static final class IntKeyWeakValueNodeFactory |
2912 |
> |
static final class IntKeyWeakValueNodeFactory |
2913 |
|
implements NodeFactory, Serializable { |
2914 |
|
private static final long serialVersionUID = 7249069346764182397L; |
2915 |
< |
public final Node newNode(int locator, |
2916 |
< |
Object key, Object value, |
2915 |
> |
public final Node newNode(int locator, |
2916 |
> |
Object key, Object value, |
2917 |
|
CustomConcurrentHashMap cchm, |
2918 |
|
Node linkage) { |
2919 |
|
if (linkage == null) |
2923 |
|
return new LinkedIntKeyWeakValueNode |
2924 |
|
(locator, key, value, cchm, linkage); |
2925 |
|
} |
2926 |
< |
} |
2926 |
> |
} |
2927 |
|
|
2928 |
|
|
2929 |
< |
static abstract class IntKeySoftValueNode |
2929 |
> |
static abstract class IntKeySoftValueNode |
2930 |
|
extends IntKeyNode { |
2931 |
|
volatile EmbeddedSoftReference valueRef; |
2932 |
|
final CustomConcurrentHashMap cchm; |
2933 |
< |
IntKeySoftValueNode(int locator, Object key, Object value, |
2934 |
< |
CustomConcurrentHashMap cchm) { |
2933 |
> |
IntKeySoftValueNode(int locator, Object key, Object value, |
2934 |
> |
CustomConcurrentHashMap cchm) { |
2935 |
|
super(locator, key); |
2936 |
|
this.cchm = cchm; |
2937 |
|
if (value != null) |
2942 |
|
} |
2943 |
|
public final Object getValue() { |
2944 |
|
EmbeddedSoftReference vr = valueRef; |
2945 |
< |
return vr == null? null : vr.get(); |
2945 |
> |
return (vr == null) ? null : vr.get(); |
2946 |
|
} |
2947 |
|
public final void setValue(Object value) { |
2948 |
|
if (value == null) |
2952 |
|
} |
2953 |
|
} |
2954 |
|
|
2955 |
< |
static final class TerminalIntKeySoftValueNode |
2955 |
> |
static final class TerminalIntKeySoftValueNode |
2956 |
|
extends IntKeySoftValueNode { |
2957 |
|
TerminalIntKeySoftValueNode(int locator, |
2958 |
< |
Object key, Object value, |
2958 |
> |
Object key, Object value, |
2959 |
|
CustomConcurrentHashMap cchm) { |
2960 |
|
super(locator, key, value, cchm); |
2961 |
|
} |
2963 |
|
public final void setLinkage(Node r) { } |
2964 |
|
} |
2965 |
|
|
2966 |
< |
static final class LinkedIntKeySoftValueNode |
2966 |
> |
static final class LinkedIntKeySoftValueNode |
2967 |
|
extends IntKeySoftValueNode { |
2968 |
|
volatile Node linkage; |
2969 |
|
LinkedIntKeySoftValueNode(int locator, |
2970 |
< |
Object key, Object value, |
2970 |
> |
Object key, Object value, |
2971 |
|
CustomConcurrentHashMap cchm, |
2972 |
|
Node linkage) { |
2973 |
|
super(locator, key, value, cchm); |
2977 |
|
public final void setLinkage(Node r) { linkage = r; } |
2978 |
|
} |
2979 |
|
|
2980 |
< |
static final class IntKeySoftValueNodeFactory |
2980 |
> |
static final class IntKeySoftValueNodeFactory |
2981 |
|
implements NodeFactory, Serializable { |
2982 |
|
private static final long serialVersionUID = 7249069346764182397L; |
2983 |
< |
public final Node newNode(int locator, |
2984 |
< |
Object key, Object value, |
2983 |
> |
public final Node newNode(int locator, |
2984 |
> |
Object key, Object value, |
2985 |
|
CustomConcurrentHashMap cchm, |
2986 |
|
Node linkage) { |
2987 |
|
if (linkage == null) |
2991 |
|
return new LinkedIntKeySoftValueNode |
2992 |
|
(locator, key, value, cchm, linkage); |
2993 |
|
} |
2994 |
< |
} |
2994 |
> |
} |
2995 |
|
|
2996 |
|
|
2997 |
|
|
2998 |
|
// Temporary Unsafe mechanics for preliminary release |
2999 |
|
|
3000 |
< |
static final Unsafe _unsafe; |
3000 |
> |
static final Unsafe UNSAFE; |
3001 |
|
static final long tableBase; |
3002 |
|
static final int tableShift; |
3003 |
|
static final long segmentsBase; |
3028 |
|
|
3029 |
|
static { |
3030 |
|
try { |
3031 |
< |
_unsafe = getUnsafe(); |
3032 |
< |
tableBase = _unsafe.arrayBaseOffset(Node[].class); |
3033 |
< |
int s = _unsafe.arrayIndexScale(Node[].class); |
3031 |
> |
UNSAFE = getUnsafe(); |
3032 |
> |
tableBase = UNSAFE.arrayBaseOffset(Node[].class); |
3033 |
> |
int s = UNSAFE.arrayIndexScale(Node[].class); |
3034 |
|
if ((s & (s-1)) != 0) |
3035 |
|
throw new Error("data type scale not a power of two"); |
3036 |
|
tableShift = 31 - Integer.numberOfLeadingZeros(s); |
3037 |
< |
segmentsBase = _unsafe.arrayBaseOffset(Segment[].class); |
3038 |
< |
s = _unsafe.arrayIndexScale(Segment[].class); |
3037 |
> |
segmentsBase = UNSAFE.arrayBaseOffset(Segment[].class); |
3038 |
> |
s = UNSAFE.arrayIndexScale(Segment[].class); |
3039 |
|
if ((s & (s-1)) != 0) |
3040 |
|
throw new Error("data type scale not a power of two"); |
3041 |
|
segmentsShift = 31 - Integer.numberOfLeadingZeros(s); |
3045 |
|
} |
3046 |
|
|
3047 |
|
// Fenced store into segment table array. Unneeded when we have Fences |
3048 |
< |
static final void storeNode(Node[] table, |
3049 |
< |
int i, Node r) { |
3050 |
< |
_unsafe.putOrderedObject(table, (i << tableShift) + tableBase, r); |
3048 |
> |
static final void storeNode(Node[] table, |
3049 |
> |
int i, Node r) { |
3050 |
> |
long nodeOffset = ((long) i << tableShift) + tableBase; |
3051 |
> |
UNSAFE.putOrderedObject(table, nodeOffset, r); |
3052 |
|
} |
3053 |
|
|
3054 |
< |
static final void storeSegment(Segment[] segs, |
3055 |
< |
int i, Segment s) { |
3056 |
< |
_unsafe.putOrderedObject(segs, (i << segmentsShift) + segmentsBase, s); |
3054 |
> |
static final void storeSegment(Segment[] segs, |
3055 |
> |
int i, Segment s) { |
3056 |
> |
long segmentOffset = ((long) i << segmentsShift) + segmentsBase; |
3057 |
> |
UNSAFE.putOrderedObject(segs, segmentOffset, s); |
3058 |
|
} |
3059 |
|
|
3060 |
|
|
3061 |
|
} |
3043 |
– |
|