mattlewis
Posts: 135
Joined: Sat Jan 12, 2013 3:05 pm
Location: UK
Contact: Website

Building Portable Binaries for Single Board Computers with diozero and GraalVM

Mon May 10, 2021 3:08 pm

This article may be of interest to this community. I've been fascinated with Java performance on the Raspberry Pi (and other devices) as of late. I wrote this article to capture my findings for a classic basic SBC performance test - toggling a GPIO. The results show that GraalVM can produce native images that almost completely remove the traditional Java start-up lag associated with the class loading and JIT "warm-up".

I still need to verify that this native image will run on other 64-bit SBCs, for example the Odroid C2. Update - the native image does indeed work on the Odroid C2 (Armbian 64-bit).

https://derviceiozero.medium.com/buildi ... 59f79d5c71

I plan to produce a related article detailing how to create a QEMU virtual machine to build the native images - 2GB RAM on the Pi 4 wasn't enough to build application unfortunately hence I actually created it via a QEMU AArch64 virtual machine on my laptop.

Comments very welcome.
Last edited by mattlewis on Wed May 12, 2021 2:22 pm, edited 1 time in total.
https://www.diozero.com/

User avatar
clicky
Posts: 535
Joined: Thu Oct 25, 2012 7:34 am

Re: Building Portable Binaries for Single Board Computers with diozero and GraalVM

Tue May 11, 2021 6:07 pm

Interesting finding. Thanks for sharing!

mattlewis
Posts: 135
Joined: Sat Jan 12, 2013 3:05 pm
Location: UK
Contact: Website

Re: Building Portable Binaries for Single Board Computers with diozero and GraalVM

Tue May 11, 2021 7:08 pm

Thanks clicky, a bit of a shame that it is 64-bit only, however, the GraalVM native image really is extremely impressive in terms of start up performance and footprint. Plus the portability with Java and diozero (with its thin JNI abstraction layer) is fantastic.
https://www.diozero.com/

User avatar
clicky
Posts: 535
Joined: Thu Oct 25, 2012 7:34 am

Re: Building Portable Binaries for Single Board Computers with diozero and GraalVM

Wed May 12, 2021 10:07 am

For some unexplained reason I adopted 64bit version of Raspberry Pi OS as my 'standard' :roll: and I'm still suffering for that decision in various ways. But, my current project works perfectly well there. Maybe I could give GraalVM a go with LibGDX, too? I wouldn't mind having extra CPU cycles here and there and add to startup times :)

mattlewis
Posts: 135
Joined: Sat Jan 12, 2013 3:05 pm
Location: UK
Contact: Website

Re: Building Portable Binaries for Single Board Computers with diozero and GraalVM

Wed May 12, 2021 7:01 pm

I'm only doing GPIO / SPI / I2C / Serial with my devices entirely via command line only, no audio or graphical desktop so I've not encountered any issues so far. Having said that I was using the Ubuntu Server 64-bit OS until switching to the 64-bit Raspberry Pi OS relatively recently - it isn't listed on the downloads page!

Word of warning - it takes a few minutes to create the native image and as mentioned needs more than 2GB RAM. This makes it a bit of a pain when in a dev / test lifecycle - the delay makes it difficult to make minor changes and retest - which I had to endure when learning all this stuff. The obvious workflow is to test as normal via the JVM and only once happy to convert to a native image.

Definitely give it a go - let me know how you get on and feel free to ask any questions.
https://www.diozero.com/

User avatar
clicky
Posts: 535
Joined: Thu Oct 25, 2012 7:34 am

Re: Building Portable Binaries for Single Board Computers with diozero and GraalVM

Sun May 16, 2021 1:54 pm

Cool, thanks! :)

BTW my 'desktop-pi' is with 8GB + 1TB SSD - and it works quite well (well - :roll: one needs more patience than, let's say MBP with only twice the memory and 2/3 times to CPU speed). There I'm happily using Eclipse (which works quite faster than IntelliJ) and PyCharm for Python (well - Eclipse doesn't have good Python support :( )

I might give it a go now as I have the latest version of the code checked out there.

User avatar
clicky
Posts: 535
Joined: Thu Oct 25, 2012 7:34 am

Re: Building Portable Binaries for Single Board Computers with diozero and GraalVM

Sun May 16, 2021 3:26 pm

Oh, well - tried :)
Simple stuff as in your post (HelloWorld) compiles without any issues. This complex code - not so much:

Code: Select all

Error: Classes that should be initialized at run time got initialized during image building:
 io.netty.buffer.UnpooledHeapByteBuf the class was requested to be initialized at run time (subtype of io.netty.buffer.AbstractReferenceCountedByteBuf). To see why io.netty.buffer.UnpooledHeapByteBuf got initialized use --trace-class-initialization=io.netty.buffer.UnpooledHeapByteBuf
io.netty.buffer.AbstractReferenceCountedByteBuf the class was requested to be initialized at run time (from the command line). To see why io.netty.buffer.AbstractReferenceCountedByteBuf got initialized use --trace-class-initialization=io.netty.buffer.AbstractReferenceCountedByteBuf
Not sure if I'm up to trying to fix it right now! :)

Return to “Java”