diff --git a/base/Base.jl b/base/Base.jl index dd63475f12e719..d2fa179d5e036a 100644 --- a/base/Base.jl +++ b/base/Base.jl @@ -187,7 +187,7 @@ include("strings/lazy.jl") # array structures include("indices.jl") -include("memoryt.jl") +include("genericmemory.jl") include("array.jl") include("abstractarray.jl") include("subarray.jl") diff --git a/base/array.jl b/base/array.jl index 53f6fd434127cb..969786a2c96387 100644 --- a/base/array.jl +++ b/base/array.jl @@ -1097,7 +1097,7 @@ function array_new_memory(mem::Memory{T}, newlen::Int, add_null::Bool) where T # if data is in a String, keep it that way # TODO: use jl_gc_expand_string(oldstr, newlen)? str = _string_n(newlen) - return ccall(:jl_string_to_memoryt, Memory{T}, (Any,), str) + return ccall(:jl_string_to_genericmemory, Memory{T}, (Any,), str) else # TODO: when implimented, this should use a memory growing call mem = Memory{T}(undef, newlen + add_null) diff --git a/base/boot.jl b/base/boot.jl index d8533e534925c0..618f9dcb25d1e0 100644 --- a/base/boot.jl +++ b/base/boot.jl @@ -494,7 +494,7 @@ const undef = UndefInitializer() if isdefined(self, :instance) && m === 0 self.instance else - ccall(:jl_alloc_memoryt, Ref{GenericMemory{isatomic,T}}, (Any, Int), self, m) + ccall(:jl_alloc_genericmemory, Ref{GenericMemory{isatomic,T}}, (Any, Int), self, m) end (self::Type{GenericMemory{isatomic,T}})(::UndefInitializer, d::NTuple{1,Int}) where {T,isatomic} = self(undef, getfield(d,1)) # empty vector constructor diff --git a/base/compiler/compiler.jl b/base/compiler/compiler.jl index b19552046ce9bc..6c435dd88cf763 100644 --- a/base/compiler/compiler.jl +++ b/base/compiler/compiler.jl @@ -105,7 +105,7 @@ include("strings/lazy.jl") # core array operations include("indices.jl") -include("memoryt.jl") +include("genericmemory.jl") include("array.jl") include("abstractarray.jl") diff --git a/base/compiler/tfuncs.jl b/base/compiler/tfuncs.jl index 9e292ebbc08058..c21aef2642e8d0 100644 --- a/base/compiler/tfuncs.jl +++ b/base/compiler/tfuncs.jl @@ -2003,14 +2003,14 @@ function array_elmtype(@nospecialize ary) return Any end -@nospecs function memoryt_builtin_common_errorcheck(boundscheck, mem, idx) +@nospecs function genericmemory_builtin_common_errorcheck(boundscheck, mem, idx) hasintersect(widenconst(boundscheck), Bool) || return false hasintersect(widenconst(mem), GenericMemory) || return false hasintersect(widenconst(idx), Int) || return false return true end -function memoryt_elemtype(@nospecialize mem) +function genericmemory_elemtype(@nospecialize mem) m = widenconst(mem) if !has_free_typevars(m) && m <: GenericMemory m0 = m @@ -2170,12 +2170,12 @@ end return true end -function memoryt_builtin_common_nothrow(argtypes::Vector{Any}, ismemoryref::Bool) +function genericmemory_builtin_common_nothrow(argtypes::Vector{Any}, ismemoryref::Bool) idx_idx = ismemoryref ? 3 : 4 length(argtypes) == idx_idx || return false boundscheck = argtypes[1] memtype = widenconst(argtypes[2]) - memoryt_builtin_common_typecheck(boundscheck, memtype, argtypes[idx_idx]) || return false + genericmemory_builtin_common_typecheck(boundscheck, memtype, argtypes[idx_idx]) || return false if ismemoryref # If we could potentially throw undef ref errors, bail out now. array_type_undefable(memtype) && return false @@ -2193,7 +2193,7 @@ function memoryt_builtin_common_nothrow(argtypes::Vector{Any}, ismemoryref::Bool return false end -@nospecs function memoryt_builtin_common_typecheck(boundscheck, memtype, idx) +@nospecs function genericmemory_builtin_common_typecheck(boundscheck, memtype, idx) return boundscheck ⊑ Bool && memtype ⊑ GenericMemory && idx ⊑ Int end @@ -3080,14 +3080,14 @@ function foreigncall_effects(@specialize(abstract_eval), e::Expr) args = e.args name = args[1] isa(name, QuoteNode) && (name = name.value) - if name === :jl_alloc_memoryt - nothrow = new_memoryt_nothrow(abstract_eval, args) + if name === :jl_alloc_genericmemory + nothrow = new_genericmemory_nothrow(abstract_eval, args) return Effects(EFFECTS_TOTAL; consistent=CONSISTENT_IF_NOTRETURNED, nothrow) end return EFFECTS_UNKNOWN end -function new_memoryt_nothrow(@nospecialize(abstract_eval), args::Vector{Any}) +function new_genericmemory_nothrow(@nospecialize(abstract_eval), args::Vector{Any}) length(args) ≥ 1+FOREIGNCALL_ARG_START || return false mtype = instanceof_tfunc(abstract_eval(args[FOREIGNCALL_ARG_START]))[1] isa(mtype, DataType) || return false diff --git a/base/memoryt.jl b/base/genericmemory.jl similarity index 98% rename from base/memoryt.jl rename to base/genericmemory.jl index 20dc1a45b6d498..3d244f72628cf3 100644 --- a/base/memoryt.jl +++ b/base/genericmemory.jl @@ -1,6 +1,6 @@ # This file is a part of Julia. License is MIT: https://julialang.org/license -## memoryt.jl: Managed Memory +## genericmemory.jl: Managed Memory """ GenericMemory{isatomic, T} <: AbstractVector{T} @@ -64,7 +64,7 @@ end unsafe_copyto!(dest::Memory, doffs, src::Memory, soffs, n) = _unsafe_copyto!(dest, doffs, src, soffs, n) -copy(a::T) where {T<:Memory} = ccall(:jl_memoryt_copy, Ref{T}, (Any,), a) +copy(a::T) where {T<:Memory} = ccall(:jl_genericmemory_copy, Ref{T}, (Any,), a) ## Constructors ## diff --git a/base/pointer.jl b/base/pointer.jl index aa75acfe3d9795..9746d9b7f4cfde 100644 --- a/base/pointer.jl +++ b/base/pointer.jl @@ -129,12 +129,12 @@ function unsafe_wrap(::Union{Type{Array},Type{Array{T}},Type{Array{T,1}}}, end function unsafe_wrap(::Union{Type{GenericMemory{isatomic}},Type{GenericMemory{isatomic,T}}}, p::Ptr{T}, dims::Tuple{Int}; own::Bool = false) where {isatomic,T} - ccall(:jl_ptr_to_memoryt, Ref{GenericMemory{isatomic,T}}, + ccall(:jl_ptr_to_genericmemory, Ref{GenericMemory{isatomic,T}}, (Any, Ptr{Cvoid}, Csize_t, Cint), Memory{isatomic,T}, p, dim[1], own) end function unsafe_wrap(::Union{Type{GenericMemory{isatomic}},Type{GenericMemory{isatomic,T}}}, p::Ptr{T}, d::Integer; own::Bool = false) where {isatomic,T} - ccall(:jl_ptr_to_memoryt, Ref{GenericMemory{isatomic,T}}, + ccall(:jl_ptr_to_genericmemory, Ref{GenericMemory{isatomic,T}}, (Any, Ptr{Cvoid}, Csize_t, Cint), GenericMemory{isatomic,T}, p, d, own) end unsafe_wrap(Atype::Union{Type{Array},Type{Array{T}},Type{Array{T,N}},Type{GenericMemory{isatomic}},Type{GenericMemory{isatomic,T}}} where {isatomic}, diff --git a/src/Makefile b/src/Makefile index 3ffd072b234f74..cab263e244bae4 100644 --- a/src/Makefile +++ b/src/Makefile @@ -42,7 +42,7 @@ endif SRCS := \ jltypes gf typemap smallintset ast builtins module interpreter symbol \ - dlload sys init task array memoryt staticdata toplevel jl_uv datatype \ + dlload sys init task array genericmemory staticdata toplevel jl_uv datatype \ simplevector runtime_intrinsics precompile jloptions \ threading partr stackwalk gc gc-debug gc-pages gc-stacks gc-alloc-profiler method \ jlapi signal-handling safepoint timing subtype rtutils gc-heap-snapshot \ diff --git a/src/array.c b/src/array.c index 5fd1804dfd9852..f67a41a15b337b 100644 --- a/src/array.c +++ b/src/array.c @@ -119,7 +119,7 @@ JL_UNUSED static size_t overallocation(size_t maxsize) JL_DLLEXPORT char *jl_array_typetagdata(jl_array_t *a) JL_NOTSAFEPOINT { assert(jl_array_isbitsunion(a)); - return jl_memoryt_typetagdata(a->ref.mem) + (uintptr_t)a->ref.data; + return jl_genericmemory_typetagdata(a->ref.mem) + (uintptr_t)a->ref.data; } STATIC_INLINE jl_array_t *_new_array(jl_value_t *atype, uint32_t ndims, size_t *dims) @@ -136,7 +136,7 @@ STATIC_INLINE jl_array_t *_new_array(jl_value_t *atype, uint32_t ndims, size_t * // extra byte for all julia allocated byte vectors int add_null = JL_ARRAY_IMPL_NUL && nel != 0 && ndims == 1 && layout->size == 1 && !layout->arrayelem_isunion; - jl_memory_t *mem = jl_alloc_memoryt(mtype, nel + add_null); + jl_genericmemory_t *mem = jl_alloc_genericmemory(mtype, nel + add_null); if (add_null && ((char*)mem->data)[nel] != '\0') ((char*)mem->data)[nel] = '\0'; JL_GC_PUSH1(&mem); @@ -162,7 +162,7 @@ STATIC_INLINE jl_array_t *_new_array(jl_value_t *atype, uint32_t ndims, size_t * return a; } -jl_memory_t *jl_new_memoryt_for_deserialization(jl_value_t *mtype, size_t nel, int isunion, int elsz); +jl_genericmemory_t *jl_new_genericmemory_for_deserialization(jl_value_t *mtype, size_t nel, int isunion, int elsz); jl_array_t *jl_new_array_for_deserialization(jl_value_t *atype, uint32_t ndims, size_t *dims, int isunboxed, int hasptr, int isunion, int elsz) @@ -178,7 +178,7 @@ jl_array_t *jl_new_array_for_deserialization(jl_value_t *atype, uint32_t ndims, jl_value_t *mtype = jl_field_type_concrete((jl_datatype_t*)jl_field_type_concrete((jl_datatype_t*)atype, 0), 1); const jl_datatype_layout_t *layout = ((jl_datatype_t*)mtype)->layout; int add_null = JL_ARRAY_IMPL_NUL && nel != 0 && ndims == 1 && layout->size == 1 && !layout->arrayelem_isunion; - jl_memory_t *mem = jl_new_memoryt_for_deserialization(mtype, nel + add_null, isunion, elsz); + jl_genericmemory_t *mem = jl_new_genericmemory_for_deserialization(mtype, nel + add_null, isunion, elsz); if (add_null && ((char*)mem->data)[nel] != '\0') ((char*)mem->data)[nel] = '\0'; JL_GC_PUSH1(&mem); @@ -247,7 +247,7 @@ JL_DLLEXPORT jl_array_t *jl_reshape_array(jl_value_t *atype, jl_array_t *data, if (offset != 0 || a->ref.mem->length != l) { // if this is a multidimentional slice of a vector, may need to record the size JL_GC_PUSH1(&a); - a->ref.mem = jl_memoryt_slice(a->ref.mem, offset, l); + a->ref.mem = jl_genericmemory_slice(a->ref.mem, offset, l); JL_GC_POP(); } } @@ -255,12 +255,12 @@ JL_DLLEXPORT jl_array_t *jl_reshape_array(jl_value_t *atype, jl_array_t *data, return a; } -JL_DLLEXPORT jl_memory_t *jl_string_to_memoryt(jl_value_t *str); +JL_DLLEXPORT jl_genericmemory_t *jl_string_to_genericmemory(jl_value_t *str); JL_DLLEXPORT jl_array_t *jl_string_to_array(jl_value_t *str) { jl_task_t *ct = jl_current_task; - jl_memory_t *mem = jl_string_to_memoryt(str); + jl_genericmemory_t *mem = jl_string_to_genericmemory(str); JL_GC_PUSH1(&mem); int ndimwords = 1; int tsz = sizeof(jl_array_t) + ndimwords*sizeof(size_t); @@ -281,7 +281,7 @@ JL_DLLEXPORT jl_array_t *jl_ptr_to_array_1d(jl_value_t *atype, void *data, jl_exceptionf(jl_argumenterror_type, "invalid Array dimensions"); jl_value_t *mtype = jl_field_type_concrete((jl_datatype_t*)jl_field_type_concrete((jl_datatype_t*)atype, 0), 1); const jl_datatype_layout_t *layout = ((jl_datatype_t*)mtype)->layout; - jl_memory_t *mem = jl_ptr_to_memoryt(mtype, data, nel, own_buffer); + jl_genericmemory_t *mem = jl_ptr_to_genericmemory(mtype, data, nel, own_buffer); JL_GC_PUSH1(&mem); int ndims = 1; int tsz = sizeof(jl_array_t) + ndims*sizeof(size_t); @@ -315,7 +315,7 @@ JL_DLLEXPORT jl_array_t *jl_ptr_to_array(jl_value_t *atype, void *data, return jl_ptr_to_array_1d(atype, data, nel, own_buffer); jl_value_t *mtype = jl_field_type_concrete((jl_datatype_t*)jl_field_type_concrete((jl_datatype_t*)atype, 0), 1); const jl_datatype_layout_t *layout = ((jl_datatype_t*)mtype)->layout; - jl_memory_t *mem = jl_ptr_to_memoryt(mtype, data, nel, own_buffer); + jl_genericmemory_t *mem = jl_ptr_to_genericmemory(mtype, data, nel, own_buffer); JL_GC_PUSH1(&mem); int ndimwords = ndims; int tsz = sizeof(jl_array_t) + ndimwords*sizeof(size_t); @@ -344,7 +344,7 @@ JL_DLLEXPORT jl_value_t *jl_array_to_string(jl_array_t *a) } jl_value_t *str; if (a->ref.data == a->ref.mem->data) - str = jl_memoryt_to_string(a->ref.mem, len); + str = jl_genericmemory_to_string(a->ref.mem, len); else str = jl_pchar_to_string(jl_array_data(a, char), len); a->ref.mem->length = 0; // TODO(jwn): unsound? @@ -366,20 +366,20 @@ static int array_resize_buffer(jl_array_t *a, size_t newlen) const jl_datatype_layout_t *layout = ((jl_datatype_t*)mtype)->layout; int add_null = JL_ARRAY_IMPL_NUL && newlen != 0 && layout->size == 1 && !layout->arrayelem_isunion; int newbuf = 1; - jl_memory_t *mem; + jl_genericmemory_t *mem; if (jl_is_string(jl_array_owner(a))) { // if data is in a String, keep it that way jl_value_t *str = jl_alloc_string(newlen); // TODO: use jl_gc_expand_string(oldstr, newlen)? JL_GC_PUSH1(&str); - mem = jl_string_to_memoryt(str); + mem = jl_string_to_genericmemory(str); a->ref.mem = mem; a->ref.data = mem->data; jl_gc_wb(a, mem); JL_GC_POP(); } else { - mem = jl_alloc_memoryt(mtype, newlen + add_null); + mem = jl_alloc_genericmemory(mtype, newlen + add_null); a->ref.mem = mem; if (layout->arrayelem_isunion || layout->size == 0) a->ref.data = 0; @@ -404,17 +404,17 @@ STATIC_INLINE void jl_array_shrink(jl_array_t *a, size_t dec) size_t nel = maxsize - dec; size_t n = jl_array_nrows(a); int add_null = JL_ARRAY_IMPL_NUL && elsz == 1 && !isbitsunion; - jl_memory_t *newmem = jl_alloc_memoryt((jl_value_t*)jl_typetagof(a->ref.mem), nel + add_null); + jl_genericmemory_t *newmem = jl_alloc_genericmemory((jl_value_t*)jl_typetagof(a->ref.mem), nel + add_null); const char *olddata = (char*)a->ref.mem->data + byteoffset; char *newdata = (char*)newmem->data + byteoffset; memcpy(newdata, olddata, n * elsz); if (isbitsunion) { char *typetagdata = jl_array_typetagdata(a); - char *newtypetagdata = jl_memoryt_typetagdata(newmem) + (uintptr_t)a->ref.data; + char *newtypetagdata = jl_genericmemory_typetagdata(newmem) + (uintptr_t)a->ref.data; memcpy(newtypetagdata, typetagdata, n); } if (add_null) { - assert(&newdata[n] < (char*)newmem->data + newmem->length + jl_is_string(jl_memoryt_owner(newmem))); + assert(&newdata[n] < (char*)newmem->data + newmem->length + jl_is_string(jl_genericmemory_owner(newmem))); if (newdata[n] != 0) newdata[n] = 0; } @@ -667,13 +667,13 @@ JL_DLLEXPORT jl_array_t *jl_array_copy(jl_array_t *ary) const jl_datatype_layout_t *layout = ((jl_datatype_t*)jl_typetagof(ary->ref.mem))->layout; int ndims = jl_array_ndims(ary); int add_null = JL_ARRAY_IMPL_NUL && len != 0 && ndims == 1 && layout->size == 1 && !layout->arrayelem_isunion; - jl_memory_t *mem = jl_new_memoryt_for_deserialization((jl_value_t*)jl_typetagof(ary->ref.mem), len + add_null, layout->arrayelem_isunion, layout->size); + jl_genericmemory_t *mem = jl_new_genericmemory_for_deserialization((jl_value_t*)jl_typetagof(ary->ref.mem), len + add_null, layout->arrayelem_isunion, layout->size); if (add_null && ((char*)mem->data)[len] != '\0') ((char*)mem->data)[len] = '\0'; // ensure isbits union arrays copy their selector bytes correctly if (layout->arrayelem_isunion) { memcpy(mem->data, (char*)ary->ref.mem->data + (size_t)jl_array_data_(ary) * elsz, len * elsz); - memcpy(jl_memoryt_typetagdata(mem), jl_array_typetagdata(ary), len); + memcpy(jl_genericmemory_typetagdata(mem), jl_array_typetagdata(ary), len); } else { memcpy(mem->data, jl_array_data_(ary), len * elsz); diff --git a/src/builtins.c b/src/builtins.c index 0fd9ae30db0d44..2eda6303aba193 100644 --- a/src/builtins.c +++ b/src/builtins.c @@ -539,8 +539,8 @@ JL_CALLABLE(jl_f_sizeof) assert(jl_is_datatype(dt)); assert(!dt->name->abstract); size_t sz = jl_datatype_size(dt); - if (jl_is_memory(x)) // TODO(jwn): add bitsunion bytes? - sz *= ((jl_memory_t*)x)->length; + if (jl_is_genericmemory(x)) // TODO(jwn): add bitsunion bytes? + sz *= ((jl_genericmemory_t*)x)->length; return jl_box_long(sz); } @@ -1547,9 +1547,9 @@ JL_CALLABLE(jl_f_memoryref) { JL_NARGS(memoryref, 1, 3); if (nargs == 1) { - JL_TYPECHK(memoryref, memory, args[0]); - jl_memory_t *m = (jl_memory_t*)args[0]; - jl_value_t *typ = jl_apply_type2((jl_value_t*)jl_memoryref_type, jl_tparam0(jl_typetagof(m)), jl_tparam1(jl_typetagof(m))); + JL_TYPECHK(memoryref, genericmemory, args[0]); + jl_genericmemory_t *m = (jl_genericmemory_t*)args[0]; + jl_value_t *typ = jl_apply_type2((jl_value_t*)jl_genericmemoryref_type, jl_tparam0(jl_typetagof(m)), jl_tparam1(jl_typetagof(m))); JL_GC_PROMISE_ROOTED(typ); // it is a concrete type const jl_datatype_layout_t *layout = ((jl_datatype_t*)jl_typetagof(m))->layout; if (layout->arrayelem_isunion || layout->size == 0) @@ -1557,11 +1557,11 @@ JL_CALLABLE(jl_f_memoryref) return (jl_value_t*)jl_new_memoryref(typ, m, m->data); } else { - JL_TYPECHK(memoryref, memoryref, args[0]); + JL_TYPECHK(memoryref, genericmemoryref, args[0]); JL_TYPECHK(memoryref, long, args[1]); if (nargs == 3) JL_TYPECHK(memoryref, bool, args[2]); - jl_memoryref_t *m = (jl_memoryref_t*)args[0]; + jl_genericmemoryref_t *m = (jl_genericmemoryref_t*)args[0]; size_t i = jl_unbox_long(args[1]) - 1; const jl_datatype_layout_t *layout = ((jl_datatype_t*)jl_typetagof(m->mem))->layout; char *data = (char*)m->data; @@ -1587,10 +1587,10 @@ JL_CALLABLE(jl_f_memoryref) JL_CALLABLE(jl_f_memoryrefget) { JL_NARGS(memoryrefget, 3, 3); - JL_TYPECHK(memoryrefget, memoryref, args[0]); + JL_TYPECHK(memoryrefget, genericmemoryref, args[0]); JL_TYPECHK(memoryrefget, symbol, args[1]); JL_TYPECHK(memoryrefget, bool, args[2]); - jl_memoryref_t m = *(jl_memoryref_t*)args[0]; + jl_genericmemoryref_t m = *(jl_genericmemoryref_t*)args[0]; jl_value_t *isatomic = jl_tparam0(jl_typetagof(m.mem)); if (isatomic == jl_false) if (args[1] != (jl_value_t*)jl_not_atomic_sym) @@ -1603,10 +1603,10 @@ JL_CALLABLE(jl_f_memoryrefget) JL_CALLABLE(jl_f_memoryrefset) { JL_NARGS(memoryrefset, 4, 4); - JL_TYPECHK(memoryrefset, memoryref, args[0]); + JL_TYPECHK(memoryrefset, genericmemoryref, args[0]); JL_TYPECHK(memoryrefset, symbol, args[2]); JL_TYPECHK(memoryrefset, bool, args[3]); - jl_memoryref_t m = *(jl_memoryref_t*)args[0]; + jl_genericmemoryref_t m = *(jl_genericmemoryref_t*)args[0]; jl_value_t *isatomic = jl_tparam0(jl_typetagof(m.mem)); if (isatomic == jl_false) if (args[2] != (jl_value_t*)jl_not_atomic_sym) @@ -1620,10 +1620,10 @@ JL_CALLABLE(jl_f_memoryrefset) JL_CALLABLE(jl_f_memoryref_isassigned) { JL_NARGS(memoryref_isassigned, 3, 3); - JL_TYPECHK(memoryref_isassigned, memoryref, args[0]); + JL_TYPECHK(memoryref_isassigned, genericmemoryref, args[0]); JL_TYPECHK(memoryref_isassigned, symbol, args[1]); JL_TYPECHK(memoryref_isassigned, bool, args[2]); - jl_memoryref_t m = *(jl_memoryref_t*)args[0]; + jl_genericmemoryref_t m = *(jl_genericmemoryref_t*)args[0]; jl_value_t *isatomic = jl_tparam0(jl_typetagof(m.mem)); if (isatomic == jl_false) if (args[1] != (jl_value_t*)jl_not_atomic_sym) @@ -1823,7 +1823,7 @@ static int references_name(jl_value_t *p, jl_typename_t *name, int affects_layou jl_datatype_t *dp = (jl_datatype_t*)p; if (affects_layout && dp->name == name) return 1; - affects_layout = jl_is_memory_type(dp) || ((jl_datatype_t*)jl_unwrap_unionall(dp->name->wrapper))->layout == NULL; + affects_layout = jl_is_genericmemory_type(dp) || ((jl_datatype_t*)jl_unwrap_unionall(dp->name->wrapper))->layout == NULL; // and even if it has a layout, the fields themselves might trigger layouts if they use tparam i // rather than checking this for each field, we just assume it applies if (!affects_layout && freevars && jl_field_names(dp) != jl_emptysvec) { @@ -2209,8 +2209,8 @@ void jl_init_primitives(void) JL_GC_DISABLED add_builtin("AbstractArray", (jl_value_t*)jl_abstractarray_type); add_builtin("DenseArray", (jl_value_t*)jl_densearray_type); add_builtin("Array", (jl_value_t*)jl_array_type); - add_builtin("GenericMemory", (jl_value_t*)jl_memory_type); - add_builtin("MemoryRef", (jl_value_t*)jl_memoryref_type); + add_builtin("GenericMemory", (jl_value_t*)jl_genericmemory_type); + add_builtin("MemoryRef", (jl_value_t*)jl_genericmemoryref_type); add_builtin("Expr", (jl_value_t*)jl_expr_type); add_builtin("LineNumberNode", (jl_value_t*)jl_linenumbernode_type); diff --git a/src/ccall.cpp b/src/ccall.cpp index 68c6a0f4d0e0d0..afde9a3ac996e7 100644 --- a/src/ccall.cpp +++ b/src/ccall.cpp @@ -1271,7 +1271,7 @@ static const std::string verify_ccall_sig(jl_value_t *&rt, jl_value_t *at, JL_TYPECHK(ccall, type, rt); JL_TYPECHK(ccall, simplevector, at); - if (rt == (jl_value_t*)jl_any_type || jl_is_array_type(rt) || jl_is_memory_type(rt) || + if (rt == (jl_value_t*)jl_any_type || jl_is_array_type(rt) || jl_is_genericmemory_type(rt) || (jl_is_datatype(rt) && ((jl_datatype_t*)rt)->layout != NULL && jl_is_layout_opaque(((jl_datatype_t*)rt)->layout))) { // n.b. `Array` used as return type just returns a julia object reference diff --git a/src/cgutils.cpp b/src/cgutils.cpp index ecdc5eeb74be63..539dcca4743a8f 100644 --- a/src/cgutils.cpp +++ b/src/cgutils.cpp @@ -725,8 +725,8 @@ static Type *_julia_struct_to_llvm(jl_codegen_params_t *ctx, LLVMContext &ctxt, if (jl_is_primitivetype(jt)) return bitstype_to_llvm(jt, ctxt, llvmcall); jl_datatype_t *jst = (jl_datatype_t*)jt; - if (jl_is_structtype(jt) && !(jst->layout && jl_is_layout_opaque(jst->layout)) && !jl_is_array_type(jst) && !jl_is_memory_type(jst)) { - if (jl_is_memoryref_type(jst)) { + if (jl_is_structtype(jt) && !(jst->layout && jl_is_layout_opaque(jst->layout)) && !jl_is_array_type(jst) && !jl_is_genericmemory_type(jst)) { + if (jl_is_genericmemoryref_type(jst)) { jl_value_t *mty_dt = jl_field_type_concrete(jst, 1); const jl_datatype_layout_t *layout = ((jl_datatype_t*)mty_dt)->layout; bool isboxed = layout->arrayelem_isboxed; @@ -2537,7 +2537,7 @@ static MDNode *best_field_tbaa(jl_codectx_t &ctx, const jl_cgval_t &strct, jl_da if (byte_offset != offsetof(jl_datatype_t, types)) return ctx.tbaa().tbaa_const; if (tbaa == ctx.tbaa().tbaa_array) { - if (jl_is_memory_type(jt)) { + if (jl_is_genericmemory_type(jt)) { if (idx == 0) return ctx.tbaa().tbaa_memorylen; if (idx == 1) @@ -2757,14 +2757,14 @@ static Value *emit_n_varargs(jl_codectx_t &ctx) #endif } -static Value *emit_memorytelsize(jl_codectx_t &ctx, Value *v, jl_value_t *typ) +static Value *emit_genericmemoryelsize(jl_codectx_t &ctx, Value *v, jl_value_t *typ) { ++EmittedArrayElsize; jl_datatype_t *sty = (jl_datatype_t*)jl_unwrap_unionall(typ); if (jl_is_datatype(sty) && !jl_has_free_typevars((jl_value_t*)sty) && sty->layout) { if (jl_is_array_type(sty)) sty = (jl_datatype_t*)jl_field_type_concrete(sty, 0); - if (jl_is_memoryref_type(sty)) + if (jl_is_genericmemoryref_type(sty)) sty = (jl_datatype_t*)jl_field_type_concrete(sty, 1); return ConstantInt::get(ctx.types().T_size, sty->layout->size); } @@ -2825,22 +2825,22 @@ static intptr_t arraytype_maxsize(jl_value_t *ty) return INTPTR_MAX / elsz; } -static ssize_t memorytype_constelsize(jl_value_t *typ) +static ssize_t genericmemoryype_constelsize(jl_value_t *typ) { jl_datatype_t *sty = (jl_datatype_t*)jl_unwrap_unionall(typ); if (jl_is_datatype(sty) && !jl_has_free_typevars((jl_value_t*)sty) && sty->layout) { if (jl_is_array_type(sty)) sty = (jl_datatype_t*)jl_field_type_concrete(sty, 0); - if (jl_is_memoryref_type(sty)) + if (jl_is_genericmemoryref_type(sty)) sty = (jl_datatype_t*)jl_field_type_concrete(sty, 1); return sty->layout->size; } return -1; } -static intptr_t memorytype_maxsize(jl_value_t *ty) +static intptr_t genericmemoryype_maxsize(jl_value_t *ty) { - ssize_t elsz = memorytype_constelsize(ty); + ssize_t elsz = genericmemoryype_constelsize(ty); if (elsz <= 0) return INTPTR_MAX; return INTPTR_MAX / elsz; @@ -2884,15 +2884,15 @@ static Value *emit_arraysize(jl_codectx_t &ctx, const jl_cgval_t &tinfo, int dim return emit_arraysize(ctx, tinfo, ConstantInt::get(getInt32Ty(ctx.builder.getContext()), dim)); } -static Value *emit_memorytlen(jl_codectx_t &ctx, Value *addr, jl_value_t *typ) +static Value *emit_genericmemorylen(jl_codectx_t &ctx, Value *addr, jl_value_t *typ) { - addr = emit_bitcast(ctx, decay_derived(ctx, addr), ctx.types().T_jlmemoryt->getPointerTo()), - addr = ctx.builder.CreateStructGEP(ctx.types().T_jlmemoryt, addr, 0); - LoadInst *LI = ctx.builder.CreateAlignedLoad(ctx.types().T_jlmemoryt->getElementType(0), addr, Align(sizeof(size_t))); + addr = emit_bitcast(ctx, decay_derived(ctx, addr), ctx.types().T_jlgenericmemory->getPointerTo()), + addr = ctx.builder.CreateStructGEP(ctx.types().T_jlgenericmemory, addr, 0); + LoadInst *LI = ctx.builder.CreateAlignedLoad(ctx.types().T_jlgenericmemory->getElementType(0), addr, Align(sizeof(size_t))); jl_aliasinfo_t aliasinfo_mem = jl_aliasinfo_t::fromTBAA(ctx, ctx.tbaa().tbaa_memorylen); aliasinfo_mem.decorateInst(LI); MDBuilder MDB(ctx.builder.getContext()); - auto rng = MDB.createRange(Constant::getNullValue(ctx.types().T_size), ConstantInt::get(ctx.types().T_size, memorytype_maxsize(typ))); + auto rng = MDB.createRange(Constant::getNullValue(ctx.types().T_size), ConstantInt::get(ctx.types().T_size, genericmemoryype_maxsize(typ))); LI->setMetadata(LLVMContext::MD_range, rng); return LI; } @@ -2902,13 +2902,13 @@ static Value *emit_vectormaxsize(jl_codectx_t &ctx, const jl_cgval_t &ary) Value *t = boxed(ctx, ary); Value *addr = ctx.builder.CreateStructGEP(ctx.types().T_jlarray, emit_bitcast(ctx, t, ctx.types().T_pjlarray), 1); - Type *T_pmemoryt = ctx.types().T_jlarray->getElementType(1); - LoadInst *LI_mem = ctx.builder.CreateAlignedLoad(T_pmemoryt, addr, Align(sizeof(char*))); + Type *T_pgenericmemory = ctx.types().T_jlarray->getElementType(1); + LoadInst *LI_mem = ctx.builder.CreateAlignedLoad(T_pgenericmemory, addr, Align(sizeof(char*))); LI_mem->setOrdering(AtomicOrdering::NotAtomic); LI_mem->setMetadata(LLVMContext::MD_nonnull, MDNode::get(ctx.builder.getContext(), None)); jl_aliasinfo_t aliasinfo_mem = jl_aliasinfo_t::fromTBAA(ctx, ctx.tbaa().tbaa_arrayptr); aliasinfo_mem.decorateInst(LI_mem); - return emit_memorytlen(ctx, LI_mem, ary.typ); // maxsize = a->ref.mem->length + return emit_genericmemorylen(ctx, LI_mem, ary.typ); // maxsize = a->ref.mem->length } static Value *emit_arraylen(jl_codectx_t &ctx, const jl_cgval_t &tinfo) @@ -2937,15 +2937,15 @@ static Value *emit_arraylen(jl_codectx_t &ctx, const jl_cgval_t &tinfo) return selidx; } -static Value *emit_memorytptr(jl_codectx_t &ctx, Value *mem, bool isboxed, bool isunion, bool isghost, unsigned AS) +static Value *emit_genericmemoryptr(jl_codectx_t &ctx, Value *mem, bool isboxed, bool isunion, bool isghost, unsigned AS) { ++EmittedArrayptr; PointerType *PT = cast(mem->getType()); assert(PT == ctx.types().T_prjlvalue); - Value *addr = emit_bitcast(ctx, mem, ctx.types().T_jlmemoryt->getPointerTo(PT->getAddressSpace())); - addr = ctx.builder.CreateStructGEP(ctx.types().T_jlmemoryt, addr, 1); + Value *addr = emit_bitcast(ctx, mem, ctx.types().T_jlgenericmemory->getPointerTo(PT->getAddressSpace())); + addr = ctx.builder.CreateStructGEP(ctx.types().T_jlgenericmemory, addr, 1); setName(ctx.emission_context, addr, ".data_ptr"); - PointerType *PPT = cast(ctx.types().T_jlmemoryt->getElementType(1)); + PointerType *PPT = cast(ctx.types().T_jlgenericmemory->getElementType(1)); LoadInst *LI = ctx.builder.CreateAlignedLoad(PPT, addr, Align(sizeof(char*))); LI->setOrdering(AtomicOrdering::NotAtomic); LI->setMetadata(LLVMContext::MD_nonnull, MDNode::get(ctx.builder.getContext(), None)); @@ -2962,9 +2962,9 @@ static Value *emit_memorytptr(jl_codectx_t &ctx, Value *mem, bool isboxed, bool return ptr; } -static Value *emit_memorytptr(jl_codectx_t &ctx, const jl_cgval_t &mem, bool isboxed, bool isunion, bool isghost, unsigned AS) +static Value *emit_genericmemoryptr(jl_codectx_t &ctx, const jl_cgval_t &mem, bool isboxed, bool isunion, bool isghost, unsigned AS) { - return emit_memorytptr(ctx, boxed(ctx, mem), isboxed, isunion, isghost, AS); + return emit_genericmemoryptr(ctx, boxed(ctx, mem), isboxed, isunion, isghost, AS); } static Value *emit_arrayptr_internal(jl_codectx_t &ctx, const jl_cgval_t &tinfo, unsigned AS, ssize_t nd, bool isboxed, bool isunion, bool isghost) @@ -2990,8 +2990,8 @@ static Value *emit_arrayptr_internal(jl_codectx_t &ctx, const jl_cgval_t &tinfo, // TODO: mark dereferenceable<16> aliasinfo.decorateInst(LI_mem); addr = decay_derived(ctx, LI_mem); - addr = ctx.builder.CreateStructGEP(ctx.types().T_jlmemoryt, addr, 1); - PPT = cast(ctx.types().T_jlmemoryt->getElementType(1)); + addr = ctx.builder.CreateStructGEP(ctx.types().T_jlgenericmemory, addr, 1); + PPT = cast(ctx.types().T_jlgenericmemory->getElementType(1)); aliasinfo = jl_aliasinfo_t::fromTBAA(ctx, ctx.tbaa().tbaa_memoryptr); } else { @@ -3022,7 +3022,7 @@ static Value *emit_arrayptr_internal(jl_codectx_t &ctx, const jl_cgval_t &tinfo, addr = LI; if (isunion) { - Value *elsize = emit_memorytelsize(ctx, LI_mem, tinfo.typ); + Value *elsize = emit_genericmemoryelsize(ctx, LI_mem, tinfo.typ); Value *offset = emit_arrayoffset(ctx, tinfo, nd); offset = ctx.builder.CreateZExt(offset, ctx.types().T_size); offset = ctx.builder.CreateMul(offset, elsize); @@ -3044,17 +3044,17 @@ static Value *emit_unsafe_arrayptr(jl_codectx_t &ctx, const jl_cgval_t &tinfo, s return emit_arrayptr_internal(ctx, tinfo, 0, nd, false, isunion, isghost); } -static Value *emit_memorytowner(jl_codectx_t &ctx, Value *t) +static Value *emit_genericmemoryowner(jl_codectx_t &ctx, Value *t) { - Value *m = emit_bitcast(ctx, decay_derived(ctx, t), ctx.types().T_jlmemoryt->getPointerTo(0)); - Value *addr = ctx.builder.CreateStructGEP(ctx.types().T_jlmemoryt, m, 1); - Type *T_data = ctx.types().T_jlmemoryt->getElementType(1); + Value *m = emit_bitcast(ctx, decay_derived(ctx, t), ctx.types().T_jlgenericmemory->getPointerTo(0)); + Value *addr = ctx.builder.CreateStructGEP(ctx.types().T_jlgenericmemory, m, 1); + Type *T_data = ctx.types().T_jlgenericmemory->getElementType(1); LoadInst *LI = ctx.builder.CreateAlignedLoad(T_data, addr, Align(sizeof(char*))); LI->setOrdering(AtomicOrdering::NotAtomic); LI->setMetadata(LLVMContext::MD_nonnull, MDNode::get(ctx.builder.getContext(), None)); jl_aliasinfo_t aliasinfo_mem = jl_aliasinfo_t::fromTBAA(ctx, ctx.tbaa().tbaa_memoryown); aliasinfo_mem.decorateInst(LI); - addr = ctx.builder.CreateConstInBoundsGEP1_32(ctx.types().T_jlmemoryt, m, 1); + addr = ctx.builder.CreateConstInBoundsGEP1_32(ctx.types().T_jlgenericmemory, m, 1); Value *foreign = ctx.builder.CreateICmpNE(addr, emit_bitcast(ctx, decay_derived(ctx, LI), addr->getType())); return emit_guarded_test(ctx, foreign, t, [&] { LoadInst *owner = ctx.builder.CreateAlignedLoad(ctx.types().T_prjlvalue, emit_bitcast(ctx, addr, ctx.types().T_pprjlvalue), Align(sizeof(void*))); @@ -3063,10 +3063,6 @@ static Value *emit_memorytowner(jl_codectx_t &ctx, Value *t) return ctx.builder.CreateSelect(ctx.builder.CreateIsNull(owner), t, owner); }); } -static Value *emit_memorytowner(jl_codectx_t &ctx, const jl_cgval_t &tinfo) -{ - return emit_memorytowner(ctx, boxed(ctx, tinfo)); -} static Value *emit_arrayowner(jl_codectx_t &ctx, const jl_cgval_t &tinfo) { Value *addr = decay_derived(ctx, boxed(ctx, tinfo)); @@ -3077,7 +3073,7 @@ static Value *emit_arrayowner(jl_codectx_t &ctx, const jl_cgval_t &tinfo) // TODO: mark dereferenceable<16> jl_aliasinfo_t aliasinfo_mem = jl_aliasinfo_t::fromTBAA(ctx, ctx.tbaa().tbaa_arrayptr); aliasinfo_mem.decorateInst(LI_mem); - return emit_memorytowner(ctx, LI_mem); + return emit_genericmemoryowner(ctx, LI_mem); } static Value *emit_arrayndims(jl_codectx_t &ctx, const jl_cgval_t &tinfo) @@ -3136,37 +3132,6 @@ static Value *emit_arraysize_for_unsafe_dim(jl_codectx_t &ctx, return dim > nd ? ConstantInt::get(ctx.types().T_size, 1) : emit_arraysize(ctx, tinfo, dim); } -static Value *emit_memoryt_idx0( - jl_codectx_t &ctx, const jl_cgval_t &mem, jl_cgval_t idx, jl_value_t *inbounds) -{ - ++EmittedArrayNdIndex; - emit_typecheck(ctx, idx, (jl_value_t*)jl_long_type, "memoryref"); - idx = update_julia_type(ctx, idx, (jl_value_t*)jl_long_type); - if (idx.typ == jl_bottom_type) - return nullptr; - Value *i = emit_unbox(ctx, ctx.types().T_size, idx, (jl_value_t*)jl_long_type); - Value *idx0 = ctx.builder.CreateSub(i, ConstantInt::get(ctx.types().T_size, 1)); - bool bc = bounds_check_enabled(ctx, inbounds); - if (bc) { - BasicBlock *failBB, *endBB; - failBB = BasicBlock::Create(ctx.builder.getContext(), "oob"); - endBB = BasicBlock::Create(ctx.builder.getContext(), "idxend"); - Value *m = boxed(ctx, mem); - Value *mlen = emit_memorytlen(ctx, m, mem.typ); - ctx.builder.CreateCondBr(ctx.builder.CreateICmpULT(idx0, mlen), endBB, failBB); - - ctx.f->getBasicBlockList().push_back(failBB); - ctx.builder.SetInsertPoint(failBB); - ctx.builder.CreateCall(prepare_call(jlboundserror_func), - { mark_callee_rooted(ctx, m), i }); - ctx.builder.CreateUnreachable(); - - ctx.f->getBasicBlockList().push_back(endBB); - ctx.builder.SetInsertPoint(endBB); - } - return idx0; -} - // `nd == -1` means the dimension is unknown. static Value *emit_array_nd_index( jl_codectx_t &ctx, const jl_cgval_t &ainfo, ssize_t nd, @@ -4345,7 +4310,7 @@ static jl_cgval_t _emit_memoryref(jl_codectx_t &ctx, Value *mem, Value *data, bo static jl_cgval_t _emit_memoryref(jl_codectx_t &ctx, const jl_cgval_t &mem, bool isboxed, bool isunion, bool isghost, jl_value_t *typ) { - Value *data = (!isboxed && isunion) || isghost ? ConstantInt::get(ctx.types().T_size, 0) : emit_memorytptr(ctx, mem, isboxed, isunion, isghost, 0); + Value *data = (!isboxed && isunion) || isghost ? ConstantInt::get(ctx.types().T_size, 0) : emit_genericmemoryptr(ctx, mem, isboxed, isunion, isghost, 0); return _emit_memoryref(ctx, boxed(ctx, mem), data, isboxed, isunion, isghost, typ); } @@ -4376,7 +4341,7 @@ static jl_cgval_t emit_memoryref(jl_codectx_t &ctx, const jl_cgval_t &ref, jl_cg Value *mem = CreateSimplifiedExtractValue(ctx, V, 1); Value *i = emit_unbox(ctx, ctx.types().T_size, idx, (jl_value_t*)jl_long_type); Value *offset = ctx.builder.CreateSub(i, ConstantInt::get(ctx.types().T_size, 1)); - Value *elsz = emit_memorytelsize(ctx, mem, ref.typ); + Value *elsz = emit_genericmemoryelsize(ctx, mem, ref.typ); bool bc = bounds_check_enabled(ctx, inbounds); #if 1 Value *ovflw = nullptr; @@ -4388,7 +4353,7 @@ static jl_cgval_t emit_memoryref(jl_codectx_t &ctx, const jl_cgval_t &ref, jl_cg BasicBlock *failBB, *endBB; failBB = BasicBlock::Create(ctx.builder.getContext(), "oob"); endBB = BasicBlock::Create(ctx.builder.getContext(), "idxend"); - Value *mlen = emit_memorytlen(ctx, mem, ref.typ); + Value *mlen = emit_genericmemorylen(ctx, mem, ref.typ); Value *inbound = ctx.builder.CreateICmpULT(newdata, mlen); ctx.builder.CreateCondBr(inbound, endBB, failBB); ctx.f->getBasicBlockList().push_back(failBB); @@ -4415,7 +4380,7 @@ static jl_cgval_t emit_memoryref(jl_codectx_t &ctx, const jl_cgval_t &ref, jl_cg // n.b. we could boundscheck that -len<=offset<=len instead of using smul.ovflw, // since we know that len*elsz does not overflow, // and we can further rearrange that as ovflw = !( offset+len < len+len ) as unsigned math - Value *mlen = emit_memorytlen(ctx, mem, ref.typ); + Value *mlen = emit_genericmemorylen(ctx, mem, ref.typ); ovflw = ctx.builder.CreateICmpUGE(ctx.builder.CreateAdd(offset, mlen), ctx.builder.CreateNUWAdd(mlen, mlen)); } #endif @@ -4427,8 +4392,8 @@ static jl_cgval_t emit_memoryref(jl_codectx_t &ctx, const jl_cgval_t &ref, jl_cg BasicBlock *failBB, *endBB; failBB = BasicBlock::Create(ctx.builder.getContext(), "oob"); endBB = BasicBlock::Create(ctx.builder.getContext(), "idxend"); - Value *mlen = emit_memorytlen(ctx, mem, ref.typ); - Value *mptr = emit_memorytptr(ctx, mem, isboxed, isunion, isghost, 0); + Value *mlen = emit_genericmemorylen(ctx, mem, ref.typ); + Value *mptr = emit_genericmemoryptr(ctx, mem, isboxed, isunion, isghost, 0); mptr = emit_bitcast(ctx, mptr, newdata->getType()); #if 0 Value *mend = emit_bitcast(ctx, mptr, getInt8PtrTy(ctx.builder.getContext())); diff --git a/src/clangsa/GCChecker.cpp b/src/clangsa/GCChecker.cpp index 4b2e7609ab63d7..8aa0ef009f4ebd 100644 --- a/src/clangsa/GCChecker.cpp +++ b/src/clangsa/GCChecker.cpp @@ -806,8 +806,8 @@ bool GCChecker::isGCTrackedType(QualType QT) { Name.endswith_lower("jl_expr_t") || Name.endswith_lower("jl_code_info_t") || Name.endswith_lower("jl_array_t") || - Name.endswith_lower("jl_memory_t") || - //Name.endswith_lower("jl_memoryref_t") || + Name.endswith_lower("jl_genericmemory_t") || + //Name.endswith_lower("jl_genericmemoryref_t") || Name.endswith_lower("jl_method_t") || Name.endswith_lower("jl_method_instance_t") || Name.endswith_lower("jl_tupletype_t") || diff --git a/src/codegen.cpp b/src/codegen.cpp index 4d19749e581253..ffcb6806da88c5 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -288,7 +288,7 @@ struct jl_typecache_t { Type *T_prjlvalue; Type *T_ppjlvalue; Type *T_pprjlvalue; - StructType *T_jlmemoryt; + StructType *T_jlgenericmemory; StructType *T_jlarray; Type *T_pjlarray; FunctionType *T_jlfunc; @@ -305,7 +305,7 @@ struct jl_typecache_t { jl_typecache_t() : T_jlvalue(nullptr), T_pjlvalue(nullptr), T_prjlvalue(nullptr), T_ppjlvalue(nullptr), T_pprjlvalue(nullptr), - T_jlmemoryt(nullptr), T_jlarray(nullptr), T_pjlarray(nullptr), + T_jlgenericmemory(nullptr), T_jlarray(nullptr), T_pjlarray(nullptr), T_jlfunc(nullptr), T_jlfuncparams(nullptr), T_sigatomic(nullptr), T_ppint8(nullptr), initialized(false) {} @@ -331,9 +331,9 @@ struct jl_typecache_t { T_jlfuncparams = JuliaType::get_jlfuncparams_ty(context); assert(T_jlfuncparams != NULL); - T_jlmemoryt = StructType::get(context, { T_size, T_pprjlvalue /* [, real-owner] */ }); + T_jlgenericmemory = StructType::get(context, { T_size, T_pprjlvalue /* [, real-owner] */ }); Type *vaelts[] = { PointerType::get(getInt8Ty(context), AddressSpace::Loaded), - PointerType::get(T_jlmemoryt, AddressSpace::Tracked), + PointerType::get(T_jlgenericmemory, AddressSpace::Tracked), // dimsize[ndims] }; T_jlarray = StructType::get(context, makeArrayRef(vaelts)); @@ -351,19 +351,19 @@ struct jl_tbaacache_t { MDNode *tbaa_unionselbyte; // a selector byte in isbits Union struct fields MDNode *tbaa_data; // Any user data that `pointerset/ref` are allowed to alias MDNode *tbaa_binding; // jl_binding_t::value - MDNode *tbaa_value; // jl_value_t, that is not jl_array_t or jl_memory_t + MDNode *tbaa_value; // jl_value_t, that is not jl_array_t or jl_genericmemory_t MDNode *tbaa_mutab; // mutable type MDNode *tbaa_datatype; // datatype MDNode *tbaa_immut; // immutable type MDNode *tbaa_ptrarraybuf; // Data in an array of boxed values MDNode *tbaa_arraybuf; // Data in an array of POD - MDNode *tbaa_array; // jl_array_t or jl_memory_t + MDNode *tbaa_array; // jl_array_t or jl_genericmemory_t MDNode *tbaa_arrayptr; // The pointer inside a jl_array_t (to memoryref) MDNode *tbaa_arraysize; // A size in a jl_array_t - MDNode *tbaa_arrayselbyte; // a selector byte in a isbits Union jl_memory_t - MDNode *tbaa_memoryptr; // The pointer inside a jl_memory_t - MDNode *tbaa_memorylen; // The length in a jl_memory_t - MDNode *tbaa_memoryown; // The owner in a foreign jl_memory_t + MDNode *tbaa_arrayselbyte; // a selector byte in a isbits Union jl_genericmemory_t + MDNode *tbaa_memoryptr; // The pointer inside a jl_genericmemory_t + MDNode *tbaa_memorylen; // The length in a jl_genericmemory_t + MDNode *tbaa_memoryown; // The owner in a foreign jl_genericmemory_t MDNode *tbaa_const; // Memory that is immutable by the time LLVM can see it bool initialized; @@ -1390,7 +1390,7 @@ static MDNode *best_tbaa(jl_tbaacache_t &tbaa_cache, jl_value_t *jt) { return tbaa_cache.tbaa_value; if (jl_is_abstracttype(jt)) return tbaa_cache.tbaa_value; - if (jl_is_memory_type(jt) || jl_is_array_type(jt)) + if (jl_is_genericmemory_type(jt) || jl_is_array_type(jt)) return tbaa_cache.tbaa_array; // If we're here, we know all subtypes are (im)mutable, even if we // don't know what the exact type is @@ -3710,11 +3710,11 @@ static bool emit_builtin_call(jl_codectx_t &ctx, jl_cgval_t *ret, jl_value_t *f, else if (f == jl_builtin_memoryref && nargs == 1) { const jl_cgval_t &mem = argv[1]; jl_value_t *mty_dt = jl_unwrap_unionall(mem.typ); - if (jl_is_memory_type(mty_dt) && jl_is_concrete_type(mty_dt)) { + if (jl_is_genericmemory_type(mty_dt) && jl_is_concrete_type(mty_dt)) { jl_value_t *isatomic = jl_tparam0(mty_dt); jl_value_t *ety = jl_tparam1(mty_dt); const jl_datatype_layout_t *layout = ((jl_datatype_t*)mty_dt)->layout; - jl_value_t *typ = jl_apply_type2((jl_value_t*)jl_memoryref_type, isatomic, ety); + jl_value_t *typ = jl_apply_type2((jl_value_t*)jl_genericmemoryref_type, isatomic, ety); *ret = _emit_memoryref(ctx, mem, layout->arrayelem_isboxed, layout->arrayelem_isunion, layout->size == 0, typ); return true; } @@ -3723,7 +3723,7 @@ static bool emit_builtin_call(jl_codectx_t &ctx, jl_cgval_t *ret, jl_value_t *f, else if (f == jl_builtin_memoryref && (nargs == 2 || nargs == 3)) { const jl_cgval_t &ref = argv[1]; jl_value_t *mty_dt = jl_unwrap_unionall(ref.typ); - if (jl_is_memoryref_type(mty_dt) && jl_is_concrete_type(mty_dt)) { + if (jl_is_genericmemoryref_type(mty_dt) && jl_is_concrete_type(mty_dt)) { mty_dt = jl_field_type_concrete((jl_datatype_t*)mty_dt, 1); const jl_datatype_layout_t *layout = ((jl_datatype_t*)mty_dt)->layout; jl_value_t *boundscheck = nargs == 3 ? argv[3].constant : nullptr; @@ -3737,7 +3737,7 @@ static bool emit_builtin_call(jl_codectx_t &ctx, jl_cgval_t *ret, jl_value_t *f, else if (f == jl_builtin_memoryrefget && nargs == 3) { const jl_cgval_t &ref = argv[1]; jl_value_t *mty_dt = jl_unwrap_unionall(ref.typ); - if (jl_is_memoryref_type(mty_dt) && jl_is_concrete_type(mty_dt)) { + if (jl_is_genericmemoryref_type(mty_dt) && jl_is_concrete_type(mty_dt)) { jl_value_t *isatomic = jl_tparam0(mty_dt); (void)isatomic; // TODO jl_value_t *ety = jl_tparam1(mty_dt); mty_dt = jl_field_type_concrete((jl_datatype_t*)mty_dt, 1); @@ -3752,7 +3752,7 @@ static bool emit_builtin_call(jl_codectx_t &ctx, jl_cgval_t *ret, jl_value_t *f, size_t elsz = layout->size; size_t al = layout->alignment; Value *mem = emit_memoryref_mem(ctx, ref, isboxed, isunion, elsz == 0); - Value *mlen = emit_memorytlen(ctx, mem, ref.typ); + Value *mlen = emit_genericmemorylen(ctx, mem, ref.typ); if (bounds_check_enabled(ctx, boundscheck)) { BasicBlock *failBB, *endBB; failBB = BasicBlock::Create(ctx.builder.getContext(), "oob"); @@ -3773,7 +3773,7 @@ static bool emit_builtin_call(jl_codectx_t &ctx, jl_cgval_t *ret, jl_value_t *f, Value *V = emit_memoryref_FCA(ctx, ref, isboxed, isunion, elsz == 0); Value *idx0 = CreateSimplifiedExtractValue(ctx, V, 0); Value *mem = CreateSimplifiedExtractValue(ctx, V, 1); - Value *data = emit_memorytptr(ctx, mem, isboxed, isunion, elsz == 0, AddressSpace::Loaded); + Value *data = emit_genericmemoryptr(ctx, mem, isboxed, isunion, elsz == 0, AddressSpace::Loaded); Value *ptindex; if (elsz == 0) { ptindex = data; @@ -3810,7 +3810,7 @@ static bool emit_builtin_call(jl_codectx_t &ctx, jl_cgval_t *ret, jl_value_t *f, const jl_cgval_t &ref = argv[1]; jl_cgval_t val = argv[2]; jl_value_t *mty_dt = jl_unwrap_unionall(ref.typ); - if (jl_is_memoryref_type(mty_dt) && jl_is_concrete_type(mty_dt)) { + if (jl_is_genericmemoryref_type(mty_dt) && jl_is_concrete_type(mty_dt)) { jl_value_t *isatomic = jl_tparam0(mty_dt); (void)isatomic; // TODO jl_value_t *ety = jl_tparam1(mty_dt); mty_dt = jl_field_type_concrete((jl_datatype_t*)mty_dt, 1); @@ -3825,7 +3825,7 @@ static bool emit_builtin_call(jl_codectx_t &ctx, jl_cgval_t *ret, jl_value_t *f, size_t elsz = layout->size; size_t al = layout->alignment; Value *mem = emit_memoryref_mem(ctx, ref, isboxed, isunion, elsz == 0); - Value *mlen = emit_memorytlen(ctx, mem, ref.typ); + Value *mlen = emit_genericmemorylen(ctx, mem, ref.typ); if (bounds_check_enabled(ctx, boundscheck)) { BasicBlock *failBB, *endBB; failBB = BasicBlock::Create(ctx.builder.getContext(), "oob"); @@ -3852,12 +3852,12 @@ static bool emit_builtin_call(jl_codectx_t &ctx, jl_cgval_t *ret, jl_value_t *f, Value *V = emit_memoryref_FCA(ctx, ref, isboxed, isunion, elsz == 0); Value *data_owner = NULL; // owner object against which the write barrier must check if (isboxed || layout->first_ptr >= 0) { // if elements are just bits, don't need a write barrier - data_owner = emit_memorytowner(ctx, CreateSimplifiedExtractValue(ctx, V, 1)); + data_owner = emit_genericmemoryowner(ctx, CreateSimplifiedExtractValue(ctx, V, 1)); } if (isunion) { Value *idx0 = CreateSimplifiedExtractValue(ctx, V, 0); Value *mem = CreateSimplifiedExtractValue(ctx, V, 1); - Value *data = emit_memorytptr(ctx, mem, isboxed, isunion, elsz == 0, AddressSpace::Loaded); + Value *data = emit_genericmemoryptr(ctx, mem, isboxed, isunion, elsz == 0, AddressSpace::Loaded); Type *AT = ArrayType::get(IntegerType::get(ctx.builder.getContext(), 8 * al), (elsz + al - 1) / al); data = emit_bitcast(ctx, data, AT->getPointerTo()); // compute tindex from val @@ -3912,7 +3912,7 @@ static bool emit_builtin_call(jl_codectx_t &ctx, jl_cgval_t *ret, jl_value_t *f, else if (f == jl_builtin_memoryref_isassigned && nargs == 3) { const jl_cgval_t &ref = argv[1]; jl_value_t *mty_dt = jl_unwrap_unionall(ref.typ); - if (jl_is_memoryref_type(mty_dt) && jl_is_concrete_type(mty_dt)) { + if (jl_is_genericmemoryref_type(mty_dt) && jl_is_concrete_type(mty_dt)) { jl_value_t *isatomic = jl_tparam0(mty_dt); (void)isatomic; // TODO mty_dt = jl_field_type_concrete((jl_datatype_t*)mty_dt, 1); jl_value_t *order = argv[2].constant; @@ -3925,7 +3925,7 @@ static bool emit_builtin_call(jl_codectx_t &ctx, jl_cgval_t *ret, jl_value_t *f, bool isunion = layout->arrayelem_isunion; size_t elsz = layout->size; Value *mem = emit_memoryref_mem(ctx, ref, isboxed, isunion, elsz == 0); - Value *mlen = emit_memorytlen(ctx, mem, ref.typ); + Value *mlen = emit_genericmemorylen(ctx, mem, ref.typ); Value *oob = bounds_check_enabled(ctx, boundscheck) ? ctx.builder.CreateIsNull(mlen) : nullptr; if (isboxed || layout->first_ptr >= 0) { PHINode *result = nullptr; @@ -4272,10 +4272,10 @@ static bool emit_builtin_call(jl_codectx_t &ctx, jl_cgval_t *ret, jl_value_t *f, *ret = mark_julia_type(ctx, len, false, jl_long_type); return true; } - else if (jl_is_memory_type(sty)) { + else if (jl_is_genericmemory_type(sty)) { Value *v = boxed(ctx, obj); - auto len = emit_memorytlen(ctx, v, (jl_value_t*)sty); - auto elsize = emit_memorytelsize(ctx, v, obj.typ); + auto len = emit_genericmemorylen(ctx, v, (jl_value_t*)sty); + auto elsize = emit_genericmemoryelsize(ctx, v, obj.typ); *ret = mark_julia_type(ctx, ctx.builder.CreateMul(len, elsize), false, jl_long_type); return true; } diff --git a/src/common_symbols2.inc b/src/common_symbols2.inc index ad5940b5e7e758..3333f3915baf3b 100644 --- a/src/common_symbols2.inc +++ b/src/common_symbols2.inc @@ -158,7 +158,7 @@ jl_symbol("chklapackerror"), jl_symbol("count"), jl_symbol("jl_array_ptr"), jl_symbol("Float32"), -jl_symbol("memoryt.jl"), +jl_symbol("genericmemory.jl"), jl_symbol("print_to_string"), jl_symbol("rethrow"), jl_symbol("sort.jl"), @@ -207,7 +207,7 @@ jl_symbol("task.jl"), jl_symbol("UnionAll"), jl_symbol("memset"), jl_symbol("xor"), -jl_symbol("jl_alloc_memoryt"), +jl_symbol("jl_alloc_genericmemory"), jl_symbol("uplo"), jl_symbol("toInt32"), jl_symbol("Base"), diff --git a/src/datatype.c b/src/datatype.c index f19b5a47a204e2..87f54006cd37f8 100644 --- a/src/datatype.c +++ b/src/datatype.c @@ -49,7 +49,7 @@ JL_DLLEXPORT jl_methtable_t *jl_new_method_table(jl_sym_t *name, jl_module_t *mo mt->name = jl_demangle_typename(name); mt->module = module; jl_atomic_store_relaxed(&mt->defs, jl_nothing); - jl_atomic_store_relaxed(&mt->leafcache, (jl_memory_t*)jl_an_empty_memory_any); + jl_atomic_store_relaxed(&mt->leafcache, (jl_genericmemory_t*)jl_an_empty_memory_any); jl_atomic_store_relaxed(&mt->cache, jl_nothing); jl_atomic_store_relaxed(&mt->max_args, 0); mt->backedges = NULL; @@ -341,7 +341,7 @@ STATIC_INLINE void jl_maybe_allocate_singleton_instance(jl_datatype_t *st) JL_NO // return whether all concrete subtypes of this type have the same layout int jl_struct_try_layout(jl_datatype_t *dt) { - if (dt->layout || jl_is_memory_type(dt)) + if (dt->layout || jl_is_genericmemory_type(dt)) return 1; else if (!jl_has_fixed_layout(dt)) return 0; @@ -486,7 +486,7 @@ static int is_type_identityfree(jl_value_t *t) } // make a copy of the layout of st, but with nfields=0 -void jl_get_memoryt_layout(jl_datatype_t *st) +void jl_get_genericmemory_layout(jl_datatype_t *st) { jl_value_t *isatomic = jl_tparam0(st); (void)isatomic; // TODO jl_value_t *eltype = jl_tparam1(st); @@ -553,7 +553,7 @@ void jl_get_memoryt_layout(jl_datatype_t *st) //st->ismutationfree = 0; //st->isidentityfree = 0; - jl_memory_t *zeroinst = (jl_memory_t*)jl_gc_permobj(sizeof(jl_memory_t) + (elsz ? elsz : isunion), st); + jl_genericmemory_t *zeroinst = (jl_genericmemory_t*)jl_gc_permobj(sizeof(jl_genericmemory_t) + (elsz ? elsz : isunion), st); zeroinst->length = 0; zeroinst->data = (char*)(zeroinst + 1); memset(zeroinst->data, 0, elsz ? elsz : isunion); @@ -575,8 +575,8 @@ void jl_compute_field_offsets(jl_datatype_t *st) st->zeroinit = 0; st->has_concrete_subtype = 1; } - if (st->name == jl_memory_typename) { - jl_get_memoryt_layout(st); + if (st->name == jl_genericmemory_typename) { + jl_get_genericmemory_layout(st); return; } int isbitstype = st->isconcretetype && st->name->mayinlinealloc; diff --git a/src/gc.c b/src/gc.c index d0229d9a44b601..316dfbec1f85fd 100644 --- a/src/gc.c +++ b/src/gc.c @@ -1125,7 +1125,7 @@ static void sweep_big(jl_ptls_t ptls, int sweep_full) JL_NOTSAFEPOINT // tracking Memorys with malloc'd storage -void jl_gc_track_malloced_memoryt(jl_ptls_t ptls, jl_memory_t *m, int isaligned){ +void jl_gc_track_malloced_genericmemory(jl_ptls_t ptls, jl_genericmemory_t *m, int isaligned){ // This is **NOT** a GC safe point. mallocarray_t *ma; if (ptls->heap.mafreelist == NULL) { @@ -1209,7 +1209,7 @@ void jl_gc_reset_alloc_count(void) JL_NOTSAFEPOINT reset_thread_gc_counts(); } -size_t jl_memoryt_nbytes(jl_memory_t *m) JL_NOTSAFEPOINT +size_t jl_genericmemory_nbytes(jl_genericmemory_t *m) JL_NOTSAFEPOINT { const jl_datatype_layout_t *layout = ((jl_datatype_t*)jl_typetagof(m))->layout; size_t sz = layout->size * m->length; @@ -1222,17 +1222,17 @@ size_t jl_memoryt_nbytes(jl_memory_t *m) JL_NOTSAFEPOINT static void jl_gc_free_array(jl_value_t *v, int isaligned) JL_NOTSAFEPOINT { - assert(jl_is_memory(v)); - jl_memory_t *m = (jl_memory_t*)v; - assert(jl_memoryt_how(m) == 1 || jl_memoryt_how(m) == 2); + assert(jl_is_genericmemory(v)); + jl_genericmemory_t *m = (jl_genericmemory_t*)v; + assert(jl_genericmemory_how(m) == 1 || jl_genericmemory_how(m) == 2); char *d = (char*)m->data; if (isaligned) jl_free_aligned(d); else free(d); jl_atomic_store_relaxed(&gc_heap_stats.heap_size, - jl_atomic_load_relaxed(&gc_heap_stats.heap_size) - jl_memoryt_nbytes(m)); - gc_num.freed += jl_memoryt_nbytes(m); + jl_atomic_load_relaxed(&gc_heap_stats.heap_size) - jl_genericmemory_nbytes(m)); + gc_num.freed += jl_genericmemory_nbytes(m); gc_num.freecall++; gc_num.freecall++; } @@ -2557,16 +2557,16 @@ FORCE_INLINE void gc_mark_outrefs(jl_ptls_t ptls, jl_gc_markqueue_t *mq, void *_ gc_setmark(ptls, o, bits, dtsz); else if (foreign_alloc) objprofile_count(vt, bits == GC_OLD_MARKED, dtsz); - jl_memory_t *owner = a->ref.mem; + jl_genericmemory_t *owner = a->ref.mem; uintptr_t nptr = (1 << 2) | (bits & GC_OLD); gc_try_claim_and_push(mq, owner, &nptr); gc_heap_snapshot_record_internal_array_edge(new_obj, (jl_value_t*)owner); gc_mark_push_remset(ptls, new_obj, nptr); return; } - if (vt->name == jl_memory_typename) { - jl_memory_t *m = (jl_memory_t*)new_obj; - int pooled = 1; // The jl_memory_t itself is always pooled-size, even with data attached to it + if (vt->name == jl_genericmemory_typename) { + jl_genericmemory_t *m = (jl_genericmemory_t*)new_obj; + int pooled = 1; // The jl_genericmemory_t itself is always pooled-size, even with data attached to it if (update_meta) { if (pooled) gc_setmark_pool(ptls, o, bits); @@ -2574,17 +2574,17 @@ FORCE_INLINE void gc_mark_outrefs(jl_ptls_t ptls, jl_gc_markqueue_t *mq, void *_ gc_setmark_big(ptls, o, bits); } else if (foreign_alloc) { - objprofile_count(vt, bits == GC_OLD_MARKED, sizeof(jl_memory_t)); + objprofile_count(vt, bits == GC_OLD_MARKED, sizeof(jl_genericmemory_t)); } - int how = jl_memoryt_how(m); + int how = jl_genericmemory_how(m); if (how == 0 || how == 2) { - gc_heap_snapshot_record_hidden_edge(new_obj, m->data, jl_memoryt_nbytes(m), how == 0 ? 2 : 0); + gc_heap_snapshot_record_hidden_edge(new_obj, m->data, jl_genericmemory_nbytes(m), how == 0 ? 2 : 0); } else if (how == 1) { if (update_meta || foreign_alloc) { objprofile_count(jl_malloc_tag, bits == GC_OLD_MARKED, - jl_memoryt_nbytes(m)); - size_t nb = jl_memoryt_nbytes(m); + jl_genericmemory_nbytes(m)); + size_t nb = jl_genericmemory_nbytes(m); gc_heap_snapshot_record_hidden_edge(new_obj, m->data, nb, 0); if (bits == GC_OLD_MARKED) { ptls->gc_cache.perm_scanned_bytes += nb; @@ -2595,7 +2595,7 @@ FORCE_INLINE void gc_mark_outrefs(jl_ptls_t ptls, jl_gc_markqueue_t *mq, void *_ } } else if (how == 3) { - jl_value_t *owner = jl_memoryt_data_owner_field(m); + jl_value_t *owner = jl_genericmemory_data_owner_field(m); uintptr_t nptr = (1 << 2) | (bits & GC_OLD); gc_try_claim_and_push(mq, owner, &nptr); gc_heap_snapshot_record_internal_array_edge(new_obj, owner); diff --git a/src/gc.h b/src/gc.h index 8b7a45896960b3..9bb5edf75d6a0b 100644 --- a/src/gc.h +++ b/src/gc.h @@ -137,7 +137,7 @@ JL_EXTENSION typedef struct _bigval_t { // must be 64-byte aligned here, in 32 & 64 bit modes } bigval_t; -// data structure for tracking malloc'd arrays and memoryt. +// data structure for tracking malloc'd arrays and genericmemory. typedef struct _mallocarray_t { jl_value_t *a; diff --git a/src/memoryt.c b/src/genericmemory.c similarity index 71% rename from src/memoryt.c rename to src/genericmemory.c index d724cbd708c69c..77a596e80c4804 100644 --- a/src/memoryt.c +++ b/src/genericmemory.c @@ -16,7 +16,7 @@ extern "C" { #endif -static inline void memorytassign_safe(int hasptr, jl_value_t *parent, char *dst, const jl_value_t *src) JL_NOTSAFEPOINT +static inline void genericmemoryassign_safe(int hasptr, jl_value_t *parent, char *dst, const jl_value_t *src) JL_NOTSAFEPOINT { size_t nb = jl_datatype_size(jl_typeof(src)); // make sure to shrink-wrap this copy if (hasptr) { @@ -25,7 +25,7 @@ static inline void memorytassign_safe(int hasptr, jl_value_t *parent, char *dst, jl_gc_multi_wb(parent, src); } else { - // memoryt can assume more alignment than a field would normally have + // genericmemory can assume more alignment than a field would normally have switch (nb) { case 0: break; case 1: *(uint8_t*)dst = *(uint8_t*)src; break; @@ -40,8 +40,8 @@ static inline void memorytassign_safe(int hasptr, jl_value_t *parent, char *dst, } } -// memoryt constructors --------------------------------------------------------- -JL_DLLEXPORT char *jl_memoryt_typetagdata(jl_memory_t *m) JL_NOTSAFEPOINT +// genericmemory constructors --------------------------------------------------------- +JL_DLLEXPORT char *jl_genericmemory_typetagdata(jl_genericmemory_t *m) JL_NOTSAFEPOINT { const jl_datatype_layout_t *layout = ((jl_datatype_t*)jl_typetagof(m))->layout; assert(layout->arrayelem_isunion); @@ -56,13 +56,13 @@ typedef uint64_t wideint_t; #define MAXINTVAL (((size_t)-1)>>1) -static jl_memory_t *_new_memoryt_(jl_value_t *mtype, size_t nel, int8_t isunion, int8_t zeroinit, size_t elsz) +static jl_genericmemory_t *_new_genericmemory_(jl_value_t *mtype, size_t nel, int8_t isunion, int8_t zeroinit, size_t elsz) { jl_task_t *ct = jl_current_task; char *data; - jl_memory_t *m; + jl_genericmemory_t *m; if (nel == 0) // zero-sized allocation optimization - return (jl_memory_t*)((jl_datatype_t*)mtype)->instance; + return (jl_genericmemory_t*)((jl_datatype_t*)mtype)->instance; size_t tot = nel == 0 ? 1 : nel; // always reserve space for at least one element for extra safety (relevant for JL_ARRAY_IMPL_NUL) wideint_t prod = (wideint_t)tot * elsz; if (isunion) { @@ -71,21 +71,21 @@ static jl_memory_t *_new_memoryt_(jl_value_t *mtype, size_t nel, int8_t isunion, } if (tot >= MAXINTVAL || prod >= (wideint_t) MAXINTVAL) jl_exceptionf(jl_argumenterror_type, "invalid GenericMemory size"); - tot = (size_t)prod + sizeof(jl_memory_t); + tot = (size_t)prod + sizeof(jl_genericmemory_t); int pooled = tot <= GC_MAX_SZCLASS; if (!pooled) { data = (char*)jl_gc_managed_malloc(prod); - tot = sizeof(jl_memory_t) + sizeof(void*); + tot = sizeof(jl_genericmemory_t) + sizeof(void*); } - m = (jl_memory_t*)jl_gc_alloc(ct->ptls, tot, mtype); + m = (jl_genericmemory_t*)jl_gc_alloc(ct->ptls, tot, mtype); if (pooled) { data = (char*)(m + 1); } else { int isaligned = 1; // jl_gc_managed_malloc is always aligned - jl_gc_track_malloced_memoryt(ct->ptls, m, isaligned); - jl_memoryt_data_owner_field(m) = (jl_value_t*)m; + jl_gc_track_malloced_genericmemory(ct->ptls, m, isaligned); + jl_genericmemory_data_owner_field(m) = (jl_value_t*)m; } m->length = nel; m->data = data; @@ -95,10 +95,10 @@ static jl_memory_t *_new_memoryt_(jl_value_t *mtype, size_t nel, int8_t isunion, return m; } -JL_DLLEXPORT jl_memory_t *jl_alloc_memoryt(jl_value_t *mtype, size_t nel) +JL_DLLEXPORT jl_genericmemory_t *jl_alloc_genericmemory(jl_value_t *mtype, size_t nel) { assert(jl_is_datatype(mtype)); - jl_memory_t *m = (jl_memory_t*)((jl_datatype_t*)mtype)->instance; + jl_genericmemory_t *m = (jl_genericmemory_t*)((jl_datatype_t*)mtype)->instance; const jl_datatype_layout_t *layout = ((jl_datatype_t*)mtype)->layout; if (m == NULL) { if (jl_tparam0((jl_datatype_t*)mtype) != (jl_value_t*)jl_not_atomic_sym) @@ -107,7 +107,7 @@ JL_DLLEXPORT jl_memory_t *jl_alloc_memoryt(jl_value_t *mtype, size_t nel) jl_type_error_rt("GenericMemory", "element type", (jl_value_t*)jl_type_type, jl_tparam1(mtype)); abort(); } - assert(jl_tparam0((jl_datatype_t*)mtype) == jl_not_atomic_sym); + assert(jl_tparam0((jl_datatype_t*)mtype) == (jl_value_t*)jl_not_atomic_sym); assert(((jl_datatype_t*)mtype)->has_concrete_subtype && layout != NULL); if (nel == 0) // zero-sized allocation optimization fast path return m; @@ -118,27 +118,27 @@ JL_DLLEXPORT jl_memory_t *jl_alloc_memoryt(jl_value_t *mtype, size_t nel) int zi = ((jl_datatype_t*)mtype)->zeroinit; if (isboxed) elsz = sizeof(void*); - return _new_memoryt_(mtype, nel, isunion, zi, elsz); + return _new_genericmemory_(mtype, nel, isunion, zi, elsz); } -jl_memory_t *jl_new_memoryt_for_deserialization(jl_value_t *mtype, size_t nel, int isunion, int elsz) +jl_genericmemory_t *jl_new_genericmemory_for_deserialization(jl_value_t *mtype, size_t nel, int isunion, int elsz) { - return _new_memoryt_(mtype, nel, isunion, 0, (size_t)elsz); + return _new_genericmemory_(mtype, nel, isunion, 0, (size_t)elsz); } -JL_DLLEXPORT jl_memory_t *jl_string_to_memoryt(jl_value_t *str) +JL_DLLEXPORT jl_genericmemory_t *jl_string_to_genericmemory(jl_value_t *str) { jl_task_t *ct = jl_current_task; - int tsz = sizeof(jl_memory_t) + sizeof(void*); - jl_memory_t *m = (jl_memory_t*)jl_gc_alloc(ct->ptls, tsz, jl_memory_uint8_type); + int tsz = sizeof(jl_genericmemory_t) + sizeof(void*); + jl_genericmemory_t *m = (jl_genericmemory_t*)jl_gc_alloc(ct->ptls, tsz, jl_memory_uint8_type); m->length = jl_string_len(str); m->data = jl_string_data(str); - jl_memoryt_data_owner_field(m) = str; + jl_genericmemory_data_owner_field(m) = str; return m; } // own_buffer != 0 iff GC should call free() on this pointer eventually -JL_DLLEXPORT jl_memory_t *jl_ptr_to_memoryt(jl_value_t *mtype, void *data, +JL_DLLEXPORT jl_genericmemory_t *jl_ptr_to_genericmemory(jl_value_t *mtype, void *data, size_t nel, int own_buffer) { jl_task_t *ct = jl_current_task; @@ -156,7 +156,7 @@ JL_DLLEXPORT jl_memory_t *jl_ptr_to_memoryt(jl_value_t *mtype, void *data, int zi = ((jl_datatype_t*)mtype)->zeroinit; if (isboxed) elsz = sizeof(void*); - jl_memory_t *m = _new_memoryt_(mtype, nel, isunion, zi, elsz); + jl_genericmemory_t *m = _new_genericmemory_(mtype, nel, isunion, zi, elsz); if (isunion) jl_exceptionf(jl_argumenterror_type, @@ -165,32 +165,32 @@ JL_DLLEXPORT jl_memory_t *jl_ptr_to_memoryt(jl_value_t *mtype, void *data, jl_exceptionf(jl_argumenterror_type, "unsafe_wrap: pointer %p is not properly aligned to %u bytes", data, align); - int tsz = sizeof(jl_memory_t) + sizeof(void*); - m = (jl_memory_t*)jl_gc_alloc(ct->ptls, tsz, mtype); + int tsz = sizeof(jl_genericmemory_t) + sizeof(void*); + m = (jl_genericmemory_t*)jl_gc_alloc(ct->ptls, tsz, mtype); m->data = data; m->length = nel; - jl_memoryt_data_owner_field(m) = NULL; + jl_genericmemory_data_owner_field(m) = NULL; int isaligned = 0; // TODO: allow passing memalign'd buffers if (own_buffer) { - jl_gc_track_malloced_memoryt(ct->ptls, m, isaligned); + jl_gc_track_malloced_genericmemory(ct->ptls, m, isaligned); jl_gc_count_allocd(nel*elsz + (elsz == 1 ? 1 : 0)); } return m; } -JL_DLLEXPORT jl_memory_t *jl_new_memoryt(jl_value_t *mtype, jl_value_t *nel) +JL_DLLEXPORT jl_genericmemory_t *jl_new_genericmemory(jl_value_t *mtype, jl_value_t *nel) { - return jl_alloc_memoryt(mtype, jl_unbox_long(nel)); + return jl_alloc_genericmemory(mtype, jl_unbox_long(nel)); } -JL_DLLEXPORT jl_memory_t *jl_pchar_to_memoryt(const char *str, size_t len) +JL_DLLEXPORT jl_genericmemory_t *jl_pchar_to_genericmemory(const char *str, size_t len) { - jl_memory_t *m = jl_alloc_memoryt(jl_memory_uint8_type, len); + jl_genericmemory_t *m = jl_alloc_genericmemory(jl_memory_uint8_type, len); memcpy(m->data, str, len); return m; } -JL_DLLEXPORT jl_value_t *jl_memoryt_to_string(jl_memory_t *m, size_t len) +JL_DLLEXPORT jl_value_t *jl_genericmemory_to_string(jl_genericmemory_t *m, size_t len) { assert(len <= m->length); if (len == 0) { @@ -199,12 +199,12 @@ JL_DLLEXPORT jl_value_t *jl_memoryt_to_string(jl_memory_t *m, size_t len) // string also created the same way, where `m = StringVector(_)`. return jl_an_empty_string; } - int how = jl_memoryt_how(m); + int how = jl_genericmemory_how(m); size_t mlength = m->length; m->length = 0; if (how != 0) { - jl_value_t *o = jl_memoryt_data_owner_field(m); - jl_memoryt_data_owner_field(m) = NULL; + jl_value_t *o = jl_genericmemory_data_owner_field(m); + jl_genericmemory_data_owner_field(m) = NULL; if (how == 3 && ((mlength + sizeof(void*) + 1 <= GC_MAX_SZCLASS) == (len + sizeof(void*) + 1 <= GC_MAX_SZCLASS))) { if (jl_string_data(o)[len] != '\0') @@ -221,12 +221,12 @@ JL_DLLEXPORT jl_value_t *jl_memoryt_to_string(jl_memory_t *m, size_t len) return jl_pchar_to_string((const char*)m->data, len); } -JL_DLLEXPORT jl_memory_t *jl_alloc_memory_any(size_t n) +JL_DLLEXPORT jl_genericmemory_t *jl_alloc_memory_any(size_t n) { - return jl_alloc_memoryt(jl_memory_any_type, n); + return jl_alloc_genericmemory(jl_memory_any_type, n); } -JL_DLLEXPORT jl_memory_t *jl_memoryt_slice(jl_memory_t *mem, size_t offset, size_t len) +JL_DLLEXPORT jl_genericmemory_t *jl_genericmemory_slice(jl_genericmemory_t *mem, size_t offset, size_t len) { jl_datatype_t *dt = (jl_datatype_t*)jl_typetagof(mem); const jl_datatype_layout_t *layout = dt->layout; @@ -235,16 +235,16 @@ JL_DLLEXPORT jl_memory_t *jl_memoryt_slice(jl_memory_t *mem, size_t offset, size if (layout->arrayelem_isunion && !(offset == 0 && mem->length == len)) jl_exceptionf(jl_argumenterror_type, "invalid GenericMemory slice"); jl_task_t *ct = jl_current_task; - jl_memory_t *newmem = (jl_memory_t*)jl_gc_alloc(ct->ptls, sizeof(jl_memory_t) + sizeof(void*), dt); + jl_genericmemory_t *newmem = (jl_genericmemory_t*)jl_gc_alloc(ct->ptls, sizeof(jl_genericmemory_t) + sizeof(void*), dt); newmem->length = len; newmem->data = (void*)((char*)mem->data + offset * layout->size); - jl_memoryt_data_owner_field(newmem) = jl_memoryt_owner(mem); + jl_genericmemory_data_owner_field(newmem) = jl_genericmemory_owner(mem); return newmem; } -// memoryt primitives ----------------------------------------------------------- +// genericmemory primitives ----------------------------------------------------------- -JL_DLLEXPORT jl_value_t *jl_ptrmemref(jl_memory_t *m JL_PROPAGATES_ROOT, size_t i) JL_NOTSAFEPOINT +JL_DLLEXPORT jl_value_t *jl_ptrmemref(jl_genericmemory_t *m JL_PROPAGATES_ROOT, size_t i) JL_NOTSAFEPOINT { assert(i < m->length); assert(((jl_datatype_t*)jl_typetagof(m))->layout->arrayelem_isboxed); @@ -254,7 +254,7 @@ JL_DLLEXPORT jl_value_t *jl_ptrmemref(jl_memory_t *m JL_PROPAGATES_ROOT, size_t return elt; } -JL_DLLEXPORT jl_value_t *jl_memorytref(jl_memory_t *m, size_t i) +JL_DLLEXPORT jl_value_t *jl_genericmemoryref(jl_genericmemory_t *m, size_t i) { const jl_datatype_layout_t *layout = ((jl_datatype_t*)jl_typetagof(m))->layout; if (layout->arrayelem_isboxed) @@ -264,7 +264,7 @@ JL_DLLEXPORT jl_value_t *jl_memorytref(jl_memory_t *m, size_t i) jl_value_t *eltype = jl_tparam1(jl_typetagof(m)); if (jl_is_uniontype(eltype)) { // isbits union selector bytes are always stored directly after the last memory element - uint8_t sel = jl_memoryt_typetagdata(m)[i]; + uint8_t sel = jl_genericmemory_typetagdata(m)[i]; eltype = jl_nth_union_component(eltype, sel); if (jl_is_datatype_singleton((jl_datatype_t*)eltype)) return ((jl_datatype_t*)eltype)->instance; @@ -275,7 +275,7 @@ JL_DLLEXPORT jl_value_t *jl_memorytref(jl_memory_t *m, size_t i) return r; } -JL_DLLEXPORT int jl_memoryt_isassigned(jl_memory_t *m, size_t i) +JL_DLLEXPORT int jl_genericmemory_isassigned(jl_genericmemory_t *m, size_t i) { const jl_datatype_layout_t *layout = ((jl_datatype_t*)jl_typetagof(m))->layout; if (layout->arrayelem_isboxed) { @@ -288,7 +288,7 @@ JL_DLLEXPORT int jl_memoryt_isassigned(jl_memory_t *m, size_t i) return 1; } -JL_DLLEXPORT void jl_memorytset(jl_memory_t *m JL_ROOTING_ARGUMENT, jl_value_t *rhs JL_ROOTED_ARGUMENT JL_MAYBE_UNROOTED, size_t i) +JL_DLLEXPORT void jl_genericmemoryset(jl_genericmemory_t *m JL_ROOTING_ARGUMENT, jl_value_t *rhs JL_ROOTED_ARGUMENT JL_MAYBE_UNROOTED, size_t i) { assert(i < m->length); jl_value_t *isatomic = jl_tparam0(jl_typetagof(m)); (void)isatomic; // TODO @@ -296,21 +296,21 @@ JL_DLLEXPORT void jl_memorytset(jl_memory_t *m JL_ROOTING_ARGUMENT, jl_value_t * if (eltype != (jl_value_t*)jl_any_type && !jl_typeis(rhs, eltype)) { JL_GC_PUSH1(&rhs); if (!jl_isa(rhs, eltype)) - jl_type_error("memorytset", eltype, rhs); + jl_type_error("genericmemoryset", eltype, rhs); JL_GC_POP(); } const jl_datatype_layout_t *layout = ((jl_datatype_t*)jl_typetagof(m))->layout; if (layout->arrayelem_isboxed) { jl_atomic_store_release(((_Atomic(jl_value_t*)*)m->data) + i, rhs); - jl_gc_wb(jl_memoryt_owner(m), rhs); + jl_gc_wb(jl_genericmemory_owner(m), rhs); } else { int hasptr; if (jl_is_uniontype(eltype)) { - uint8_t *psel = &((uint8_t*)jl_memoryt_typetagdata(m))[i]; + uint8_t *psel = &((uint8_t*)jl_genericmemory_typetagdata(m))[i]; unsigned nth = 0; if (!jl_find_union_component(eltype, jl_typeof(rhs), &nth)) - assert(0 && "invalid memorytset to isbits union"); + assert(0 && "invalid genericmemoryset to isbits union"); *psel = nth; if (jl_is_datatype_singleton((jl_datatype_t*)jl_typeof(rhs))) return; @@ -319,11 +319,11 @@ JL_DLLEXPORT void jl_memorytset(jl_memory_t *m JL_ROOTING_ARGUMENT, jl_value_t * else { hasptr = layout->first_ptr >= 0; } - memorytassign_safe(hasptr, jl_memoryt_owner(m), &((char*)m->data)[i * layout->size], rhs); + genericmemoryassign_safe(hasptr, jl_genericmemory_owner(m), &((char*)m->data)[i * layout->size], rhs); } } -JL_DLLEXPORT void jl_memorytunset(jl_memory_t *m, size_t i) +JL_DLLEXPORT void jl_genericmemoryunset(jl_genericmemory_t *m, size_t i) { if (i >= m->length) jl_bounds_error_int((jl_value_t*)m, i + 1); @@ -337,24 +337,24 @@ JL_DLLEXPORT void jl_memorytunset(jl_memory_t *m, size_t i) } } -JL_DLLEXPORT jl_memory_t *jl_memoryt_copy(jl_memory_t *m) +JL_DLLEXPORT jl_genericmemory_t *jl_genericmemory_copy(jl_genericmemory_t *m) { jl_value_t *mtype = (jl_value_t*)jl_typetagof(m); const jl_datatype_layout_t *layout = ((jl_datatype_t*)mtype)->layout; size_t elsz = layout->size; size_t len = m->length; int isunion = layout->arrayelem_isunion; - jl_memory_t *new_mem = _new_memoryt_(mtype, len, isunion, 0, elsz); + jl_genericmemory_t *new_mem = _new_genericmemory_(mtype, len, isunion, 0, elsz); memcpy(new_mem->data, m->data, len * elsz); // ensure isbits union memorys copy their selector bytes correctly if (isunion) - memcpy(jl_memoryt_typetagdata(new_mem), jl_memoryt_typetagdata(m), len); + memcpy(jl_genericmemory_typetagdata(new_mem), jl_genericmemory_typetagdata(m), len); return new_mem; } // Copy element by element until we hit a young object, at which point // we can finish by using `memmove`. -static NOINLINE ssize_t jl_memoryt_ptr_copy_forward(jl_value_t *owner, +static NOINLINE ssize_t jl_genericmemory_ptr_copy_forward(jl_value_t *owner, void **src_p, void **dest_p, ssize_t n) JL_NOTSAFEPOINT { @@ -372,7 +372,7 @@ static NOINLINE ssize_t jl_memoryt_ptr_copy_forward(jl_value_t *owner, return n; } -static NOINLINE ssize_t jl_memoryt_ptr_copy_backward(jl_value_t *owner, +static NOINLINE ssize_t jl_genericmemory_ptr_copy_backward(jl_value_t *owner, void **src_p, void **dest_p, ssize_t n) JL_NOTSAFEPOINT { @@ -391,25 +391,25 @@ static NOINLINE ssize_t jl_memoryt_ptr_copy_backward(jl_value_t *owner, } // Unsafe, assume inbounds and that dest and src have the same eltype -JL_DLLEXPORT void jl_memoryt_ptr_copy(jl_memory_t *dest, void **dest_p, - jl_memory_t *src, void **src_p, ssize_t n) JL_NOTSAFEPOINT +JL_DLLEXPORT void jl_genericmemory_ptr_copy(jl_genericmemory_t *dest, void **dest_p, + jl_genericmemory_t *src, void **src_p, ssize_t n) JL_NOTSAFEPOINT { assert(((jl_datatype_t*)jl_typetagof(src))->layout->arrayelem_isboxed && ((jl_datatype_t*)jl_typetagof(dest))->layout->arrayelem_isboxed); - jl_value_t *owner = jl_memoryt_owner(dest); + jl_value_t *owner = jl_genericmemory_owner(dest); // Destination is old and doesn't refer to any young object if (__unlikely(jl_astaggedvalue(owner)->bits.gc == GC_OLD_MARKED)) { - jl_value_t *src_owner = jl_memoryt_owner(src); + jl_value_t *src_owner = jl_genericmemory_owner(src); // Source is young or being promoted or might refer to young objects // (i.e. source is not an old object that doesn't have wb triggered) if (jl_astaggedvalue(src_owner)->bits.gc != GC_OLD_MARKED) { ssize_t done; if (dest_p < src_p || dest_p > src_p + n) { - done = jl_memoryt_ptr_copy_forward(owner, src_p, dest_p, n); + done = jl_genericmemory_ptr_copy_forward(owner, src_p, dest_p, n); dest_p += done; src_p += done; } else { - done = jl_memoryt_ptr_copy_backward(owner, src_p, dest_p, n); + done = jl_genericmemory_ptr_copy_backward(owner, src_p, dest_p, n); } n -= done; } @@ -417,19 +417,19 @@ JL_DLLEXPORT void jl_memoryt_ptr_copy(jl_memory_t *dest, void **dest_p, memmove_refs(dest_p, src_p, n); } -JL_DLLEXPORT jl_value_t *(jl_memoryt_data_owner)(jl_memory_t *m) JL_NOTSAFEPOINT +JL_DLLEXPORT jl_value_t *(jl_genericmemory_data_owner)(jl_genericmemory_t *m) JL_NOTSAFEPOINT { - return jl_memoryt_data_owner_field(m); + return jl_genericmemory_data_owner_field(m); } -//STATIC_INLINE int jl_has_implicit_byte(jl_memory_t *m) +//STATIC_INLINE int jl_has_implicit_byte(jl_genericmemory_t *m) //{ // const jl_datatype_layout_t *layout = ((jl_datatype_t*)jl_typetagof(m))->layout; // if (!JL_MEMORY_IMPL_NUL || layout->size != 1) // return 0; -// int how = jl_memoryt_how(m); +// int how = jl_genericmemory_how(m); // if (how == 3) { -// m = (jl_memory_t*)jl_memoryt_data_owner_field(m); +// m = (jl_genericmemory_t*)jl_genericmemory_data_owner_field(m); // if (jl_is_string(m)) // return 1; // how = 0; @@ -438,28 +438,28 @@ JL_DLLEXPORT jl_value_t *(jl_memoryt_data_owner)(jl_memory_t *m) JL_NOTSAFEPOINT //} // Create a memory block with the same content and a trailing \0 -//JL_DLLEXPORT jl_memory_t *jl_memory_cconvert_cstring(jl_memory_t *m) +//JL_DLLEXPORT jl_genericmemory_t *jl_memory_cconvert_cstring(jl_genericmemory_t *m) //{ // static_assert(JL_MEMORY_IMPL_NUL, ""); // assert(jl_typetagis(m, jl_memory_uint8_type)); // if (!jl_has_implicit_byte(m)) -// m = jl_memoryt_copy(m); +// m = jl_genericmemory_copy(m); // if (((char*)m->data)[m->length] != 0) // avoid issues with immutable memory // ((char*)m->data)[m->length] = 0; // return m; //} -jl_memoryref_t *jl_new_memoryref(jl_value_t *typ, jl_memory_t *mem, void *data) +jl_genericmemoryref_t *jl_new_memoryref(jl_value_t *typ, jl_genericmemory_t *mem, void *data) { jl_task_t *ct = jl_current_task; - jl_memoryref_t *m = (jl_memoryref_t*)jl_gc_alloc(ct->ptls, sizeof(jl_memoryref_t), typ); + jl_genericmemoryref_t *m = (jl_genericmemoryref_t*)jl_gc_alloc(ct->ptls, sizeof(jl_genericmemoryref_t), typ); m->mem = mem; m->data = data; return m; } // memoryref primitives -JL_DLLEXPORT jl_memoryref_t jl_memoryrefindex(jl_memoryref_t m JL_ROOTING_ARGUMENT, size_t idx) +JL_DLLEXPORT jl_genericmemoryref_t jl_memoryrefindex(jl_genericmemoryref_t m JL_ROOTING_ARGUMENT, size_t idx) { const jl_datatype_layout_t *layout = ((jl_datatype_t*)jl_typetagof(m.mem))->layout; if ((layout->arrayelem_isboxed || !layout->arrayelem_isunion) && layout->size != 0) { @@ -473,7 +473,7 @@ JL_DLLEXPORT jl_memoryref_t jl_memoryrefindex(jl_memoryref_t m JL_ROOTING_ARGUME return m; } -JL_DLLEXPORT jl_value_t *jl_ptrmemrefget(jl_memoryref_t m JL_PROPAGATES_ROOT) JL_NOTSAFEPOINT +JL_DLLEXPORT jl_value_t *jl_ptrmemrefget(jl_genericmemoryref_t m JL_PROPAGATES_ROOT) JL_NOTSAFEPOINT { assert((char*)m.data - (char*)m.mem->data < sizeof(jl_value_t*) * m.mem->length); assert(((jl_datatype_t*)jl_typetagof(m.mem))->layout->arrayelem_isboxed); @@ -483,7 +483,7 @@ JL_DLLEXPORT jl_value_t *jl_ptrmemrefget(jl_memoryref_t m JL_PROPAGATES_ROOT) JL return elt; } -JL_DLLEXPORT jl_value_t *jl_memoryrefget(jl_memoryref_t m) +JL_DLLEXPORT jl_value_t *jl_memoryrefget(jl_genericmemoryref_t m) { const jl_datatype_layout_t *layout = ((jl_datatype_t*)jl_typetagof(m.mem))->layout; if (layout->arrayelem_isboxed) @@ -496,7 +496,7 @@ JL_DLLEXPORT jl_value_t *jl_memoryrefget(jl_memoryref_t m) size_t i = (size_t)data; assert(i < m.mem->length); // isbits union selector bytes are always stored directly after the last memory element - uint8_t sel = jl_memoryt_typetagdata(m.mem)[i]; + uint8_t sel = jl_genericmemory_typetagdata(m.mem)[i]; eltype = jl_nth_union_component(eltype, sel); if (jl_is_datatype_singleton((jl_datatype_t*)eltype)) return ((jl_datatype_t*)eltype)->instance; @@ -513,7 +513,7 @@ JL_DLLEXPORT jl_value_t *jl_memoryrefget(jl_memoryref_t m) return r; } -static int _jl_memoryref_isassigned(jl_memoryref_t m) +static int _jl_memoryref_isassigned(jl_genericmemoryref_t m) { const jl_datatype_layout_t *layout = ((jl_datatype_t*)jl_typetagof(m.mem))->layout; if (layout->arrayelem_isboxed) { @@ -526,12 +526,12 @@ static int _jl_memoryref_isassigned(jl_memoryref_t m) return 1; } -JL_DLLEXPORT jl_value_t *jl_memoryref_isassigned(jl_memoryref_t m) +JL_DLLEXPORT jl_value_t *jl_memoryref_isassigned(jl_genericmemoryref_t m) { return _jl_memoryref_isassigned(m) ? jl_true : jl_false; } -JL_DLLEXPORT void jl_memoryrefset(jl_memoryref_t m JL_ROOTING_ARGUMENT, jl_value_t *rhs JL_ROOTED_ARGUMENT JL_MAYBE_UNROOTED) +JL_DLLEXPORT void jl_memoryrefset(jl_genericmemoryref_t m JL_ROOTING_ARGUMENT, jl_value_t *rhs JL_ROOTED_ARGUMENT JL_MAYBE_UNROOTED) { jl_value_t *isatomic = jl_tparam0(jl_typetagof(m.mem)); (void)isatomic; // TODO jl_value_t *eltype = jl_tparam1(jl_typetagof(m.mem)); @@ -545,7 +545,7 @@ JL_DLLEXPORT void jl_memoryrefset(jl_memoryref_t m JL_ROOTING_ARGUMENT, jl_value if (layout->arrayelem_isboxed) { assert((char*)m.data - (char*)m.mem->data < sizeof(jl_value_t*) * m.mem->length); jl_atomic_store_release((_Atomic(jl_value_t*)*)m.data, rhs); - jl_gc_wb(jl_memoryt_owner(m.mem), rhs); + jl_gc_wb(jl_genericmemory_owner(m.mem), rhs); } else { int hasptr; @@ -554,10 +554,10 @@ JL_DLLEXPORT void jl_memoryrefset(jl_memoryref_t m JL_ROOTING_ARGUMENT, jl_value assert(jl_is_uniontype(eltype)); size_t i = (size_t)data; assert(i < m.mem->length); - uint8_t *psel = (uint8_t*)jl_memoryt_typetagdata(m.mem) + i; + uint8_t *psel = (uint8_t*)jl_genericmemory_typetagdata(m.mem) + i; unsigned nth = 0; if (!jl_find_union_component(eltype, jl_typeof(rhs), &nth)) - assert(0 && "invalid memorytset to isbits union"); + assert(0 && "invalid genericmemoryset to isbits union"); *psel = nth; if (jl_is_datatype_singleton((jl_datatype_t*)jl_typeof(rhs))) return; @@ -568,11 +568,11 @@ JL_DLLEXPORT void jl_memoryrefset(jl_memoryref_t m JL_ROOTING_ARGUMENT, jl_value hasptr = layout->first_ptr >= 0; } assert(data - (char*)m.mem->data < layout->size * m.mem->length); - memorytassign_safe(hasptr, jl_memoryt_owner(m.mem), data, rhs); + genericmemoryassign_safe(hasptr, jl_genericmemory_owner(m.mem), data, rhs); } } -JL_DLLEXPORT void jl_memoryrefunset(jl_memoryref_t m) +JL_DLLEXPORT void jl_memoryrefunset(jl_genericmemoryref_t m) { if (m.mem->length == 0) jl_bounds_error_int((jl_value_t*)m.mem, 1); @@ -587,9 +587,9 @@ JL_DLLEXPORT void jl_memoryrefunset(jl_memoryref_t m) } } -JL_DLLEXPORT jl_value_t *jl_mem_owner(jl_memory_t *m JL_PROPAGATES_ROOT) JL_NOTSAFEPOINT +JL_DLLEXPORT jl_value_t *jl_mem_owner(jl_genericmemory_t *m JL_PROPAGATES_ROOT) JL_NOTSAFEPOINT { - return jl_memoryt_owner(m); + return jl_genericmemory_owner(m); } #ifdef __cplusplus } diff --git a/src/gf.c b/src/gf.c index 164cb99a7520d3..1694340948d139 100644 --- a/src/gf.c +++ b/src/gf.c @@ -640,7 +640,7 @@ static int reset_mt_caches(jl_methtable_t *mt, void *env) // removes all method caches // this might not be entirely safe (GC or MT), thus we only do it very early in bootstrapping if (!mt->frozen) { // make sure not to reset builtin functions - jl_atomic_store_release(&mt->leafcache, (jl_memory_t*)jl_an_empty_memory_any); + jl_atomic_store_release(&mt->leafcache, (jl_genericmemory_t*)jl_an_empty_memory_any); jl_atomic_store_release(&mt->cache, jl_nothing); } jl_typemap_visitor(jl_atomic_load_relaxed(&mt->defs), get_method_unspec_list, env); @@ -1213,7 +1213,7 @@ static int concretesig_equal(jl_value_t *tt, jl_value_t *simplesig) JL_NOTSAFEPO return 1; } -static inline jl_typemap_entry_t *lookup_leafcache(jl_memory_t *leafcache JL_PROPAGATES_ROOT, jl_value_t *tt, size_t world) JL_NOTSAFEPOINT +static inline jl_typemap_entry_t *lookup_leafcache(jl_genericmemory_t *leafcache JL_PROPAGATES_ROOT, jl_value_t *tt, size_t world) JL_NOTSAFEPOINT { jl_typemap_entry_t *entry = (jl_typemap_entry_t*)jl_eqtable_get(leafcache, (jl_value_t*)tt, NULL); if (entry) { @@ -1240,7 +1240,7 @@ static jl_method_instance_t *cache_method( int8_t offs = mt ? jl_cachearg_offset(mt) : 1; { // scope block if (mt) { - jl_memory_t *leafcache = jl_atomic_load_relaxed(&mt->leafcache); + jl_genericmemory_t *leafcache = jl_atomic_load_relaxed(&mt->leafcache); jl_typemap_entry_t *entry = lookup_leafcache(leafcache, (jl_value_t*)tt, world); if (entry) return entry->func.linfo; @@ -1420,11 +1420,11 @@ static jl_method_instance_t *cache_method( jl_cache_type_(tt); JL_UNLOCK(&typecache_lock); // Might GC } - jl_memory_t *oldcache = jl_atomic_load_relaxed(&mt->leafcache); + jl_genericmemory_t *oldcache = jl_atomic_load_relaxed(&mt->leafcache); jl_typemap_entry_t *old = (jl_typemap_entry_t*)jl_eqtable_get(oldcache, (jl_value_t*)tt, jl_nothing); jl_atomic_store_relaxed(&newentry->next, old); jl_gc_wb(newentry, old); - jl_memory_t *newcache = jl_eqtable_put(jl_atomic_load_relaxed(&mt->leafcache), (jl_value_t*)tt, (jl_value_t*)newentry, NULL); + jl_genericmemory_t *newcache = jl_eqtable_put(jl_atomic_load_relaxed(&mt->leafcache), (jl_value_t*)tt, (jl_value_t*)newentry, NULL); if (newcache != oldcache) { jl_atomic_store_release(&mt->leafcache, newcache); jl_gc_wb(mt, newcache); @@ -1445,7 +1445,7 @@ static jl_method_instance_t *jl_mt_assoc_by_type(jl_methtable_t *mt JL_PROPAGATE // caller must hold the mt->writelock assert(tt->isdispatchtuple || tt->hasfreetypevars); if (tt->isdispatchtuple) { - jl_memory_t *leafcache = jl_atomic_load_relaxed(&mt->leafcache); + jl_genericmemory_t *leafcache = jl_atomic_load_relaxed(&mt->leafcache); jl_typemap_entry_t *entry = lookup_leafcache(leafcache, (jl_value_t*)tt, world); if (entry) return entry->func.linfo; @@ -1872,10 +1872,10 @@ static void jl_method_table_invalidate(jl_methtable_t *mt, jl_typemap_entry_t *m mt_cache_env.shadowed = NULL; mt_cache_env.invalidated = 0; jl_typemap_visitor(jl_atomic_load_relaxed(&mt->cache), disable_mt_cache, (void*)&mt_cache_env); - jl_memory_t *leafcache = jl_atomic_load_relaxed(&mt->leafcache); + jl_genericmemory_t *leafcache = jl_atomic_load_relaxed(&mt->leafcache); size_t i, l = leafcache->length; for (i = 1; i < l; i += 2) { - jl_typemap_entry_t *oldentry = (jl_typemap_entry_t*)jl_memoryt_ptr_ref(leafcache, i); + jl_typemap_entry_t *oldentry = (jl_typemap_entry_t*)jl_genericmemory_ptr_ref(leafcache, i); if (oldentry) { while ((jl_value_t*)oldentry != jl_nothing) { if (oldentry->max_world == ~(size_t)0) @@ -2168,10 +2168,10 @@ JL_DLLEXPORT void jl_method_table_insert(jl_methtable_t *mt, jl_method_t *method mt_cache_env.invalidated = 0; jl_typemap_visitor(jl_atomic_load_relaxed(&mt->cache), invalidate_mt_cache, (void*)&mt_cache_env); - jl_memory_t *leafcache = jl_atomic_load_relaxed(&mt->leafcache); + jl_genericmemory_t *leafcache = jl_atomic_load_relaxed(&mt->leafcache); size_t i, l = leafcache->length; for (i = 1; i < l; i += 2) { - jl_value_t *entry = jl_memoryt_ptr_ref(leafcache, i); + jl_value_t *entry = jl_genericmemory_ptr_ref(leafcache, i); if (entry) { while (entry != jl_nothing) { invalidate_mt_cache((jl_typemap_entry_t*)entry, (void*)&mt_cache_env); @@ -2244,7 +2244,7 @@ jl_method_instance_t *jl_method_lookup(jl_value_t **args, size_t nargs, size_t w if (entry) return entry->func.linfo; jl_tupletype_t *tt = arg_type_tuple(args[0], &args[1], nargs); - jl_memory_t *leafcache = jl_atomic_load_relaxed(&mt->leafcache); + jl_genericmemory_t *leafcache = jl_atomic_load_relaxed(&mt->leafcache); entry = lookup_leafcache(leafcache, (jl_value_t*)tt, world); if (entry) return entry->func.linfo; @@ -3000,9 +3000,9 @@ STATIC_INLINE jl_method_instance_t *jl_lookup_generic_(jl_value_t *F, jl_value_t // if no method was found in the associative cache, check the full cache JL_TIMING(METHOD_LOOKUP_FAST, METHOD_LOOKUP_FAST); mt = jl_gf_mtable(F); - jl_memory_t *leafcache = jl_atomic_load_relaxed(&mt->leafcache); + jl_genericmemory_t *leafcache = jl_atomic_load_relaxed(&mt->leafcache); entry = NULL; - if (leafcache != (jl_memory_t*)jl_an_empty_memory_any && + if (leafcache != (jl_genericmemory_t*)jl_an_empty_memory_any && jl_typetagis(jl_atomic_load_relaxed(&mt->cache), jl_typemap_level_type)) { // hashing args is expensive, but looking at mt->cache is probably even more expensive tt = lookup_arg_type_tuple(F, args, nargs); @@ -3609,7 +3609,7 @@ static jl_value_t *ml_matches(jl_methtable_t *mt, if (mt) { // check the leaf cache if this type can be in there if (((jl_datatype_t*)unw)->isdispatchtuple) { - jl_memory_t *leafcache = jl_atomic_load_relaxed(&mt->leafcache); + jl_genericmemory_t *leafcache = jl_atomic_load_relaxed(&mt->leafcache); jl_typemap_entry_t *entry = lookup_leafcache(leafcache, (jl_value_t*)type, world); if (entry) { jl_method_instance_t *mi = entry->func.linfo; diff --git a/src/iddict.c b/src/iddict.c index 5ef81814225dc2..9ebc54a1f4bfe8 100644 --- a/src/iddict.c +++ b/src/iddict.c @@ -8,14 +8,14 @@ #define keyhash(k) jl_object_id_(jl_typeof(k), k) #define h2index(hv, sz) (size_t)(((hv) & ((sz)-1)) * 2) -static inline int jl_table_assign_bp(jl_memory_t **pa, jl_value_t *key, jl_value_t *val); +static inline int jl_table_assign_bp(jl_genericmemory_t **pa, jl_value_t *key, jl_value_t *val); -JL_DLLEXPORT jl_memory_t *jl_idtable_rehash(jl_memory_t *a, size_t newsz) +JL_DLLEXPORT jl_genericmemory_t *jl_idtable_rehash(jl_genericmemory_t *a, size_t newsz) { size_t sz = a->length; size_t i; jl_value_t **ol = (jl_value_t **) a->data; - jl_memory_t *newa = jl_alloc_memory_any(newsz); + jl_genericmemory_t *newa = jl_alloc_memory_any(newsz); // keep the original memory in the original slot since we need `ol` // to be valid in the loop below. JL_GC_PUSH2(&newa, &a); @@ -30,11 +30,11 @@ JL_DLLEXPORT jl_memory_t *jl_idtable_rehash(jl_memory_t *a, size_t newsz) return newa; } -static inline int jl_table_assign_bp(jl_memory_t **pa, jl_value_t *key, jl_value_t *val) +static inline int jl_table_assign_bp(jl_genericmemory_t **pa, jl_value_t *key, jl_value_t *val) { // pa points to a **un**rooted address uint_t hv; - jl_memory_t *a = *pa; + jl_genericmemory_t *a = *pa; size_t orig, index, iter, empty_slot; size_t newsz, sz = hash_size(a); if (sz == 0) { @@ -109,7 +109,7 @@ static inline int jl_table_assign_bp(jl_memory_t **pa, jl_value_t *key, jl_value } /* returns bp if key is in hash, otherwise NULL */ -inline _Atomic(jl_value_t*) *jl_table_peek_bp(jl_memory_t *a, jl_value_t *key) JL_NOTSAFEPOINT +inline _Atomic(jl_value_t*) *jl_table_peek_bp(jl_genericmemory_t *a, jl_value_t *key) JL_NOTSAFEPOINT { size_t sz = hash_size(a); if (sz == 0) @@ -142,7 +142,7 @@ inline _Atomic(jl_value_t*) *jl_table_peek_bp(jl_memory_t *a, jl_value_t *key) J } JL_DLLEXPORT -jl_memory_t *jl_eqtable_put(jl_memory_t *h, jl_value_t *key, jl_value_t *val, int *p_inserted) +jl_genericmemory_t *jl_eqtable_put(jl_genericmemory_t *h, jl_value_t *key, jl_value_t *val, int *p_inserted) { int inserted = jl_table_assign_bp(&h, key, val); if (p_inserted) @@ -153,20 +153,20 @@ jl_memory_t *jl_eqtable_put(jl_memory_t *h, jl_value_t *key, jl_value_t *val, in // Note: lookup in the IdDict is permitted concurrently, if you avoid deletions, // and assuming you do use an external lock around all insertions JL_DLLEXPORT -jl_value_t *jl_eqtable_get(jl_memory_t *h, jl_value_t *key, jl_value_t *deflt) JL_NOTSAFEPOINT +jl_value_t *jl_eqtable_get(jl_genericmemory_t *h, jl_value_t *key, jl_value_t *deflt) JL_NOTSAFEPOINT { _Atomic(jl_value_t*) *bp = jl_table_peek_bp(h, key); return (bp == NULL) ? deflt : jl_atomic_load_relaxed(bp); } -jl_value_t *jl_eqtable_getkey(jl_memory_t *h, jl_value_t *key, jl_value_t *deflt) JL_NOTSAFEPOINT +jl_value_t *jl_eqtable_getkey(jl_genericmemory_t *h, jl_value_t *key, jl_value_t *deflt) JL_NOTSAFEPOINT { _Atomic(jl_value_t*) *bp = jl_table_peek_bp(h, key); return (bp == NULL) ? deflt : jl_atomic_load_relaxed(bp - 1); } JL_DLLEXPORT -jl_value_t *jl_eqtable_pop(jl_memory_t *h, jl_value_t *key, jl_value_t *deflt, int *found) +jl_value_t *jl_eqtable_pop(jl_genericmemory_t *h, jl_value_t *key, jl_value_t *deflt, int *found) { _Atomic(jl_value_t*) *bp = jl_table_peek_bp(h, key); if (found) @@ -180,7 +180,7 @@ jl_value_t *jl_eqtable_pop(jl_memory_t *h, jl_value_t *key, jl_value_t *deflt, i } JL_DLLEXPORT -size_t jl_eqtable_nextind(jl_memory_t *t, size_t i) +size_t jl_eqtable_nextind(jl_genericmemory_t *t, size_t i) { if (i & 1) i++; diff --git a/src/ircode.c b/src/ircode.c index 0752535cc35347..0ad4e919866327 100644 --- a/src/ircode.c +++ b/src/ircode.c @@ -122,14 +122,14 @@ static void jl_encode_as_indexed_root(jl_ircode_state *s, jl_value_t *v) } } -static void jl_encode_memory_slice(jl_ircode_state *s, jl_memory_t *mem, size_t offset, size_t len) JL_GC_DISABLED +static void jl_encode_memory_slice(jl_ircode_state *s, jl_genericmemory_t *mem, size_t offset, size_t len) JL_GC_DISABLED { jl_datatype_t *t = (jl_datatype_t*)jl_typetagof(mem); size_t i; const jl_datatype_layout_t *layout = t->layout; if (layout->arrayelem_isboxed) { for (i = 0; i < len; i++) { - jl_value_t *e = jl_memoryt_ptr_ref(mem, offset + i); + jl_value_t *e = jl_genericmemory_ptr_ref(mem, offset + i); jl_encode_value(s, e); } } @@ -155,8 +155,8 @@ static void jl_encode_memory_slice(jl_ircode_state *s, jl_memory_t *mem, size_t } else { ios_write(s->s, (char*)mem->data + offset * layout->size, len * layout->size); - if (jl_memoryt_isbitsunion(mem)) - ios_write(s->s, jl_memoryt_typetagdata(mem) + offset, len); + if (jl_genericmemory_isbitsunion(mem)) + ios_write(s->s, jl_genericmemory_typetagdata(mem) + offset, len); } } @@ -395,8 +395,8 @@ static void jl_encode_value_(jl_ircode_state *s, jl_value_t *v, int as_literal) offset = (char*)ar->ref.data - (char*)ar->ref.mem->data; jl_encode_memory_slice(s, ar->ref.mem, offset, l); } - else if (as_literal && jl_is_memory(v)) { - jl_memory_t* m = (jl_memory_t*)v; + else if (as_literal && jl_is_genericmemory(v)) { + jl_genericmemory_t* m = (jl_genericmemory_t*)v; write_uint8(s->s, TAG_MEMORYT); jl_encode_value(s, (jl_datatype_t*)jl_typetagof(v)); jl_encode_value(s, jl_box_long(m->length)); @@ -489,7 +489,7 @@ static jl_value_t *jl_decode_value_svec(jl_ircode_state *s, uint8_t tag) JL_GC_D static jl_value_t *jl_decode_value_memory(jl_ircode_state *s, jl_value_t *mty, size_t nel) JL_GC_DISABLED { - jl_memory_t *m = jl_alloc_memoryt(mty, nel); + jl_genericmemory_t *m = jl_alloc_genericmemory(mty, nel); const jl_datatype_layout_t *layout = ((jl_datatype_t*)mty)->layout; if (layout->arrayelem_isboxed) { jl_value_t **data = (jl_value_t**)m->data; @@ -521,7 +521,7 @@ static jl_value_t *jl_decode_value_memory(jl_ircode_state *s, jl_value_t *mty, s assert(jl_astaggedvalue(m)->bits.gc == GC_CLEAN); // gc is disabled } else { - size_t extra = jl_memoryt_isbitsunion(m) ? m->length : 0; + size_t extra = jl_genericmemory_isbitsunion(m) ? m->length : 0; size_t tot = m->length * layout->size + extra; ios_readall(s->s, (char*)m->data, tot); } @@ -545,7 +545,7 @@ static jl_value_t *jl_decode_value_array(jl_ircode_state *s, uint8_t tag) JL_GC_ } jl_value_t *aty = jl_decode_value(s); jl_array_t *a = jl_alloc_array_nd(aty, dims, ndims); - a->ref.mem = (jl_memory_t*)jl_decode_value_memory(s, jl_field_type_concrete((jl_datatype_t*)jl_field_type_concrete((jl_datatype_t*)aty, 0), 1), len); + a->ref.mem = (jl_genericmemory_t*)jl_decode_value_memory(s, jl_field_type_concrete((jl_datatype_t*)jl_field_type_concrete((jl_datatype_t*)aty, 0), 1), len); const jl_datatype_layout_t *layout = ((jl_datatype_t*)jl_typetagof(a->ref.mem))->layout; if (layout->arrayelem_isunion || layout->size == 0) a->ref.data = (void*)0; @@ -1163,7 +1163,7 @@ void jl_init_serializer(void) deser_tag[TAG_SLOTNUMBER] = (jl_value_t*)jl_slotnumber_type; deser_tag[TAG_SVEC] = (jl_value_t*)jl_simplevector_type; deser_tag[TAG_ARRAY] = (jl_value_t*)jl_array_type; - deser_tag[TAG_MEMORYT] = (jl_value_t*)jl_memory_type; + deser_tag[TAG_MEMORYT] = (jl_value_t*)jl_genericmemory_type; deser_tag[TAG_EXPR] = (jl_value_t*)jl_expr_type; deser_tag[TAG_PHINODE] = (jl_value_t*)jl_phinode_type; deser_tag[TAG_PHICNODE] = (jl_value_t*)jl_phicnode_type; diff --git a/src/jl_exported_data.inc b/src/jl_exported_data.inc index c0a572ab3ab56a..e43255f3dcea66 100644 --- a/src/jl_exported_data.inc +++ b/src/jl_exported_data.inc @@ -66,13 +66,13 @@ XX(jl_main_module) \ XX(jl_memory_any_type) \ XX(jl_memory_exception) \ - XX(jl_memory_type) \ - XX(jl_memory_typename) \ + XX(jl_genericmemory_type) \ + XX(jl_genericmemory_typename) \ XX(jl_memory_uint8_type) \ XX(jl_memory_uint64_type) \ XX(jl_memoryref_any_type) \ - XX(jl_memoryref_type) \ - XX(jl_memoryref_typename) \ + XX(jl_genericmemoryref_type) \ + XX(jl_genericmemoryref_typename) \ XX(jl_memoryref_uint8_type) \ XX(jl_memoryref_uint64_type) \ XX(jl_methoderror_type) \ diff --git a/src/jltypes.c b/src/jltypes.c index 6bb386ebbed318..b302336d9abb1e 100644 --- a/src/jltypes.c +++ b/src/jltypes.c @@ -294,7 +294,7 @@ int jl_has_fixed_layout(jl_datatype_t *dt) { if (dt->isconcretetype) return 1; - if (jl_is_memory_type(dt)) { // GenericMemory{isatomic,T} uses T for final layout, which is a parameter not a field however + if (jl_is_genericmemory_type(dt)) { // GenericMemory{isatomic,T} uses T for final layout, which is a parameter not a field however // optionally: return !layout_uses_free_typevars(jl_tparam1(dt), env); return 0; } @@ -321,7 +321,7 @@ int jl_has_fixed_layout(jl_datatype_t *dt) int jl_type_mappable_to_c(jl_value_t *ty) { assert(!jl_is_typevar(ty) && jl_is_type(ty)); - if (jl_is_array_type(ty) || jl_is_memory_type(ty) || + if (jl_is_array_type(ty) || jl_is_genericmemory_type(ty) || (jl_is_datatype(ty) && ((jl_datatype_t*)ty)->layout != NULL && jl_is_layout_opaque(((jl_datatype_t*)ty)->layout))) return 1; // as boxed @@ -2088,7 +2088,7 @@ static jl_value_t *inst_datatype_inner(jl_datatype_t *dt, jl_svec_t *p, jl_value ndt->types = jl_emptysvec; // XXX: this is essentially always false } } - else if (tn == jl_memoryref_typename || tn == jl_memory_typename) { + else if (tn == jl_genericmemoryref_typename || tn == jl_genericmemory_typename) { jl_value_t *isatomic = jl_svecref(p, 0); if (!jl_is_typevar(isatomic) && !jl_is_symbol(isatomic)) jl_type_error_rt("GenericMemory", "isatomic parameter", (jl_value_t*)jl_symbol_type, isatomic); @@ -2896,8 +2896,8 @@ void jl_init_types(void) JL_GC_DISABLED jl_perm_symsvec(2, "length", "data"), jl_svec(2, jl_long_type, pointer_void), jl_emptysvec, 0, 1, 2); - jl_memory_typename = memory_datatype->name; - jl_memory_type = (jl_unionall_t*)jl_memory_typename->wrapper; + jl_genericmemory_typename = memory_datatype->name; + jl_genericmemory_type = (jl_unionall_t*)jl_genericmemory_typename->wrapper; const static uint32_t memory_constfields[1] = { 0x00000003 }; // (1<<1)|(1<<0) memory_datatype->name->constfields = memory_constfields; memory_datatype->ismutationfree = 0; @@ -2908,14 +2908,14 @@ void jl_init_types(void) JL_GC_DISABLED jl_perm_symsvec(2, "ptr", "mem"), jl_svec(2, pointer_void, memory_datatype), jl_emptysvec, 0, 0, 2); - jl_memoryref_typename = memoryref_datatype->name; - jl_memoryref_type = (jl_unionall_t*)jl_memoryref_typename->wrapper; + jl_genericmemoryref_typename = memoryref_datatype->name; + jl_genericmemoryref_type = (jl_unionall_t*)jl_genericmemoryref_typename->wrapper; memoryref_datatype->ismutationfree = 0; - jl_memory_any_type = jl_apply_type2((jl_value_t*)jl_memory_type, (jl_value_t*)jl_not_atomic_sym, (jl_value_t*)jl_any_type); - jl_memory_uint8_type = jl_apply_type2((jl_value_t*)jl_memory_type, (jl_value_t*)jl_not_atomic_sym, (jl_value_t*)jl_uint8_type); - jl_memoryref_any_type = jl_apply_type2((jl_value_t*)jl_memoryref_type, (jl_value_t*)jl_not_atomic_sym, (jl_value_t*)jl_any_type); - jl_memoryref_uint8_type = jl_apply_type2((jl_value_t*)jl_memoryref_type, (jl_value_t*)jl_not_atomic_sym, (jl_value_t*)jl_uint8_type); + jl_memory_any_type = jl_apply_type2((jl_value_t*)jl_genericmemory_type, (jl_value_t*)jl_not_atomic_sym, (jl_value_t*)jl_any_type); + jl_memory_uint8_type = jl_apply_type2((jl_value_t*)jl_genericmemory_type, (jl_value_t*)jl_not_atomic_sym, (jl_value_t*)jl_uint8_type); + jl_memoryref_any_type = jl_apply_type2((jl_value_t*)jl_genericmemoryref_type, (jl_value_t*)jl_not_atomic_sym, (jl_value_t*)jl_any_type); + jl_memoryref_uint8_type = jl_apply_type2((jl_value_t*)jl_genericmemoryref_type, (jl_value_t*)jl_not_atomic_sym, (jl_value_t*)jl_uint8_type); tv = jl_svec2(tvar("T"), tvar("N")); jl_array_typename = jl_new_datatype(jl_symbol("Array"), core, @@ -2923,7 +2923,7 @@ void jl_init_types(void) JL_GC_DISABLED tv, jl_perm_symsvec(2, "ref", "size"), jl_svec(2, - jl_apply_type2((jl_value_t*)jl_memoryref_type, (jl_value_t*)jl_not_atomic_sym, jl_svecref(tv, 0)), + jl_apply_type2((jl_value_t*)jl_genericmemoryref_type, (jl_value_t*)jl_not_atomic_sym, jl_svecref(tv, 0)), jl_apply_type1((jl_value_t*)jl_tuple_type, (jl_value_t*)jl_wrap_vararg((jl_value_t*)jl_long_type, jl_svecref(tv, 1), 0))), jl_emptysvec, 0, 1, 2)->name; jl_array_type = (jl_unionall_t*)jl_array_typename->wrapper; @@ -2936,8 +2936,8 @@ void jl_init_types(void) JL_GC_DISABLED jl_array_uint64_type = jl_apply_type2((jl_value_t*)jl_array_type, (jl_value_t*)jl_uint64_type, jl_box_long(1)); jl_an_empty_vec_any = (jl_value_t*)jl_alloc_vec_any(0); // used internally jl_an_empty_memory_any = (jl_value_t*)jl_alloc_memory_any(0); // used internally - jl_atomic_store_relaxed(&jl_nonfunction_mt->leafcache, (jl_memory_t*)jl_an_empty_memory_any); - jl_atomic_store_relaxed(&jl_type_type_mt->leafcache, (jl_memory_t*)jl_an_empty_memory_any); + jl_atomic_store_relaxed(&jl_nonfunction_mt->leafcache, (jl_genericmemory_t*)jl_an_empty_memory_any); + jl_atomic_store_relaxed(&jl_type_type_mt->leafcache, (jl_genericmemory_t*)jl_an_empty_memory_any); jl_expr_type = jl_new_datatype(jl_symbol("Expr"), core, diff --git a/src/julia.h b/src/julia.h index daf9211a0a9c8e..edf104f2e38297 100644 --- a/src/julia.h +++ b/src/julia.h @@ -180,17 +180,17 @@ JL_EXTENSION typedef struct { // jl_value_t *owner // T inl[]; // }; -} jl_memory_t; +} jl_genericmemory_t; JL_EXTENSION typedef struct { JL_DATA_TYPE void *data; - jl_memory_t *mem; -} jl_memoryref_t; + jl_genericmemory_t *mem; +} jl_genericmemoryref_t; JL_EXTENSION typedef struct { JL_DATA_TYPE - jl_memoryref_t ref; + jl_genericmemoryref_t ref; size_t dimsize[]; // length for 1-D, otherwise length is mem->length } jl_array_t; @@ -652,10 +652,10 @@ typedef struct _jl_typemap_level_t { // next split may be on Type{T} as LeafTypes then TypeName's parents up to Any // next split may be on LeafType // next split may be on TypeName - _Atomic(jl_memory_t*) arg1; // contains LeafType (in a map of non-abstract TypeName) - _Atomic(jl_memory_t*) targ; // contains Type{LeafType} (in a map of non-abstract TypeName) - _Atomic(jl_memory_t*) name1; // a map for a map for TypeName, for parents up to (excluding) Any - _Atomic(jl_memory_t*) tname; // a map for Type{TypeName}, for parents up to (including) Any + _Atomic(jl_genericmemory_t*) arg1; // contains LeafType (in a map of non-abstract TypeName) + _Atomic(jl_genericmemory_t*) targ; // contains Type{LeafType} (in a map of non-abstract TypeName) + _Atomic(jl_genericmemory_t*) name1; // a map for a map for TypeName, for parents up to (excluding) Any + _Atomic(jl_genericmemory_t*) tname; // a map for Type{TypeName}, for parents up to (including) Any // next a linear list of things too complicated at this level for analysis (no more levels) _Atomic(jl_typemap_entry_t*) linear; // finally, start a new level if the type at offs is Any @@ -667,7 +667,7 @@ typedef struct _jl_methtable_t { JL_DATA_TYPE jl_sym_t *name; // sometimes used for debug printing _Atomic(jl_typemap_t*) defs; - _Atomic(jl_memory_t*) leafcache; + _Atomic(jl_genericmemory_t*) leafcache; _Atomic(jl_typemap_t*) cache; _Atomic(intptr_t) max_args; // max # of non-vararg arguments in a signature jl_module_t *module; // sometimes used for debug printing @@ -791,10 +791,10 @@ extern JL_DLLIMPORT jl_unionall_t *jl_abstractarray_type JL_GLOBALLY_ROOTED; extern JL_DLLIMPORT jl_unionall_t *jl_densearray_type JL_GLOBALLY_ROOTED; extern JL_DLLIMPORT jl_unionall_t *jl_array_type JL_GLOBALLY_ROOTED; extern JL_DLLIMPORT jl_typename_t *jl_array_typename JL_GLOBALLY_ROOTED; -extern JL_DLLIMPORT jl_unionall_t *jl_memory_type JL_GLOBALLY_ROOTED; -extern JL_DLLIMPORT jl_typename_t *jl_memory_typename JL_GLOBALLY_ROOTED; -extern JL_DLLIMPORT jl_unionall_t *jl_memoryref_type JL_GLOBALLY_ROOTED; -extern JL_DLLIMPORT jl_typename_t *jl_memoryref_typename JL_GLOBALLY_ROOTED; +extern JL_DLLIMPORT jl_unionall_t *jl_genericmemory_type JL_GLOBALLY_ROOTED; +extern JL_DLLIMPORT jl_typename_t *jl_genericmemory_typename JL_GLOBALLY_ROOTED; +extern JL_DLLIMPORT jl_unionall_t *jl_genericmemoryref_type JL_GLOBALLY_ROOTED; +extern JL_DLLIMPORT jl_typename_t *jl_genericmemoryref_typename JL_GLOBALLY_ROOTED; extern JL_DLLIMPORT jl_datatype_t *jl_weakref_type JL_GLOBALLY_ROOTED; extern JL_DLLIMPORT jl_datatype_t *jl_abstractstring_type JL_GLOBALLY_ROOTED; extern JL_DLLIMPORT jl_datatype_t *jl_string_type JL_GLOBALLY_ROOTED; @@ -1076,7 +1076,7 @@ STATIC_INLINE jl_value_t *jl_svecset( } #endif -#define jl_memoryt_data_owner_field(a) (*(jl_value_t**)((jl_memory_t*)(a) + 1)) +#define jl_genericmemory_data_owner_field(a) (*(jl_value_t**)((jl_genericmemory_t*)(a) + 1)) #define jl_nparams(t) jl_svec_len(((jl_datatype_t*)(t))->parameters) #define jl_tparam0(t) jl_svecref(((jl_datatype_t*)(t))->parameters, 0) @@ -1088,7 +1088,7 @@ STATIC_INLINE jl_value_t *jl_svecset( #define jl_array_dim0(a) (((jl_array_t*)(a))->dimsize[0]) #define jl_array_nrows(a) (((jl_array_t*)(a))->dimsize[0]) #define jl_array_ndims(a) (*(size_t*)jl_tparam1(jl_typetagof(a))) -#define jl_array_data_owner_field(a) (jl_memoryt_data_owner_field(((jl_array_t*)a)->ref.mem)) +#define jl_array_data_owner_field(a) (jl_genericmemory_data_owner_field(((jl_array_t*)a)->ref.mem)) #define jl_array_maxsize(a) (((jl_array_t*)(a))->ref.mem->length) #define jl_array_len(a) (jl_array_ndims(a) == 1 ? jl_array_nrows(a) : jl_array_maxsize(a)) @@ -1099,11 +1099,11 @@ STATIC_INLINE jl_value_t *jl_svecset( 2 = malloc-allocated pointer (may or may not own it) 3 = has a pointer to the object that owns the data pointer */ -STATIC_INLINE int jl_memoryt_how(jl_memory_t *m) JL_NOTSAFEPOINT +STATIC_INLINE int jl_genericmemory_how(jl_genericmemory_t *m) JL_NOTSAFEPOINT { if (m->data == (void*)(m + 1)) return 0; - jl_value_t *owner = jl_memoryt_data_owner_field(m); + jl_value_t *owner = jl_genericmemory_data_owner_field(m); if (owner == (jl_value_t*)m) return 1; if (owner == NULL) @@ -1111,42 +1111,42 @@ STATIC_INLINE int jl_memoryt_how(jl_memory_t *m) JL_NOTSAFEPOINT return 3; } -STATIC_INLINE jl_value_t *jl_memoryt_owner(jl_memory_t *m JL_PROPAGATES_ROOT) JL_NOTSAFEPOINT +STATIC_INLINE jl_value_t *jl_genericmemory_owner(jl_genericmemory_t *m JL_PROPAGATES_ROOT) JL_NOTSAFEPOINT { - if (jl_memoryt_how(m) == 3) - return jl_memoryt_data_owner_field(m); + if (jl_genericmemory_how(m) == 3) + return jl_genericmemory_data_owner_field(m); return (jl_value_t*)m; } JL_DLLEXPORT char *jl_array_typetagdata(jl_array_t *a) JL_NOTSAFEPOINT; -JL_DLLEXPORT char *jl_memoryt_typetagdata(jl_memory_t *m) JL_NOTSAFEPOINT; +JL_DLLEXPORT char *jl_genericmemory_typetagdata(jl_genericmemory_t *m) JL_NOTSAFEPOINT; #ifdef __clang_gcanalyzer__ -jl_value_t **jl_memoryt_ptr_data(jl_memory_t *m JL_PROPAGATES_ROOT) JL_NOTSAFEPOINT; -STATIC_INLINE jl_value_t *jl_memoryt_ptr_ref(void *m JL_PROPAGATES_ROOT, size_t i) JL_NOTSAFEPOINT; -STATIC_INLINE jl_value_t *jl_memoryt_ptr_set( +jl_value_t **jl_genericmemory_ptr_data(jl_genericmemory_t *m JL_PROPAGATES_ROOT) JL_NOTSAFEPOINT; +STATIC_INLINE jl_value_t *jl_genericmemory_ptr_ref(void *m JL_PROPAGATES_ROOT, size_t i) JL_NOTSAFEPOINT; +STATIC_INLINE jl_value_t *jl_genericmemory_ptr_set( void *m JL_ROOTING_ARGUMENT, size_t i, void *x JL_ROOTED_ARGUMENT) JL_NOTSAFEPOINT; #else -#define jl_memoryt_ptr_data(a) ((jl_value_t**)((jl_memory_t*)(a))->data) -STATIC_INLINE jl_value_t *jl_memoryt_ptr_ref(void *m JL_PROPAGATES_ROOT, size_t i) JL_NOTSAFEPOINT +#define jl_genericmemory_ptr_data(a) ((jl_value_t**)((jl_genericmemory_t*)(a))->data) +STATIC_INLINE jl_value_t *jl_genericmemory_ptr_ref(void *m JL_PROPAGATES_ROOT, size_t i) JL_NOTSAFEPOINT { - jl_memory_t *m_ = (jl_memory_t*)m; + jl_genericmemory_t *m_ = (jl_genericmemory_t*)m; assert(((jl_datatype_t*)jl_typetagof(m_))->layout->arrayelem_isboxed); assert(i < m_->length); return jl_atomic_load_relaxed(((_Atomic(jl_value_t*)*)(m_->data)) + i); } -STATIC_INLINE jl_value_t *jl_memoryt_ptr_set( +STATIC_INLINE jl_value_t *jl_genericmemory_ptr_set( void *m JL_ROOTING_ARGUMENT, size_t i, void *x JL_ROOTED_ARGUMENT) JL_NOTSAFEPOINT { - jl_memory_t *m_ = (jl_memory_t*)m; + jl_genericmemory_t *m_ = (jl_genericmemory_t*)m; assert(((jl_datatype_t*)jl_typetagof(m_))->layout->arrayelem_isboxed); assert(i < m_->length); jl_atomic_store_release(((_Atomic(jl_value_t*)*)(m_->data)) + i, (jl_value_t*)x); if (x) { - if (jl_memoryt_how(m_) == 3) - m = (void*)jl_memoryt_data_owner_field(m_); + if (jl_genericmemory_how(m_) == 3) + m = (void*)jl_genericmemory_data_owner_field(m_); jl_gc_wb(m, x); } return (jl_value_t*)x; @@ -1155,14 +1155,14 @@ STATIC_INLINE jl_value_t *jl_memoryt_ptr_set( STATIC_INLINE uint8_t jl_memory_uint8_ref(void *m, size_t i) JL_NOTSAFEPOINT { - jl_memory_t *m_ = (jl_memory_t*)m; + jl_genericmemory_t *m_ = (jl_genericmemory_t*)m; assert(jl_typetagis(m_, jl_memory_uint8_type)); assert(i < m_->length); return ((uint8_t*)m_->data)[i]; } STATIC_INLINE void jl_memory_uint8_set(void *m, size_t i, uint8_t x) JL_NOTSAFEPOINT { - jl_memory_t *m_ = (jl_memory_t*)m; + jl_genericmemory_t *m_ = (jl_genericmemory_t*)m; assert(jl_typetagis(m_, jl_memory_uint8_type)); assert(i < m_->length); ((uint8_t*)m_->data)[i] = x; @@ -1170,7 +1170,7 @@ STATIC_INLINE void jl_memory_uint8_set(void *m, size_t i, uint8_t x) JL_NOTSAFEP STATIC_INLINE jl_value_t *jl_array_owner(jl_array_t *a JL_PROPAGATES_ROOT) JL_NOTSAFEPOINT { - return jl_memoryt_owner(a->ref.mem); + return jl_genericmemory_owner(a->ref.mem); } #ifdef __clang_gcanalyzer__ @@ -1440,8 +1440,8 @@ static inline int jl_field_isconst(jl_datatype_t *st, int i) JL_NOTSAFEPOINT #define jl_is_uint8pointer(v)jl_typetagis(v,jl_uint8pointer_type) #define jl_is_llvmpointer(v) (((jl_datatype_t*)jl_typeof(v))->name == jl_llvmpointer_typename) #define jl_is_intrinsic(v) jl_typetagis(v,jl_intrinsic_type) -#define jl_memoryt_isbitsunion(a) (((jl_datatype_t*)jl_typetagof(a))->layout->arrayelem_isunion) -#define jl_array_isbitsunion(a) (jl_memoryt_isbitsunion(((jl_array_t*)(a))->ref.mem)) +#define jl_genericmemory_isbitsunion(a) (((jl_datatype_t*)jl_typetagof(a))->layout->arrayelem_isunion) +#define jl_array_isbitsunion(a) (jl_genericmemory_isbitsunion(((jl_array_t*)(a))->ref.mem)) JL_DLLEXPORT int jl_subtype(jl_value_t *a, jl_value_t *b); @@ -1502,28 +1502,28 @@ STATIC_INLINE int jl_is_array(void *v) JL_NOTSAFEPOINT return jl_is_array_type(t); } -STATIC_INLINE int jl_is_memory_type(void *t) JL_NOTSAFEPOINT +STATIC_INLINE int jl_is_genericmemory_type(void *t) JL_NOTSAFEPOINT { return (jl_is_datatype(t) && - ((jl_datatype_t*)(t))->name == jl_memory_typename); + ((jl_datatype_t*)(t))->name == jl_genericmemory_typename); } -STATIC_INLINE int jl_is_memory(void *v) JL_NOTSAFEPOINT +STATIC_INLINE int jl_is_genericmemory(void *v) JL_NOTSAFEPOINT { jl_value_t *t = jl_typeof(v); - return jl_is_memory_type(t); + return jl_is_genericmemory_type(t); } -STATIC_INLINE int jl_is_memoryref_type(void *t) JL_NOTSAFEPOINT +STATIC_INLINE int jl_is_genericmemoryref_type(void *t) JL_NOTSAFEPOINT { return (jl_is_datatype(t) && - ((jl_datatype_t*)(t))->name == jl_memoryref_typename); + ((jl_datatype_t*)(t))->name == jl_genericmemoryref_typename); } -STATIC_INLINE int jl_is_memoryref(void *v) JL_NOTSAFEPOINT +STATIC_INLINE int jl_is_genericmemoryref(void *v) JL_NOTSAFEPOINT { jl_value_t *t = jl_typeof(v); - return jl_is_memoryref_type(t); + return jl_is_genericmemoryref_type(t); } STATIC_INLINE int jl_is_opaque_closure_type(void *t) JL_NOTSAFEPOINT @@ -1580,14 +1580,14 @@ STATIC_INLINE int jl_is_type_type(jl_value_t *v) JL_NOTSAFEPOINT ((jl_datatype_t*)(v))->name == ((jl_datatype_t*)jl_type_type->body)->name); } -STATIC_INLINE int jl_is_memoryt_zeroinit(jl_memory_t *m) JL_NOTSAFEPOINT +STATIC_INLINE int jl_is_genericmemory_zeroinit(jl_genericmemory_t *m) JL_NOTSAFEPOINT { return ((jl_datatype_t*)jl_typeof(m))->zeroinit; } STATIC_INLINE int jl_is_array_zeroinit(jl_array_t *a) JL_NOTSAFEPOINT { - return jl_is_memoryt_zeroinit(a->ref.mem); + return jl_is_genericmemory_zeroinit(a->ref.mem); } // object identity @@ -1800,27 +1800,27 @@ JL_DLLEXPORT void *jl_array_ptr(jl_array_t *a); JL_DLLEXPORT void *jl_array_eltype(jl_value_t *a); JL_DLLEXPORT int jl_array_rank(jl_value_t *a); -// memoryt -JL_DLLEXPORT jl_memory_t *jl_new_memoryt(jl_value_t *mtype, jl_value_t *dim); -JL_DLLEXPORT jl_memory_t *jl_ptr_to_memoryt(jl_value_t *mtype, void *data, +// genericmemory +JL_DLLEXPORT jl_genericmemory_t *jl_new_genericmemory(jl_value_t *mtype, jl_value_t *dim); +JL_DLLEXPORT jl_genericmemory_t *jl_ptr_to_genericmemory(jl_value_t *mtype, void *data, size_t nel, int own_buffer); -JL_DLLEXPORT jl_memory_t *jl_alloc_memoryt(jl_value_t *mtype, size_t nel); -JL_DLLEXPORT jl_memory_t *jl_pchar_to_memory(const char *str, size_t len); -JL_DLLEXPORT jl_value_t *jl_memoryt_to_string(jl_memory_t *m, size_t len); -JL_DLLEXPORT jl_memory_t *jl_alloc_memory_any(size_t n); -JL_DLLEXPORT jl_memory_t *jl_memoryt_slice(jl_memory_t *mem, size_t offset, size_t len); -JL_DLLEXPORT jl_value_t *jl_memorytref(jl_memory_t *m, size_t i); // 0-indexed -JL_DLLEXPORT void jl_memorytset(jl_memory_t *m JL_ROOTING_ARGUMENT, jl_value_t *v JL_ROOTED_ARGUMENT JL_MAYBE_UNROOTED, size_t i); // 0-indexed -JL_DLLEXPORT void jl_memorytunset(jl_memory_t *m, size_t i); // 0-indexed -JL_DLLEXPORT int jl_memoryt_isassigned(jl_memory_t *m, size_t i); // 0-indexed - -JL_DLLEXPORT jl_memoryref_t *jl_new_memoryref(jl_value_t *typ, jl_memory_t *mem, void *data); -JL_DLLEXPORT jl_value_t *jl_memoryrefget(jl_memoryref_t m JL_PROPAGATES_ROOT); -JL_DLLEXPORT jl_value_t *jl_ptrmemoryrefget(jl_memoryref_t m JL_PROPAGATES_ROOT) JL_NOTSAFEPOINT; -JL_DLLEXPORT jl_value_t *jl_memoryref_isassigned(jl_memoryref_t m) JL_GLOBALLY_ROOTED; -JL_DLLEXPORT jl_memoryref_t jl_memoryrefindex(jl_memoryref_t m JL_PROPAGATES_ROOT, size_t idx) JL_NOTSAFEPOINT; -JL_DLLEXPORT void jl_memoryrefset(jl_memoryref_t m JL_ROOTING_ARGUMENT, jl_value_t *v JL_ROOTED_ARGUMENT JL_MAYBE_UNROOTED); -JL_DLLEXPORT void jl_memoryrefunset(jl_memoryref_t m); +JL_DLLEXPORT jl_genericmemory_t *jl_alloc_genericmemory(jl_value_t *mtype, size_t nel); +JL_DLLEXPORT jl_genericmemory_t *jl_pchar_to_memory(const char *str, size_t len); +JL_DLLEXPORT jl_value_t *jl_genericmemory_to_string(jl_genericmemory_t *m, size_t len); +JL_DLLEXPORT jl_genericmemory_t *jl_alloc_memory_any(size_t n); +JL_DLLEXPORT jl_genericmemory_t *jl_genericmemory_slice(jl_genericmemory_t *mem, size_t offset, size_t len); +JL_DLLEXPORT jl_value_t *jl_genericmemoryref(jl_genericmemory_t *m, size_t i); // 0-indexed +JL_DLLEXPORT void jl_genericmemoryset(jl_genericmemory_t *m JL_ROOTING_ARGUMENT, jl_value_t *v JL_ROOTED_ARGUMENT JL_MAYBE_UNROOTED, size_t i); // 0-indexed +JL_DLLEXPORT void jl_genericmemoryunset(jl_genericmemory_t *m, size_t i); // 0-indexed +JL_DLLEXPORT int jl_genericmemory_isassigned(jl_genericmemory_t *m, size_t i); // 0-indexed + +JL_DLLEXPORT jl_genericmemoryref_t *jl_new_memoryref(jl_value_t *typ, jl_genericmemory_t *mem, void *data); +JL_DLLEXPORT jl_value_t *jl_memoryrefget(jl_genericmemoryref_t m JL_PROPAGATES_ROOT); +JL_DLLEXPORT jl_value_t *jl_ptrmemoryrefget(jl_genericmemoryref_t m JL_PROPAGATES_ROOT) JL_NOTSAFEPOINT; +JL_DLLEXPORT jl_value_t *jl_memoryref_isassigned(jl_genericmemoryref_t m) JL_GLOBALLY_ROOTED; +JL_DLLEXPORT jl_genericmemoryref_t jl_memoryrefindex(jl_genericmemoryref_t m JL_PROPAGATES_ROOT, size_t idx) JL_NOTSAFEPOINT; +JL_DLLEXPORT void jl_memoryrefset(jl_genericmemoryref_t m JL_ROOTING_ARGUMENT, jl_value_t *v JL_ROOTED_ARGUMENT JL_MAYBE_UNROOTED); +JL_DLLEXPORT void jl_memoryrefunset(jl_genericmemoryref_t m); // strings JL_DLLEXPORT const char *jl_string_ptr(jl_value_t *s); @@ -1877,10 +1877,10 @@ STATIC_INLINE jl_function_t *jl_get_function(jl_module_t *m, const char *name) } // eq hash tables -JL_DLLEXPORT jl_memory_t *jl_eqtable_put(jl_memory_t *h JL_ROOTING_ARGUMENT, jl_value_t *key, jl_value_t *val JL_ROOTED_ARGUMENT, int *inserted); -JL_DLLEXPORT jl_value_t *jl_eqtable_get(jl_memory_t *h JL_PROPAGATES_ROOT, jl_value_t *key, jl_value_t *deflt) JL_NOTSAFEPOINT; -JL_DLLEXPORT jl_value_t *jl_eqtable_pop(jl_memory_t *h, jl_value_t *key, jl_value_t *deflt, int *found); -jl_value_t *jl_eqtable_getkey(jl_memory_t *h JL_PROPAGATES_ROOT, jl_value_t *key, jl_value_t *deflt) JL_NOTSAFEPOINT; +JL_DLLEXPORT jl_genericmemory_t *jl_eqtable_put(jl_genericmemory_t *h JL_ROOTING_ARGUMENT, jl_value_t *key, jl_value_t *val JL_ROOTED_ARGUMENT, int *inserted); +JL_DLLEXPORT jl_value_t *jl_eqtable_get(jl_genericmemory_t *h JL_PROPAGATES_ROOT, jl_value_t *key, jl_value_t *deflt) JL_NOTSAFEPOINT; +JL_DLLEXPORT jl_value_t *jl_eqtable_pop(jl_genericmemory_t *h, jl_value_t *key, jl_value_t *deflt, int *found); +jl_value_t *jl_eqtable_getkey(jl_genericmemory_t *h JL_PROPAGATES_ROOT, jl_value_t *key, jl_value_t *deflt) JL_NOTSAFEPOINT; // system information JL_DLLEXPORT int jl_errno(void) JL_NOTSAFEPOINT; diff --git a/src/julia_internal.h b/src/julia_internal.h index 2cd0527d8ff647..5cacf2c6af3ef1 100644 --- a/src/julia_internal.h +++ b/src/julia_internal.h @@ -569,7 +569,7 @@ JL_DLLEXPORT void JL_NORETURN jl_throw_out_of_memory_error(void); JL_DLLEXPORT int64_t jl_gc_diff_total_bytes(void) JL_NOTSAFEPOINT; JL_DLLEXPORT int64_t jl_gc_sync_total_bytes(int64_t offset) JL_NOTSAFEPOINT; void jl_gc_track_malloced_array(jl_ptls_t ptls, jl_array_t *a) JL_NOTSAFEPOINT; -void jl_gc_track_malloced_memoryt(jl_ptls_t ptls, jl_memory_t *m, int isaligned) JL_NOTSAFEPOINT; +void jl_gc_track_malloced_genericmemory(jl_ptls_t ptls, jl_genericmemory_t *m, int isaligned) JL_NOTSAFEPOINT; void jl_gc_count_allocd(size_t sz) JL_NOTSAFEPOINT; void jl_gc_run_all_finalizers(jl_task_t *ct); void jl_release_task_stack(jl_ptls_t ptls, jl_task_t *task); @@ -786,7 +786,7 @@ JL_DLLEXPORT void jl_binding_deprecation_warning(jl_module_t *m, jl_sym_t *sym, extern jl_array_t *jl_module_init_order JL_GLOBALLY_ROOTED; extern htable_t jl_current_modules JL_GLOBALLY_ROOTED; extern JL_DLLEXPORT jl_module_t *jl_precompile_toplevel_module JL_GLOBALLY_ROOTED; -extern jl_memory_t *jl_global_roots_table JL_GLOBALLY_ROOTED; +extern jl_genericmemory_t *jl_global_roots_table JL_GLOBALLY_ROOTED; JL_DLLEXPORT int jl_is_globally_rooted(jl_value_t *val JL_MAYBE_UNROOTED) JL_NOTSAFEPOINT; JL_DLLEXPORT jl_value_t *jl_as_global_root(jl_value_t *val JL_MAYBE_UNROOTED); @@ -970,8 +970,8 @@ uint8_t jl_object_in_image(jl_value_t* v) JL_NOTSAFEPOINT; // the first argument to jl_idtable_rehash is used to return a value // make sure it is rooted if it is used after the function returns -JL_DLLEXPORT jl_memory_t *jl_idtable_rehash(jl_memory_t *a, size_t newsz); -_Atomic(jl_value_t*) *jl_table_peek_bp(jl_memory_t *a, jl_value_t *key) JL_NOTSAFEPOINT; +JL_DLLEXPORT jl_genericmemory_t *jl_idtable_rehash(jl_genericmemory_t *a, size_t newsz); +_Atomic(jl_value_t*) *jl_table_peek_bp(jl_genericmemory_t *a, jl_value_t *key) JL_NOTSAFEPOINT; JL_DLLEXPORT jl_method_t *jl_new_method_uninit(jl_module_t*); diff --git a/src/rtutils.c b/src/rtutils.c index d4246a67aef22e..ed60ad94f5a291 100644 --- a/src/rtutils.c +++ b/src/rtutils.c @@ -1072,8 +1072,8 @@ static size_t jl_static_show_x_(JL_STREAM *out, jl_value_t *v, jl_datatype_t *vt n += jl_static_show_x(out, (jl_value_t*)av->ref.mem, depth, ctx); n += jl_printf(out, ")"); } - else if (jl_memory_type && jl_is_memory_type(vt)) { - jl_memory_t *m = (jl_memory_t*)v; + else if (jl_genericmemory_type && jl_is_genericmemory_type(vt)) { + jl_genericmemory_t *m = (jl_genericmemory_t*)v; n += jl_printf(out, "GenericMemory{"); jl_value_t *isatomic = jl_tparam0(vt); n += jl_static_show_x(out, isatomic, depth, ctx); @@ -1107,7 +1107,7 @@ static size_t jl_static_show_x_(JL_STREAM *out, jl_value_t *v, jl_datatype_t *vt } } else if (jl_is_uniontype(el_type)) { - typetagdata = jl_memoryt_typetagdata(m); + typetagdata = jl_genericmemory_typetagdata(m); } if (nlsep && tlen > 1) n += jl_printf(out, "\n "); diff --git a/src/staticdata.c b/src/staticdata.c index 897d172a94e8df..960fef0d86a244 100644 --- a/src/staticdata.c +++ b/src/staticdata.c @@ -99,7 +99,7 @@ extern "C" { // TODO: put WeakRefs on the weak_refs list during deserialization // TODO: handle finalizers -#define NUM_TAGS 174 +#define NUM_TAGS 172 // An array of references that need to be restored from the sysimg // This is a manually constructed dual of the gvars array, which would be produced by codegen for Julia code, for C. @@ -198,10 +198,10 @@ jl_value_t **const*const get_tags(void) { INSERT_TAG(jl_number_type); INSERT_TAG(jl_signed_type); INSERT_TAG(jl_pair_type); - INSERT_TAG(jl_memory_type); + INSERT_TAG(jl_genericmemory_type); INSERT_TAG(jl_memory_any_type); INSERT_TAG(jl_memory_uint8_type); - INSERT_TAG(jl_memoryref_type); + INSERT_TAG(jl_genericmemoryref_type); INSERT_TAG(jl_memoryref_any_type); INSERT_TAG(jl_memoryref_uint8_type); @@ -214,8 +214,8 @@ jl_value_t **const*const get_tags(void) { INSERT_TAG(jl_namedtuple_typename); INSERT_TAG(jl_vecelement_typename); INSERT_TAG(jl_opaque_closure_typename); - INSERT_TAG(jl_memory_typename); - INSERT_TAG(jl_memoryref_typename); + INSERT_TAG(jl_genericmemory_typename); + INSERT_TAG(jl_genericmemoryref_typename); // special exceptions INSERT_TAG(jl_errorexception_type); @@ -834,11 +834,11 @@ static void jl_insert_into_serialization_queue(jl_serializer_state *s, jl_value_ jl_value_t *mem = get_replaceable_field((jl_value_t**)&ar->ref.mem, 1); jl_queue_for_serialization_(s, mem, 1, immediate); } - else if (jl_is_memory(v)) { - jl_memory_t *m = (jl_memory_t*)v; + else if (jl_is_genericmemory(v)) { + jl_genericmemory_t *m = (jl_genericmemory_t*)v; const char *data = (const char*)m->data; - if (jl_memoryt_how(m) == 3) { - jl_queue_for_serialization_(s, jl_memoryt_data_owner_field(v), 1, immediate); + if (jl_genericmemory_how(m) == 3) { + jl_queue_for_serialization_(s, jl_genericmemory_data_owner_field(v), 1, immediate); } else if (layout->arrayelem_isboxed) { size_t i, l = m->length; @@ -1168,10 +1168,10 @@ static void jl_write_module(jl_serializer_state *s, uintptr_t item, jl_module_t assert(ios_pos(s->s) - reloc_offset == tot); } -static void record_memoryref(jl_serializer_state *s, size_t reloc_offset, jl_memoryref_t ref) { +static void record_memoryref(jl_serializer_state *s, size_t reloc_offset, jl_genericmemoryref_t ref) { ios_t *f = s->s; // make some header modifications in-place - jl_memoryref_t *newref = (jl_memoryref_t*)&f->buf[reloc_offset]; + jl_genericmemoryref_t *newref = (jl_genericmemoryref_t*)&f->buf[reloc_offset]; const jl_datatype_layout_t *layout = ((jl_datatype_t*)jl_typetagof(ref.mem))->layout; if (!layout->arrayelem_isunion && layout->size != 0) { newref->data = (void*)((char*)ref.data - (char*)ref.mem->data); // relocation offset (bytes) @@ -1191,8 +1191,8 @@ static void record_memoryrefs_inside(jl_serializer_state *s, jl_datatype_t *t, s jl_value_t *ft = jl_field_type_concrete(t, i); if (jl_is_uniontype(ft)) continue; - if (jl_is_memoryref_type(ft)) - record_memoryref(s, reloc_offset + offset, *(jl_memoryref_t*)(data + offset)); + if (jl_is_genericmemoryref_type(ft)) + record_memoryref(s, reloc_offset + offset, *(jl_genericmemoryref_t*)(data + offset)); else record_memoryrefs_inside(s, (jl_datatype_t*)ft, reloc_offset + offset, data + offset); } @@ -1311,28 +1311,28 @@ static void jl_write_values(jl_serializer_state *s) JL_GC_DISABLED arraylist_push(&s->relocs_list, (void*)backref_id(s, mem, s->link_ids_relocs)); // relocation target record_memoryref(s, reloc_offset + offsetof(jl_array_t, ref), ar->ref); } - else if (jl_is_memory(v)) { + else if (jl_is_genericmemory(v)) { assert(f == s->s); - // Internal data for types in julia.h with `jl_memory_t` field(s) - jl_memory_t *m = (jl_memory_t*)v; + // Internal data for types in julia.h with `jl_genericmemory_t` field(s) + jl_genericmemory_t *m = (jl_genericmemory_t*)v; const jl_datatype_layout_t *layout = t->layout; size_t len = m->length; - if (jl_memoryt_how(m) == 3 && jl_is_memory(jl_memoryt_data_owner_field(m))) { - jl_memory_t *owner = (jl_memory_t*)jl_memoryt_data_owner_field(m); + if (jl_genericmemory_how(m) == 3 && jl_is_genericmemory(jl_genericmemory_data_owner_field(m))) { + jl_genericmemory_t *owner = (jl_genericmemory_t*)jl_genericmemory_data_owner_field(m); size_t data = ((char*)m->data - (char*)owner->data); // relocation offset (bytes) write_uint(f, len); write_uint(f, data); write_pointerfield(s, (jl_value_t*)owner); // perform record_memoryref - arraylist_push(&s->memref_list, (void*)(reloc_offset + offsetof(jl_memory_t, data))); // relocation location + arraylist_push(&s->memref_list, (void*)(reloc_offset + offsetof(jl_genericmemory_t, data))); // relocation location arraylist_push(&s->memref_list, NULL); // relocation target (ignored) } - // else if (jl_memoryt_how(m) == 3) { - // jl_value_t *owner = jl_memoryt_data_owner_field(m); + // else if (jl_genericmemory_how(m) == 3) { + // jl_value_t *owner = jl_genericmemory_data_owner_field(m); // write_uint(f, len); // write_pointerfield(s, owner); // write_pointerfield(s, owner); - // jl_memory_t *new_mem = (jl_memory_t*)&f->buf[reloc_offset]; + // jl_genericmemory_t *new_mem = (jl_genericmemory_t*)&f->buf[reloc_offset]; // assert(new_mem->data == NULL); // new_mem->data = (void*)((char*)m->data - (char*)owner); // relocation offset // } @@ -1342,7 +1342,7 @@ static void jl_write_values(jl_serializer_state *s) JL_GC_DISABLED int isbitsunion = layout->arrayelem_isunion; if (isbitsunion) tot += len; - size_t headersize = sizeof(jl_memory_t); + size_t headersize = sizeof(jl_genericmemory_t); // copy header ios_write(f, (char*)v, headersize); size_t alignment_amt = JL_SMALL_BYTE_ALIGNMENT; @@ -1357,11 +1357,11 @@ static void jl_write_values(jl_serializer_state *s) JL_GC_DISABLED uintptr_t data = LLT_ALIGN(ios_pos(s->const_data), alignment_amt); write_padding(s->const_data, data - ios_pos(s->const_data)); // write data and relocations - jl_memory_t *new_mem = (jl_memory_t*)&f->buf[reloc_offset]; + jl_genericmemory_t *new_mem = (jl_genericmemory_t*)&f->buf[reloc_offset]; new_mem->data = NULL; // relocation offset data /= sizeof(void*); assert(data < ((uintptr_t)1 << RELOC_TAG_OFFSET) && "offset to constant data too large"); - arraylist_push(&s->relocs_list, (void*)(reloc_offset + offsetof(jl_memory_t, data))); // relocation location + arraylist_push(&s->relocs_list, (void*)(reloc_offset + offsetof(jl_genericmemory_t, data))); // relocation location arraylist_push(&s->relocs_list, (void*)(((uintptr_t)ConstDataRef << RELOC_TAG_OFFSET) + data)); // relocation target jl_value_t *et = jl_tparam1(t); if (jl_is_cpointer_type(et)) { @@ -1378,7 +1378,7 @@ static void jl_write_values(jl_serializer_state *s) JL_GC_DISABLED else { if (isbitsunion) { ios_write(s->const_data, (char*)m->data, datasize); - ios_write(s->const_data, jl_memoryt_typetagdata(m), len); + ios_write(s->const_data, jl_genericmemory_typetagdata(m), len); } else { ios_write(s->const_data, (char*)m->data, tot); @@ -1386,14 +1386,14 @@ static void jl_write_values(jl_serializer_state *s) JL_GC_DISABLED } if (len == 0) // TODO: should we have a zero-page, instead of writing each type's fragment separately? write_padding(s->const_data, layout->size ? layout->size : isbitsunion); - else if (jl_memoryt_how(m) == 3 && jl_is_string(jl_memoryt_data_owner_field(m))) + else if (jl_genericmemory_how(m) == 3 && jl_is_string(jl_genericmemory_data_owner_field(m))) write_padding(s->const_data, 1); } else { // Pointer eltypes are encoded in the mutable data section size_t data = LLT_ALIGN(ios_pos(f), alignment_amt); size_t padding_amt = data - ios_pos(f); - jl_memory_t *new_mem = (jl_memory_t*)&f->buf[reloc_offset]; + jl_genericmemory_t *new_mem = (jl_genericmemory_t*)&f->buf[reloc_offset]; if (padding_amt != 0) { // set owner to NULL if we want to increase alignment // from the default of 16 @@ -1404,7 +1404,7 @@ static void jl_write_values(jl_serializer_state *s) JL_GC_DISABLED write_pointer(f); } new_mem->data = (void*)headersize; // relocation offset - arraylist_push(&s->relocs_list, (void*)(reloc_offset + offsetof(jl_memory_t, data))); // relocation location + arraylist_push(&s->relocs_list, (void*)(reloc_offset + offsetof(jl_genericmemory_t, data))); // relocation location arraylist_push(&s->relocs_list, (void*)(((uintptr_t)DataRef << RELOC_TAG_OFFSET) + item)); // relocation target if (!layout->arrayelem_isboxed) { // copy all of the data first @@ -1720,9 +1720,9 @@ static void jl_write_values(jl_serializer_state *s) JL_GC_DISABLED // will need to rehash this, later (after types are fully constructed) arraylist_push(&s->fixup_objs, (void*)reloc_offset); } - else if (jl_is_memoryref(v)) { + else if (jl_is_genericmemoryref(v)) { assert(f == s->s); - record_memoryref(s, reloc_offset, *(jl_memoryref_t*)v); + record_memoryref(s, reloc_offset, *(jl_genericmemoryref_t*)v); } else { write_padding(f, jl_datatype_size(t) - tot); @@ -1999,7 +1999,7 @@ static void jl_read_memreflist(jl_serializer_state *s) uintptr_t pos = last_pos + pos_diff; last_pos = pos; - jl_memoryref_t *pv = (jl_memoryref_t*)(base + pos); + jl_genericmemoryref_t *pv = (jl_genericmemoryref_t*)(base + pos); size_t offset = (size_t)pv->data; pv->data = (void*)((char*)pv->mem->data + offset); } @@ -2413,7 +2413,7 @@ static void jl_strip_all_codeinfos(void) // --- entry points --- -jl_memory_t *jl_global_roots_table; +jl_genericmemory_t *jl_global_roots_table; jl_mutex_t global_roots_lock; JL_DLLEXPORT int jl_is_globally_rooted(jl_value_t *val JL_MAYBE_UNROOTED) JL_NOTSAFEPOINT @@ -3049,7 +3049,7 @@ static void jl_restore_system_image_from_stream_(ios_t *f, jl_image_t *image, jl JL_SMALL_TYPEOF(XX) #undef XX export_small_typeof(); - jl_global_roots_table = (jl_memory_t*)jl_read_value(&s); + jl_global_roots_table = (jl_genericmemory_t*)jl_read_value(&s); // set typeof extra-special values now that we have the type set by tags above jl_astaggedvalue(jl_nothing)->header = (uintptr_t)jl_nothing_type | jl_astaggedvalue(jl_nothing)->header; s.ptls->root_task->tls = jl_read_value(&s); @@ -3389,7 +3389,7 @@ static void jl_restore_system_image_from_stream_(ios_t *f, jl_image_t *image, jl else { // rehash IdDict //assert(((jl_datatype_t*)(jl_typeof(obj)))->name == jl_idtable_typename); - jl_memory_t **a = (jl_memory_t**)obj; + jl_genericmemory_t **a = (jl_genericmemory_t**)obj; assert(jl_typetagis(*a, jl_memory_any_type)); *a = jl_idtable_rehash(*a, (*a)->length); jl_gc_wb(obj, *a); diff --git a/src/staticdata_utils.c b/src/staticdata_utils.c index 8436eef806aad9..6d786fd22257a8 100644 --- a/src/staticdata_utils.c +++ b/src/staticdata_utils.c @@ -1,5 +1,5 @@ // inverse of backedges graph (caller=>callees hash) -jl_memory_t *edges_map JL_GLOBALLY_ROOTED = NULL; // rooted for the duration of our uses of this +jl_genericmemory_t *edges_map JL_GLOBALLY_ROOTED = NULL; // rooted for the duration of our uses of this static void write_float64(ios_t *s, double x) JL_NOTSAFEPOINT { diff --git a/src/typemap.c b/src/typemap.c index 6760c6edd69d37..06273b83c25ad6 100644 --- a/src/typemap.c +++ b/src/typemap.c @@ -277,20 +277,20 @@ static int is_cache_leaf(jl_value_t *ty, int tparam) return (jl_is_concrete_type(ty) && (tparam || !jl_is_kind(ty))); } -static _Atomic(jl_value_t*) *mtcache_hash_lookup_bp(jl_memory_t *cache JL_PROPAGATES_ROOT, jl_value_t *ty) JL_NOTSAFEPOINT +static _Atomic(jl_value_t*) *mtcache_hash_lookup_bp(jl_genericmemory_t *cache JL_PROPAGATES_ROOT, jl_value_t *ty) JL_NOTSAFEPOINT { - if (cache == (jl_memory_t*)jl_an_empty_memory_any) + if (cache == (jl_genericmemory_t*)jl_an_empty_memory_any) return NULL; _Atomic(jl_value_t*) *pml = jl_table_peek_bp(cache, ty); JL_GC_PROMISE_ROOTED(pml); // clang-sa doesn't trust our JL_PROPAGATES_ROOT claim return pml; } -static void mtcache_hash_insert(_Atomic(jl_memory_t*) *cache, jl_value_t *parent, jl_value_t *key, jl_typemap_t *val) +static void mtcache_hash_insert(_Atomic(jl_genericmemory_t*) *cache, jl_value_t *parent, jl_value_t *key, jl_typemap_t *val) { int inserted = 0; - jl_memory_t *a = jl_atomic_load_relaxed(cache); - if (a == (jl_memory_t*)jl_an_empty_memory_any) { + jl_genericmemory_t *a = jl_atomic_load_relaxed(cache); + if (a == (jl_genericmemory_t*)jl_an_empty_memory_any) { a = jl_alloc_memory_any(16); jl_atomic_store_release(cache, a); if (parent) @@ -305,9 +305,9 @@ static void mtcache_hash_insert(_Atomic(jl_memory_t*) *cache, jl_value_t *parent } } -static jl_typemap_t *mtcache_hash_lookup(jl_memory_t *cache JL_PROPAGATES_ROOT, jl_value_t *ty) JL_NOTSAFEPOINT +static jl_typemap_t *mtcache_hash_lookup(jl_genericmemory_t *cache JL_PROPAGATES_ROOT, jl_value_t *ty) JL_NOTSAFEPOINT { - if (cache == (jl_memory_t*)jl_an_empty_memory_any) + if (cache == (jl_genericmemory_t*)jl_an_empty_memory_any) return (jl_typemap_t*)jl_nothing; jl_typemap_t *ml = (jl_typemap_t*)jl_eqtable_get(cache, ty, jl_nothing); return ml; @@ -315,7 +315,7 @@ static jl_typemap_t *mtcache_hash_lookup(jl_memory_t *cache JL_PROPAGATES_ROOT, // ----- Sorted Type Signature Lookup Matching ----- // -static int jl_typemap_memory_visitor(jl_memory_t *a, jl_typemap_visitor_fptr fptr, void *closure) +static int jl_typemap_memory_visitor(jl_genericmemory_t *a, jl_typemap_visitor_fptr fptr, void *closure) { size_t i, l = a->length; _Atomic(jl_typemap_t*) *data = (_Atomic(jl_typemap_t*)*) a->data; @@ -324,8 +324,8 @@ static int jl_typemap_memory_visitor(jl_memory_t *a, jl_typemap_visitor_fptr fpt JL_GC_PROMISE_ROOTED(d); if (d == NULL) continue; - if (jl_is_memory(d)) { - if (!jl_typemap_memory_visitor((jl_memory_t*)d, fptr, closure)) + if (jl_is_genericmemory(d)) { + if (!jl_typemap_memory_visitor((jl_genericmemory_t*)d, fptr, closure)) return 0; } else { @@ -352,22 +352,22 @@ int jl_typemap_visitor(jl_typemap_t *cache, jl_typemap_visitor_fptr fptr, void * { if (jl_typeof(cache) == (jl_value_t*)jl_typemap_level_type) { jl_typemap_level_t *node = (jl_typemap_level_t*)cache; - jl_memory_t *a; + jl_genericmemory_t *a; JL_GC_PUSH1(&a); a = jl_atomic_load_relaxed(&node->targ); - if (a != (jl_memory_t*)jl_an_empty_memory_any) + if (a != (jl_genericmemory_t*)jl_an_empty_memory_any) if (!jl_typemap_memory_visitor(a, fptr, closure)) goto exit; a = jl_atomic_load_relaxed(&node->arg1); - if (a != (jl_memory_t*)jl_an_empty_memory_any) + if (a != (jl_genericmemory_t*)jl_an_empty_memory_any) if (!jl_typemap_memory_visitor(a, fptr, closure)) goto exit; a = jl_atomic_load_relaxed(&node->tname); - if (a != (jl_memory_t*)jl_an_empty_memory_any) + if (a != (jl_genericmemory_t*)jl_an_empty_memory_any) if (!jl_typemap_memory_visitor(a, fptr, closure)) goto exit; a = jl_atomic_load_relaxed(&node->name1); - if (a != (jl_memory_t*)jl_an_empty_memory_any) + if (a != (jl_genericmemory_t*)jl_an_empty_memory_any) if (!jl_typemap_memory_visitor(a, fptr, closure)) goto exit; if (!jl_typemap_node_visitor(jl_atomic_load_relaxed(&node->linear), fptr, closure)) @@ -451,7 +451,7 @@ static int concrete_intersects(jl_value_t *t, jl_value_t *ty, int8_t tparam) // tparam bit 0 is ::Type{T} (vs. T) // tparam bit 1 is typename(T) (vs. T) -static int jl_typemap_intersection_memory_visitor(jl_memory_t *a, jl_value_t *ty, int8_t tparam, +static int jl_typemap_intersection_memory_visitor(jl_genericmemory_t *a, jl_value_t *ty, int8_t tparam, int8_t offs, struct typemap_intersection_env *closure) { JL_GC_PUSH1(&a); @@ -492,8 +492,8 @@ static int jl_typemap_intersection_memory_visitor(jl_memory_t *a, jl_value_t *ty tname_intersection_dt(tydt, (jl_typename_t*)t, height)) { if ((tparam & 1) && t == (jl_value_t*)jl_typeofbottom_type->name) // skip Type{Union{}} and Type{typeof(Union{})}, since the caller should have already handled those continue; - if (jl_is_memory(ml)) { - if (!jl_typemap_intersection_memory_visitor((jl_memory_t*)ml, ty, tparam & ~2, offs, closure)) + if (jl_is_genericmemory(ml)) { + if (!jl_typemap_intersection_memory_visitor((jl_genericmemory_t*)ml, ty, tparam & ~2, offs, closure)) goto exit; } else { @@ -627,15 +627,15 @@ int jl_typemap_intersection_visitor(jl_typemap_t *map, int offs, if (jl_has_free_typevars(ty)) ty = jl_rewrap_unionall(ty, closure->type); JL_GC_PUSH1(&ty); - jl_memory_t *targ = jl_atomic_load_relaxed(&cache->targ); - jl_memory_t *tname = jl_atomic_load_relaxed(&cache->tname); + jl_genericmemory_t *targ = jl_atomic_load_relaxed(&cache->targ); + jl_genericmemory_t *tname = jl_atomic_load_relaxed(&cache->tname); int maybe_type = 0; int maybe_kind = 0; int exclude_typeofbottom = 0; jl_value_t *typetype = NULL; jl_value_t *name = NULL; // pre-check: optimized pre-intersection test to see if `ty` could intersect with any Type or Kind - if (targ != (jl_memory_t*)jl_an_empty_memory_any || tname != (jl_memory_t*)jl_an_empty_memory_any) { + if (targ != (jl_genericmemory_t*)jl_an_empty_memory_any || tname != (jl_genericmemory_t*)jl_an_empty_memory_any) { maybe_kind = jl_has_intersect_kind_not_type(ty); maybe_type = maybe_kind || jl_has_intersect_type_not_kind(ty); if (maybe_type && !maybe_kind) { @@ -651,7 +651,7 @@ int jl_typemap_intersection_visitor(jl_typemap_t *map, int offs, } } // First check for intersections with methods defined on Type{T}, where T was a concrete type - if (targ != (jl_memory_t*)jl_an_empty_memory_any && maybe_type && + if (targ != (jl_genericmemory_t*)jl_an_empty_memory_any && maybe_type && (!typetype || jl_has_free_typevars(typetype) || is_cache_leaf(typetype, 1))) { // otherwise cannot contain this particular kind, so don't bother with checking if (!exclude_typeofbottom) { // detect Type{Union{}}, Type{Type{Union{}}}, and Type{typeof(Union{}} and do those early here @@ -680,18 +680,18 @@ int jl_typemap_intersection_visitor(jl_typemap_t *map, int offs, // attempt semi-direct lookup of types via their names // consider the type name first jl_value_t *ml = mtcache_hash_lookup(targ, (jl_value_t*)name); - if (jl_is_memory(ml)) { + if (jl_is_genericmemory(ml)) { if (typetype && !jl_has_free_typevars(typetype)) { // direct lookup of leaf types if (is_cache_leaf(typetype, 1)) { - ml = mtcache_hash_lookup((jl_memory_t*)ml, typetype); + ml = mtcache_hash_lookup((jl_genericmemory_t*)ml, typetype); if (ml != jl_nothing) { if (!jl_typemap_intersection_visitor((jl_typemap_t*)ml, offs+1, closure)) { JL_GC_POP(); return 0; } } } } else { - if (!jl_typemap_intersection_memory_visitor((jl_memory_t*)ml, ty, 1, offs, closure)) { JL_GC_POP(); return 0; } + if (!jl_typemap_intersection_memory_visitor((jl_genericmemory_t*)ml, ty, 1, offs, closure)) { JL_GC_POP(); return 0; } } } else if (ml != jl_nothing) { @@ -704,14 +704,14 @@ int jl_typemap_intersection_visitor(jl_typemap_t *map, int offs, } } } - jl_memory_t *cachearg1 = jl_atomic_load_relaxed(&cache->arg1); - if (cachearg1 != (jl_memory_t*)jl_an_empty_memory_any) { + jl_genericmemory_t *cachearg1 = jl_atomic_load_relaxed(&cache->arg1); + if (cachearg1 != (jl_genericmemory_t*)jl_an_empty_memory_any) { if (is_cache_leaf(ty, 0)) { jl_typename_t *name = ty == jl_bottom_type ? jl_typeofbottom_type->name : ((jl_datatype_t*)ty)->name; // direct lookup of leaf types jl_value_t *ml = mtcache_hash_lookup(cachearg1, (jl_value_t*)name); - if (jl_is_memory(ml)) - ml = mtcache_hash_lookup((jl_memory_t*)ml, ty); + if (jl_is_genericmemory(ml)) + ml = mtcache_hash_lookup((jl_genericmemory_t*)ml, ty); if (ml != jl_nothing) { if (!jl_typemap_intersection_visitor(ml, offs+1, closure)) { JL_GC_POP(); return 0; } } @@ -721,8 +721,8 @@ int jl_typemap_intersection_visitor(jl_typemap_t *map, int offs, if (name && jl_type_extract_name_precise(ty, 0)) { // direct lookup of leaf types jl_value_t *ml = mtcache_hash_lookup(cachearg1, name); - if (jl_is_memory(ml)) { - if (!jl_typemap_intersection_memory_visitor((jl_memory_t*)ml, ty, 0, offs, closure)) { JL_GC_POP(); return 0; } + if (jl_is_genericmemory(ml)) { + if (!jl_typemap_intersection_memory_visitor((jl_genericmemory_t*)ml, ty, 0, offs, closure)) { JL_GC_POP(); return 0; } } else { if (!jl_typemap_intersection_visitor((jl_typemap_t*)ml, offs+1, closure)) { JL_GC_POP(); return 0; } @@ -735,7 +735,7 @@ int jl_typemap_intersection_visitor(jl_typemap_t *map, int offs, } } // Next check for intersections with methods defined on Type{T}, where T was not concrete (it might even have been a TypeVar), but had an extractable TypeName - if (tname != (jl_memory_t*)jl_an_empty_memory_any && maybe_type) { + if (tname != (jl_genericmemory_t*)jl_an_empty_memory_any && maybe_type) { if (!exclude_typeofbottom || (!typetype && jl_isa((jl_value_t*)jl_typeofbottom_type, ty))) { // detect Type{Union{}}, Type{Type{Union{}}}, and Type{typeof(Union{}} and do those early here // otherwise the possibility of encountering `Type{Union{}}` in this intersection may @@ -780,8 +780,8 @@ int jl_typemap_intersection_visitor(jl_typemap_t *map, int offs, if (!jl_typemap_intersection_memory_visitor(tname, exclude_typeofbottom && !maybe_kind ? ty : (jl_value_t*)jl_any_type, 3, offs, closure)) { JL_GC_POP(); return 0; } } } - jl_memory_t *name1 = jl_atomic_load_relaxed(&cache->name1); - if (name1 != (jl_memory_t*)jl_an_empty_memory_any) { + jl_genericmemory_t *name1 = jl_atomic_load_relaxed(&cache->name1); + if (name1 != (jl_genericmemory_t*)jl_an_empty_memory_any) { jl_value_t *name = jl_type_extract_name(ty); if (name && jl_type_extract_name_precise(ty, 0)) { jl_datatype_t *super = (jl_datatype_t*)jl_unwrap_unionall(((jl_typename_t*)name)->wrapper); @@ -989,12 +989,12 @@ jl_typemap_entry_t *jl_typemap_assoc_by_type( if (jl_is_type_type(ty)) { jl_value_t *a0 = jl_tparam0(ty); if (is_cache_leaf(a0, 1)) { - jl_memory_t *targ = jl_atomic_load_relaxed(&cache->targ); - if (targ != (jl_memory_t*)jl_an_empty_memory_any) { + jl_genericmemory_t *targ = jl_atomic_load_relaxed(&cache->targ); + if (targ != (jl_genericmemory_t*)jl_an_empty_memory_any) { jl_typename_t *name = a0 == jl_bottom_type ? jl_typeofbottom_type->name : ((jl_datatype_t*)a0)->name; jl_value_t *ml = mtcache_hash_lookup(targ, (jl_value_t*)name); - if (jl_is_memory(ml)) - ml = mtcache_hash_lookup((jl_memory_t*)ml, a0); + if (jl_is_genericmemory(ml)) + ml = mtcache_hash_lookup((jl_genericmemory_t*)ml, a0); if (ml != jl_nothing) { jl_typemap_entry_t *li = jl_typemap_assoc_by_type((jl_typemap_t*)ml, search, offs + 1, subtype); if (li) return li; @@ -1004,12 +1004,12 @@ jl_typemap_entry_t *jl_typemap_assoc_by_type( } } if (is_cache_leaf(ty, 0)) { - jl_memory_t *cachearg1 = jl_atomic_load_relaxed(&cache->arg1); - if (cachearg1 != (jl_memory_t*)jl_an_empty_memory_any) { + jl_genericmemory_t *cachearg1 = jl_atomic_load_relaxed(&cache->arg1); + if (cachearg1 != (jl_genericmemory_t*)jl_an_empty_memory_any) { jl_typename_t *name = ty == jl_bottom_type ? jl_typeofbottom_type->name : ((jl_datatype_t*)ty)->name; jl_value_t *ml = mtcache_hash_lookup(cachearg1, (jl_value_t*)name); - if (jl_is_memory(ml)) - ml = mtcache_hash_lookup((jl_memory_t*)ml, ty); + if (jl_is_genericmemory(ml)) + ml = mtcache_hash_lookup((jl_genericmemory_t*)ml, ty); if (ml != jl_nothing) { jl_typemap_entry_t *li = jl_typemap_assoc_by_type((jl_typemap_t*)ml, search, offs + 1, subtype); if (li) return li; @@ -1020,8 +1020,8 @@ jl_typemap_entry_t *jl_typemap_assoc_by_type( } if (ty || subtype) { // now look at the optimized TypeName caches - jl_memory_t *tname = jl_atomic_load_relaxed(&cache->tname); - if (tname != (jl_memory_t*)jl_an_empty_memory_any) { + jl_genericmemory_t *tname = jl_atomic_load_relaxed(&cache->tname); + if (tname != (jl_genericmemory_t*)jl_an_empty_memory_any) { jl_value_t *a0 = ty && jl_is_type_type(ty) ? jl_type_extract_name(jl_tparam0(ty)) : NULL; if (a0) { // TODO: if we start analyzing Union types in jl_type_extract_name, then a0 might be over-approximated here, leading us to miss possible subtypes jl_datatype_t *super = (jl_datatype_t*)jl_unwrap_unionall(((jl_typename_t*)a0)->wrapper); @@ -1039,7 +1039,7 @@ jl_typemap_entry_t *jl_typemap_assoc_by_type( } else { if (!ty || !jl_has_empty_intersection((jl_value_t*)jl_type_type, ty)) { - jl_memory_t *tname = jl_atomic_load_relaxed(&cache->tname); // reload after type-intersect + jl_genericmemory_t *tname = jl_atomic_load_relaxed(&cache->tname); // reload after type-intersect // couldn't figure out unique `a0` initial point, so scan all for matches size_t i, l = tname->length; _Atomic(jl_typemap_t*) *data = (_Atomic(jl_typemap_t*)*) tname->data; @@ -1058,8 +1058,8 @@ jl_typemap_entry_t *jl_typemap_assoc_by_type( } } } - jl_memory_t *name1 = jl_atomic_load_relaxed(&cache->name1); - if (name1 != (jl_memory_t*)jl_an_empty_memory_any) { + jl_genericmemory_t *name1 = jl_atomic_load_relaxed(&cache->name1); + if (name1 != (jl_genericmemory_t*)jl_an_empty_memory_any) { if (ty) { jl_value_t *a0 = jl_type_extract_name(ty); if (a0) { // TODO: if we start analyzing Union types in jl_type_extract_name, then a0 might be over-approximated here, leading us to miss possible subtypes @@ -1199,26 +1199,26 @@ jl_typemap_entry_t *jl_typemap_level_assoc_exact(jl_typemap_level_t *cache, jl_v jl_value_t *a1 = (offs == 0 ? arg1 : args[offs - 1]); jl_value_t *ty = jl_typeof(a1); assert(jl_is_datatype(ty)); - jl_memory_t *targ = jl_atomic_load_relaxed(&cache->targ); - if (targ != (jl_memory_t*)jl_an_empty_memory_any && is_cache_leaf(a1, 1)) { + jl_genericmemory_t *targ = jl_atomic_load_relaxed(&cache->targ); + if (targ != (jl_genericmemory_t*)jl_an_empty_memory_any && is_cache_leaf(a1, 1)) { jl_typename_t *name = a1 == jl_bottom_type ? jl_typeofbottom_type->name : ((jl_datatype_t*)a1)->name; jl_value_t *ml_or_cache = mtcache_hash_lookup(targ, (jl_value_t*)name); - if (jl_is_memory(ml_or_cache)) - ml_or_cache = mtcache_hash_lookup((jl_memory_t*)ml_or_cache, a1); + if (jl_is_genericmemory(ml_or_cache)) + ml_or_cache = mtcache_hash_lookup((jl_genericmemory_t*)ml_or_cache, a1); jl_typemap_entry_t *ml = jl_typemap_assoc_exact(ml_or_cache, arg1, args, n, offs+1, world); if (ml) return ml; } - jl_memory_t *cachearg1 = jl_atomic_load_relaxed(&cache->arg1); - if (cachearg1 != (jl_memory_t*)jl_an_empty_memory_any && is_cache_leaf(ty, 0)) { + jl_genericmemory_t *cachearg1 = jl_atomic_load_relaxed(&cache->arg1); + if (cachearg1 != (jl_genericmemory_t*)jl_an_empty_memory_any && is_cache_leaf(ty, 0)) { jl_typename_t *name = ty == jl_bottom_type ? jl_typeofbottom_type->name : ((jl_datatype_t*)ty)->name; jl_value_t *ml_or_cache = mtcache_hash_lookup(cachearg1, (jl_value_t*)name); - if (jl_is_memory(ml_or_cache)) - ml_or_cache = mtcache_hash_lookup((jl_memory_t*)ml_or_cache, ty); + if (jl_is_genericmemory(ml_or_cache)) + ml_or_cache = mtcache_hash_lookup((jl_genericmemory_t*)ml_or_cache, ty); jl_typemap_entry_t *ml = jl_typemap_assoc_exact((jl_typemap_t*)ml_or_cache, arg1, args, n, offs+1, world); if (ml) return ml; } - jl_memory_t *tname = jl_atomic_load_relaxed(&cache->tname); - if (jl_is_kind(ty) && tname != (jl_memory_t*)jl_an_empty_memory_any) { + jl_genericmemory_t *tname = jl_atomic_load_relaxed(&cache->tname); + if (jl_is_kind(ty) && tname != (jl_genericmemory_t*)jl_an_empty_memory_any) { jl_value_t *name = jl_type_extract_name(a1); if (name) { if (ty != (jl_value_t*)jl_datatype_type) @@ -1252,8 +1252,8 @@ jl_typemap_entry_t *jl_typemap_level_assoc_exact(jl_typemap_level_t *cache, jl_v JL_GC_POP(); } } - jl_memory_t *name1 = jl_atomic_load_relaxed(&cache->name1); - if (name1 != (jl_memory_t*)jl_an_empty_memory_any) { + jl_genericmemory_t *name1 = jl_atomic_load_relaxed(&cache->name1); + if (name1 != (jl_genericmemory_t*)jl_an_empty_memory_any) { while (1) { name1 = jl_atomic_load_relaxed(&cache->name1); // reload after tree descent (which may hit safepoints) jl_typemap_t *ml_or_cache = mtcache_hash_lookup( @@ -1298,17 +1298,17 @@ static jl_typemap_level_t *jl_new_typemap_level(void) jl_typemap_level_t *cache = (jl_typemap_level_t*)jl_gc_alloc(ct->ptls, sizeof(jl_typemap_level_t), jl_typemap_level_type); - jl_atomic_store_relaxed(&cache->arg1, (jl_memory_t*)jl_an_empty_memory_any); - jl_atomic_store_relaxed(&cache->targ, (jl_memory_t*)jl_an_empty_memory_any); - jl_atomic_store_relaxed(&cache->name1, (jl_memory_t*)jl_an_empty_memory_any); - jl_atomic_store_relaxed(&cache->tname, (jl_memory_t*)jl_an_empty_memory_any); + jl_atomic_store_relaxed(&cache->arg1, (jl_genericmemory_t*)jl_an_empty_memory_any); + jl_atomic_store_relaxed(&cache->targ, (jl_genericmemory_t*)jl_an_empty_memory_any); + jl_atomic_store_relaxed(&cache->name1, (jl_genericmemory_t*)jl_an_empty_memory_any); + jl_atomic_store_relaxed(&cache->tname, (jl_genericmemory_t*)jl_an_empty_memory_any); jl_atomic_store_relaxed(&cache->linear, (jl_typemap_entry_t*)jl_nothing); jl_atomic_store_relaxed(&cache->any, jl_nothing); return cache; } static void jl_typemap_memory_insert_( - jl_typemap_t *map, _Atomic(jl_memory_t*) *pcache, jl_value_t *key, jl_typemap_entry_t *newrec, + jl_typemap_t *map, _Atomic(jl_genericmemory_t*) *pcache, jl_value_t *key, jl_typemap_entry_t *newrec, jl_value_t *parent, int8_t tparam, int8_t offs, jl_value_t *doublesplit); static jl_value_t *jl_method_convert_list_to_cache( @@ -1337,7 +1337,7 @@ static jl_value_t *jl_method_convert_list_to_cache( assert(jl_is_type_type(key)); key = jl_tparam0(key); } - jl_typemap_memory_insert_(map, (_Atomic(jl_memory_t*)*)&cache, key, ml, NULL, 0, offs, NULL); + jl_typemap_memory_insert_(map, (_Atomic(jl_genericmemory_t*)*)&cache, key, ml, NULL, 0, offs, NULL); } else jl_typemap_level_insert_(map, (jl_typemap_level_t*)cache, ml, offs); @@ -1372,9 +1372,9 @@ static void jl_typemap_insert_generic( jl_typemap_entry_t *newrec, int8_t tparam, int8_t offs, jl_value_t *doublesplit) { jl_value_t *ml = jl_atomic_load_relaxed(pml); - if (jl_is_memory(ml)) { + if (jl_is_genericmemory(ml)) { assert(doublesplit); - jl_typemap_memory_insert_(map, (_Atomic(jl_memory_t*)*)pml, doublesplit, newrec, parent, 0, offs, NULL); + jl_typemap_memory_insert_(map, (_Atomic(jl_genericmemory_t*)*)pml, doublesplit, newrec, parent, 0, offs, NULL); return; } if (jl_typeof(ml) == (jl_value_t*)jl_typemap_level_type) { @@ -1390,7 +1390,7 @@ static void jl_typemap_insert_generic( jl_atomic_store_release(pml, ml); jl_gc_wb(parent, ml); if (doublesplit) - jl_typemap_memory_insert_(map, (_Atomic(jl_memory_t*)*)pml, doublesplit, newrec, parent, 0, offs, NULL); + jl_typemap_memory_insert_(map, (_Atomic(jl_genericmemory_t*)*)pml, doublesplit, newrec, parent, 0, offs, NULL); else jl_typemap_level_insert_(map, (jl_typemap_level_t*)ml, newrec, offs); return; @@ -1401,10 +1401,10 @@ static void jl_typemap_insert_generic( } static void jl_typemap_memory_insert_( - jl_typemap_t *map, _Atomic(jl_memory_t*) *pcache, jl_value_t *key, jl_typemap_entry_t *newrec, + jl_typemap_t *map, _Atomic(jl_genericmemory_t*) *pcache, jl_value_t *key, jl_typemap_entry_t *newrec, jl_value_t *parent, int8_t tparam, int8_t offs, jl_value_t *doublesplit) { - jl_memory_t *cache = jl_atomic_load_relaxed(pcache); + jl_genericmemory_t *cache = jl_atomic_load_relaxed(pcache); _Atomic(jl_value_t*) *pml = mtcache_hash_lookup_bp(cache, key); if (pml == NULL) mtcache_hash_insert(pcache, parent, key, (jl_typemap_t*)newrec);