[tomcat] 02/02: Avoid reflection for default instantiation
This is an automated email from the ASF dual-hosted git repository. fhanik pushed a commit to branch 9.0.x in repository https://gitbox.apache.org/repos/asf/tomcat.git commit f4dac6846c548144799b1c3f33aba4eb320a3413 Author: Filip Hanik AuthorDate: Mon Jul 13 12:43:55 2020 -0700 Avoid reflection for default instantiation (Most commonly used codepath) Avoid having to load APR classes in the Connector Ensure that IntrospectionUtils can call setProperty on PersistentProviderRegistrations --- .../auth/message/config/AuthConfigFactory.java | 8 ++- .../jaspic/PersistentProviderRegistrations.java| 5 +- java/org/apache/catalina/connector/Connector.java | 14 ++--- .../apache/catalina/core/AprLifecycleListener.java | 43 ++ java/org/apache/catalina/core/AprStatus.java | 69 ++ java/org/apache/catalina/core/StandardHost.java| 4 +- java/org/apache/catalina/loader/WebappLoader.java | 4 ++ java/org/apache/catalina/startup/Tomcat.java | 8 ++- 8 files changed, 119 insertions(+), 36 deletions(-) diff --git a/java/javax/security/auth/message/config/AuthConfigFactory.java b/java/javax/security/auth/message/config/AuthConfigFactory.java index d98b2f2..b27235b 100644 --- a/java/javax/security/auth/message/config/AuthConfigFactory.java +++ b/java/javax/security/auth/message/config/AuthConfigFactory.java @@ -72,8 +72,12 @@ public abstract class AuthConfigFactory { // this class. Note that the Thread context class loader // should not be used since that would trigger a memory leak // in container environments. -Class clazz = Class.forName(className); -return (AuthConfigFactory) clazz.getConstructor().newInstance(); +if (className.equals("org.apache.catalina.authenticator.jaspic.AuthConfigFactoryImpl")) { +return new org.apache.catalina.authenticator.jaspic.AuthConfigFactoryImpl(); +} else { +Class clazz = Class.forName(className); +return (AuthConfigFactory) clazz.getConstructor().newInstance(); +} } }); } catch (PrivilegedActionException e) { diff --git a/java/org/apache/catalina/authenticator/jaspic/PersistentProviderRegistrations.java b/java/org/apache/catalina/authenticator/jaspic/PersistentProviderRegistrations.java index a1ba60c..cd75799 100644 --- a/java/org/apache/catalina/authenticator/jaspic/PersistentProviderRegistrations.java +++ b/java/org/apache/catalina/authenticator/jaspic/PersistentProviderRegistrations.java @@ -41,7 +41,7 @@ import org.xml.sax.SAXException; * Utility class for the loading and saving of JASPIC persistent provider * registrations. */ -final class PersistentProviderRegistrations { +public final class PersistentProviderRegistrations { private static final StringManager sm = StringManager.getManager(PersistentProviderRegistrations.class); @@ -233,6 +233,9 @@ final class PersistentProviderRegistrations { public void addProperty(Property property) { properties.put(property.getName(), property.getValue()); } +public void setProperty(String name, String value) { +addProperty(name, value); +} void addProperty(String name, String value) { properties.put(name, value); } diff --git a/java/org/apache/catalina/connector/Connector.java b/java/org/apache/catalina/connector/Connector.java index b22ce95..1cc1580 100644 --- a/java/org/apache/catalina/connector/Connector.java +++ b/java/org/apache/catalina/connector/Connector.java @@ -29,7 +29,7 @@ import org.apache.catalina.Globals; import org.apache.catalina.LifecycleException; import org.apache.catalina.LifecycleState; import org.apache.catalina.Service; -import org.apache.catalina.core.AprLifecycleListener; +import org.apache.catalina.core.AprStatus; import org.apache.catalina.util.LifecycleMBeanBase; import org.apache.coyote.AbstractProtocol; import org.apache.coyote.Adapter; @@ -80,8 +80,8 @@ public class Connector extends LifecycleMBeanBase { public Connector(String protocol) { -boolean apr = AprLifecycleListener.isAprAvailable() && -AprLifecycleListener.getUseAprConnector(); +boolean apr = AprStatus.isAprAvailable() && +AprStatus.getUseAprConnector(); ProtocolHandler p = null; try { p = ProtocolHandler.create(protocol, apr); @@ -625,7 +625,7 @@ public class Connector extends LifecycleMBeanBase { * @return the Coyote protocol handler in use. */ public String getProtocol() { -boolean apr = AprLifecycleListener.getUseAprConnector();
Re: [tomcat] 02/02: Avoid reflection for default instantiation
Hi, On Wed, Jul 22, 2020 at 2:18 AM wrote: > This is an automated email from the ASF dual-hosted git repository. > > fhanik pushed a commit to branch 9.0.x > in repository https://gitbox.apache.org/repos/asf/tomcat.git > > commit f4dac6846c548144799b1c3f33aba4eb320a3413 > Author: Filip Hanik > AuthorDate: Mon Jul 13 12:43:55 2020 -0700 > > Avoid reflection for default instantiation > > (Most commonly used codepath) > > Avoid having to load APR classes in the Connector > > Ensure that IntrospectionUtils can call setProperty on > PersistentProviderRegistrations > --- > .../auth/message/config/AuthConfigFactory.java | 8 ++- > .../jaspic/PersistentProviderRegistrations.java| 5 +- > java/org/apache/catalina/connector/Connector.java | 14 ++--- > .../apache/catalina/core/AprLifecycleListener.java | 43 ++ > java/org/apache/catalina/core/AprStatus.java | 69 > ++ > java/org/apache/catalina/core/StandardHost.java| 4 +- > java/org/apache/catalina/loader/WebappLoader.java | 4 ++ > java/org/apache/catalina/startup/Tomcat.java | 8 ++- > 8 files changed, 119 insertions(+), 36 deletions(-) > > diff --git > a/java/javax/security/auth/message/config/AuthConfigFactory.java > b/java/javax/security/auth/message/config/AuthConfigFactory.java > index d98b2f2..b27235b 100644 > --- a/java/javax/security/auth/message/config/AuthConfigFactory.java > +++ b/java/javax/security/auth/message/config/AuthConfigFactory.java > @@ -72,8 +72,12 @@ public abstract class AuthConfigFactory { > // this class. Note that the Thread context > class loader > // should not be used since that would > trigger a memory leak > // in container environments. > -Class clazz = Class.forName(className); > -return (AuthConfigFactory) > clazz.getConstructor().newInstance(); > +if > (className.equals("org.apache.catalina.authenticator.jaspic.AuthConfigFactoryImpl")) > { > +return new > org.apache.catalina.authenticator.jaspic.AuthConfigFactoryImpl(); > +} else { > +Class clazz = Class.forName(className); > +return (AuthConfigFactory) > clazz.getConstructor().newInstance(); > +} > } > }); > } catch (PrivilegedActionException e) { > diff --git > a/java/org/apache/catalina/authenticator/jaspic/PersistentProviderRegistrations.java > b/java/org/apache/catalina/authenticator/jaspic/PersistentProviderRegistrations.java > index a1ba60c..cd75799 100644 > --- > a/java/org/apache/catalina/authenticator/jaspic/PersistentProviderRegistrations.java > +++ > b/java/org/apache/catalina/authenticator/jaspic/PersistentProviderRegistrations.java > @@ -41,7 +41,7 @@ import org.xml.sax.SAXException; > * Utility class for the loading and saving of JASPIC persistent provider > * registrations. > */ > -final class PersistentProviderRegistrations { > +public final class PersistentProviderRegistrations { > > private static final StringManager sm = > > StringManager.getManager(PersistentProviderRegistrations.class); > @@ -233,6 +233,9 @@ final class PersistentProviderRegistrations { > public void addProperty(Property property) { > properties.put(property.getName(), property.getValue()); > } > +public void setProperty(String name, String value) { > +addProperty(name, value); > +} > void addProperty(String name, String value) { > properties.put(name, value); > } > diff --git a/java/org/apache/catalina/connector/Connector.java > b/java/org/apache/catalina/connector/Connector.java > index b22ce95..1cc1580 100644 > --- a/java/org/apache/catalina/connector/Connector.java > +++ b/java/org/apache/catalina/connector/Connector.java > @@ -29,7 +29,7 @@ import org.apache.catalina.Globals; > import org.apache.catalina.LifecycleException; > import org.apache.catalina.LifecycleState; > import org.apache.catalina.Service; > -import org.apache.catalina.core.AprLifecycleListener; > +import org.apache.catalina.core.AprStatus; > import org.apache.catalina.util.LifecycleMBeanBase; > import org.apache.coyote.AbstractProtocol; > import org.apache.coyote.Adapter; > @@ -80,8 +80,8 @@ public class Connector extends LifecycleMBeanBase { > > > public Connector(String protocol) { > -boolean apr = AprLifecycleListener.isAprAvailable() && > -AprLifecycleListener.getUseAprConnector(); > +boolean apr = AprStatus.isAprAvailable() && > +AprStatus.getUseAprConnector(); > ProtocolHandler p = null; > try { > p = ProtocolHandler.create(protocol, apr); > @@ -625,7 +625,7 @
Re: [tomcat] 02/02: Avoid reflection for default instantiation
From: Martin Grigorov Sent: Wednesday, July 22, 2020 2:29 AM To: Tomcat Developers List Subject: Re: [tomcat] 02/02: Avoid reflection for default instantiation +public class AprStatus { +private static volatile boolean aprInitialized = false; +private static volatile boolean aprAvailable = false; +private static volatile boolean useAprConnector = false; +private static volatile boolean useOpenSSL = true; Is this a good default value ? OpenSSL should be used only when APR is available, no ? If APR is not available then JSSE should be used. Martin Filip: It's not the intention of this commit to change the default value. https://github.com/apache/tomcat/commit/f4dac6846c548144799b1c3f33aba4eb320a3413#diff-bda15c59296a87416d8b6da5682cffc8L82 Feel free to start another thread on that topic - To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org