> De: "Peter Levart" <peter.lev...@gmail.com>
> À: "Remi Forax" <fo...@univ-mlv.fr>, "mandy chung" <mandy.ch...@oracle.com>
> Cc: "Xueming Shen" <xueming.s...@oracle.com>, "core-libs-dev"
> <core-libs-dev@openjdk.java.net>
> Envoyé: Vendredi 29 Septembre 2017 22:56:26
> Objet: Re: RFR JDK-8185582, Update Zip implementation to use Cleaner, not
> finalizers

> Hi Remi,
Hi Peter, 

> On 09/29/17 22:49, Remi Forax wrote:

>> ----- Mail original -----

>>> De: "mandy chung" [ mailto:mandy.ch...@oracle.com | 
>>> <mandy.ch...@oracle.com> ]
>>> À: "Peter Levart" [ mailto:peter.lev...@gmail.com | 
>>> <peter.lev...@gmail.com> ]
>>> , "Xueming Shen" [ mailto:xueming.s...@oracle.com | 
>>> <xueming.s...@oracle.com> ]
>>> , "core-libs-dev" [ mailto:core-libs-dev@openjdk.java.net |
>>> <core-libs-dev@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.
I do not think that you are wrong now but this is a property (a side effect) of 
the current implementation, Panama and Metropolis may change that. 
I think it's better to keep the reference available with a reachability fence. 

> Regards, Peter
Rémi 

>> 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
>> |
>> http://docs.oracle.com/javase/9/docs/api/java/lang/ref/Reference.html#reachabilityFence-java.lang.Object
>> ] -

>>> Mandy

>> Rémi

Reply via email to