jpype icon indicating copy to clipboard operation
jpype copied to clipboard

Crash on Windows 10 startJVM()

Open kpoman opened this issue 4 years ago • 26 comments

Hello, A code that works on linux (32 and 64bit) crashs on windows 10, when using 32bit python AND 32bit Java. See below for versions:

C:\Users\kpoman>python
Python 3.7.5 (tags/v3.7.5:5c02a39a0b, Oct 14 2019, 23:09:19) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> ^Z


C:\Users\kpoman>"c:\Program Files (x86)\Java\jre1.8.0_201\bin\java.exe" -version
java version "1.8.0_201"
Java(TM) SE Runtime Environment (build 1.8.0_201-b09)
Java HotSpot(TM) Client VM (build 25.201-b09, mixed mode)

C:\Users\kpoman>python
Python 3.7.5 (tags/v3.7.5:5c02a39a0b, Oct 14 2019, 23:09:19) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import jpype
>>> jpype.startJVM('c:/Program Files (x86)/Java/jre1.8.0_201/bin/client/jvm.dll')
C:\Python37-32\lib\site-packages\jpype\_core.py:210: UserWarning:
-------------------------------------------------------------------------------
Deprecated: convertStrings was not specified when starting the JVM. The default
behavior in JPype will be False starting in JPype 0.8. The recommended setting
for new code is convertStrings=False.  The legacy value of True was assumed for
this session. If you are a user of an application that reported this warning,
please file a ticket with the developer.
-------------------------------------------------------------------------------

  """)

C:\Users\kpoman>

kpoman avatar Dec 15 '19 22:12 kpoman

See details from the Windows Event Viewer:

Faulting application name: python.exe, version: 3.7.5150.1013, time stamp: 0x5da5006a
Faulting module name: _jpype.cp37-win32.pyd, version: 0.0.0.0, time stamp: 0x5df6ca25
Exception code: 0xc0000409
Fault offset: 0x00014c02
Faulting process id: 0x3688
Faulting application start time: 0x01d5b3a5c7a41cdd
Faulting application path: C:\Python37-32\python.exe
Faulting module path: C:\Python37-32\lib\site-packages\_jpype.cp37-win32.pyd
Report Id: 15d7da6b-19ba-4487-8479-0606d73a792f
Faulting package full name: 
Faulting package-relative application ID: 

kpoman avatar Dec 15 '19 22:12 kpoman

Just to clarify, running on Windows 10 64 bits. Win10-64 + Python37-64 + Java8-64 works Win10-64 + Python37-32 + Java8-32 crashs

kpoman avatar Dec 15 '19 22:12 kpoman

I will have to see if I can replicate this. I don't currently have that setup available in my installed software, but it should have been covered in the CI.

Thrameos avatar Dec 16 '19 04:12 Thrameos

Hi Thrameos, any update on this issue ????

kpoman avatar Dec 24 '19 15:12 kpoman

It works for me. I believe your problem is a site issue.

(python-3.7-x86) C:\cygwin64\home\nelson85\devel\open\jpype>python
Python 3.7.5 (tags/v3.7.5:5c02a39a0b, Oct 14 2019, 23:09:19) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import jpype
>>> print(jpype.getDefaultJVMPath())
C:\Program Files (x86)\Java\jre1.8.0_231\bin\client\jvm.dll
>>> jpype.startJVM()
C:\cygwin64\home\nelson85\devel\open\jpype\jpype\_core.py:218: UserWarning:
-------------------------------------------------------------------------------
Deprecated: convertStrings was not specified when starting the JVM. The default
behavior in JPype will be False starting in JPype 0.8. The recommended setting
for new code is convertStrings=False.  The legacy value of True was assumed for
this session. If you are a user of an application that reported this warning,
please file a ticket with the developer.
-------------------------------------------------------------------------------

  """)
>>>

Thrameos avatar Dec 24 '19 17:12 Thrameos

@kpoman I am also experiencing this; jpype1=0.6.3 running on Anaconda3 (python 3.7.4) on Windows. @Thrameos what do you mean that it is a "site issue"?

ebb-earl-co avatar Dec 26 '19 23:12 ebb-earl-co

Jpype 0.6.3 has a number of crashes including one when the JVM finder grabs the wrong architecture dll. Though the orginal report appears correct. Jpype 0.7.0 has addressed all of those issues and issues an error if you attempt to force the wrong JVM. I attempted to replicate the reported error using 0.7.0 and every test was successful (worked or properly reported) thus it either must be old software, machine configuration such as bad jvm, or so local problem with modifications. Unfortunately if i cant replicate it i cant address it thus my best guess is a site specific problem. All i can say is upgrade/reinstall so that it is as current as possible, then use enable tracing to capture the fault point if it is still happening. I ran for one year with 0.6.3 with windows 10 32 bit so i know that that configuration could be made to work.

Thrameos avatar Dec 27 '19 14:12 Thrameos

@Thrameos thank you for the response. How do I enable tracing? I haven't heard that phrase before.

ebb-earl-co avatar Dec 27 '19 15:12 ebb-earl-co

It somewhat depends on version. Older versions require a modification to the header file should be found with grep on TRACING. Newer versions merely require giving --enable-tracing to setup.py when you build. When tracing is enabled everthing (yes i mean everything) gets dumped to standard out. That is how i determine what is crossing between Python and JNI as well as finding origin on reference counting. Other debugging hints can be found in the devel guide.

Thrameos avatar Dec 27 '19 16:12 Thrameos

One last note, I do not have a pattern to get the visual studio to debug JPype. The issue is that JVM intentionally triggers a segfault during startup as part of its testing that its hooks are installed. I have patterns to bypass the check for gdb but not for visual studio.

Thrameos avatar Dec 27 '19 16:12 Thrameos

Hi,

Is there any update on this one? I'm getting "Process finished with exit code -1073740791 (0xC0000409)" while I'm trying to startJVM(). each time I'm running with 32-bit python and 32-bit java 11 on windows 10. However, when I switch to 64-bit python and 64-bit java 11, everything works fine. Python - 3.7.6 Jpype1 - 0.7.4 Java - 11.0.5_10

Thanks, Albert

AlbertKarger avatar May 14 '20 15:05 AlbertKarger

You can try the project/debug/windows directory on how to diagnose this type of issue.

As far as I am aware problems with starting up are usually site specific problems, (mismatched libraries, missing files, etc). We have certain guards against obvious problems but there is no programmatic way to detect many of these issues. Since is no way for me to know all of the ways that a particular site can be messed up, I posted a guide to help people solve their site issues.

Thrameos avatar May 14 '20 15:05 Thrameos

Thanks for your update, unfortunately, I'm still not able to run jpype over the 32-bit environment. As you said, it is probably related to a site-specific problem, as over other sites I've checked it's working with 32 and 64 without any problem. qq, should I have the same DLLs dependent over 32-bit? by running dumpbin /dependents "%JAVA_HOME%bin\server\jvm.dll" for 64-bit JRE I'm getting the same output as you mentioned under project/debug/windows, however for 32-bit, it has some missing DLLs.

AlbertKarger avatar May 18 '20 09:05 AlbertKarger

Missing DLLS would definitely prevent the JVM from running. It seems like the issue has been diagnosed. Assuming you can correct the missing 32-bit DLLs, it should work.

Thrameos avatar May 18 '20 13:05 Thrameos

Hi, I see this 4 years old issue is still open, so I comment my own problem here, as it looks very similar. I am also using a 32bit Python and JRE, because he SDK I am trying to wrap includes 32bits DLL. It worked well while trying to start the JVM in 64bits, but with 32, it crashes without any error message. It even seems to crash my python :

PS C:\Users\UF962PBU> py
Python 3.11.3 (tags/v3.11.3:f3909b8, Apr  4 2023, 23:34:50) [MSC v.1934 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import jpype
>>> jpype.startJVM()
PS C:\Users\UF962PBU>

PYBurosseAG avatar May 12 '23 13:05 PYBurosseAG

Do you have a 32 bit JVM? There most common problem here is starting a 32 bit python and then loading a 64 bit jvm dll.

Second most common is a dll conflict. That is the 32 bit python or dll loaded in python does not match one supplied by the 32 bit jvm. When the jvm starts rather than loading the expected copy it gets the memory copy which is missing symbols. Hence a crash.

Unfortunately these are generally site issues in which the jvm and python installs were taken from builds that dont match those that we test on. Usually caused by building with tools from different eras. Searching on github you will find plenty of reports of such bad combinations. The fixes listed are get python from this sounce and java from that and it will work. As we dont control either distributions it is difficult to solve.

Thrameos avatar May 12 '23 14:05 Thrameos

Well my JVM is indeed 32 bits, because when I try to start with a 64 bits Python, I get : jpype._jvmfinder.JVMNotSupportedException: JVM mismatch, python is 64 bit and JVM is 32 bit.

PYBurosseAG avatar May 12 '23 15:05 PYBurosseAG

At least that catch is working. So next you would need to look for conflicts in the dlls.

Thrameos avatar May 12 '23 15:05 Thrameos

I have no clue where to start looking for that kind of conflict. What DLLs are we talking about ? Java's or Python's ?

PYBurosseAG avatar May 15 '23 07:05 PYBurosseAG

You will have to find the dlls that were loaded by both Java and Python and look for a conflict (any dll that is on both but resolves to a different location.) That is the most likely source of a conflict.

As for how to do this task, I can't be of a lot of help. When I was working with windows I used the program cygcheck which was able to list all the dependencies and how they will be resolved. There are other windows tools such as dumpbin that get at the information. Unfortunately those don't show how it is resolved and they don't traverse into the dlls to find those with additional dependencies.

https://stackoverflow.com/questions/475148/how-do-i-find-out-which-dlls-an-executable-will-load

Assuming you can't find a 3rd party tool that examines the executable and finds dependencies, you can look to see what dlls are in the distributions of Python and Java. For the Java side I believe all the dlls it uses are located under $JAVA_HOME/bin so you should just have compare that list to see if there is a matching name in Python.

Thrameos avatar May 15 '23 15:05 Thrameos

Thank you for that. While investigating the subject, I tried to use MS Process Explorer to see what dlls are loaded. It includes a debugger that uses Visual Studio. When I use that on my python process while I try to start the JVM, it crashes while loading _jpype.cp311-win32.pyd : image

In any case, could you indicate me a combination of a python version and java version that works in 32 bits ? preferably a python 3.X ? Right now I'm on the latest python today (3.11.3) and the latest java I could find that is available in 32 bits jre_1.8.0_211

PYBurosseAG avatar May 16 '23 09:05 PYBurosseAG

Interesting. How did jpype get built for this python version? It may be a problem with the build tools rather than a dll conflict. It may be required to build JPype with debugging symbols to figure out the crash point. But before doing thatperhaps rolling back to Python 3.9 would be best. 3.11 had some API changes that were a challenge to work around regarding memory allocation.

Thrameos avatar May 16 '23 15:05 Thrameos

Well I stumbled upon this thread on Stack Overflow : https://stackoverflow.com/questions/69072487/jpype-startjvm-exits-without-giving-any-error-message It plainly said that you can't run JPype with Python 32bits and Java 32bits on a 64bits Windows

PYBurosseAG avatar May 17 '23 07:05 PYBurosseAG

It seems to agree with me on the heart of the problem, DLL hell. I am not sure why Windows\System32 would contain 64 bit dlls, but if that is the case it would certainly trigger the issue you are seeing. I am not sure of their final conclusion that it isn't possible to run, more like exceedingly difficult.

Unfortunately, I don't think this solves your issue. At best I can add this to the documentation so that others don't end going down the same rabbit hole.

Thrameos avatar May 17 '23 14:05 Thrameos

i am running on 64 bit java and 64 bit python its crashing without giving any error while starting JVM on windows 10 any solutions please

krishna9845 avatar Jan 23 '24 16:01 krishna9845

I would need some version info and diagnostics. I run that 64 bit java and python without issue.

Thrameos avatar Jan 23 '24 17:01 Thrameos