Skip to content

Commit

Permalink
[JENKINS-72067] High memory usage from `XStream2.AssociatedConverterI…
Browse files Browse the repository at this point in the history
…mpl` (#8529)
  • Loading branch information
basil authored Sep 29, 2023
1 parent 6be55c1 commit 91527dc
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions core/src/main/java/hudson/util/XStream2.java
Original file line number Diff line number Diff line change
Expand Up @@ -475,12 +475,8 @@ protected Class<? extends ConverterMatcher> computeValue(Class<?> type) {
return computeConverterClass(type);
}
};
private final ClassValue<Converter> cache = new ClassValue<Converter>() {
@Override
protected Converter computeValue(Class<?> type) {
return computeConverter(type);
}
};
private final ConcurrentHashMap<Class<?>, Converter> cache =
new ConcurrentHashMap<>();

private AssociatedConverterImpl(XStream xstream) {
this.xstream = xstream;
Expand All @@ -491,7 +487,9 @@ private Converter findConverter(@CheckForNull Class<?> t) {
if (t == null) {
return null;
}
return cache.get(t);
Converter result = cache.computeIfAbsent(t, unused -> computeConverter(t));
// ConcurrentHashMap does not allow null, so use this object to represent null
return result == this ? null : result;
}

@CheckForNull
Expand All @@ -515,7 +513,8 @@ private static Class<? extends ConverterMatcher> computeConverterClass(@NonNull
private Converter computeConverter(@NonNull Class<?> t) {
Class<? extends ConverterMatcher> cl = classCache.get(t);
if (cl == null) {
return null;
// See above.. this object in cache represents null
return this;
}
try {
Constructor<?> c = cl.getConstructors()[0];
Expand Down

0 comments on commit 91527dc

Please sign in to comment.