Skip to content
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

Fix TSModule tracking. #494

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/debug.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ const memcheck_enabled = parse(Bool, @load_preference("memcheck", "false"))

const tracked_objects = Dict{Any,Any}()

function mark_alloc(obj::Any)
function mark_alloc(obj::Any; allow_overwrite::Bool=false)
@static if memcheck_enabled
io = Core.stdout
new_alloc_bt = backtrace()[2:end]

if haskey(tracked_objects, obj)
if haskey(tracked_objects, obj) && !allow_overwrite
old_alloc_bt, dispose_bt = tracked_objects[obj]
if dispose_bt == nothing
print("\nWARNING: An instance of $(typeof(obj)) was not properly disposed of, and a new allocation will overwrite it.")
Expand Down
10 changes: 5 additions & 5 deletions src/executionengine/ts_module.jl
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,12 @@ function ThreadSafeModule(mod::Module)
# Module and a regular Context, only a method to create one from a Module
# and a pre-existing TSContext, which isn't useful...
# TODO: expose the other convenience method?
# XXX: work around this by serializing/deserializing the module in the correct contex
# XXX: work around this by serializing/deserializing in the correct context
bitcode = convert(MemoryBuffer, mod)
new_mod = context!(context(ts_context())) do
dispose(mod)
mod = context!(context(ts_context())) do
parse(Module, bitcode)
end
dispose(mod)
mod = new_mod
end
@assert context(mod) == context(ts_context())

Expand Down Expand Up @@ -140,7 +139,7 @@ end

function tsm_callback(data::Ptr{Cvoid}, ref::API.LLVMModuleRef)
cb = Base.unsafe_pointer_to_objref(data)::ThreadSafeModuleCallback
mod = Module(ref)
mod = mark_alloc(Module(ref); allow_overwrite=true)
ctx = context(mod)
activate(ctx)
try
Expand All @@ -149,6 +148,7 @@ function tsm_callback(data::Ptr{Cvoid}, ref::API.LLVMModuleRef)
msg = sprint(Base.display_error, err, Base.catch_backtrace())
return API.LLVMCreateStringError(msg)
finally
mark_dispose(mod)
deactivate(ctx)
end
return convert(API.LLVMErrorRef, C_NULL)
Expand Down
Loading