RFR: 6543126: Level.known can leak memory

Daniel Fuchs daniel.fuchs at oracle.com
Tue Aug 16 13:14:11 UTC 2016


Hi Peter,

On 16/08/16 13:52, Peter Levart wrote:
> Ah, I see. Right. Of course, my bad.
>
> In that case, there is a possible race that could lead to exception here:
>
>  476             // add new Level.
>  477             Level levelObject = new Level(name, x);
>  478             return KnownLevel.findByValue(x,
> KnownLevel::referent).get();
>
> ...between lines 477 and 478 and between lines 377 and 378, the newly
> constructed Level object could already get GC-ed and so findByValue
> could return an empty Optional.
>
> You should do something like:
>
> Level levelObject = new Level(name, x);
> Level result = KnownLevel.findByValue(x, KnownLevel::referent).get();
> Reference.reachabilityFence(levelObject);
> return result;

That's what I did in the very first version of the patch,
but Chris commented that this was unnecessary because when
level.getClass() == Level.class then levelObject == mirroredLevel.
Chris found that using Reference.reachabilityFence(levelObject)
just added more mystery - so I removed the statement.

best regards,

-- daniel

>
>
> Regards, Peter



More information about the core-libs-dev mailing list