You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2019/03/07 20:07:19 UTC

[tomcat] branch 8.5.x updated: Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=63236

This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch 8.5.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/8.5.x by this push:
     new 2e13d46  Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=63236
2e13d46 is described below

commit 2e13d4653c405e4ed25c0824963faa18f4d6c84f
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Thu Mar 7 19:36:43 2019 +0000

    Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=63236
    
    Use intern() as suggested by Phillip Webb to reduce memory wasted due to
    string duplication. Saves ~254k on a clean install.
    Thanks to YourKit for helping to track these down.
---
 java/org/apache/catalina/util/LifecycleMBeanBase.java             | 2 +-
 java/org/apache/tomcat/util/digester/CallMethodRule.java          | 2 +-
 java/org/apache/tomcat/util/digester/Digester.java                | 8 ++------
 java/org/apache/tomcat/util/modeler/ManagedBean.java              | 4 ++--
 .../modeler/modules/MbeansDescriptorsIntrospectionSource.java     | 4 ++--
 webapps/docs/changelog.xml                                        | 7 +++++++
 6 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/java/org/apache/catalina/util/LifecycleMBeanBase.java b/java/org/apache/catalina/util/LifecycleMBeanBase.java
index 1386cd6..417015d 100644
--- a/java/org/apache/catalina/util/LifecycleMBeanBase.java
+++ b/java/org/apache/catalina/util/LifecycleMBeanBase.java
@@ -241,7 +241,7 @@ public abstract class LifecycleMBeanBase extends LifecycleBase
 
         this.mserver = server;
         this.oname = name;
-        this.domain = name.getDomain();
+        this.domain = name.getDomain().intern();
 
         return oname;
     }
diff --git a/java/org/apache/tomcat/util/digester/CallMethodRule.java b/java/org/apache/tomcat/util/digester/CallMethodRule.java
index 10ffc84..9221aae 100644
--- a/java/org/apache/tomcat/util/digester/CallMethodRule.java
+++ b/java/org/apache/tomcat/util/digester/CallMethodRule.java
@@ -303,7 +303,7 @@ public class CallMethodRule extends Rule {
             throws Exception {
 
         if (paramCount == 0) {
-            this.bodyText = bodyText.trim();
+            this.bodyText = bodyText.trim().intern();
         }
 
     }
diff --git a/java/org/apache/tomcat/util/digester/Digester.java b/java/org/apache/tomcat/util/digester/Digester.java
index 093ef03..f0345a5 100644
--- a/java/org/apache/tomcat/util/digester/Digester.java
+++ b/java/org/apache/tomcat/util/digester/Digester.java
@@ -977,7 +977,7 @@ public class Digester extends DefaultHandler2 {
         // Fire "body" events for all relevant rules
         List<Rule> rules = matches.pop();
         if ((rules != null) && (rules.size() > 0)) {
-            String bodyText = this.bodyText.toString();
+            String bodyText = this.bodyText.toString().intern();
             for (int i = 0; i < rules.size(); i++) {
                 try {
                     Rule rule = rules.get(i);
@@ -2030,17 +2030,13 @@ public class Digester extends DefaultHandler2 {
         for (int i = 0; i < nAttributes; ++i) {
             String value = newAttrs.getValue(i);
             try {
-                String newValue = IntrospectionUtils.replaceProperties(value, null, source);
-                if (value != newValue) {
-                    newAttrs.setValue(i, newValue);
-                }
+                newAttrs.setValue(i, IntrospectionUtils.replaceProperties(value, null, source).intern());
             } catch (Exception e) {
                 log.warn(sm.getString("digester.failedToUpdateAttributes", newAttrs.getLocalName(i), value), e);
             }
         }
 
         return newAttrs;
-
     }
 
 
diff --git a/java/org/apache/tomcat/util/modeler/ManagedBean.java b/java/org/apache/tomcat/util/modeler/ManagedBean.java
index 6162b7e..8b8e5ed 100644
--- a/java/org/apache/tomcat/util/modeler/ManagedBean.java
+++ b/java/org/apache/tomcat/util/modeler/ManagedBean.java
@@ -571,7 +571,7 @@ public class ManagedBean implements java.io.Serializable {
         StringUtils.join(operation.getSignature(), ',', new Function<ParameterInfo>() {
             @Override public String apply(ParameterInfo t) { return t.getType(); }}, key);
         key.append(')');
-        return key.toString();
+        return key.toString().intern();
     }
 
 
@@ -581,6 +581,6 @@ public class ManagedBean implements java.io.Serializable {
         StringUtils.join(parameterTypes, ',', key);
         key.append(')');
 
-        return key.toString();
+        return key.toString().intern();
     }
 }
diff --git a/java/org/apache/tomcat/util/modeler/modules/MbeansDescriptorsIntrospectionSource.java b/java/org/apache/tomcat/util/modeler/modules/MbeansDescriptorsIntrospectionSource.java
index f3637f4..b19f1fc 100644
--- a/java/org/apache/tomcat/util/modeler/modules/MbeansDescriptorsIntrospectionSource.java
+++ b/java/org/apache/tomcat/util/modeler/modules/MbeansDescriptorsIntrospectionSource.java
@@ -345,8 +345,8 @@ public class MbeansDescriptorsIntrospectionSource extends ModelerSource
                     for(int i=0; i<parms.length; i++ ) {
                         ParameterInfo pi=new ParameterInfo();
                         pi.setType(parms[i].getName());
-                        pi.setName( "param" + i);
-                        pi.setDescription("Introspected parameter param" + i);
+                        pi.setName(("param" + i).intern());
+                        pi.setDescription(("Introspected parameter param" + i).intern());
                         op.addParameter(pi);
                     }
                     mbean.addOperation(op);
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 29f5fc6..36c3168 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -107,6 +107,13 @@
         searching for nested groups when the JNDIRealm is configured with
         <code>roleNested</code> set to <code>true</code>. (markt)
       </fix>
+      <fix>
+        <bug>63236</bug>: Use <code>String.intern()</code> as suggested by
+        Phillip Webb to reduce memory wasted due to String duplication. This
+        changes saves ~245k when starting a clean installation. With additional
+        thanks to YourKit Java profiler for helping to track down the wasted
+        memory and the root causes. (markt)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Coyote">


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org