On 9/29/17 1:49 PM, Remi Forax wrote:
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.
The case that Peter observed is when "this" is being optimized out and becomes unreachable before setDictionary is called. Since setDictionary is a JNI function, the caller has to pass this (as jobject) to the native function. Would that cover this special case? Mandy