Commit 47a56616 authored by Phillip Webb's avatar Phillip Webb

Merge branch '1.5.x'

parents c9080647 ecfc8d73
...@@ -330,17 +330,28 @@ public class Restarter { ...@@ -330,17 +330,28 @@ public class Restarter {
private void cleanupKnownCaches() throws Exception { private void cleanupKnownCaches() throws Exception {
// Whilst not strictly necessary it helps to cleanup soft reference caches // Whilst not strictly necessary it helps to cleanup soft reference caches
// early rather than waiting for memory limits to be reached // early rather than waiting for memory limits to be reached
clear(ResolvableType.class, "cache"); ResolvableType.clearCache();
clear("org.springframework.core.SerializableTypeWrapper", "cache"); cleanCachedIntrospectionResultsCache();
ReflectionUtils.clearCache();
clearAnnotationUtilsCache();
if (!JavaVersion.getJavaVersion().isEqualOrNewerThan(JavaVersion.NINE)) {
clear("com.sun.naming.internal.ResourceManager", "propertiesCache");
}
}
private void cleanCachedIntrospectionResultsCache() throws Exception {
clear(CachedIntrospectionResults.class, "acceptedClassLoaders"); clear(CachedIntrospectionResults.class, "acceptedClassLoaders");
clear(CachedIntrospectionResults.class, "strongClassCache"); clear(CachedIntrospectionResults.class, "strongClassCache");
clear(CachedIntrospectionResults.class, "softClassCache"); clear(CachedIntrospectionResults.class, "softClassCache");
clear(ReflectionUtils.class, "declaredFieldsCache"); }
clear(ReflectionUtils.class, "declaredMethodsCache");
clear(AnnotationUtils.class, "findAnnotationCache"); private void clearAnnotationUtilsCache() throws Exception {
clear(AnnotationUtils.class, "annotatedInterfaceCache"); try {
if (!JavaVersion.getJavaVersion().isEqualOrNewerThan(JavaVersion.NINE)) { AnnotationUtils.clearCache();
clear("com.sun.naming.internal.ResourceManager", "propertiesCache"); }
catch (Throwable ex) {
clear(AnnotationUtils.class, "findAnnotationCache");
clear(AnnotationUtils.class, "annotatedInterfaceCache");
} }
} }
...@@ -354,14 +365,19 @@ public class Restarter { ...@@ -354,14 +365,19 @@ public class Restarter {
} }
private void clear(Class<?> type, String fieldName) throws Exception { private void clear(Class<?> type, String fieldName) throws Exception {
Field field = type.getDeclaredField(fieldName); try {
field.setAccessible(true); Field field = type.getDeclaredField(fieldName);
Object instance = field.get(null); field.setAccessible(true);
if (instance instanceof Set) { Object instance = field.get(null);
((Set<?>) instance).clear(); if (instance instanceof Set) {
} ((Set<?>) instance).clear();
if (instance instanceof Map) { }
((Map<?, ?>) instance).keySet().removeIf(this::isFromRestartClassLoader); if (instance instanceof Map) {
((Map<?, ?>) instance).keySet().removeIf(this::isFromRestartClassLoader);
}
}
catch (Exception ex) {
this.logger.debug("Unable to clear field " + type + " " + fieldName, ex);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment