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
Please include hsdis in Adoptium builds #213
Comments
Thanks for opening the discussion. Just to note that |
@theRealAph Reading a bit around this tool for the first time, a popular backend option is to use For the record, the resulting |
The Binutils backend is the one that has been in OpenJDK since launch - and before there were different backends - and suffers from a license incompatibility between it (GPLv3+) and HotSpot (GPLv2). That's one of the main reasons the other backends were introduced. There is also now an LLVM backend which is what I'm planning to look into packaging in RHEL & Fedora, as they already have LLVM packages available. |
From a technical point of view I'd use Binutils, but there's no licence-conforming way to to do it, as far as I can see from GPL v3. But it's something of a legal grey area. I don't want to go there. Hsdis built with Capstone is about the same size as Binutils, at 2.4M. |
Noting that CentOS6 (which we use for building on x86 Linux for JDK17 and below) does not have capstone in its repositories so we may need to build from source on there. [EDIT: The flags to enable hsdis only seem to be in later versions of the codebase, so we would only be able to use these options on systems which aready build with CentOS/RHEL7, so the CentOS6 thing is not a blocking issue unless this gets backported to JDK17] |
My current initial approach has been to install a suitable capstone as part of the machine setup process (within our ansible scripts) and then invoke the appropriate options during the openjdk build to pick it up. This should allow it to work on CentOS6 without the problems from the earlier comment, and also keep the library smaller (some default installations of capstone appear to contain support for every architecture in the library) A second option would be to build (and probably therefore also download during each build) the library as part of the Temurin build process, so we'd rebuild it each time. Since this implementation is re-shipping the built library, this might be a preferable option. Thoughts? |
3rd option:
|
After a couple of discussions today I am now leaning more towards an option 2.5 (Somewhere between 2 and 3) of pulling from pre-built binaries on stored in the |
The main advantage of Capstone is that it is small, and it has a BSD licence, thus GPL v2 compatible. Be aware that Capstone can be built in multiple ways. By default, it builds for all architectures. This is not what we want. |
Yep the draft PR I had was to only build for the specific architecture. The approach I'm trialing after my last comment is to store prebuilt versions for each architecture in a form we can download and use within the build process to ensure that we are using an identical binary for each build for reproducibility comparison purposes. Broadly speaking I'm doing this to build the version, which we will cache and use in a build PR I'm about to look at putting together :-)
|
I'm thinking we go for an initial approach of doing it dynamically against a suitable capstone and then subsequently look at adjusting that to do it statically if we make the changes upstream. WDYT @theRealAph? Noting that if we don't statically link capstone4, CentOS Stream 9 (so likely RHEL9), Ubuntu 22.04 (Latest LTS) and Debian 12 Bookworm all have it. Earlier major versions do not. I think I'm leaning back towards my option 1 above and installing as version in the playbooks which would have the additional advantage that it would be installed on the system for the purposes of testing until such time as we statically link it in. |
The PMC decided today to not include it in the 20.0.1 October deliverable and to subsequently evaluate whether this was useful in a non-development build of the JDK. As an interim we can let users use the builds in the previous comment for evaluation purposes and feedback, or we can look at providing a separate hsdis library that people could add in if desired. This may be more useful once we get a statically linked version of capstone included into hsdis. |
This is the JDK, not the JRE, right? So it's for Java developers. Some popular tools, especially JMH, need hsdis in order to provide full functionality. Sure, hsdis can be built externally, but you need JDK source to do it, and our Java developers shouldn't have to do that, and many of them don't even know how to do that. Being able to see the generated code is very useful as an educational tool for helping Java developers understand performance issues. C/C++ compilers provide visible assembly-language, and IMVHO all Java developers have a right to this information too. |
My understanding was that the current approach of building |
hsdis (a disassembler) is extremely useful when analysing HotSpot performance. At present Temurin builds don't support hsdis.
Capstone is a "univeral disassembler" project. It is easy to use Capstone to build OpenJDK's hsdis.
To build OpenJDK using Capstone you need to have Capstone installed. Typical ways of installation can be
sudo apt install libcapstone-dev
(on Debian and derivatives), or brew install capstone (on macOS with Homebrew). For Windows, you need to download the "Core Engine", and unzip it. See the Capstone Download page for up-to-date download links.The easiest way to build with support for hsdis on RHEL/CentOS is something like this:
After this, the newly-built shared library
jdk/lib/hsdis-XXX.so
(not the built JDK, just hsdis) has a runtime dependency onlibcapstone.so.4.x
. So, to use the disassembly option in OpenJDK not only must a user install the Capstone library, but they must install Version 4 of it. This is rather unfortunate.An alternative would be to link hsdis statically against libcapstone. This means that we have no runtime dependency on capstone. This would require me to make a small change to the OpenJDK configuration upstream.
As far as I'm aware there are no licence problems using Capstone in this way.
The text was updated successfully, but these errors were encountered: