JDK-4809008 : Introspector cache should be cleared without explicit flush methods calls
  • Type: Enhancement
  • Component: client-libs
  • Sub-Component: java.beans
  • Affected Version: 5.0
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: solaris_8
  • CPU: sparc
  • Submitted: 2003-01-28
  • Updated: 2008-11-05
  • Resolved: 2003-08-09
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
5.0 tigerFixed
Related Reports
Relates :  
Relates :  
Relates :  
Relates :  
Description
JDK 1.4.1 API doc has following description about Introspector cache.
--------------------------------------------------------------------------------------
http://java.sun.com/j2se/1.4.1/docs/api/java/beans/Introspector.html

Because the Introspector caches BeanInfo classes for better performance, 
take care if you use it in an application that uses multiple class loaders. 
In general, when you destroy a ClassLoader that has been used to introspect classes, 
you should use the Introspector.flushCaches or Introspector.flushFromCaches method 
to flush all of the introspected classes out of the cache. 
--------------------------------------------------------------------------------------
A licensee had a server crash issue on their J2EE application server
using many class loaders and wants us to improve the way Introspector 
flushes its cache.

They claim that an application server does not know if user application 
uses Introspector or not. Thus, they want Introspector to flush cache by itself.

I have discussed this request with the responsible engineer and
got two suggestions for Tiger (J2SE 1.5) from him.

1. Adding new flushCaches(ClassLoader) method to API.
    This will be useful for short life time ClassLoaders.
    Current two methods, flushCaches() and flushCache(Class) have
    room for improvement. The flushCaches() clears everything and
    it is often too aggressive. To use the flushCache(Class),
    users have to keep references to all class objects.

2. Making Introspector detect removed ClassLoaders and call above 
   method internally (by itself).
    
I believe those two enhancements solve a licensee issue and would
like the bean team to work on it.

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: tiger FIXED IN: tiger INTEGRATED IN: tiger tiger-b15
14-06-2004

PUBLIC COMMENTS Strong references to Method, Method[], Class and Class[] have been changed to a combination of Soft and Weak refererences. ###@###.### 2003-07-31
31-07-2003

EVALUATION This issue has been discussed with the submitter over email during the past few months. There are many dimensions to this fix to make sure that it satisfies the removal of held class references when a class loader goes away but also ensures that the classes are not prematurely removed for classes that depend on BeanInfos held within the cache - litk the XML persistence. ###@###.### 2003-01-29 I have found a much better approach to this fix without having to add a new method. See suggested fix. Currently, all FeatureDescriptor subclasses which are held by the BeanInfo have a strong reference to the Method or a Class (or arrays of Methods and Classes). These strong references prevent the keys in the WeakHashMap static caches in the Introspector from being reclaimed. For example, the WeakHashMap that holds the BeanInfo cache looks like: key: Class value: BeanInfo->MethodDescriptor->Method->Class or key: Class value: BeanInfo->BeanDescriptor->Class Since the Descriptors hold strong references to Methods or Classes it will not be reclaimed when the classloader goes away. ###@###.### 2003-07-14
14-07-2003

SUGGESTED FIX The solution is to wrap all strong references to Class and Method and the arrays with Weak and Soft references and maintain enough information to reconstitute them when they have been reclaimed. A basic guideline that I've taken has been to wrap the Class references in WeakReferences since the reference will only be null when the class loader goes away. All the Class[], Method[] and Method references will be wrapped in SoftReferences since most of the time the descriptor will be the only reference to these Objects and a WeakReference will cause the garbage collection to reclaim those references too agressively. There has been a significant ammount of code that has to be changed to implement this fix. After testing all the issues, I have a solution which I feel is acceptable. For infrequent use of the Introspector, there will be no performance degradation. Heavy Introspector use will cause a very slight performance regression (~5%) as the SoftReferences loose the reference and have to be refetched. As part of this fix, I also implemented some Introspector optimizations. ###@###.### 2003-07-14
14-07-2003