You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2023/01/16 18:02:24 UTC

[tomcat] branch 8.5.x updated (92b8bdf60b -> 94b2b6dfc5)

This is an automated email from the ASF dual-hosted git repository.

markt pushed a change to branch 8.5.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


    from 92b8bdf60b Branch name update
     new 2da103a135 Refactor to avoid issues if JVM optimises conversion to ASCII
     new 547a99bd1a Disable test for Java 16 onwards since performance is comparable
     new 94b2b6dfc5 Add a Jre16 check - required by unit tests

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../util/compat/Jre16Compat.java}                  | 34 ++++++---
 .../org/apache/tomcat/util/compat/Jre19Compat.java |  2 +-
 java/org/apache/tomcat/util/compat/JreCompat.java  | 44 +++++++----
 .../apache/tomcat/util/buf/TestMessageBytes.java   | 86 ++++++++++++++--------
 4 files changed, 110 insertions(+), 56 deletions(-)
 copy java/org/apache/{coyote/ajp/AjpProtocol.java => tomcat/util/compat/Jre16Compat.java} (56%)


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


[tomcat] 03/03: Add a Jre16 check - required by unit tests

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch 8.5.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit 94b2b6dfc5b79ba3d533841d269ae511864dccf3
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Mon Jan 16 18:02:16 2023 +0000

    Add a Jre16 check - required by unit tests
---
 .../org/apache/tomcat/util/compat/Jre16Compat.java | 47 ++++++++++++++++++++++
 .../org/apache/tomcat/util/compat/Jre19Compat.java |  2 +-
 java/org/apache/tomcat/util/compat/JreCompat.java  | 44 +++++++++++++-------
 3 files changed, 78 insertions(+), 15 deletions(-)

diff --git a/java/org/apache/tomcat/util/compat/Jre16Compat.java b/java/org/apache/tomcat/util/compat/Jre16Compat.java
new file mode 100644
index 0000000000..ab436cde17
--- /dev/null
+++ b/java/org/apache/tomcat/util/compat/Jre16Compat.java
@@ -0,0 +1,47 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.tomcat.util.compat;
+
+import org.apache.juli.logging.Log;
+import org.apache.juli.logging.LogFactory;
+import org.apache.tomcat.util.res.StringManager;
+
+class Jre16Compat extends Jre9Compat {
+
+    private static final Log log = LogFactory.getLog(Jre16Compat.class);
+    private static final StringManager sm = StringManager.getManager(Jre16Compat.class);
+
+    private static final Class<?> unixDomainSocketAddressClazz;
+
+    static {
+        Class<?> c1 = null;
+        try {
+            c1 = Class.forName("java.net.UnixDomainSocketAddress");
+        } catch (ClassNotFoundException e) {
+            // Must be pre-Java 16
+            log.debug(sm.getString("jre16Compat.javaPre16"), e);
+        } catch (IllegalArgumentException e) {
+            // Should never happen
+            log.error(sm.getString("jre16Compat.unexpected"), e);
+        }
+        unixDomainSocketAddressClazz = c1;
+    }
+
+    static boolean isSupported() {
+        return unixDomainSocketAddressClazz != null;
+    }
+}
diff --git a/java/org/apache/tomcat/util/compat/Jre19Compat.java b/java/org/apache/tomcat/util/compat/Jre19Compat.java
index 7f120c4d61..fb94810b40 100644
--- a/java/org/apache/tomcat/util/compat/Jre19Compat.java
+++ b/java/org/apache/tomcat/util/compat/Jre19Compat.java
@@ -22,7 +22,7 @@ import org.apache.juli.logging.Log;
 import org.apache.juli.logging.LogFactory;
 import org.apache.tomcat.util.res.StringManager;
 
-public class Jre19Compat extends Jre9Compat {
+public class Jre19Compat extends Jre16Compat {
 
     private static final Log log = LogFactory.getLog(Jre19Compat.class);
     private static final StringManager sm = StringManager.getManager(Jre19Compat.class);
diff --git a/java/org/apache/tomcat/util/compat/JreCompat.java b/java/org/apache/tomcat/util/compat/JreCompat.java
index 6780664285..87fd07f5e1 100644
--- a/java/org/apache/tomcat/util/compat/JreCompat.java
+++ b/java/org/apache/tomcat/util/compat/JreCompat.java
@@ -45,6 +45,7 @@ public class JreCompat {
 
     private static final JreCompat instance;
     private static final boolean jre19Available;
+    private static final boolean jre16Available;
     private static final boolean jre11Available;
     private static final boolean jre9Available;
     private static final boolean jre8Available;
@@ -57,21 +58,31 @@ public class JreCompat {
         if (Jre19Compat.isSupported()) {
             instance = new Jre19Compat();
             jre19Available = true;
+            jre16Available = true;
+            jre9Available = true;
+            jre8Available = true;
+        } else if (Jre16Compat.isSupported()) {
+            instance = new Jre16Compat();
+            jre19Available = false;
+            jre16Available = true;
             jre9Available = true;
             jre8Available = true;
         } else if (Jre9Compat.isSupported()) {
             instance = new Jre9Compat();
             jre19Available = false;
+            jre16Available = false;
             jre9Available = true;
             jre8Available = true;
         } else if (Jre8Compat.isSupported()) {
             instance = new Jre8Compat();
             jre19Available = false;
+            jre16Available = false;
             jre9Available = false;
             jre8Available = true;
         } else {
             instance = new JreCompat();
             jre19Available = false;
+            jre16Available = false;
             jre9Available = false;
             jre8Available = false;
         }
@@ -84,13 +95,28 @@ public class JreCompat {
     }
 
 
-    // Java 7 implementation of Java 8 methods
+    public static boolean isAlpnSupported() {
+        return isJre9Available() || (isJre8Available() && Jre8Compat.isAlpnSupported());
+    }
+
 
     public static boolean isJre8Available() {
         return jre8Available;
     }
 
 
+    public static boolean isJre9Available() {
+        return jre9Available;
+    }
+
+
+    public static boolean isJre16Available() {
+        return jre16Available;
+    }
+
+
+    // Java 7 implementation of Java 8 methods
+
     @SuppressWarnings("unused")
     public void setUseServerCipherSuitesOrder(SSLParameters engine, boolean useCipherSuitesOrder) {
         throw new UnsupportedOperationException(sm.getString("jreCompat.noServerCipherSuiteOrder"));
@@ -105,16 +131,6 @@ public class JreCompat {
 
     // Java 7 implementation of Java 9 methods
 
-    public static boolean isAlpnSupported() {
-        return isJre9Available() || (isJre8Available() && Jre8Compat.isAlpnSupported());
-    }
-
-
-    public static boolean isJre9Available() {
-        return jre9Available;
-    }
-
-
     /**
      * Test if the provided exception is an instance of
      * java.lang.reflect.InaccessibleObjectException.
@@ -133,9 +149,9 @@ public class JreCompat {
     /**
      * Set the application protocols the server will accept for ALPN
      *
-     * @param sslParameters    The SSL parameters for a connection
-     * @param protocols        The application protocols to be allowed for that
-     *                         connection
+     * @param sslParameters The SSL parameters for a connection
+     * @param protocols     The application protocols to be allowed for that
+     *                      connection
      */
     public void setApplicationProtocols(SSLParameters sslParameters, String[] protocols) {
         throw new UnsupportedOperationException(sm.getString("jreCompat.noApplicationProtocols"));


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


[tomcat] 01/03: Refactor to avoid issues if JVM optimises conversion to ASCII

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch 8.5.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit 2da103a1353021f5549076707abcccf079322409
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Mon Nov 14 11:38:38 2022 +0000

    Refactor to avoid issues if JVM optimises conversion to ASCII
---
 .../apache/tomcat/util/buf/TestMessageBytes.java   | 79 ++++++++++++++--------
 1 file changed, 50 insertions(+), 29 deletions(-)

diff --git a/test/org/apache/tomcat/util/buf/TestMessageBytes.java b/test/org/apache/tomcat/util/buf/TestMessageBytes.java
index f2016f478d..3311996394 100644
--- a/test/org/apache/tomcat/util/buf/TestMessageBytes.java
+++ b/test/org/apache/tomcat/util/buf/TestMessageBytes.java
@@ -16,7 +16,10 @@
  */
 package org.apache.tomcat.util.buf;
 
-import java.nio.charset.Charset;
+import java.nio.CharBuffer;
+import java.nio.charset.CharacterCodingException;
+import java.nio.charset.CharsetEncoder;
+import java.nio.charset.CodingErrorAction;
 import java.nio.charset.StandardCharsets;
 
 import org.junit.Assert;
@@ -24,6 +27,26 @@ import org.junit.Test;
 
 public class TestMessageBytes {
 
+    private static final String CONVERSION_STRING =
+            "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" +
+            "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" +
+            "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" +
+            "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" +
+            "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" +
+            "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" +
+            "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" +
+            "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" +
+            "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" +
+            "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" +
+            "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" +
+            "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" +
+            "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" +
+            "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" +
+            "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" +
+            "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF";
+
+    private static final int CONVERSION_LOOPS = 1000000;
+
     @Test
     public void testToStringFromNull() {
         MessageBytes mb = MessageBytes.newInstance();
@@ -73,8 +96,7 @@ public class TestMessageBytes {
 
 
     /*
-     * Checks the the optimized code is at least twice as fast as the
-     * non-optimized code.
+     * Checks the the optimized code is faster than the non-optimized code.
      */
     @Test
     public void testConversionPerformance() {
@@ -87,12 +109,12 @@ public class TestMessageBytes {
          * non-optimised code. Loop three times allows once to warn up the JVM
          * once to run the test and once more in case of unexpected CI /GC
          * slowness. The test will exit early if possible.
+         *
+         * MeesageBytes only optimises conversion for ISO_8859_1
          */
         for (int i = 0; i < 3; i++) {
-            optimized = doTestConversionPerformance(StandardCharsets.ISO_8859_1);
-            // US_ASCII chosen as the conversion is the same and it is another
-            // Charset available on all platforms.
-            nonOptimized = doTestConversionPerformance(StandardCharsets.US_ASCII);
+            optimized = doTestOptimisedConversionPerformance();
+            nonOptimized = doTestConversionPerformance();
 
             System.out.println(optimized + " " + nonOptimized);
             if (optimized * 2 < nonOptimized) {
@@ -100,37 +122,36 @@ public class TestMessageBytes {
             }
         }
 
-        Assert.assertTrue("Non-optimised code was faster (" + nonOptimized + "ns) compared to optimized (" + optimized + "ns)", optimized < nonOptimized);
+        Assert.assertTrue("Non-optimised code was faster (" + nonOptimized + "ns) compared to optimized (" +
+                optimized + "ns)", optimized < nonOptimized);
     }
 
 
-    private long doTestConversionPerformance(Charset charset) {
+    private long doTestOptimisedConversionPerformance() {
         MessageBytes mb = MessageBytes.newInstance();
 
-        int loops = 1000000;
-
         long start = System.nanoTime();
-        for (int i = 0; i < loops; i++) {
+        for (int i = 0; i < CONVERSION_LOOPS; i++) {
             mb.recycle();
-            mb.setCharset(charset);
-            mb.setString("0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" +
-                    "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" +
-                    "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" +
-                    "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" +
-                    "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" +
-                    "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" +
-                    "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" +
-                    "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" +
-                    "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" +
-                    "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" +
-                    "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" +
-                    "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" +
-                    "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" +
-                    "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" +
-                    "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" +
-                    "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF");
+            mb.setCharset(StandardCharsets.ISO_8859_1);
+            mb.setString(CONVERSION_STRING);
             mb.toBytes();
         }
         return System.nanoTime() - start;
     }
+
+
+    private long doTestConversionPerformance() {
+        long start = System.nanoTime();
+        for (int i = 0; i < CONVERSION_LOOPS; i++) {
+            CharsetEncoder encoder = StandardCharsets.ISO_8859_1.newEncoder().onMalformedInput(
+                    CodingErrorAction.REPORT).onUnmappableCharacter(CodingErrorAction.REPORT);
+            try {
+                encoder.encode(CharBuffer.wrap(CONVERSION_STRING));
+            } catch (CharacterCodingException cce) {
+                Assert.fail();
+            }
+        }
+        return System.nanoTime() - start;
+    }
 }


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


[tomcat] 02/03: Disable test for Java 16 onwards since performance is comparable

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch 8.5.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit 547a99bd1a36e31f4d62afdf0dc985125f19133b
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Mon Nov 14 11:42:53 2022 +0000

    Disable test for Java 16 onwards since performance is comparable
---
 test/org/apache/tomcat/util/buf/TestMessageBytes.java | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/test/org/apache/tomcat/util/buf/TestMessageBytes.java b/test/org/apache/tomcat/util/buf/TestMessageBytes.java
index 3311996394..4abc1b6374 100644
--- a/test/org/apache/tomcat/util/buf/TestMessageBytes.java
+++ b/test/org/apache/tomcat/util/buf/TestMessageBytes.java
@@ -23,8 +23,11 @@ import java.nio.charset.CodingErrorAction;
 import java.nio.charset.StandardCharsets;
 
 import org.junit.Assert;
+import org.junit.Assume;
 import org.junit.Test;
 
+import org.apache.tomcat.util.compat.JreCompat;
+
 public class TestMessageBytes {
 
     private static final String CONVERSION_STRING =
@@ -100,6 +103,10 @@ public class TestMessageBytes {
      */
     @Test
     public void testConversionPerformance() {
+
+        // ISO_8859_1 conversion appears to be optimised in Java 16 onwards
+        Assume.assumeFalse(JreCompat.isJre16Available());
+
         long optimized = -1;
         long nonOptimized = -1;
 
@@ -110,7 +117,7 @@ public class TestMessageBytes {
          * once to run the test and once more in case of unexpected CI /GC
          * slowness. The test will exit early if possible.
          *
-         * MeesageBytes only optimises conversion for ISO_8859_1
+         * MessageBytes only optimises conversion for ISO_8859_1
          */
         for (int i = 0; i < 3; i++) {
             optimized = doTestOptimisedConversionPerformance();


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