Skip to content

8210765: Remove finalize method in CStrike.java #26397

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

Closed
wants to merge 2 commits into from

Conversation

prrace
Copy link
Contributor

@prrace prrace commented Jul 18, 2025

Remove finalize method from CStrike.java

This one is a bit odd in that there's already a Disposer used - and in fact it involves two classes
CStrikeDisposer.java and its subclass - the nested class CStrike.GlyphInfoCache
CStrike.GlyphInfoCache is tracking all the glyph image references.

CStrikeDisposer has the full set of constructors of its superclass - FontStrikeDisposer including support
for the native context

And if supplied, CStrikeDisposer will call the native method freeNativeScalerContext(long) to free the native context
but that native method does not exist !
And there's no CStrike.GlyphInfoCache constructor which allows it to be specified

So the fix is to add that and call the disposeNativeStrikePtr method instead.

I also rejigged things a little so nativeStrikePtr could be final which is supposed to help with the thread visibility.


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

Issue

  • JDK-8210765: Remove finalize method in CStrike.java (Bug - P4)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 26397

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Jul 18, 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 Jul 18, 2025

@prrace This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8210765: Remove finalize method in CStrike.java

Reviewed-by: psadhukhan, achung, azvegint

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 206 new commits pushed to the master branch:

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot changed the title 8210765 8210765: Remove finalize method in CStrike.java Jul 18, 2025
@openjdk openjdk bot added the rfr Pull request is ready for review label Jul 18, 2025
@openjdk
Copy link

openjdk bot commented Jul 18, 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.

@mlbridge
Copy link

mlbridge bot commented Jul 18, 2025

Webrevs

@prrace prrace marked this pull request as draft July 19, 2025 21:03
@openjdk openjdk bot removed the rfr Pull request is ready for review label Jul 19, 2025
@prrace
Copy link
Contributor Author

prrace commented Jul 19, 2025

/label remove rfr
Not ready yet

@openjdk
Copy link

openjdk bot commented Jul 19, 2025

@prrace
The label rfr is not a valid label.
These labels are valid:

  • graal
  • serviceability
  • hotspot
  • hotspot-compiler
  • ide-support
  • i18n
  • shenandoah
  • jdk
  • javadoc
  • security
  • hotspot-runtime
  • jmx
  • build
  • nio
  • client
  • core-libs
  • compiler
  • net
  • hotspot-gc
  • hotspot-jfr

@prrace prrace marked this pull request as ready for review July 21, 2025 16:45
@openjdk openjdk bot added the rfr Pull request is ready for review label Jul 21, 2025
if (nativeStrikePtr != 0) {
return nativeStrikePtr;
}
return nativeStrikePtr;
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason this check was removed?
I see that initNativeStrikePtr will call createNativeStrikePtr which does this where there is no null check and it just returns what it gets so shouldn't we check it here?

awtStrike = [AWTStrike awtStrikeForFont:awtFont tx:glyphTx invDevTx:invDevTx style:style aaStyle:aaStyle]; // autoreleased

    if (awtStrike)
    {
        CFRetain(awtStrike); // GC
    }

JNI_COCOA_EXIT(env);
    return ptr_to_jlong(awtStrike);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And if it is 0, what would you do ?
Previously 0 meant it hadn't yet been initialized. Now it is always initialized.

You'd need to return it anyway even it was zero.

Copy link
Contributor

Choose a reason for hiding this comment

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

Then I guess whoever is using the nativeStrikePtr should account for that it can receive null or 0..
I haven't seen all cases but one case I saw getFontMetrics calls getFontMetrics(getNativeStrikePtr())
and there it does this where it dereference awtStrikePtr...Shouldn't it cause SIGSEGV if it ever becomes 0?

JNIEXPORT jobject JNICALL
Java_sun_font_CStrike_getFontMetrics
    (JNIEnv *env, jclass clazz, jlong awtStrikePtr)
{
    jobject metrics = NULL;

JNI_COCOA_ENTER(env);
    AWT_FONT_CLEANUP_SETUP;

    AWTFont *awtfont = ((AWTStrike *)jlong_to_ptr(awtStrikePtr))->fAWTFont;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nothing is different than before.
We return the result of calling createNativeStrikePtr() both before and after this fix.
So this is a pre-existing issue and one that I am not sure is very likely.
It would require the native alloc for the Objective C object to fail.
And it probably would require all callers to be ready to handle it.
Dealing with that pre-existing theoretical problem is well outside the scope of this.

Copy link
Contributor

@prsadhuk prsadhuk left a comment

Choose a reason for hiding this comment

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

Guess wildcard import and copyright year fix can be done..

@prrace
Copy link
Contributor Author

prrace commented Aug 1, 2025

Guess wildcard import and copyright year fix can be done..

I'm not going looking for clean up here.

Copy link
Contributor

@alisenchung alisenchung left a comment

Choose a reason for hiding this comment

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

I ran clientlibs test and everything looks good

Copy link
Contributor

@prsadhuk prsadhuk left a comment

Choose a reason for hiding this comment

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

LGTM

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Aug 3, 2025
@prrace
Copy link
Contributor Author

prrace commented Aug 4, 2025

/integrate

@openjdk
Copy link

openjdk bot commented Aug 4, 2025

Going to push as commit 0d0d93e.
Since your change was applied there have been 209 commits pushed to the master branch:

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Aug 4, 2025
@openjdk openjdk bot closed this Aug 4, 2025
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Aug 4, 2025
@openjdk
Copy link

openjdk bot commented Aug 4, 2025

@prrace Pushed as commit 0d0d93e.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
client [email protected] integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

4 participants