Uploaded image for project: 'XWiki Commons'
  1. XWiki Commons
  2. XCOMMONS-3938

Cache bean descriptors with ClassValue instead of SoftCache

    XMLWordPrintable

Details

    • Improvement
    • Resolution: Fixed
    • Major
    • 19.0.0-rc-1
    • 17.10.0
    • Properties
    • None
    • Unit
    • Unknown
    • N/A
    • N/A

    Description

      DefaultBeanManager caches the BeanDescriptor computed for each bean class in a SoftCache, a map with soft keys and values protected by a read/write lock, introduced in XCOMMONS-1481 so that the cache doesn't prevent classes coming from extensions or scripts from being garbage collected.

      The JDK provides a dedicated mechanism for associating a computed value with a class: java.lang.ClassValue. Using it simplifies the code:

      • The descriptor is stored in the Class object itself, so it is released exactly when the class (and its class loader) is garbage collected, instead of being held through soft references until the JVM runs short of memory, which could keep classes of an old class loader in the cache.
      • Lookups are lock-free and the descriptor is computed once per class: when several threads compute it concurrently, all of them get the same instance.

      No behavior change is expected; this issue exists for traceability.

      Attachments

        Issue Links

          Activity

            People

              MichaelHamann Michael Hamann
              MichaelHamann Michael Hamann
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: