On Wed, May 18, 2022 at 8:52 PM <[email protected]> wrote:
>
> This is an automated email from the ASF dual-hosted git repository.
>
> markt pushed a commit to branch main
> in repository https://gitbox.apache.org/repos/asf/tomcat.git
>
>
> The following commit(s) were added to refs/heads/main by this push:
> new 93108de112 The ObjectStreamClass memory leak has been fixed in newer
> JREs
> 93108de112 is described below
>
> commit 93108de1127fb228e343a3f3304554bfe7177583
> Author: Mark Thomas <[email protected]>
> AuthorDate: Wed May 18 19:52:00 2022 +0100
>
> The ObjectStreamClass memory leak has been fixed in newer JREs
>
> https://bugs.openjdk.java.net/browse/JDK-8277072
> Disable the clean-up code when running on a JRE that includes the fix.
This is great because accessing the structures to clean them up looked
hard to me (I couldn't understand how this cache worked today ;) ).
Rémy
> ---
> .../catalina/loader/WebappClassLoaderBase.java | 27
> +++++++++++++++-------
> webapps/docs/changelog.xml | 5 ++++
> webapps/docs/config/context.xml | 4 ++++
> 3 files changed, 28 insertions(+), 8 deletions(-)
>
> diff --git a/java/org/apache/catalina/loader/WebappClassLoaderBase.java
> b/java/org/apache/catalina/loader/WebappClassLoaderBase.java
> index b87cc72abe..6ba682b610 100644
> --- a/java/org/apache/catalina/loader/WebappClassLoaderBase.java
> +++ b/java/org/apache/catalina/loader/WebappClassLoaderBase.java
> @@ -2289,6 +2289,12 @@ public abstract class WebappClassLoaderBase extends
> URLClassLoader
>
>
> private void clearReferencesObjectStreamClassCaches() {
> + if (JreCompat.isJre19Available()) {
> + // The memory leak this fixes has been fixed in Java 19 onwards,
> + // 17.0.4 onwards and 11.0.16 onwards
> + // See https://bugs.openjdk.java.net/browse/JDK-8277072
> + return;
> + }
> try {
> Class<?> clazz =
> Class.forName("java.io.ObjectStreamClass$Caches");
> clearCache(clazz, "localDescs");
> @@ -2316,14 +2322,19 @@ public abstract class WebappClassLoaderBase extends
> URLClassLoader
> throws ReflectiveOperationException, SecurityException,
> ClassCastException {
> Field f = target.getDeclaredField(mapName);
> f.setAccessible(true);
> - Map<?,?> map = (Map<?,?>) f.get(null);
> - Iterator<?> keys = map.keySet().iterator();
> - while (keys.hasNext()) {
> - Object key = keys.next();
> - if (key instanceof Reference) {
> - Object clazz = ((Reference<?>) key).get();
> - if (loadedByThisOrChild(clazz)) {
> - keys.remove();
> + Object map = f.get(null);
> + // Avoid trying to clear references if Tomcat is running on a JRE
> that
> + // includes the fix for this memory leak
> + // See https://bugs.openjdk.java.net/browse/JDK-8277072
> + if (map instanceof Map<?,?>) {
> + Iterator<?> keys = ((Map<?,?>) map).keySet().iterator();
> + while (keys.hasNext()) {
> + Object key = keys.next();
> + if (key instanceof Reference) {
> + Object clazz = ((Reference<?>) key).get();
> + if (loadedByThisOrChild(clazz)) {
> + keys.remove();
> + }
> }
> }
> }
> diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
> index 2b22817b79..c1a182402b 100644
> --- a/webapps/docs/changelog.xml
> +++ b/webapps/docs/changelog.xml
> @@ -115,6 +115,11 @@
> Improve the error message if a required <code>--add-opens</code>
> option
> is missing. (markt)
> </fix>
> + <fix>
> + Disable the memory leak correction code enabled by the Context
> attribute
> + <code>clearReferencesObjectStreamClassCaches</code> when running on a
> + JRE that includes a fix for the underlying memory leak. (markt)
> + </fix>
> </changelog>
> </subsection>
> <subsection name="Jasper">
> diff --git a/webapps/docs/config/context.xml b/webapps/docs/config/context.xml
> index 78e75b20d8..0fa30a07f2 100644
> --- a/webapps/docs/config/context.xml
> +++ b/webapps/docs/config/context.xml
> @@ -799,6 +799,10 @@
> therefore requires that the command line option
> <code>-XaddExports:java.base/java.io=ALL-UNNAMED</code> is set. If
> not
> specified, the default value of <code>true</code> will be used.</p>
> + <p>The memory leak associated with <code>ObjectStreamClass</code> has
> + been fixed in Java 19 onwards, Java 17.0.4 onwards and Java 11.0.16
> + onwards. The check will be disabled when running on a version
> + of Java that contains the fix.</p>
> </attribute>
>
> <attribute name="clearReferencesRmiTargets" required="false">
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]