Class IovArrayReferenceCollector

  • All Implemented Interfaces:
    ChannelOutboundBuffer.MessageProcessor

    final class IovArrayReferenceCollector
    extends java.lang.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.

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void add​(ByteBuf buffer)  
      private void grow()
      Doubles the backing array once it fills up.
      boolean processMessage​(java.lang.Object msg)
      Will be called for each flushed message until it either there are no more flushed messages or this method returns false.
      private void recordIfAdded​(java.lang.Object msg, int previousCount)
      Records the buffer behind msg once IovArray actually gained an entry for it.
      (package private) ReferenceCounted[] referencesArray()  
      (package private) int referencesCount()  
      (package private) void reset()
      Drops the previous references, keeping the array for reuse.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 stale ByteBuf references reachable through the backing array until the next reset, which risks promoting them into an old generation.
      • recordIfAdded

        private void recordIfAdded​(java.lang.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.
      • 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.