Class ClassInfoCache

java.lang.Object
com.sun.corba.ee.impl.misc.ClassInfoCache

public class ClassInfoCache extends Object
This class caches information about classes that is somewhat expensive to obtain, notably the results of isInterface(), isArray(), and isAssignableFrom. A user simply calls ClassInfoCache.get( Class ) to get the information about a class.

All of the isA methods on ClassInfo need to be passed the same Class that was used in the get call! This is an awkward interface, but the alternative is to store the class in the ClassInfo, which would create a strong reference from the value to the key, making the WeakHashMap useless. It also appears to be difficult to use a weak or soft reference here, because I can't handle the case of an empty reference to the class inside the ClassInfo object. If ClassInfoCache supported the methods directly, we could work around this, but then we would in some case be doing multiple lookups for a class to get class information, which would slow things down significantly (the get call is a significant cost in the benchmarks).

XXX There is a better solution: add MORE information to the cache. In particular, use a ClassAnalyzer to construct the linearized inheritance chain (order doesn't matter in this case, but we already have the implementation) and implement all of the isA methods by a simple check on whether the class is in the chain (or perhaps convert to Set). We can statically fill the cache with all of the basic objects (e.g. Streamable, Serializable, etc.) needs in a static initializer.

  • Field Details

  • Constructor Details

    • ClassInfoCache

      public ClassInfoCache()
  • Method Details

    • get

      public static ClassInfoCache.ClassInfo get(Class<?> cls)
    • getEnumClass

      public static Class getEnumClass(ClassInfoCache.ClassInfo cinfo, Class cls)
      Find the class that is an enum in the superclass chain starting at cls. cinfo MUST be the ClassInfo for cls.
      Parameters:
      cinfo - ClassInfo for cls
      cls - Class which may have java.lang.Enum in its superclass chain.
      Returns:
      A class for which isEnum() is true, or null if no such class exists in the superclass chain of cls.