If you use the same tag (defined in a JSP 2.0 tag file) on two different JSPs, the tag-class will get loaded from two different classloaders resulting in two loaded classes in the perm gen space. You can trace this behaviour when starting the VM with the arguments "-XX:+TraceClassLoading -XX:+TraceClassUnloading". The classes get loaded multiple times even when development/reloading is disabled. This behaviour gets a problem if you have a huge number of JSPs (in our case >10.000) and a few tags used on every single JSP. I traced down the problem in the source code: For each JSP to compile, a new instance of a JspCompilationContext is used. The JspCompilationContext holds a reference to a JasperLoader (a ClassLoader), which initially is null (a new JasperLoader will be created when it is first used). The JspCompilationContext will not only load the JSP class, but also compiles and loads tag-files referenced within the JSP. As the JasperLoader loads all classes starting with "org.apache.jsp" by itself and does not delegate to it's parent, the tag class (which lies underneath this package) will get loaded via multiple JasperLoader instances. I perfectly understand that loading each JSP via a different classloader may be necessary, when reloading is enabled, but if reloading/development is disabled, the same JasperLoader instance could be used. This would prevent the tag class to get loaded multiple times. (I.e. a previously used JasperLoader instance could be passed to the JspCompilationContext, if running in production mode). By the way I think that loading the tag file via the same classloader as the JSP in a reloading-enviornmane may result in some strange behaviour: If two JSPs use the same tag and you change the tag as well as one JSP, you'll see the new version of the tag on the reloaded JSP, but the previous version of the same tag (but loaded via a different class-instance) on the unchanged JSP. But to solve this issue, some greater refactoring would be necessary, I think....
I have committed the following fix for this to trunk. http://svn.apache.org/viewvc?rev=607464&view=rev Feedback from any testing you could do would be much appreciated.
Hi Mark, thank you very much! We'll test the new version first thing in the new year and let you know the results. Have a good start into 2008, Philipp
Looking at it, my patch is clearly nonsense. I'm working on one that actually works...
Hi Mark, thanks for the heads-up - I´ll forward it to my colleagues to let them know that they don't need to start testing. Philipp
I have committed a better fix for this to trunk. Any testing results you can provide would be much appreciated. The fix has also been proposed for 6.0.x.
This patch has been sat in the proposals list for a few weeks and hasn't gathered much interest. Remy commented that the use case is very close to the pre-compilation one which likely explains why there isn't much support for the patch. On this basis I marking this bug as WONTFIX on the grounds pre-compilation achieves pretty much the same result. You are of course, free to use the patch in your own environment if it is useful to you. I have included a link to my improved patch for this below: http://svn.apache.org/viewvc?rev=616563&view=rev
*** Bug 55150 has been marked as a duplicate of this bug. ***