On Tue, 30 Nov 2021 11:25:48 GMT, Roman Kennke <rken...@openjdk.org> wrote:

>> The caches in ObjectStreamClass basically map WeakReference<Class> to 
>> SoftReference<ObjectStreamClass>, where the ObjectStreamClass also 
>> references the same Class. That means that the cache entry, and thus the 
>> class and its class-loader, will not get reclaimed, unless the GC determines 
>> that memory pressure is very high.
>> 
>> However, this seems bogus, because that unnecessarily keeps ClassLoaders and 
>> all its classes alive much longer than necessary: as soon as a ClassLoader 
>> (and all its classes) become unreachable, there is no point in retaining the 
>> stuff in OSC's caches.
>> 
>> The proposed change is to use WeakReference instead of SoftReference for the 
>> values in caches.
>> 
>> Testing:
>>  - [x] tier1
>>  - [x] tier2
>>  - [x] tier3
>>  - [ ] tier4
>
> Roman Kennke has updated the pull request with a new target base due to a 
> merge or a rebase. The incremental webrev excludes the unrelated changes 
> brought in by the merge/rebase. The pull request contains six additional 
> commits since the last revision:
> 
>  - Merge remote-tracking branch 'jdk-plevart/JDK-8277072-peter' into 
> JDK-8277072
>  - Use ClassValue to solve JDK-8277072
>  - Use ForceGC instead of System.gc()
>  - Convert test to testng
>  - Fix indentation of new testcase
>  - 8277072: ObjectStreamClass caches keep ClassLoaders alive

...I think that you could remove now obsolete 
java.io.ObjectStreamClass.EntryFuture nested class. It's not used any more.

It would be nice to follow-up this patch with patches that make use of 
ClassValue also for:
- java.io.ObjectInputStream.Caches#subclassAudits
- java.io.ObjectOutputStream.Caches#subclassAudits

...this way the common static machinery like:
- java.io.ObjectStreamClass#processQueue
- java.io.ObjectStreamClass.WeakClassKey
...could get removed as it is not used in ObjectStreamClass any more.

-------------

PR: https://git.openjdk.java.net/jdk/pull/6375

Reply via email to