diff --git a/src/atomicsutils.jl b/src/atomicsutils.jl index 3c70363..11feea9 100644 --- a/src/atomicsutils.jl +++ b/src/atomicsutils.jl @@ -34,10 +34,9 @@ end ) else fptr = fieldpointer(obj, field) - vint = UInt(pointer_from_objref(value)) - julia_write_barrier(value) - julia_write_barrier(obj, value) - GC.@preserve obj value begin + ref = Ref{Any}(value) + GC.@preserve obj ref begin + vint = unsafe_load(Ptr{UInt}(pointer_from_objref(ref))) UnsafeAtomics.store!(fptr, vint, order) end end diff --git a/src/dict.jl b/src/dict.jl index b28d93e..5a3525c 100644 --- a/src/dict.jl +++ b/src/dict.jl @@ -298,14 +298,14 @@ allocate_slot(::AbstractVector{<:AbstractPair}) = nothing # TODO: handle `Value isa Union` newvalueint = uint_from(value) end - ref = nothing + handle = nothing if Slot <: InlinedPair newkeyint = uint_from(Inlined{KeyUnion{Key}}(key)) elseif key isa Moved{Key} - ref = Ref(key) - newkeyint = UInt(pointer_from_objref(ref)) - julia_write_barrier(ref) - julia_write_barrier(root, ref) + handle = Ref{Any}(Ref(key)) + GC.@preserve handle begin + newkeyint = unsafe_load(Ptr{UInt}(pointer_from_objref(handle))) + end else newkeyint = UInt(_pointer_from_objref(key)) end @@ -316,7 +316,7 @@ allocate_slot(::AbstractVector{<:AbstractPair}) = nothing ou = UIntType(oldvalueint) ou <<= fieldoffset(Slot, 2) * 8 ou |= slotref.keyint - GC.@preserve ref begin + GC.@preserve handle begin fu = UnsafeAtomics.cas!(Ptr{typeof(nu)}(ptr), ou, nu) end # @show ou nu fu @@ -361,11 +361,10 @@ allocate_slot(::AbstractVector{Slot}) where {Slot<:Ref} = Ref(Slot()) ptr = slotref.ptr new_slot = new_slot_ref[] new_slot[] = value isa NoValue ? P(key) : P(key, value) - GC.@preserve new_slot_ref begin - ou = UInt(pointer_from_objref(slotref.ref)) + ref = slotref.ref + GC.@preserve ref new_slot_ref begin + ou = UInt(pointer_from_objref(ref)) nu = UInt(unsafe_load(Ptr{Ptr{Cvoid}}(pointer_from_objref(new_slot_ref)))) - julia_write_barrier(new_slot) - julia_write_barrier(root, new_slot) fu = UnsafeAtomics.cas!(Ptr{typeof(nu)}(ptr), ou, nu) end return fu == ou diff --git a/src/utils.jl b/src/utils.jl index fd5b397..9949598 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -69,14 +69,6 @@ function padsize_for_cas(::Type{T}) where {T} end end -function padded_type(::Type{T}) where {T} - Padded = IPadder{T,padsize_for_cas(T)} - if sizeof(Padded) > 16 - @static_error("size of padded type is larger than 16 bytes") - end - return Padded -end - @inline function uint_for(::Type{T}) where {T} if sizeof(T) <= 1 return UInt8 @@ -166,43 +158,6 @@ end end end -@generated function julia_write_barrier(args::Vararg{Any,N}) where {N} - pointer_exprs = map(1:N) do i - :(_pointer_from_objref(args[$i])) - end - jlp = "{} addrspace(10)*" - llvm_args = string.("%", 0:N-1) - word = "i$(Base.Sys.WORD_SIZE)" - entry_sig = join(word .* " " .* llvm_args, ", ") - ptrs = string.("%ptr", 0:N-1) - wb_sig = join("$jlp " .* ptrs, ", ") - inttoptr = join( - (ptrs .* "_tmp = inttoptr $word " .* llvm_args .* " to {}*\n") .* - (ptrs .* " = addrspacecast {}* " .* ptrs .* "_tmp to $jlp"), - "\n", - ) - IR = ( - """ - define void @entry($entry_sig) #0 { - top: - $inttoptr - call void ($jlp, ...) @julia.write_barrier($wb_sig) - ret void - } - - declare void @julia.write_barrier($jlp, ...) #1 - - attributes #0 = { alwaysinline } - attributes #1 = { inaccessiblememonly norecurse nounwind } - """, - "entry", - ) - quote - $(Expr(:meta, :inline)) - Base.llvmcall($IR, Cvoid, NTuple{N,Ptr{Cvoid}}, $(pointer_exprs...)) - end -end - @generated allocate_singleton_ref(::Type{T}) where {T} = Ref{Any}(T.instance) @inline function pointer_from_singleton(::T) where {T}