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

cfbolz at codespeak.net cfbolz at codespeak.net
Mon Aug 29 16:59:50 CEST 2005


Author: cfbolz
Date: Mon Aug 29 16:59:47 2005
New Revision: 17040

Modified:
   pypy/dist/pypy/rpython/memory/convertlltype.py
   pypy/dist/pypy/rpython/memory/gc.py
   pypy/dist/pypy/rpython/memory/gclltype.py
   pypy/dist/pypy/rpython/memory/gcwrapper.py
   pypy/dist/pypy/rpython/memory/test/test_gc.py
Log:
somewhat of an intermediate checkin: I refactored the GCs in a way that makes
them hopefully be annotatable soon. 


Modified: pypy/dist/pypy/rpython/memory/convertlltype.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/convertlltype.py	(original)
+++ pypy/dist/pypy/rpython/memory/convertlltype.py	Mon Aug 29 16:59:47 2005
@@ -14,22 +14,14 @@
                  types.BuiltinFunctionType)
 
 class LLTypeConverter(object):
-    def __init__(self, address, gc=None):
+    def __init__(self, address, gc=None, qt=None):
         self.type_to_typeid = {}
         self.types = []
         self.converted = {}
         self.curraddress = address
         self.constantroots = []
         self.gc = gc
-
-    def get_typeid(self, TYPE):
-        if TYPE not in self.type_to_typeid:
-            index = len(self.types)
-            self.type_to_typeid[TYPE] = index
-            self.types.append(TYPE)
-            return index
-        typeid = self.type_to_typeid[TYPE]
-        return typeid
+        self.query_types = qt
 
     def convert(self, val_or_ptr, inline_to_ptr=None):
         TYPE = lltype.typeOf(val_or_ptr)
@@ -63,12 +55,12 @@
             ptr = inline_to_ptr
         else:
             startaddr = self.curraddress
-            if self.gc is not None:
-                self.gc.init_gc_object(startaddr, self.get_typeid(TYPE))
-                startaddr += self.gc.size_gc_header()
             self.curraddress += size
             if self.gc is not None:
-                self.curraddress += self.gc.size_gc_header()
+                typeid = self.query_types.get_typeid(TYPE)
+                self.gc.init_gc_object(startaddr, typeid)
+                startaddr += self.gc.size_gc_header(typeid)
+                self.curraddress += self.gc.size_gc_header(typeid)
             ptr = init_object_on_address(startaddr, TYPE, arraylength)
             self.constantroots.append(ptr)
         self.converted[_array] = ptr
@@ -103,12 +95,12 @@
             ptr = inline_to_ptr
         else:
             startaddr = self.curraddress
-            if self.gc is not None:
-                self.gc.init_gc_object(startaddr, self.get_typeid(TYPE))
-                startaddr += self.gc.size_gc_header()
             self.curraddress += size
             if self.gc is not None:
-                self.curraddress += self.gc.size_gc_header()
+                typeid = self.query_types.get_typeid(TYPE)
+                self.gc.init_gc_object(startaddr, typeid)
+                startaddr += self.gc.size_gc_header(typeid)
+                self.curraddress += self.gc.size_gc_header(typeid)
             ptr = init_object_on_address(startaddr, TYPE, inlinedarraylength)
             self.constantroots.append(ptr)
         self.converted[_struct] = ptr
@@ -134,12 +126,13 @@
                             lladdress.get_address_of_object(_obj))
 
 class FlowGraphConstantConverter(object):
-    def __init__(self, flowgraphs, gc=None):
+    def __init__(self, flowgraphs, gc=None, qt=None):
         self.flowgraphs = flowgraphs
         self.memory = lladdress.NULL
         self.cvter = None
         self.total_size = 0
         self.gc = gc
+        self.query_types = qt
 
     def collect_constants_and_types(self):
         constants = {}
@@ -192,7 +185,8 @@
                 length = len(cand.items)
                 total_size += sizeof(cand._TYPE, length)
                 if self.gc is not None:
-                    total_size += self.gc.size_gc_header()
+                    typeid = self.query_types.get_typeid(cand._TYPE)
+                    total_size += self.gc.size_gc_header(typeid)
                 for item in cand.items:
                     candidates.append(item)
             elif isinstance(cand, lltype._struct):
@@ -211,7 +205,8 @@
                     else:
                         total_size += sizeof(TYPE)
                     if self.gc is not None:
-                        total_size += self.gc.size_gc_header()
+                        typeid = self.query_types.get_typeid(TYPE)
+                        total_size += self.gc.size_gc_header(typeid)
                 for name in TYPE._flds:
                     candidates.append(getattr(cand, name))
             elif isinstance(cand, lltype._opaque):
@@ -226,7 +221,7 @@
 
     def convert_constants(self):
         self.memory = lladdress.raw_malloc(self.total_size)
-        self.cvter = LLTypeConverter(self.memory, self.gc)
+        self.cvter = LLTypeConverter(self.memory, self.gc, self.query_types)
         for constant in self.constants.iterkeys():
             if isinstance(constant.value, lltype.LowLevelType):
                 self.constants[constant] = constant.value
@@ -256,16 +251,16 @@
 
     def create_type_ids(self):
         for TYPE in self.types:
-            print TYPE
             if isinstance(TYPE, (lltype.Array, lltype.Struct)):
                 #assign a typeid
-                self.cvter.get_typeid(TYPE)
+                self.query_types.get_typeid(TYPE)
             elif isinstance(TYPE, lltype.Ptr):
-                self.cvter.get_typeid(TYPE.TO)
+                self.query_types.get_typeid(TYPE.TO)
 
     def convert(self):
         self.collect_constants_and_types()
         self.calculate_size()
         self.convert_constants()
         self.patch_graphs()
-        self.create_type_ids()
+        if self.query_types is not None:
+            self.create_type_ids()

Modified: pypy/dist/pypy/rpython/memory/gc.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/gc.py	(original)
+++ pypy/dist/pypy/rpython/memory/gc.py	Mon Aug 29 16:59:47 2005
@@ -10,24 +10,50 @@
 class GCError(Exception):
     pass
 
+class GCBase(object):
+    _alloc_flavor_ = "raw"
+
+    def set_query_functions(self, is_varsize, offsets_to_gc_pointers,
+                            fixed_size, varsize_item_sizes,
+                            varsize_offset_to_variable_part,
+                            varsize_offset_to_length,
+                            varsize_offsets_to_gcpointers_in_var_part):
+        self.is_varsize = is_varsize
+        self.offsets_to_gc_pointers = offsets_to_gc_pointers
+        self.fixed_size = fixed_size
+        self.varsize_item_sizes = varsize_item_sizes
+        self.varsize_offset_to_variable_part = varsize_offset_to_variable_part
+        self.varsize_offset_to_length = varsize_offset_to_length
+        self.varsize_offsets_to_gcpointers_in_var_part = varsize_offsets_to_gcpointers_in_var_part
+        
 
-class MarkSweepGC(object):
+class MarkSweepGC(GCBase):
     _alloc_flavor_ = "raw"
 
-    def __init__(self, objectmodel, start_heap_size):
+    def __init__(self, start_heap_size, get_roots, is_varsize,
+                 offsets_to_gc_pointers, fixed_size, varsize_item_sizes,
+                 varsize_offset_to_variable_part, varsize_offset_to_length,
+                 varsize_offsets_to_gcpointers_in_var_part):
         self.bytes_malloced = 0
         self.heap_size = start_heap_size
         #need to maintain a list of malloced objects, since we used the systems
         #allocator and can't walk the heap
         self.malloced_objects = AddressLinkedList()
-        self.objectmodel = objectmodel
+        self.is_varsize = is_varsize
+        self.offsets_to_gc_pointers = offsets_to_gc_pointers
+        self.fixed_size = fixed_size
+        self.varsize_item_sizes = varsize_item_sizes
+        self.varsize_offset_to_variable_part = varsize_offset_to_variable_part
+        self.varsize_offset_to_length = varsize_offset_to_length
+        self.varsize_offsets_to_gcpointers_in_var_part = varsize_offsets_to_gcpointers_in_var_part
+        self.get_roots = get_roots
 
     def malloc(self, typeid, length=0):
         if self.bytes_malloced > self.heap_size:
             self.collect()
-        size = self.objectmodel.fixed_size(typeid)
-        if self.objectmodel.is_varsize(typeid):
-            size += length * self.objectmodel.varsize_item_sizes(typeid)
+        size = self.fixed_size(typeid)
+        if self.is_varsize(typeid):
+            size += length * self.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)
@@ -39,7 +65,7 @@
     def collect(self):
         print "collecting"
         self.bytes_malloced = 0
-        roots = self.objectmodel.get_roots()
+        roots = self.get_roots()
         objects = AddressLinkedList()
         while 1:
             curr = roots.pop()
@@ -61,16 +87,16 @@
             if gc_info.signed[0] == 1:
                 continue
             typeid = gc_info.signed[1]
-            offsets = self.objectmodel.offsets_to_gc_pointers(typeid)
+            offsets = self.offsets_to_gc_pointers(typeid)
             for i in range(len(offsets)):
                 pointer = curr + offsets[i]
                 objects.append(pointer.address[0])
-            if self.objectmodel.is_varsize(typeid):
-                offset = self.objectmodel.varsize_offset_to_variable_part(
+            if self.is_varsize(typeid):
+                offset = self.varsize_offset_to_variable_part(
                     typeid)
-                length = (curr + self.objectmodel.varsize_offset_to_length(typeid)).signed[0]
-                offsets = self.objectmodel.varsize_offsets_to_gcpointers_in_var_part(typeid)
-                itemlength = self.objectmodel.varsize_item_sizes(typeid)
+                length = (curr + self.varsize_offset_to_length(typeid)).signed[0]
+                offsets = self.varsize_offsets_to_gcpointers_in_var_part(typeid)
+                itemlength = self.varsize_item_sizes(typeid)
                 curr += offset
                 for i in range(length):
                     item = curr + itemlength * i
@@ -85,10 +111,10 @@
             if curr == NULL:
                 break
             typeid = curr.signed[1]
-            size = self.objectmodel.fixed_size(typeid)
-            if self.objectmodel.is_varsize(typeid):
-                length = (curr + self.size_gc_header() + self.objectmodel.varsize_offset_to_length(typeid)).signed[0]
-                size += length * self.objectmodel.varsize_item_sizes(typeid)
+            size = self.fixed_size(typeid)
+            if self.is_varsize(typeid):
+                length = (curr + self.size_gc_header() + self.varsize_offset_to_length(typeid)).signed[0]
+                size += length * self.varsize_item_sizes(typeid)
             if curr.signed[0] == 1:
                 curr.signed[0] = 0
                 newmo.append(curr)
@@ -102,7 +128,7 @@
         if curr_heap_size > self.heap_size:
             self.heap_size = curr_heap_size
 
-    def size_gc_header(self):
+    def size_gc_header(self, typeid=0):
         return lltypesimulation.sizeof(lltype.Signed) * 2
 
     def init_gc_object(self, addr, typeid):
@@ -110,22 +136,32 @@
         addr.signed[1] = typeid
 
 
-class SemiSpaceGC(object):
+class SemiSpaceGC(GCBase):
     _alloc_flavor_ = "raw"
 
-    def __init__(self, objectmodel, space_size):
+    def __init__(self, space_size, get_roots, is_varsize,
+                 offsets_to_gc_pointers, fixed_size, varsize_item_sizes,
+                 varsize_offset_to_variable_part, varsize_offset_to_length,
+                 varsize_offsets_to_gcpointers_in_var_part):
         self.bytes_malloced = 0
         self.space_size = space_size
         self.tospace = raw_malloc(space_size)
         self.top_of_space = self.tospace + space_size
         self.fromspace = raw_malloc(space_size)
         self.free = self.tospace
-        self.objectmodel = objectmodel
+        self.is_varsize = is_varsize
+        self.offsets_to_gc_pointers = offsets_to_gc_pointers
+        self.fixed_size = fixed_size
+        self.varsize_item_sizes = varsize_item_sizes
+        self.varsize_offset_to_variable_part = varsize_offset_to_variable_part
+        self.varsize_offset_to_length = varsize_offset_to_length
+        self.varsize_offsets_to_gcpointers_in_var_part = varsize_offsets_to_gcpointers_in_var_part
+        self.get_roots = get_roots
 
     def malloc(self, typeid, length=0):
-        size = self.objectmodel.fixed_size(typeid)
-        if self.objectmodel.is_varsize(typeid):
-            size += length * self.objectmodel.varsize_item_sizes(typeid)
+        size = self.fixed_size(typeid)
+        if self.is_varsize(typeid):
+            size += length * self.varsize_item_sizes(typeid)
         totalsize = size + self.size_gc_header()
         if self.free + totalsize > self.top_of_space:
             self.collect()
@@ -143,7 +179,7 @@
         print "collecting"
         self.fromspace, self.tospace = self.tospace, self.fromspace
         self.top_of_space = self.tospace + self.space_size
-        roots = self.objectmodel.get_roots()
+        roots = self.get_roots()
         scan = self.free = self.tospace
         while 1:
             root = roots.pop()
@@ -174,7 +210,7 @@
             return newobj
 
     def copy_non_managed_obj(self, obj): #umph, PBCs, not really copy
-        print "copying nonmanaged", obj, self.objectmodel.types[obj.signed[-1]]
+        print "copying nonmanaged", obj
         #we have to do the tracing here because PBCs are not moved to tospace
         self.trace_and_copy(obj)
         return obj
@@ -183,17 +219,17 @@
         gc_info = obj - self.size_gc_header()
         typeid = gc_info.signed[1]
         print "scanning", obj, typeid
-        offsets = self.objectmodel.offsets_to_gc_pointers(typeid)
+        offsets = self.offsets_to_gc_pointers(typeid)
         for i in range(len(offsets)):
             pointer = obj + offsets[i]
             if pointer.address[0] != NULL:
                 pointer.address[0] = self.copy(pointer.address[0])
-        if self.objectmodel.is_varsize(typeid):
-            offset = self.objectmodel.varsize_offset_to_variable_part(
+        if self.is_varsize(typeid):
+            offset = self.varsize_offset_to_variable_part(
                 typeid)
-            length = (obj + self.objectmodel.varsize_offset_to_length(typeid)).signed[0]
-            offsets = self.objectmodel.varsize_offsets_to_gcpointers_in_var_part(typeid)
-            itemlength = self.objectmodel.varsize_item_sizes(typeid)
+            length = (obj + self.varsize_offset_to_length(typeid)).signed[0]
+            offsets = self.varsize_offsets_to_gcpointers_in_var_part(typeid)
+            itemlength = self.varsize_item_sizes(typeid)
             for i in range(length):
                 item = obj + offset + itemlength * i
                 for j in range(len(offsets)):
@@ -214,15 +250,15 @@
 
     def get_size(self, obj):
         typeid = (obj - self.size_gc_header()).signed[1]
-        size = self.objectmodel.fixed_size(typeid)
-        if self.objectmodel.is_varsize(typeid):
-            lenaddr = obj + self.objectmodel.varsize_offset_to_length(typeid)
+        size = self.fixed_size(typeid)
+        if self.is_varsize(typeid):
+            lenaddr = obj + self.varsize_offset_to_length(typeid)
             length = lenaddr.signed[0]
-            size += length * self.objectmodel.varsize_item_sizes(typeid)
+            size += length * self.varsize_item_sizes(typeid)
         return size
 
 
-    def size_gc_header(self):
+    def size_gc_header(self, typeid=0):
         return lltypesimulation.sizeof(lltype.Signed) * 2
 
     def init_gc_object(self, addr, typeid):

Modified: pypy/dist/pypy/rpython/memory/gclltype.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/gclltype.py	(original)
+++ pypy/dist/pypy/rpython/memory/gclltype.py	Mon Aug 29 16:59:47 2005
@@ -38,16 +38,15 @@
 from pypy.rpython.memory.gc import MarkSweepGC, SemiSpaceGC
 use_gc = MarkSweepGC
 def create_mark_sweep_gc(llinterp, flowgraphs):
-    from pypy.rpython.memory.gcwrapper import GcWrapper, LLInterpObjectModel
-    #XXX hackish: we need the gc before the object model is ready
-    gc = use_gc(None, 4096)
-    fgcc = FlowGraphConstantConverter(flowgraphs, gc)
-    fgcc.convert()    
-    om = LLInterpObjectModel(llinterp, fgcc.cvter.types,
-                             fgcc.cvter.type_to_typeid,
-                             fgcc.cvter.constantroots)
-    gc.objectmodel = om
-    wrapper = GcWrapper(llinterp, gc)
+    from pypy.rpython.memory.gcwrapper import GcWrapper, QueryTypes
+    # XXX there might me GCs that have headers that depend on the type
+    # therefore we have to change the query functions to annotatable ones later
+    qt = QueryTypes(llinterp)
+    gc = use_gc(4096, None, *qt.get_setup_query_functions())
+    fgcc = FlowGraphConstantConverter(flowgraphs, gc, qt)
+    fgcc.convert()
+    gc.set_query_functions(*qt.create_query_functions())
+    wrapper = GcWrapper(llinterp, gc, qt, fgcc.cvter.constantroots)
     return wrapper
 
-prepare_graphs_and_create_gc = create_mark_sweep_gc
+prepare_graphs_and_create_gc = create_no_gc

Modified: pypy/dist/pypy/rpython/memory/gcwrapper.py
==============================================================================
--- pypy/dist/pypy/rpython/memory/gcwrapper.py	(original)
+++ pypy/dist/pypy/rpython/memory/gcwrapper.py	Mon Aug 29 16:59:47 2005
@@ -5,86 +5,144 @@
 from pypy.rpython.memory import lltypesimulation
 from pypy.rpython.memory.gc import MarkSweepGC
 
-class LLInterpObjectModel(object):
-    def __init__(self, llinterp, types,
-                 type_to_typeid, constantroots):
-        self.type_to_typeid = type_to_typeid
-        self.constantroots = constantroots
-        self.roots = []
-        self.pseudo_root_pointers = NULL
+class QueryTypes(object):
+    def __init__(self, llinterp):
         self.llinterp = llinterp
-        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 = []
-        self._varsize_offsets_to_gcpointers_in_var_part = []
-        tttid = zip(*zip(*type_to_typeid.items())[::-1])
+        self.types = []
+        self.type_to_typeid = {}
+
+    def get_typeid(self, TYPE):
+        if TYPE not in self.type_to_typeid:
+            index = len(self.types)
+            self.type_to_typeid[TYPE] = index
+            self.types.append(TYPE)
+            return index
+        typeid = self.type_to_typeid[TYPE]
+        return typeid
+
+    def create_query_functions(self):
+        _is_varsize = []
+        _offsets_to_gc_pointers = []
+        _fixed_size = []
+        _varsize_item_sizes = []
+        _varsize_offset_to_variable_part = []
+        _varsize_offset_to_length = []
+        _varsize_offsets_to_gcpointers_in_var_part = []
+        tttid = zip(*zip(*self.type_to_typeid.items())[::-1])
         tttid.sort()
         tttid = zip(*zip(*tttid)[::-1])
         for TYPE, typeid in tttid:
             varsize = (isinstance(TYPE, lltype.Array) or
                        (isinstance(TYPE, lltype.Struct) and
                         TYPE._arrayfld is not None))
-            self._is_varsize.append(varsize)
-            self._offsets_to_gc_pointers.append(
+            _is_varsize.append(varsize)
+            _offsets_to_gc_pointers.append(
                 lltypelayout.offsets_to_gc_pointers(TYPE))
-            self._fixed_size.append(
-                lltypelayout.get_fixed_size(TYPE))
+            _fixed_size.append(lltypelayout.get_fixed_size(TYPE))
             if varsize:
-                self._varsize_item_sizes.append(
-                    lltypelayout.get_variable_size(TYPE))
-                self._varsize_offset_to_variable_part.append(
+                _varsize_item_sizes.append(lltypelayout.get_variable_size(TYPE))
+                _varsize_offset_to_variable_part.append(
                     lltypelayout.get_fixed_size(TYPE))
-                self._varsize_offset_to_length.append(
+                _varsize_offset_to_length.append(
                     lltypelayout.varsize_offset_to_length(TYPE))
-                self._varsize_offsets_to_gcpointers_in_var_part.append(
+                _varsize_offsets_to_gcpointers_in_var_part.append(
                     lltypelayout.varsize_offsets_to_gcpointers_in_var_part(TYPE))
             else:
-                self._varsize_item_sizes.append(0)
-                self._varsize_offset_to_variable_part.append(0)
-                self._varsize_offset_to_length.append(0)
-                self._varsize_offsets_to_gcpointers_in_var_part.append([])
-
-    def update_changed_addresses(self):
-        for i, root in enumerate(self.roots):
-            if root._address != self.pseudo_root_pointers.address[i]:
-                print "address changed:", root._address, self.pseudo_root_pointers.address[i]
-            root.__dict__['_address'] = self.pseudo_root_pointers.address[i]
-
-    def get_typeid(self, TYPE):
-        typeid = self.type_to_typeid[TYPE]
-        return typeid
+                _varsize_item_sizes.append(0)
+                _varsize_offset_to_variable_part.append(0)
+                _varsize_offset_to_length.append(0)
+                _varsize_offsets_to_gcpointers_in_var_part.append([])
+        def is_varsize(typeid):
+            return _is_varsize[typeid]
+        def offsets_to_gc_pointers(typeid):
+            return _offsets_to_gc_pointers[typeid]
+        def fixed_size(typeid):
+            return _fixed_size[typeid]
+        def varsize_item_sizes(typeid):
+            return _varsize_item_sizes[typeid]
+        def varsize_offset_to_variable_part(typeid):
+            return _varsize_offset_to_variable_part[typeid]
+        def varsize_offset_to_length(typeid):
+            return _varsize_offset_to_length[typeid]
+        def varsize_offsets_to_gcpointers_in_var_part(typeid):
+            return _varsize_offsets_to_gcpointers_in_var_part[typeid]
+        return (is_varsize, offsets_to_gc_pointers, fixed_size,
+                varsize_item_sizes, varsize_offset_to_variable_part,
+                varsize_offset_to_length,
+                varsize_offsets_to_gcpointers_in_var_part)
 
     def is_varsize(self, typeid):
         assert typeid >= 0
-        return self._is_varsize[typeid]
+        TYPE = self.types[typeid]
+        return (isinstance(TYPE, lltype.Array) or
+                (isinstance(TYPE, lltype.Struct) and
+                 TYPE._arrayfld is not None))
 
     def offsets_to_gc_pointers(self, typeid):
         assert typeid >= 0
-        return self._offsets_to_gc_pointers[typeid]
+        return lltypelayout.offsets_to_gc_pointers(self.types[typeid])
 
     def fixed_size(self, typeid):
         assert typeid >= 0
-        return self._fixed_size[typeid]
+        return lltypelayout.get_fixed_size(self.types[typeid])
 
     def varsize_item_sizes(self, typeid):
         assert typeid >= 0
-        return self._varsize_item_sizes[typeid]
+        if self.is_varsize(typeid):
+            return lltypelayout.get_variable_size(self.types[typeid])
+        else:
+            return 0
 
     def varsize_offset_to_variable_part(self, typeid):
         assert typeid >= 0
-        return self._varsize_offset_to_variable_part[typeid]
+        if self.is_varsize(typeid):
+            return lltypelayout.get_fixed_size(self.types[typeid])
+        else:
+            return 0
 
     def varsize_offset_to_length(self, typeid):
         assert typeid >= 0
-        return self._varsize_offset_to_length[typeid]
+        if self.is_varsize(typeid):
+            return lltypelayout.varsize_offset_to_length(self.types[typeid])
+        else:
+            return 0
 
     def varsize_offsets_to_gcpointers_in_var_part(self, typeid):
         assert typeid >= 0
-        return self._varsize_offsets_to_gcpointers_in_var_part[typeid]
+        if self.is_varsize(typeid):
+            return lltypelayout.varsize_offsets_to_gcpointers_in_var_part(
+                self.types[typeid])
+        else:
+            return 0
+
+    def get_setup_query_functions(self):
+        return (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,
+                self.varsize_offsets_to_gcpointers_in_var_part)
+
+class GcWrapper(object):
+    def __init__(self, llinterp, gc, qt, constantroots):
+        self.llinterp = llinterp
+        self.gc = gc
+        self.gc.get_roots = self.get_roots
+        self.query_types = qt
+        self.constantroots = constantroots
+        self.pseudo_root_pointers = NULL
+        self.roots = []
+
+    def malloc(self, TYPE, size=0):
+        typeid = self.query_types.get_typeid(TYPE)
+        address = self.gc.malloc(typeid, size)
+        result = lltypesimulation.init_object_on_address(address, TYPE, size)
+        self.update_changed_addresses()
+        return result
+
+    def update_changed_addresses(self):
+        for i, root in enumerate(self.roots):
+            if root._address != self.pseudo_root_pointers.address[i]:
+                print "address changed:", root._address, self.pseudo_root_pointers.address[i]
+            root.__dict__['_address'] = self.pseudo_root_pointers.address[i]
 
     def get_roots(self):
         print "getting roots"
@@ -103,18 +161,3 @@
             self.pseudo_root_pointers.address[i] = root._address
             ll.append(self.pseudo_root_pointers + INT_SIZE * i)
         return ll
-
-
-class GcWrapper(object):
-    def __init__(self, llinterp, gc):
-        self.llinterp = llinterp
-        self.objectmodel = gc.objectmodel
-        assert isinstance(self.objectmodel, LLInterpObjectModel)
-        self.gc = gc
-
-    def malloc(self, TYPE, size=0):
-        typeid = self.objectmodel.get_typeid(TYPE)
-        address = self.gc.malloc(typeid, 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	Mon Aug 29 16:59:47 2005
@@ -47,7 +47,7 @@
         return self.layout_mapping[typeid]
 
 class TestMarkSweepGC(object):
-    def test_simple(self):
+    def DONOTtest_simple(self):
         variables = raw_malloc(4 * INT_SIZE)
         roots = [variables + i * INT_SIZE for i in range(4)]
         layout0 = [] #int
@@ -155,7 +155,7 @@
     def teardown_class(cls):
         gclltype.use_gc = cls.old
 
-    def test_simple(self):
+    def DONOTtest_simple(self):
         variables = raw_malloc(4 * INT_SIZE)
         roots = [variables + i * INT_SIZE for i in range(4)]
         layout0 = [] #int



More information about the Pypy-commit mailing list