iOSプラットフォームの実装の詳細

JDK 9 iOSポートは、x64シミュレーターとARM64ビットデバイスの実行の両方をサポートします。x64実装は標準のホットスポットJITを使用しますが、ARM64ビットデバイスの実装はゼロインタープリターに制限されています。これは、AppleがiOSARMプラットフォームでの動的コード生成を許可していないためです。この制限により、ホットスポットの動的に生成されたテンプレートインタープリターは実行時に生成されるため、使用できません。この制限を回避するために、iOSデバイスのサポートをゼロ「C」インタープリターに依存しています。

ビルド要件

ビルドマシン

iOS JDK 9ビルドには、Xcode7以降を実行できるMacシステムが必要です。Xcode 7を実行するには、少なくともOSX 10.10.5(Yosemite)が必要です。

Xcode

私たちのプロジェクトには現在、開発者サイトでAppleからダウンロードできるXcode7.1が必要です。

https://developer.apple.com/xcode/

libffi(ARMビルドにのみ必要)

iOS arm64ポートで使用されるZeroインタープリターには、ネイティブ関数を呼び出すためのサードパーティライブラリが必要です。このライブラリはlibffi(Foreign Function Interface Library)です。現在、このライブラリのバージョン3.2.1を使用しています。

libffi 3.2.1ソースは、ここからダウンロードできます。

https://sourceware.org/libffi/

バンドルをダウンロードして作業ディレクトリに解凍し、そのディレクトリに「cd」してから、次のコマンドを実行します。

%xcodebuild -arch arm64
%cdbuild_iphoneos-arm64
%make prefix = `pwd` install

「makeinstall」はライブラリをビルドし、build_iphoneos-arm64のincludeディレクトリとlibディレクトリに、JDKのビルドに必要なビルドされたlibffiライブラリアーティファクトを入力します。

libfreetype

FreeType 2.6.2ソースは、次の場所からダウンロードできます。

http://freetype.org/download.html

iOS x86_64ディストリビューションをビルドするには、ソースをダウンロードし、最上位ディレクトリにcdして、次のコマンドを実行します。

。/構成、設定 \
-なし-zlib \
-なし-png \
-なし-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 '
きれいにする
作る
インストールする

ビルドの出力はbuild_iphoneos-x86_64ディレクトリに保存されます

iOS arm64ディストリビューションを構築するには、次のコマンドを実行します。

% 。/構成、設定 \
-なし-zlib \
-なし-png \
-なし-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/開発者/SDK/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
%make install

ビルドの出力はbuild_iphoneos-drm64ディレクトリに保存されます

JDKの構築

必要なツールとライブラリをビルドしたら、モバイル/開発ソースをダウンロードし、ビルドシステムのセットアップに合わせて以下のビルドコマンドをカスタマイズし、ビルドスクリプトを実行します。

ソースのダウンロード

hg clone http://hg.openjdk.java.net/mobile/dev mobile-dev
cd mobile-dev
sh get_source.sh

x86_64のビルドコマンド

#!/ bin / csh
#セットアップに合わせて次のパスをカスタマイズします
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設定\
--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 = minimum1 \
--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-プリコンパイル済みヘッダー\
--with-freetype-lib = $ FREETYPE_DIR / lib \
--with-freetype-in​​clude = $ FREETYPE_DIR / include / freetype2

cd build / ios-x86_64-normal-minimal1-release
画像を作る

arm64のビルドコマンド

#!/ bin / csh
#セットアップに合わせて次のパスをカスタマイズします
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設定\
--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-プリコンパイル済みヘッダー\
--with-freetype-lib = $ FREETYPE_DIR / lib \
--with-freetype-in​​clude = $ FREETYPE_DIR / include / freetype2

cd build / ios-aarch64-normal-zero-release
画像を作る

サンプルXcodeシミュレータプロジェクト

iOS x86_64 JDK 9バイナリイメージの構築に成功したら、Xcodeシミュレーターで実行することにより、テストドライブに使用できます。

これを行うには、以下のリンクからサンプルHelloWorldプロジェクトをダウンロードし、指示に従います。

Xcode iOSX86_64サンプルHelloWorldプロジェクト

HELLOWORLDサンプルの実行 

%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

Xcode IDEで実行していて、VMの実行中にSIGSEGVまたはSIGBUSが表示される場合、これらは完全に正常である可能性があります。

このSEGVが予期されているかどうかを判断する最も簡単な方法は、信号をVMに配信できるようにすることです。これを行うには、VMを起動する前に、Xcodelldbウィンドウで次の2つのコマンドを実行します。

プロセスハンドル-sfalse SIGSEGV
プロセスハンドル-sfalse SIGBUS

シグナルをプロセスに渡した後、Javaランタイムが正常に機能する場合、これらのシグナルが予期されます。VMがクラッシュした場合は、デバッグの時間です。

原文