JDK-8276422 : Add command-line option to disable finalization
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.lang
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2021-11-02
  • Updated: 2021-12-22
  • Resolved: 2021-12-08
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 18 JDK 19
18 b27Fixed 19Fixed
Related Reports
Blocks :  
CSR :  
Sub Tasks
JDK-8277305 :  
JDK-8277365 :  
JDK-8277502 :  
JDK-8278574 :  
JDK-8278575 :  
Description
JEP 421 proposes to deprecate finalization for removal. As part of that work, it proposes a command-line option to disable finalization, so that developers can evaluate the effect on applications of not having finalization prior to its removal. This enhancement request covers the option.

The option would be as follows:

--finalization=<value>

Legal values are "enabled" and "disabled". The default value in this release will be "enabled". In a future release, the default value will change to "disabled". However, both values will be accepted in the current release. The option "--finalization=disabled" on the command line will disable finalization, and "--finalization=enabled" will do nothing, as finalization is enabled by default. Other values will cause an error. Additional valid values may be added in the future.

The effect of disabling finalization is as follows:

 * When a class is loaded into the JVM, the detection of a non-trivial finalize() method in the class is disabled. This prevents creation of finalization-related data structures by various GCs. This also disables the upcall to Finalizer::register, which prevents finalization-eligible objects from ever appearing on the heap. FinalReference processing will therefore not be done, and objects' finalize() methods won't be called.

 * The finalizer thread is not created.

 * Calls to `System::runFinalization` and `Runtime::runFinalization` have no effect.

The Java Platform Specification, the JLS, and the "java" tool reference page will be updated to document this option. See the CSR JDK-8276773 for details.

Comments
Changeset: d7ad5467 Author: Stuart Marks <smarks@openjdk.org> Date: 2021-12-08 00:27:53 +0000 URL: https://git.openjdk.java.net/jdk/commit/d7ad546758091ea16f836c9771ff5c03a32fb712
08-12-2021

I have a prototype that does this in the launcher, but it's probably a complete hack that will need to be rewritten. So yes it will probably need to be moved into arguments.cpp at some point, depending on exactly where the state resides, and this bug should get moved to the right hotspot category at that time.
03-11-2021

This will probably require the argument processing in src/hotspot/share/runtime/arguments.cpp rather than the launcher.
03-11-2021