Skip to content

Conversation

@rose00
Copy link
Contributor

@rose00 rose00 commented Dec 20, 2025

first cut: passes smoke tests in interpreter and C1 (aarch64)

https://bugs.openjdk.org/browse/JDK-8374169
too many intrinsics

Fold getIntAcquire and every other getFooBar into getPrimitiveBitsMO(mo, bt, base, offset).
Do similar moves for put and the various CAS operations.


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

Integration blocker

 ⚠️ Title mismatch between PR and JBS for issue JDK-8374169

Warning

 ⚠️ Found leading lowercase letter in issue title for 8374169: too many unsafe intrinsics (simplify unsafe intrinsic processing)

Issue

  • JDK-8374169: too many unsafe intrinsics (Enhancement - P4) ⚠️ Title mismatch between PR and JBS.

Reviewers without OpenJDK IDs

  • @khanbilal732 (no known openjdk.org user name / role) 🔄 Re-review required (review applies to d2f0c35a)

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 28940

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

Using diff file

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

@bridgekeeper
Copy link

bridgekeeper bot commented Dec 20, 2025

👋 Welcome back jrose! 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 Dec 20, 2025

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

@openjdk
Copy link

openjdk bot commented Dec 20, 2025

@rose00 The following labels will be automatically applied to this pull request:

  • core-libs
  • hotspot
  • nio

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

@rose00
Copy link
Contributor Author

rose00 commented Dec 21, 2025

Status:

No testing beyond looking for smoke when I run javac (in the changed VM).

I have not gone looking for inlining failures. I know they are endemic in C2.

I think the interpreter support (native methods) is stable, as are JDK code adjustments.

The vmIntrinsics.hpp declarations define a bunch of “polymorphic intrinsic wrappers” (F_PW).
I think we should eventually remove them all; there’s no value to this classification.
(But we should find a way to ensure that Unsafe wrappers never fail to inline!)

C2 support is not started yet. It should be relatively simple, as with C1.
When C2 is done, I will try to remove the old intrinsic names, and see what breaks.

The C1 support is nearly stable. Smoke test with javac passes.
The IR for CAS should be further simplified, to make it easier to consider cmpxchg.

I added some C1 canonicalization logic for back-to-back conversions.
For example, when you run javac on a small job, C1 simplifies 71 instances of l2i(i2l(x) ⇒ x.
It may be we can avoid adding those canonicalizations, but they do help the poly-intrinsics.

@rose00
Copy link
Contributor Author

rose00 commented Dec 21, 2025

Overall goal is to thin out the current Dark Forest of intrinsics, which has become overgrown.
Besides improving maintainability, my goal here is to prepare for new intrinsics in the future.
Keeping up with the hardware is too difficult, if you have to add a new intrinsic for every single instruction.
That why folding groups of single-instruction intrinsics to single polymorphic intrinsics
will help us keep up with hardware capabilities.

Copy link

@ExE-Boss ExE-Boss left a comment

Choose a reason for hiding this comment

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

I think the final modifier should be kept on the Unsafe methods to ease the burden on reviewing the git diff.


/** Special-access version of {@link #getInt(Object, long)} */
@ForceInline
public int getIntMO(byte memoryOrder, Object o, long offset) {
Copy link

@ExE-Boss ExE-Boss Dec 21, 2025

Choose a reason for hiding this comment

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

I think it might be better to keep these parametrised memory order implementation methods private without changing the Java API by changing @IntrinsicCandidate to @ForceInline on all the [get/put/compareAnd​[Set/⁠Exchange]]​<Type>​[/Opaque/Acquire/Release/Volatile] methods.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, exporting the primitive type polymorphism is too much, at least for now. (I know about the one public method that is still private.) The BT values can go private as well.

As you can see, I am experimenting with polymorphism of memory ordering, although I think we need to retain the Volatile versions of everything, which I find annoying. But the Plain Acquire Release and Opaque versions are just too niche-y; the power user that wants them needs to just use the new MO constants.

Regarding the final modifier, 1. it has no force since the class as a whole is already final, 2. it has been used inconsistently in the API to date, and 3. there is lots of review friction in this big changeset, which may require breaking it up into a queue of changesets. We’ll probably do that breakup when the time for integration comes closer.

The OP constants will stay public, to reduce the number of names while still providing full functionality. Also, RISC-V has min and max reduction ops (signed and unsigned) and that suggests to me that we are not done adding OP modes, for the get-and-operate API points.

@openjdk
Copy link

openjdk bot commented Dec 22, 2025

@rose00 shenandoah has been added to this pull request based on files touched in new commit(s).

@rose00 rose00 changed the title simplify unsafe intrinsic processing 8374169: too many unsafe intrinsics (simplify unsafe intrinsic processing) Dec 22, 2025
@rose00
Copy link
Contributor Author

rose00 commented Dec 22, 2025

One idea behind this new polymorphism of MO and BT and OP: The Unsafe API is not useful as an important arbitration point for what hardware operations are surfaced upward through the JDK. The JITs have a much more fundamental role as arbitration points. Unsafe “gets out of the way” by providing all reasonable combinations of MO and BT and OP, and then the JITs can make the call (following the evolution of hardware) what to expose.

In the previous configuration, get-and-bitop (bitop = and, xor, etc.) are provided by our major platforms, and yet they are inaccessible because Unsafe provides a choke-point that blocks them from the rest of the system.

BTW, get-and-max might be a good way to handle monotonically versioned values. And 128-bit atomics are here today, but not visible yet. Valhalla comes first to open up the possibilities for a 128-bit hyper-long, and then we can consider surfacing the 128-bit hardware primitives. Polymorphism makes it easy to climb the hill of functionality without slipping into a combinatorial swamp.

@rose00
Copy link
Contributor Author

rose00 commented Dec 22, 2025

BTW, I am not asking for anybody to press the Review button, yet. This is a draft review.

If you have a helpful comment, please do make it. (Thanks, ExE-Boss.)

But pressing the Review button, at this point, doesn’t help me with this task.

Also, pressing the review button with no comments is the same as adding a silly comment, identifying the button-presser as a noise source.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

3 participants