8245867: Logger/bundleLeak/BundleTest.java fails due to "OutOfMemoryError: Java heap space"

David Holmes david.holmes at oracle.com
Thu May 28 23:36:25 UTC 2020


Hi Daniel,

This caught my eye ...

On 28/05/2020 6:50 pm, Daniel Fuchs wrote:
> Hi,
> 
> Please find an almost trivial fix for:
> 
> 8245867: Logger/bundleLeak/BundleTest.java fails due
>           to "OutOfMemoryError: Java heap space"
> https://bugs.openjdk.java.net/browse/JDK-8245867
> 
> webrev:
> http://cr.openjdk.java.net/~dfuchs/webrev_8245867/webrev.00/
> 
> My new test for JDK-8239013 has been observed failing
> intermittently in OutOfMemory. The test needs to trigger
> the clearing of SoftReferences, and does so by eating
> up heap memory in order to trigger a GC that will
> clear them.

This seems to be assuming that the GC will clear all SoftReferences when 
it needs to clear any SoftReference. I don't think that is at all 
guaranteed. In theory your memory eating loop could be satisfied by 
clearing only the SoftReference added in the previous iteration of the loop.

I would have expected the fix here to be simply to clear memory ie:

} catch (OutOfMemoryError oome) {
   stop = true;
   memory = null;
   System.gc();
}

Cheers,
David

> The issue is that the test didn't release the memory
> when it no longer needed it, which caused trouble for
> the test harness when it tried to clean up after the
> test.
> 
> The fix is to use SoftReference to retain the eaten-up
> memory (instead of strong references) so that it can
> be reclaimed at the time the full GC that clear soft
> references is triggered, and also to release the heap
> memory as soon as it is no longer needed.
> 
> best regards,
> 
> -- daniel


More information about the core-libs-dev mailing list