Skip to content

8386972: [lworld] Finalizer should not be registered for value objects#2589

Open
fparain wants to merge 5 commits into
openjdk:lworldfrom
fparain:finalizer_registration
Open

8386972: [lworld] Finalizer should not be registered for value objects#2589
fparain wants to merge 5 commits into
openjdk:lworldfrom
fparain:finalizer_registration

Conversation

@fparain

@fparain fparain commented Jun 26, 2026

Copy link
Copy Markdown
Collaborator

Change in finalizers registration to prevent it for value classes.

Tested tier1-4.



Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed (1 review required, with at least 1 Committer)

Issue

  • JDK-8386972: [lworld] Finalizer should not be registered for value objects (Bug - P2)

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 2589

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

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/valhalla/pull/2589.diff

@bridgekeeper

bridgekeeper Bot commented Jun 26, 2026

Copy link
Copy Markdown

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

@openjdk

openjdk Bot commented Jun 26, 2026

Copy link
Copy Markdown

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

if (InstanceKlass::is_finalization_enabled() &&
(m != nullptr) && !m->is_empty_method()) {
(m != nullptr) && !m->is_empty_method() &&
m->method_holder()->access_flags().is_identity_class()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could we call ClassFileParser's is_identity_class() here instead of going through the method_holder?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Fred pointed out my proposed change actually changes the meaning as my proposal checks the current class, not the class that defines the finalize method. This is different for a finalize method from an abstract value class

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

A finalizer in an abstract value class should probably still be registered for identity subclasses; as otherwise, changing an abstract identity class with a finalizer to an abstract value class with a finalizer would be a breaking change as long as finalizers continue to exist.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

An abstract class with final fields may be good candidate to migrate to an abstract value class. If the abstract class relies on finalization then it is probably not a good candidate. If someone were to migrate without removing the dependency on finalization then it's not going to work as they might think as presumably the motivation for migrating the abstract class is to allow for subclasses to be value classes.

Right now, compiling an abstract value class with a finalize method emits a warning at compile-time to say that class should not have a finalize method as it will not be invoked (this is in addition to the removal warning that finalization is deprecated for removal). This will hopefully make developers aware that it doesn't work as they might think.

@openjdk

openjdk Bot commented Jul 1, 2026

Copy link
Copy Markdown

@fparain this pull request can not be integrated into lworld due to one or more merge conflicts. To resolve these merge conflicts and update this pull request you can run the following commands in the local repository for your personal fork:

git checkout finalizer_registration
git fetch https://git.openjdk.org/valhalla.git lworld
git merge FETCH_HEAD
# resolve conflicts and follow the instructions given by git merge
git commit -m "Merge lworld"
git push

@openjdk openjdk Bot added the merge-conflict Pull request has merge conflict with target branch label Jul 1, 2026
@AlanBateman

Copy link
Copy Markdown
Contributor

There are two tests in test/jdk/java/lang/Object/ValueObjects.java that are @Disabled for now. The @Disabled annotations can be removed when the changes here are integrated.

@fparain fparain marked this pull request as ready for review July 1, 2026 16:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-conflict Pull request has merge conflict with target branch

Development

Successfully merging this pull request may close these issues.

4 participants