Skip to content

8199138: Add RISC-V support to Zero#573

Open
DingliZhang wants to merge 4 commits into
openjdk:masterfrom
DingliZhang:backport-8199138
Open

8199138: Add RISC-V support to Zero#573
DingliZhang wants to merge 4 commits into
openjdk:masterfrom
DingliZhang:backport-8199138

Conversation

@DingliZhang
Copy link
Copy Markdown
Member

@DingliZhang DingliZhang commented Sep 3, 2024

Hi all,

I'd like to backport this patch to jdk8u. Since most linux distributions support riscv64 and provide zero version jdk8 for riscv64. However, we may need to do some workarounds each time we upgrade the version, so I think it is helpful to provide zero support for riscv64 here.

common/autoconf/build-aux/config.guess and hotspot/src/os/linux/vm/os_linux.cpp do not apply cleanly due to context difference, but it is easy to resolve them manually. common/autoconf/platform.m4 just changed file path and remove test of x$OPENJDK_$1_CPU.

common/autoconf/generated-configure.sh regenerated by bash common/autoconf/autogen.sh. I used autoconf-2.69 and build from the source . But it looks a bit different from the one generated in the repo. I also tried autoconf-2.69 that comes with ubuntu 20.04 and the generated file is similar to the one in #413. I'm not quite sure which version of autoconf2.69 to use, if anyone has a better suggestion or is willing to help me generate a different one, I'd appreciate it!

Both cross-compile build and native build on riscv64 hardware is tested.

cross-compile on x86

boot jdk

openjdk version "1.8.0_43"
OpenJDK Runtime Environment (build 1.8.0_43-b03)
OpenJDK 64-Bit Server VM (build 25.40-b25, mixed mode)

run on qemu

openjdk version "1.8.0_432-internal"
OpenJDK Runtime Environment (build 1.8.0_432-internal-zhangdingli_2024_09_02_21_37-b00)
OpenJDK 64-Bit Zero VM (build 25.432-b00, interpreted mode)

native build on lp4a

boot jdk

openjdk version "1.8.0_412"
OpenJDK Runtime Environment Bisheng (build 1.8.0_412-b08)
OpenJDK 64-Bit Zero VM Bisheng (build 25.412-b08, interpreted mode)

run on lp4a

openjdk version "1.8.0_432-internal"
OpenJDK Runtime Environment (build 1.8.0_432-internal-openeuler_2024_09_02_21_38-b00)
OpenJDK 64-Bit Zero VM (build 25.432-b00, interpreted mode)

Thanks,
Dingli



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
  • JDK-8199138 needs maintainer approval

Issue

Reviewers

Contributors

  • Gui Cao <gcao@openjdk.org>

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk8u-dev.git pull/573/head:pull/573
$ git checkout pull/573

Update a local copy of the PR:
$ git checkout pull/573
$ git pull https://git.openjdk.org/jdk8u-dev.git pull/573/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 573

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

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk8u-dev/pull/573.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link
Copy Markdown

bridgekeeper Bot commented Sep 3, 2024

👋 Welcome back dzhang! 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
Copy Markdown

openjdk Bot commented Sep 3, 2024

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

@openjdk openjdk Bot changed the title Backport edc4ffe54b8c1f042e98c0ddb9dce757d88b01f4 8199138: Add RISC-V support to Zero Sep 3, 2024
@openjdk
Copy link
Copy Markdown

openjdk Bot commented Sep 3, 2024

This backport pull request has now been updated with issue from the original commit.

@openjdk openjdk Bot added backport Port of a pull request already in a different code base rfr Pull request is ready for review labels Sep 3, 2024
@mlbridge
Copy link
Copy Markdown

mlbridge Bot commented Sep 3, 2024

Webrevs

@DingliZhang
Copy link
Copy Markdown
Member Author

DingliZhang commented Sep 3, 2024

Thanks to Gui Cao for the original patch.
/contributor add gcao

@openjdk
Copy link
Copy Markdown

openjdk Bot commented Sep 3, 2024

@DingliZhang
Contributor Gui Cao <gcao@openjdk.org> successfully added.

@openjdk openjdk Bot added the approval Requires approval; will be removed when approval is received label Sep 3, 2024
@DingliZhang
Copy link
Copy Markdown
Member Author

/approval request allow Zero build on RISC-V

@openjdk
Copy link
Copy Markdown

openjdk Bot commented Sep 3, 2024

@DingliZhang
8199138: The approval request has been created successfully.

Copy link
Copy Markdown
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.

Hi, I have only one minor comment. Thanks.

Comment thread hotspot/src/os/linux/vm/os_linux.cpp
Copy link
Copy Markdown
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.

Thanks for the update. I am not sure about the autoconf issue here. You need to ask for the maintainer's comments/suggestions (@gnu-andrew once mentioned the possibility of backporting https://bugs.openjdk.org/browse/JDK-8195689 on #413) to remove the generated configure at the start of the next release cycle). The rest of the change looks good to me (Not a 8u Reviewer).

@bridgekeeper
Copy link
Copy Markdown

bridgekeeper Bot commented Oct 1, 2024

@DingliZhang This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

@gnu-andrew
Copy link
Copy Markdown
Member

@DingliZhang This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

Keep this open. I'll review after the upcoming release on the 15th.

@gnu-andrew
Copy link
Copy Markdown
Member

Thanks for the update. I am not sure about the autoconf issue here. You need to ask for the maintainer's comments/suggestions (@gnu-andrew once mentioned the possibility of backporting https://bugs.openjdk.org/browse/JDK-8195689 on #413) to remove the generated configure at the start of the next release cycle). The rest of the change looks good to me (Not a 8u Reviewer).

Yes, the in-tree auto-generated configure is a recurring problem. I certainly would like to backport the other fix. I'll have a look when I review this as to whether we should wait on that here or just commit this as is.

@DingliZhang
Copy link
Copy Markdown
Member Author

Thanks for the update. I am not sure about the autoconf issue here. You need to ask for the maintainer's comments/suggestions (@gnu-andrew once mentioned the possibility of backporting https://bugs.openjdk.org/browse/JDK-8195689 on #413) to remove the generated configure at the start of the next release cycle). The rest of the change looks good to me (Not a 8u Reviewer).

Yes, the in-tree auto-generated configure is a recurring problem. I certainly would like to backport the other fix. I'll have a look when I review this as to whether we should wait on that here or just commit this as is.

Thanks for the reply, I'm looking forward to it.

@bridgekeeper
Copy link
Copy Markdown

bridgekeeper Bot commented Nov 9, 2024

@DingliZhang This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

@DingliZhang
Copy link
Copy Markdown
Member Author

bot, please keep it open

@bridgekeeper
Copy link
Copy Markdown

bridgekeeper Bot commented Dec 11, 2024

@DingliZhang This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

@DingliZhang
Copy link
Copy Markdown
Member Author

bot, please keep it open

@bridgekeeper
Copy link
Copy Markdown

bridgekeeper Bot commented Jan 9, 2025

@DingliZhang This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

@DingliZhang
Copy link
Copy Markdown
Member Author

bot, please keep it open

@bridgekeeper
Copy link
Copy Markdown

bridgekeeper Bot commented Feb 6, 2025

@DingliZhang This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

@DingliZhang
Copy link
Copy Markdown
Member Author

bot, please keep it open

@bridgekeeper
Copy link
Copy Markdown

bridgekeeper Bot commented Mar 17, 2025

@DingliZhang This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

@DingliZhang
Copy link
Copy Markdown
Member Author

bot, please keep it open

@bridgekeeper
Copy link
Copy Markdown

bridgekeeper Bot commented Jul 29, 2025

@DingliZhang This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply issue a /touch or /keepalive command to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

@DingliZhang
Copy link
Copy Markdown
Member Author

bot, please keep it open

@bridgekeeper
Copy link
Copy Markdown

bridgekeeper Bot commented Aug 27, 2025

@DingliZhang This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply issue a /touch or /keepalive command to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

@DingliZhang
Copy link
Copy Markdown
Member Author

bot, please keep it open

@bridgekeeper
Copy link
Copy Markdown

bridgekeeper Bot commented Sep 25, 2025

@DingliZhang This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply issue a /touch or /keepalive command to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

@bridgekeeper
Copy link
Copy Markdown

bridgekeeper Bot commented Oct 24, 2025

@DingliZhang This pull request has been inactive for more than 8 weeks and will now be automatically closed. If you would like to continue working on this pull request in the future, feel free to reopen it! This can be done using the /open pull request command.

@bridgekeeper bridgekeeper Bot closed this Oct 24, 2025
@zzambers
Copy link
Copy Markdown
Contributor

zzambers commented May 11, 2026

@gnu-andrew @DingliZhang this PR one seems to have been forgotten

I have done some testing of it.

Cross-build:

  • Since I did not have jdk8+riscv64 jdk, to be used as boot jdk, I started with cross-build.

  • I used x86_64 debian trixie (container) as build OS with riscv64 trixie as sysroot (trixie introduces riscv64 support). Otherwise steps were basically equivalent to how cross-compilation is performed in GH CI.

  • I have faced following configure error, but I was able to fix this by replacing common/autoconf/build-aux/autoconf-config.sub with file from debian's autoconf /usr/share/autoconf/build-aux/config.sub:

checking build system type... x86_64-unknown-linux-gnu
checking host system type... Invalid configuration `riscv64-linux-gnu': machine `riscv64' not recognized
configure: error: /usr/bin/bash /starfive/jdk8u-dev/common/autoconf/build-aux/config.sub riscv64-linux-gnu failed
  • I have also faced some compilation errors, due to newer gcc version in debian trixie (14.2.0). So I have rebased this to current master, to get compiler fixes done since. (Rebase was almost clean, only conflict was timestamp in generated-configure.sh.) In addition to that, I had to add fix for JDK-8162545 to avoid:
/starfive/jdk8u-dev/jdk/src/share/native/sun/awt/image/jpeg/imageioJPEG.c: In function 'Java_com_sun_imageio_plugins_jpeg_JPEGImageWriter_writeImage':
/starfive/jdk8u-dev/jdk/src/share/native/sun/awt/image/jpeg/imageioJPEG.c:2857:19: error: passing argument 1 of 'freeArray' from incompatible pointer type [-Wincompatible-pointer-types]
 2857 |         freeArray(scale, numBands);
      |                   ^~~~~
      |                   |
      |                   UINT8 ** {aka unsigned char **}
  • After that, I was able to do successfully cross-build of zero, though with warning as errors disabled:
    make images WARNINGS_ARE_ERRORS=

Native build:

  • After that, I proceeded with native build on riscv64 board (starfive visionfive 2, also debian trixie) using jdk I cross-built, as boot jdk. With necessary dependencies installed and small source changes, as for cross-build (mentioned higher), I was able to do successfull native build with just:
bash configure --with-boot-jdk=/home/zz/j2sdk-image --with-jvm-variants=zero
make images WARNINGS_ARE_ERRORS=
  • Native buiild took a while, since build with zero as boot jdk on cheap riscv64 board is very slow, but after almost 6 hrs (I think), it produced working jdk. (I have tried just basic --version test.)

For reference, here is rebased branch with 2 additional changes, I ended up with: https://github.com/zzambers/jdk8u-dev/tree/riscv-rebase

@zzambers zzambers mentioned this pull request May 11, 2026
5 tasks
@zzambers
Copy link
Copy Markdown
Contributor

Configure error seems like: JDK-8285630, so separate issue.
Change looks good to me.

@DingliZhang
Copy link
Copy Markdown
Member Author

  • I have faced following configure error, but I was able to fix this by replacing common/autoconf/build-aux/autoconf-config.sub with file from debian's autoconf /usr/share/autoconf/build-aux/config.sub:
checking build system type... x86_64-unknown-linux-gnu
checking host system type... Invalid configuration `riscv64-linux-gnu': machine `riscv64' not recognized
configure: error: /usr/bin/bash /starfive/jdk8u-dev/common/autoconf/build-aux/config.sub riscv64-linux-gnu failed

Thanks for testing this.
I think using:

 --openjdk-target=riscv64-unknown-linux-gnu 

should be sufficient here, since the updated config.guess recognizes that triplet correctly.

@DingliZhang
Copy link
Copy Markdown
Member Author

/open

@DingliZhang
Copy link
Copy Markdown
Member Author

/template append

@openjdk openjdk Bot reopened this May 11, 2026
@openjdk
Copy link
Copy Markdown

openjdk Bot commented May 11, 2026

@DingliZhang This pull request is now open

@openjdk
Copy link
Copy Markdown

openjdk Bot commented May 11, 2026

@DingliZhang 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 backport-8199138
git fetch https://git.openjdk.org/jdk8u-dev.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 and removed rfr Pull request is ready for review labels May 11, 2026
@openjdk
Copy link
Copy Markdown

openjdk Bot commented May 11, 2026

@DingliZhang The pull request template has been appended to the pull request body

@openjdk openjdk Bot added the rfr Pull request is ready for review label May 11, 2026
@zzambers
Copy link
Copy Markdown
Contributor

  • I have faced following configure error, but I was able to fix this by replacing common/autoconf/build-aux/autoconf-config.sub with file from debian's autoconf /usr/share/autoconf/build-aux/config.sub:
checking build system type... x86_64-unknown-linux-gnu
checking host system type... Invalid configuration `riscv64-linux-gnu': machine `riscv64' not recognized
configure: error: /usr/bin/bash /starfive/jdk8u-dev/common/autoconf/build-aux/config.sub riscv64-linux-gnu failed

Thanks for testing this. I think using:

 --openjdk-target=riscv64-unknown-linux-gnu 

should be sufficient here, since the updated config.guess recognizes that triplet correctly.

I have tried this (with unmodified autoconf-config.sub), it indeed passed confugure. However, in this case, I had to set some additional env. variables prior to running configure to pass the build. Namely:

OBJCOPY=riscv64-linux-gnu-objcopy
STRIP=riscv64-linux-gnu-strip

Otherwise configure picked un-prefixed variants of these tools and subsequent build failed. (Debian uses riscv64-linux-gnu- prefix for cross toolchain.)

It then passed cross-build without autoconf-config.sub modifications.
thanks

Copy link
Copy Markdown
Member

@gnu-andrew gnu-andrew left a comment

Choose a reason for hiding this comment

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

Sorry for taking so long to get back to this and thanks @zzambers for the testing. I'm happy for this to go in once merged, assuming it still looks much the same. I've seen similar differences in the generated-configure.sh output and it's another reason to finally get rid of it. I'll look at doing that next week in time, hopefully in time to get it into 8u502.

@openjdk openjdk Bot removed the merge-conflict Pull request has merge conflict with target branch label May 27, 2026
Copy link
Copy Markdown
Member

@gnu-andrew gnu-andrew left a comment

Choose a reason for hiding this comment

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

To stay close to 11u, I would move the EM_RISCV lines above the EM_LOONGARCH ones. RISC-V was added before LoongArch in 11u which is why you are seeing a different context in 8u.

i.e. this is 11u:

#ifndef EM_AARCH64
  #define EM_AARCH64    183               /* ARM AARCH64 */
#endif
#ifndef EM_RISCV
  #define EM_RISCV      243               /* RISC-V */
#endif
#ifndef EM_LOONGARCH
  #define EM_LOONGARCH  258               /* LoongArch */
#endif

and

    {EM_AARCH64,     EM_AARCH64, ELFCLASS64, ELFDATA2LSB, (char*)"AARCH64"},
    {EM_RISCV,       EM_RISCV,   ELFCLASS64, ELFDATA2LSB, (char*)"RISC-V"},
    {EM_LOONGARCH,   EM_LOONGARCH, ELFCLASS64, ELFDATA2LSB, (char*)"LoongArch"},

We should keep the order the same in 8u to help with any future patches.

Other than that, I think this is ready to go in.

@DingliZhang
Copy link
Copy Markdown
Member Author

Hi @gnu-andrew Thanks for the review!
I have updated the patch as suggested and moved the EM_RISCV lines before the EM_LOONGARCH ones to keep the same order as 11u.
I also verified it with a simple linux-riscv64-zero cross-build test.

@DingliZhang DingliZhang requested a review from gnu-andrew May 27, 2026 07:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport Port of a pull request already in a different code base rfr Pull request is ready for review

Development

Successfully merging this pull request may close these issues.

4 participants