Skip to content

Commit 3edf6c4

Browse files
committed
move ConcurrentReferenceHashMap back to Envers where it is actually used
1 parent 582a3a4 commit 3edf6c4

File tree

2 files changed

+47
-42
lines changed

2 files changed

+47
-42
lines changed
+47-41
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
* SPDX-License-Identifier: Apache-2.0
33
* Copyright Red Hat Inc. and Hibernate Authors
44
*/
5-
package org.hibernate.internal.util.collections;
5+
package org.hibernate.envers.internal.tools;
66

77
import java.io.IOException;
8+
import java.io.Serial;
89
import java.io.Serializable;
910
import java.lang.ref.Reference;
1011
import java.lang.ref.ReferenceQueue;
@@ -122,14 +123,15 @@
122123
* @author Doug Lea
123124
* @author Jason T. Greene
124125
*/
125-
public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V>
126+
class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V>
126127
implements java.util.concurrent.ConcurrentMap<K, V>, Serializable {
128+
@Serial
127129
private static final long serialVersionUID = 7249069246763182397L;
128130

129131
/*
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+
*/
133135

134136
/**
135137
* 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) {
455457
*/
456458
static final class Segment<K, V> extends ReentrantLock implements Serializable {
457459
/*
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+
*/
493495

496+
@Serial
494497
private static final long serialVersionUID = 2249069246763182397L;
495498

496499
/**
@@ -952,7 +955,7 @@ public ConcurrentReferenceHashMap(
952955
identityComparisons = options != null && options.contains( Option.IDENTITY_COMPARISONS );
953956

954957
for ( int i = 0; i < this.segments.length; ++i ) {
955-
this.segments[i] = new Segment<K, V>(
958+
this.segments[i] = new Segment<>(
956959
cap, loadFactor,
957960
keyType, valueType, identityComparisons
958961
);
@@ -1642,6 +1645,7 @@ public V nextElement() {
16421645
* This class is needed for JDK5 compatibility.
16431646
*/
16441647
static class SimpleEntry<K, V> implements Entry<K, V>, Serializable {
1648+
@Serial
16451649
private static final long serialVersionUID = -8499721149061103585L;
16461650

16471651
private final K key;
@@ -1848,6 +1852,7 @@ public void clear() {
18481852
* for each key-value mapping, followed by a null pair.
18491853
* The key-value mappings are emitted in no particular order.
18501854
*/
1855+
@Serial
18511856
private void writeObject(java.io.ObjectOutputStream s) throws IOException {
18521857
s.defaultWriteObject();
18531858

@@ -1883,6 +1888,7 @@ private void writeObject(java.io.ObjectOutputStream s) throws IOException {
18831888
*
18841889
* @param s the stream
18851890
*/
1891+
@Serial
18861892
@SuppressWarnings("unchecked")
18871893
private void readObject(java.io.ObjectInputStream s)
18881894
throws IOException, ClassNotFoundException {

hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/ReflectionTools.java

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import org.hibernate.envers.exception.AuditException;
1414
import org.hibernate.envers.internal.entities.PropertyData;
1515
import org.hibernate.envers.tools.Pair;
16-
import org.hibernate.internal.util.collections.ConcurrentReferenceHashMap;
1716
import org.hibernate.property.access.spi.Getter;
1817
import org.hibernate.property.access.spi.PropertyAccessStrategy;
1918
import org.hibernate.property.access.spi.PropertyAccessStrategyResolver;

0 commit comments

Comments
 (0)