Skip to content

Commit

Permalink
6323 resource creation deadlock (#6324)
Browse files Browse the repository at this point in the history
* make map reads concurrent

* change log
  • Loading branch information
JasonRoberts-smile authored and tadgh committed Oct 2, 2024
1 parent 02d38bc commit 6ca612e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,15 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public abstract class BaseRuntimeElementDefinition<T extends IBase> {

private static final Class<Void> VOID_CLASS = Void.class;
private final Class<? extends T> myImplementingClass;
private final String myName;
private final boolean myStandardType;
private Map<Class<?>, Constructor<T>> myConstructors = Collections.synchronizedMap(new HashMap<>());
private final Map<Class<?>, Constructor<T>> myConstructors = new ConcurrentHashMap<>();
private List<RuntimeChildDeclaredExtensionDefinition> myExtensions = new ArrayList<>();
private List<RuntimeChildDeclaredExtensionDefinition> myExtensionsModifier = new ArrayList<>();
private List<RuntimeChildDeclaredExtensionDefinition> myExtensionsNonModifier = new ArrayList<>();
Expand Down Expand Up @@ -84,27 +85,24 @@ private Constructor<T> getConstructor(@Nullable Object theArgument) {
argumentType = theArgument.getClass();
}

Constructor<T> retVal = myConstructors.get(argumentType);
if (retVal == null) {
Constructor<T> retVal = myConstructors.computeIfAbsent(argumentType, type -> {
for (Constructor<?> next : getImplementingClass().getConstructors()) {
if (argumentType == VOID_CLASS) {
if (type == VOID_CLASS) {
if (next.getParameterTypes().length == 0) {
retVal = (Constructor<T>) next;
break;
}
} else if (next.getParameterTypes().length == 1) {
if (next.getParameterTypes()[0].isAssignableFrom(argumentType)) {
retVal = (Constructor<T>) next;
break;
return (Constructor<T>) next;
}
} else if (next.getParameterTypes().length == 1 && next.getParameterTypes()[0].isAssignableFrom(type)) {
return (Constructor<T>) next;
}
}
if (retVal == null) {
throw new ConfigurationException(Msg.code(1695) + "Class " + getImplementingClass()
+ " has no constructor with a single argument of type " + argumentType);
}
myConstructors.put(argumentType, retVal);
return null;
});

if (retVal == null) {
throw new ConfigurationException(Msg.code(1695) + "Class " + getImplementingClass()
+ " has no constructor with a single argument of type " + argumentType);
}

return retVal;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
type: perf
issue: 6323
title: "A synchronization choke point was removed from the model object initialization code, reducing the risk of
multi-thread contention."

0 comments on commit 6ca612e

Please sign in to comment.