Class IovArrayReferenceCollector

java.lang.Object
io.netty.channel.uring.IovArrayReferenceCollector
All Implemented Interfaces:
ChannelOutboundBuffer.MessageProcessor

final class IovArrayReferenceCollector extends Object implements ChannelOutboundBuffer.MessageProcessor
Fills the IoUringIoHandler's IovArray from flushed outbound messages and records the ByteBuf behind each entry it added, so the caller can copy those references into a WriteOperation slot once the SQE is built.

One instance per IoUringIoHandler, matching the IovArray it wraps: the handler hands out the same IovArray instance 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 a reset() and the WriteOperation record call that copies its references out -- the caller then resets it from a finally that 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 Details

    • iovArray

      private final IovArray iovArray
    • references

      private ReferenceCounted[] references
    • count

      private int count
  • Constructor Details

    • IovArrayReferenceCollector

      IovArrayReferenceCollector(IovArray iovArray)
  • Method Details

    • 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 stale ByteBuf references reachable through the backing array until the next reset, which risks promoting them into an old generation.
    • processMessage

      public boolean processMessage(Object msg) throws Exception
      Description copied from interface: ChannelOutboundBuffer.MessageProcessor
      Will be called for each flushed message until it either there are no more flushed messages or this method returns false.
      Specified by:
      processMessage in interface ChannelOutboundBuffer.MessageProcessor
      Throws:
      Exception
    • recordIfAdded

      private void recordIfAdded(Object msg, int previousCount)
      Records the buffer behind msg once IovArray actually gained an entry for it. Split out of processMessage(Object) so that method stays under HotSpot's default inline size threshold (35 bytes), which it exceeded with the if check 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 of add(ByteBuf) so that method stays under HotSpot's default inline size threshold (35 bytes); growing is genuinely the rare branch here, since reset() clears the array in place for reuse instead of shrinking it back down.