Comments (5)
So here is the commit that added savedArgs
, about 5 years ago: 6993eb6 . cconvert
was either very new, or just about to be released. GC.@preserve
certainly wasnt around.
This change was done deliberately, and did fix some reported segfaults, so it did help. And we've not had any reports of JavaCall segfaults in years (not that this is foolproof evidence, but we used to get regular crash reports earlier, but this fix, and another around casting, made all of that go away)
Still, I can sorta see why this might be problematic, and cconvert
might the correct option. But the argument conversions are a bit wierd, and I'm not entirely sure fi cconvert
works in all cases -- if only because I havent had the chance to think about it deeply. GC.@preserve
ing savedArgs
might be a simpler, but uglier, fix
from javacall.jl.
Could we use GC.@preserve
here?
from javacall.jl.
Yes, this use of savedArgs looks likely incorrect.
If it's possible to overload cconvert
for the types which are being passed here, that should be the preferred solution. ccall
already has builtin support for GC rooting its arguments after cconvert
, but before unsafe_convert
.
If for some reason the cconvert
mechanism won't work here, you can use GC.@preserve
.
from javacall.jl.
@aviks was telling me that this code was written before cconvert
existed. We may be able to remove it enitrely and let the ccall
and cconvert
handle it as @c42f suggests.
from javacall.jl.
This change was done deliberately, and did fix some reported segfaults, so it did help.
Absolutely, it's very likely that this fixed the crashes in practice!
But if so, this is an implementation detail of the Julia runtime. In the future, it's very likely that Julia codegen will aggressively elide roots more and more often, and these crashes will emerge again.
I don't think it much matters whether you use the ccall
builtin rooting, or GC.@preserve
: choose whichever you think is easier to understand in the context of the JavaCall implementation.
Note also that cconvert
itself doesn't cause any rooting, or really have anything to do with the GC. It's the compilation of ccall
itself which is special: ccall
roots arguments passed to it as they come out of cconvert
, but before they go into unsafe_convert
. If you examine the macro expansion of the new @ccall
macro in 1.5 you will more clearly see how the conversion pipeline works, and which things are rooted:
julia> @macroexpand @ccall foo(x::A, y::B)::C
quote
var"#15#arg1root" = Base.cconvert(A, x)
var"#16#arg1" = Base.unsafe_convert(A, var"#15#arg1root")
var"#17#arg2root" = Base.cconvert(B, y)
var"#18#arg2" = Base.unsafe_convert(B, var"#17#arg2root")
$(Expr(:foreigncall,
:(:foo),
:C,
:(Core.svec(A, B)),
0,
:(:ccall),
Symbol("#16#arg1"),
Symbol("#18#arg2"),
Symbol("#15#arg1root"),
Symbol("#17#arg2root")
))
end
The things named arg$(n)root
are rooted during the foreigncall
(foreigncall is a new internal name for ccall, more or less).
from javacall.jl.
Related Issues (20)
- Ways to mitigate overall jankyness (intermittent NoClassDefFoundError and IllegalMonitorStateException) HOT 16
- Segmentation fault on JavaCall.init HOT 13
- Possible memory leak in `convert_result` HOT 4
- Use BinaryBuilder to install java?? HOT 4
- Error when loading JDK 15 x64 on Windows with Julia 1.6 RC 1 HOT 6
- Calling of java methods in a .jar file fails, but listing methods works fine. HOT 17
- TagBot trigger issue HOT 3
- Git history removed? HOT 10
- Avoiding Exceptions during automatic testing HOT 16
- Can IJulia Jupyter/Pluto run on Linux without JULIA_COPY_STACKS=1? HOT 6
- Calling java.lang.String constructor doesn't return reference to String object HOT 4
- JVM installs signal handlers by default HOT 11
- JavaCall crashes Julia 1.6.3 on macOS HOT 11
- help with jmathplot HOT 1
- jvoid missing in JavaCall v0.7.7 HOT 10
- Is 'pattern == "*.jar"' in jvm.jl a bug? HOT 3
- Allow multidimensional array inputs HOT 2
- how to set JULIA_COPY_STACKS=1 in jupyter? HOT 2
- handling of Enum types HOT 8
- Call methods of a class generated in runtime HOT 12
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from javacall.jl.