This is an automated email from the ASF dual-hosted git repository.
remm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/master by this push:
new 5e8eb55 Remove the rest of Jasper system property configuration
5e8eb55 is described below
commit 5e8eb5533f551c3dbc3003e4c2f4f0d2958a8eb3
Author: remm <[email protected]>
AuthorDate: Tue Mar 31 23:28:43 2020 +0200
Remove the rest of Jasper system property configuration
The default values and cache behaviors could be worth revisiting.
---
java/org/apache/jasper/Constants.java | 9 ++++
.../org/apache/jasper/runtime/BodyContentImpl.java | 51 +++++-----------------
java/org/apache/jasper/runtime/JspFactoryImpl.java | 22 +++++-----
.../org/apache/jasper/runtime/PageContextImpl.java | 12 ++++-
.../apache/jasper/servlet/JasperInitializer.java | 14 ++++++
webapps/docs/changelog.xml | 4 +-
webapps/docs/config/systemprops.xml | 32 --------------
webapps/docs/jasper-howto.xml | 19 ++++++--
8 files changed, 72 insertions(+), 91 deletions(-)
diff --git a/java/org/apache/jasper/Constants.java
b/java/org/apache/jasper/Constants.java
index fd7c1fe..16e2e96 100644
--- a/java/org/apache/jasper/Constants.java
+++ b/java/org/apache/jasper/Constants.java
@@ -98,4 +98,13 @@ public class Constants {
*/
public static final String XML_BLOCK_EXTERNAL_INIT_PARAM =
"org.apache.jasper.XML_BLOCK_EXTERNAL";
+
+ /**
+ * Name of the ServletContext init-param that determines the JSP
+ * factory pool size. Set the value to a positive integer to enable it.
+ * The default value is <code>8</code> per thread.
+ */
+ public static final String JSP_FACTORY_POOL_SIZE_INIT_PARAM =
+ "org.apache.jasper.runtime.JspFactoryImpl.POOL_SIZE";
+
}
diff --git a/java/org/apache/jasper/runtime/BodyContentImpl.java
b/java/org/apache/jasper/runtime/BodyContentImpl.java
index 7575650..2164a83 100644
--- a/java/org/apache/jasper/runtime/BodyContentImpl.java
+++ b/java/org/apache/jasper/runtime/BodyContentImpl.java
@@ -21,13 +21,10 @@ import java.io.CharArrayReader;
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
import jakarta.servlet.jsp.JspWriter;
import jakarta.servlet.jsp.tagext.BodyContent;
-import org.apache.jasper.Constants;
import org.apache.jasper.compiler.Localizer;
/**
@@ -42,40 +39,8 @@ import org.apache.jasper.compiler.Localizer;
*/
public class BodyContentImpl extends BodyContent {
- private static final boolean LIMIT_BUFFER;
- private static final int TAG_BUFFER_SIZE;
-
- static {
- if (System.getSecurityManager() == null) {
- LIMIT_BUFFER = Boolean.parseBoolean(System.getProperty(
- "org.apache.jasper.runtime.BodyContentImpl.LIMIT_BUFFER",
"false"));
- TAG_BUFFER_SIZE = Integer.getInteger(
- "org.apache.jasper.runtime.BodyContentImpl.BUFFER_SIZE",
- Constants.DEFAULT_TAG_BUFFER_SIZE).intValue();
- } else {
- LIMIT_BUFFER = AccessController.doPrivileged(
- new PrivilegedAction<Boolean>() {
- @Override
- public Boolean run() {
- return Boolean.valueOf(System.getProperty(
-
"org.apache.jasper.runtime.BodyContentImpl.LIMIT_BUFFER",
- "false"));
- }
- }
- ).booleanValue();
- TAG_BUFFER_SIZE = AccessController.doPrivileged(
- new PrivilegedAction<Integer>() {
- @Override
- public Integer run() {
- return Integer.getInteger(
-
"org.apache.jasper.runtime.BodyContentImpl.BUFFER_SIZE",
- Constants.DEFAULT_TAG_BUFFER_SIZE);
- }
- }
- ).intValue();
- }
- }
-
+ private final boolean limitBuffer;
+ private final int tagBufferSize;
private char[] cb;
private int nextChar;
@@ -89,10 +54,14 @@ public class BodyContentImpl extends BodyContent {
/**
* Constructor.
* @param enclosingWriter The wrapped writer
+ * @param limitBuffer <code>true</code> to discard large buffers
+ * @param tagBufferSize the buffer sise
*/
- public BodyContentImpl(JspWriter enclosingWriter) {
+ public BodyContentImpl(JspWriter enclosingWriter, boolean limitBuffer, int
tagBufferSize) {
super(enclosingWriter);
- cb = new char[TAG_BUFFER_SIZE];
+ this.limitBuffer = limitBuffer;
+ this.tagBufferSize = tagBufferSize;
+ cb = new char[tagBufferSize];
bufferSize = cb.length;
nextChar = 0;
closed = false;
@@ -547,8 +516,8 @@ public class BodyContentImpl extends BodyContent {
throw new IOException();
} else {
nextChar = 0;
- if (LIMIT_BUFFER && (cb.length > TAG_BUFFER_SIZE)) {
- cb = new char[TAG_BUFFER_SIZE];
+ if (limitBuffer && (cb.length > tagBufferSize)) {
+ cb = new char[tagBufferSize];
bufferSize = cb.length;
}
}
diff --git a/java/org/apache/jasper/runtime/JspFactoryImpl.java
b/java/org/apache/jasper/runtime/JspFactoryImpl.java
index 44a53db..25d6406 100644
--- a/java/org/apache/jasper/runtime/JspFactoryImpl.java
+++ b/java/org/apache/jasper/runtime/JspFactoryImpl.java
@@ -38,12 +38,8 @@ import org.apache.jasper.Constants;
*/
public class JspFactoryImpl extends JspFactory {
- private static final boolean USE_POOL =
-
Boolean.parseBoolean(System.getProperty("org.apache.jasper.runtime.JspFactoryImpl.USE_POOL",
"true"));
- private static final int POOL_SIZE =
-
Integer.parseInt(System.getProperty("org.apache.jasper.runtime.JspFactoryImpl.POOL_SIZE",
"8"));
-
private final ThreadLocal<PageContextPool> localPool = new ThreadLocal<>();
+ private int poolSize = -1;
@Override
public PageContext getPageContext(Servlet servlet, ServletRequest request,
@@ -85,15 +81,19 @@ public class JspFactoryImpl extends JspFactory {
};
}
+ public void setPoolSize(int poolSize) {
+ this.poolSize = poolSize;
+ }
+
private PageContext internalGetPageContext(Servlet servlet, ServletRequest
request,
ServletResponse response, String errorPageURL, boolean
needsSession,
int bufferSize, boolean autoflush) {
PageContext pc;
- if (USE_POOL) {
+ if (poolSize > 0) {
PageContextPool pool = localPool.get();
if (pool == null) {
- pool = new PageContextPool();
+ pool = new PageContextPool(poolSize);
localPool.set(pool);
}
pc = pool.get();
@@ -117,7 +117,7 @@ public class JspFactoryImpl extends JspFactory {
private void internalReleasePageContext(PageContext pc) {
pc.release();
- if (USE_POOL && (pc instanceof PageContextImpl)) {
+ if (poolSize > 0 && (pc instanceof PageContextImpl)) {
localPool.get().put(pc);
}
}
@@ -179,12 +179,12 @@ public class JspFactoryImpl extends JspFactory {
private int current = -1;
- public PageContextPool() {
- this.pool = new PageContext[POOL_SIZE];
+ public PageContextPool(int poolSize) {
+ this.pool = new PageContext[poolSize];
}
public void put(PageContext o) {
- if (current < (POOL_SIZE - 1)) {
+ if (current < (pool.length - 1)) {
current++;
pool[current] = o;
}
diff --git a/java/org/apache/jasper/runtime/PageContextImpl.java
b/java/org/apache/jasper/runtime/PageContextImpl.java
index fcbbae8..f5510b2 100644
--- a/java/org/apache/jasper/runtime/PageContextImpl.java
+++ b/java/org/apache/jasper/runtime/PageContextImpl.java
@@ -82,6 +82,10 @@ public class PageContextImpl extends PageContext {
private String errorPageURL;
+ private boolean limitBodyContentBuffer;
+
+ private int bodyContentTagBufferSize = Constants.DEFAULT_TAG_BUFFER_SIZE;
+
// page-scope attributes
private final transient HashMap<String, Object> attributes;
@@ -125,6 +129,12 @@ public class PageContextImpl extends PageContext {
this.request = request;
this.response = response;
+ limitBodyContentBuffer =
Boolean.parseBoolean(config.getInitParameter("limitBodyContentBuffer"));
+ String bodyContentTagBufferSize =
config.getInitParameter("bodyContentTagBufferSize");
+ if (bodyContentTagBufferSize != null) {
+ this.bodyContentTagBufferSize =
Integer.parseInt(bodyContentTagBufferSize);
+ }
+
// initialize application context
this.applicationContext =
JspApplicationContextImpl.getInstance(context);
@@ -545,7 +555,7 @@ public class PageContextImpl extends PageContext {
depth++;
if (depth >= outs.length) {
BodyContentImpl[] newOuts = Arrays.copyOf(outs, depth + 1);
- newOuts[depth] = new BodyContentImpl(out);
+ newOuts[depth] = new BodyContentImpl(out, limitBodyContentBuffer,
bodyContentTagBufferSize);
outs = newOuts;
}
diff --git a/java/org/apache/jasper/servlet/JasperInitializer.java
b/java/org/apache/jasper/servlet/JasperInitializer.java
index 390c8b6..f2f3700 100644
--- a/java/org/apache/jasper/servlet/JasperInitializer.java
+++ b/java/org/apache/jasper/servlet/JasperInitializer.java
@@ -43,6 +43,7 @@ public class JasperInitializer implements
ServletContainerInitializer {
private static final String MSG =
"org.apache.jasper.servlet.JasperInitializer";
private final Log log = LogFactory.getLog(JasperInitializer.class); //
must not be static
+ private static JspFactoryImpl defaultFactory;
/**
* Preload classes required at runtime by a JSP servlet so that
* we don't get a defineClassInPackage security exception.
@@ -52,6 +53,7 @@ public class JasperInitializer implements
ServletContainerInitializer {
SecurityClassLoad.securityClassLoad(factory.getClass().getClassLoader());
if (JspFactory.getDefaultFactory() == null) {
JspFactory.setDefaultFactory(factory);
+ defaultFactory = factory;
}
}
@@ -93,6 +95,18 @@ public class JasperInitializer implements
ServletContainerInitializer {
context.setAttribute(TldCache.SERVLET_CONTEXT_ATTRIBUTE_NAME,
new TldCache(context, scanner.getUriTldResourcePathMap(),
scanner.getTldResourcePathTaglibXmlMap()));
+
+ String poolSizeValue =
context.getInitParameter(Constants.JSP_FACTORY_POOL_SIZE_INIT_PARAM);
+ int poolSize = 8;
+ if (poolSizeValue != null) {
+ try {
+ poolSize = Integer.parseInt(poolSizeValue);
+ } catch (NumberFormatException e) {
+ throw new ServletException(e);
+ }
+ }
+ defaultFactory.setPoolSize(poolSize);
+
}
protected TldScanner newTldScanner(ServletContext context, boolean
namespaceAware,
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index aa6978e..49fd838 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -165,8 +165,8 @@
supported version will used. (markt)
</add>
<update>
- Remove many rarely used Jasper system property configuration,
- replaced by a new set of init parameters. (remm)
+ Remove Jasper configuration using system properties and replace them
+ by a new set of JSP Servlet init parameters. (remm)
</update>
</changelog>
</subsection>
diff --git a/webapps/docs/config/systemprops.xml
b/webapps/docs/config/systemprops.xml
index 0fdef8f..37c5d93 100644
--- a/webapps/docs/config/systemprops.xml
+++ b/webapps/docs/config/systemprops.xml
@@ -113,38 +113,6 @@
</properties>
</section>
-<section name="Jasper">
- <properties>
-
- <property name="org.apache.jasper.runtime. BodyContentImpl.BUFFER_SIZE">
- <p>The size (in characters) to use when creating a tag buffer.</p>
- <p>If not specified, the default value of
- <code>org.apache.jasper.Constants.DEFAULT_TAG_BUFFER_SIZE</code> (512)
- will be used.</p>
- </property>
-
- <property name="org.apache.jasper.runtime. BodyContentImpl.LIMIT_BUFFER">
- <p>If <code>true</code>, any tag buffer that expands beyond
- <code>org.apache.jasper.runtime.BodyContentImpl.BUFFER_SIZE</code> will
be
- destroyed and a new buffer created.</p>
- <p>If not specified, the default value of <code>false</code> will be
used.</p>
- </property>
-
- <property name="org.apache.jasper.runtime. JspFactoryImpl.USE_POOL">
- <p>If <code>true</code>, a ThreadLocal <code>PageContext</code> pool will
- be used.</p>
- <p>If not specified, the default value of <code>true</code> will be
used.</p>
- </property>
-
- <property name="org.apache.jasper.runtime. JspFactoryImpl.POOL_SIZE">
- <p>The size of the ThreadLocal <code>PageContext</code>.</p>
- <p>If not specified, the default value of <code>8</code> will be
used.</p>
- </property>
-
- </properties>
-
-</section>
-
<section name="Security">
diff --git a/webapps/docs/jasper-howto.xml b/webapps/docs/jasper-howto.xml
index 0a91cd0..abee2db 100644
--- a/webapps/docs/jasper-howto.xml
+++ b/webapps/docs/jasper-howto.xml
@@ -279,6 +279,17 @@ be applied to the expression? <code>true</code> or
<code>false</code>, default
the instance manager is used to obtain tag handler instances.
<code>true</code> or <code>false</code>, default <code>false</code>.</li>
+<li><strong>limitBodyContentBuffer</strong> - If <code>true</code>, any
+ tag buffer that expands beyond the value of the
+ <code>bodyContentTagBufferSize</code> init parameter will be
+ destroyed and a new buffer created.
+ <code>true</code> or <code>false</code>, default <code>false</code>.</li>
+
+<li><strong>bodyContentTagBufferSize</strong> - The size (in characters)
+ to use when creating a tag buffer. If not specified, the default value of
+ <code>org.apache.jasper.Constants.DEFAULT_TAG_BUFFER_SIZE</code> (512)
+ will be used.</li>
+
</ul>
<p>The Java compiler from Eclipse JDT in included as the default compiler. It
is
@@ -454,10 +465,10 @@ and the compile JSP servlet classes at
<ul>
<li> When you switch to another Tomcat release, then regenerate and recompile
your JSP's with the new Tomcat version.</li>
-<li>Use java system property at server runtime to disable PageContext pooling
-<code>org.apache.jasper.runtime.JspFactoryImpl.USE_POOL=false</code>.
-and limit the buffering with
-<code>org.apache.jasper.runtime.BodyContentImpl.LIMIT_BUFFER=true</code>. Note
+<li>Use a Servlet context parameter to disable PageContext pooling
+<code>org.apache.jasper.runtime.JspFactoryImpl.POOL_SIZE=-1</code>
+and limit the buffering with the JSP Servlet init-param
+<code>limitBodyContentBuffer=true</code>. Note
that changing from the defaults may affect performance, but it will vary
depending on the application.</li>
</ul>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]