mike-neckのブログ

Java or Groovy or Swift or Golang

loom の JDK をビルドしてみた

表題の通り、 project loom の JDK をビルドしてみた。

f:id:mike_neck:20181019112748p:plain


環境

以下の環境でビルドした。癖で(バーストしない方がよいかなと思って)インスタンスタイプは m5a.large にしたけど、 t3a.micro とかでもいいかもしれない(よくわからん)。

boot JDK には jdk12 または jdk13 しか選べない。 Java 8 や Java 11 ではビルドできないので注意。


ビルド方法

project loom の mercurial レポジトリーをクローンして、 configure すれば必要なソフトウェアがわかるので、上記 OS 以外の人は configure の際に表示される案内に従うこと。

また、 configure の際に、 --prefix=$HOME/loom みたいなパラメーターをつけると、 make install でインストールされるディレクトリーが設定できる。デフォルトは /usr/local/bin にインストールされる。

sudo apt-get update
sudo apt-get install -y build-essential mercurial zip unzip autoconf \
    curl libx11-dev libxext-dev libxrender-dev libxrandr-dev libxtst-dev \
    libxt-dev libcups2-dev libfontconfig1-dev libasound2-dev
curl -s "https://get.sdkman.io" | bash
source "/root/.sdkman/bin/sdkman-init.sh"

mkdir /work
cd /work
hg clone http://hg.openjdk.java.net/loom/loom/
cd loom
hg update -r fibers 
chmod +x configure
./configure --prefix=$HOME/loom
make images
make install

あと、なぜかは不明だが docker でビルドすると、もれなく docker ごと落ちてしまうっぽい。

実行

上記のスクリプト$HOME/loom にインストールされる。その中にに jvmbin というディレクトリーができる。 jvm/openjdk-13-internal/bin/jshell または bin/jshell を実行すると、 Jshell が起動できる。

$ $HOME/loom/bin/jshell
May 20, 2019 9:22:38 PM java.util.prefs.FileSystemPreferences$1 run
INFO: Created user preferences directory.
|  Welcome to JShell -- Version 13-internal
|  For an introduction type: /help intro

jshell>

お約束の Continuation

jshell> var cont = new Continuation(scope, () ->
   ...>   IntStream.range(0,10).
   ...>     <Runnable>mapToObj(i -> () -> System.out.println("phase: " + i)).
   ...>     flatMap(runnable -> Stream.of(runnable, () -> Continuation.yield(scope))).
   ...>     forEach(Runnable::run))
cont ==> java.lang.Continuation@6d21714c scope: test-scope

jshell> while(!cont.isDone()) {
   ...>   System.out.println("running");
   ...>   cont.run();
   ...> }
running
phase: 0
running
phase: 1
running
phase: 2
running
phase: 3
running
phase: 4
running
phase: 5
running
phase: 6
running
phase: 7
running
phase: 8
running
phase: 9
running