You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-dev@jakarta.apache.org by Daryl Beattie <da...@date.com> on 2005/05/12 23:14:12 UTC
RE: Memory Leak in ELEvaluator (cont'd...)
Hi folks,
Did anybody ever follow up with this?
For what it's worth, I've been using JSTL 1.1 for a while now
and have noticed no leak. Honestly I haven't profiled anything to be
sure, but I think it's safe enough to close the bug as it no longer
applies to the JSTL 1.1+ -- or maybe mark it as "WON'T FIX" for version
1.0?
Sincerely,
Daryl.
> -----Original Message-----
> From: Kris Schneider [mailto:kris@dotech.com]
> Sent: Sunday, February 27, 2005 1:51 PM
> To: Tag Libraries Developers List
> Subject: Re: Memory Leak in ELEvaluator (cont'd...)
>
>
> Or just use the setAccessible hack:
>
> elcache.jsp:
> ------------
> <%@ page import="java.io.*" %>
> <%@ page import="java.lang.reflect.*" %>
> <%@ page import="java.util.*" %>
> <%@ page import="org.apache.taglibs.standard.lang.jstl.*" %>
> <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
>
> <%
> String genPath =
> pageContext.getServletContext().getRealPath("/generated.jsp");
> PrintStream ps = null;
> try {
> ps = new PrintStream(new BufferedOutputStream(new
> FileOutputStream(genPath, false), 4096));
>
> ps.println("<%" + "@ taglib prefix=\"c\"
> uri=\"http://java.sun.com/jstl/core\" %\>");
> ps.println("<html><head>");
> ps.println("<meta http-equiv=\"refresh\" content=\"3;
> URL=elcache.jsp\">");
> ps.println("<title>Generated</title>");
> ps.println("</head><body><ul>");
>
> long time = System.currentTimeMillis();
> for (int i = 0; i < 100; i++) {
> long value = time + i;
> String var = "v_" + value;
> ps.print("<li>");
> ps.print("<c:set var='" + var + "' value='${" +
> value + "}'/>");
> ps.print("<c:out value='${pageScope." + var + "}'/>");
> ps.println("</li>");
> }
>
> ps.println("</ul></body></html>");
> } catch (FileNotFoundException exc) {
> exc.printStackTrace();
> } finally {
> if (ps != null) {
> ps.close();
> }
> }
>
> Field cachedExpressionStringsField =
> ELEvaluator.class.getDeclaredField("sCachedExpressionStrings");
> cachedExpressionStringsField.setAccessible(true);
> Map cachedExpressionStrings =
> (Map)cachedExpressionStringsField.get(ELEvaluator.class);
> %>
>
> <html>
>
> <head>
> <meta http-equiv="refresh" content="3; URL=generated.jsp">
> <title>EL Cache Test</title>
> </head>
>
> <body>
> <p>Number cached expr strings: <%=
> cachedExpressionStrings.size()
> %></p>
> </body>
>
> </html>
>
> It should increase by 200 each time elcache.jsp is accessed.
> The reason for
> the non-zero refresh is that a newly generated.jsp only seemed to be
> recognized for every request by introducing a slight delay. I ran TC
> 4.1.31's Jasper in dev mode so it would check for mods on
> every request as
> well as setting it not to fork compiles. Of course, JSP
> compilation could
> still be performed in a background thread within the same
> JVM, which might
> explain why the delay was required...
>
> Daryl Beattie wrote:
> > Yeah, that's basically it! Dunno why I never thought of using a
> > scriptlet instead of writing a custom tag... It's probably because
> > scriptlets are so frowned-upon where I currently work that
> I hardly ever
> > consider using them.
> >
> > One thing I did in one of my tests was actually to print
> out the size of
> > the cache in the JSP. So as my JSP refreshed every second,
> I could watch
> > the size of the cache climb. This, of course, requires a change to
> > ELEvaluator.java so that the size of the cache is publicly
> visible --
> > perhaps by adding a "getCacheSize()" method.
> >
> > Although I don't like to have my test JSPs actually display
> their own
> > results, the problem with this kind of test is that it
> can't be easily
> > converted to a "unit" test; it's results are somewhat subjective.
> > Because of that, I found that adding the cache size to the
> JSP eased my
> > results.
> >
> > By adding this to ELEvaluator.java:
> > public static int getELCacheSize() {
> > return ELEvaluator.sCachedExpressionStrings.size();
> > }
> >
> > You can then change the body of the JSP to:
> > <body>
> > <p>EL Cache Test</p>
> > <p>EL Cache Size: <%=ELEvaluator.getELCacheSize()%></p>
> > </body>
> >
> > Then you just load the JSP and watch it climb; if it climbs
> > indefinitely, you've got a bug in the cache. If it climbs to a fixed
> > size and stops there's no bug. ...And I would personally
> put the refresh
> > delay down to 0 just so that the cache is filled up
> faster... cuz I'm
> > impatient. :)
> >
> > - Daryl Beattie
> >
> >
> >
> >>-----Original Message-----
> >>From: Kris Schneider [mailto:kris@dotech.com]
> >>Sent: Friday, February 25, 2005 1:57 PM
> >>To: Tag Libraries Developers List
> >>Subject: Re: Memory Leak in ELEvaluator (cont'd...)
> >>
> >>
> >>Here's an approach to dynamically generating unique
> >>expressions that might work as a test.
> >>
> >>elcache.jsp:
> >>------------
> >><%@ page import="java.io.*" %>
> >><%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
> >>
> >><%
> >>String genPath =
> >>pageContext.getServletContext().getRealPath("/generated.jsp");
> >>PrintStream ps = null;
> >>try {
> >> ps = new PrintStream(new BufferedOutputStream(new
> >>FileOutputStream(genPath, false), 4096));
> >>
> >> ps.println("<%" + "@ taglib prefix=\"c\"
> >>uri=\"http://java.sun.com/jstl/core\" %\>");
> >> ps.println("<html><head>");
> >> ps.println("<meta http-equiv=\"refresh\" content=\"3;
> >>URL=elcache.jsp\">");
> >> ps.println("<title>Generated</title>");
> >> ps.println("</head><body><ul>");
> >>
> >> long time = System.currentTimeMillis();
> >> for (int i = 0; i < 100; i++) {
> >> long value = time + i;
> >> String var = "v_" + value;
> >> ps.print("<li>");
> >> ps.print("<c:set var='" + var + "' value='${" + value
> >>+ "}'/>");
> >> ps.print("<c:out value='${pageScope." + var + "}'/>");
> >> ps.println("</li>");
> >> }
> >>
> >> ps.println("</ul></body></html>");
> >>} catch (FileNotFoundException exc) {
> >> exc.printStackTrace();
> >>} finally {
> >> if (ps != null) {
> >> ps.close();
> >> }
> >>}
> >>%>
> >>
> >><html>
> >>
> >> <head>
> >> <meta http-equiv="refresh" content="3; URL=generated.jsp">
> >> <title>EL Cache Test</title>
> >> </head>
> >>
> >> <body>
> >> <p>EL Cache Test</p>
> >> </body>
> >>
> >></html>
> >>
> >>If you drop this into TC's $CATALINA_HOME/webapps/ROOT and
> >>add the JSTL libs to $CATALINA_HOME/webapps/ROOT/WEB-INF/lib,
> >>it should do what you want. I tested this with TC 4.1.31 and
> >>Standard 1.0.6, but didn't do any sort of profiling. If you
> >>don't see the output from generated.jsp change for each
> >>request, try increasing the refresh interval.
> >>
> >>--
> >>Kris Schneider <ma...@dotech.com>
> >>D.O.Tech <http://www.dotech.com/>
>
> --
> Kris Schneider <ma...@dotech.com>
> D.O.Tech <http://www.dotech.com/>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: taglibs-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: taglibs-dev-help@jakarta.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-dev-help@jakarta.apache.org