25 |
|
* <li> {@linkplain SoftReference Soft}, {@linkplain |
26 |
|
* WeakReference weak} or strong (regular) keys and values. |
27 |
|
* |
28 |
< |
* <li> User-definable <code>MappingFunctions</code> that may be |
28 |
> |
* <li> User-definable {@code MappingFunctions} that may be |
29 |
|
* used in method {@link |
30 |
|
* CustomConcurrentHashMap#computeIfAbsent} to atomically |
31 |
|
* establish a computed value, along with |
32 |
< |
* <code>RemappingFunctions</code> that can be used in method |
32 |
> |
* {@code RemappingFunctions} that can be used in method |
33 |
|
* {@link CustomConcurrentHashMap#compute} to atomically |
34 |
|
* replace values. |
35 |
|
* |
36 |
< |
* <li>Factory methods returning specialized forms for <tt>int</tt> |
36 |
> |
* <li>Factory methods returning specialized forms for {@code int} |
37 |
|
* keys and/or values, that may be more space-efficient |
38 |
|
* |
39 |
|
* </ul> |
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 |
75 |
> |
* method {@code intern}, which may be of use in canonicalizing |
76 |
|
* elements. |
77 |
|
* |
78 |
|
* <p>When used with (Weak or Soft) Reference keys and/or values, |
79 |
< |
* elements that have asynchronously become <code>null</code> are |
79 |
> |
* elements that have asynchronously become {@code null} are |
80 |
|
* treated as absent from the map and (eventually) removed from maps |
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 |
83 |
> |
* {@code containsValue} have weaker guarantees than you might |
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 |
85 |
> |
* operations. For example {@code containsValue(value)} may |
86 |
> |
* return true even if {@code value} is no longer available upon |
87 |
|
* return from the method. |
88 |
|
* |
89 |
|
* <p>When Equivalences other than equality are used, the returned |
90 |
< |
* collections may violate the specifications of <tt>Map</tt> and/or |
91 |
< |
* <tt>Set</tt> interfaces, which mandate the use of the |
92 |
< |
* <tt>equals</tt> method when comparing objects. The methods of this |
90 |
> |
* collections may violate the specifications of {@code Map} and/or |
91 |
> |
* {@code Set} interfaces, which mandate the use of the |
92 |
> |
* {@code equals} method when comparing objects. The methods of this |
93 |
|
* class otherwise have properties similar to those of {@link |
94 |
|
* java.util.ConcurrentHashMap} under its default settings. To |
95 |
|
* adaptively maintain semantics and performance under varying |
165 |
|
* An object performing equality comparisons, along with a hash |
166 |
|
* function consistent with this comparison. The type signatures |
167 |
|
* of the methods of this interface reflect those of {@link |
168 |
< |
* java.util.Map}: While only elements of <code>K</code> may be |
169 |
< |
* entered into a Map, any <code>Object</code> may be tested for |
168 |
> |
* java.util.Map}: While only elements of {@code K} may be |
169 |
> |
* entered into a Map, any {@code Object} may be tested for |
170 |
|
* membership. Note that the performance of hash maps is heavily |
171 |
|
* dependent on the quality of hash functions. |
172 |
|
*/ |
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} if there is no mapping. |
228 |
|
*/ |
229 |
|
public static interface MappingFunction<K, V> { |
230 |
|
/** |
244 |
|
|
245 |
|
/** |
246 |
|
* A function computing a new mapping from the given key and its |
247 |
< |
* current value to a new value, or <code>null</code> if there is |
247 |
> |
* current value to a new value, or {@code null} if there is |
248 |
|
* no mapping |
249 |
|
*/ |
250 |
|
public static interface RemappingFunction<K, V> { |
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 |
|
*/ |
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++) { |
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 |
|
/** |
545 |
< |
* Creates a new CustomConcurrentHashMap with the given parameters |
545 |
> |
* Creates a new CustomConcurrentHashMap with the given parameters. |
546 |
|
* @param keyStrength the strength for keys |
547 |
|
* @param keyEquivalence the Equivalence to use for keys |
548 |
|
* @param valueStrength the strength for values |
571 |
|
|
572 |
|
/** |
573 |
|
* Returns a new map using Integer keys and the given value |
574 |
< |
* parameters |
574 |
> |
* parameters. |
575 |
|
* @param valueStrength the strength for values |
576 |
|
* @param valueEquivalence the Equivalence to use for values |
577 |
|
* @param expectedSize an estimate of the number of elements |
589 |
|
} |
590 |
|
|
591 |
|
/** |
592 |
< |
* Returns a new map using the given key parameters and Integer values |
592 |
> |
* Returns a new map using the given key parameters and Integer values. |
593 |
|
* @param keyStrength the strength for keys |
594 |
|
* @param keyEquivalence the Equivalence to use for keys |
595 |
|
* @param expectedSize an estimate of the number of elements |
607 |
|
} |
608 |
|
|
609 |
|
/** |
610 |
< |
* Returns a new map using Integer keys and values |
610 |
> |
* Returns a new map using Integer keys and values. |
611 |
|
* @param expectedSize an estimate of the number of elements |
612 |
|
* that will be held in the map. If no estimate is known, |
613 |
|
* zero is an acceptable value. |
621 |
|
} |
622 |
|
|
623 |
|
/** |
624 |
< |
* Returns the segment for traversing table for key with given hash |
624 |
> |
* Returns the segment for traversing table for key with given hash. |
625 |
|
* @param hash the hash code for the key |
626 |
|
* @return the segment, or null if not yet initialized |
627 |
|
*/ |
654 |
|
} |
655 |
|
|
656 |
|
/** |
657 |
< |
* Returns node for key, or null if none |
657 |
> |
* Returns node for key, or null if none. |
658 |
|
*/ |
659 |
|
final Node findNode(Object key, int hash, Segment seg) { |
660 |
|
if (seg != null) { |
676 |
|
} |
677 |
|
|
678 |
|
/** |
679 |
< |
* Returns <tt>true</tt> if this map contains a key equivalent to |
679 |
> |
* Returns {@code true} if this map contains a key equivalent to |
680 |
|
* the given key with respect to this map's key Equivalence. |
681 |
|
* |
682 |
|
* @param key possible key |
683 |
< |
* @return <tt>true</tt> if this map contains the specified key |
683 |
> |
* @return {@code true} if this map contains the specified key |
684 |
|
* @throws NullPointerException if the specified key is null |
685 |
|
*/ |
686 |
|
public boolean containsKey(Object key) { |
695 |
|
/** |
696 |
|
* Returns the value associated with a key equivalent to the given |
697 |
|
* key with respect to this map's key Equivalence, or {@code null} |
698 |
< |
* if no such mapping exists |
698 |
> |
* if no such mapping exists. |
699 |
|
* |
700 |
|
* @param key possible key |
701 |
< |
* @return the value associated with the key or <tt>null</tt> if |
701 |
> |
* @return the value associated with the key or {@code null} if |
702 |
|
* there is no mapping. |
703 |
|
* @throws NullPointerException if the specified key is null |
704 |
|
*/ |
750 |
|
* |
751 |
|
* @param key key with which the specified value is to be associated |
752 |
|
* @param value value to be associated with the specified key |
753 |
< |
* @return the previous value associated with <tt>key</tt>, or |
754 |
< |
* <tt>null</tt> if there was no mapping for <tt>key</tt> |
753 |
> |
* @return the previous value associated with {@code key}, or |
754 |
> |
* {@code null} if there was no mapping for {@code key} |
755 |
|
* @throws NullPointerException if the specified key or value is null |
756 |
|
*/ |
757 |
|
public V put(K key, V value) { |
762 |
|
* {@inheritDoc} |
763 |
|
* |
764 |
|
* @return the previous value associated with the specified key, |
765 |
< |
* or <tt>null</tt> if there was no mapping for the key |
765 |
> |
* or {@code null} if there was no mapping for the key |
766 |
|
* @throws NullPointerException if the specified key or value is null |
767 |
|
*/ |
768 |
|
public V putIfAbsent(K key, V value) { |
811 |
|
* {@inheritDoc} |
812 |
|
* |
813 |
|
* @return the previous value associated with the specified key, |
814 |
< |
* or <tt>null</tt> if there was no mapping for the key |
814 |
> |
* or {@code null} if there was no mapping for the key |
815 |
|
* @throws NullPointerException if the specified key or value is null |
816 |
|
*/ |
817 |
|
public boolean replace(K key, V oldValue, V newValue) { |
843 |
|
* Removes the mapping for the specified key. |
844 |
|
* |
845 |
|
* @param key the key to remove |
846 |
< |
* @return the previous value associated with <tt>key</tt>, or |
847 |
< |
* <tt>null</tt> if there was no mapping for <tt>key</tt> |
846 |
> |
* @return the previous value associated with {@code key}, or |
847 |
> |
* {@code null} if there was no mapping for {@code key} |
848 |
|
* @throws NullPointerException if the specified key is null |
849 |
|
*/ |
850 |
|
public V remove(Object key) { |
940 |
|
} |
941 |
|
|
942 |
|
/** |
943 |
< |
* Remove node if its key or value are null |
943 |
> |
* Removes node if its key or value are null. |
944 |
|
*/ |
945 |
|
final void removeIfReclaimed(Node r) { |
946 |
|
int hash = r.getLocator(); |
977 |
|
} |
978 |
|
|
979 |
|
/** |
980 |
< |
* Returns <tt>true</tt> if this map contains no key-value mappings. |
980 |
> |
* Returns {@code true} if this map contains no key-value mappings. |
981 |
|
* |
982 |
< |
* @return <tt>true</tt> if this map contains no key-value mappings |
982 |
> |
* @return {@code true} if this map contains no key-value mappings |
983 |
|
*/ |
984 |
|
public final boolean isEmpty() { |
985 |
|
final Segment[] segs = this.segments; |
995 |
|
|
996 |
|
/** |
997 |
|
* Returns the number of key-value mappings in this map. If the |
998 |
< |
* map contains more than <tt>Integer.MAX_VALUE</tt> elements, returns |
999 |
< |
* <tt>Integer.MAX_VALUE</tt>. |
998 |
> |
* map contains more than {@code Integer.MAX_VALUE} elements, returns |
999 |
> |
* {@code Integer.MAX_VALUE}. |
1000 |
|
* |
1001 |
|
* @return the number of key-value mappings in this map |
1002 |
|
*/ |
1012 |
|
} |
1013 |
|
|
1014 |
|
/** |
1015 |
< |
* Returns <tt>true</tt> if this map maps one or more keys to a |
1015 |
> |
* Returns {@code true} if this map maps one or more keys to a |
1016 |
|
* value equivalent to the given value with respect to this map's |
1017 |
|
* value Equivalence. Note: This method requires a full internal |
1018 |
|
* traversal of the hash table, and so is much slower than method |
1019 |
< |
* <tt>containsKey</tt>. |
1019 |
> |
* {@code containsKey}. |
1020 |
|
* |
1021 |
|
* @param value value whose presence in this map is to be tested |
1022 |
< |
* @return <tt>true</tt> if this map maps one or more keys to the |
1022 |
> |
* @return {@code true} if this map maps one or more keys to the |
1023 |
|
* specified value |
1024 |
|
* @throws NullPointerException if the specified value is null |
1025 |
|
*/ |
1089 |
|
* @param key key with which the specified value is to be associated |
1090 |
|
* @param mappingFunction the function to compute a value |
1091 |
|
* @return the current (existing or computed) value associated with |
1092 |
< |
* the specified key, or <tt>null</tt> if the computation |
1093 |
< |
* returned <tt>null</tt>. |
1092 |
> |
* the specified key, or {@code null} if the computation |
1093 |
> |
* returned {@code null}. |
1094 |
|
* @throws NullPointerException if the specified key or mappingFunction |
1095 |
|
* is null, |
1096 |
|
* @throws RuntimeException or Error if the mappingFunction does so, |
1163 |
|
* @param key key with which the specified value is to be associated |
1164 |
|
* @param remappingFunction the function to compute a value |
1165 |
|
* @return the updated value or |
1166 |
< |
* <tt>null</tt> if the computation returned <tt>null</tt> |
1166 |
> |
* {@code null} if the computation returned {@code null} |
1167 |
|
* @throws NullPointerException if the specified key or remappingFunction |
1168 |
|
* is null, |
1169 |
|
* @throws RuntimeException or Error if the remappingFunction does so, |
1431 |
|
* The set is backed by the map, so changes to the map are |
1432 |
|
* reflected in the set, and vice-versa. The set supports element |
1433 |
|
* removal, which removes the corresponding mapping from this map, |
1434 |
< |
* via the <tt>Iterator.remove</tt>, <tt>Set.remove</tt>, |
1435 |
< |
* <tt>removeAll</tt>, <tt>retainAll</tt>, and <tt>clear</tt> |
1436 |
< |
* operations. It does not support the <tt>add</tt> or |
1437 |
< |
* <tt>addAll</tt> operations. |
1434 |
> |
* via the {@code Iterator.remove}, {@code Set.remove}, |
1435 |
> |
* {@code removeAll}, {@code retainAll}, and {@code clear} |
1436 |
> |
* operations. It does not support the {@code add} or |
1437 |
> |
* {@code addAll} operations. |
1438 |
|
* |
1439 |
< |
* <p>The view's <tt>iterator</tt> is a "weakly consistent" iterator |
1439 |
> |
* <p>The view's {@code iterator} is a "weakly consistent" iterator |
1440 |
|
* that will never throw {@link ConcurrentModificationException}, |
1441 |
|
* and guarantees to traverse elements as they existed upon |
1442 |
|
* construction of the iterator, and may (but is not guaranteed to) |
1452 |
|
* The collection is backed by the map, so changes to the map are |
1453 |
|
* reflected in the collection, and vice-versa. The collection |
1454 |
|
* supports element removal, which removes the corresponding |
1455 |
< |
* mapping from this map, via the <tt>Iterator.remove</tt>, |
1456 |
< |
* <tt>Collection.remove</tt>, <tt>removeAll</tt>, |
1457 |
< |
* <tt>retainAll</tt>, and <tt>clear</tt> operations. It does not |
1458 |
< |
* support the <tt>add</tt> or <tt>addAll</tt> operations. |
1455 |
> |
* mapping from this map, via the {@code Iterator.remove}, |
1456 |
> |
* {@code Collection.remove}, {@code removeAll}, |
1457 |
> |
* {@code retainAll}, and {@code clear} operations. It does not |
1458 |
> |
* support the {@code add} or {@code addAll} operations. |
1459 |
|
* |
1460 |
< |
* <p>The view's <tt>iterator</tt> is a "weakly consistent" iterator |
1460 |
> |
* <p>The view's {@code iterator} is a "weakly consistent" iterator |
1461 |
|
* that will never throw {@link ConcurrentModificationException}, |
1462 |
|
* and guarantees to traverse elements as they existed upon |
1463 |
|
* construction of the iterator, and may (but is not guaranteed to) |
1473 |
|
* The set is backed by the map, so changes to the map are |
1474 |
|
* reflected in the set, and vice-versa. The set supports element |
1475 |
|
* removal, which removes the corresponding mapping from the map, |
1476 |
< |
* via the <tt>Iterator.remove</tt>, <tt>Set.remove</tt>, |
1477 |
< |
* <tt>removeAll</tt>, <tt>retainAll</tt>, and <tt>clear</tt> |
1478 |
< |
* operations. It does not support the <tt>add</tt> or |
1479 |
< |
* <tt>addAll</tt> operations. |
1476 |
> |
* via the {@code Iterator.remove}, {@code Set.remove}, |
1477 |
> |
* {@code removeAll}, {@code retainAll}, and {@code clear} |
1478 |
> |
* operations. It does not support the {@code add} or |
1479 |
> |
* {@code addAll} operations. |
1480 |
|
* |
1481 |
< |
* <p>The view's <tt>iterator</tt> is a "weakly consistent" iterator |
1481 |
> |
* <p>The view's {@code iterator} is a "weakly consistent" iterator |
1482 |
|
* that will never throw {@link ConcurrentModificationException}, |
1483 |
|
* and guarantees to traverse elements as they existed upon |
1484 |
|
* construction of the iterator, and may (but is not guaranteed to) |
1493 |
|
|
1494 |
|
/** |
1495 |
|
* Compares the specified object with this map for equality. |
1496 |
< |
* Returns <tt>true</tt> if the given object is also a map of the |
1496 |
> |
* Returns {@code true} if the given object is also a map of the |
1497 |
|
* same size, holding keys that are equal using this Map's key |
1498 |
|
* Equivalence, and which map to values that are equal according |
1499 |
|
* to this Map's value equivalence. |
1500 |
|
* |
1501 |
|
* @param o object to be compared for equality with this map |
1502 |
< |
* @return <tt>true</tt> if the specified object is equal to this map |
1502 |
> |
* @return {@code true} if the specified object is equal to this map |
1503 |
|
*/ |
1504 |
|
public boolean equals(Object o) { |
1505 |
|
if (o == this) |
1536 |
|
|
1537 |
|
/** |
1538 |
|
* Returns the sum of the hash codes of each entry in this map's |
1539 |
< |
* <tt>entrySet()</tt> view, which in turn are the hash codes |
1539 |
> |
* {@code entrySet()} view, which in turn are the hash codes |
1540 |
|
* computed using key and value Equivalences for this Map. |
1541 |
|
* @return the hash code |
1542 |
|
*/ |
1549 |
|
} |
1550 |
|
|
1551 |
|
/** |
1552 |
< |
* Save the state of the instance to a stream (i.e., serialize |
1553 |
< |
* it). |
1552 |
> |
* Saves the state of the instance to a stream (i.e., serializes it). |
1553 |
> |
* |
1554 |
|
* @param s the stream |
1555 |
|
* @serialData |
1556 |
|
* the key (Object) and value (Object) |
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(); |
1586 |
|
|
1587 |
|
/** |
1588 |
|
* A hash-based set with properties identical to those of |
1589 |
< |
* <code>Collections.newSetFromMap</code> applied to a |
1590 |
< |
* <code>CustomConcurrentHashMap</code>, but possibly more |
1589 |
> |
* {@code Collections.newSetFromMap} applied to a |
1590 |
> |
* {@code CustomConcurrentHashMap}, but possibly more |
1591 |
|
* space-efficient. The set does not permit null elements. The |
1592 |
|
* set is serializable; however, serializing a set that uses soft |
1593 |
|
* or weak references can give unpredictable results. |
1598 |
|
final CustomConcurrentHashMap<K,K> cchm; |
1599 |
|
|
1600 |
|
/** |
1601 |
< |
* Creates a set with the given parameters |
1601 |
> |
* Creates a set with the given parameters. |
1602 |
|
* @param strength the strength of elements |
1603 |
|
* @param equivalence the Equivalence to use |
1604 |
|
* @param expectedSize an estimate of the number of elements |
1619 |
|
* exists, else adds and returns the given element. |
1620 |
|
* |
1621 |
|
* @param e the element |
1622 |
< |
* @return e, or an element equivalent to e. |
1622 |
> |
* @return e, or an element equivalent to e |
1623 |
|
*/ |
1624 |
|
public K intern(K e) { |
1625 |
|
K oldElement = cchm.doPut(e, e, true); |
1627 |
|
} |
1628 |
|
|
1629 |
|
/** |
1630 |
< |
* Returns <tt>true</tt> if this set contains an |
1630 |
> |
* Returns {@code true} if this set contains an |
1631 |
|
* element equivalent to the given element with respect |
1632 |
|
* to this set's Equivalence. |
1633 |
|
* @param o element whose presence in this set is to be tested |
1634 |
< |
* @return <tt>true</tt> if this set contains the specified element |
1634 |
> |
* @return {@code true} if this set contains the specified element |
1635 |
|
*/ |
1636 |
|
public boolean contains(Object o) { |
1637 |
|
return cchm.containsKey(o); |
1654 |
|
* respect to this set's Equivalence. |
1655 |
|
* |
1656 |
|
* @param e element to be added to this set |
1657 |
< |
* @return <tt>true</tt> if this set did not already contain |
1657 |
> |
* @return {@code true} if this set did not already contain |
1658 |
|
* the specified element |
1659 |
|
*/ |
1660 |
|
public boolean add(K e) { |
1666 |
|
* respect to this set's Equivalence, if one is present. |
1667 |
|
* |
1668 |
|
* @param o object to be removed from this set, if present |
1669 |
< |
* @return <tt>true</tt> if the set contained the specified element |
1669 |
> |
* @return {@code true} if the set contained the specified element |
1670 |
|
*/ |
1671 |
|
public boolean remove(Object o) { |
1672 |
|
return cchm.remove(o) != null; |
1673 |
|
} |
1674 |
|
|
1675 |
|
/** |
1676 |
< |
* Returns <tt>true</tt> if this set contains no elements. |
1676 |
> |
* Returns {@code true} if this set contains no elements. |
1677 |
|
* |
1678 |
< |
* @return <tt>true</tt> if this set contains no elements |
1678 |
> |
* @return {@code true} if this set contains no elements |
1679 |
|
*/ |
1680 |
|
public boolean isEmpty() { |
1681 |
|
return cchm.isEmpty(); |
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) { |
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); |
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) { |
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) { |
1958 |
|
|
1959 |
|
// ... |
1960 |
|
|
1961 |
< |
static abstract class StrongKeyWeakValueNode |
1961 |
> |
abstract static class StrongKeyWeakValueNode |
1962 |
|
extends StrongKeyNode { |
1963 |
|
volatile EmbeddedWeakReference valueRef; |
1964 |
|
final CustomConcurrentHashMap cchm; |
2026 |
|
} |
2027 |
|
|
2028 |
|
|
2029 |
< |
static abstract class StrongKeySoftValueNode |
2029 |
> |
abstract static class StrongKeySoftValueNode |
2030 |
|
extends StrongKeyNode { |
2031 |
|
volatile EmbeddedSoftReference valueRef; |
2032 |
|
final CustomConcurrentHashMap cchm; |
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; |
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) { |
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, |
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, |
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, |
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, |
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; |
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) { |
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, |
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, |
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, |
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, |
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(); |
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); |
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) { |
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) { |
2856 |
|
} |
2857 |
|
} |
2858 |
|
|
2859 |
< |
static abstract class IntKeyWeakValueNode |
2859 |
> |
abstract static class IntKeyWeakValueNode |
2860 |
|
extends IntKeyNode { |
2861 |
|
volatile EmbeddedWeakReference valueRef; |
2862 |
|
final CustomConcurrentHashMap cchm; |
2924 |
|
} |
2925 |
|
|
2926 |
|
|
2927 |
< |
static abstract class IntKeySoftValueNode |
2927 |
> |
abstract static class IntKeySoftValueNode |
2928 |
|
extends IntKeyNode { |
2929 |
|
volatile EmbeddedSoftReference valueRef; |
2930 |
|
final CustomConcurrentHashMap cchm; |
3001 |
|
static final long segmentsBase; |
3002 |
|
static final int segmentsShift; |
3003 |
|
|
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 |
– |
|
3004 |
|
static { |
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 |
|
} |
3020 |
|
} |
3021 |
|
|
3022 |
|
// Fenced store into segment table array. Unneeded when we have Fences |
3023 |
< |
static final void storeNode(Node[] table, |
3024 |
< |
int i, Node r) { |
3023 |
> |
static final void storeNode(Node[] table, |
3024 |
> |
int i, Node r) { |
3025 |
|
long nodeOffset = ((long) i << tableShift) + tableBase; |
3026 |
|
UNSAFE.putOrderedObject(table, nodeOffset, r); |
3027 |
|
} |
3028 |
|
|
3029 |
< |
static final void storeSegment(Segment[] segs, |
3030 |
< |
int i, Segment s) { |
3029 |
> |
static final void storeSegment(Segment[] segs, |
3030 |
> |
int i, Segment s) { |
3031 |
|
long segmentOffset = ((long) i << segmentsShift) + segmentsBase; |
3032 |
|
UNSAFE.putOrderedObject(segs, segmentOffset, s); |
3033 |
|
} |
3034 |
|
|
3035 |
< |
|
3035 |
> |
/** |
3036 |
> |
* Returns a sun.misc.Unsafe. Suitable for use in a 3rd party package. |
3037 |
> |
* Replace with a simple call to Unsafe.getUnsafe when integrating |
3038 |
> |
* into a jdk. |
3039 |
> |
* |
3040 |
> |
* @return a sun.misc.Unsafe |
3041 |
> |
*/ |
3042 |
> |
private static sun.misc.Unsafe getUnsafe() { |
3043 |
> |
try { |
3044 |
> |
return sun.misc.Unsafe.getUnsafe(); |
3045 |
> |
} catch (SecurityException tryReflectionInstead) {} |
3046 |
> |
try { |
3047 |
> |
return java.security.AccessController.doPrivileged |
3048 |
> |
(new java.security.PrivilegedExceptionAction<sun.misc.Unsafe>() { |
3049 |
> |
public sun.misc.Unsafe run() throws Exception { |
3050 |
> |
Class<sun.misc.Unsafe> k = sun.misc.Unsafe.class; |
3051 |
> |
for (java.lang.reflect.Field f : k.getDeclaredFields()) { |
3052 |
> |
f.setAccessible(true); |
3053 |
> |
Object x = f.get(null); |
3054 |
> |
if (k.isInstance(x)) |
3055 |
> |
return k.cast(x); |
3056 |
> |
} |
3057 |
> |
throw new NoSuchFieldError("the Unsafe"); |
3058 |
> |
}}); |
3059 |
> |
} catch (java.security.PrivilegedActionException e) { |
3060 |
> |
throw new RuntimeException("Could not initialize intrinsics", |
3061 |
> |
e.getCause()); |
3062 |
> |
} |
3063 |
> |
} |
3064 |
|
} |