remm 02/03/30 01:36:30 Modified: jasper2/src/share/org/apache/jasper JspEngineContext.java jasper2/src/share/org/apache/jasper/compiler Compiler.java JspCompiler.java jasper2/src/share/org/apache/jasper/servlet JspServlet.java Log: - Add some (experimental) runtime optimizations. - Avoid uneeded file access, as well as try to reuse some objects between requests. - Remove the debug logs which were in the critical path. Revision Changes Path 1.2 +9 -3 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/JspEngineContext.java Index: JspEngineContext.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/JspEngineContext.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- JspEngineContext.java 28 Mar 2002 18:46:15 -0000 1.1 +++ JspEngineContext.java 30 Mar 2002 09:36:29 -0000 1.2 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/JspEngineContext.java,v 1.1 2002/03/28 18:46:15 kinman Exp $ - * $Revision: 1.1 $ - * $Date: 2002/03/28 18:46:15 $ + * $Header: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/JspEngineContext.java,v 1.2 2002/03/30 09:36:29 remm Exp $ + * $Revision: 1.2 $ + * $Date: 2002/03/30 09:36:29 $ * * ==================================================================== * @@ -98,6 +98,7 @@ ServletWriter writer; ServletContext context; URLClassLoader loader; + Compiler jspCompiler; String classpath; // for compiling JSPs. boolean isErrPage; String jspFile; @@ -305,6 +306,10 @@ * SunJavaCompiler is used. */ public Compiler createCompiler() throws JasperException { + + if (jspCompiler != null) + return jspCompiler; + String compilerPath = options.getJspCompilerPath(); Class jspCompilerPlugin = options.getJspCompilerPlugin(); JavaCompiler javac; @@ -325,10 +330,11 @@ if (compilerPath != null) javac.setCompilerPath(compilerPath); - Compiler jspCompiler = new JspCompiler(this); + jspCompiler = new JspCompiler(this); jspCompiler.setJavaCompiler(javac); return jspCompiler; + } /** 1.2 +3 -6 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Compiler.java Index: Compiler.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Compiler.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- Compiler.java 28 Mar 2002 18:46:15 -0000 1.1 +++ Compiler.java 30 Mar 2002 09:36:30 -0000 1.2 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Compiler.java,v 1.1 2002/03/28 18:46:15 kinman Exp $ - * $Revision: 1.1 $ - * $Date: 2002/03/28 18:46:15 $ + * $Header: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Compiler.java,v 1.2 2002/03/30 09:36:30 remm Exp $ + * $Revision: 1.2 $ + * $Date: 2002/03/30 09:36:30 $ * * ==================================================================== * @@ -110,9 +110,6 @@ String className = mangler.getClassName(); ctxt.setServletClassName(className); - Constants.message("jsp.message.class_name_is", - new Object[] { className }, - Logger.DEBUG); if (!isOutDated()) return false; 1.2 +10 -0 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/JspCompiler.java Index: JspCompiler.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/JspCompiler.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- JspCompiler.java 28 Mar 2002 18:46:15 -0000 1.1 +++ JspCompiler.java 30 Mar 2002 09:36:30 -0000 1.2 @@ -88,6 +88,8 @@ // ClassFileData cfd; boolean outDated; + long lastChecked = -1; + Logger.Helper loghelper = new Logger.Helper("JASPER_LOG", "JspCompiler"); public JspCompiler(JspCompilationContext ctxt) throws JasperException { @@ -173,6 +175,13 @@ * from whence it came */ public boolean isOutDated() { + + long time = System.currentTimeMillis(); + if (time < lastChecked) + return false; + + lastChecked = time + 2000; + long jspRealLastModified = 0; try { @@ -193,6 +202,7 @@ } return outDated; + } } 1.2 +55 -32 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/servlet/JspServlet.java Index: JspServlet.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/servlet/JspServlet.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- JspServlet.java 28 Mar 2002 18:46:20 -0000 1.1 +++ JspServlet.java 30 Mar 2002 09:36:30 -0000 1.2 @@ -112,6 +112,7 @@ * * @author Anil K. Vijendran * @author Harish Prabandham + * @author Remy Maucherat */ public class JspServlet extends HttpServlet { @@ -124,13 +125,36 @@ // ServletWrapper will set this Class servletClass; URLClassLoader loader = null; + JspCompilationContext ctxt = null; + String outDir = null; JspServletWrapper(String jspUri, boolean isErrorPage) { this.jspUri = jspUri; this.isErrorPage = isErrorPage; this.theServlet = null; + createOutdir(); } + private void createOutdir() { + File outDir = null; + try { + URL outURL = options.getScratchDir().toURL(); + String outURI = outURL.toString(); + if( outURI.endsWith("/") ) + outURI = outURI + jspUri.substring(1,jspUri.lastIndexOf("/")+1); + else + outURI = outURI + jspUri.substring(0,jspUri.lastIndexOf("/")+1);; + outURL = new URL(outURI); + outDir = new File(outURL.getFile()); + if( !outDir.exists() ) { + outDir.mkdirs(); + } + this.outDir = outDir.toString() + File.separator; + } catch(Exception e) { + throw new IllegalStateException("No output directory: " + e.getMessage()); + } + } + private void load() throws JasperException, ServletException { try { // This is to maintain the original protocol. @@ -167,14 +191,7 @@ } else accordingto = "according to the Servlet Engine"; - Constants.message("jsp.message.cp_is", - new Object[] { - accordingto, - cp == null ? "" : cp - }, - Logger.INFORMATION); - - if (loadJSP(jspUri, cp, isErrorPage, req, res) + if (loadJSP(this, jspUri, cp, isErrorPage, req, res) || theServlet == null) { load(); } @@ -371,6 +388,12 @@ Throwable exception, boolean precompile) throws ServletException, IOException { + + // First check if the requested JSP page exists, to avoid creating + // unnecessary directories and files. + if (context.getResourceAsStream(jspUri) == null) + throw new FileNotFoundException(jspUri); + boolean isErrorPage = exception != null; JspServletWrapper wrapper = (JspServletWrapper) jsps.get(jspUri); @@ -514,36 +537,36 @@ boolean isErrorPage, HttpServletRequest req, HttpServletResponse res) throws JasperException, FileNotFoundException { - // First check if the requested JSP page exists, to avoid creating - // unnecessary directories and files. - if (context.getResourceAsStream(jspUri) == null) - throw new FileNotFoundException(jspUri); JspServletWrapper jsw=(JspServletWrapper) jsps.get(jspUri); if( jsw==null ) { throw new JasperException("Can't happen - JspServletWrapper=null"); } - File outDir = null; - try { - URL outURL = options.getScratchDir().toURL(); - String outURI = outURL.toString(); - if( outURI.endsWith("/") ) - outURI = outURI + jspUri.substring(1,jspUri.lastIndexOf("/")+1); - else - outURI = outURI + jspUri.substring(0,jspUri.lastIndexOf("/")+1);; - outURL = new URL(outURI); - outDir = new File(outURL.getFile()); - if( !outDir.exists() ) { - outDir.mkdirs(); - } - } catch(Exception e) { - throw new JasperException("No output directory: " + e.getMessage()); - } + return loadJSP(jsw, jspUri, classpath, isErrorPage, req, res); + + } + + + /* Check if we need to reload a JSP page. + * + * Side-effect: re-compile the JSP page. + * + * @param classpath explicitly set the JSP compilation path. + * @return true if JSP files is newer + */ + boolean loadJSP(JspServletWrapper jsw, String jspUri, String classpath, + boolean isErrorPage, HttpServletRequest req, HttpServletResponse res) + throws JasperException, FileNotFoundException + { + boolean firstTime = jsw.servletClass == null; - JspCompilationContext ctxt = new JspEngineContext(parentClassLoader, classpath, - context, jspUri, outDir.toString() + File.separator, - isErrorPage, options, - req, res); + if (jsw.ctxt == null) { + jsw.ctxt = new JspEngineContext + (parentClassLoader, classpath, context, jspUri, + jsw.outDir, isErrorPage, options, + req, res); + } + JspCompilationContext ctxt = jsw.ctxt; boolean outDated = false; Compiler compiler = ctxt.createCompiler();
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>