First Steps with Java's New Vector API and JITWatch

Описание к видео First Steps with Java's New Vector API and JITWatch

Java has a new Vector API and in this video I show the basics of how to use it.

To get everyone on the same page, I start by showing how to prepare the Eclipse IDE. This includes the installation process, installing a couple plugins (Launch Configuration View, and Jeeeyul's Eclipse Themes), and walking through several preferences that I wish someone had told me about earlier.

The new Vector API is still "incubating" so it's no surprise that performance is improving with each new release of the JDK. To highlight the differences, I show how to test your code with Java 16, 17, and 18. Java 18 is not out yet, but nightly builds are available on Shipilev's web site (and other places.)

I share an example of when you might use vectorized (SIMD) code: checksum validation. Telemetry Viewer has a "binary mode" with optional checksums, and this is one area of my code that could use some optimizing. I benchmark my original scalar code against four attempts at vectorizing it. As we'll see, sometimes performance gets better, but other times it gets worse -- sometimes much worse. We'll run across a bug in Java 16, and see how slowly some of the API's fallback implementations perform.

The code is tested in Windows, in a Linux VM, and even on a Raspberry Pi 4. Two versions of Raspberry Pi OS are tested: the default Arm32 (32-bit) version, and the beta AArch64 (64-bit) version. The new vector API does not support Arm32 right now, and we'll see some serious bugs that crashed the JVM when running on a Pi.

With 3 operating systems to test, and 3 versions of Java for each OS, that's a total of 9 different configurations. It would be a pain to manually test changes to the code, but we can use Eclipse's "Launch Group" feature to automate the whole process. It's like a crude CI/CD pipeline.

Finally, I show how to use JITWatch to look at how your source code transforms to Java bytecode and to actual assembly instructions. We can get the runtime to output a log with the disassembly and optimization details by using a handful of flags passed to the JRE. That log can then be parsed by JITWatch, allowing us to see what happened.

OpenJDK does not include the disassembler due to licensing conflicts, so I show to to manually compile the HSDIS DLL. This involves use Cygwin to setup a development environment, and downloading the source code for OpenJDK and Binutils. A Make target is invoked, and after a few minutes the DLL is ready to use.

A text summary of this video is available on my web site:
http://www.farrellf.com/projects/soft...

Комментарии

Информация по комментариям в разработке