| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Codecov Report✅ All modified and coverable lines are covered by tests. @@ Coverage Diff @@
## master #182 +/- ##
==========================================
+ Coverage 67.01% 67.90% +0.88%
==========================================
Files 11 11
Lines 1043 1050 +7
==========================================
+ Hits 699 713 +14
+ Misses 344 337 -7 ☔ View full report in Codecov by Sentry.
|
Sorry, something went wrong.
|
This seems reasonable. Thank you. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
The bug: In _jcall, only savedArgs is protected by GC.@preserve.
For most argument types, convert_arg returns (x, x) so preserving savedArgs implicitly preserves convertedArgs. But for array arguments (Vector{jint}, Vector{T<:JavaObject}, etc.), convert_arg returns different objects:
JavaCall.jl/src/convert.jl
Lines 98 to 121 in 7e1e4e0
In that case savedArgs[i] = carg, the Julia Vector{jint} while convertedArgs[i] is a new JavaObject wrapping the JNI array pointer.
This JavaObject has a finalizer that calls DeleteLocalRef. Since it's not in GC.@preserve, GC can finalize it during the ccall, deleting the JNI array while the JVM is reading from it. Similarly, obj has its pointer extracted via Ptr(obj) and is not referenced afterwards, so it could also be collected.
I couldn't write a self-contained reproducer that reliably segfaults (the GC timing race is hard to trigger in isolation), but the fix resolves a non-deterministic segfault I get when running https://github.com/JuliaConstraints/JaCoP.jl with the MathOptInterface's test suite that was kind of reproducible before this PR when running ~1200 tests creating many Java objects with array arguments. After this PR, the segfault disappears.