Skip to content

Conversation

@eastig
Copy link
Member

@eastig eastig commented Nov 11, 2025

The instruction cache maintenance function internally handles any required barriers.
This means we don't need any barriers before calling it.
This PR removes a redundant OrderAccess::fence in ZBarrierSetAssembler::patch_barrier_relocation.


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-8371649: ZGC: AArch64: redundant OrderAccess::fence in ZBarrierSetAssembler::patch_barrier_relocation (Enhancement - P4)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 28244

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Nov 11, 2025

👋 Welcome back eastigeevich! 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 Nov 11, 2025

@eastig 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:

8371649: ZGC: AArch64: redundant OrderAccess::fence in ZBarrierSetAssembler::patch_barrier_relocation

Reviewed-by: aph

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 28 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
Copy link

openjdk bot commented Nov 11, 2025

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

  • hotspot

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 rfr Pull request is ready for review label Nov 11, 2025
@mlbridge
Copy link

mlbridge bot commented Nov 11, 2025

Webrevs

@eastig
Copy link
Member Author

eastig commented Nov 12, 2025

Hi Andrew(@theRealAph),
Can you please take a look?

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Nov 12, 2025
@eastig
Copy link
Member Author

eastig commented Nov 12, 2025

Thank you, @theRealAph
JFYI, where it was found: https://bugs.openjdk.org/browse/JDK-8370947

@theRealAph
Copy link
Contributor

Thank you, @theRealAph JFYI, where it was found: https://bugs.openjdk.org/browse/JDK-8370947

That's fascinating, thanks.

@openjdk openjdk bot removed the ready Pull request is ready to be integrated label Nov 12, 2025
@eastig eastig changed the title 8371649: AArch64: redundant OrderAccess::fence in ZBarrierSetAssembler::patch_barrier_relocation 8371649: ZGC: AArch64: redundant OrderAccess::fence in ZBarrierSetAssembler::patch_barrier_relocation Nov 12, 2025
@openjdk openjdk bot added the ready Pull request is ready to be integrated label Nov 12, 2025
@eastig
Copy link
Member Author

eastig commented Nov 12, 2025

Hi Erik (@fisk),
Could you also please take a look, just in case the fence was intentionally put there?

@fisk
Copy link
Contributor

fisk commented Nov 12, 2025

Hi Erik (@fisk),

Could you also please take a look, just in case the fence was intentionally put there?

The way I look at it, the fence was there for hardware that is unsophisticated enough to require manual cache flushing instead of having cache coherency that understands instruction edits, and at the same time has unsophisticated enough fences that are not speculated across such that the buffered store hits the cache before invalidating the cache, and not after, which would be awkward.

It is certainly possible that in practice the cache invalidation facilities also do the right level of fencing. So this is mostly just defensive programming.

If I flip the question around - how confident do you feel on a scale from 1 to 10 that the cache invalidation mechanism guarantees across all implementations, that the preceding store is flushed out to the caches before the cache is flushed? This is an area of the code where I don't want to take chances and slip unless we feel a high level of confidence.

@theRealAph
Copy link
Contributor

theRealAph commented Nov 13, 2025

The way I look at it, the fence was there for hardware that is unsophisticated enough to require manual cache flushing instead of having cache coherency that understands instruction edits, and at the same time has unsophisticated enough fences that are not speculated across such that the buffered store hits the cache before invalidating the cache, and not after, which would be awkward.

[edited]

Understood. But there are two caches, and OrderAccess::fence does not affect icache. So OrderAccess::fence cannot do anything to help. in order to make sure the buffered store hits the icache we need DSB; ISB, which ICache::invalidate does.

On the other hand, the cost of OrderAccess::fence is small in comparison with ICache::invalidate_word, so there's a question about why we're bothering to remove it.

@eastig
Copy link
Member Author

eastig commented Nov 13, 2025

@fisk:

The way I look at it, the fence was there for hardware that is unsophisticated enough to require manual cache flushing instead of having cache coherency that understands instruction edits, and at the same time has unsophisticated enough fences that are not speculated across such that the buffered store hits the cache before invalidating the cache, and not after, which would be awkward.

Such hardware would violate Arm ARM:

  • B2.3 Ordering requirements defined by the formal concurrency model: Same-Cache-Line-ordered-before.
  • B2.7.4.2 Synchronization and coherency issues between data and instruction accesses.

Yes, it might be a bug in hardware. Neoverse-N1 errata 1542419 is a good example.
In such a case, this bug should be handled inside ICache, if possible. If not possible, there should be something explaining why it's not in ICache.

It is certainly possible that in practice the cache invalidation facilities also do the right level of fencing. So this is mostly just defensive programming.

The issue is that we don't have this fence at other places, where ICache::invalidate are used. A reasonable question would be: why don't we use it there?

If I flip the question around - how confident do you feel on a scale from 1 to 10 that the cache invalidation mechanism guarantees across all implementations, that the preceding store is flushed out to the caches before the cache is flushed?

10, if we assume correct AArch64 implementation and correct ICache::invalidate.

@theRealAph

On the other hand, the cost of OrderAccess::fence is small in comparison with ICache::invalidate_word, so there's a question about why we're bothering to remove it.

This change is not about performance. It's about logical inconsistency: not using this everywhere, absence of history and contradiction to Arm ARM.

Also, an assumption of a needed fence complicates a fix of JDK-8370947. See ICacheInvalidationContext::fence in Alex's solution: master...xmas92:jdk:deferred_icache_invalidation

@theRealAph
Copy link
Contributor

@theRealAph

On the other hand, the cost of OrderAccess::fence is small in comparison with ICache::invalidate_word, so there's a question about why we're bothering to remove it.

This change is not about performance. It's about logical inconsistency: not using this everywhere, absence of history and contradiction to Arm ARM.

I see. So there is little or no performance benefit, but we're doing this for reasons of formal consistency.

Also, an assumption of a needed fence complicates a fix of JDK-8370947. See ICacheInvalidationContext::fence in Alex's solution: master...xmas92:jdk:deferred_icache_invalidation

I guess so, but there is no assumption of a needed fence.

A question is whether some future Arm system with fully-coherent i- and d-caches might want to supply a weaker version of ICache::invalidate_word. But even if it did, it would at the very least have to be a DMB, so there isn't an issue.

@theRealAph
Copy link
Contributor

@fisk , I'm assuming that no other thread is executing the target instructions while were patching them.

@fisk
Copy link
Contributor

fisk commented Nov 13, 2025

@fisk , I'm assuming that no other thread is executing the target instructions while were patching them.

Indeed; no concurrent thread is executing the instructions being modified.

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

Labels

hotspot [email protected] ready Pull request is ready to be integrated rfr Pull request is ready for review

Development

Successfully merging this pull request may close these issues.

3 participants