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

8298075: RISC-V: Implement post-call NOPs #11502

Closed
wants to merge 7 commits into from

Conversation

zhengxiaolinX
Copy link
Contributor

@zhengxiaolinX zhengxiaolinX commented Dec 5, 2022

Same as JDK-8287567, we need to implement post-call NOPs in the RISC-V backend.

We use li32 to implement it. li32 will signed-extend the loaded imm32 to a 64-bit register. However, our reader NativePostCallNop::displacement() only needs the low 32 bits value so we are safe.

The current post-call NOP is like:

nop                    (always 4-byte, used for deoptimization, please see `NativePostCallNop::make_deopt()`)
lui zr, <imm20>        (always 4-byte)
addiw zr, zr, <imm12>  (always 4-byte)

The code size here is the same as the AArch64 counterpart, 12 bytes.

The logic of setting the post-call NOP displacement is at install_post_call_nop_displacement() [1] when nmethods are being installed, so no one is running post-call NOPs when we are patching them.

One can check them by directly using java --enable-preview -XX:+UnlockDiagnosticVMOptions -XX:+PrintAssembly.

Tested hotspot tier1~4 and jdk tier1~4 using fastdebug by force turning on --enable-preview; SPECjbb2015 and dacapo were tested without regressions found. Skynet JMH benchmark seems to have an improvement from 8662ms/op -> 8495ms/op.

Thanks,
Xiaolin

[1]

static void install_post_call_nop_displacement(nmethod* nm, address pc) {
NativePostCallNop* nop = nativePostCallNop_at((address) pc);
intptr_t cbaddr = (intptr_t) nm;
intptr_t offset = ((intptr_t) pc) - cbaddr;
int oopmap_slot = nm->oop_maps()->find_slot_for_offset((intptr_t) pc - (intptr_t) nm->code_begin());
if (oopmap_slot < 0) { // this can happen at asynchronous (non-safepoint) stackwalks
log_debug(codecache)("failed to find oopmap for cb: " INTPTR_FORMAT " offset: %d", cbaddr, (int) offset);
} else if (((oopmap_slot & 0xff) == oopmap_slot) && ((offset & 0xffffff) == offset)) {
jint value = (oopmap_slot << 24) | (jint) offset;
nop->patch(value);
} else {
log_debug(codecache)("failed to encode %d %d", oopmap_slot, (int) offset);
}
}
void nmethod::finalize_relocations() {
NoSafepointVerifier nsv;
// Make sure that post call nops fill in nmethod offsets eagerly so
// we don't have to race with deoptimization
RelocIterator iter(this);
while (iter.next()) {
if (iter.type() == relocInfo::post_call_nop_type) {
post_call_nop_Relocation* const reloc = iter.post_call_nop_reloc();
address pc = reloc->addr();
install_post_call_nop_displacement(this, pc);
}
}
}


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

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 11502

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

Using diff file

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

@bridgekeeper
Copy link

bridgekeeper bot commented Dec 5, 2022

👋 Welcome back xlinzheng! 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 Dec 5, 2022
@openjdk
Copy link

openjdk bot commented Dec 5, 2022

@zhengxiaolinX 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 hotspot hotspot-dev@openjdk.org label Dec 5, 2022
@mlbridge
Copy link

mlbridge bot commented Dec 5, 2022

Webrevs

@@ -444,8 +444,16 @@ void NativePostCallNop::make_deopt() {
NativeDeoptInstruction::insert(addr_at(0));
}

int NativePostCallNop::displacement() const {
// discard the high 32-bit
Copy link
Member

Choose a reason for hiding this comment

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

Suggestion: // Discard the high 32 bits

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you - done.

Copy link
Member

@RealFYang RealFYang left a comment

Choose a reason for hiding this comment

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

Change looks good. I also performed regular benchmark tests (Dacapo, specjbb,2015, Renaissance) for this change and I didn't notice regressions from the numbers. So I guess it should be safe to have this.

@openjdk
Copy link

openjdk bot commented Dec 7, 2022

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

8298075: RISC-V: Implement post-call NOPs

Reviewed-by: fyang, luhenry

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

  • 3aa4070: 8294047: HttpResponseInputStream swallows interrupts
  • af8fb7e: 8282578: AIOOBE in javax.sound.sampled.Clip
  • 8b69a2e: 8298099: [JVMCI] decouple libgraal from JVMCI module at runtime
  • 8a9911e: 8295803: Console should be usable in jshell and other environments
  • 5d4c71c: 8281236: (D)TLS key exchange named groups
  • 10356e7: 8298303: (fs) temporarily remove Path.getExtension
  • 3b8c7ef: 8157023: Integrate NMT with JFR
  • e86f31b: 8298301: C2: assert(main_cmp->in(2)->Opcode() == Op_Opaque1) failed: main loop has no opaque node?
  • 8edb98d: 8165943: LineBreakMeasurer does not measure correctly if TextAttribute.TRACKING is set.
  • 3934484: 8298205: Prefer Member Initialization Lists for JFR classes in os_perf.hpp
  • ... and 251 more: https://git.openjdk.org/jdk/compare/b4bd287f736b6b5dcfe1b183cae9b11eb6f22686...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 (@RealFYang, @luhenry) 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 Dec 7, 2022
@zhengxiaolinX
Copy link
Contributor Author

Thank you for reviewing @RealFYang @luhenry and the additional testing!

/integrate

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label Dec 8, 2022
@openjdk
Copy link

openjdk bot commented Dec 8, 2022

@zhengxiaolinX
Your change (at version 21142c1) is now ready to be sponsored by a Committer.

@RealFYang
Copy link
Member

/sponsor

@openjdk
Copy link

openjdk bot commented Dec 8, 2022

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

  • 3aa4070: 8294047: HttpResponseInputStream swallows interrupts
  • af8fb7e: 8282578: AIOOBE in javax.sound.sampled.Clip
  • 8b69a2e: 8298099: [JVMCI] decouple libgraal from JVMCI module at runtime
  • 8a9911e: 8295803: Console should be usable in jshell and other environments
  • 5d4c71c: 8281236: (D)TLS key exchange named groups
  • 10356e7: 8298303: (fs) temporarily remove Path.getExtension
  • 3b8c7ef: 8157023: Integrate NMT with JFR
  • e86f31b: 8298301: C2: assert(main_cmp->in(2)->Opcode() == Op_Opaque1) failed: main loop has no opaque node?
  • 8edb98d: 8165943: LineBreakMeasurer does not measure correctly if TextAttribute.TRACKING is set.
  • 3934484: 8298205: Prefer Member Initialization Lists for JFR classes in os_perf.hpp
  • ... and 251 more: https://git.openjdk.org/jdk/compare/b4bd287f736b6b5dcfe1b183cae9b11eb6f22686...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Dec 8, 2022
@openjdk openjdk bot closed this Dec 8, 2022
@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 Dec 8, 2022
@openjdk
Copy link

openjdk bot commented Dec 8, 2022

@RealFYang @zhengxiaolinX Pushed as commit 74f346b.

💡 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
hotspot hotspot-dev@openjdk.org integrated Pull request has been integrated
3 participants