Skip to content

Commit

Permalink
Update ConcurrencyManager impl to be in sync with master (#1347)
Browse files Browse the repository at this point in the history
Signed-off-by: Will Dazey <[email protected]>
  • Loading branch information
dazey3 authored Oct 26, 2021
1 parent 0c1a376 commit a437d85
Showing 1 changed file with 24 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,23 @@
// Oracle - initial API and implementation from Oracle TopLink
package org.eclipse.persistence.internal.helper;

import java.io.*;
import java.io.Serializable;
import java.io.StringWriter;
import java.security.AccessController;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;

import org.eclipse.persistence.config.SystemProperties;
import org.eclipse.persistence.exceptions.*;
import org.eclipse.persistence.internal.localization.*;
import org.eclipse.persistence.exceptions.ConcurrencyException;
import org.eclipse.persistence.internal.identitymaps.CacheKey;
import org.eclipse.persistence.internal.localization.ToStringLocalization;
import org.eclipse.persistence.internal.localization.TraceLocalization;
import org.eclipse.persistence.internal.security.PrivilegedAccessHelper;
import org.eclipse.persistence.internal.security.PrivilegedGetSystemProperty;
import org.eclipse.persistence.logging.*;
import org.eclipse.persistence.logging.AbstractSessionLog;
import org.eclipse.persistence.logging.SessionLog;

/**
* INTERNAL:
Expand Down Expand Up @@ -79,7 +82,7 @@ public class ConcurrencyManager implements Serializable {
private static final Map<Thread, String> THREADS_TO_WAIT_ON_ACQUIRE_NAME_OF_METHOD_CREATING_TRACE = new ConcurrentHashMap<>();
// Holds as a keys threads that needed to acquire one or more read locks on different cache keys.
private static final Map<Thread, ReadLockManager> READ_LOCK_MANAGERS = new ConcurrentHashMap<>();
private static final Set<Thread> THREADS_WAITING_TO_RELEASE_DEFERRED_LOCKS = new HashSet<>();
private static final Set<Thread> THREADS_WAITING_TO_RELEASE_DEFERRED_LOCKS = ConcurrentHashMap.newKeySet();
private static final Map<Thread, String> THREADS_WAITING_TO_RELEASE_DEFERRED_LOCKS_BUILD_OBJECT_COMPLETE_GOES_NOWHERE = new ConcurrentHashMap<>();

private static final String ACQUIRE_METHOD_NAME = ConcurrencyManager.class.getName() + ".acquire(...)";
Expand Down Expand Up @@ -209,7 +212,8 @@ public synchronized boolean acquireWithWait(boolean forMerge, int wait) throws C
} finally {
removeThreadNoLongerWaitingToAcquireLockForWriting(currentThread);
}
if ((this.activeThread == null && this.numberOfReaders.get() == 0) || (this.activeThread == currentThread)) {
if ((this.activeThread == null && this.numberOfReaders.get() == 0)
|| (this.activeThread == currentThread)) {
acquire(forMerge);
return true;
}
Expand Down Expand Up @@ -375,7 +379,7 @@ public Thread getActiveThread() {
* Return the deferred lock manager from the thread
*/
public static DeferredLockManager getDeferredLockManager(Thread thread) {
return (thread == null) ? null : getDeferredLockManagers().get(thread);
return getDeferredLockManagers().get(thread);
}

/**
Expand Down Expand Up @@ -458,7 +462,8 @@ public static boolean isBuildObjectOnThreadComplete(Thread thread, Map recursive
}

Vector deferredLocks = lockManager.getDeferredLocks();
for (Enumeration deferredLocksEnum = deferredLocks.elements(); deferredLocksEnum.hasMoreElements();) {
for (Enumeration deferredLocksEnum = deferredLocks.elements();
deferredLocksEnum.hasMoreElements();) {
ConcurrencyManager deferedLock = (ConcurrencyManager)deferredLocksEnum.nextElement();
Thread activeThread = null;
if (deferedLock.isAcquired()) {
Expand Down Expand Up @@ -808,6 +813,7 @@ protected static Map<Thread, ReadLockManager> getReadLockManagers() {
/**
* Print the nested depth.
*/
@Override
public String toString() {
Object[] args = { Integer.valueOf(getDepth()) };
return Helper.getShortClassName(getClass()) + ToStringLocalization.buildMessage("nest_level", args);
Expand Down Expand Up @@ -852,7 +858,16 @@ private static String getPropertyRecordStackOnLock() {
*
*/
public void putThreadAsWaitingToAcquireLockForWriting(Thread thread, String methodName) {
THREADS_TO_WAIT_ON_ACQUIRE.put(thread, this);
THREADS_TO_WAIT_ON_ACQUIRE_NAME_OF_METHOD_CREATING_TRACE.put(thread, methodName);
}

/**
* The thread has acquired the lock for writing or decided to defer acquiring the lock putting this lock into its
* deferred lock list.
*/
public void removeThreadNoLongerWaitingToAcquireLockForWriting(Thread thread) {
THREADS_TO_WAIT_ON_ACQUIRE.remove(thread);
THREADS_TO_WAIT_ON_ACQUIRE_NAME_OF_METHOD_CREATING_TRACE.remove(thread);
}

Expand All @@ -873,14 +888,6 @@ public void removeThreadNoLongerWaitingToAcquireLockForReading(Thread thread) {
THREADS_TO_WAIT_ON_ACQUIRE_READ_LOCK_NAME_OF_METHOD_CREATING_TRACE.remove(thread);
}

/**
* The thread has acquired the lock for writing or decided to defer acquiring the lock putting this lock into its
* deferred lock list.
*/
public void removeThreadNoLongerWaitingToAcquireLockForWriting(Thread thread) {
THREADS_TO_WAIT_ON_ACQUIRE.remove(thread);
}

/** Getter for {@link #concurrencyManagerId} */
public long getConcurrencyManagerId() {
return concurrencyManagerId;
Expand Down Expand Up @@ -982,10 +989,7 @@ protected static ReadLockManager getReadLockManagerEnsureResultIsNotNull(Thread
Map<Thread, ReadLockManager> readLockManagers = getReadLockManagers();
if (!readLockManagers.containsKey(thread)) {
ReadLockManager readLockManager = new ReadLockManager();
ReadLockManager value = readLockManagers.get(thread);
if (value == null) {
readLockManagers.put(thread, readLockManager);
}
readLockManagers.putIfAbsent(thread, readLockManager);
return readLockManager;
}
return readLockManagers.get(thread);
Expand Down

0 comments on commit a437d85

Please sign in to comment.