On arm builds of OpenJDK/OpenJ9 java -version fails with an unexpected IllegalArgumentException:
Exception in thread "main" java/lang/IllegalArgumentException
at jdk/internal/misc/Unsafe.copyMemory0 (java.base@9/NativeMethod:4294967295)
at jdk/internal/misc/Unsafe.copyMemory (java.base@9/Unsafe.java:833)
at sun/nio/fs/NativeBuffers.copyCStringToNativeBuffer (java.base@9/NativeBuffers.java:127)
at sun/nio/fs/UnixNativeDispatcher.copyToNativeBuffer (java.base@9/UnixNativeDispatcher.java:50)
at sun/nio/fs/UnixNativeDispatcher.stat (java.base@9/UnixNativeDispatcher.java:306)
at sun/nio/fs/UnixFileSystemProvider.isRegularFile (java.base@9/UnixFileSystemProvider.java:514)
at java/nio/file/Files.isRegularFile (java.base@9/Files.java:2262)
at jdk/internal/loader/BuiltinClassLoader.setJimageURL (java.base@9/BuiltinClassLoader.java:257)
at jdk/internal/loader/BuiltinClassLoader.access$100 (java.base@9/BuiltinClassLoader.java:109)
at jdk/internal/loader/BuiltinClassLoader$LoadedModule.convertJrtToFileURL (java.base@9/BuiltinClassLoader.java:296)
at jdk/internal/loader/BuiltinClassLoader$LoadedModule.<init> (java.base@9/BuiltinClassLoader.java:286)
at jdk/internal/loader/BuiltinClassLoader.loadModule (java.base@9/BuiltinClassLoader.java:354)
at jdk/internal/loader/BootLoader.loadModule (java.base@9/BootLoader.java:108)
at jdk/internal/module/ModuleBootstrap.boot (java.base@9/ModuleBootstrap.java:152)
at java/lang/ClassLoader.initializeClassLoaders (java.base@9/ClassLoader.java:218)
at java/lang/Thread.initialize (java.base@9/Thread.java:422)
at java/lang/Thread.<init> (java.base@9/Thread.java:153)
The problem is avoided by running with -Xjit:disableDirectToJNI
openjdk version "9-internal"
OpenJDK Runtime Environment (build 9-internal+0-adhoc.jkingdon.openj9-openjdk-jdk9)
Eclipse OpenJ9 VM (build 2.9, JRE 9 Linux arm-32 20171110_000000 (JIT enabled, AOT enabled)
OpenJ9 - 5e2451c
OMR - 30c2196
OpenJDK - ae4d07b based on jdk-9+181)
I appreciate that while builds for arm are not readily available this issue could be seen as premature, but it seems better to record the problems as they are found so that we maintain awareness for future planning.
Be aware that the ARM system linkage was reworked in eclipse/omr#1132 mainly to make it less Java-specific and more generally useful. This may have a bearing on this issue.
As I recall, before https://github.com/eclipse/omr/pull/1132, the ARM system linkage implementation was incomplete and unused in J9 (not yet open source at the time). That pull request only added some bare-bone implementation for the missing pieces.
So, just to clarify, I don't think the ARM system linkage directly affects this issue.
There was discussion of refactoring JNI linkage to make use of system linkages. AFAIK, no work has been done to this end. However, it may be worth looking deeper into this possibility as part of the work to resolve this issue.
IllegalArgumentException with Unsafe.copyMemory0() is a problem in handling 64-bit arguments passed to JNI methods, as I examined the generated code.
The JIT places the half of a 64-bit argument in register r3, and the other half in the C stack. That is not correct in ARM ABI. The whole 64 bits must be placed in the C stack by skipping r3 in this case.
As communicated personally, I identified the root cause of this problem. It was TR::Compiler->target.isEABI() that returned a wrong result, i.e. false in this case.
I will be making a pull request for this later.
Corrected my commit message.
Most helpful comment
IllegalArgumentException with Unsafe.copyMemory0() is a problem in handling 64-bit arguments passed to JNI methods, as I examined the generated code.
The JIT places the half of a 64-bit argument in register r3, and the other half in the C stack. That is not correct in ARM ABI. The whole 64 bits must be placed in the C stack by skipping r3 in this case.