Skip to content

8362376: Use @Stable annotation in Java FDLIBM implementation #26341

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 3 commits into
base: master
Choose a base branch
from

Conversation

jddarcy
Copy link
Member

@jddarcy jddarcy commented Jul 16, 2025

Add @Stable to the static final arrays used in the Java port of FDLIBM.


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-8362376: Use @Stable annotation in Java FDLIBM implementation (Enhancement - P4)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 26341

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Jul 16, 2025

👋 Welcome back darcy! 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 16, 2025

@jddarcy This change is no longer ready for integration - check the PR body for details.

@openjdk openjdk bot changed the title JDK-8362376: Use @Stable annotation in Java FDLIBM implementation 8362376: Use @Stable annotation in Java FDLIBM implementation Jul 16, 2025
@jddarcy
Copy link
Member Author

jddarcy commented Jul 16, 2025

Some small refactorings could be used to make a few non-static arrays static.

@openjdk openjdk bot added the rfr Pull request is ready for review label Jul 16, 2025
@openjdk
Copy link

openjdk bot commented Jul 16, 2025

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

  • core-libs

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 the core-libs core-libs-dev@openjdk.org label Jul 16, 2025
@mlbridge
Copy link

mlbridge bot commented Jul 16, 2025

Webrevs

@jddarcy jddarcy marked this pull request as draft July 16, 2025 05:00
@openjdk openjdk bot removed the rfr Pull request is ready for review label Jul 16, 2025
@jddarcy jddarcy marked this pull request as ready for review July 16, 2025 17:47
@openjdk openjdk bot added the rfr Pull request is ready for review label Jul 16, 2025
@rose00
Copy link
Contributor

rose00 commented Jul 16, 2025

The effect of this PR is to make the affected array elements eligible for constant-folding by the JIT.

The contract of @Stable is private to the JDK, since it is a trusted annotation. The trusted user promises not to change the array elements after the JIT might have observed them.

If we had a frozen (immutable) array feature in the JVM this PR could be formulated using frozen array constants. But we are not there yet.

@jddarcy
Copy link
Member Author

jddarcy commented Jul 16, 2025

The effect of this PR is to make the affected array elements eligible for constant-folding by the JIT.

The contract of @Stable is private to the JDK, since it is a trusted annotation. The trusted user promises not to change the array elements after the JIT might have observed them.

If we had a frozen (immutable) array feature in the JVM this PR could be formulated using frozen array constants. But we are not there yet.

Yes; my intention was to allow HotSpot greater leeway to optimize the FDLIBM code. Under my limited performance testing, the change seemed to be performance neutral, but if it shouldn't cause a regression, I'd be comfortable pushing the change.

@jddarcy
Copy link
Member Author

jddarcy commented Jul 16, 2025

The methods directly affected by this update are atan, exp, and sin, cos, tan. The sin, cos, and tan method are affected by the updates to KernelRemPio2 and tan is also directly affected by its own updates.

Copy link
Contributor

@rgiulietti rgiulietti left a comment

Choose a reason for hiding this comment

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

The arrays at L.2257-2262 could be declared static and @Stable as well, and moved outside the method.

@@ -809,6 +814,7 @@ static final class KernelRemPio2 {

private static final int init_jk[] = {2, 3, 4, 6}; // initial value for jk
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
private static final int init_jk[] = {2, 3, 4, 6}; // initial value for jk
@Stable private static final int init_jk[] = {2, 3, 4, 6}; // initial value for jk

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
private static final int init_jk[] = {2, 3, 4, 6}; // initial value for jk
@Stable
private static final int[] init_jk = {2, 3, 4, 6}; // initial value for jk

Copy link
Member Author

Choose a reason for hiding this comment

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

Missed that array on my edit; will add. Thanks.

@@ -451,7 +453,8 @@ static double compute(double x) {
*/
private static final double
pio4 = 0x1.921fb54442d18p-1, // 7.85398163397448278999e-01
pio4lo= 0x1.1a62633145c07p-55, // 3.06161699786838301793e-17
pio4lo= 0x1.1a62633145c07p-55; // 3.06161699786838301793e-17
@Stable private static final double
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
@Stable private static final double
@Stable
private static final double

Copy link
Member

@liach liach left a comment

Choose a reason for hiding this comment

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

These additions look reasonable.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Jul 17, 2025
@rgiulietti
Copy link
Contributor

@jddarcy What about the local arrays mentioned in my comment above

The arrays at L.2257-2262 could be declared static and @Stable as well, and moved outside the method.

@liach
Copy link
Member

liach commented Jul 17, 2025

I think local arrays require more structural changes to the code, which might be why this patch did not include that change. However, note as said in #26355, such conversions are meaningful and would potentially allow performance boosts.

@jddarcy
Copy link
Member Author

jddarcy commented Jul 17, 2025

The arrays at L.2257-2262 could be declared static and @Stable as well, and moved outside the method.

Right; those were the ones I was referring to when I wrote "Some small refactorings could be used to make a few non-static arrays static." :-)

I wanted to just start with the static final arrays, but I could pull those out too in this PR.

@jddarcy
Copy link
Member Author

jddarcy commented Jul 17, 2025

I think local arrays require more structural changes to the code, which might be why this patch did not include that change. However, note as said in #26355, such conversions are meaningful and would potentially allow performance boosts.

Okay; I took a look at what the code was actually doing and wrote something that avoiding using arrays entirely.

@openjdk openjdk bot removed the ready Pull request is ready to be integrated label Jul 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core-libs core-libs-dev@openjdk.org rfr Pull request is ready for review
Development

Successfully merging this pull request may close these issues.

5 participants