Fight the Future

Java言語とJVM、そしてJavaエコシステム全般にまつわること

macOSでOpenJDK(panama)ビルドするとエラーになってたのをクリアしてビルドし、Vector APIを試す

前回amberはビルドできたのですが、panamaはmakeでエラーになりました。

jyukutyo.hatenablog.com

今回panamaもビルドしてVector APIを試すことができました。

結論

configureでオプションを付ける。つまり、エラーを無視しているだけである。

$ bash ./configure --with-extra-cflags="-Wno-error=deprecated-declarations -Werror=nonnull -Wno-undefined-var-template -Wno-error=mismatched-parameter-types -Wno-error=shift-negative-value"
$ make

エラーを理解して直せればいいのですが、いかんせんnon-Javaな世界。どうすればいいかまったくわからず、エラーを無視するオプションをつけるというしょぼい手段です。

詳細

前回はこういうエラーが出ていました。

In file included from /Users/jyukutyo/code/panama/hotspot/src/share/vm/gc/cms/compactibleFreeListSpace.cpp:1:
In file included from /Users/jyukutyo/code/panama/hotspot/src/share/vm/precompiled/precompiled.hpp:296:
In file included from /Users/jyukutyo/code/panama/hotspot/src/share/vm/gc/cms/compactibleFreeListSpace.hpp:33:
/Users/jyukutyo/code/panama/hotspot/src/share/vm/memory/binaryTreeDictionary.hpp:167:12: error: instantiation of variable 'TreeChunk<FreeChunk, AdaptiveFreeList<FreeChunk> >::_min_tree_chunk_size' required here, but no definition is available [-Werror,-Wundefined-var-template]
    return _min_tree_chunk_size;
           ^
/Users/jyukutyo/code/panama/hotspot/src/share/vm/memory/binaryTreeDictionary.hpp:293:44: note: in instantiation of member function 'TreeChunk<FreeChunk, AdaptiveFreeList<FreeChunk> >::min_size' requested here
    return TreeChunk<Chunk_t, FreeList_t>::min_size();
                                           ^
/Users/jyukutyo/code/panama/hotspot/src/share/vm/gc/cms/compactibleFreeListSpace.cpp:2681:67: note: in instantiation of member function 'BinaryTreeDictionary<FreeChunk, AdaptiveFreeList<FreeChunk> >::min_size' requested here
      fc = dictionary()->get_chunk(MAX2(n * word_sz, _dictionary->min_size()),
                                                                  ^
/Users/jyukutyo/code/panama/hotspot/src/share/vm/memory/binaryTreeDictionary.hpp:148:17: note: forward declaration of template entity is here
  static size_t _min_tree_chunk_size;
                ^
1 error generated.
make[3]: *** [/Users/jyukutyo/code/panama/build/macosx-x86_64-normal-server-release/hotspot/variant-server/libjvm/objs/compactibleFreeListSpace.o] Error 1
make[3]: *** Waiting for unfinished jobs....
Compiling 18 files for java.datatransfer
Compiling 118 files for java.compiler
Compiling 34 files for java.logging
make[2]: *** [hotspot-server-libs] Error 2
make[2]: *** Waiting for unfinished jobs....

ERROR: Build failed for target 'default (exploded-image)' in configuration 'macosx-x86_64-normal-server-release' (exit code 2) 
Stopping sjavac server

=== Output from failing command(s) repeated here ===
* For target hotspot_variant-server_libjvm_objs_compactibleFreeListSpace.o:
In file included from /Users/jyukutyo/code/panama/hotspot/src/share/vm/gc/cms/compactibleFreeListSpace.cpp:1:
In file included from /Users/jyukutyo/code/panama/hotspot/src/share/vm/precompiled/precompiled.hpp:296:
In file included from /Users/jyukutyo/code/panama/hotspot/src/share/vm/gc/cms/compactibleFreeListSpace.hpp:33:
/Users/jyukutyo/code/panama/hotspot/src/share/vm/memory/binaryTreeDictionary.hpp:167:12: error: instantiation of variable 'TreeChunk<FreeChunk, AdaptiveFreeList<FreeChunk> >::_min_tree_chunk_size' required here, but no definition is available [-Werror,-Wundefined-var-template]
    return _min_tree_chunk_size;
           ^
/Users/jyukutyo/code/panama/hotspot/src/share/vm/memory/binaryTreeDictionary.hpp:293:44: note: in instantiation of member function 'TreeChunk<FreeChunk, AdaptiveFreeList<FreeChunk> >::min_size' requested here
    return TreeChunk<Chunk_t, FreeList_t>::min_size();
                                           ^
/Users/jyukutyo/code/panama/hotspot/src/share/vm/gc/cms/compactibleFreeListSpace.cpp:2681:67: note: in instantiation of member function 'BinaryTreeDictionary<FreeChunk, AdaptiveFreeList<FreeChunk> >::min_size' requested here
      fc = dictionary()->get_chunk(MAX2(n * word_sz, _dictionary->min_size()),
                                                                  ^
   ... (rest of output omitted)

* All command lines available in /Users/jyukutyo/code/panama/build/macosx-x86_64-normal-server-release/make-support/failure-logs.
=== End of repeated output ===

No indication of failed target found.
Hint: Try searching the build log for '] Error'.
Hint: See common/doc/building.html#troubleshooting for assistance.

make[1]: *** [main] Error 2
make: *** [default] Error 2

[-Werror,-Wundefined-var-template]とあるので、undefined-var-templateを無視するよう-Wno-undefined-var-templateをつけました。するとエラーがこうなりました。

/Users/jyukutyo/code/panama/jdk/src/java.desktop/macosx/native/libosxapp/NSApplicationAWT.m:335:48: error: conflicting parameter types in implementation of 'nextEventMatchingMask:untilDate:inMode:dequeue:': 'NSEventMask' (aka 'enum NSEventMask') vs 'NSUInteger' (aka 'unsigned long') [-Werror,-Wmismatched-parameter-types]
- (NSEvent *)nextEventMatchingMask:(NSUInteger)mask untilDate:(NSDate *)expiration inMode:(NSString *)mode dequeue:(BOOL)deqFlag {
                                    ~~~~~~~~~~ ^
/System/Library/Frameworks/AppKit.framework/Headers/NSApplication.h:283:58: note: previous definition is here
- (nullable NSEvent *)nextEventMatchingMask:(NSEventMask)mask untilDate:(nullable NSDate *)expiration inMode:(NSRunLoopMode)mode dequeue:(BOOL)deqFlag;
                                             ~~~~~~~~~~~ ^
1 error generated.
make[3]: *** [/Users/jyukutyo/code/panama/build/macosx-x86_64-normal-server-release/support/native/java.desktop/libosxapp/NSApplicationAWT.o] Error 1
make[3]: *** Waiting for unfinished jobs....
Creating support/modules_libs/java.management/libmanagement.dylib from 9 file(s)
make[2]: *** [java.desktop-libs] Error 2
make[2]: *** Waiting for unfinished jobs....
ld: warning: object file (/Users/jyukutyo/code/panama/build/macosx-x86_64-normal-server-release/support/native/java.base/libjli_static.a) was built for newer OSX version (10.12) than being linked (10.7)

ERROR: Build failed for target 'default (exploded-image)' in configuration 'macosx-x86_64-normal-server-release' (exit code 2) 

=== Output from failing command(s) repeated here ===
* For target support_native_java.desktop_libosxapp_NSApplicationAWT.o:
/Users/jyukutyo/code/panama/jdk/src/java.desktop/macosx/native/libosxapp/NSApplicationAWT.m:335:48: error: conflicting parameter types in implementation of 'nextEventMatchingMask:untilDate:inMode:dequeue:': 'NSEventMask' (aka 'enum NSEventMask') vs 'NSUInteger' (aka 'unsigned long') [-Werror,-Wmismatched-parameter-types]
- (NSEvent *)nextEventMatchingMask:(NSUInteger)mask untilDate:(NSDate *)expiration inMode:(NSString *)mode dequeue:(BOOL)deqFlag {
                                    ~~~~~~~~~~ ^
/System/Library/Frameworks/AppKit.framework/Headers/NSApplication.h:283:58: note: previous definition is here
- (nullable NSEvent *)nextEventMatchingMask:(NSEventMask)mask untilDate:(nullable NSDate *)expiration inMode:(NSRunLoopMode)mode dequeue:(BOOL)deqFlag;
                                             ~~~~~~~~~~~ ^
1 error generated.

* All command lines available in /Users/jyukutyo/code/panama/build/macosx-x86_64-normal-server-release/make-support/failure-logs.
=== End of repeated output ===

No indication of failed target found.
Hint: Try searching the build log for '] Error'.
Hint: See common/doc/building.html#troubleshooting for assistance.

make[1]: *** [main] Error 2
make: *** [default] Error 2

error: conflicting parameter types in implementation of 'nextEventMatchingMask:untilDate:inMode:dequeue:': 'NSEventMask' (aka 'enum NSEventMask') vs 'NSUInteger' (aka 'unsigned long') [-Werror,-Wmismatched-parameter-types]です。パラメータの型がミスマッチと。

これも-Wno-error=mismatched-parameter-typesをつけて無視しました。するとエラーがこうなりました。

/Users/jyukutyo/code/panama/jdk/src/java.desktop/share/native/libjavajpeg/jdhuff.c:461:42: error: shifting a negative signed value is undefined [-Werror,-Wshift-negative-value]
    ((-1)<<13) + 1, ((-1)<<14) + 1, ((-1)<<15) + 1 };
                                     ~~~~^
15 errors generated.
make[3]: *** [/Users/jyukutyo/code/panama/build/macosx-x86_64-normal-server-release/support/native/java.desktop/libjavajpeg/jdhuff.o] Error 1
make[2]: *** [java.desktop-libs] Error 2

shifting a negative signed value is undefinedで、負の値はシフト演算できないようです。

これも-Wno-error=shift-negative-valueをつけて無視しました。今度はビルドが成功しました。

Finished building target 'default (exploded-image)' in configuration 'macosx-x86_64-normal-server-release'

Vector APIを試す

$ export JAVA_HOME=[panama]/build/macosx-x86_64-normal-server-release/jdk

$ java -version
openjdk version "9-internal"
OpenJDK Runtime Environment (build 9-internal+0-adhoc.koichisakata.panama)
OpenJDK 64-Bit Server VM (build 9-internal+0-adhoc.koichisakata.panama, mixed mode)

まだ9のままのようです。

$ jshell
|  JShellへようこそ -- バージョン9-internal
|  概要については、次を入力してください: /help intro

jshell> import jdk.incubator.vector.FloatVector;
jshell> import jdk.incubator.vector.Vector;
jshell> import jdk.incubator.vector.Shapes;

Vector APIインポートできてます。こちらからサンプルをとってきます。

software.intel.com

jshell> public static void AddArrays (float [] left, float [] right, float [] res, int i) {
   ...> FloatVector.FloatSpecies<Shapes.S256Bit> species = (FloatVector.FloatSpecies<Shapes.S256Bit>) 
   ...> Vector.speciesInstance (Float.class, Shapes.S_256_BIT);
   ...>        FloatVector<Shapes.S256Bit> l  = species.fromArray (left, i);
   ...> FloatVector<Shapes.S256Bit> r  = species.fromArray (right, i);
   ...>        FloatVector<Shapes.S256Bit> lr = l.add(r);
   ...> lr.intoArray (res, i);
   ...> }
|  警告:
|  修飾子'static' は、トップ・レベル宣言で使用できません。無視されます
|  public static void AddArrays (float [] left, float [] right, float [] res, int i) {
|  ^-----------^
|  次を作成しました: メソッド AddArrays(float [],float [],float [],int)

サンプルがstaticだったJShellに怒られましたが、そのまま突っ切ります。しかもメソッド名大文字始まり。

えーと、256ビットの演算なので、floatだと8つ(256 / 32)用意すればいい。

jshell> float[] left = new float[] {0.0F,1.0F,1.5F,2.0F,0.0F,1.0F,1.5F,2.0F}
left ==> float[8] { 0.0, 1.0, 1.5, 2.0, 0.0, 1.0, 1.5, 2.0 }

jshell> float[] right = new float[] {0.0F,1.0F,1.5F,2.0F,0.0F,1.0F,1.5F,2.0F}
right ==> float[8] { 0.0, 1.0, 1.5, 2.0, 0.0, 1.0, 1.5, 2.0 }

jshell> float[] res = new float[8]
res ==> float[8] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }

jshell> AddArrays(left, right, res, 0)

jshell> System.out.println(Arrays.toString(res))
[0.0, 2.0, 3.0, 4.0, 0.0, 2.0, 3.0, 4.0]

配列同士で添字が同じものを足し算するのと同じ結果(実際はSIMDで複数の演算を一括で実施)なので、これで合っています。

今までエラーが出るとビルドを諦めていましたが、ここまでできれば今後エラーが出てもビルド自体はできそうです(エラーを無視している点は問題ですが)。