|
2 | 2 | * SPDX-License-Identifier: Apache-2.0 |
3 | 3 | * Copyright Red Hat Inc. and Hibernate Authors |
4 | 4 | */ |
5 | | -package org.hibernate.internal.util.collections; |
| 5 | +package org.hibernate.envers.internal.tools; |
6 | 6 |
|
7 | 7 | import java.io.IOException; |
| 8 | +import java.io.Serial; |
8 | 9 | import java.io.Serializable; |
9 | 10 | import java.lang.ref.Reference; |
10 | 11 | import java.lang.ref.ReferenceQueue; |
|
122 | 123 | * @author Doug Lea |
123 | 124 | * @author Jason T. Greene |
124 | 125 | */ |
125 | | -public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> |
| 126 | +class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> |
126 | 127 | implements java.util.concurrent.ConcurrentMap<K, V>, Serializable { |
| 128 | + @Serial |
127 | 129 | private static final long serialVersionUID = 7249069246763182397L; |
128 | 130 |
|
129 | 131 | /* |
130 | | - * The basic strategy is to subdivide the table among Segments, |
131 | | - * each of which itself is a concurrently readable hash table. |
132 | | - */ |
| 132 | + * The basic strategy is to subdivide the table among Segments, |
| 133 | + * each of which itself is a concurrently readable hash table. |
| 134 | + */ |
133 | 135 |
|
134 | 136 | /** |
135 | 137 | * An option specifying which Java reference type should be used to refer |
@@ -455,42 +457,43 @@ static <K, V> HashEntry<K, V>[] newArray(int i) { |
455 | 457 | */ |
456 | 458 | static final class Segment<K, V> extends ReentrantLock implements Serializable { |
457 | 459 | /* |
458 | | - * Segments maintain a table of entry lists that are ALWAYS |
459 | | - * kept in a consistent state, so can be read without locking. |
460 | | - * Next fields of nodes are immutable (final). All list |
461 | | - * additions are performed at the front of each bin. This |
462 | | - * makes it easy to check changes, and also fast to traverse. |
463 | | - * When nodes would otherwise be changed, new nodes are |
464 | | - * created to replace them. This works well for hash tables |
465 | | - * since the bin lists tend to be short. (The average length |
466 | | - * is less than two for the default load factor threshold.) |
467 | | - * |
468 | | - * Read operations can thus proceed without locking, but rely |
469 | | - * on selected uses of volatiles to ensure that completed |
470 | | - * write operations performed by other threads are |
471 | | - * noticed. For most purposes, the "count" field, tracking the |
472 | | - * number of elements, serves as that volatile variable |
473 | | - * ensuring visibility. This is convenient because this field |
474 | | - * needs to be read in many read operations anyway: |
475 | | - * |
476 | | - * - All (unsynchronized) read operations must first read the |
477 | | - * "count" field, and should not look at table entries if |
478 | | - * it is 0. |
479 | | - * |
480 | | - * - All (synchronized) write operations should write to |
481 | | - * the "count" field after structurally changing any bin. |
482 | | - * The operations must not take any action that could even |
483 | | - * momentarily cause a concurrent read operation to see |
484 | | - * inconsistent data. This is made easier by the nature of |
485 | | - * the read operations in Map. For example, no operation |
486 | | - * can reveal that the table has grown but the threshold |
487 | | - * has not yet been updated, so there are no atomicity |
488 | | - * requirements for this with respect to reads. |
489 | | - * |
490 | | - * As a guide, all critical volatile reads and writes to the |
491 | | - * count field are marked in code comments. |
492 | | - */ |
| 460 | + * Segments maintain a table of entry lists that are ALWAYS |
| 461 | + * kept in a consistent state, so can be read without locking. |
| 462 | + * Next fields of nodes are immutable (final). All list |
| 463 | + * additions are performed at the front of each bin. This |
| 464 | + * makes it easy to check changes, and also fast to traverse. |
| 465 | + * When nodes would otherwise be changed, new nodes are |
| 466 | + * created to replace them. This works well for hash tables |
| 467 | + * since the bin lists tend to be short. (The average length |
| 468 | + * is less than two for the default load factor threshold.) |
| 469 | + * |
| 470 | + * Read operations can thus proceed without locking, but rely |
| 471 | + * on selected uses of volatiles to ensure that completed |
| 472 | + * write operations performed by other threads are |
| 473 | + * noticed. For most purposes, the "count" field, tracking the |
| 474 | + * number of elements, serves as that volatile variable |
| 475 | + * ensuring visibility. This is convenient because this field |
| 476 | + * needs to be read in many read operations anyway: |
| 477 | + * |
| 478 | + * - All (unsynchronized) read operations must first read the |
| 479 | + * "count" field, and should not look at table entries if |
| 480 | + * it is 0. |
| 481 | + * |
| 482 | + * - All (synchronized) write operations should write to |
| 483 | + * the "count" field after structurally changing any bin. |
| 484 | + * The operations must not take any action that could even |
| 485 | + * momentarily cause a concurrent read operation to see |
| 486 | + * inconsistent data. This is made easier by the nature of |
| 487 | + * the read operations in Map. For example, no operation |
| 488 | + * can reveal that the table has grown but the threshold |
| 489 | + * has not yet been updated, so there are no atomicity |
| 490 | + * requirements for this with respect to reads. |
| 491 | + * |
| 492 | + * As a guide, all critical volatile reads and writes to the |
| 493 | + * count field are marked in code comments. |
| 494 | + */ |
493 | 495 |
|
| 496 | + @Serial |
494 | 497 | private static final long serialVersionUID = 2249069246763182397L; |
495 | 498 |
|
496 | 499 | /** |
@@ -952,7 +955,7 @@ public ConcurrentReferenceHashMap( |
952 | 955 | identityComparisons = options != null && options.contains( Option.IDENTITY_COMPARISONS ); |
953 | 956 |
|
954 | 957 | for ( int i = 0; i < this.segments.length; ++i ) { |
955 | | - this.segments[i] = new Segment<K, V>( |
| 958 | + this.segments[i] = new Segment<>( |
956 | 959 | cap, loadFactor, |
957 | 960 | keyType, valueType, identityComparisons |
958 | 961 | ); |
@@ -1642,6 +1645,7 @@ public V nextElement() { |
1642 | 1645 | * This class is needed for JDK5 compatibility. |
1643 | 1646 | */ |
1644 | 1647 | static class SimpleEntry<K, V> implements Entry<K, V>, Serializable { |
| 1648 | + @Serial |
1645 | 1649 | private static final long serialVersionUID = -8499721149061103585L; |
1646 | 1650 |
|
1647 | 1651 | private final K key; |
@@ -1848,6 +1852,7 @@ public void clear() { |
1848 | 1852 | * for each key-value mapping, followed by a null pair. |
1849 | 1853 | * The key-value mappings are emitted in no particular order. |
1850 | 1854 | */ |
| 1855 | + @Serial |
1851 | 1856 | private void writeObject(java.io.ObjectOutputStream s) throws IOException { |
1852 | 1857 | s.defaultWriteObject(); |
1853 | 1858 |
|
@@ -1883,6 +1888,7 @@ private void writeObject(java.io.ObjectOutputStream s) throws IOException { |
1883 | 1888 | * |
1884 | 1889 | * @param s the stream |
1885 | 1890 | */ |
| 1891 | + @Serial |
1886 | 1892 | @SuppressWarnings("unchecked") |
1887 | 1893 | private void readObject(java.io.ObjectInputStream s) |
1888 | 1894 | throws IOException, ClassNotFoundException { |
|
0 commit comments