Skip to content

Commit e067460

Browse files
committed
Align buffer use pattern with the FFM code
This uses 18KB of memory per connection.
1 parent 285098c commit e067460

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

java/org/apache/tomcat/util/net/openssl/OpenSSLEngine.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ enum ClientAuthMode {
135135
private final long ssl;
136136
private final long networkBIO;
137137
private final long aprGeneration;
138+
private ByteBuffer buf = ByteBuffer.allocateDirect(MAX_ENCRYPTED_PACKET_LENGTH);
138139

139140
private enum Accepted {
140141
NOT,
@@ -234,6 +235,7 @@ public synchronized void shutdown() {
234235
Library.returnCleanUpLock();
235236
}
236237
}
238+
ByteBufferUtils.cleanDirectBuffer(buf);
237239
}
238240
}
239241

@@ -260,7 +262,6 @@ private int writePlaintextData(final long ssl, final ByteBuffer src) throws SSLE
260262
return sslWrote;
261263
}
262264
} else {
263-
ByteBuffer buf = ByteBuffer.allocateDirect(len);
264265
try {
265266
final long addr = Buffer.address(buf);
266267

@@ -281,7 +282,6 @@ private int writePlaintextData(final long ssl, final ByteBuffer src) throws SSLE
281282
}
282283
} finally {
283284
buf.clear();
284-
ByteBufferUtils.cleanDirectBuffer(buf);
285285
}
286286
}
287287

@@ -308,7 +308,6 @@ private int writeEncryptedData(final long networkBIO, final ByteBuffer src) thro
308308
return netWrote;
309309
}
310310
} else {
311-
ByteBuffer buf = ByteBuffer.allocateDirect(len);
312311
try {
313312
final long addr = Buffer.address(buf);
314313

@@ -326,7 +325,6 @@ private int writeEncryptedData(final long networkBIO, final ByteBuffer src) thro
326325
}
327326
} finally {
328327
buf.clear();
329-
ByteBufferUtils.cleanDirectBuffer(buf);
330328
}
331329
}
332330

@@ -355,7 +353,6 @@ private int readPlaintextData(final long ssl, final ByteBuffer dst) throws SSLEx
355353
final int pos = dst.position();
356354
final int limit = dst.limit();
357355
final int len = Math.min(MAX_ENCRYPTED_PACKET_LENGTH, limit - pos);
358-
final ByteBuffer buf = ByteBuffer.allocateDirect(len);
359356
try {
360357
final long addr = Buffer.address(buf);
361358

@@ -371,7 +368,6 @@ private int readPlaintextData(final long ssl, final ByteBuffer dst) throws SSLEx
371368
}
372369
} finally {
373370
buf.clear();
374-
ByteBufferUtils.cleanDirectBuffer(buf);
375371
}
376372
}
377373

@@ -396,7 +392,6 @@ private int readEncryptedData(final long networkBIO, final ByteBuffer dst, final
396392
checkLastError();
397393
}
398394
} else {
399-
final ByteBuffer buf = ByteBuffer.allocateDirect(pending);
400395
try {
401396
final long addr = Buffer.address(buf);
402397

@@ -413,7 +408,6 @@ private int readEncryptedData(final long networkBIO, final ByteBuffer dst, final
413408
}
414409
} finally {
415410
buf.clear();
416-
ByteBufferUtils.cleanDirectBuffer(buf);
417411
}
418412
}
419413

webapps/docs/changelog.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,14 @@
105105
issues do not "pop up" wrt. others).
106106
-->
107107
<section name="Tomcat 9.0.117 (remm)" rtext="in development">
108+
<subsection name="Coyote">
109+
<changelog>
110+
<update>
111+
Align buffer reuse of the OpenSSLEngine for tomcat-native with the FFM
112+
code. (remm)
113+
</update>
114+
</changelog>
115+
</subsection>
108116
</section>
109117
<section name="Tomcat 9.0.116 (remm)" rtext="release in progress">
110118
<subsection name="Catalina">

0 commit comments

Comments
 (0)