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

8320697: RISC-V: Small refactoring for runtime calls #16816

Closed
wants to merge 5 commits into from

Conversation

feilongjiang
Copy link
Member

@feilongjiang feilongjiang commented Nov 26, 2023

Hi, please review this refactoring for runtime calls.
Major changes:

  1. Unified the runtime calls with the existing MacroAssembler::rt_call. This will remove the duplicate code like relocate(target.rspec() [&] {...} to emit uncompressed instructions.
  2. Removed MacroAssembler::far_branches and made the call sites default to far branches. branch_range is 1MB for riscv, and ReservedCodeCacheSize will always bigger than branch_range in practice. We should remove this unnecessary check and simplify the code logic.
  3. Renamed MacroAssembler::la_patchable with MacroAssembler::la making it less confusing.
  4. far_call in rt_call should use tmp instead of the default temporary register t0
  5. Removed some unused codes in g1BarrierSetAssembler_riscv.cpp

Testing:

  • Tier1-3 tested on hifive unmatched board (release)
  • Run non-trivial benchmark workloads (fastdebug)

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-8320697: RISC-V: Small refactoring for runtime calls (Enhancement - P4)

Reviewers

Contributors

  • Fei Yang <fyang@openjdk.org>

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 16816

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

Using diff file

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

Webrev

Link to Webrev Comment

@feilongjiang feilongjiang marked this pull request as draft November 26, 2023 10:52
@feilongjiang feilongjiang changed the title RISC-V: Small refactoring for runtime calls 8320697: RISC-V: Small refactoring for runtime calls Nov 26, 2023
@bridgekeeper
Copy link

bridgekeeper bot commented Nov 26, 2023

👋 Welcome back fjiang! 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 26, 2023

@feilongjiang 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 Nov 26, 2023
@feilongjiang
Copy link
Member Author

/label remove hotspot
/label add hotspot-compiler

@openjdk openjdk bot removed the hotspot hotspot-dev@openjdk.org label Nov 27, 2023
@openjdk
Copy link

openjdk bot commented Nov 27, 2023

@feilongjiang
The hotspot label was successfully removed.

@openjdk openjdk bot added the hotspot-compiler hotspot-compiler-dev@openjdk.org label Nov 27, 2023
@openjdk
Copy link

openjdk bot commented Nov 27, 2023

@feilongjiang
The hotspot-compiler label was successfully added.

@feilongjiang feilongjiang marked this pull request as ready for review November 27, 2023 02:43
@openjdk openjdk bot added the rfr Pull request is ready for review label Nov 27, 2023
@mlbridge
Copy link

mlbridge bot commented Nov 27, 2023

Webrevs

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.

Looks fine. Happy to see that MacroAssembler::far_branches removed and code logic simplied. In fact, the JVM won't start when ReservedCodeCacheSize is less than 2496K. BTW: I also performed hotspot:tier4 test, result is also good.

@openjdk
Copy link

openjdk bot commented Nov 28, 2023

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

8320697: RISC-V: Small refactoring for runtime calls

Co-authored-by: Fei Yang <fyang@openjdk.org>
Reviewed-by: fyang, rehn

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 no new commits pushed to the master branch. If another commit should be pushed before you perform the /integrate command, your PR will be automatically rebased. If you prefer to avoid any potential 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 openjdk bot added the ready Pull request is ready to be integrated label Nov 28, 2023
@robehn
Copy link
Contributor

robehn commented Nov 28, 2023

Renamed MacroAssembler::la_patchable with MacroAssembler::auipc making it explicit that this will emit pc-relative addressing code.

First, above is not true, as it may emit movptr, it's now an implicit movptr instead. When you thought you were getting auipc.
Secondly auipc is not a mnemonic AFAIK, it means just the instruction auipc. Having it as both is confusing.
Third the one version is now called "la" while the other one is called "auipc" ?

Sorry, but this part is worse now in IMHO.

@RealFYang
Copy link
Member

RealFYang commented Nov 28, 2023

Renamed MacroAssembler::la_patchable with MacroAssembler::auipc making it explicit that this will emit pc-relative addressing code.

First, above is not true, as it may emit movptr, it's now an implicit movptr instead. When you thought you were getting auipc. Secondly auipc is not a mnemonic AFAIK, it means just the instruction auipc. Having it as both is confusing. Third the one version is now called "la" while the other one is called "auipc" ?

Sorry, but this part is worse now in IMHO.

Yeah, I see that too :-) I guess the intention is to try to map to the aarch64 counterpart MacroAssembler::adrp [1].
I did some history searching and seems that the else block is there only to handle some corner cases [2].
We might want to find a better name for this function but seems not easy to do :-(

[1] https://github.com/openjdk/jdk/blob/master/src/hotspot/cpu/aarch64/macroAssembler_aarch64.cpp#L4968
[2] https://mail.openjdk.org/pipermail/hotspot-compiler-dev/2015-November/019895.html

@robehn
Copy link
Contributor

robehn commented Nov 28, 2023

Renamed MacroAssembler::la_patchable with MacroAssembler::auipc making it explicit that this will emit pc-relative addressing code.
First, above is not true, as it may emit movptr, it's now an implicit movptr instead. When you thought you were getting auipc. Secondly auipc is not a mnemonic AFAIK, it means just the instruction auipc. Having it as both is confusing. Third the one version is now called "la" while the other one is called "auipc" ?
Sorry, but this part is worse now in IMHO.

Yeah, I see that too :-) I guess the intention is to try to map to the aarch64 counterpart MacroAssembler::adrp [1]. I did some history searching and seems that the else block is there only to handle some corner cases [2]. We might want to find a better name for this function but seems not easy to do :-(

[1] https://github.com/openjdk/jdk/blob/master/src/hotspot/cpu/aarch64/macroAssembler_aarch64.cpp#L4968 [2] https://mail.openjdk.org/pipermail/hotspot-compiler-dev/2015-November/019895.html

I think there is an underlying issue with the whole design with masm/asm.
As there is no clear separation between "I want this to happen" and "I want to emit this instruction".
I think methods which have identical name as an instruction should indicate "I want to emit this instruction".

@feilongjiang
Copy link
Member Author

feilongjiang commented Nov 28, 2023

Renamed MacroAssembler::la_patchable with MacroAssembler::auipc making it explicit that this will emit pc-relative addressing code.

First, above is not true, as it may emit movptr, it's now an implicit movptr instead. When you thought you were getting auipc. Secondly auipc is not a mnemonic AFAIK, it means just the instruction auipc. Having it as both is confusing. Third the one version is now called "la" while the other one is called "auipc" ?

Sorry, but this part is worse now in IMHO.

Yeah, I see that too :-) I guess the intention is to try to map to the aarch64 counterpart MacroAssembler::adrp [1].

I did some history searching and seems that the else block is there only to handle some corner cases [2].

We might want to find a better name for this function but seems not easy to do :-(

[1] https://github.com/openjdk/jdk/blob/master/src/hotspot/cpu/aarch64/macroAssembler_aarch64.cpp#L4968

[2] https://mail.openjdk.org/pipermail/hotspot-compiler-dev/2015-November/019895.html

Thanks Fei.
Yes, that's also part of the reason why I rename this function to the new name auipc. The other consideration which I didn't mention is that the old name la_patchable is kind of confusing because we also have other la function which are also pachable too like MacroAssembler::la [1].

I am happy if we can find a better name, suggestions are welcomed.

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

@feilongjiang
Copy link
Member Author

feilongjiang commented Nov 28, 2023

I think there is an underlying issue with the whole design with masm/asm. As there is no clear separation between "I want this to happen" and "I want to emit this instruction". I think methods which have identical name as an instruction should indicate "I want to emit this instruction".

Agreed. I can revert the renaming of la_patchable and keep the other parts. IMHO, la_patchable is not good enough though. So maybe we could do more refactoring on la_patchable, but this should be done in another pr.
@robehn Does that work for you?

@RealFYang
Copy link
Member

I think there is an underlying issue with the whole design with masm/asm. As there is no clear separation between "I want this to happen" and "I want to emit this instruction". I think methods which have identical name as an instruction should indicate "I want to emit this instruction".

Do we have any other occurences except for the case here? I am supposing the auipc in this change would be the only one which bears such an issue. No?

@theRealAph
Copy link
Contributor

I think there is an underlying issue with the whole design with masm/asm. As there is no clear separation between "I want this to happen" and "I want to emit this instruction". I think methods which have identical name as an instruction should indicate "I want to emit this instruction".

I can see the logic behind that, but certain CPU designers write things like "A "programmer-friendly" assembler may accept a negative immediate between -(2^24 -1) and -1 inclusive, causing it to convert a requested ADD operation to a SUB, or vice versa, and then encode the absolute value of the immediate as for uimm24." So I think maybe that bird has already flown...

@robehn
Copy link
Contributor

robehn commented Nov 29, 2023

I think there is an underlying issue with the whole design with masm/asm. As there is no clear separation between "I want this to happen" and "I want to emit this instruction". I think methods which have identical name as an instruction should indicate "I want to emit this instruction".

I can see the logic behind that, but certain CPU designers write things like "A "programmer-friendly" assembler may accept a negative immediate between -(2^24 -1) and -1 inclusive, causing it to convert a requested ADD operation to a SUB, or vice versa, and then encode the absolute value of the immediate as for uimm24." So I think maybe that bird has already flown...

Yes. I think this case is extra confusing as you ask for one instruction for a materializing a pc relative value.
But you can get several instruction loading an absolute value.

If this is okey, the programmer never want a pc relative value, he just wanted that value.
Therefore I think using the name auipc is a bit sub-optimal to tell this story.

If it's only me, and we don't have any other good name, I guess you should just override me...

@RealFYang
Copy link
Member

RealFYang commented Nov 30, 2023

Another way which I think might resolve our concerns is to simply rename la_patchable as la and overload the
existing three la assembler functions [1][2][3].

In fact, this la_patchable is very similar to the existing MacroAssembler::la(Register Rd, const address addr) [1].
The only difference is that la_patchable will do some distance checks based on high/low bound of code cache and return
a displacement through its third reference parameter offset for the succeeding addi/jalr/ld/st instructions.
While la [1] is mainly used by la[2] for loading address of an label which is more simpler compared with la_patchable.
At the same time, I think la_patchable should receive an address instead of Address since it's always expecting a
literal address. This will also help distinguish with la[3] which receives an Address.

So the replacement for la_patchable looks like void MacroAssembler::la(Register Rd, const address addr, int32_t &offset)
And I have tried following add-on change and it seems to work.
16816-addon.diff.txt

[1] https://github.com/openjdk/jdk/blob/master/src/hotspot/cpu/riscv/macroAssembler_riscv.cpp#L720
[2] https://github.com/openjdk/jdk/blob/master/src/hotspot/cpu/riscv/macroAssembler_riscv.cpp#L755
[3] https://github.com/openjdk/jdk/blob/master/src/hotspot/cpu/riscv/macroAssembler_riscv.cpp#L730

@robehn
Copy link
Contributor

robehn commented Nov 30, 2023

Another way which I think might resolve our concerns is to simply rename la_patchable as la and overload the existing three la assembler functions [1][2][3].

I like this a lot more, thanks!

All onboard ? :)

@feilongjiang
Copy link
Member Author

Another way which I think might resolve our concerns is to simply rename la_patchable as la and overload the existing three la assembler functions [1][2][3].
So the replacement for la_patchable looks like void MacroAssembler::la(Register Rd, const address addr, int32_t &offset)

Thanks! It looks much cleaner and clearer. I will apply your patch later.

@feilongjiang
Copy link
Member Author

Applied Fei's patch.
/contributor add @RealFYang

@openjdk
Copy link

openjdk bot commented Nov 30, 2023

@feilongjiang
Contributor Fei Yang <fyang@openjdk.org> successfully added.

Copy link
Contributor

@robehn robehn left a comment

Choose a reason for hiding this comment

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

Thank you, looks good! (not a line for line review)

You have some unrelated changes in g1BarrierSet, I don't mind, but pointing that out for the record.

@feilongjiang
Copy link
Member Author

You have some unrelated changes in g1BarrierSet, I don't mind, but pointing that out for the record.

Thanks for the reminder, I've updated the description.

@robehn
Copy link
Contributor

robehn commented Dec 4, 2023

Hey!

I notice this:

  static int far_branch_size() {   
    if (far_branches()) {                                          
      return 2 * 4;  // auipc + jalr, see far_call() & far_jump()

Which is used to determine deopt handler size.

I don't understand how we ever may use movptr here instead without knowing who is calling?

I think we want two methods here one with fixed size ?

@feilongjiang
Copy link
Member Author

feilongjiang commented Dec 5, 2023

I don't understand how we ever may use movptr here instead without knowing who is calling?

I think we want two methods here one with fixed size ?

Hi @robehn, I'm not sure if I understand it correctly. Do you mean we should use movptr to get fixed instruction size instead of la_patchable?

@robehn
Copy link
Contributor

robehn commented Dec 5, 2023

I don't understand how we ever may use movptr here instead without knowing who is calling?
I think we want two methods here one with fixed size ?

Hi @robehn, I'm not sure if I understand it correctly. Do you mean we should use movptr to get fixed instruction size instead of la_patchable?

https://bugs.openjdk.org/browse/JDK-8321315

Let's take here, this PR is good!

@feilongjiang
Copy link
Member Author

https://bugs.openjdk.org/browse/JDK-8321315

Let's take here, this PR is good!

Ok. Let's get this integrated then. Thanks. Tier1-3 tests are still good.

/integrate

@openjdk
Copy link

openjdk bot commented Dec 5, 2023

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

  • 50d1839: 8318809: java/util/concurrent/ConcurrentLinkedQueue/WhiteBox.java shows intermittent failures on linux ppc64le and aarch64
  • 81484d8: 8320687: sun.jvmstat.monitor.MonitoredHost.getMonitoredHost() throws unexpected exceptions when invoked concurrently
  • 30b5d42: 8321069: JvmtiThreadState::state_for_while_locked() returns nullptr for an attached JNI thread with a java.lang.Thread object after JDK-8319935
  • bd04f91: 8321131: Console read line with zero out should zero out underlying buffer in JLine
  • 155abc5: 8311906: Improve robustness of String constructors with mutable array inputs
  • 316b783: 8321276: runtime/cds/appcds/dynamicArchive/DynamicSharedSymbols.java failed with "'17 2: jdk/test/lib/apps ' missing from stdout/stderr"
  • 65be5e0: 8305931: jdk/jfr/jcmd/TestJcmdDumpPathToGCRoots.java failed with "Expected chains but found none"
  • f6be922: 8316193: jdk/jfr/event/oldobject/TestListenerLeak.java java.lang.Exception: Could not find leak
  • a9de5c7: 8315128: jdk/jfr/event/runtime/TestResidentSetSizeEvent.java fails with "The size should be less than or equal to peak"
  • d2c529c: 8319072: JFR: Turn off events for JFR.view
  • ... and 28 more: https://git.openjdk.org/jdk/compare/ecd335d8f42757d332f217e220e1a9db8c48c8d6...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Dec 5, 2023
@openjdk openjdk bot closed this Dec 5, 2023
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Dec 5, 2023
@openjdk
Copy link

openjdk bot commented Dec 5, 2023

@feilongjiang Pushed as commit aec3865.

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