forward type alignment information to seqs (#12430)
This commit is contained in:
parent
a8f030fea2
commit
4005f0d0e4
25 changed files with 152 additions and 114 deletions
|
|
@ -1,4 +1,6 @@
|
|||
|
||||
|
||||
|
||||
proc boehmGCinit {.importc: "GC_init", boehmGC.}
|
||||
proc boehmGC_disable {.importc: "GC_disable", boehmGC.}
|
||||
proc boehmGC_enable {.importc: "GC_enable", boehmGC.}
|
||||
|
|
@ -96,6 +98,7 @@ proc initGC() =
|
|||
proc boehmgc_finalizer(obj: pointer, typedFinalizer: (proc(x: pointer) {.cdecl.})) =
|
||||
typedFinalizer(obj)
|
||||
|
||||
|
||||
proc newObj(typ: PNimType, size: int): pointer {.compilerproc.} =
|
||||
if ntfNoRefs in typ.flags: result = allocAtomic(size)
|
||||
else: result = alloc(size)
|
||||
|
|
@ -103,7 +106,7 @@ proc newObj(typ: PNimType, size: int): pointer {.compilerproc.} =
|
|||
boehmRegisterFinalizer(result, boehmgc_finalizer, typ.finalizer, nil, nil)
|
||||
{.push overflowChecks: on.}
|
||||
proc newSeq(typ: PNimType, len: int): pointer {.compilerproc.} =
|
||||
result = newObj(typ, len * typ.base.size + GenericSeqSize)
|
||||
result = newObj(typ, align(GenericSeqSize, typ.base.align) + len * typ.base.size)
|
||||
cast[PGenericSeq](result).len = len
|
||||
cast[PGenericSeq](result).reserved = len
|
||||
{.pop.}
|
||||
|
|
@ -135,4 +138,3 @@ proc deallocOsPages(r: var MemRegion) {.inline.} = discard
|
|||
proc deallocOsPages() {.inline.} = discard
|
||||
|
||||
include "system/cellsets"
|
||||
|
||||
|
|
|
|||
|
|
@ -101,28 +101,32 @@ proc newObjNoInit(typ: PNimType, size: int): pointer =
|
|||
writebarrierptr(addr(result), newObj(typ, size))
|
||||
|
||||
proc newSeq(typ: PNimType, len: int): pointer {.compilerproc.} =
|
||||
writebarrierptr(addr(result), newObj(typ, len * typ.base.size + GenericSeqSize))
|
||||
writebarrierptr(addr(result), newObj(typ, align(GenericSeqSize, typ.base.align) + len * typ.base.size))
|
||||
cast[PGenericSeq](result).len = len
|
||||
cast[PGenericSeq](result).reserved = len
|
||||
cast[PGenericSeq](result).elemSize = typ.base.size
|
||||
cast[PGenericSeq](result).elemAlign = typ.base.align
|
||||
|
||||
proc newSeqRC1(typ: PNimType, len: int): pointer {.compilerRtl.} =
|
||||
writebarrierptr(addr(result), newSeq(typ, len))
|
||||
|
||||
proc nimNewSeqOfCap(typ: PNimType, cap: int): pointer {.compilerproc.} =
|
||||
result = newObj(typ, cap * typ.base.size + GenericSeqSize)
|
||||
result = newObj(typ, align(GenericSeqSize, typ.base.align) + cap * typ.base.size)
|
||||
cast[PGenericSeq](result).len = 0
|
||||
cast[PGenericSeq](result).reserved = cap
|
||||
cast[PGenericSeq](result).elemSize = typ.base.size
|
||||
cast[PGenericSeq](result).elemAlign = typ.base.align
|
||||
|
||||
proc typedMemMove(dest: pointer, src: pointer, size: uint) {.importc: "typedmemmove", dynlib: goLib.}
|
||||
|
||||
proc growObj(old: pointer, newsize: int): pointer =
|
||||
# the Go GC doesn't have a realloc
|
||||
let old = cast[PGenericSeq](old)
|
||||
var metadataOld = cast[PGenericSeq](old)
|
||||
if metadataOld.elemSize == 0:
|
||||
metadataOld.elemSize = 1
|
||||
let oldsize = cast[PGenericSeq](old).len * cast[PGenericSeq](old).elemSize + GenericSeqSize
|
||||
|
||||
let oldsize = align(GenericSeqSize, old.elemAlign) + old.len * old.elemSize
|
||||
writebarrierptr(addr(result), goMalloc(newsize.uint))
|
||||
typedMemMove(result, old, oldsize.uint)
|
||||
|
||||
|
|
@ -149,4 +153,3 @@ proc alloc0(r: var MemRegion, size: int): pointer =
|
|||
proc dealloc(r: var MemRegion, p: pointer) = dealloc(p)
|
||||
proc deallocOsPages(r: var MemRegion) {.inline.} = discard
|
||||
proc deallocOsPages() {.inline.} = discard
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ proc newObjNoInit(typ: PNimType, size: int): pointer =
|
|||
|
||||
{.push overflowChecks: on.}
|
||||
proc newSeq(typ: PNimType, len: int): pointer {.compilerproc.} =
|
||||
result = newObj(typ, len * typ.base.size + GenericSeqSize)
|
||||
result = newObj(typ, align(GenericSeqSize, typ.align) + len * typ.base.size)
|
||||
cast[PGenericSeq](result).len = len
|
||||
cast[PGenericSeq](result).reserved = len
|
||||
{.pop.}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue