Package io.netty.channel.uring
Class IovArrayReferenceCollector
- java.lang.Object
-
- io.netty.channel.uring.IovArrayReferenceCollector
-
- All Implemented Interfaces:
ChannelOutboundBuffer.MessageProcessor
final class IovArrayReferenceCollector extends java.lang.Object implements ChannelOutboundBuffer.MessageProcessor
Fills theIoUringIoHandler'sIovArrayfrom flushed outbound messages and records theByteBufbehind each entry it added, so the caller can copy those references into aWriteOperationslot once the SQE is built.One instance per
IoUringIoHandler, matching theIovArrayit wraps: the handler hands out the sameIovArrayinstance to every channel it services, so a per-channel collector would be scoped smaller than the array it fills. This collector is only ever valid between areset()and theWriteOperationrecord call that copies its references out -- the caller then resets it from afinallythat also covers the submit, so every exit from the write path, including the ones that throw, leaves it empty. Without that reset this instance, being permanently owned by the event loop rather than any one channel, would keep the previous write's buffers reachable for as long as this event loop went without servicing another write.
-
-
Field Summary
Fields Modifier and Type Field Description private intcountprivate IovArrayiovArrayprivate ReferenceCounted[]references
-
Constructor Summary
Constructors Constructor Description IovArrayReferenceCollector(IovArray iovArray)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidadd(ByteBuf buffer)private voidgrow()Doubles the backing array once it fills up.booleanprocessMessage(java.lang.Object msg)Will be called for each flushed message until it either there are no more flushed messages or this method returnsfalse.private voidrecordIfAdded(java.lang.Object msg, int previousCount)Records the buffer behindmsgonceIovArrayactually gained an entry for it.(package private) ReferenceCounted[]referencesArray()(package private) intreferencesCount()(package private) voidreset()Drops the previous references, keeping the array for reuse.
-
-
-
Field Detail
-
iovArray
private final IovArray iovArray
-
references
private ReferenceCounted[] references
-
count
private int count
-
-
Constructor Detail
-
IovArrayReferenceCollector
IovArrayReferenceCollector(IovArray iovArray)
-
-
Method Detail
-
reset
void reset()
Drops the previous references, keeping the array for reuse. Nulls out the dropped entries too: otherwise a smaller write reusing the collector after a larger one would leave staleByteBufreferences reachable through the backing array until the next reset, which risks promoting them into an old generation.
-
processMessage
public boolean processMessage(java.lang.Object msg) throws java.lang.ExceptionDescription copied from interface:ChannelOutboundBuffer.MessageProcessorWill be called for each flushed message until it either there are no more flushed messages or this method returnsfalse.- Specified by:
processMessagein interfaceChannelOutboundBuffer.MessageProcessor- Throws:
java.lang.Exception
-
recordIfAdded
private void recordIfAdded(java.lang.Object msg, int previousCount)Records the buffer behindmsgonceIovArrayactually gained an entry for it. Split out ofprocessMessage(Object)so that method stays under HotSpot's default inline size threshold (35 bytes), which it exceeded with theifcheck below inlined.
-
referencesArray
ReferenceCounted[] referencesArray()
-
referencesCount
int referencesCount()
-
add
private void add(ByteBuf buffer)
-
grow
private void grow()
Doubles the backing array once it fills up. Split out ofadd(ByteBuf)so that method stays under HotSpot's default inline size threshold (35 bytes); growing is genuinely the rare branch here, sincereset()clears the array in place for reuse instead of shrinking it back down.
-
-