Class HybridJacksonPool

java.lang.Object
io.vertx.core.json.jackson.HybridJacksonPool
All Implemented Interfaces:
com.fasterxml.jackson.core.util.RecyclerPool<com.fasterxml.jackson.core.util.BufferRecycler>, Serializable

public class HybridJacksonPool extends Object implements com.fasterxml.jackson.core.util.RecyclerPool<com.fasterxml.jackson.core.util.BufferRecycler>
This is a custom implementation of the Jackson's RecyclerPool intended to work equally well with both platform and virtual threads. This pool works regardless of the version of the JVM in use and internally uses 2 distinct pools one for platform threads (which is exactly the same ThreadLocal based one provided by Jackson out of the box) and the other designed for being virtual threads friendly. It switches between the 2 only depending on the nature of thread (virtual or not) requiring the acquisition of a pooled resource, obtained via MethodHandle to guarantee compatibility also with old JVM versions. The pool also guarantees that the pooled resource is always released to the same internal pool from where it has been acquired, regardless if the releasing thread is different from the one that originally made the acquisition.

The virtual thread friendly inner pool is implemented with N striped linked lists using a simple lock free algorithm based on CAS. The striping is performed shuffling the id of the thread requiring to acquire a pooled resource with a xorshift based computation. The resulting of this computation is also stored in the pooled resource, bringing the twofold advantage of always releasing the resource in the same bucket from where it has been taken regardless if the releasing thread is different from the one that did the acquisition and avoiding the need of recalculating the position of that bucket also during the release. The heads of the linked lists are hold in an AtomicReferenceArray where each head has a distance of 16 positions from the adjacent ones to prevent the false sharing problem.

See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
     

    Nested classes/interfaces inherited from interface com.fasterxml.jackson.core.util.RecyclerPool

    com.fasterxml.jackson.core.util.RecyclerPool.BoundedPoolBase<P extends com.fasterxml.jackson.core.util.RecyclerPool.WithPool<P>>, com.fasterxml.jackson.core.util.RecyclerPool.ConcurrentDequePoolBase<P extends com.fasterxml.jackson.core.util.RecyclerPool.WithPool<P>>, com.fasterxml.jackson.core.util.RecyclerPool.LockFreePoolBase<P extends com.fasterxml.jackson.core.util.RecyclerPool.WithPool<P>>, com.fasterxml.jackson.core.util.RecyclerPool.NonRecyclingPoolBase<P extends com.fasterxml.jackson.core.util.RecyclerPool.WithPool<P>>, com.fasterxml.jackson.core.util.RecyclerPool.StatefulImplBase<P extends com.fasterxml.jackson.core.util.RecyclerPool.WithPool<P>>, com.fasterxml.jackson.core.util.RecyclerPool.ThreadLocalPoolBase<P extends com.fasterxml.jackson.core.util.RecyclerPool.WithPool<P>>, com.fasterxml.jackson.core.util.RecyclerPool.WithPool<P extends com.fasterxml.jackson.core.util.RecyclerPool.WithPool<P>>
  • Method Summary

    Modifier and Type
    Method
    Description
    com.fasterxml.jackson.core.util.BufferRecycler
     
    com.fasterxml.jackson.core.util.BufferRecycler
     
     
    void
    releasePooled(com.fasterxml.jackson.core.util.BufferRecycler bufferRecycler)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface com.fasterxml.jackson.core.util.RecyclerPool

    clear, pooledCount
  • Method Details

    • getInstance

      public static HybridJacksonPool getInstance()
    • acquirePooled

      public com.fasterxml.jackson.core.util.BufferRecycler acquirePooled()
      Specified by:
      acquirePooled in interface com.fasterxml.jackson.core.util.RecyclerPool<com.fasterxml.jackson.core.util.BufferRecycler>
    • acquireAndLinkPooled

      public com.fasterxml.jackson.core.util.BufferRecycler acquireAndLinkPooled()
      Specified by:
      acquireAndLinkPooled in interface com.fasterxml.jackson.core.util.RecyclerPool<com.fasterxml.jackson.core.util.BufferRecycler>
    • releasePooled

      public void releasePooled(com.fasterxml.jackson.core.util.BufferRecycler bufferRecycler)
      Specified by:
      releasePooled in interface com.fasterxml.jackson.core.util.RecyclerPool<com.fasterxml.jackson.core.util.BufferRecycler>