Return-Path: Delivered-To: apmail-jakarta-taglibs-dev-archive@www.apache.org Received: (qmail 17112 invoked from network); 27 Feb 2005 18:50:58 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 27 Feb 2005 18:50:58 -0000 Received: (qmail 75806 invoked by uid 500); 27 Feb 2005 18:50:57 -0000 Delivered-To: apmail-jakarta-taglibs-dev-archive@jakarta.apache.org Received: (qmail 75792 invoked by uid 500); 27 Feb 2005 18:50:57 -0000 Mailing-List: contact taglibs-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Tag Libraries Developers List" Reply-To: "Tag Libraries Developers List" Delivered-To: mailing list taglibs-dev@jakarta.apache.org Received: (qmail 75778 invoked by uid 99); 27 Feb 2005 18:50:57 -0000 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_HELO_PASS X-Spam-Check-By: apache.org Received-SPF: neutral (hermes.apache.org: local policy) Received: from ms-smtp-04.nyroc.rr.com (HELO ms-smtp-04.nyroc.rr.com) (24.24.2.58) by apache.org (qpsmtpd/0.28) with ESMTP; Sun, 27 Feb 2005 10:50:55 -0800 Received: from [192.168.1.101] (cpe-24-93-18-210.rochester.res.rr.com [24.93.18.210]) by ms-smtp-04.nyroc.rr.com (8.12.10/8.12.10) with ESMTP id j1RIonpl017040; Sun, 27 Feb 2005 13:50:50 -0500 (EST) Message-ID: <42221681.1000402@dotech.com> Date: Sun, 27 Feb 2005 13:50:41 -0500 From: Kris Schneider User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Tag Libraries Developers List Subject: Re: Memory Leak in ELEvaluator (cont'd...) References: <00ff01c51b76$e5010f70$3510a8c0@Toronto.date.com> In-Reply-To: <00ff01c51b76$e5010f70$3510a8c0@Toronto.date.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Symantec AntiVirus Scan Engine X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N 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(""); ps.println(""); ps.println("Generated"); ps.println("
    "); long time = System.currentTimeMillis(); for (int i = 0; i < 100; i++) { long value = time + i; String var = "v_" + value; ps.print("
  • "); ps.print(""); ps.print(""); ps.println("
  • "); } ps.println("
"); } 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); %> EL Cache Test

Number cached expr strings: <%= cachedExpressionStrings.size() %>

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: > >

EL Cache Test

>

EL Cache Size: <%=ELEvaluator.getELCacheSize()%>

> > > 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(""); >> ps.println(">URL=elcache.jsp\">"); >> ps.println("Generated"); >> ps.println("
    "); >> >> long time = System.currentTimeMillis(); >> for (int i = 0; i < 100; i++) { >> long value = time + i; >> String var = "v_" + value; >> ps.print("
  • "); >> ps.print(""); >> ps.print(""); >> ps.println("
  • "); >> } >> >> ps.println("
"); >>} catch (FileNotFoundException exc) { >> exc.printStackTrace(); >>} finally { >> if (ps != null) { >> ps.close(); >> } >>} >>%> >> >> >> >> >> >> EL Cache Test >> >> >> >>

EL Cache Test

>> >> >> >> >>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 >>D.O.Tech -- Kris Schneider D.O.Tech --------------------------------------------------------------------- To unsubscribe, e-mail: taglibs-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: taglibs-dev-help@jakarta.apache.org