You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by kk...@apache.org on 2012/11/13 21:38:12 UTC

svn commit: r1408946 - in /tomcat/trunk/java/org/apache/catalina/valves: AccessLogValve.java Constants.java

Author: kkolinko
Date: Tue Nov 13 20:38:11 2012
New Revision: 1408946

URL: http://svn.apache.org/viewvc?rev=1408946&view=rev
Log:
Review of r1389005 - GC optimization of statusCode display in AccessLogValve
Simplify code and do not expose public char[] arrays.

Modified:
    tomcat/trunk/java/org/apache/catalina/valves/AccessLogValve.java
    tomcat/trunk/java/org/apache/catalina/valves/Constants.java

Modified: tomcat/trunk/java/org/apache/catalina/valves/AccessLogValve.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/valves/AccessLogValve.java?rev=1408946&r1=1408945&r2=1408946&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/valves/AccessLogValve.java (original)
+++ tomcat/trunk/java/org/apache/catalina/valves/AccessLogValve.java Tue Nov 13 20:38:11 2012
@@ -39,7 +39,6 @@ import java.util.TimeZone;
 
 import javax.servlet.ServletException;
 import javax.servlet.http.Cookie;
-import javax.servlet.http.HttpServletResponse;
 import javax.servlet.http.HttpSession;
 
 import org.apache.catalina.AccessLog;
@@ -1598,133 +1597,14 @@ public class AccessLogValve extends Valv
         public void addElement(CharArrayWriter buf, Date date, Request request,
                 Response response, long time) {
             if (response != null) {
-                // This approach is used to reduce GC
-                switch (response.getStatus()) {
-                    case HttpServletResponse.SC_CONTINUE:
-                        buf.write(Constants.SC_CONTINUE_CHAR, 0, 3);
-                        break;
-                    case HttpServletResponse.SC_SWITCHING_PROTOCOLS:
-                        buf.write(Constants.SC_SWITCHING_PROTOCOLS_CHAR, 0, 3);
-                        break;
-                    case HttpServletResponse.SC_OK:
-                        buf.write(Constants.SC_OK_CHAR, 0, 3);
-                        break;
-                    case HttpServletResponse.SC_CREATED:
-                        buf.write(Constants.SC_CREATED_CHAR, 0, 3);
-                        break;
-                    case HttpServletResponse.SC_ACCEPTED:
-                        buf.write(Constants.SC_ACCEPTED_CHAR, 0, 3);
-                        break;
-                    case HttpServletResponse.SC_NON_AUTHORITATIVE_INFORMATION:
-                        buf.write(Constants.SC_NON_AUTHORITATIVE_INFORMATION_CHAR, 0, 3);
-                        break;
-                    case HttpServletResponse.SC_NO_CONTENT:
-                        buf.write(Constants.SC_NO_CONTENT_CHAR, 0, 3);
-                        break;
-                    case HttpServletResponse.SC_RESET_CONTENT:
-                        buf.write(Constants.SC_RESET_CONTENT_CHAR, 0, 3);
-                        break;
-                    case HttpServletResponse.SC_PARTIAL_CONTENT:
-                        buf.write(Constants.SC_PARTIAL_CONTENT_CHAR, 0, 3);
-                        break;
-                    case HttpServletResponse.SC_MULTIPLE_CHOICES:
-                        buf.write(Constants.SC_MULTIPLE_CHOICES_CHAR, 0, 3);
-                        break;
-                    case HttpServletResponse.SC_MOVED_PERMANENTLY:
-                        buf.write(Constants.SC_MOVED_PERMANENTLY_CHAR, 0, 3);
-                        break;
-                    case HttpServletResponse.SC_MOVED_TEMPORARILY:
-                        buf.write(Constants.SC_MOVED_TEMPORARILY_CHAR, 0, 3);
-                        break;
-                    case HttpServletResponse.SC_SEE_OTHER:
-                        buf.write(Constants.SC_SEE_OTHER_CHAR, 0, 3);
-                        break;
-                    case HttpServletResponse.SC_NOT_MODIFIED:
-                        buf.write(Constants.SC_NOT_MODIFIED_CHAR, 0, 3);
-                        break;
-                    case HttpServletResponse.SC_USE_PROXY:
-                        buf.write(Constants.SC_USE_PROXY_CHAR, 0, 3);
-                        break;
-                    case HttpServletResponse.SC_TEMPORARY_REDIRECT:
-                        buf.write(Constants.SC_TEMPORARY_REDIRECT_CHAR, 0, 3);
-                        break;
-                    case HttpServletResponse.SC_BAD_REQUEST:
-                        buf.write(Constants.SC_BAD_REQUEST_CHAR, 0, 3);
-                        break;
-                    case HttpServletResponse.SC_UNAUTHORIZED:
-                        buf.write(Constants.SC_UNAUTHORIZED_CHAR, 0, 3);
-                        break;
-                    case HttpServletResponse.SC_PAYMENT_REQUIRED:
-                        buf.write(Constants.SC_PAYMENT_REQUIRED_CHAR, 0, 3);
-                        break;
-                    case HttpServletResponse.SC_FORBIDDEN:
-                        buf.write(Constants.SC_FORBIDDEN_CHAR, 0, 3);
-                        break;
-                    case HttpServletResponse.SC_NOT_FOUND:
-                        buf.write(Constants.SC_NOT_FOUND_CHAR, 0, 3);
-                        break;
-                    case HttpServletResponse.SC_METHOD_NOT_ALLOWED:
-                        buf.write(Constants.SC_METHOD_NOT_ALLOWED_CHAR, 0, 3);
-                        break;
-                    case HttpServletResponse.SC_NOT_ACCEPTABLE:
-                        buf.write(Constants.SC_NOT_ACCEPTABLE_CHAR, 0, 3);
-                        break;
-                    case HttpServletResponse.SC_PROXY_AUTHENTICATION_REQUIRED:
-                        buf.write(Constants.SC_PROXY_AUTHENTICATION_REQUIRED_CHAR, 0, 3);
-                        break;
-                    case HttpServletResponse.SC_REQUEST_TIMEOUT:
-                        buf.write(Constants.SC_REQUEST_TIMEOUT_CHAR, 0, 3);
-                        break;
-                    case HttpServletResponse.SC_CONFLICT:
-                        buf.write(Constants.SC_CONFLICT_CHAR, 0, 3);
-                        break;
-                    case HttpServletResponse.SC_GONE:
-                        buf.write(Constants.SC_GONE_CHAR, 0, 3);
-                        break;
-                    case HttpServletResponse.SC_LENGTH_REQUIRED:
-                        buf.write(Constants.SC_LENGTH_REQUIRED_CHAR, 0, 3);
-                        break;
-                    case HttpServletResponse.SC_PRECONDITION_FAILED:
-                        buf.write(Constants.SC_PRECONDITION_FAILED_CHAR, 0, 3);
-                        break;
-                    case HttpServletResponse.SC_REQUEST_ENTITY_TOO_LARGE:
-                        buf.write(Constants.SC_REQUEST_ENTITY_TOO_LARGE_CHAR, 0, 3);
-                        break;
-                    case HttpServletResponse.SC_REQUEST_URI_TOO_LONG:
-                        buf.write(Constants.SC_REQUEST_URI_TOO_LONG_CHAR, 0, 3);
-                        break;
-                    case HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE:
-                        buf.write(Constants.SC_UNSUPPORTED_MEDIA_TYPE_CHAR, 0, 3);
-                        break;
-                    case HttpServletResponse.SC_REQUESTED_RANGE_NOT_SATISFIABLE:
-                        buf.write(Constants.SC_REQUESTED_RANGE_NOT_SATISFIABLE_CHAR, 0, 3);
-                        break;
-                    case HttpServletResponse.SC_EXPECTATION_FAILED:
-                        buf.write(Constants.SC_EXPECTATION_FAILED_CHAR, 0, 3);
-                        break;
-                    case HttpServletResponse.SC_INTERNAL_SERVER_ERROR:
-                        buf.write(Constants.SC_INTERNAL_SERVER_ERROR_CHAR, 0, 3);
-                        break;
-                    case HttpServletResponse.SC_NOT_IMPLEMENTED:
-                        buf.write(Constants.SC_NOT_IMPLEMENTED_CHAR, 0, 3);
-                        break;
-                    case HttpServletResponse.SC_BAD_GATEWAY:
-                        buf.write(Constants.SC_BAD_GATEWAY_CHAR, 0, 3);
-                        break;
-                    case HttpServletResponse.SC_SERVICE_UNAVAILABLE:
-                        buf.write(Constants.SC_SERVICE_UNAVAILABLE_CHAR, 0, 3);
-                        break;
-                    case HttpServletResponse.SC_GATEWAY_TIMEOUT:
-                        buf.write(Constants.SC_GATEWAY_TIMEOUT_CHAR, 0, 3);
-                        break;
-                    case HttpServletResponse.SC_HTTP_VERSION_NOT_SUPPORTED:
-                        buf.write(Constants.SC_HTTP_VERSION_NOT_SUPPORTED_CHAR, 0, 3);
-                        break;
-                    default:
-                        // Don't use this for known codes due to the garbage the
-                        // conversion creates
-                        buf.append(Integer.toString(response.getStatus()));
-                        break;
+                // This approach is used to reduce GC from toString conversion
+                int status = response.getStatus();
+                if (100 <= status && status < 1000) {
+                    buf.append((char) ('0' + (status / 100)))
+                            .append((char) ('0' + ((status / 10) % 10)))
+                            .append((char) ('0' + (status % 10)));
+                } else {
+                   buf.append(Integer.toString(status));
                 }
             } else {
                 buf.append('-');

Modified: tomcat/trunk/java/org/apache/catalina/valves/Constants.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/valves/Constants.java?rev=1408946&r1=1408945&r2=1408946&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/valves/Constants.java (original)
+++ tomcat/trunk/java/org/apache/catalina/valves/Constants.java Tue Nov 13 20:38:11 2012
@@ -36,44 +36,4 @@ public final class Constants {
         public static final String COMBINED_PATTERN = "%h %l %u %t \"%r\" %s %b \"%{Referer}i\" \"%{User-Agent}i\"";
     }
 
-    public static final char[] SC_CONTINUE_CHAR = new char[] {'1', '0', '0'};
-    public static final char[] SC_SWITCHING_PROTOCOLS_CHAR = new char[] {'1', '0', '1'};
-    public static final char[] SC_OK_CHAR = new char[] {'2', '0', '0'};
-    public static final char[] SC_CREATED_CHAR = new char[] {'2', '0', '1'};
-    public static final char[] SC_ACCEPTED_CHAR = new char[] {'2', '0', '2'};
-    public static final char[] SC_NON_AUTHORITATIVE_INFORMATION_CHAR = new char[] {'2', '0', '3'};
-    public static final char[] SC_NO_CONTENT_CHAR = new char[] {'2', '0', '4'};
-    public static final char[] SC_RESET_CONTENT_CHAR = new char[] {'2', '0', '5'};
-    public static final char[] SC_PARTIAL_CONTENT_CHAR = new char[] {'2', '0', '6'};
-    public static final char[] SC_MULTIPLE_CHOICES_CHAR = new char[] {'3', '0', '0'};
-    public static final char[] SC_MOVED_PERMANENTLY_CHAR = new char[] {'3', '0', '1'};
-    public static final char[] SC_MOVED_TEMPORARILY_CHAR = new char[] {'3', '0', '2'};
-    public static final char[] SC_SEE_OTHER_CHAR = new char[] {'3', '0', '3'};
-    public static final char[] SC_NOT_MODIFIED_CHAR = new char[] {'3', '0', '4'};
-    public static final char[] SC_USE_PROXY_CHAR = new char[] {'3', '0', '5'};
-    public static final char[] SC_TEMPORARY_REDIRECT_CHAR = new char[] {'3', '0', '7'};
-    public static final char[] SC_BAD_REQUEST_CHAR = new char[] {'4', '0', '0'};
-    public static final char[] SC_UNAUTHORIZED_CHAR = new char[] {'4', '0', '1'};
-    public static final char[] SC_PAYMENT_REQUIRED_CHAR = new char[] {'4', '0', '2'};
-    public static final char[] SC_FORBIDDEN_CHAR = new char[] {'4', '0', '3'};
-    public static final char[] SC_NOT_FOUND_CHAR = new char[] {'4', '0', '4'};
-    public static final char[] SC_METHOD_NOT_ALLOWED_CHAR = new char[] {'4', '0', '5'};
-    public static final char[] SC_NOT_ACCEPTABLE_CHAR = new char[] {'4', '0', '6'};
-    public static final char[] SC_PROXY_AUTHENTICATION_REQUIRED_CHAR = new char[] {'4', '0', '7'};
-    public static final char[] SC_REQUEST_TIMEOUT_CHAR = new char[] {'4', '0', '8'};
-    public static final char[] SC_CONFLICT_CHAR = new char[] {'4', '0', '9'};
-    public static final char[] SC_GONE_CHAR = new char[] {'4', '1', '0'};
-    public static final char[] SC_LENGTH_REQUIRED_CHAR = new char[] {'4', '1', '1'};
-    public static final char[] SC_PRECONDITION_FAILED_CHAR = new char[] {'4', '1', '2'};
-    public static final char[] SC_REQUEST_ENTITY_TOO_LARGE_CHAR = new char[] {'4', '1', '3'};
-    public static final char[] SC_REQUEST_URI_TOO_LONG_CHAR = new char[] {'4', '1', '4'};
-    public static final char[] SC_UNSUPPORTED_MEDIA_TYPE_CHAR = new char[] {'4', '1', '5'};
-    public static final char[] SC_REQUESTED_RANGE_NOT_SATISFIABLE_CHAR = new char[] {'4', '1', '6'};
-    public static final char[] SC_EXPECTATION_FAILED_CHAR = new char[] {'4', '1', '7'};
-    public static final char[] SC_INTERNAL_SERVER_ERROR_CHAR = new char[] {'5', '0', '0'};
-    public static final char[] SC_NOT_IMPLEMENTED_CHAR = new char[] {'5', '0', '1'};
-    public static final char[] SC_BAD_GATEWAY_CHAR = new char[] {'5', '0', '2'};
-    public static final char[] SC_SERVICE_UNAVAILABLE_CHAR = new char[] {'5', '0', '3'};
-    public static final char[] SC_GATEWAY_TIMEOUT_CHAR = new char[] {'5', '0', '4'};
-    public static final char[] SC_HTTP_VERSION_NOT_SUPPORTED_CHAR = new char[] {'5', '0', '5'};
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org