You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by "Korn, Christoph" <Ko...@ImmobilienScout24.de> on 2007/12/10 11:30:27 UTC

Memory leak with tagfiles - re-use JasperLoader?

Hello Tomcat (Jasper) developers,

in our project we have a serious memory problem (perm gen space) related
to JSP tag files: The class generated from the tag file gets loaded for
every JSP the tag is placed on. So if you put such a tag on i.e. 8000
JPSs, the tag class will seriously pollute the perm gen space. The
problem gets even worse, if you have a great number of tags used nearly
on every singe page. (You can trace class loading by starting the VM
with the options "-XX:+TraceClassLoading -XX:+TraceClassUnloading" and
see what I mean).

I traced down the problem in the Jasper sources and found out that even
though the container is configured not to re-load JSPs, a new instance
of a JspCompilationContext is used for every JSP. This
JspCompilationContext holds a reference to a JasperLoader (which is null
in the beginning and a new instance is created by the
JspCompilationContext on demand). Thus a new JasperLoader (=a new
ClassLoader) is used for every JSP. As tagfiles of tags placed on this
JSP get loaded via the same ClassLoader as the JSP, the class of the
same tag placed on different JSPs gets loaded via different
ClassLoaders.

There is no problem with Java-coded tags, as those get loaded by the
parent class loader and the JasperLoaders delegate to it's parent if the
class-name does not start with "org.apache.jsp".

I perfectly understand that loading each JSPs via a different
ClassLoader is necessary if you want to be able to reload the JSP-class,
but if the reloading-feature is turned off (development=false), I don't
see the need for a new ClassLoader for each JSP/tag.

It's the first time I took a look into the Tomcat sources and surely
I've missed an important point, so please excuse my silly question: But
wouldn't it be possible to re-use the ClassLoader if reloading is turned
off? I attached a simple (dirty hack) patch to illustrate what I mean.
(I don't think a static map is really a good idea here, but it a first
shot to show you what I mean)

I've already filed a bugreport for this some days ago:
http://issues.apache.org/bugzilla/show_bug.cgi?id=43878


christoph

AW: Memory leak with tagfiles - re-use JasperLoader?

Posted by "Korn, Christoph" <Ko...@ImmobilienScout24.de>.
> This is a hack. This may work great for you, and that's the 
> whole point of using OSS, but this is not a solution for 
> others.

Sure this is a dirty hack and I haven't tested it for more than five
minutes. As I have no deep understanding of the Tomcat code and what
side effects the patch might have, I don't want to propose this as a
fix.

I just wanted to start a discussion about this issue and see if you are
aware of this problem. Maybe this discussion may lead to a better
solution than my dirty hack.

Precompiling the JSPs may be a workaround. I'll try this out. Thanks.

christoph





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


Re: Memory leak with tagfiles - re-use JasperLoader?

Posted by Antonio Petrelli <an...@gmail.com>.
2007/12/10, Remy Maucherat <re...@apache.org>:
>
> This is a hack. This may work great for you, and that's the whole point
> of using OSS, but this is not a solution for others.



Here I disagree: at Struts we were discussing one big problem with JSP (that
depends on the specification, not the platform): JSP are not reachable
through the classpath.
This is one of the reasons because many people is moving from JSP to
FreeMarker and Velocity.
I know that this question is a lot different to the Christoph's one, but the
classloading case is similar. The patch is a hack and it should be taken as
it is, but probably a "pluggable" way of defining how to load JSP servlet
classes could be useful (in this case Jasper would be used outside of Tomcat
itself).

Antonio

Re: Memory leak with tagfiles - re-use JasperLoader?

Posted by Remy Maucherat <re...@apache.org>.
On Mon, 2007-12-10 at 11:30 +0100, Korn, Christoph wrote:
> I perfectly understand that loading each JSPs via a different
> ClassLoader is necessary if you want to be able to reload the JSP-class,
> but if the reloading-feature is turned off (development=false), I don't
> see the need for a new ClassLoader for each JSP/tag.
> 
> It's the first time I took a look into the Tomcat sources and surely
> I've missed an important point, so please excuse my silly question: But
> wouldn't it be possible to re-use the ClassLoader if reloading is turned
> off? I attached a simple (dirty hack) patch to illustrate what I mean.
> (I don't think a static map is really a good idea here, but it a first
> shot to show you what I mean)
> 
> I've already filed a bugreport for this some days ago:
> http://issues.apache.org/bugzilla/show_bug.cgi?id=43878

This is a hack. This may work great for you, and that's the whole point
of using OSS, but this is not a solution for others. Reloading is also
(efficiently) handled by a background thread.

BTW, you might want to look into the behavior when using precompilation
(JSPs are mapped and loaded as servlets).

Rémy



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