RFR 9: 8165641 : Deprecate Object.finalize

Mandy Chung mandy.chung at oracle.com
Tue Mar 14 20:13:24 UTC 2017


> On Mar 14, 2017, at 10:37 AM, Stuart Marks <stuart.marks at oracle.com> wrote:
> 
> Tagir Valeev asked on Twitter whether System.runFinalization() and Runtime.runFinalization() should also be deprecated. The obvious answer is "yes" since we're deprecating finalization, but maybe it's not so obvious.
> 
> One view is that we're not deprecating the entire finalization mechanism, we're simply deprecating Object.finalize() and its overrides. The point of doing this is to encourage code to migrate away from these methods. Code that calls runFinalization() can't rely on it having many semantics, so such calls are harmless. (Well, mostly harmless.) Encouraging migration away from runFinalization() thus isn't necessary.
> 

I agree deprecating runFinalization() isn’t necessary in this proposed patch.  Deprecating Object.finalize would encourage existing code to migrate away from finalizers as well as discourage new code to add any new finalizer.

> Another point is that "finalization" in a generic sense can be applied to reference processing, not just calls to the finalize() method.

Hmm..  I am not sure what this exactly means here.  But there would be lot to figure out what happens next and what baby steps to take.  

> Offhand I'm not sure what runFinalization() does today, but perhaps in the future it could be modified to have stronger semantics regarding reference processing -- which is one of the big unresolved issues in this area.
> 

I don’t know about this.  Certainly it would be something to look into.

Mandy

> What do you think?
> 
> s'marks
> 
> On 3/10/17 1:40 PM, Roger Riggs wrote:
>> Finalizers are inherently problematic and their use can lead to performance issues,
>> deadlocks, hangs, and other problematic behavior.
>> 
>> The problems have been accumulating for many years and the first step to
>> deprecate Object.finalize and the overrides in the JDK to communicate the
>> issues, recommend alternatives, and motivate changes where finalization is
>> currently used.
>> 
>> The behavior of finalization nor any uses of finalize are not modified by this
>> change.
>> Most of the changes are to suppress compilation warnings within the JDK.
>> 
>> Please review and comment.
>> 
>> Webrev:
>> http://cr.openjdk.java.net/~rriggs/webrev-finalize-deprecate-8165641/
>> 
>> Issue:
>>   https://bugs.openjdk.java.net/browse/JDK-8165641
>> 
>> Thanks, Roger
>> 
>> 



More information about the core-libs-dev mailing list