Class SoftlyReferencingTypePoolCache

  • All Implemented Interfaces:
    net.bytebuddy.agent.builder.AgentBuilder.PoolStrategy

    public class SoftlyReferencingTypePoolCache
    extends net.bytebuddy.agent.builder.AgentBuilder.PoolStrategy.WithTypePoolCache
    Caches TypeDescriptions which speeds up type matching - especially when the matching requires lookup of other TypeDescriptions. Such as when in order to match a type, it's superclass has to be determined. Without a type pool cache those types would have to be re-loaded from the file system if their Class has not been loaded yet.

    In order to avoid OutOfMemoryErrors because of this cache, the TypePool.CacheProviders are wrapped in a SoftReference. If the underlying cache is being GC'ed, a new one is immediately being created instead, so to both prevent OOME and enable continuous caching. Any cache that is not being accessed for some time (configurable through constructor), is being cleared, so that caches don't occupy heap memory until there is a heap stress. This fits the typical pattern of most type matching occurring at the beginning of the agent attachment.

    • Nested Class Summary

      • Nested classes/interfaces inherited from class net.bytebuddy.agent.builder.AgentBuilder.PoolStrategy.WithTypePoolCache

        net.bytebuddy.agent.builder.AgentBuilder.PoolStrategy.WithTypePoolCache.Simple
      • Nested classes/interfaces inherited from interface net.bytebuddy.agent.builder.AgentBuilder.PoolStrategy

        net.bytebuddy.agent.builder.AgentBuilder.PoolStrategy.ClassLoading, net.bytebuddy.agent.builder.AgentBuilder.PoolStrategy.Default, net.bytebuddy.agent.builder.AgentBuilder.PoolStrategy.Eager, net.bytebuddy.agent.builder.AgentBuilder.PoolStrategy.WithTypePoolCache
    • Field Summary

      • Fields inherited from class net.bytebuddy.agent.builder.AgentBuilder.PoolStrategy.WithTypePoolCache

        readerMode
    • Constructor Summary

      Constructors 
      Constructor Description
      SoftlyReferencingTypePoolCache​(net.bytebuddy.pool.TypePool.Default.ReaderMode readerMode, int clearIfNotAccessedSinceMinutes, net.bytebuddy.matcher.ElementMatcher.Junction<java.lang.ClassLoader> ignoredClassLoaders)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected net.bytebuddy.pool.TypePool.CacheProvider locate​(java.lang.ClassLoader classLoader)  
      • Methods inherited from class net.bytebuddy.agent.builder.AgentBuilder.PoolStrategy.WithTypePoolCache

        equals, hashCode, typePool, typePool
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SoftlyReferencingTypePoolCache

        public SoftlyReferencingTypePoolCache​(net.bytebuddy.pool.TypePool.Default.ReaderMode readerMode,
                                              int clearIfNotAccessedSinceMinutes,
                                              net.bytebuddy.matcher.ElementMatcher.Junction<java.lang.ClassLoader> ignoredClassLoaders)
    • Method Detail

      • locate

        protected net.bytebuddy.pool.TypePool.CacheProvider locate​(java.lang.ClassLoader classLoader)
        Specified by:
        locate in class net.bytebuddy.agent.builder.AgentBuilder.PoolStrategy.WithTypePoolCache