| 1 |
JVM startup debugging |
| 2 |
===================== |
| 3 |
|
| 4 |
So the JVM won't start under JPype. It works fine for everyone else, but just |
| 5 |
not you. Now what? The following instructions are for Linux, but apply to |
| 6 |
most unix like systems with minor modifications. |
| 7 |
|
| 8 |
JAVA_HOME |
| 9 |
--------- |
| 10 |
|
| 11 |
First make sure your JAVA_HOME is set correctly. It should point to a |
| 12 |
directory containing the JRE or JDK. It should look something like...:: |
| 13 |
|
| 14 |
bin conf COPYRIGHT include jmods legal lib release |
| 15 |
|
| 16 |
For Unix we expect to find ``$JAVA_HOME\lib\server\libjvm.so`` or |
| 17 |
``$JAVA_HOME\lib\client\libjvm.dll``. We will assume it is server for this |
| 18 |
document. |
| 19 |
|
| 20 |
|
| 21 |
Architecture |
| 22 |
------------ |
| 23 |
|
| 24 |
To check the type of a file, use the ``file`` command. |
| 25 |
|
| 26 |
First lets check the architecture of the ``libjvm.so`` file:: |
| 27 |
|
| 28 |
$ file $JAVA_HOME/lib/server/libjvm.so |
| 29 |
/usr/lib/jvm/java-11-openjdk-amd64/lib/server/libjvm.so: ELF 64-bit LSB shared object, x86-64, |
| 30 |
version 1 (GNU/Linux), dynamically linked, BuildID[sha1]=1313ccf3deaef446a6c2fec9561f2232e4202bc8, stripped |
| 31 |
|
| 32 |
We can also check the architecture of python or the test file:: |
| 33 |
|
| 34 |
$ file a.out |
| 35 |
a.out: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/l, for GNU/Linux 3.2.0, BuildID[sha1]=24c58f45e6aa4a41c0d69a74063243b692d51e0d, not stripped |
| 36 |
|
| 37 |
$ file /usr/bin/python3.8 |
| 38 |
/usr/bin/python3.8: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/l, for GNU/Linux 3.2.0, BuildID[sha1]=f9e05e26d8232239158889727d8056c122a9e958, stripped |
| 39 |
|
| 40 |
The import thing is that each must have the samme architecture. In this case, 64-bit LSB x86-64. |
| 41 |
|
| 42 |
If one or more libraries or binaries has a mismatch then it likely won't work with that JVM. |
| 43 |
|
| 44 |
|
| 45 |
Dependencies |
| 46 |
------------ |
| 47 |
|
| 48 |
The JVM has many dependencies. If any of them are missing, or |
| 49 |
not in a search path, or they are the wrong architecture then |
| 50 |
it will fail to load. To get a list of dependencies use:: |
| 51 |
|
| 52 |
ldd -v "$JAVA_HOME/lib/server/libjvm.so" |
| 53 |
|
| 54 |
It should produce an output similar to:: |
| 55 |
|
| 56 |
linux-vdso.so.1 (0x00007ffff3591000) |
| 57 |
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fd55b5b0000) |
| 58 |
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fd55b390000) |
| 59 |
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fd55b000000) |
| 60 |
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fd55ac60000) |
| 61 |
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fd55a860000) |
| 62 |
/lib64/ld-linux-x86-64.so.2 (0x00007fd55cc00000) |
| 63 |
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fd55a640000) |
| 64 |
|
| 65 |
If any of these libraries are missing or the wrong architecture it will cause issues. |
| 66 |
|
| 67 |
Testing the JVM |
| 68 |
--------------- |
| 69 |
|
| 70 |
Assuming that you have the JAVA_HOME set, the architectures are correct, and |
| 71 |
all of the dependencies are in place it should load. But lets run a test. |
| 72 |
|
| 73 |
Compile using the System C++ compiler. |
| 74 |
|
| 75 |
Use:: |
| 76 |
|
| 77 |
g++ testJVM.cpp -ldl |
| 78 |
|
| 79 |
Run it with:: |
| 80 |
|
| 81 |
a.out "$JAVA_HOME\lib\server\libjvm.so" |
| 82 |
|
| 83 |
It should produce and output like:: |
| 84 |
|
| 85 |
$ ./a.out $JAVA_HOME/lib/server/libjvm.so |
| 86 |
Load library |
| 87 |
Load entry points |
| 88 |
Entry point found 0x7fad8e08f670 |
| 89 |
Pack JVM arguments |
| 90 |
Num options: 0 |
| 91 |
Create JVM |
| 92 |
Create Java resources |
| 93 |
Destroy JVM |
| 94 |
Unload library |
| 95 |
Success |
| 96 |
|
| 97 |
Testing static load |
| 98 |
------------------- |
| 99 |
|
| 100 |
Dlopen provides very little diagnostic information. So you may want to try a static JVM load. |
| 101 |
|
| 102 |
To build a static JVM test use:: |
| 103 |
|
| 104 |
g++ staticJVM.cpp -ljvm -L $JAVA_HOME/lib/server/ |
| 105 |
|
| 106 |
The launch it with:: |
| 107 |
|
| 108 |
LD_LIBRARY_PATH=$JAVA_HOME/lib/server a.out |
| 109 |
|
| 110 |
This should produce the output:: |
| 111 |
|
| 112 |
Pack JVM arguments |
| 113 |
Num options: 0 |
| 114 |
Create JVM |
| 115 |
Create Java resources |
| 116 |
Destroy JVM |
| 117 |
Success |
| 118 |
|
| 119 |
If the library does not match it should produce something like:: |
| 120 |
|
| 121 |
./a.out: error while loading shared libraries: libjvm.so: cannot open shared object file: No such file or directory |
| 122 |
|
| 123 |
|
| 124 |
Two different libstdc++ versions |
| 125 |
-------------------------------- |
| 126 |
|
| 127 |
|
| 128 |
If you are compiling the source on a test environment and pushing the compiled Jpype source to a different environment (Unix/Linux) you might see a situation where running:: |
| 129 |
|
| 130 |
ldd libstdc++.so.6 |
| 131 |
|
| 132 |
links to a different version of your production environment. |
| 133 |
|
| 134 |
You can rememdy this by copying the so file to your production system and creating a soft link to the file with:: |
| 135 |
|
| 136 |
ln -s libstdc++.so.6.0.29 libstdc++.so.6 |
| 137 |
|
| 138 |
Then override the system's (in the example below, Oracle/Solaris) 64bit dynamic linker path with:: |
| 139 |
|
| 140 |
export LD_LIBRARY_PATH_64=/path/to/linked/file/above |
| 141 |
|
| 142 |
NOTE: You will want to include the path to any other .so files you will be needing. |