Author: markt
Date: Wed May 18 10:25:41 2016
New Revision: 1744377
URL: http://svn.apache.org/viewvc?rev=1744377&view=rev
Log:
Make checking for RMI Target memory leaks optional and log a warning if running
on Java 9 without the necessary command line options
Modified:
tomcat/tc8.5.x/trunk/ (props changed)
tomcat/tc8.5.x/trunk/java/org/apache/catalina/core/StandardContext.java
tomcat/tc8.5.x/trunk/java/org/apache/catalina/core/mbeans-descriptors.xml
tomcat/tc8.5.x/trunk/java/org/apache/catalina/loader/LocalStrings.properties
tomcat/tc8.5.x/trunk/java/org/apache/catalina/loader/WebappClassLoaderBase.java
tomcat/tc8.5.x/trunk/webapps/docs/changelog.xml
tomcat/tc8.5.x/trunk/webapps/docs/config/context.xml
Propchange: tomcat/tc8.5.x/trunk/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed May 18 10:25:41 2016
@@ -1 +1 @@
-/tomcat/trunk:1734785,1734799,1734845,1734928,1735041,1735044,1735480,1735577,1735597,1735599-1735600,1735615,1736145,1736162,1736209,1736280,1736297,1736299,1736489,1736646,1736703,1736836,1736849,1737104-1737105,1737112,1737117,1737119-1737120,1737155,1737157,1737192,1737280,1737339,1737632,1737664,1737715,1737748,1737785,1737834,1737860,1737959,1738005,1738007,1738014-1738015,1738018,1738022,1738039,1738043,1738059-1738060,1738147,1738149,1738174-1738175,1738261,1738589,1738623-1738625,1738643,1738816,1738850,1738855,1738946-1738948,1738953-1738954,1738979,1738982,1739079-1739081,1739087,1739113,1739153,1739172,1739176,1739191,1739474,1739726,1739762,1739775,1739814,1739817-1739818,1739975,1740131,1740324,1740465,1740495,1740508-1740509,1740520,1740535,1740707,1740803,1740810,1740969,1740980,1740991,1740997,1741015,1741033,1741036,1741058,1741060,1741080,1741147,1741159,1741164,1741173,1741181,1741190,1741197,1741202,1741208,1741213,1741221,1741225,1741232,1741409,1741501,1741677
,1741892,1741896,1741984,1742023,1742042,1742071,1742090,1742093,1742101,1742105,1742111,1742139,1742146,1742148,1742166,1742181,1742184,1742187,1742246,1742248-1742251,1742263-1742264,1742268,1742276,1742369,1742387,1742448,1742509-1742512,1742917,1742919,1742933,1742975-1742976,1742984,1742986,1743019,1743115,1743117,1743124-1743125,1743134,1743425,1743554,1743679,1743696-1743698,1743700-1743701,1744058,1744064-1744065,1744125,1744194,1744229,1744270
+/tomcat/trunk:1734785,1734799,1734845,1734928,1735041,1735044,1735480,1735577,1735597,1735599-1735600,1735615,1736145,1736162,1736209,1736280,1736297,1736299,1736489,1736646,1736703,1736836,1736849,1737104-1737105,1737112,1737117,1737119-1737120,1737155,1737157,1737192,1737280,1737339,1737632,1737664,1737715,1737748,1737785,1737834,1737860,1737959,1738005,1738007,1738014-1738015,1738018,1738022,1738039,1738043,1738059-1738060,1738147,1738149,1738174-1738175,1738261,1738589,1738623-1738625,1738643,1738816,1738850,1738855,1738946-1738948,1738953-1738954,1738979,1738982,1739079-1739081,1739087,1739113,1739153,1739172,1739176,1739191,1739474,1739726,1739762,1739775,1739814,1739817-1739818,1739975,1740131,1740324,1740465,1740495,1740508-1740509,1740520,1740535,1740707,1740803,1740810,1740969,1740980,1740991,1740997,1741015,1741033,1741036,1741058,1741060,1741080,1741147,1741159,1741164,1741173,1741181,1741190,1741197,1741202,1741208,1741213,1741221,1741225,1741232,1741409,1741501,1741677
,1741892,1741896,1741984,1742023,1742042,1742071,1742090,1742093,1742101,1742105,1742111,1742139,1742146,1742148,1742166,1742181,1742184,1742187,1742246,1742248-1742251,1742263-1742264,1742268,1742276,1742369,1742387,1742448,1742509-1742512,1742917,1742919,1742933,1742975-1742976,1742984,1742986,1743019,1743115,1743117,1743124-1743125,1743134,1743425,1743554,1743679,1743696-1743698,1743700-1743701,1744058,1744064-1744065,1744125,1744194,1744229,1744270,1744323
Modified:
tomcat/tc8.5.x/trunk/java/org/apache/catalina/core/StandardContext.java
URL:
http://svn.apache.org/viewvc/tomcat/tc8.5.x/trunk/java/org/apache/catalina/core/StandardContext.java?rev=1744377&r1=1744376&r2=1744377&view=diff
==============================================================================
--- tomcat/tc8.5.x/trunk/java/org/apache/catalina/core/StandardContext.java
(original)
+++ tomcat/tc8.5.x/trunk/java/org/apache/catalina/core/StandardContext.java Wed
May 18 10:25:41 2016
@@ -707,6 +707,13 @@ public class StandardContext extends Con
private JarScanner jarScanner = null;
/**
+ * Enables the RMI Target memory leak detection to be controlled. This is
+ * necessary since the detection can only work on Java 9 if some of the
+ * modularity checks are disabled.
+ */
+ private boolean clearReferencesRmiTargets = true;
+
+ /**
* Should Tomcat attempt to null out any static or final fields from loaded
* classes when a web application is stopped as a work around for apparent
* garbage collection bugs and application coding errors? There have been
@@ -2570,6 +2577,19 @@ public class StandardContext extends Con
}
+ public boolean getClearReferencesRmiTargets() {
+ return this.clearReferencesRmiTargets;
+ }
+
+
+ public void setClearReferencesRmiTargets(boolean
clearReferencesRmiTargets) {
+ boolean oldClearReferencesRmiTargets = this.clearReferencesRmiTargets;
+ this.clearReferencesRmiTargets = clearReferencesRmiTargets;
+ support.firePropertyChange("clearReferencesRmiTargets",
+ oldClearReferencesRmiTargets, this.clearReferencesRmiTargets);
+ }
+
+
/**
* @return the clearReferencesStatic flag for this Context.
*/
@@ -5047,6 +5067,8 @@ public class StandardContext extends Con
// since the loader just started, the webapp classloader is now
// created.
+ setClassLoaderProperty("clearReferencesRmiTargets",
+ getClearReferencesRmiTargets());
setClassLoaderProperty("clearReferencesStatic",
getClearReferencesStatic());
setClassLoaderProperty("clearReferencesStopThreads",
Modified:
tomcat/tc8.5.x/trunk/java/org/apache/catalina/core/mbeans-descriptors.xml
URL:
http://svn.apache.org/viewvc/tomcat/tc8.5.x/trunk/java/org/apache/catalina/core/mbeans-descriptors.xml?rev=1744377&r1=1744376&r2=1744377&view=diff
==============================================================================
--- tomcat/tc8.5.x/trunk/java/org/apache/catalina/core/mbeans-descriptors.xml
(original)
+++ tomcat/tc8.5.x/trunk/java/org/apache/catalina/core/mbeans-descriptors.xml
Wed May 18 10:25:41 2016
@@ -82,6 +82,10 @@
description="Object names of all children"
type="[Ljavax.management.ObjectName;"/>
+ <attribute name="clearReferencesRmiTargets"
+ description="Should Tomcat look for memory leaks in RMI Targets
and clear them if found as a work around for application coding errors?"
+ type="boolean"/>
+
<attribute name="clearReferencesStatic"
description="Should Tomcat attempt to null out any static or
final fields from loaded classes when a web application is stopped as a work
around for apparent garbage collection bugs and application coding errors?"
type="boolean"/>
Modified:
tomcat/tc8.5.x/trunk/java/org/apache/catalina/loader/LocalStrings.properties
URL:
http://svn.apache.org/viewvc/tomcat/tc8.5.x/trunk/java/org/apache/catalina/loader/LocalStrings.properties?rev=1744377&r1=1744376&r2=1744377&view=diff
==============================================================================
---
tomcat/tc8.5.x/trunk/java/org/apache/catalina/loader/LocalStrings.properties
(original)
+++
tomcat/tc8.5.x/trunk/java/org/apache/catalina/loader/LocalStrings.properties
Wed May 18 10:25:41 2016
@@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+webappClassLoader.addExports=When running on Java 9 you need to add
"-XaddExports:java.rmi/sun.rmi.transport=ALL-UNNAMED" to the JVM command line
arguments to enable RMI Target memory leak detection. Alternatively, you can
suppress this warning by disabling RMI Target memory leak detection.
webappClassLoader.addPermisionNoCanonicalFile=Unable to obtain a canonical
file path from the URL [{0}]
webappClassLoader.addPermisionNoProtocol=The protocol [{0}] in the URL [{1}]
is not supported so no read permission was granted for resources located at
this URL
webappClassLoader.illegalJarPath=Illegal JAR entry detected with name {0}
Modified:
tomcat/tc8.5.x/trunk/java/org/apache/catalina/loader/WebappClassLoaderBase.java
URL:
http://svn.apache.org/viewvc/tomcat/tc8.5.x/trunk/java/org/apache/catalina/loader/WebappClassLoaderBase.java?rev=1744377&r1=1744376&r2=1744377&view=diff
==============================================================================
---
tomcat/tc8.5.x/trunk/java/org/apache/catalina/loader/WebappClassLoaderBase.java
(original)
+++
tomcat/tc8.5.x/trunk/java/org/apache/catalina/loader/WebappClassLoaderBase.java
Wed May 18 10:25:41 2016
@@ -77,6 +77,7 @@ import org.apache.juli.logging.LogFactor
import org.apache.tomcat.InstrumentableClassLoader;
import org.apache.tomcat.util.ExceptionUtils;
import org.apache.tomcat.util.IntrospectionUtils;
+import org.apache.tomcat.util.compat.JreCompat;
import org.apache.tomcat.util.compat.JreVendor;
import org.apache.tomcat.util.res.StringManager;
@@ -328,6 +329,13 @@ public abstract class WebappClassLoaderB
/**
+ * Enables the RMI Target memory leak detection to be controlled. This is
+ * necessary since the detection can only work on Java 9 if some of the
+ * modularity checks are disabled.
+ */
+ private boolean clearReferencesRmiTargets = true;
+
+ /**
* Should Tomcat attempt to null out any static or final fields from loaded
* classes when a web application is stopped as a work around for apparent
* garbage collection bugs and application coding errors? There have been
@@ -521,6 +529,16 @@ public abstract class WebappClassLoaderB
}
+ public boolean getClearReferencesRmiTargets() {
+ return this.clearReferencesRmiTargets;
+ }
+
+
+ public void setClearReferencesRmiTargets(boolean
clearReferencesRmiTargets) {
+ this.clearReferencesRmiTargets = clearReferencesRmiTargets;
+ }
+
+
/**
* Return the clearReferencesStatic flag for this Context.
* @return <code>true</code> if the classloader should attempt to set to
null
@@ -1531,7 +1549,9 @@ public abstract class WebappClassLoaderB
checkThreadLocalsForLeaks();
// Clear RMI Targets loaded by this class loader
- clearReferencesRmiTargets();
+ if (clearReferencesRmiTargets) {
+ clearReferencesRmiTargets();
+ }
// Null out any static or final fields from loaded classes,
// as a workaround for apparent garbage collection bugs
@@ -2276,6 +2296,16 @@ public abstract class WebappClassLoaderB
IllegalAccessException e) {
log.warn(sm.getString("webappClassLoader.clearRmiFail",
getContextName()), e);
+ } catch (Exception e) {
+ JreCompat jreCompat = JreCompat.getInstance();
+ if (jreCompat.isInstanceOfInaccessibleObjectException(e)) {
+ // Must be running on Java 9 without the necessary command line
+ // options.
+ log.warn(sm.getString("webappClassLoader.addExports"));
+ } else {
+ // Re-throw all other exceptions
+ throw e;
+ }
}
}
Modified: tomcat/tc8.5.x/trunk/webapps/docs/changelog.xml
URL:
http://svn.apache.org/viewvc/tomcat/tc8.5.x/trunk/webapps/docs/changelog.xml?rev=1744377&r1=1744376&r2=1744377&view=diff
==============================================================================
--- tomcat/tc8.5.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc8.5.x/trunk/webapps/docs/changelog.xml Wed May 18 10:25:41 2016
@@ -51,7 +51,9 @@
RMI Target related memory leaks are avoidable which makes them an
application bug that needs to be fixed rather than a JRE bug to work
around. Therefore, start logging RMI Target related memory leaks on web
- application stop. (markt)
+ application stop. Add an option that controls if the check for these
+ leaks is made. Log a warning if running on Java 9 with this check
+ enabled but without the command line option it requires. (markt)
</fix>
<fix>
Ensure NPE will not be thrown during deployment when scanning jar files
Modified: tomcat/tc8.5.x/trunk/webapps/docs/config/context.xml
URL:
http://svn.apache.org/viewvc/tomcat/tc8.5.x/trunk/webapps/docs/config/context.xml?rev=1744377&r1=1744376&r2=1744377&view=diff
==============================================================================
--- tomcat/tc8.5.x/trunk/webapps/docs/config/context.xml (original)
+++ tomcat/tc8.5.x/trunk/webapps/docs/config/context.xml Wed May 18 10:25:41
2016
@@ -677,7 +677,7 @@
appBase for its Host.</p>
</attribute>
- <attribute name="clearReferencesHttpClientKeepAliveThread" required =
"false">
+ <attribute name="clearReferencesHttpClientKeepAliveThread"
required="false">
<p>If <code>true</code> and an <code>sun.net.www.http.HttpClient</code>
keep-alive timer thread has been started by this web application and is
still running, Tomcat will change the context class loader for that
@@ -688,7 +688,17 @@
not specified, the default value of <code>true</code> will be used.</p>
</attribute>
- <attribute name="clearReferencesStatic" required = "false">
+ <attribute name="clearReferencesRmiTargets" required="false">
+ <p>If <code>true</code>, Tomcat looks for memory leaks associated with
+ RMI Targets and clears any it finds. This feature uses reflection to
+ identify the leaks and therefore requires that the command line option
+ <code>-XaddExports:java.rmi/sun.rmi.transport=ALL-UNNAMED</code> is set
+ when running on Java 9 and above. Applications without memory leaks
+ should operate correctly with this attribute set to <code>false</code>.
+ If not specified, the default value of <code>true</code> will be
used.</p>
+ </attribute>
+
+ <attribute name="clearReferencesStatic" required="false">
<p>If <code>true</code>, Tomcat attempts to null out any static or
final
fields from loaded classes when a web application is stopped as a work
around for apparent garbage collection bugs and application coding
@@ -699,7 +709,7 @@
<code>false</code> will be used.</p>
</attribute>
- <attribute name="clearReferencesStopThreads" required = "false">
+ <attribute name="clearReferencesStopThreads" required="false">
<p>If <code>true</code>, Tomcat attempts to terminate threads that have
been started by the web application. Stopping threads is performed via
the deprecated (for good reason) <code>Thread.stop()</code> method and
@@ -712,7 +722,7 @@
<code>Thread.stop()</code> is called on any remaining threads.</p>
</attribute>
- <attribute name="clearReferencesStopTimerThreads" required = "false">
+ <attribute name="clearReferencesStopTimerThreads" required="false">
<p>If <code>true</code>, Tomcat attempts to terminate
<code>java.util.Timer</code> threads that have been started by the web
application. Unlike standard threads, timer threads can be stopped
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]