| 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? |
| 6 |
|
| 7 |
JAVA_HOME |
| 8 |
--------- |
| 9 |
|
| 10 |
First make sure your JAVA_HOME is set correctly. It should point to a |
| 11 |
directory containing the JRE or JDK. It should look something like...:: |
| 12 |
|
| 13 |
bin conf COPYRIGHT include jmods legal lib release |
| 14 |
|
| 15 |
For Windows we expect to find ``%JAVA_HOME%\bin\server\jvm.dll`` or |
| 16 |
``%JAVA_HOME%\bin\client\jvm.dll``. We will assume it is server for this |
| 17 |
document. |
| 18 |
|
| 19 |
|
| 20 |
Architecture |
| 21 |
------------ |
| 22 |
|
| 23 |
Next make sure that Python and the JVM have the same architecture. We can do |
| 24 |
this with ``DUMPBIN``. |
| 25 |
|
| 26 |
Run:: |
| 27 |
|
| 28 |
dumpbin /headers "%JAVA_HOME%/bin/jvm.dll" |
| 29 |
|
| 30 |
It will produce a big output. The relevant section is:: |
| 31 |
|
| 32 |
File Type: DLL |
| 33 |
|
| 34 |
FILE HEADER VALUES |
| 35 |
8664 machine (x64) <== Type is x64 |
| 36 |
7 number of sections |
| 37 |
5CA35D83 time date stamp Tue Apr 2 06:02:59 2019 |
| 38 |
0 file pointer to symbol table |
| 39 |
0 number of symbols |
| 40 |
F0 size of optional header |
| 41 |
2022 characteristics |
| 42 |
Executable |
| 43 |
Application can handle large (>2GB) addresses |
| 44 |
DLL |
| 45 |
|
| 46 |
Run the same command on the Python executable:: |
| 47 |
|
| 48 |
File Type: EXECUTABLE IMAGE |
| 49 |
|
| 50 |
FILE HEADER VALUES |
| 51 |
8664 machine (x64) <== Type is x64 |
| 52 |
6 number of sections |
| 53 |
5C9BF5B3 time date stamp Wed Mar 27 15:14:11 2019 |
| 54 |
0 file pointer to symbol table |
| 55 |
0 number of symbols |
| 56 |
F0 size of optional header |
| 57 |
22 characteristics |
| 58 |
Executable |
| 59 |
Application can handle large (>2GB) addresses |
| 60 |
|
| 61 |
If they match then the issue is not an architecture problem. |
| 62 |
|
| 63 |
|
| 64 |
Dependencies |
| 65 |
------------ |
| 66 |
|
| 67 |
The JVM has many dependencies. If any of them are missing, or |
| 68 |
not in a search path, or they are the wrong architecture then |
| 69 |
it will fail to load. To get a list of dependencies use:: |
| 70 |
|
| 71 |
dumpbin /dependents "%JAVA_HOME%/bin/server/jvm.dll" |
| 72 |
|
| 73 |
It should produce an output:: |
| 74 |
|
| 75 |
Dump of file C:\Program Files\Java\jdk-12.0.1/bin/server/jvm.dll |
| 76 |
|
| 77 |
File Type: DLL |
| 78 |
Image has the following dependencies: |
| 79 |
KERNEL32.dll |
| 80 |
USER32.dll |
| 81 |
ADVAPI32.dll |
| 82 |
WSOCK32.dll |
| 83 |
WINMM.dll |
| 84 |
VERSION.dll |
| 85 |
PSAPI.DLL |
| 86 |
VCRUNTIME140.dll |
| 87 |
api-ms-win-crt-stdio-l1-1-0.dll |
| 88 |
api-ms-win-crt-string-l1-1-0.dll |
| 89 |
api-ms-win-crt-runtime-l1-1-0.dll |
| 90 |
api-ms-win-crt-convert-l1-1-0.dll |
| 91 |
api-ms-win-crt-environment-l1-1-0.dll |
| 92 |
api-ms-win-crt-utility-l1-1-0.dll |
| 93 |
api-ms-win-crt-math-l1-1-0.dll |
| 94 |
api-ms-win-crt-filesystem-l1-1-0.dll |
| 95 |
api-ms-win-crt-time-l1-1-0.dll |
| 96 |
api-ms-win-crt-heap-l1-1-0.dll |
| 97 |
|
| 98 |
Summary |
| 99 |
DB000 .data |
| 100 |
59000 .pdata |
| 101 |
243000 .rdata |
| 102 |
39000 .reloc |
| 103 |
1000 .rsrc |
| 104 |
7BF000 .text |
| 105 |
3000 _RDATA |
| 106 |
|
| 107 |
So every one of these libraries needs to be found on the path. All of the required |
| 108 |
DLLs should be located in ``%JAVA_HOME%/bin``. However, Windows search order may |
| 109 |
find another copy of one of these DLLs elsewhere in the search process. If the file |
| 110 |
it finds is the wrong architechure or corrupt the JVM will fail to load. |
| 111 |
|
| 112 |
Please note the search order in |
| 113 |
https://docs.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-search-order |
| 114 |
|
| 115 |
The order is:: |
| 116 |
|
| 117 |
1) The directory from which the application loaded. |
| 118 |
|
| 119 |
2) The current directory. |
| 120 |
|
| 121 |
3) The system directory. Use the GetSystemDirectory function to get the path |
| 122 |
of this directory. |
| 123 |
|
| 124 |
4) The 16-bit system directory. There is no function that obtains the path of |
| 125 |
this directory, but it is searched. |
| 126 |
|
| 127 |
5) The Windows directory. Use the GetWindowsDirectory function to get the |
| 128 |
path of this directory. |
| 129 |
|
| 130 |
6) The directories that are listed in the PATH environment variable. Note |
| 131 |
that this does not include the per-application path specified by the App Paths |
| 132 |
registry key. The App Paths key is not used when computing the DLL search path. |
| 133 |
|
| 134 |
So even if the PATH is pointing to ``%JAVA_HOME%/bin``, you may have a bad dll |
| 135 |
in any of the first 5 places. |
| 136 |
|
| 137 |
|
| 138 |
Testing the JVM |
| 139 |
--------------- |
| 140 |
|
| 141 |
Assuming that you have the JAVA_HOME set, the architectures are correct, and |
| 142 |
all of the dependencies are in place it should load. But lets run a test. |
| 143 |
|
| 144 |
Compile using the Visual Studio shell ``x64 Native Tools Command`` or |
| 145 |
``x86 Native Tools Command`` depending on your Python architecture. |
| 146 |
|
| 147 |
Use:: |
| 148 |
|
| 149 |
CL.EXE testJVM.cpp |
| 150 |
|
| 151 |
Run it with:: |
| 152 |
|
| 153 |
testJVM.exe "%JAVA_HOME%\bin\server\jvm.dll" |
| 154 |
|
| 155 |
It should produce and output like:: |
| 156 |
|
| 157 |
Check paths |
| 158 |
SystemDirectory: C:\windows\system32 |
| 159 |
WindowsDirectory: C:\windows |
| 160 |
Load library |
| 161 |
Load entry points |
| 162 |
Entry point found 00007FFEDE4703B0 |
| 163 |
Pack JVM arguments |
| 164 |
Num options: 0 |
| 165 |
Create JVM |
| 166 |
Create Java resources |
| 167 |
Destroy JVM |
| 168 |
Unload library |
| 169 |
Success |
| 170 |
|
| 171 |
Here are some common problems: |
| 172 |
|
| 173 |
The architecture of the jvm or one of the dependencies does not match the |
| 174 |
program or is corrupted:: |
| 175 |
|
| 176 |
Failed to load JVM from C:\Program Files (x86)\Java\jre1.8.0_251\bin\client\jvm.dll |
| 177 |
LastError 193 |
| 178 |
Message: %1 is not a valid Win32 application. |
| 179 |
|
| 180 |
A module or jar file is missing from the Java distribution:: |
| 181 |
|
| 182 |
Failed to load JVM from jvm1.dll |
| 183 |
Error occurred during initialization of VM |
| 184 |
Failed setting boot class path. |
| 185 |
|
| 186 |
A dll used by the JVM is missing:: |
| 187 |
|
| 188 |
Failed to load JVM from jvm1.dll |
| 189 |
LastError 126 |
| 190 |
Message: The specified module could not be found. |
| 191 |
|