On Wed, 1 Dec 2021 21:09:14 GMT, Roger Riggs <rri...@openjdk.org> wrote:

> Without the use of SoftReference, memory pressure won't release any of the 
> cached info. That seems to swing the other way from overly aggressively 
> freeing memory with the WeakReference (and needing to recompute) as the 
> change originally proposed. Its hard to tell in what environments it might be 
> observed.

Right. The problem with the original code was that the softreference would keep 
the class from getting unloaded, except when under pressure. Now that the 
cached value is tied to the object lifetime using ClassValue, we can relatively 
easily use SoftReference to also make it sensitive to memory pressure. I 
factored this code out into its own class to avoid making a mess, and to be 
able to reuse it in subclassAudits (see #6637).

> src/java.base/share/classes/java/io/ObjectStreamClass.java line 2133:
> 
>> 2131:             if (oldReflector != null) {
>> 2132:                 reflector = oldReflector;
>> 2133:             }
> 
> Map.computeIfAbsent(key, () -> new FieldReflector(matchFields, localDesc));
> might be more compact.

That would be nicer, indeed. Problem is that matchFields throws an 
InvalidClassException, and that would have to get passed through the lambda.
Also, that problem is pre-existing and not related to the change.

> test/jdk/java/io/ObjectStreamClass/TestOSCClassLoaderLeak.java line 52:
> 
>> 50:         Class<?> loadClass = 
>> myOwnClassLoader.loadClass("ObjectStreamClass_MemoryLeakExample");
>> 51:         Constructor con = loadClass.getConstructor();
>> 52:         con.setAccessible(true);
> 
> Isn't the constructor already public?

> 
Yes, but:

test TestOSCClassLoaderLeak.run(): failure
java.lang.IllegalAccessException: class TestOSCClassLoaderLeak cannot access a 
member of class ObjectStreamClass_MemoryLeakExample with modifiers "public"

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

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

Reply via email to