remm 2002/06/10 20:35:35
Modified: jasper2/src/share/org/apache/jasper/compiler Generator.java
jasper2/src/share/org/apache/jasper/runtime
PageContextImpl.java
Log:
- Take advantage of the fact that the PageContext is pooled.
- Modify the way the buffer reuse is done to conform with the PageContext
contract (basically, the code moves from the generated servlet to PageContext).
Revision Changes Path
1.24 +14 -47
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.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- Generator.java 10 Jun 2002 21:08:30 -0000 1.23
+++ Generator.java 11 Jun 2002 03:35:34 -0000 1.24
@@ -358,7 +358,7 @@
// Local variable declarations
out.printil("JspFactory _jspxFactory = null;");
- out.printil("org.apache.jasper.runtime.PageContextImpl pageContext = null;");
+ out.printil("javax.servlet.jsp.PageContext pageContext = null;");
if (pageInfo.isSession())
out.printil("HttpSession session = null;");
@@ -386,8 +386,7 @@
out.print (quote(pageInfo.getContentType()));
out.println(");");
- out.printil("pageContext = (org.apache.jasper.runtime.PageContextImpl)"
- + " _jspxFactory.getPageContext(this, request, response,");
+ out.printil("pageContext = _jspxFactory.getPageContext(this, request,
response,");
out.printin("\t\t\t");
out.print (quote(pageInfo.getErrorPage()));
out.print (", " + pageInfo.isSession());
@@ -432,17 +431,11 @@
out.pushIndent();
out.printil("public int tagCount;");
out.println();
- out.printil("public int tagDepth;");
- out.println();
- out.printil("public javax.servlet.jsp.tagext.BodyContent[] outs;");
- out.println();
out.printil("public JspWriter out;");
out.println();
out.printil("public JspxState() {");
out.pushIndent();
out.printil("tagCount = 0;");
- out.printil("tagDepth = -1;");
- out.printil("outs = new org.apache.jasper.runtime.BodyContentImpl[" +
(maxTagNesting) + "];");
out.popIndent();
out.printil("}");
out.popIndent();
@@ -1045,21 +1038,12 @@
out.print(parent);
out.print(", ");
}
- out.println("org.apache.jasper.runtime.PageContextImpl pageContext,
JspxState _jspxState)");
+ out.println("javax.servlet.jsp.PageContext pageContext, JspxState
_jspxState)");
out.printil(" throws Throwable {");
out.pushIndent();
// Initilaize local variables used in this method.
- out.printil("JspWriter out = null;");
- out.printil("if (_jspxState.tagDepth < 0) {");
- out.pushIndent();
- out.printil("out = _jspxState.out;");
- out.popIndent();
- out.printil("} else {");
- out.pushIndent();
- out.printil("out = _jspxState.outs[_jspxState.tagDepth];");
- out.popIndent();
- out.printil("}");
+ out.printil("JspWriter out = pageContext.getOut();");
if (n.isHasUsebean()) {
out.println("HttpSession session = pageContext.getSession();");
out.println("ServletContext application =
pageContext.getServletContext();");
@@ -1265,23 +1249,12 @@
if (!implementsTryCatchFinally) {
out.printil("_jspxState.tagCount++;");
}
- out.printil("_jspxState.tagDepth++;");
-
- out.printil("if (_jspxState.outs[_jspxState.tagDepth] == null)
{");
- out.pushIndent();
- out.printil("_jspxState.outs[_jspxState.tagDepth] = new
org.apache.jasper.runtime.BodyContentImpl(out);");
- out.popIndent();
- out.printil("} else {");
- out.pushIndent();
- out.printil("_jspxState.outs[_jspxState.tagDepth].clear();");
- out.popIndent();
- out.printil("}");
-
- out.printil("out = _jspxState.outs[_jspxState.tagDepth];");
- out.printil("pageContext.setOut(out);");
+ out.printil("javax.servlet.jsp.tagext.BodyContent _bc =
pageContext.pushBody();");
+ out.printil("_bc.clear();");
+ out.printil("out = _bc;");
out.printin(tagHandlerVar);
-
out.println(".setBodyContent(_jspxState.outs[_jspxState.tagDepth]);");
+ out.println(".setBodyContent(_bc);");
out.printin(tagHandlerVar);
out.println(".doInitBody();");
@@ -1339,9 +1312,7 @@
if (!implementsTryCatchFinally) {
out.printil("_jspxState.tagCount--;");
}
- out.printil("out =
_jspxState.outs[_jspxState.tagDepth].getEnclosingWriter();");
- out.printil("_jspxState.tagDepth--;");
- out.printil("pageContext.setOut(out);");
+ out.printil("out = pageContext.popBody();");
out.popIndent();
}
@@ -1591,16 +1562,12 @@
out.popIndent();
out.printil("if (pageContext != null) pageContext.handlePageException(t);");
+
out.popIndent();
out.printil("} finally {");
out.pushIndent();
- // Cleanup the tags on the stack
- if (maxTagNesting > 0) {
- out.printil("out = _jspxState.out;");
- out.printil("pageContext.setOut(out);");
- }
-
+ out.printil("out = _jspxState.out;");
out.printil("if (_jspxFactory != null)
_jspxFactory.releasePageContext(pageContext);");
out.popIndent();
1.9 +46 -34
jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/runtime/PageContextImpl.java
Index: PageContextImpl.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/runtime/PageContextImpl.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- PageContextImpl.java 10 Jun 2002 20:12:27 -0000 1.8
+++ PageContextImpl.java 11 Jun 2002 03:35:35 -0000 1.9
@@ -139,16 +139,18 @@
this.session = ((HttpServletRequest)request).getSession();
if (needsSession && session == null)
- throw new IllegalStateException("Page needs a session and none is
available");
+ throw new IllegalStateException
+ ("Page needs a session and none is available");
- // initialize the initial out ...
- // System.out.println("Initialize PageContextImpl " + out );
- if( out == null ) {
- out = _createOut(bufferSize, autoFlush); // throws
- } else {
- ((JspWriterImpl)out).init(response, bufferSize, autoFlush );
+ // initialize the initial out ...
+ depth = -1;
+ if (this.baseOut == null) {
+ this.baseOut = _createOut(bufferSize, autoFlush);
+ } else {
+ this.baseOut.init(response, bufferSize, autoFlush);
}
-
+ this.out = baseOut;
+
if (this.out == null)
throw new IllegalStateException("failed initialize JspWriter");
@@ -190,9 +192,9 @@
autoFlush = true;
request = null;
response = null;
- //out = null;
- if( out instanceof JspWriterImpl )
- ((JspWriterImpl)out).recycle();
+ depth = -1;
+ out = baseOut;
+ baseOut.recycle();
session = null;
attributes.clear();
@@ -428,21 +430,30 @@
}
}
- public void setOut(JspWriter newOut) {
- out = newOut;
- }
-
- Stack writerStack = new Stack();
+ protected BodyContent[] outs = new BodyContentImpl[0];
+ protected int depth = -1;
public BodyContent pushBody() {
- JspWriter previous = out;
- writerStack.push(out);
- out = new BodyContentImpl(previous);
- return (BodyContent) out;
+ depth++;
+ if (depth >= outs.length) {
+ BodyContent[] newOuts = new BodyContentImpl[depth + 1];
+ for (int i = 0; i < outs.length; i++) {
+ newOuts[i] = outs[i];
+ }
+ newOuts[depth] = new BodyContentImpl(out);
+ outs = newOuts;
+ }
+ out = outs[depth];
+ return outs[depth];
}
public JspWriter popBody() {
- out = (JspWriter) writerStack.pop();
+ depth--;
+ if (depth >= 0) {
+ out = outs[depth];
+ } else {
+ out = baseOut;
+ }
return out;
}
@@ -485,15 +496,14 @@
}
}
- protected JspWriter _createOut(int bufferSize, boolean autoFlush)
- throws IOException, IllegalArgumentException
- {
- try {
- return new JspWriterImpl(response, bufferSize, autoFlush);
- } catch( Throwable t ) {
- loghelper.log("creating out", t);
- return null;
- }
+ protected JspWriterImpl _createOut(int bufferSize, boolean autoFlush)
+ throws IOException, IllegalArgumentException {
+ try {
+ return new JspWriterImpl(response, bufferSize, autoFlush);
+ } catch( Throwable t ) {
+ loghelper.log("creating out", t);
+ return null;
+ }
}
/*
@@ -531,5 +541,7 @@
// initial output stream
- protected transient JspWriter out;
+ protected transient JspWriter out;
+ protected transient JspWriterImpl baseOut;
+
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>