cvs commit: jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/runtime TagHandlerPool.java
kinman 2003/01/30 19:34:45 Modified:jasper2/src/share/org/apache/jasper/compiler Generator.java jasper2/src/share/org/apache/jasper/runtime TagHandlerPool.java Log: - Fixed 16572, caused by recent change in tag pooling. Make sure that tag pooling works for custom tags used in tag files also. Revision ChangesPath 1.158 +47 -26 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Generator.java Index: Generator.java === RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Generator.java,v retrieving revision 1.157 retrieving revision 1.158 diff -u -r1.157 -r1.158 --- Generator.java30 Jan 2003 20:30:51 - 1.157 +++ Generator.java31 Jan 2003 03:34:44 - 1.158 @@ -318,12 +318,41 @@ } /** + * Generates the _jspInit() method for instantiating the tag handler pools. + * For tag file, _jspInit has to be invoked manually, and the ServletConfig + * object explicitly passed. + */ +private void generateInit() { + +if (ctxt.isTagFile()) { +out.printil(private void _jspInit(ServletConfig config) {); + } + else { +out.printil(public void _jspInit() {); + } + +out.pushIndent(); +for (int i=0; itagHandlerPoolNames.size(); i++) { +out.printin((String) tagHandlerPoolNames.elementAt(i)); +out.print( = org.apache.jasper.runtime.TagHandlerPool.getTagHandlerPool(); +if (ctxt.isTagFile()) { +out.print(config); +} +else { +out.print(getServletConfig()); +} +out.println();); +} +out.popIndent(); +out.printil(}); +out.println(); +} + +/** * Generates the _jspDestroy() method which is responsible for calling the * release() method on every tag handler in any of the tag handler pools. */ private void generateDestroy() { - if (tagHandlerPoolNames.size() = 0) - return; out.printil(public void _jspDestroy() {); out.pushIndent(); @@ -415,12 +444,6 @@ } out.println(); } - - // Constructor - if (ctxt.getOptions().isPoolingEnabled() - !tagHandlerPoolNames.isEmpty()) { - generateConstructor(className); - } } /** @@ -440,6 +463,7 @@ if (ctxt.getOptions().isPoolingEnabled() !tagHandlerPoolNames.isEmpty()) { + generateInit(); generateDestroy(); } } @@ -484,6 +508,9 @@ // Class variable declarations genPreambleClassVariableDeclarations( servletClassName ); + // Constructor +// generateConstructor(className); + // Methods here genPreambleMethods(); @@ -663,19 +690,6 @@ out.printil(public + className + () {); out.printil(}); out.println(); - -out.printil(public void _jspInit() {); -out.pushIndent(); -for (int i=0; itagHandlerPoolNames.size(); i++) { -out.printin((String) tagHandlerPoolNames.elementAt(i)); -out.print( = org.apache.jasper.runtime.TagHandlerPool.getTagHandlerPool(); -out.print(this); -out.println();); -} -out.popIndent(); -out.printil(}); -out.println(); - } /** @@ -2971,7 +2985,7 @@ gen.fragmentHelperClass, gen.ctxt.getClassLoader(), tagInfo)); - gen.generateTagHandlerPostamble( tagInfo ); + gen.generateTagHandlerPostamble(tagInfo); } else { gen.generatePreamble(page); gen.generateXmlDeclaration(page); @@ -3078,8 +3092,11 @@ pageContext.getServletContext(); ); out.printil(javax.servlet.ServletConfig config = + pageContext.getServletConfig();); - out.printil(javax.servlet.jsp.JspWriter out = jspContext.getOut();); + if (ctxt.getOptions().isPoolingEnabled() + !tagHandlerPoolNames.isEmpty()) { + out.printil(_jspInit(config);); + } generatePageScopedVariables(tagInfo); // Number of tag object that need to be popped @@ -3111,6 +3128,10 @@ out.printil( } finally { ); out.pushIndent(); out.printil(((org.apache.jasper.runtime.JspContextWrapper) jspContext).syncEndTagFile();); + if (ctxt.getOptions().isPoolingEnabled() + !tagHandlerPoolNames.isEmpty())
cvs commit: jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/runtime TagHandlerPool.java
costin 2003/01/22 11:54:25 Modified:jasper2/src/share/org/apache/jasper/runtime TagHandlerPool.java Log: Few small optimizations ( take expensive operations out of sync ). Added a factory method and a mechanism to configure individual jsps at _runtime_. Some JSPs may have more tags or be more frequently used, one size won't fit all. It uses servlet and context init params. Revision ChangesPath 1.4 +73 -22 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/runtime/TagHandlerPool.java Index: TagHandlerPool.java === RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/runtime/TagHandlerPool.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- TagHandlerPool.java 16 Nov 2002 04:20:10 - 1.3 +++ TagHandlerPool.java 22 Jan 2003 19:54:24 - 1.4 @@ -63,6 +63,7 @@ import javax.servlet.jsp.JspException; import javax.servlet.jsp.tagext.Tag; +import javax.servlet.Servlet; import org.apache.jasper.Constants; /** @@ -74,20 +75,55 @@ private Tag[] handlers; +public static String OPTION_TAGPOOL=jasper.tagpoolClassName; +public static String OPTION_MAXSIZE=jasper.tagpoolMaxSize; + // index of next available tag handler private int current; +public static TagHandlerPool getTagHandlerPool( Servlet jspServlet) { +TagHandlerPool result=null; + +String tpClassName=getOption( jspServlet, OPTION_TAGPOOL, null); +if( tpClassName != null ) { +try { +Class c=Class.forName( tpClassName ); +result=(TagHandlerPool)c.newInstance(); +} catch (Exception e) { +e.printStackTrace(); +result=null; +} +} +if( result==null ) result=new TagHandlerPool(); +result.init(jspServlet); + +return result; +} + +protected void init( Servlet servlet ) { +int maxSize=-1; +String maxSizeS=getOption(servlet, OPTION_MAXSIZE, null); +maxSize=Integer.parseInt(maxSizeS); +if( maxSize 0 ) { +maxSize=Constants.MAX_POOL_SIZE; +} +this.handlers = new Tag[maxSize]; +this.current = -1; +} + /** * Constructs a tag handler pool with the default capacity. */ public TagHandlerPool() { - this(Constants.MAX_POOL_SIZE); + // Nothing - jasper generated servlets call the other constructor, +// this should be used in future + init . } /** * Constructs a tag handler pool with the given capacity. * * @param capacity Tag handler pool capacity + * @deprecated Use static getTagHandlerPool */ public TagHandlerPool(int capacity) { this.handlers = new Tag[capacity]; @@ -104,20 +140,22 @@ * * @throws JspException if a tag handler cannot be instantiated */ -public synchronized Tag get(Class handlerClass) throws JspException { +public Tag get(Class handlerClass) throws JspException { Tag handler = null; - - if (current = 0) { - handler = handlers[current--]; - } else { - try { - return (Tag) handlerClass.newInstance(); - } catch (Exception e) { - throw new JspException(e.getMessage(), e); - } - } - - return handler; +synchronized( this ) { +if (current = 0) { +handler = handlers[current--]; +return handler; +} +} + +// Out of sync block - there is no need for other threads to +// wait for us to construct a tag for this thread. +try { +return (Tag) handlerClass.newInstance(); +} catch (Exception e) { +throw new JspException(e.getMessage(), e); +} } /** @@ -127,11 +165,15 @@ * * @param handler Tag handler to add to this tag handler pool */ -public synchronized void reuse(Tag handler) { - if (current (handlers.length - 1)) - handlers[++current] = handler; - else - handler.release(); +public void reuse(Tag handler) { +synchronized( this ) { +if (current (handlers.length - 1)) { +handlers[++current] = handler; +return; +} +} +// There is no need for other threads to wait for us to release +handler.release(); } /** @@ -143,5 +185,14 @@ handlers[i].release(); } } + +protected static String getOption( Servlet servlet,
cvs commit: jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/runtime TagHandlerPool.java
costin 2003/01/22 11:58:45 Modified:jasper2/src/share/org/apache/jasper/runtime TagHandlerPool.java Log: Strange - getServletConfig() returns null. Revision ChangesPath 1.5 +5 -0 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/runtime/TagHandlerPool.java Index: TagHandlerPool.java === RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/runtime/TagHandlerPool.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- TagHandlerPool.java 22 Jan 2003 19:54:24 - 1.4 +++ TagHandlerPool.java 22 Jan 2003 19:58:44 - 1.5 @@ -187,8 +187,13 @@ } protected static String getOption( Servlet servlet, String name, String defaultV) { +if( servlet==null ) return defaultV; +if( servlet.getServletConfig() == null ) return defaultV; + String value=servlet.getServletConfig().getInitParameter(name); if( value != null ) return value; +if( servlet.getServletConfig().getServletContext() ==null ) +return defaultV; value=servlet.getServletConfig().getServletContext().getInitParameter(name); if( value!=null ) return value; return defaultV; -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
Re: cvs commit: jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/runtime TagHandlerPool.java
[EMAIL PROTECTED] wrote: costin 2003/01/22 11:58:45 Modified:jasper2/src/share/org/apache/jasper/runtime TagHandlerPool.java Log: Strange - getServletConfig() returns null. Need help.. This happens because TagHandlerPools are created in the constructor. How can I move that to init, where SerlvetConfig is available ? Should it generate a init() method that calls super and initializes the tag pools ? I would also like to add an option to do no pooling if maxSize is 0 ( just fast return, with now sync ). Costin -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
cvs commit: jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/runtime TagHandlerPool.java
costin 2003/01/22 12:43:07 Modified:jasper2/src/share/org/apache/jasper/runtime TagHandlerPool.java Log: Another fix. I found how to do the init. Revision ChangesPath 1.6 +17 -11 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/runtime/TagHandlerPool.java Index: TagHandlerPool.java === RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/runtime/TagHandlerPool.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- TagHandlerPool.java 22 Jan 2003 19:58:44 - 1.5 +++ TagHandlerPool.java 22 Jan 2003 20:43:06 - 1.6 @@ -4,10 +4,10 @@ * $Date$ * * - * + * * The Apache Software License, Version 1.1 * - * Copyright (c) 1999 The Apache Software Foundation. All rights + * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -15,7 +15,7 @@ * are met: * * 1. Redistributions of source code must retain the above copyright - *notice, this list of conditions and the following disclaimer. + *notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright *notice, this list of conditions and the following disclaimer in @@ -23,15 +23,15 @@ *distribution. * * 3. The end-user documentation included with the redistribution, if - *any, must include the following acknowlegement: - * This product includes software developed by the + *any, must include the following acknowlegement: + * This product includes software developed by the *Apache Software Foundation (http://www.apache.org/). *Alternately, this acknowlegement may appear in the software itself, *if and wherever such third-party acknowlegements normally appear. * * 4. The names The Jakarta Project, Tomcat, and Apache Software *Foundation must not be used to endorse or promote products derived - *from this software without prior written permission. For written + *from this software without prior written permission. For written *permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called Apache @@ -57,7 +57,7 @@ * information on the Apache Software Foundation, please see * http://www.apache.org/. * - */ + */ package org.apache.jasper.runtime; @@ -103,7 +103,13 @@ protected void init( Servlet servlet ) { int maxSize=-1; String maxSizeS=getOption(servlet, OPTION_MAXSIZE, null); -maxSize=Integer.parseInt(maxSizeS); +if( maxSizeS != null ) { +try { +maxSize=Integer.parseInt(maxSizeS); +} catch( Exception ex) { +maxSize=-1; +} +} if( maxSize 0 ) { maxSize=Constants.MAX_POOL_SIZE; } -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
cvs commit: jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/runtime TagHandlerPool.java
luehe 2002/11/15 20:20:10 Modified:jasper2/src/share/org/apache/jasper Constants.java EmbededServletOptions.java JspC.java Options.java jasper2/src/share/org/apache/jasper/compiler Generator.java ServletWriter.java jasper2/src/share/org/apache/jasper/resources messages.properties jasper2/src/share/org/apache/jasper/runtime TagHandlerPool.java Log: Added init param to configure tag pool size. Revision ChangesPath 1.9 +7 -0 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/Constants.java Index: Constants.java === RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/Constants.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- Constants.java20 Sep 2002 18:06:38 - 1.8 +++ Constants.java16 Nov 2002 04:20:09 - 1.9 @@ -138,6 +138,13 @@ public static final int DEFAULT_TAG_BUFFER_SIZE = 512; /** + * Default tag handler pool size. + */ +public static final int MAX_POOL_SIZE = 5; +public static final Integer MAX_POOL_SIZE_INTEGER + = new Integer(MAX_POOL_SIZE); + +/** * The query parameter that causes the JSP engine to just * pregenerated the servlet but not invoke it. */ 1.12 +42 -10 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/EmbededServletOptions.java Index: EmbededServletOptions.java === RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/EmbededServletOptions.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- EmbededServletOptions.java22 Oct 2002 22:23:14 - 1.11 +++ EmbededServletOptions.java16 Nov 2002 04:20:09 - 1.12 @@ -105,7 +105,12 @@ /** * Determines whether tag handler pooling is enabled. */ -private boolean poolingEnabled = true; +private boolean isPoolingEnabled = true; + + /** + * Tag handler pool size. + */ +private int tagPoolSize; /** * Do you want support for mapped files? This will generate @@ -198,7 +203,14 @@ } public boolean isPoolingEnabled() { - return poolingEnabled; + return isPoolingEnabled; +} + +/** + * Returns the tag handler pool size. + */ +public int getTagPoolSize() { + return tagPoolSize; } /** @@ -293,12 +305,15 @@ * Create an EmbededServletOptions object using data available from * ServletConfig and ServletContext. */ -public EmbededServletOptions(ServletConfig config, ServletContext context) { +public EmbededServletOptions(ServletConfig config, + ServletContext context) { + + this.tagPoolSize = Constants.MAX_POOL_SIZE; + Enumeration enum=config.getInitParameterNames(); while( enum.hasMoreElements() ) { String k=(String)enum.nextElement(); String v=config.getInitParameter( k ); - setProperty( k, v); } @@ -325,17 +340,34 @@ else Constants.message (jsp.warning.largeFile, Logger.WARNING); } - poolingEnabled = true; + this.isPoolingEnabled = true; String poolingEnabledParam = config.getInitParameter(enablePooling); if (poolingEnabledParam != null !poolingEnabledParam.equalsIgnoreCase(true)) { if (poolingEnabledParam.equalsIgnoreCase(false)) -this.poolingEnabled = false; +this.isPoolingEnabled = false; else Constants.message(jsp.warning.enablePooling, Logger.WARNING); } +String tagPoolSizeParam = config.getInitParameter(tagPoolSize); +if (tagPoolSizeParam != null) { +try { +this.tagPoolSize = Integer.parseInt(tagPoolSizeParam); +if (this.tagPoolSize = 0) { +this.tagPoolSize = Constants.MAX_POOL_SIZE; +Constants.message(jsp.warning.invalidTagPoolSize, + new Object[] { Constants.MAX_POOL_SIZE_INTEGER }, + Logger.WARNING); +} +} catch(NumberFormatException ex) { +Constants.message(jsp.warning.invalidTagPoolSize, + new Object[] { Constants.MAX_POOL_SIZE_INTEGER }, + Logger.WARNING); +} +
cvs commit: jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/runtime TagHandlerPool.java
luehe 2002/07/26 16:21:39 Modified:jasper2/src/share/org/apache/jasper/runtime TagHandlerPool.java Log: Added Header, Revision, and Date CVS keywords Revision ChangesPath 1.2 +6 -0 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/runtime/TagHandlerPool.java Index: TagHandlerPool.java === RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/runtime/TagHandlerPool.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- TagHandlerPool.java 8 Jun 2002 00:16:45 - 1.1 +++ TagHandlerPool.java 26 Jul 2002 23:21:39 - 1.2 @@ -1,4 +1,10 @@ /* + * $Header$ + * $Revision$ + * $Date$ + * + * + * * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation. All rights -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
cvs commit: jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/runtime TagHandlerPool.java
kinman 2002/06/07 17:16:45 Added: jasper2/src/share/org/apache/jasper/runtime TagHandlerPool.java Log: - Added a new runtime class. Patch by Jan Luehe. Revision ChangesPath 1.1 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/runtime/TagHandlerPool.java Index: TagHandlerPool.java === /* * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright *notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright *notice, this list of conditions and the following disclaimer in *the documentation and/or other materials provided with the *distribution. * * 3. The end-user documentation included with the redistribution, if *any, must include the following acknowlegement: * This product includes software developed by the *Apache Software Foundation (http://www.apache.org/). *Alternately, this acknowlegement may appear in the software itself, *if and wherever such third-party acknowlegements normally appear. * * 4. The names The Jakarta Project, Tomcat, and Apache Software *Foundation must not be used to endorse or promote products derived *from this software without prior written permission. For written *permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called Apache *nor may Apache appear in their names without prior written *permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * http://www.apache.org/. * */ package org.apache.jasper.runtime; import javax.servlet.jsp.JspException; import javax.servlet.jsp.tagext.Tag; /** * Pool of tag handlers that can be reused. * * @author Jan Luehe */ public class TagHandlerPool { private static final int MAX_POOL_SIZE = 5; private Tag[] handlers; // index of next available tag handler private int current; /** * Constructs a tag handler pool with the default capacity. */ public TagHandlerPool() { this(MAX_POOL_SIZE); } /** * Constructs a tag handler pool with the given capacity. * * @param capacity Tag handler pool capacity */ public TagHandlerPool(int capacity) { this.handlers = new Tag[capacity]; this.current = -1; } /** * Gets the next available tag handler from this tag handler pool, * instantiating one if this tag handler pool is empty. * * @param handlerClass Tag handler class * * @return Reused or newly instantiated tag handler * * @throws JspException if a tag handler cannot be instantiated */ public synchronized Tag get(Class handlerClass) throws JspException { Tag handler = null; if (current = 0) { handler = handlers[current--]; } else { try { return (Tag) handlerClass.newInstance(); } catch (Exception e) { throw new JspException(e.getMessage(), e); } } return handler; } /** * Adds the given tag handler to this tag handler pool, unless this tag * handler pool has already reached its capacity, in which case the tag * handler's release() method is called. * * @param handler Tag handler to