Skip to content

8362515: RISC-V: cleanup NativeFarCall #26370

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

Hamlin-Li
Copy link

@Hamlin-Li Hamlin-Li commented Jul 17, 2025

Hi,
Can you help to review this patch?

By https://github.com/openjdk/jdk/blob/master/src/hotspot/cpu/riscv/macroAssembler_riscv.hpp#L1270, there are far call, indirect call, reloc call.
NativeFarCall is in fact a reloc call, the name is confusing, better to rename it to RelocCall.
Also add some comments and do some other simple cleanup.

Thanks!


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-8362515: RISC-V: cleanup NativeFarCall (Enhancement - P4)

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 26370

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Jul 17, 2025

👋 Welcome back mli! 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 17, 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 Jul 17, 2025

@Hamlin-Li this pull request can not be integrated into master due to one or more merge conflicts. To resolve these merge conflicts and update this pull request you can run the following commands in the local repository for your personal fork:

git checkout cleanup-NativeFarCall
git fetch https://git.openjdk.org/jdk.git master
git merge FETCH_HEAD
# resolve conflicts and follow the instructions given by git merge
git commit -m "Merge master"
git push

@openjdk openjdk bot added merge-conflict Pull request has merge conflict with target branch rfr Pull request is ready for review labels Jul 17, 2025
@openjdk
Copy link

openjdk bot commented Jul 17, 2025

@Hamlin-Li 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.

@mlbridge
Copy link

mlbridge bot commented Jul 17, 2025

Webrevs


CodeBlob *code = CodeCache::find_blob(call_addr);
assert(code != nullptr, "Could not find the containing code blob");

address dest = MacroAssembler::pd_call_destination(call_addr);
address dest = MacroAssembler::target_addr_for_insn(call_addr);
Copy link
Member

Choose a reason for hiding this comment

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

Is this change safe? Seems it modifies the original logic.

Copy link
Author

Choose a reason for hiding this comment

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

Yes, MacroAssembler::pd_call_destination only call MacroAssembler::target_addr_for_insn.
And MacroAssembler::target_addr_for_insn are used in other places in NativeFarCall, so it's better to use target_addr_for_insn only to improve readability.

Copy link
Member

@RealFYang RealFYang Jul 22, 2025

Choose a reason for hiding this comment

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

There seems to be a subtle differnece here. I see MacroAssembler::pd_call_destination delegates work to NativeFarCall::reloc_destination which calls MacroAssembler::target_addr_for_insn under condition if (stub_addr != nullptr). After this change, that condition is gone. I haven't looked into how this may make a difference.

I see this function was introduce by JDK-8332689, maybe @robehn could comment?

[1] https://github.com/openjdk/jdk/blob/master/src/hotspot/cpu/riscv/nativeInst_riscv.cpp#L112

Copy link
Author

Choose a reason for hiding this comment

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

I see MacroAssembler::pd_call_destination delegates work to NativeFarCall::reloc_destination which calls MacroAssembler::target_addr_for_insn under condition if (stub_addr != nullptr).

Can you clarify "MacroAssembler::pd_call_destination delegates work to NativeFarCall::reloc_destination"?
Robbin is on vacation for weeks, so I'm afraid he's not going to reponse in time.

Copy link
Author

Choose a reason for hiding this comment

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

I don't think this pr changes the logic in NativeFarCall::reloc_destination, am I right?
Or maybe you're misled by the name change from stub_address to reloc_destination_without_check and existing method reloc_destination()?

Copy link
Member

@RealFYang RealFYang Jul 22, 2025

Choose a reason for hiding this comment

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

I see MacroAssembler::pd_call_destination delegates work to NativeFarCall::reloc_destination which calls MacroAssembler::target_addr_for_insn under condition if (stub_addr != nullptr).

Can you clarify "MacroAssembler::pd_call_destination delegates work to NativeFarCall::reloc_destination"? Robbin is on vacation for weeks, so I'm afraid he's not going to reponse in time.

Sorry for not being clear. Let me clarify. I mean this code snippet at [1]:

 74 address Relocation::pd_call_destination(address orig_addr) {
 75   assert(is_call(), "should be a call here");
 76   if (NativeCall::is_at(addr())) {
 77     return nativeCall_at(addr())->reloc_destination();           <======================
 78   }
 79
 80   if (orig_addr != nullptr) {

Before this change, we call MacroAssembler::pd_call_destination here.
And NativeFarCall::reloc_destination at L77 will only call MacroAssembler::target_addr_for_insn under condition if (stub_addr != nullptr) [2]. But we will always/unconditionally call MacroAssembler::target_addr_for_insn here after this change. That seems make a difference? Did I miss anything?

[1] https://github.com/openjdk/jdk/blob/master/src/hotspot/cpu/riscv/relocInfo_riscv.cpp#L77
[2] https://github.com/openjdk/jdk/blob/master/src/hotspot/cpu/riscv/nativeInst_riscv.cpp#L112

Copy link
Author

Choose a reason for hiding this comment

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

The call path was:
Relocation::pd_call_destination(address orig_addr) =>
NativeCall::reloc_destination() =>
NativeFarCall::reloc_destination()

After change, it's:
Relocation::pd_call_destination(address orig_addr) =>
NativeCall::reloc_destination() =>
RelocCall::reloc_destination()

The code path does not change except that NativeFarCall::reloc_destination is changed to RelocCall::reloc_destination and assert(NativeFarCall... is changed to assert(RelocCall.
Seems it does not change any logic in this code path, but just names.

Before this change, we call MacroAssembler::pd_call_destination here.
And NativeFarCall::reloc_destination at L77 will only call MacroAssembler::target_addr_for_insn under condition if (stub_addr != nullptr)

The code between NativeFarCall::reloc_destination and RelocCall::reloc_destination is almost the same, except of names.

But we will always/unconditionally call MacroAssembler::target_addr_for_insn here after this change.

No. I guess you might have mistoken RelocCall::reloc_destination_without_check() as RelocCall::reloc_destination()?

@openjdk openjdk bot removed the merge-conflict Pull request has merge conflict with target branch label Jul 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hotspot-compiler [email protected] rfr Pull request is ready for review
Development

Successfully merging this pull request may close these issues.

2 participants