iOS Platform Implementation Details
The JDK 9 iOS port supports both x64 simulator and ARM 64-bit device execution. The x64 implementation uses the standard Hotspot JIT but the ARM 64-bit device implementation is restricted to the Zero interpreter. This is due to the fact that Apple does not allow dynamic code generation on iOS ARM platforms. This restriction prohibits using the Hotspot dynamically generated template interpreter since it is generated at runtime. To work around this limitation we rely on the Zero "C" interpreter for iOS device support.
Build Requirements
Build machine
The iOS JDK 9 build requires a Mac System capable of running Xcode 7+. Xcode 7 requires at a minimum OSX 10.10.5 (Yosemite) in order to run.
Xcode
Our project currently requires Xcode 7.1 which can be downloaded from Apple at their developer site.
https://developer.apple.com/xcode/
libffi (required for ARM builds only)
The Zero interpreter used in our iOS arm64 port requires a third party library for calling native functions. This library is libffi (Foreign Function Interface Library). We are currently working with version 3.2.1 of this library.
The libffi 3.2.1 sources can be downloaded from here:
https://sourceware.org/libffi/
Download the bundle and untar it to a working directory, "cd" into that directory and then execute the following commands:
% xcodebuild -arch arm64 % cd build_iphoneos-arm64 % make prefix=`pwd` install
The "make install" will build the library and populate the include and lib directories in build_iphoneos-arm64 with the built libffi library artifacts needed to build the JDK.
libfreetype
The FreeType 2.6.2 sources can be downloaded from here:
http://freetype.org/download.html
To build an iOS x86_64 distribution, download the sources, cd to the top directory and run these commands:
./configure \ --without-zlib \ --without-png \ --without-bzip2 \ --host=x86_64-apple-darwin \ --prefix=`pwd`/build_iphoneos-x86_64 \ CFLAGS='-arch x86_64 -miphoneos-version-min=8.0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/' \ LDFLAGS='-miphoneos-version-min=8.0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/ -L/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/lib -L/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/lib/system' make clean make make install
The output of the build will be stored in the build_iphoneos-x86_64 directory
To build an iOS arm64 distribution, run these commands:
% ./configure \ --without-zlib \ --without-png \ --without-bzip2 \ --prefix=`pwd`/build_iphoneos-arm64 \ --host=arm-apple-darwin \ --enable-static=yes \ --enable-shared=no \ 'CFLAGS=-arch arm64 -pipe -std=c99 -Wno-trigraphs -fpascal-strings -O2 -Wreturn-type -Wunused-variable -fmessage-length=0 -fvisibility=hidden -miphoneos-version-min=8.0 -I/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/libxml2/ -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/' \ AR=/usr/bin/ar \ 'LDFLAGS=-arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/ -miphoneos-version-min=8.0' % make clean % make % make install
The output of the build will be stored in the build_iphoneos-drm64 directory
Building the JDK
Once you have the required tools and libraries built, download the mobile/dev sources, customize the build commands below to match your build system setup and run the build script.
Downloading the sources
hg clone http://hg.openjdk.org/mobile/dev mobile-dev cd mobile-dev sh get_source.sh
Build command for x86_64
# !/bin/csh # # Customize the following paths to match your setup # setenv CUPS_DIR $HOME/jdk9mobile/cups/include setenv FREETYPE_DIR $HOME/jdk9mobile/freetype-2.6.2/build_iphoneos-x86_64 setenv JDK_DIR /Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home # cd mobile-dev bash configure \ --enable-option-checking=fatal \ --build=x86_64-apple-darwin \ --host=x86_64-macos-ios \ --target=x86_64-macos-ios \ --disable-warnings-as-errors \ --enable-headless-only \ --with-boot-jdk=$JDK_DIR \ --with-jdk-variant=normal \ --with-jvm-variants=minimal1 \ --enable-static-build=yes \ --with-extra-cflags="-arch x86_64 -Wno-implicit-function-declaration -Wno-unused-parameter -miphoneos-version-min=8.0.0" \ --with-extra-cxxflags="-arch x86_64 -Wno-implicit-function-declaration -Wno-unused-parameter -miphoneos-version-min=8.0.0" \ --with-extra-ldflags="-arch x86_64 -miphoneos-version-min=8.0.0 -L/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/lib -L/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/lib/system" \ --with-cups-include=$CUPS_DIR \ --with-sys-root=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk \ --with-tools-dir=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/../../usr/bin \ --with-debug-level=release \ --disable-precompiled-headers \ --with-freetype-lib=$FREETYPE_DIR/lib \ --with-freetype-include=$FREETYPE_DIR/include/freetype2 cd build/ios-x86_64-normal-minimal1-release make images
Build command for arm64
# !/bin/csh # # Customize the following paths to match your setup # setenv LIBFFI_DIR $HOME/jdk9mobile/libffi-3.2.1/build_iphoneos-arm64 setenv CUPS_DIR $HOME/jdk9mobile/cups/include setenv FREETYPE_DIR $HOME/jdk9mobile/freetype-2.6.2/build_iphoneos-arm64 setenv JDK_DIR /Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home # cd mobile-dev bash configure \ --enable-option-checking=fatal \ --build=x86_64-apple-darwin \ --host=aarch64-macos-ios \ --target=aarch64-macos-ios \ --disable-warnings-as-errors \ --enable-headless-only \ --with-boot-jdk=$JDK_DIR \ --with-jdk-variant=normal \ --with-jvm-variants=zero \ --enable-static-build=yes \ --with-libffi-include=$LIBFFI_DIR/include \ --with-libffi-lib=$LIBFFI_DIR/lib \ --with-extra-cflags="-arch arm64 -Wno-implicit-function-declaration -Wno-unused-parameter -miphoneos-version-min=8.0.0" \ --with-extra-cxxflags="-arch arm64 -Wno-implicit-function-declaration -Wno-unused-parameter -miphoneos-version-min=8.0.0" \ --with-extra-ldflags="-arch arm64 -miphoneos-version-min=8.0.0 -L/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib -L/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib/system" \ --with-cups-include=$CUPS_DIR \ --with-sys-root=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk \ --with-tools-dir=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin \ --with-debug-level=release \ --disable-precompiled-headers \ --with-freetype-lib=$FREETYPE_DIR/lib \ --with-freetype-include=$FREETYPE_DIR/include/freetype2 cd build/ios-aarch64-normal-zero-release make images
Sample Xcode Simulator Project
Once you have successfully built an iOS x86_64 JDK 9 binary image, you can take it for a test drive by running it under the Xcode simulator.
To accomplish this, download the Sample HelloWorld project from the link below and follow the instructions.
Xcode iOS X86_64 Sample HelloWorld Project
RUNNING THE HELLO WORLD SAMPLE % tar xzvf hello-ios-x86_64.tar.gz % setenv BUILD_DIR {mobile_dir}/build/ios-x86_64-normal-minimal1-release % cd hello-ios-x86_64 % bash copy-jre.sh {mobile_dir} is the location where you installed the JDK 9 Mobile forest.
Once these steps are completed, open the hello-ios-x86_64/hello.xcodeproj in your Xcode program.
In Xcode, select Build and then Run.
This should bring up a Simulator with the Hello application. Click on the RunJava button which will start Java and display "Hello World" in the Xcode console.
If you wish to update the Java runtime that's being used by the Hello application, use the remove-jre.sh script to remove it and re-execute the copy-jre.sh script to install a new Java runtime.
Known Issues & Troubleshooting
1. SIGSEGV or SIGBUS while running Java
If you are running under the Xcode IDE and are seeing SIGSEGV or SIGBUS while the VM is running, these may be perfectly normal.
The quickest way of determining if this SEGV is expected is to allow the signal to be delivered to the VM. To do this, execute these two commands in the Xcode lldb window prior to launching the VM:
process handle -s false SIGSEGV process handle -s false SIGBUS
If the Java runtime functions normally after passing the signals to the process, then these signals are expected. If the VM crashes, then it's time for debugging.