Skip to content

8365292: Remove javax.imageio.spi.ServiceRegistry.finalize() #26752

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

prrace
Copy link
Contributor

@prrace prrace commented Aug 12, 2025

Remove javax.imageio.spi.ServiceRegistry.finalize() since it is deprecated for removal.
The impact of this should be minimal. The IIORegistry will now be a singleton - which it already was
in practice since Applets are no longer supported. Since it is a singleton, it will persist for the life
of the VM, so will never be garbage collected.
A test that verifies one per-AppContext is now obsolete, and is deleted, and there's no good reason to make it a negative test, since in due course AppContext itself will be deleted and is un-used today except in tests.

Since JDK 9, ServiceRegistry has supported only Image I/O specified providers, and since the IIORegistry does this,
in practice there is very little reason for an application to create instances or subclasses of it.
And even if they do, typically like IIORegistry, they be used for the life time of the application.
And if they are collected, without calling ServiceRegistry.deregisterAll() there may be no impact,
since only providers that implement RegisterableService will be affected.

See the JBS issue for all the details.

The CSR is ready for review https://bugs.openjdk.org/browse/JDK-8365409


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change requires CSR request JDK-8365409 to be approved

Issues

  • JDK-8365292: Remove javax.imageio.spi.ServiceRegistry.finalize() (Bug - P4)
  • JDK-8365409: Remove javax.imageio.spi.ServiceRegistry.finalize() (CSR)

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/26752/head:pull/26752
$ git checkout pull/26752

Update a local copy of the PR:
$ git checkout pull/26752
$ git pull https://git.openjdk.org/jdk.git pull/26752/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 26752

View PR using the GUI difftool:
$ git pr show -t 26752

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/26752.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Aug 12, 2025

👋 Welcome back prr! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Aug 12, 2025

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

@openjdk openjdk bot changed the title 8365292 8365292: Remove javax.imageio.spi.ServiceRegistry.finalize() Aug 12, 2025
@@ -78,7 +78,7 @@
* proxy for the heavyweight service.
*
* <p> An application may customize the contents of a registry as it
* sees fit, so long as it has the appropriate runtime permission.
* sees fit.
*
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing the above text is not related to finalization, but the text is meaningless since the SecurityManager was permanently disabled, so I will take this opportunity to remove it.

@openjdk
Copy link

openjdk bot commented Aug 12, 2025

@prrace The following label will be automatically applied to this pull request:

  • client

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added client [email protected] rfr Pull request is ready for review labels Aug 12, 2025
@mlbridge
Copy link

mlbridge bot commented Aug 12, 2025

Webrevs

@openjdk openjdk bot added the csr Pull request needs approved CSR before integration label Aug 12, 2025
@@ -105,25 +104,18 @@ private IIORegistry() {
registerApplicationClasspathSpis();
}

private static final IIORegistry registry;
static {
registry = new IIORegistry();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Constructor of IIORegistry executes a large amount of code, might be better to load it lazily as before? instead of from the class initialization. could be a good opportunity to use StableValue?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about that whilst making the change, but
(1) The javax.imagio.ImageIO class has this code

private static final IIORegistry theRegistry =  IIORegistry.getDefaultInstance();

So it is going to get initialized really early on in virtually all uses of ImageIO, so doing as I did seems fine.

(2) The code in getDefaultInstance() is now going to run 1,000 times faster than it did before so stable value to get it running 2,000 times faster probably is not necessary. And in any case, the version cached on ImageIO is what is going to be used. Hmm, it probably should not have been doing that as it defeated the AppContext, but it doesn't matter now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not worried much about performance, but I am concerned about the possibility of a deadlock in static initializers, since the services loaded by the IIORegistry can trigger any code.

btw why not "private static final IIORegistry registry = new IIORegistry();"?

@openjdk openjdk bot removed the csr Pull request needs approved CSR before integration label Aug 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
client [email protected] rfr Pull request is ready for review
Development

Successfully merging this pull request may close these issues.

2 participants