This is an automated email from the ASF dual-hosted git repository.
remm pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/main by this push:
new dd61cbee8e Align buffer use pattern with the FFM code
dd61cbee8e is described below
commit dd61cbee8e0c5338eb044c3ab25da7fc0bc8a2df
Author: remm <[email protected]>
AuthorDate: Mon Oct 7 15:01:46 2024 +0200
Align buffer use pattern with the FFM code
This uses 18KB of memory per connection.
---
java/org/apache/tomcat/util/net/openssl/OpenSSLEngine.java | 10 ++--------
webapps/docs/changelog.xml | 4 ++++
2 files changed, 6 insertions(+), 8 deletions(-)
diff --git a/java/org/apache/tomcat/util/net/openssl/OpenSSLEngine.java
b/java/org/apache/tomcat/util/net/openssl/OpenSSLEngine.java
index 99bd981944..890d473374 100644
--- a/java/org/apache/tomcat/util/net/openssl/OpenSSLEngine.java
+++ b/java/org/apache/tomcat/util/net/openssl/OpenSSLEngine.java
@@ -136,6 +136,7 @@ public final class OpenSSLEngine extends SSLEngine
implements SSLUtil.ProtocolIn
private final OpenSSLState state;
private final Cleanable cleanable;
+ private ByteBuffer buf =
ByteBuffer.allocateDirect(MAX_ENCRYPTED_PACKET_LENGTH);
private enum Accepted { NOT, IMPLICIT, EXPLICIT }
private Accepted accepted = Accepted.NOT;
@@ -225,6 +226,7 @@ public final class OpenSSLEngine extends SSLEngine
implements SSLUtil.ProtocolIn
cleanable.clean();
// internal errors can cause shutdown without marking the engine
closed
isInboundDone = isOutboundDone = engineClosed = true;
+ ByteBufferUtils.cleanDirectBuffer(buf);
}
}
@@ -252,7 +254,6 @@ public final class OpenSSLEngine extends SSLEngine
implements SSLUtil.ProtocolIn
return sslWrote;
}
} else {
- ByteBuffer buf = ByteBuffer.allocateDirect(len);
try {
final long addr = Buffer.address(buf);
@@ -273,7 +274,6 @@ public final class OpenSSLEngine extends SSLEngine
implements SSLUtil.ProtocolIn
}
} finally {
buf.clear();
- ByteBufferUtils.cleanDirectBuffer(buf);
}
}
@@ -300,7 +300,6 @@ public final class OpenSSLEngine extends SSLEngine
implements SSLUtil.ProtocolIn
return netWrote;
}
} else {
- ByteBuffer buf = ByteBuffer.allocateDirect(len);
try {
final long addr = Buffer.address(buf);
@@ -318,7 +317,6 @@ public final class OpenSSLEngine extends SSLEngine
implements SSLUtil.ProtocolIn
}
} finally {
buf.clear();
- ByteBufferUtils.cleanDirectBuffer(buf);
}
}
@@ -346,7 +344,6 @@ public final class OpenSSLEngine extends SSLEngine
implements SSLUtil.ProtocolIn
final int pos = dst.position();
final int limit = dst.limit();
final int len = Math.min(MAX_ENCRYPTED_PACKET_LENGTH, limit - pos);
- final ByteBuffer buf = ByteBuffer.allocateDirect(len);
try {
final long addr = Buffer.address(buf);
@@ -362,7 +359,6 @@ public final class OpenSSLEngine extends SSLEngine
implements SSLUtil.ProtocolIn
}
} finally {
buf.clear();
- ByteBufferUtils.cleanDirectBuffer(buf);
}
}
@@ -386,7 +382,6 @@ public final class OpenSSLEngine extends SSLEngine
implements SSLUtil.ProtocolIn
checkLastError();
}
} else {
- final ByteBuffer buf = ByteBuffer.allocateDirect(pending);
try {
final long addr = Buffer.address(buf);
@@ -403,7 +398,6 @@ public final class OpenSSLEngine extends SSLEngine
implements SSLUtil.ProtocolIn
}
} finally {
buf.clear();
- ByteBufferUtils.cleanDirectBuffer(buf);
}
}
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index e84918a8e5..f4b8814599 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -155,6 +155,10 @@
<fix>
Skip OpenSSLConf with BoringSSL since it is unsupported. (remm)
</fix>
+ <update>
+ Align buffer reuse of the OpenSSLEngine for tomcat-native with the FFM
+ code. (remm)
+ </update>
</changelog>
</subsection>
<subsection name="Jasper">
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]