[pypy-svn] r47297 - in pypy/branch/kill-keepalives-again/pypy/rpython: . memory

arigo at codespeak.net arigo at codespeak.net
Mon Oct 8 18:37:17 CEST 2007


Author: arigo
Date: Mon Oct  8 18:37:17 2007
New Revision: 47297

Modified:
   pypy/branch/kill-keepalives-again/pypy/rpython/llinterp.py
   pypy/branch/kill-keepalives-again/pypy/rpython/memory/gc.py
   pypy/branch/kill-keepalives-again/pypy/rpython/memory/gcwrapper.py
Log:
Modify llinterp.find_roots() to return a list of "addresses"
to its local variables.


Modified: pypy/branch/kill-keepalives-again/pypy/rpython/llinterp.py
==============================================================================
--- pypy/branch/kill-keepalives-again/pypy/rpython/llinterp.py	(original)
+++ pypy/branch/kill-keepalives-again/pypy/rpython/llinterp.py	Mon Oct  8 18:37:17 2007
@@ -123,6 +123,7 @@
             log.traceback(line)
 
     def find_roots(self):
+        """Return a list of the addresses of the roots."""
         #log.findroots("starting")
         frame = self.active_frame
         roots = []
@@ -455,14 +456,17 @@
 
     def find_roots(self, roots):
         #log.findroots(self.curr_block.inputargs)
-        PyObjPtr = lltype.Ptr(lltype.PyObject)
-        for arg in self.curr_block.inputargs:
-            if (isinstance(arg, Variable) and
-                isinstance(getattr(arg, 'concretetype', PyObjPtr), lltype.Ptr)):
-                roots.append(self.getval(arg))
+        vars = []
+        for v in self.curr_block.inputargs:
+            if isinstance(v, Variable):
+                vars.append(v)
         for op in self.curr_block.operations[:self.curr_operation_index]:
-            if isinstance(getattr(op.result, 'concretetype', PyObjPtr), lltype.Ptr):
-                roots.append(self.getval(op.result))
+            vars.append(op.result)
+
+        for v in vars:
+            TYPE = getattr(v, 'concretetype', None)
+            if isinstance(TYPE, lltype.Ptr) and TYPE.TO._gckind == 'gc':
+                roots.append(_address_of_local_var(self, v))
 
     # __________________________________________________________
     # misc LL operation implementations
@@ -1209,6 +1213,30 @@
         addcls(cls)
     return result
 
+class _address_of_local_var(object):
+    _TYPE = llmemory.Address
+    def __init__(self, frame, v):
+        self._frame = frame
+        self._v = v
+    def _getaddress(self):
+        return _address_of_local_var_accessor(self._frame, self._v)
+    address = property(_getaddress)
+
+class _address_of_local_var_accessor(object):
+    def __init__(self, frame, v):
+        self.frame = frame
+        self.v = v
+    def __getitem__(self, index):
+        if index != 0:
+            raise IndexError("address of local vars only support [0] indexing")
+        p = self.frame.getval(self.v)
+        return llmemory.cast_ptr_to_adr(p)
+    def __setitem__(self, index, newvalue):
+        if index != 0:
+            raise IndexError("address of local vars only support [0] indexing")
+        p = llmemory.cast_adr_to_ptr(newvalue, self.v.concretetype)
+        self.frame.setvar(self.v, p)
+
 # by default we route all logging messages to nothingness
 # e.g. tests can then switch on logging to get more help
 # for failing tests

Modified: pypy/branch/kill-keepalives-again/pypy/rpython/memory/gc.py
==============================================================================
--- pypy/branch/kill-keepalives-again/pypy/rpython/memory/gc.py	(original)
+++ pypy/branch/kill-keepalives-again/pypy/rpython/memory/gc.py	Mon Oct  8 18:37:17 2007
@@ -88,6 +88,9 @@
     def statistics(self, index):
         return -1
 
+    def size_gc_header(self, typeid=0):
+        return self.gcheaderbuilder.size_gc_header
+
     def x_swap_pool(self, newpool):
         return newpool
 
@@ -116,9 +119,6 @@
     def collect(self):
         self.get_roots() #this is there so that the annotator thinks get_roots is a function
 
-    def size_gc_header(self, typeid=0):
-        return self.gcheaderbuilder.size_gc_header
-
     def init_gc_object(self, addr, typeid):
         return
     init_gc_object_immortal = init_gc_object
@@ -1120,8 +1120,8 @@
 ##             print "already copied to", self.get_forwarding_address(obj)
             return self.get_forwarding_address(obj)
         else:
-            newaddr = self.free
-            totalsize = self.get_size(obj) + self.size_gc_header()
+            totalsize = self.size_gc_header() + self.get_size(obj)
+            newaddr = llarena.arena_reserve(self.free, totalsize)
             raw_memcopy(obj - self.size_gc_header(), newaddr, totalsize)
             self.free += totalsize
             newobj = newaddr + self.size_gc_header()

Modified: pypy/branch/kill-keepalives-again/pypy/rpython/memory/gcwrapper.py
==============================================================================
--- pypy/branch/kill-keepalives-again/pypy/rpython/memory/gcwrapper.py	(original)
+++ pypy/branch/kill-keepalives-again/pypy/rpython/memory/gcwrapper.py	Mon Oct  8 18:37:17 2007
@@ -37,11 +37,8 @@
         ll = self.AddressLinkedList()
         for addrofaddr in self.constantroots:
             ll.append(addrofaddr)
-        for root in self.llinterp.find_roots():
-            if lltype.typeOf(root).TO._gckind == 'gc':
-                addrofaddr = llmemory.raw_malloc(sizeofaddr)
-                addrofaddr.address[0] = llmemory.cast_ptr_to_adr(root)
-                ll.append(addrofaddr)
+        for addrofaddr in self.llinterp.find_roots():
+            ll.append(addrofaddr)
         return ll
 
     # ____________________________________________________________



More information about the Pypy-commit mailing list