Repository navigation
Error on JavaCall.init() with Julia >= 1.12 #170
Description
Activity
While I think we might be able to fix the bounds error, this really deserves a full engineering review.
My priority here would be to address the "single-thread" case, which I'm not entirely sure exists anymore.
It may be that the Julia and Java signal handling facilities in each thread / task stack have now become incompatible. We would need to build some sort of signal chaining mechanism.
Could I ask about your application? How do you intend to use this?
As for fixing the bounds error, my current thought is that should consider putting for the JNI environment in a
Dict{Int}I have a simple use case, I just want to be able to run JavaCall. If possible with Julia multithreading enabled, so I can use JavaCall in one place and multithreading in another unrelated place, all while being in the same Julia session. But if that's really not possible, having a clear warning/error message would be nice.
To summarize it would be good if it could work at least for the single-threaded case. And in the other case, give an explicit error message.
The most likely scenario is that might be able to support calling Java from a single thread / task, particular the root task running on thread 1, perhaps even without
JULIA_COPY_STACKSdepending on the operating system. One model would be to run a service on a sticky Julia root task that communicates with other Julia tasks while also remaining on the initial thread. To call Java, the other tasks, possibly on other threads, would first communicate with the service on the root task, which would then communicate with the JVM.I prototyped what such a service might look like here:
https://github.com/mkitti/TaskWorkers.jlThe issue is that both Julia and Java seem to be trying to use the same signalling resources (e.g.
sigaction) which requires installing a signal handler on the stack.Java actually does have a facility for this called signal chaining:
https://docs.oracle.com/javase/8/docs/technotes/guides/vm/signal-chaining.htmlWe might need to figure out how to implement a similar facility for Julia to keep this working.
I need to review this model in light of the interactive thread pool.
Works fine if you start Julia single threaded (as I am now doing in the CI). This needs to be noted in the README and the docs.
This is probably because of
JavaCall.jl/src/JNI.jl
Lines 168 to 178 in 2f1824f
See JuliaFolds2/OhMyThreads.jl#136 (comment) and https://julialang.org/blog/2023/07/PSA-dont-use-threadid/