Author: remy.maucherat(a)jboss.com
Date: 2009-10-22 11:14:14 -0400 (Thu, 22 Oct 2009)
New Revision: 1221
Added:
trunk/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java
Modified:
trunk/java/org/apache/jasper/compiler/Parser.java
Log:
- Port fix for 48019. Be more careful to skip over all of nodes we aren't interested
it.
- Add a listener to prevent leaks by preinitializing singletons.
Added: trunk/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java
===================================================================
--- trunk/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java
(rev 0)
+++ trunk/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java 2009-10-22
15:14:14 UTC (rev 1221)
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.catalina.core;
+
+import javax.imageio.ImageIO;
+
+import org.apache.catalina.Lifecycle;
+import org.apache.catalina.LifecycleEvent;
+import org.apache.catalina.LifecycleListener;
+
+/**
+ * Provide a workaround for known places where the Java Runtime environment uses
+ * the context class loader to load a singleton as this will cause a memory leak
+ * if a web application class loader happens to be the context class loader at
+ * the time. The work-around is to initialise these singletons when Tomcat's
+ * common class loader is the context class loader.
+ */
+public class JreMemoryLeakPreventionListener implements LifecycleListener {
+
+ @Override
+ public void lifecycleEvent(LifecycleEvent event) {
+ // Initialise these classes when Tomcat starts
+ if (Lifecycle.INIT_EVENT.equals(event.getType())) {
+ /*
+ * Several components end up calling:
+ * sun.awt.AppContext.getAppContext()
+ *
+ * Those libraries / components known to trigger memory leaks due to
+ * eventual calls to getAppContext() are:
+ *
+ * - Google Web Toolkit via its use of javax.imageio
+ * - Tomcat via its use of java.beans.Introspector.flushCaches() in
+ * 1.6.0_15 onwards
+ * - others TBD
+ */
+
+ // Trigger a call to sun.awt.AppContext.getAppContext(). This will
+ // pin the common class loader in memory but that shouldn't be an
+ // issue.
+ ImageIO.getCacheDirectory();
+
+ }
+ }
+
+}
Modified: trunk/java/org/apache/jasper/compiler/Parser.java
===================================================================
--- trunk/java/org/apache/jasper/compiler/Parser.java 2009-10-22 14:40:46 UTC (rev 1220)
+++ trunk/java/org/apache/jasper/compiler/Parser.java 2009-10-22 15:14:14 UTC (rev 1221)
@@ -1777,11 +1777,21 @@
while (reader.hasMoreInput()) {
start = reader.mark();
if (reader.matches("%--")) {
- parseComment(parent);
+ // Comment
+ reader.skipUntil("--%>");
} else if (reader.matches("%@")) {
parseDirective(parent);
} else if (reader.matches("jsp:directive.")) {
parseXMLDirective(parent);
+ } else if (reader.matches("%!")) {
+ // Declaration
+ reader.skipUntil("%>");
+ } else if (reader.matches("%=")) {
+ // Expression
+ reader.skipUntil("%>");
+ } else if (reader.matches("%")) {
+ // Scriptlet
+ reader.skipUntil("%>");
}
reader.skipUntil("<");
}