-
Notifications
You must be signed in to change notification settings - Fork 186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Failure to start JVM with jpype 1.5.1 on Windows #1242
Comments
Do you happen to know the path to the org.jpype.jar? If it is locatable and on the path, then the next issue is why java.instrument is missing. |
I'll try to find out (I don't have access to Windows at home) and I'll report! |
Maybe some new information! I have reproduced the issue on another machine.
Then:
Fiddling around I noticed
So I moved my jdk-17 to a similar place, and it worked!
Now.... what is wrong with the previous jdk-17 path? I have no idea and I hope you can figure out! |
It sounds like someone has shipped a partial copy of the JVM. There are lots of reasons that that can happen, though there is never a guarantee we will run without a full JVM. It must be JE only version. I will have to have to make some options to catch that case.
|
It seems like the best plan would be to make agent an option rather than the default and add logic to specifically add org.jpype to the classpath automatically. Our original solution was bad because our module was a second class citizen cause we were never loaded into the main system class loader. This always presented a problem because I run my testing with org.jpype on the classpath which meant I was constantly getting better results than typical runs. I tried to rectify this by loading as agent which has the huge advantage that we guarantee to load first, and we can register ourselves as the controlling module. Running as an agent is a privileged position, but it requires java.instrumentation module which apparently some distributions are shipping without.
The problem is that we have thus created a new requirement and someone is shipping out stripped down copies of the JVM. Stripped down copies are for light installs and typically used when you are serving just one application thus you know in advance all the classes that need to be provided. There was NEVER a guarantee that JPype will run with a stripped down JVM. It is always subject to breakage because at any time we may add a new call to org.jpype and if stripped down JVM doesn’t have it then it will fail.
So the logic choice is try to get everything working as a first class citizen and do a 1.5.2 release. I am guessing a month or so depending on my availability over the holidays. In the meantime either 1.5.0 or if Python 3.13 is required then we must use a full copy of the OpenJDK.
|
I just did a bit of testing and it seems the problem is actually occurring on a full OpenJDK from https://jdk.java.net/23/. This is not the distro I typically use but I bet a lot of people do. UPDATE: Actually something else weird might be going on in my case....OpenJDK may be fine after all. |
The real issue is looking like a conflict between 2 different versions of Java being used at the same time...one on the PATH, and a different one on JAVA_HOME. |
I may have an appropriate fix. It seems to be an issue that has been present in jpype for a long time and the changes in 1.5.1 just only caused it to appear. I'll give it a go tonight. |
A temporary workaround that I've confirmed works is to ensure that your |
@ryanmkurtz Please test with #1245 @astrelsky I put a PR that fixes it on my side, but as I still don't know the exact origin of the problem there are still questions. I am going to also take a shot at the non-ascii path issue in the same go. |
I can test on Friday. |
In case it's useful, although it looks like it's been solved, but this wasn't the case for me.
|
I also see reports of some failures on osx. So clearly there is more than one issue. We are currently guessing:
We have two PR addressing these. Hopefully there isn't a third. |
jpype version 1.5.1 fails to start the JVM on Windows for currently unknown reasons. See #70 and jpype-project/jpype#1242.
Just doing a quick check in on the progress of JPype 1.5.2 to address this issue. |
|
I have an issue with jpype. In a python console, the command jpype.startJVM(path-to-jvm.dll) leads to a crash of the python console without any error message. I am using Windows 10 Enterprise, version 22H2 and python 3.10.8. This crash happens in jpype 1.5.2 and 1.5.1. When I downgrade to jpype 1.5.0, the jvm starts normally with jpype.startJVM(path-to-jvm.dll), both for the jvm.dll provided by openJDK-18.0.2.1 and COMSOL 62. However, if I add the classpath parameter, or define the CLASSPATH environment variable, python crashes again without any error message. In case I give the parameter classpath='', or no CLASSPATH defined, the jvm starts normally. After reading through the issues, I checked the following:
Any idea why the classpath of CLASSPATH triggers a python crash without error message? As this is a computer at my workplace, could security settings (which I cannot change) be to blame? |
You would need to catch the crash in a debugger to be sure. 1.5.1 attempted to use the java agent which was a problem for some systems but 1.5.2 rolled that back. It could be that jpype us triggering something in the jvm that is causing a crash or that jpype is triggering something in the C++. But without a line number there us nothing to go on. |
Here is the information given by the IDLE debugger at the point python crashes. It uses jpype-1.5.0. The full python command of the calling code reads: Here is the debugger output: with jpype-1.5.2, jpype.startJVM, called without classpath parameter and no CLASSPATH environment variable set, fails at the same location according to the debugger. For completeness, COMSOL 6.2 is shipped with |
It appears that crash occurred when something released a lock in the importlib bootstrap layer. We are going to need to nail it down to the line in C++ which lead to that call and then examine the code above . Please review doc/develguide.rst on the section "Tracing" it will allow you to build a tracing version which will write a log file of which methods were hit. If the method is large and there are no TRACE commands then add traces as needed to isolate the crash point. |
As for the most likely cause. It must be a reference counting error in JPype. Python wasn't great about its bookkeeping for certain reference counts particularly with modules. They are trying to close that gap but it tends to exposed bugs in Python modules where something assumed the reference counter was held and it wasn't. But this is only a theory. |
Here is what I obtain for jpype-1.5.2 compiled with --enable-tracing. The command jpype.startJVM('c:...) in the test script produces the following output (i did not include the large output before the call to this method):
The script does of course not finish, with python crashing. |
So the next step would to be find the location of the last error message and add additional trace statements until we pin down the fault point. Most likely in the resource creation section as we are past the jvm start. |
The other possibility us the start jvm actually failed in some unexpected way and we didn't catch it. I do not see a leave startJVM so in must be a child of the block itself. I also don't see an exception so either this block lacks exception handling or no exception was thrown. Currently it appears to be failing in line 205 to 215. So we need to add a JP_TRACE_IN at 205 and a JP_TRACE_OUT at the end on JPContext::initializeResources. Then add JP_TRACE statements in front of each of the statements leading up to 216. If you are not comfortable with the mods I can make a PR for testing. The three statements in that area are critical to starting as they create the handles for exception processing. They are unchecked currently as we don't yet have the safety system for exception handling in place. On the other hand these statements should never fail or it would indicate something is fatally wrong with the JVM. In other words the most we can accomplish here is tell the user something failed (ie unable to get class java.lang.Throwable) and then gracefully exit telling them the jvm is broken. Unfortunately I have no clue how a jvm can be broken like that. But lets start by confirming the fatal point then look at the differences between the two versions to nail it down. You may want add compile 1.5.0 with tracing as well so you have a successful trace to compare to. |
Here is the trace output of the modified method: so the error should occur in the line "delete [] jniArgs.options;", provided no screen output got stuck in a buffer. |
That line should not fail as we are just deleting memory created a few lines ago. I recommend trying a few fixes.
|
I put the jp_trace_in and jp_trace_out into the initializeResources method, and the test run produced no further output, so it seems (to me) that the call of this method is never reached. I try tracing version 1.5.0 |
Good. That confirms the problem is one of two locations.
|
ad 1.: no change in behaviour!
ad 2.: test script runs until the end, i.e. successful completion!
|
I tested a tracing version of jpype-1.5.0:
|
Okay I think I missed something. I was assuming it worked in 1.5.0 but failed in 1.5.2. If it also failed in 1.5.0 then I don't need to consider the changes to be fault. (This should have been its own bug report as this is clearly not the same issue.) I will have to analyze that section of the code. Perhaps we should just change the memory usage there to use malloc and free rather than new and delete. |
To avoid any misunderstandings, here is the condensed information about failing/succesfull runs of the testscript:
|
I have enough information to formulate an alterative. I will send you a PR to test when it is complete. |
With 1.5.0 on this env I could start the JVM.
Updating to jpype 1.5.1 it fails:
The text was updated successfully, but these errors were encountered: