RFR JDK-8185582, Update Zip implementation to use Cleaner, not finalizers

Peter Levart peter.levart at gmail.com
Fri Sep 29 20:56:26 UTC 2017

Hi Remi,

On 09/29/17 22:49, Remi Forax wrote:
> ----- Mail original -----
>> De: "mandy chung" <mandy.chung at oracle.com>
>> À: "Peter Levart" <peter.levart at gmail.com>, "Xueming Shen" <xueming.shen at oracle.com>, "core-libs-dev"
>> <core-libs-dev at openjdk.java.net>
>> Envoyé: Vendredi 29 Septembre 2017 22:34:52
>> Objet: Re: RFR JDK-8185582, Update Zip implementation to use Cleaner, not finalizers
>> On 9/27/17 2:31 AM, Peter Levart wrote:
>>> Up to a point where 'this' is dereferenced to obtain the 'zsRef' value
>>> (line 261), the Deflater instance is reachable. But after that, even
>>> ensureOpen() may be inlined and 'this' is not needed any more. After
>>> that point, obtaining zsRef.address() and calling setDictionaly on the
>>> obtained address may be racing with Cleaner thread invoking
>>> ZStreamRef.run():
>> What about making the native setDictionary method as an instance method
>> (currently it's a static method) so that this object remains strongly
>> reachable until the method returns?
> Mandy,
> unlike in C or C++, in Java a reference is garbage collected as soon as you do not need it anymore,
> so using an instance method will not change the issue here.

I might be wrong, but native instance method is an exception. It can't 
be inlined. The preparation for native method invocation makes sure 
'this' is kept reachable because it can be dereferenced from the native 
code then and native code is out-of-bounds for JIT optimization.

Regards, Peter

> one way to be sure that a referenced object is not garbage collected is to use
> http://docs.oracle.com/javase/9/docs/api/java/lang/ref/Reference.html#reachabilityFence-java.lang.Object-
>> Mandy
> Rémi

More information about the core-libs-dev mailing list