On Mon, 15 Nov 2021 21:35:06 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 incrementally with two additional 
> commits since the last revision:
> 
>  - Use ForceGC instead of System.gc()
>  - Convert test to testng

> A patch is worth a thousand words. Here's what I meant when I said this could 
> be elegantly solved with ClassValue:
> 
> [plevart@6e16e5e](https://github.com/plevart/jdk/commit/6e16e5e526c7f3d868b16543f2f3418c751068e4)
> 
> Note this is not tested. Just an idea.

Very nice!
I've merged your change, it passes the testcase, and I've also run tier1 
successfully. I'm testing it more. Do you want to take over? It's mostly your 
change now, anyway (except for the testcase). Or do you want me to finish it?

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

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

Reply via email to