[pypy-svn] r16491 - in pypy/dist/pypy/rpython/memory: . test
cfbolz at codespeak.net
cfbolz at codespeak.net
Thu Aug 25 15:18:28 CEST 2005
Author: cfbolz
Date: Thu Aug 25 15:18:27 2005
New Revision: 16491
Modified:
pypy/dist/pypy/rpython/memory/gc.py
pypy/dist/pypy/rpython/memory/gcwrapper.py
pypy/dist/pypy/rpython/memory/test/test_gc.py
Log:
fixed bug: the roots were never changed. ouch. the copying collector now seems
to work reasonably except for the fact that the heapsize is never increased.
Modified: pypy/dist/pypy/rpython/memory/gc.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/gc.py (original)
+++ pypy/dist/pypy/rpython/memory/gc.py Thu Aug 25 15:18:27 2005
@@ -129,6 +129,9 @@
totalsize = size + self.size_gc_header()
if self.free + totalsize > self.top_of_space:
self.collect()
+ #XXX need to increase the space size if the object is too big
+ #for bonus points do big blocks differently
+ return self.malloc(typeid, length)
result = self.free
self.init_gc_object(result, typeid)
print "mallocing %s, size %s at %s" % (typeid, size, result)
@@ -156,8 +159,9 @@
def copy(self, obj):
if not self.fromspace <= obj < self.fromspace + self.space_size:
return self.copy_non_managed_obj(obj)
- print "copying regularly", obj
+ print "copying regularly", obj,
if self.is_forwared(obj):
+ print "already copied to", self.get_forwarding_address(obj)
return self.get_forwarding_address(obj)
else:
newaddr = self.free
@@ -165,11 +169,12 @@
raw_memcopy(obj - self.size_gc_header(), newaddr, totalsize)
self.free += totalsize
newobj = newaddr + self.size_gc_header()
+ print "to", newobj
self.set_forwarding_address(obj, newobj)
return newobj
def copy_non_managed_obj(self, obj): #umph, PBCs, not really copy
- print "copying nonmanaged", obj
+ print "copying nonmanaged", obj, self.objectmodel.types[obj.signed[-1]]
#we have to do the tracing here because PBCs are not moved to tospace
self.trace_and_copy(obj)
return obj
@@ -197,14 +202,14 @@
pointer.address[0] = self.copy(pointer.address[0])
def is_forwared(self, obj):
- return (obj - self.size_gc_header()).signed[1] == -1
+ return (obj - self.size_gc_header()).signed[1] < 0
def get_forwarding_address(self, obj):
return (obj - self.size_gc_header()).address[0]
def set_forwarding_address(self, obj, newobj):
gc_info = obj - self.size_gc_header()
- gc_info.signed[1] = -1
+ gc_info.signed[1] = -gc_info.signed[1] - 1
gc_info.address[0] = newobj
def get_size(self, obj):
Modified: pypy/dist/pypy/rpython/memory/gcwrapper.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/gcwrapper.py (original)
+++ pypy/dist/pypy/rpython/memory/gcwrapper.py Thu Aug 25 15:18:27 2005
@@ -115,6 +115,6 @@
def malloc(self, TYPE, size=0):
typeid = self.objectmodel.get_typeid(TYPE)
address = self.gc.malloc(typeid, size)
- return lltypesimulation.init_object_on_address(address, TYPE, size)
+ result = lltypesimulation.init_object_on_address(address, TYPE, size)
self.objectmodel.update_changed_addresses()
return result
Modified: pypy/dist/pypy/rpython/memory/test/test_gc.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/test/test_gc.py (original)
+++ pypy/dist/pypy/rpython/memory/test/test_gc.py Thu Aug 25 15:18:27 2005
@@ -136,7 +136,7 @@
res = interpret(append_to_list, [i, i - 1])
assert res == i - 1 # crashes if constants are not considered roots
- def test_string_concatenation(self):
+ def DONOTtest_string_concatenation(self):
curr = simulator.current_size
def concat(j):
lst = []
@@ -230,3 +230,25 @@
res = interpret(malloc_a_lot, [])
assert simulator.current_size - curr < 16000
print "size before: %s, size after %s" % (curr, simulator.current_size)
+
+ def test_global_list(self):
+ lst = []
+ def append_to_list(i, j):
+ lst.append([i] * 50)
+ return lst[j][0]
+ res = interpret(append_to_list, [0, 0])
+ assert res == 0
+ for i in range(1, 15):
+ res = interpret(append_to_list, [i, i - 1])
+ assert res == i - 1 # crashes if constants are not considered roots
+
+ def test_string_concatenation(self):
+ curr = simulator.current_size
+ def concat(j):
+ lst = []
+ for i in range(j):
+ lst.append(str(i))
+ return len("".join(lst))
+ res = interpret(concat, [100])
+ assert res == concat(100)
+ assert simulator.current_size - curr < 16000
More information about the Pypy-commit
mailing list