Reputation: 27385
I'm trying to profile native memory allocated by C-written methods and plugged to JVM
through JNI
. I installed
$ valgrind --version
valgrind-3.13.0
And tried to run JVM with the following options:
valgrind --tool=massif --massif-out-file=/tmp/massif-j.out java
-XX:+UnlockDiagnosticVMOptions //...
The thing is it crashes with core dump created
0x00000000080e4196: fxrstor64 (%rsp)
0x00000000080e419b: add $0x200,%rsp
0x00000000080e41a2: mov (%rsp),%r15
0x00000000080e41a6: mov 0x8(%rsp),%r14
0x00000000080e41ab: mov 0x10(%rsp),%r13
0x00000000080e41b0: mov 0x18(%rsp),%r12
0x00000000080e41b5: mov 0x20(%rsp),%r11
0x00000000080e41ba: mov 0x28(%rsp),%r10
0x00000000080e41bf: mov 0x30(%rsp),%r9
0x00000000080e41c4: mov 0x38(%rsp),%r8
0x00000000080e41c9: mov 0x40(%rsp),%rdi
0x00000000080e41ce: mov 0x48(%rsp),%rsi
0x00000000080e41d3: mov 0x50(%rsp),%rbp
0x00000000080e41d8: mov 0x60(%rsp),%rbx
0x00000000080e41dd: mov 0x68(%rsp),%rdx
0x00000000080e41e2: mov 0x70(%rsp),%rcx
0x00000000080e41e7: mov 0x78(%rsp),%rax
0x00000000080e41ec: add $0x80,%rsp
0x00000000080e41f3: add $0x8,%rsp
0x00000000080e41f7: Fatal error: Disassembling failed with error code: 15#
# A fatal error has been detected by the Java Runtime Environment:
#
# Internal Error (sharedRuntime.cpp:834), pid=12441, tid=0x0000000021385700
# fatal error: exception happened outside interpreter, nmethods and vtable stubs at pc 0x00000000080e4147
#
# JRE version: Java(TM) SE Runtime Environment (8.0_181-b13) (build 1.8.0_181-b13)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.181-b13 mixed mode linux-amd64 compressed oops)
# Core dump written. Default location: /var/log/prj/core or core.12441
#
# An error report file with more information is saved as:
# /var/log/prj/hs_err_pid12441.log
#
# If you would like to submit a bug report, please visit:
# http://bugreport.java.com/bugreport/crash.jsp
#
==12441==
==12441== Process terminating with default action of signal 6 (SIGABRT): dumping core
==12441== at 0x54AAE97: raise (raise.c:51)
==12441== by 0x54AC800: abort (abort.c:79)
==12441== by 0x658B3C4: ??? (in /usr/lib/jvm/java-oracle-8-amd64/jdk/jre/lib/amd64/server/libjvm.so)
==12441== by 0x672F5B2: ??? (in /usr/lib/jvm/java-oracle-8-amd64/jdk/jre/lib/amd64/server/libjvm.so)
==12441== by 0x615EE98: ??? (in /usr/lib/jvm/java-oracle-8-amd64/jdk/jre/lib/amd64/server/libjvm.so)
==12441== by 0x662A099: ??? (in /usr/lib/jvm/java-oracle-8-amd64/jdk/jre/lib/amd64/server/libjvm.so)
==12441== by 0x6591A49: JVM_handle_linux_signal (in /usr/lib/jvm/java-oracle-8-amd64/jdk/jre/lib/amd64/server/libjvm.so)
==12441== by 0x6587652: ??? (in /usr/lib/jvm/java-oracle-8-amd64/jdk/jre/lib/amd64/server/libjvm.so)
==12441== by 0x4E4588F: ??? (in /lib/x86_64-linux-gnu/libpthread-2.27.so)
==12441== by 0x80E4146: ???
==12441== by 0x107: ???
==12441== by 0x84CBC43: ???
==12441== by 0x10001BD37: ???
==12441== by 0xFDC7103F: ???
==12441== by 0xA3FFFFFFFF: ???
==12441== by 0xFF9275A7: ???
==12441==
Can anyone give an idea of what could go wrong? Is that because of Fatal error: Disassembling failed with error code: 15#
?
Upvotes: 0
Views: 1189
Reputation: 98284
Valgrind (and Valgrind-based tools) does not work well with self-modifying code. However, HotSpot JVM heavily relies on dynamic code generation, including overwriting and patching the previously generated instructions. This holds even when JIT compiler is disabled, because HotSpot also uses dynamic code generation for interpreter and runtime stubs.
For native memory allocation profiling you may also use jemalloc or async-profiler. The latter has the advatange of integration with Java runtime, i.e. it can show mixed stack traces with both native and Java frames. Furthermore, both tools have rather small performance overhead unlike Valgrind which virtualizes the running program.
For more information see this and this answers.
Upvotes: 2