[pypy-svn] r16171 - in pypy/dist/pypy/rpython/memory: . test

cfbolz at codespeak.net cfbolz at codespeak.net
Fri Aug 19 19:07:31 CEST 2005


Author: cfbolz
Date: Fri Aug 19 19:07:30 2005
New Revision: 16171

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:
made the gc's malloc calculate the size of the malloced object itself.


Modified: pypy/dist/pypy/rpython/memory/gc.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/gc.py	(original)
+++ pypy/dist/pypy/rpython/memory/gc.py	Fri Aug 19 19:07:30 2005
@@ -21,9 +21,12 @@
         self.malloced_objects = AddressLinkedList()
         self.objectmodel = objectmodel
 
-    def malloc(self, typeid, size):
+    def malloc(self, typeid, length=0):
         if self.bytes_malloced > self.collect_every_bytes:
             self.collect()
+        size = self.objectmodel.fixed_size(typeid)
+        if self.objectmodel.is_varsize(typeid):
+            size += length * self.objectmodel.varsize_item_sizes(typeid)
         size_gc_header = self.size_gc_header()
         result = raw_malloc(size + size_gc_header)
         print "mallocing %s, size %s at %s" % (typeid, size, result)

Modified: pypy/dist/pypy/rpython/memory/gcwrapper.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/gcwrapper.py	(original)
+++ pypy/dist/pypy/rpython/memory/gcwrapper.py	Fri Aug 19 19:07:30 2005
@@ -16,6 +16,7 @@
         self.types = types
         self._is_varsize = []
         self._offsets_to_gc_pointers = []
+        self._fixed_size = []
         self._varsize_item_sizes = []
         self._varsize_offset_to_variable_part = []
         self._varsize_offset_to_length = []
@@ -30,6 +31,8 @@
             self._is_varsize.append(varsize)
             self._offsets_to_gc_pointers.append(
                 lltypelayout.offsets_to_gc_pointers(TYPE))
+            self._fixed_size.append(
+                lltypelayout.get_fixed_size(TYPE))
             if varsize:
                 self._varsize_item_sizes.append(
                     lltypelayout.get_variable_size(TYPE))
@@ -61,6 +64,9 @@
     def offsets_to_gc_pointers(self, typeid):
         return self._offsets_to_gc_pointers[typeid]
 
+    def fixed_size(self, typeid):
+        return self._fixed_size[typeid]
+
     def varsize_item_sizes(self, typeid):
         return self._varsize_item_sizes[typeid]
 
@@ -99,8 +105,7 @@
 
     def malloc(self, TYPE, size=0):
         typeid = self.objectmodel.get_typeid(TYPE)
-        address = self.gc.malloc(typeid,
-                                 lltypesimulation.sizeof(TYPE, size))
+        address = self.gc.malloc(typeid, size)
         return 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	Fri Aug 19 19:07:30 2005
@@ -25,9 +25,10 @@
     """Object model for testing purposes: you can specify roots and a
     layout_mapping which is a dictionary of typeids to a list of offsets of
     pointers in an object"""
-    def __init__(self, roots, layout_mapping):
+    def __init__(self, roots, layout_mapping, size_mapping):
         self.roots = roots
         self.layout_mapping = layout_mapping
+        self.size_mapping = size_mapping
 
     def get_roots(self):
         self.roots
@@ -39,9 +40,11 @@
     def is_varsize(self, typeid):
         False
 
+    def fixed_size(self, typeid):
+        return self.size_mapping[typeid]
+
     def offsets_to_gc_pointers(self, typeid):
-        layout = self.layout_mapping[typeid]
-        return layout
+        return self.layout_mapping[typeid]
 
 class TestMarkSweepGC(object):
     def test_simple(self):
@@ -49,27 +52,27 @@
         roots = [variables + i * INT_SIZE for i in range(4)]
         layout0 = [] #int
         layout1 = [0, INT_SIZE] #(ptr, ptr)
-        om = PseudoObjectModel(roots, {0: layout0, 1: layout1})
+        om = PseudoObjectModel(roots, {0: layout0, 1: layout1}, {0: INT_SIZE, 1: 2 * INT_SIZE})
         gc = MarkSweepGC(om, 2 ** 16)
-        variables.address[0] = gc.malloc(0, INT_SIZE)
-        variables.address[1] = gc.malloc(0, INT_SIZE)
-        variables.address[2] = gc.malloc(0, INT_SIZE)
-        variables.address[3] = gc.malloc(0, INT_SIZE)
+        variables.address[0] = gc.malloc(0)
+        variables.address[1] = gc.malloc(0)
+        variables.address[2] = gc.malloc(0)
+        variables.address[3] = gc.malloc(0)
         print "roots", roots
         gc.collect() #does not crash
-        addr = gc.malloc(0, INT_SIZE)
+        addr = gc.malloc(0)
         addr.signed[0] = 1
         print "roots", roots
         gc.collect()
         py.test.raises(MemorySimulatorError, "addr.signed[0]")
-        variables.address[0] = gc.malloc(1, 2 * INT_SIZE)
+        variables.address[0] = gc.malloc(1)
         variables.address[0].address[0] = variables.address[1]
         variables.address[0].address[1] = NULL
         print "roots", roots
         gc.collect() #does not crash
-        addr0 = gc.malloc(1, 2 * INT_SIZE)
+        addr0 = gc.malloc(1)
         addr0.address[1] = NULL
-        addr1 = gc.malloc(1, 2 * INT_SIZE)
+        addr1 = gc.malloc(1)
         addr1.address[0] = addr1.address[1] = NULL
         addr0.address[0] = addr1
         addr2 = variables.address[1]



More information about the Pypy-commit mailing list