Thursday, June 13, 2013

Using Oracle JDK 8 for ARM Early Access VM in OpenJDK under BeagleBoneBlack

Note that Oracle 8 JDK official release for ARM is out.  There is no need to follow the steps below.  Also, if you want to install it via apt-get, you may refer to this link.

Following similar instructions for Raspberry Pi, here are the instructions on how to boost the Java performance on BeagleBone Black by using Oracle's JDK 8 Early Access HotSpot with OpenJDK.

Note that I am using Debian on my BBB

Install openjdk
/mnt/usb/debian/test$ sudo apt-get install openjdk-7-jdk


Optional. Download a benchmark program. Save it as fastaredux.java and test the performance of the stock OpenJDK.
/mnt/usb/debian/test$ java -version
java version "1.7.0_03"
OpenJDK Runtime Environment (IcedTea7 2.1.7) (7u3-2.1.7-1)
OpenJDK Zero VM (build 22.0-b10, mixed mode)
/mnt/usb/debian/test$ javac fastaredux.java
/mnt/usb/debian/test$ time java -XX:+TieredCompilation -XX:+AggressiveOpts fastaredux 25000000 > /dev/null 2>&1

real    1m40.294s
user    1m40.047s
sys     0m0.180s


Download the JDK 8 for ARM Early Access package from Oracle web site.

Following the instructions, extract the hotspot VM and add it to OpenJDK

/mnt/usb/debian/test$ tar --extract --verbose --file=jdk-8-ea-b36e-linux-arm-hflt-29_nov_2012.tar.gz jdk1.8.0/jre/lib/arm/client
jdk1.8.0/jre/lib/arm/client/
jdk1.8.0/jre/lib/arm/client/Xusage.txt
jdk1.8.0/jre/lib/arm/client/libjvm.so
jdk1.8.0/jre/lib/arm/client/libjsig.so
/mnt/usb/debian/test$ sudo mv jdk1.8.0/jre/lib/arm/client /usr/lib/jvm/java-7-openjdk-armhf/jre/lib/arm/oracle
/mnt/usb/debian/test$ sudo chown -R root:root /usr/lib/jvm/java-7-openjdk-armhf/jre/lib/arm/oracle


Make the HotSpot VM as our default VM. Edit the file /etc/java-7-openjdk/jvm-armhf.cfg and add -oracle KNOWN as the first parameter. (or, as stated in the instructions, use the sed command to add it to the first line of the file)
-oracle KNOWN
-server KNOWN
-client IGNORE
-hotspot ERROR
-classic WARN
-native ERROR
-green ERROR
-zero ALIASED_TO -server
-cacao KNOWN
-zero ERROR
-shark ERROR
-jamvm KNOWN


Note the last line of the output. Now it changed to use HotSpot VM
/mnt/usb/debian/test$ java -version
java version "1.7.0_03"
OpenJDK Runtime Environment (IcedTea7 2.1.7) (7u3-2.1.7-1)
Java HotSpot(TM) Client VM (build 25.0-b04, mixed mode)


Result of running the same benchmark. The performance almost tripled.
/mnt/usb/debian/test$ time java -XX:+TieredCompilation -XX:+AggressiveOpts fastaredux 25000000 > /dev/null 2>&1

real    0m35.102s
user    0m34.906s
sys     0m0.166s


Note that using the -server option on the HotSpot VM seems to slow down the performance though.

Using the -server option will actually switch back to use the default OpenJDK Zero VM
$ java -server -version
java version "1.7.0_03"
OpenJDK Runtime Environment (IcedTea7 2.1.7) (7u3-2.1.7-1)
OpenJDK Zero VM (build 22.0-b10, mixed mode)
$ java -version
java version "1.7.0_03"
OpenJDK Runtime Environment (IcedTea7 2.1.7) (7u3-2.1.7-1)
Java HotSpot(TM) Client VM (build 25.0-b04, mixed mode)


You can also alias -server option to use HotSpot VM:
-oracle KNOWN
-server ALIASED_TO -oracle
#-server KNOWN
-client IGNORE
-hotspot ERROR
-classic WARN
-native ERROR
-green ERROR
-zero ALIASED_TO -server
-cacao ERROR
-zero ERROR
-shark ERROR
-jamvm KNOWN


PS. Here is the before vs after result on my Raspberry Pi.

Before:
pi@raspberrypi ~/test $ time java -XX:+TieredCompilation -XX:+AggressiveOpts fastaredux 25000000 > /dev/null 2>&1

real    8m4.807s
user    7m56.410s
sys     0m1.880s


After:
pi@raspberrypi ~/test $ time java -XX:+TieredCompilation -XX:+AggressiveOpts fastaredux 25000000 > /dev/null 2>&1

real    0m44.109s
user    0m43.160s
sys     0m0.320s

No comments:

Post a Comment