This is an automated email from the ASF dual-hosted git repository.
remm pushed a commit to branch 11.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/11.0.x by this push:
new 2a13740f70 Align buffer use pattern with the FFM code
2a13740f70 is described below
commit 2a13740f706650515c5e3778b842077db117aa45
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 e95416ec92..06bdfefdc6 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -134,6 +134,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>
</section>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]