Got rid of pointer tagging (was probably useless)
This commit is contained in:
parent
2d9a6b9a8d
commit
3e9b84fb4f
|
@ -111,11 +111,6 @@ proc newPeonGC*: PeonGC =
|
||||||
proc collect*(self: var PeonVM)
|
proc collect*(self: var PeonVM)
|
||||||
|
|
||||||
|
|
||||||
# Our pointer tagging routines
|
|
||||||
template tag(p: untyped): untyped = cast[pointer](cast[uint64](p) or (1'u64 shl 63'u64))
|
|
||||||
template untag(p: untyped): untyped = cast[pointer](cast[uint64](p) and 0x7fffffffffffffff'u64)
|
|
||||||
template getTag(p: untyped): untyped = (p and (1'u64 shl 63'u64)) == 0
|
|
||||||
|
|
||||||
|
|
||||||
proc reallocate*(self: var PeonVM, p: pointer, oldSize: int, newSize: int): pointer =
|
proc reallocate*(self: var PeonVM, p: pointer, oldSize: int, newSize: int): pointer =
|
||||||
## Simple wrapper around realloc with
|
## Simple wrapper around realloc with
|
||||||
|
@ -147,7 +142,7 @@ proc reallocate*(self: var PeonVM, p: pointer, oldSize: int, newSize: int): poin
|
||||||
else:
|
else:
|
||||||
if self.gc.bytesAllocated.current >= self.gc.nextGC:
|
if self.gc.bytesAllocated.current >= self.gc.nextGC:
|
||||||
self.collect()
|
self.collect()
|
||||||
result = tag(realloc(untag(p), newSize))
|
result = realloc(p, newSize)
|
||||||
except NilAccessDefect:
|
except NilAccessDefect:
|
||||||
stderr.writeLine("Peon: could not manage memory, segmentation fault")
|
stderr.writeLine("Peon: could not manage memory, segmentation fault")
|
||||||
quit(139) # For now, there's not much we can do if we can't get the memory we need, so we exit
|
quit(139) # For now, there's not much we can do if we can't get the memory we need, so we exit
|
||||||
|
@ -178,12 +173,12 @@ proc allocate(self: var PeonVM, kind: ObjectKind, size: typedesc, count: int): p
|
||||||
## Allocates an object on the heap and adds its
|
## Allocates an object on the heap and adds its
|
||||||
## location to the internal pointer list of the
|
## location to the internal pointer list of the
|
||||||
## garbage collector
|
## garbage collector
|
||||||
result = cast[ptr HeapObject](untag(self.reallocate(nil, 0, sizeof(HeapObject))))
|
result = cast[ptr HeapObject](self.reallocate(nil, 0, sizeof(HeapObject)))
|
||||||
setkind(result[], kind, kind)
|
setkind(result[], kind, kind)
|
||||||
result.marked = false
|
result.marked = false
|
||||||
case kind:
|
case kind:
|
||||||
of String:
|
of String:
|
||||||
result.str = cast[ptr UncheckedArray[char]](untag(self.reallocate(nil, 0, sizeof(size) * count)))
|
result.str = cast[ptr UncheckedArray[char]](self.reallocate(nil, 0, sizeof(size) * count))
|
||||||
result.len = count
|
result.len = count
|
||||||
else:
|
else:
|
||||||
discard # TODO
|
discard # TODO
|
||||||
|
@ -228,13 +223,9 @@ proc markRoots(self: var PeonVM): HashSet[ptr HeapObject] =
|
||||||
# This should resolve the potential memory leak (hopefully)
|
# This should resolve the potential memory leak (hopefully)
|
||||||
var result = initHashSet[uint64](self.gc.pointers.len())
|
var result = initHashSet[uint64](self.gc.pointers.len())
|
||||||
for obj in self.calls:
|
for obj in self.calls:
|
||||||
if not obj.getTag():
|
|
||||||
continue
|
|
||||||
if obj in self.gc.pointers:
|
if obj in self.gc.pointers:
|
||||||
result.incl(obj)
|
result.incl(obj)
|
||||||
for obj in self.operands:
|
for obj in self.operands:
|
||||||
if not obj.getTag():
|
|
||||||
continue
|
|
||||||
if obj in self.gc.pointers:
|
if obj in self.gc.pointers:
|
||||||
result.incl(obj)
|
result.incl(obj)
|
||||||
var obj: ptr HeapObject
|
var obj: ptr HeapObject
|
||||||
|
|
Loading…
Reference in New Issue