posts
Liberica JDK offers
native Java builds
for Apple Silicon M1

Liberica JDK offers native Java builds for Apple Silicon M1

Mar 12, 2021
Aleksei Voitylov
13.6

As of January 2021, Liberica JDK runs natively on Macs powered by the first processor of Apple’s design specifically for Macintosh computers, M1. This feature applies to both LTS’s (8, 11, 17) and the current version. 18 months have passed since then. Apple extended the line of M1 processors, each more powerful than the previous one. But as a Java developer, you must primarily be interested in practical things:

  • Are there any compatibility issues?
  • Are all solutions optimized for Apple M1?
  • Are there any differences in installing and running software?
  • Which applications will benefit most from Apple silicon?

Find the answers to these questions and more in our article!

 

Thinking different with Apple silicon

What do we understand by this concept? Well, it’s three things in one, each with its weight.

Primarily, it refers to Apple-designed chips and the company’s first ARM-based SoCs (systems on a chip) for Macs called M1. They are intended to replace the lineup of Core processors. Some people would mean specific devices with the said processor: Mac mini, as well as MacBook Pro 13 and MacBook Air, both Late 2020. The third possible denomination builds upon the macOS Big Sur and newer. In this case, Apple silicon should be viewed as a hardware + software combination designed for ultimate speed and performance.

The overarching characteristic here is a transition to the arm64 architecture. This is right up BellSoft’s alley — we’ve been exploring this technology for many years (read more in my article for Java Magazine, Sep/Oct 2018). Its key difference between ARM and x86 CPUs is in their methods for building instruction set architectures (ISAs): CISC and RISC. While the first design, Complex Instruction Set Computing, focuses on complicated instructions to encode more than one operation, RISC (Reduced Instruction Set Computing) based one uses fixed-length instructions, each performing a single operation. Thus, ARM is optimal for mobile devices, and x86 is perfect for desktops. But everything is changing.

When arm64 moves to desktops, it shows significant advantages:

  • with ARM lower TDP (Thermal Design Power) per core, M1 is much more energy-efficient
  • early benchmark tests already show how the new chips outclass Intel-made processors in previous Macs

Here’s an illustration of why we need a native JVM for Apple silicon. We took several DaCapo benchmarks using default JVM parameters on two implementations: macOS-x86_64 on Rosetta 2 and macOS-aarch64. A few times difference in performance is the answer.

Family of Apple silicon chips

Apple silicon reveals new capacities with each new product in the line.

In addition to the basic M1 chip, Apple released M1 Max in 2021, and M1 Ultra and M1 Pro in 2022. Both M1 Max and M1 Pro feature up to ten CPU cores with eight performance cores and two efficiency cores , but M1 Pro includes 16 GPU cores, whereas M1 Max has twice as much. M1 Pro stands between plain M1 and M1 Max chips in terms of performance and is suitable for most professional tasks. But users who have to deal with demanding GPU workflows such as 3D modeling, video editing, etc., will benefit more from the M1 Max, which also has two video encode engines as compared to M1 Pro with only one. 

M1 Ultra is the most powerful chip in the family. It features 20 CPU cores and 64 GPU cores as It is essentially two M1 Max chips connected together with a silicon interposer — the technique helped to avoid performance tradeoff and increased power consumption. So the new chip boasts doubled capabilities of M1 Max and can be considered the most powerful PC chip in the world (although due to its size, M1 Ultra is utilized only in the Mac Studio):

  • The Geekbench 5 benchmark demonstrated M1 Ultra multi-core performance results of 24,055, which is three times higher than M1 results and almost two times higher than M1 Max
  • 128GB of unified memory as compared to max 48 GB in the most powerful PC graphic cards deliver the most impressive results for intensive GPU workflows
  • The 32-core Neural Engine running up to 22 trillion operations per second is fit for the most demanding machine learning tasks 
  • Thanks to four video encode engines, M1 Ultra is the only chip in the world that can play back up to 18 streams of 8K ProRes 422 video  

In June 2022, the company introduced one more Apple silicon family member — the M2 chip. It nestles cozily in-between M1 and M1 Pro. Apple claims it has an 18% increase in CPU performance, a 35% increase in GPU performance, and a 40% more performant Neural Engine as compared to the M1 chip.    

Apple’s expansion of the processor family means, firstly, that the research continues and we may expect even more powerful chips in the future, and secondly, that any user can choose a device perfectly suitable for their needs.

Liberica JDK on M1

How to install Java on macOS (x86 or ARM)

Liberica JDK for M1 is a production-ready TCK-verified binary. Try BellSoft’s progressive Java runtime for modern deployments and fully experience its benefits for macOS users.

For the latest JDK release on macOS, BellSoft offers a choice between Liberica JDK for x86 and ARM. However, we recommend installing both runtimes on your M1 device in early 2021.

  1. Download the .zip package and unpack it. Change the name of the top-level directory to jdk-xx.xx.xx.jdk (e.g. jdk-11.0.10.jdk).
wget https://download.bell-sw.com/java/11.0.10+9/bellsoft-jdk11.0.10+9-macos-amd64.zip

unzip bellsoft-jdk11.0.10+9-macos-amd64.zip

  1. Download the second archive and unpack it without changes.
wget https://download.bell-sw.com/java/11.0.10+9/bellsoft-jdk11.0.10+9-macos-aarch64.zip

unzip bellsoft-jdk11.0.10+9-macos-aarch64.zip

DO NOT download and install DMG files if you want to run both x86 and ARM builds on one JDK version.

Alternatively, you may use DMG to install different versions of Liberica JDK (e.g. 15.0.2 for ARM + 11.0.10 for x86 ). Learn more about this process in the Install Guide.

Why are native builds important? Java™ is a cross-platform language, meaning that all Java applications should run on every system available. But large software often has native code compiled for a specific architecture, including x86_64, which had been the only option in desktop and laptop Macs.

Another reason is that many app developers have not yet moved their products to ARM. They will eventually. Apple itself expects the transition to take about two years, during which it will still produce Intel-based machines. For the time being, older versions of software built for x86 can run under a special translation environment, Rosetta 2, bundled with Big Sur. This virtualization tool, in fact, makes both x86 and ARM builds of Liberica JDK work simultaneously.

Support for JVM features:

  • all necessary garbage collectors
  • C1 and C2 just-in-time compilers required for normal operation

Docker

The latest Docker versions are compatible with Apple silicon. Docker Desktop supports multi-platform images, so there is no need for a complex cross-compilation environment in case you want to build images for both platforms: x86 and ARM. In addition, the docker buildx command enables seamless integration of multi-platform builds into the project.

Compatibility issues are being gradually eliminated. However, there are still cases when you need to use Rosetta 2:

  • Some command line options (the old version of 1x docker compose, docker scan, and docker-credential-ecr-login) do not work without translator software
  • Some images do not support ARM64 yet
  • ping from inside a container to the Internet is associated with unexpected behavior
  • Occasional data drop with a half-closed TCP stream

It is recommended to use containers built for ARM64 whenever possible to avoid issues and performance deterioration. Use Docker Hub to identify images supporting ARM64. 

GraalVM

Starting with GraalVM version 22.1, the technology is compatible with ARM64. The components built on JDK11 or JDK17 include JVM with libgraal, native-image, JavaScript, Java on Truffle (Espresso).

Liberica Native Image Kit, a tool based on GraalVM CE, is also available for Apple silicon. Unlike GraalVM CE that comes only as .tar.gz package, Liberica NIK can also be downloaded as .dmg with a convenient Installator.

In addition, Liberica NIK comes in three versions: Full with LibericaFX (an instance of OpenJFX), Standard with plugins for non-Java languages, and Core with Liberica VM and native-image without support for language installables.

Technologies not yet optimized for Apple silicon

Although the software optimization for Apple M1 chips is in full swing, some applications including VirtualBox still do not support the new architecture. A solution would be to search for alternatives. For instance, VirtualBox can be substituted with VMware Fusion.

Other utilities require Rosetta 2 to function properly: MongoDB Compass, MongoDB, Apache Maven, MySQL Workbench, etc. A comprehensive compatibility table can be found here.

Features specific to Liberica JDK

  • BellSoft provides a notarized runtime, which allows notarizing your Java or JavaFX applications. To learn more about how to use Liberica JDK with the Javapackager tool, follow our detailed notarization guide
  • Serviceability Agent API in JDK 8 to monitor VM’s internal operations, a handy tool for advanced Java development
  • Full Liberica JDK binaries include JavaFX for complex and appealing visual interfaces, complete with OpenJFX Graphics, Media (video and audio), Controls, and Webkit modules

Conclusion

The ARM architecture has been a prominent trend during the past couple of years. We feel fortunate to have predicted its rise back in 2018. Thanks to that, BellSoft is now one of the few OpenJDK contributors who are actively involved in advancing Java on this platform. Apple M1 promises massive power shifts in the IT industry, and we’re looking to the future with interest and healthy optimism. While macOS app developers are slowly transitioning from x86, you may count on Liberica JDK to run seamlessly on every device and have your business covered.

Subcribe to our newsletter

figure

Read the industry news, receive solutions to your problems, and find the ways to save money.

Further reading