I cant make JavaCall.init() work from a julia session started by the VSCode plugin.
Same as for this post RCall vscode REPL crash, it works fine if I do it from a terminal.
I have tried on two different machines, with 1.6, 1.7, and 1.8
Here is how to reproduce the problem:
Create a new project
Add dependency to JavaCall
Start a julia session from VSCode
Execute the following:
using JavaCall
JavaCall.init()
The julia extension version is v1.38.2
VSCode version is 1.74.2
If I activate the tmux persistent session, the only additional information that I get is the following: Pane is dead (signal 11, Thu Jan 5 15:13:44 2023)
Just tmux telling the pane in which the julia session runs is dead
I’m not sure if I have tested JavaCall.jl with a JVM beyond Java 11, so you might try downgrading if possible.
My suspicion is that we are running into issues with signals and signal chaining. Some of it could actually be ignored if we could catch it before it becomes fatal.
My recommendation would be to try some kind of message passing and IPC instead. For example, ZMQ and Apache Arrow.
julia> using Pkg
julia> pkg"add JavaCall"
Resolving package versions...
No Changes to `~/mambaforge/envs/julia185_java17/share/julia/environments/julia185_java17/Project.toml`
No Changes to `~/mambaforge/envs/julia185_java17/share/julia/environments/julia185_java17/Manifest.toml`
julia> using JavaCall
julia> JavaCall.init()
julia> jls = @jimport java.lang.System
JavaObject{Symbol("java.lang.System")}
julia> jcall(jls, "getProperty", JString, (JString,), "java.version")
"17.0.3-internal"
julia> out = jfield(jls, "out", @jimport java.io.PrintStream)
JavaObject{Symbol("java.io.PrintStream")}(JavaCall.JavaLocalRef(Ptr{Nothing} @0x0000559d3590e310))
julia> jcall(out, "println", Nothing, (JString,), "Hello World from Julia 1.8.5 and Java 17")
Hello World from Julia 1.8.5 and Java 17
I had issues with mambaforge, so I wasnt able to do what you wanted me to.
But I have tried on 3 different linux machines and on one Windows machine.
It fails for all linux machines but not for the windows machine.
On linux the problem happens only when using vscode.
Regarding your last question, I thought the tittle of the discussion and my first message didnt lead to confusion, but let me say it again:
We only have the problem with a julia session started by VSCode julia extension (Open Palettte > Julia:Start REPL)
We tried with openJDK JREs and oracle JREs, on Ubuntu, Debian, Fedora.
Last try was with openjdk version “17.0.5” 2022-10-18 on Fedora 37
The issue with mamba-forge is that on my local environment it messed up my env, I uninstalled it and with remote containerized dev, Im not sure how to achieve that.
I’m glad we eventually got this solved. One hint for me was that you were having more issues on Linux than Windows.
To elaborate, the issue is due to interference between task context switching and intraprocess signalling. Java and Julia both use signals, such as SIGSEGV and SIGTERM, and install signal handlers. If the wrong signal handler catches the signal or the signal handler does not exist in the current stack as expected, a segmentation fault (signal 11) can occur. The situation continues to be quite fragile.
You may also want to consider running Java and Julia in different processes and communicating using an interprocess communication (IPC) protocol such as ZeroMQ and shared memory (Apache Arrow).