herumi / mcl

a portable and fast pairing-based cryptography library
BSD 3-Clause "New" or "Revised" License
458 stars 157 forks source link

JVM Fatal Error While Running Java FFI Tests For v1.36 #104

Closed rheitjoh closed 3 years ago

rheitjoh commented 3 years ago

Problem

While running make test_mcl in /ffi/java to compile the Java bindings, the tests crash via a fatal error of the JVM. This happens for me for version v1.36 (master as well). A colleague also has this issue for v1.35 already (v1.35 just gets stuck for me). v1.34 and before are not affected.

The error results in the following log file: hs_err_pid466986.log

Click here for console output ```----- Java include path: /usr/lib/jvm/java-8-openjdk-amd64/include ----- g++ mcl_wrap.cxx -o ../../lib/libmcljava.so -g3 -Wall -Wextra -Wformat=2 -Wcast-qual -Wcast-align -Wwrite-strings -Wfloat-equal -Wpointer-arith -Wundef -m64 -I include -I test -fomit-frame-pointer -DNDEBUG -fno-stack-protector -Ofast -DMCL_USE_VINT -DMCL_DONT_USE_OPENSSL -fPIC -z noexecstack -I/usr/lib/jvm/java-8-openjdk-amd64/include -I/usr/lib/jvm/java-8-openjdk-amd64/include/linux -I ../../include -I ../../../xbyak -I ../../../cybozulib/include -Wno-strict-aliasing ../../lib/libmcl.a -lrt -m64 -lrt -shared javac MclTest.java cd ../../lib && LD_LIBRARY_PATH=../lib: java -classpath ../ffi/java MclTest libName : libmcljava.so curve=BN254 # # A fatal error has been detected by the Java Runtime Environment: # # SIGILL (0x4) at pc=0x00007f1f380422bd, pid=466986, tid=466987 # # JRE version: OpenJDK Runtime Environment (11.0.10+9) (build 11.0.10+9-Ubuntu-0ubuntu1.20.04) # Java VM: OpenJDK 64-Bit Server VM (11.0.10+9-Ubuntu-0ubuntu1.20.04, mixed mode, sharing, tiered, compressed oops, g1 gc, linux-amd64) # Problematic frame: # C 0x00007f1f380422bd # # Core dump will be written. Default location: Core dumps may be processed with "/usr/share/apport/apport %p %s %c %d %P %E" (or dumping to /tmp/mcl/lib/core.466986) # # An error report file with more information is saved as: # /tmp/mcl/lib/hs_err_pid466986.log # # If you would like to submit a bug report, please visit: # https://bugs.launchpad.net/ubuntu/+source/openjdk-lts # The crash happened outside the Java Virtual Machine in native code. # See problematic frame for where to report the bug. # Aborted (core dumped) make: *** [Makefile:57: test_mcl] Error 134 ```

Reproducing the problem

Run

cd /tmp
git clone git://github.com/herumi/mcl
cd mcl
git checkout v1.36
make -j4
cd ffi/java
make test_mcl JAVA_INC=-I/usr/lib/jvm/java-8-openjdk-amd64/include # my include path

What I tried so far

herumi commented 3 years ago

Could you tell me information of your compiler, OS and CPU?

herumi commented 3 years ago

cf. https://github.com/herumi/mcl/runs/2052904880?check_suite_focus=true

herumi commented 3 years ago

Host: Intel(R) Core(TM) i5-4210M CPU @ 2.60GHz, 4 cores, 15G, Ubuntu 20.04.1 LTS in https://github.com/herumi/mcl/files/6095455/hs_err_pid466986.log

herumi commented 3 years ago

analyze log

Instructions: (pc=0x00007f1f380422bd)

0x00007f1f3804228d:   4c 8d 35 6c fd ff ff 48 8b 0e 4c 8b 46 08 4c 8b
0x00007f1f3804229d:   4e 10 4c 8b 56 18 48 8b 5e 20 48 ba e5 35 94 d7
0x00007f1f380422ad:   50 5e 43 08 48 0f af d1 48 31 ed c4 42 fb f6 26
0x00007f1f380422bd:   f3 48 0f 38 f6 c8 66 4d 0f 38 f6 c4 c4 42 fb f6
0x00007f1f380422cd:   66 08 f3 4c 0f 38 f6 c0 66 4d 0f 38 f6 cc c4 42

disasm

4c 8d 35 6c fd ff ff    lea    -0x294(%rip),%r14        # 0xfffffe43
48 8b 0e                mov    (%rsi),%rcx
4c 8b 46 08             mov    0x8(%rsi),%r8
4c 8b 4e 10             mov    0x10(%rsi),%r9
4c 8b 56 18             mov    0x18(%rsi),%r10
48 8b 5e 20             mov    0x20(%rsi),%rbx
48 ba e5 35 94 d7 50    movabs $0x8435e50d79435e5,%rdx
5e 43 08
48 0f af d1             imul   %rcx,%rdx
48 31 ed                xor    %rbp,%rbp
c4 42 fb f6 26          mulx   (%r14),%rax,%r12
f3 48 0f 38 f6 c8       adox   %rax,%rcx             ; -(***)
66 4d 0f 38 f6 c4       adcx   %r12,%r8
c4 42 fb f6 66 08       mulx   0x8(%r14),%rax,%r12
f3 4c 0f 38 f6 c0       adox   %rax,%r8

Core i5-4210M is Haswell processor, so does not support adox. I have to avoid the mnemonic on the CPU.

herumi commented 3 years ago
sde -hsw -- bin/bn_test.exe
JIT 1
ctest:module=size
ctest:module=naive
mcl version=136
i=0 curve=BN254
TID 0 SDE-ERROR: Executed instruction not valid for specified chip (HASWELL): 0x7fc5e0a862bd: adox rcx, rax
Instruction bytes are: f3 48 0f 38 f6 c8
herumi commented 3 years ago

I've fixed this problem. Could you try https://github.com/herumi/mcl/commit/e974e3e2da94daf2ca51f591c18786e850690d77 ?

rheitjoh commented 3 years ago

The JVM error has been resolved for me, thank you.