Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear com.sun.naming.internal.ResourceManager#propertiesCache #41723

Merged
merged 1 commit into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion build-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,8 @@
</systemPropertyVariables>
<!-- limit the amount of memory surefire can use, 1500m should be plenty-->
<!-- set tmpdir as early as possible because surefire sets it too late for JDK16 -->
<argLine>${jacoco.agent.argLine} -Xmx1500m -XX:MaxMetaspaceSize=1500m -Djava.io.tmpdir="${project.build.directory}" ${surefire.argLine.additional}</argLine>
<!-- the add-opens is here to allow to clear the propertiesCache in com.sun.naming.internal.ResourceManager -->
<argLine>${jacoco.agent.argLine} -Xmx1500m -XX:MaxMetaspaceSize=1500m -Djava.io.tmpdir="${project.build.directory}" ${surefire.argLine.additional} --add-opens java.naming/com.sun.naming.internal=ALL-UNNAMED</argLine>
<excludedEnvironmentVariables>MAVEN_OPTS</excludedEnvironmentVariables>
</configuration>
</plugin>
Expand Down
10 changes: 3 additions & 7 deletions extensions/jaxb/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

<artifactId>quarkus-jaxb-deployment</artifactId>
<name>Quarkus - JAXB - Deployment</name>
<properties>
<surefire.argLine.additional>-Duser.language=en</surefire.argLine.additional>
</properties>

<dependencies>
<dependency>
Expand Down Expand Up @@ -52,13 +55,6 @@
</annotationProcessorPaths>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>-Duser.language=en</argLine>
</configuration>
</plugin>
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,46 @@ public class ClearCache {

public static void clearCaches() {
clearAnnotationCache();
clearResourceManagerPropertiesCache();
clearBeansIntrospectorCache();
}

private static void clearAnnotationCache() {
clearMap(AnnotationUtils.class, "repeatableAnnotationContainerCache");
}

/**
* This will only be effective if the tests are launched with --add-opens java.naming/com.sun.naming.internal=ALL-UNNAMED,
* which is the case in the Quarkus codebase where memory usage is actually an issue.
* <p>
* While not mandatory, this actually helps so enabling it only in the Quarkus codebase has actual value.
*/
private static void clearResourceManagerPropertiesCache() {
try {
Field f = AnnotationUtils.class.getDeclaredField("repeatableAnnotationContainerCache");
f.setAccessible(true);
((Map) (f.get(null))).clear();
} catch (NoSuchFieldException | IllegalAccessException e) {
//ignore
log.debug("Failed to clear annotation cache", e);
clearMap(Class.forName("com.sun.naming.internal.ResourceManager"), "propertiesCache");
} catch (ClassNotFoundException e) {
// ignore
log.debug("Unable to load com.sun.naming.internal.ResourceManager", e);
}
}

private static void clearBeansIntrospectorCache() {
try {
Introspector.flushCaches();
} catch (Exception e) {
//ignore
// ignore
log.debug("Failed to clear java.beans.Introspector cache", e);
}
}

private static void clearMap(Class<?> clazz, String mapField) {
try {
Field f = clazz.getDeclaredField(mapField);
f.setAccessible(true);
((Map) (f.get(null))).clear();
} catch (Exception e) {
// ignore
log.debugf(e, "Failed to clear cache for %s#%s cache", clazz.getName(), mapField);
}
}
}
Loading