Categories: DevOps, Java

Windows OpenJDK Development Environment Setup

I documented how to set up an OpenJDK build environment for macOS and for Ubuntu Linux. Here is how to do the same for a Windows x86-64 environment on a Windows x86-64 machine. To create a JDK build for a Windows ARM64 environment, see the last section of this post.

  1. Install Visual Studio Code.
  2. Install Git and set Visual Studio Code as Git’s default editor.
  3. Install Visual Studio 2019. Ensure the Desktop Development with C++ workload is selected so that the C++ compiler is available.
The Visual Studio Desktop development with C++ workload
  1. Install a boot JDK. I used winget, the Windows package manager, to do this as outlined in the OpenJDK Windows installation instructions.
winget search Microsoft.OpenJDK
winget install Microsoft.OpenJDK.17
Microsoft Build of OpenJDK with Hotspot 17.0.1+12 (x64) 
Please watt while Windows configures Microsoft Build of OpenJDK with 
Hotspot 170 1+12(x64) 
Time remaining 7 seconds
  1. Install Cygwin using the command below.
setup-x86_64.exe -q -P autoconf -P make -P unzip -P zip
  1. Launch Cygwin, clone the OpenJDK repo then run bash configure. This should output an error if there are any missing dependencies. Once that completes successfully, make images will build the OpenJDK code.
mkdir ~/repos
cd ~/repos
git clone https://github.com/openjdk/jdk
cd ~/repos/jdk
bash configure
make images

To try out the local JDK build, run java.exe in the build folder, e.g.

cd ~/repos/jdk/build/windows-x86_64-server-slowdebug
cd jdk/bin
./java.exe -version

Troubleshooting

Keep in mind that make images can fail due to Cygwin-specific issues. The only workaround may be to downgrade Cygwin to a version known to work well, as I had to do when I ran into segfaults when running make.

Windows ARM64 JDK

To create a JDK build for a Windows ARM64 machine (as of this posting), you still need to set up the Windows x86-64 environment as described above with the additional changes below.

  1. Launch the Visual Studio Installer then install the “MSVC v142 – VS 2019 C++ ARM64 build tools (Latest)” item.
  2. Run bash configure with the additional –openjdk-target argument as outlined at https://github.com/microsoft/openjdk-aarch64
bash configure --openjdk-target=aarch64-unknown-cygwin

Running the ARM64 JDK on x86-64?

I was curious to see what happens if you try to run the ARM64 Java build in Cygwin on x86-64:

User@Machine /cygdrive/c/dev/repos/jdk/build/windows-aarch64-server-release/jdk/bin
$ ./java -version
-bash: ./java: cannot execute binary file: Exec format error

In the Windows command line we get this message in the terminal and the subsequent dialog box:

C:\dev\repos\jdk\build\windows-aarch64-server-release\jdk\bin>.\java.exe
This version of C:\dev\repos\jdk\build\windows-aarch64-server-release\jdk\bin\java.exe is not compatible with the version of Windows you're running. Check your computer's system information and then contact the software publisher.
Machine Type Mismatch

Launching it from Windows Explorer fails with this error:

Platform mismatch launching ARM64 Java on Windows x86-64

Categories: DevOps, Java

Set up macOS for OpenJDK Development

Last week I bought a new MacBook Pro with the Apple M1 Chip and 16GB of RAM. These are the steps I used to set it up for building the OpenJDK codebase.

General macOS Configuration

  1. Set the OS appearance (theme). I tend to prefer dark theme.
  2. Set your Mac’s name (it bothers me when the terminal has some random host name). You might need to restart your terminal for this change to take effect.

Install Development Tools

Should any of the commands below fail, see the troubleshooting section at the end for possible workarounds.

  1. Install homebrew by running the recommended command (and see the troubleshooting section if there are any git errors):
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  1. Clone the OpenJDK repo:
mkdir ~/repos
cd ~/repos
git clone https://github.com/openjdk/jdk
  1. Install Xcode from the App Store. Xcode 13.1 is the most recent as of this post.
  2. Download and install the Xcode command line tools.
  3. Select the Xcode command line tools: launch Xcode then go to Preferences > Locations. Select Xcode 13.1 in the Command Line Tools dropdown as shown below.
Selecting the Command Line Tools in Xcode
  1. Install autoconf: brew install autoconf
  2. Install Visual Studio Code (optional)

Installing the Boot JDK

This was surprisingly straightforward. The instructions on how to install the Microsoft Build of OpenJDK on macOS comprise a single homebrew command:

brew install --cask microsoft-openjdk

Installing the Microsoft OpenJDK on macOS

Building the OpenJDK

Running bash configure in the JDK folder should display any missing dependencies. Any errors from bash configure will need to be resolved before running make images.

cd ~/repos/jdk
bash configure
make images

To browse through the contents of the build folder in finder:

open ~/repos/jdk/build/

To try out your new build, switch to the bin folder and check the Java version:

cd ~/repos/jdk/build/macosx-aarch64-server-release/jdk/bin
./java -version

Here is the output I get:

saint@Saints-MBP-2021 bin % ./java -version
openjdk version "18-internal" 2022-03-22
OpenJDK Runtime Environment (build 18-internal+0-adhoc.saint.jdk)
OpenJDK 64-Bit Server VM (build 18-internal+0-adhoc.saint.jdk, mixed mode)
saint@Saints-MBP-2021 bin % 

Troubleshooting

Homebrew Installation Failure

Installing homebrew appeared to be successful (last message output below) but there was a git error in the output!

==> Downloading and installing Homebrew..
remote: Enumerating objects: 345, done.
remote: Counting objects: 100% (297/297), done.
remote: Compressing objects: 100% (107/107), done.
remote: Total 345 (delta 227), reused 238 (delta 184), pack-reused 48
Receiving objects: 100% (345/345), 171.73 KiB | 971.00 KiB/s, done.
Resolving deltas: 100% (227/227),
completed with 54 local objects.
From https://github.com/Homebrew/brew
* [new branch]
dependabot/bundler/Librarv/Homebrew/sorbet-0.5.9396
-> origin/dependabot/bundler/Librarv/Homebrew/sorbet-0.5.9396
778de69b0..be908f679 master -> origin/master
* [new tag] 3.3.6 -> 3.3.6
HEAD is now at be908f679 Merge pull request #12502 from carlocab/bug-template
error: Not a valid ref: refs/remotes/origin/master
fatal: ambiguous argument
'refs/remotes/origin/master': unknown revision or path not in the working tree.
Use
"_-' to separate paths from revisions, like this:
'git <command> [<revision>...] - I<files...11
fatal: Could not resolve HEAD to a revision
Warning: /opt/homebrew/bin is not in your PATH.
Instructions on how to configure vour shell for Homebrew
can be found in the 'Next steps' section below.
==> Installation successful!

Here is the relevant error, which I was able to copy/paste (with some typos) from the PNG!!!

error: Not a valid ref: refs/remotes/origin/master
fatal: ambiguous argument
'refs/remotes/origin/master': unknown revision or path not in the working tree.

I thought I could keep chugging along merrily but other steps will fail if this is not addressed. Thankfully, https://stackoverflow.com/questions/65605282/trying-to-install-hugo-via-homebrew-could-not-resolve-head-to-a-revision already addressed how to fix this. I had to look up the -C flag in the git docs (it executes the command in the context of the specified directory).

git -C $(brew --repository homebrew/core) checkout master
Fixing the homebrew/core git repo

Autoconf Installation Failures

No available formula with the name “autoconf”

I ran into errors of the form No available formula with the name "autoconf" when attempting to install autoconf. However, this happen with the unresolved brew installation git issue described above. Once that was resolved, https://stackoverflow.com/questions/11552171/cant-install-software-using-brew-on-my-mac helpfully pointed out that autoconf is part of the command line tools package (hence step 4 in the instructions above).

[saint@Saints-MBP-2021 jk % brew install autoconf
fatal: Could not resolve HEAD to a revision
Running 'brew update --preinstall'
==> Homebrew is run entirelv by unpaid volunteers. Please consider donating:
https://github.com/Homebrew/brew#donations
==› Auto-updated Homebrew!
Updated 1 tap (homebrew/cask).
==> Updated Casks
dated 1 cask.
Warning: No available formula with the name
"autoconf"
==› Searching for similarlv named formulae.
Error: No similarly named formulae found.
==> Searching for a previously deleted formula (in the last month).
Error: No previously deleted formula found.
==> Searching taps on GitHub.
Error: No formulae found in taps.

No Such File or Directory @ dir_chdir

Setting up a build environment on my Intel MacBook Pro led to errors like this:

==> Installing autoconf dependency: m4
Error: No such file or directory @ dir_chdir - /usr/local/Cellar

The workaround from https://programmerah.com/brew-install-node-error-no-such-file-or-directory-dir_chdir-bottle-installation-failed-5943/ is to simply reinstall brew.

Missing Xcodebuild tool

One of my bash configure runs failed with this error:

checking for sdk name..
configure: error: No xcodebuild tool and no system framework headers found, use --with-sysroot or --with-sdk-name to provide a path to a valid SDK
/Users/saint/repos/idk/build/.configure-support/generated-configure.sh: line 84: 5: Bad file descriptor
configure exiting with result code 1

This was because the command line tools had not been selected in Xcode as show in step 6. This resolution came from https://stackoverflow.com/questions/17980759/xcode-select-active-developer-directory-error.


Categories: DevOps

Downgrading Cygwin

Last week I was trying to set up an OpenJDK build environment on my Windows 11 machine. Building the repo would fail due to segfaults when running make. The workaround is to downgrade Cygwin from 3.3 to 3.2:

  1. Launch the Cygwin setup program (setup-x86_64.exe).
  2. Change the View dropdown to Full.
  3. Enter cygwin into the search box then select the cygwin package..
  4. Open the cygwin package’s dropdown in the New column.
  5. Change the selection from Keep to the desired version as shown in the image below.
Cygwin Setup - Select Packages 
Select packages to install 
Full 
Pack age 
base-cyg',vin 
cygnin-debuginfo 
cygwin-devel 
cygwin-doc 
cygwin-x-doc 
cygwin32 
cygwin32-binutiIs 
cygwin32-binutiIs-debuginfo 
cygwin32-defaufMıantfest 
cygwi n 32-gcc-core 
cygwi n 32-gcc-debuginfo 
cyg n 32-gcc*oftran 
cygwin32-gcc-g++ 
cygwin32-gettext 
cygwin324ibbfd 
cygwin324ibiconv 
cygwin324ibtooI 
cygwin32%N32apiheadem 
cygwi n -ıuntime 
cygwin32-zIib 
Korg -serv Sh repon er 
Korg -serv er-cygwin shrepoft 
Side obsolete packages 
Src7 Categofies 
Uninstall 
Skip 
31.7-1 
3.1 .ı-ı 
3.12-1 
3.1.5-ı 
3.1.6-ı 
3.1.7-ı 
Size 
O 
kep Best 
Descfiption 
O 
Jest 
332-1 
321-1 
331-0,1.9814cfd8f693 (Test) 
331-0.2.6c1f49f83fde (Test) 
331- ı 
33.1-1 
Keep 
Reinstall 
L] Lhils 
Debug 
2,931k 
Intial base installation helper scıipt 
LIIBtion engine 
or cyg',vın 
pment files 
%fıc documentation including man pages 
yectfic document ation 
t toolchain 
ygwin 3%tt toolchain 
or cygwin32-binutiIs 
ication manifest for Cygwin32 toolchain 
Win 32btt toolchain (C, OpenMP) 
or cygwin32-gcc 
Win 32btt toolchain (Fortran) 
Win 32bt toolchain 
t for Cygwin 32bt toolchain 
Nin 32btt toolchain 
gwin 3%tt toolchain 
gwin 3%tt toolchain 
,gwin 3%tt toolchain 
veadem for Cygwin 3hit toolchain 
libs for Cygwin 3hit toolchain 
in 32btt toolchain 
A breakpad crashrepofter for Cygwin 
Debug info for xorg-servercygwincrashrepofter
Cygwin version selection
  1. Click on the Next button then verify that the downgrade is to the desired version.
Cygwin Setup - Review and confirm changes 
Review coriirm 
Uninstall cygwin 3 3 2-1 (automatically added) 
Install cygwin 3 2 0-1 
c
Reviewing cygwin downgrade version

Finish the setup process then launch cygwin and verify that the version is correct by running:

cygcheck -c Cygwin
Verifying cygwin version after downgrading