Skip to content
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

8324123: aarch64: fix prfm literal encoding in assembler #17482

Closed
wants to merge 7 commits into from

Conversation

sandlerwang
Copy link
Contributor

@sandlerwang sandlerwang commented Jan 18, 2024

Current prfm literal mode encoding in aarch64 assembler is not correct.
The prfm_literal instruction requires 31 and 30 bits to be 0x11, while current assembler encodes the two bits to be 0x11, which is a ldr instruction, not prfm.
For example, if adding the following code in stubGenerator
__ prfm(Address(__ pc()))
we get a ldr instruction like
ldr x0, 0x0000ffff83f8539c
but it should be a prfm instruction like
prfm pldl1keep, 0x0000ffff8ff8539c

The bug is caused in ld_st2, literal mode, bit 31 and 30 bits are set to (size & 0b01), while for prfm instructions, 31 and 30 bits must be 0b11.
void ld_st2(Register Rt, const Address &adr, int size, int op, int V = 0) {
starti;

f(V, 26); // general reg?
zrf(Rt, 0);

// Encoding for literal loads is done here (rather than pushed
// down into Address::encode) because the encoding of this
// instruction is too different from all of the other forms to
// make it worth sharing.
if (adr.getMode() == Address::literal) {
  assert(size == 0b10 || size == 0b11, "bad operand size in ldr");
  assert(op == 0b01, "literal form can only be used with loads");
  f(**size & 0b01, 31, 30**), f(0b011, 29, 27), f(0b00, 25, 24);
  int64_t offset = (adr.target() - pc()) >> 2;
  sf(offset, 23, 5);
  code_section()->relocate(pc(), adr.rspec());
  return;
}

f(size, 31, 30);
f(op, 23, 22); // str
adr.encode(&current_insn);

}


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-8324123: aarch64: fix prfm literal encoding in assembler (Bug - P4)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 17482

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

Using diff file

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

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Jan 18, 2024

👋 Welcome back wzhuo! 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 openjdk bot added the rfr Pull request is ready for review label Jan 18, 2024
@openjdk
Copy link

openjdk bot commented Jan 18, 2024

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

  • hotspot-compiler

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 hotspot-compiler hotspot-compiler-dev@openjdk.org label Jan 18, 2024
@mlbridge
Copy link

mlbridge bot commented Jan 18, 2024

Webrevs

f(pfop, 4, 0); \
int64_t offset = (adr.target() - pc()) >> 2; \
sf(offset, 23, 5); \
} else { \
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks reasonable, but we don't need it to be inline. See the examples of adr and _adrp.

Copy link
Contributor Author

@sandlerwang sandlerwang Jan 22, 2024

Choose a reason for hiding this comment

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

Thank you APH. I have updated the patch to make prfm no inline. Please check the commit
do not use inline for prfm encoding function

Copy link
Contributor

@theRealAph theRealAph left a comment

Choose a reason for hiding this comment

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

Thanks.

@@ -187,6 +187,18 @@ void Address::lea(MacroAssembler *as, Register r) const {
zrf(Rd, 0);
}

void Assembler::prfm(const Address &adr, prfop pfop) {
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
void Assembler::prfm(const Address &adr, prfop pfop) {
// This encoding is similar (but not quite identical) to the encoding used
// by literal ld/st. see JDK-8324123.
void Assembler::prfm(const Address &adr, prfop pfop) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for your suggestions. I have added the comments, please check


INSN(prfm, 0b11, 0b10); // FIXME: PRFM should not be used with
// writeback modes, but the assembler
// doesn't enfore that.
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't we still need this comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got the comments back.

// This encoding is similar (but not quite identical) to the encoding used
// by literal ld/st. see JDK-8324123.
// FIXME: PRFM should not be used with writeback modes, but the assembler
// doesn't enfore that.
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
// doesn't enfore that.
// doesn't enforce that.

Copy link
Contributor

@theRealAph theRealAph left a comment

Choose a reason for hiding this comment

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

Good.

@openjdk
Copy link

openjdk bot commented Jan 23, 2024

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

8324123: aarch64: fix prfm literal encoding in assembler

Reviewed-by: aph, dlong

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 85 new commits pushed to the master branch:

  • b5995a7: 8302019: Clarify Elements.overrides
  • 95310ea: 8223696: java/net/httpclient/MaxStreams.java failed with didn't finish within the time-out
  • 39b756a: 8324492: Remove Atomic support for OopHandle
  • 12b89cd: 8323717: Introduce test keyword for tests that need external dependencies
  • 746a086: 8306767: Concurrent repacking of extra data in MethodData is potentially unsafe
  • ffe3bb6: 8324657: Intermittent OOME on exception message create
  • e709842: 8324636: Serial: Remove Generation::block_is_obj
  • 7a798d3: 8324598: use mem_unit when working with sysinfo memory and swap related information
  • 6d36eb7: 8322768: Optimize non-subword vector compress and expand APIs for AVX2 target.
  • 9d1a6d1: 8323645: Remove unused internal sun.net.www.protocol.jar.URLJarFileCallBack interface
  • ... and 75 more: https://git.openjdk.org/jdk/compare/ff8cc268fdaaf85299c94088a226b73e7eaf6bdb...master

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.

As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@theRealAph, @dean-long) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Jan 23, 2024
@eme64
Copy link
Contributor

eme64 commented Jan 23, 2024

@sandlerwang could there be a regression test for this bug?

@sandlerwang
Copy link
Contributor Author

@sandlerwang could there be a regression test for this bug?

Sorry, I tried but cannot get a test for this bug, because the prfm literal encoding is not used in current tip.
I met the bug when I tried to use prfm to prefetch instructions, but no similar case in tip

@@ -187,6 +187,22 @@ void Address::lea(MacroAssembler *as, Register r) const {
zrf(Rd, 0);
}

// This encoding is similar (but not quite identical) to the encoding used
// by literal ld/st. see JDK-8324123.
// FIXME: PRFM should not be used with writeback modes, but the assembler
Copy link
Contributor

Choose a reason for hiding this comment

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

FIXME: is it ok to leave this in the code?
I think we prefer filed RFE's to comments in the code that nobody will ever look at again.
You can put the RFE number in the code though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. The FIXME was there because PRFM did not support pre/post indexing and we had no check for that.
Some guarantee checks were added and FIXME was removed.
Please check the last 3 patches.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks @sandlerwang !

Copy link
Contributor

@theRealAph theRealAph left a comment

Choose a reason for hiding this comment

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

Still good.

sandlerwang and others added 2 commits January 25, 2024 19:29
Co-authored-by: Andrew Haley <aph-open@littlepinkcloud.com>
Co-authored-by: Andrew Haley <aph-open@littlepinkcloud.com>
@sandlerwang
Copy link
Contributor Author

/integrate

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label Jan 26, 2024
@openjdk
Copy link

openjdk bot commented Jan 26, 2024

@sandlerwang
Your change (at version 62cce40) is now ready to be sponsored by a Committer.

@D-D-H
Copy link
Contributor

D-D-H commented Jan 26, 2024

/sponsor

@openjdk
Copy link

openjdk bot commented Jan 26, 2024

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

  • b5995a7: 8302019: Clarify Elements.overrides
  • 95310ea: 8223696: java/net/httpclient/MaxStreams.java failed with didn't finish within the time-out
  • 39b756a: 8324492: Remove Atomic support for OopHandle
  • 12b89cd: 8323717: Introduce test keyword for tests that need external dependencies
  • 746a086: 8306767: Concurrent repacking of extra data in MethodData is potentially unsafe
  • ffe3bb6: 8324657: Intermittent OOME on exception message create
  • e709842: 8324636: Serial: Remove Generation::block_is_obj
  • 7a798d3: 8324598: use mem_unit when working with sysinfo memory and swap related information
  • 6d36eb7: 8322768: Optimize non-subword vector compress and expand APIs for AVX2 target.
  • 9d1a6d1: 8323645: Remove unused internal sun.net.www.protocol.jar.URLJarFileCallBack interface
  • ... and 75 more: https://git.openjdk.org/jdk/compare/ff8cc268fdaaf85299c94088a226b73e7eaf6bdb...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Jan 26, 2024
@openjdk openjdk bot closed this Jan 26, 2024
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review sponsor Pull request is ready to be sponsored labels Jan 26, 2024
@openjdk
Copy link

openjdk bot commented Jan 26, 2024

@D-D-H @sandlerwang Pushed as commit bde8789.

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

@mmyxym
Copy link

mmyxym commented Feb 28, 2024

/backport jdk21u-dev

@openjdk
Copy link

openjdk bot commented Feb 28, 2024

@mmyxym the backport was successfully created on the branch backport-mmyxym-bde87895 in my personal fork of openjdk/jdk21u-dev. To create a pull request with this backport targeting openjdk/jdk21u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit bde87895 from the openjdk/jdk repository.

The commit being backported was authored by Wang Zhuo on 26 Jan 2024 and was reviewed by Andrew Haley and Dean Long.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk21u-dev:

$ git fetch https://github.com/openjdk-bots/jdk21u-dev.git backport-mmyxym-bde87895:backport-mmyxym-bde87895
$ git checkout backport-mmyxym-bde87895
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk21u-dev.git backport-mmyxym-bde87895

@mmyxym
Copy link

mmyxym commented Feb 29, 2024

/backport jdk17u-dev

@openjdk
Copy link

openjdk bot commented Feb 29, 2024

@mmyxym Could not automatically backport bde87895 to openjdk/jdk17u-dev due to conflicts in the following files:

  • src/hotspot/cpu/aarch64/assembler_aarch64.cpp
  • src/hotspot/cpu/aarch64/assembler_aarch64.hpp

Please fetch the appropriate branch/commit and manually resolve these conflicts by using the following commands in your personal fork of openjdk/jdk17u-dev. Note: these commands are just some suggestions and you can use other equivalent commands you know.

# Fetch the up-to-date version of the target branch
$ git fetch --no-tags https://git.openjdk.org/jdk17u-dev.git master:master

# Check out the target branch and create your own branch to backport
$ git checkout master
$ git checkout -b backport-mmyxym-bde87895

# Fetch the commit you want to backport
$ git fetch --no-tags https://git.openjdk.org/jdk.git bde87895c8b1b9df198e3883d24cd9ea840efc98

# Backport the commit
$ git cherry-pick --no-commit bde87895c8b1b9df198e3883d24cd9ea840efc98
# Resolve conflicts now

# Commit the files you have modified
$ git add files/with/resolved/conflicts
$ git commit -m 'Backport bde87895c8b1b9df198e3883d24cd9ea840efc98'

Once you have resolved the conflicts as explained above continue with creating a pull request towards the openjdk/jdk17u-dev with the title Backport bde87895c8b1b9df198e3883d24cd9ea840efc98.

Below you can find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit bde87895 from the openjdk/jdk repository.

The commit being backported was authored by Wang Zhuo on 26 Jan 2024 and was reviewed by Andrew Haley and Dean Long.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hotspot-compiler hotspot-compiler-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

6 participants