[pypy-svn] r47283 - in pypy/branch/kill-keepalives-again/pypy/rpython: lltypesystem memory

arigo at codespeak.net arigo at codespeak.net
Mon Oct 8 13:27:18 CEST 2007


Author: arigo
Date: Mon Oct  8 13:27:16 2007
New Revision: 47283

Modified:
   pypy/branch/kill-keepalives-again/pypy/rpython/lltypesystem/llarena.py
   pypy/branch/kill-keepalives-again/pypy/rpython/lltypesystem/lltype.py
   pypy/branch/kill-keepalives-again/pypy/rpython/memory/gc.py
Log:
Some clean-ups in gc.py.  A bit of a hack in lltype to allow llarena addresses
to be cast to GCREF and back.


Modified: pypy/branch/kill-keepalives-again/pypy/rpython/lltypesystem/llarena.py
==============================================================================
--- pypy/branch/kill-keepalives-again/pypy/rpython/lltypesystem/llarena.py	(original)
+++ pypy/branch/kill-keepalives-again/pypy/rpython/lltypesystem/llarena.py	Mon Oct  8 13:27:16 2007
@@ -112,6 +112,9 @@
             return llmemory.fakeaddress.__eq__(self, other)
 
     def _cast_to_ptr(self, EXPECTED_TYPE):
+        if EXPECTED_TYPE == llmemory.GCREF:
+            obj = lltype._opaque(EXPECTED_TYPE.TO, _original_address = self)
+            return obj._as_ptr()
         # the first cast determines what object type is at this address
         if self.offset not in self.arena.objects:
             self.arena.allocate_object(self.offset, EXPECTED_TYPE.TO)

Modified: pypy/branch/kill-keepalives-again/pypy/rpython/lltypesystem/lltype.py
==============================================================================
--- pypy/branch/kill-keepalives-again/pypy/rpython/lltypesystem/lltype.py	(original)
+++ pypy/branch/kill-keepalives-again/pypy/rpython/lltypesystem/lltype.py	Mon Oct  8 13:27:16 2007
@@ -1194,6 +1194,9 @@
 ##            addr = llmemory.fakeaddress(normalizeptr(_ptr(Ptr(T), parent)))
 ##            addr += llmemory.itemoffsetof(T, parentindex)
 ##            return addr
+        elif (isinstance(self._obj, _opaque)
+              and hasattr(self._obj, '_original_address')):
+            return self._obj._original_address      # for llarena.py
         else:
             # normal case
             return llmemory.fakeaddress(normalizeptr(self))
@@ -1754,7 +1757,8 @@
     elif isinstance(T, Array):
         o = _array(T, n, initialization=initialization)
     elif isinstance(T, OpaqueType):
-        o = _opaque(T, n, initialization=initialization)
+        assert n is None
+        o = _opaque(T, initialization=initialization)
     else:
         raise TypeError, "malloc for Structs and Arrays only"
     if T._gckind != 'gc' and not immortal and flavor.startswith('gc'):

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 13:27:16 2007
@@ -117,7 +117,7 @@
         self.get_roots() #this is there so that the annotator thinks get_roots is a function
 
     def size_gc_header(self, typeid=0):
-        return 0
+        return self.gcheaderbuilder.size_gc_header
 
     def init_gc_object(self, addr, typeid):
         return
@@ -618,9 +618,6 @@
             return self.bytes_malloced
         return -1
 
-    def size_gc_header(self, typeid=0):
-        return self.gcheaderbuilder.size_gc_header
-
     def init_gc_object(self, addr, typeid):
         hdr = llmemory.cast_adr_to_ptr(addr, self.HDRPTR)
         hdr.typeid = typeid << 1
@@ -1001,7 +998,7 @@
 class SemiSpaceGC(GCBase):
     _alloc_flavor_ = "raw"
 
-    HDR = lltype.Struct('header', ('forw', lltype.Signed),
+    HDR = lltype.Struct('header', ('forw', llmemory.Address),
                                   ('typeid', lltype.Signed))
 
     def __init__(self, AddressLinkedList, space_size=4096,
@@ -1136,8 +1133,8 @@
         return obj
 
     def trace_and_copy(self, obj):
-        gc_info = obj - self.size_gc_header()
-        typeid = gc_info.signed[1]
+        gc_info = self.header(obj)
+        typeid = gc_info.typeid
 ##         print "scanning", obj, typeid
         offsets = self.offsets_to_gc_pointers(typeid)
         i = 0
@@ -1164,18 +1161,17 @@
                 i += 1
 
     def is_forwarded(self, obj):
-        return (obj - self.size_gc_header()).signed[1] < 0
+        return self.header(obj).forw != NULL
 
     def get_forwarding_address(self, obj):
-        return (obj - self.size_gc_header()).address[0]
+        return self.header(obj).forw
 
     def set_forwarding_address(self, obj, newobj):
-        gc_info = obj - self.size_gc_header()
-        gc_info.signed[1] = -gc_info.signed[1] - 1
-        gc_info.address[0] = newobj
+        gc_info = self.header(obj)
+        gc_info.forw = newobj
 
     def get_size(self, obj):
-        typeid = (obj - self.size_gc_header()).signed[1]
+        typeid = self.header(obj).typeid
         size = self.fixed_size(typeid)
         if self.is_varsize(typeid):
             lenaddr = obj + self.varsize_offset_to_length(typeid)
@@ -1183,17 +1179,18 @@
             size += length * self.varsize_item_sizes(typeid)
         return size
 
-    def size_gc_header(self, typeid=0):
-        return self.gcheaderbuilder.size_gc_header
+    def header(self, addr):
+        addr -= self.gcheaderbuilder.size_gc_header
+        return llmemory.cast_adr_to_ptr(addr, lltype.Ptr(self.HDR))
 
     def init_gc_object(self, addr, typeid):
         hdr = llmemory.cast_adr_to_ptr(addr, lltype.Ptr(self.HDR))
-        #hdr.forw = 0      -- unneeded, the space is initially filled with zero
+        #hdr.forw = NULL   -- unneeded, the space is initially filled with zero
         hdr.typeid = typeid
 
     def init_gc_object_immortal(self, addr, typeid):
         hdr = llmemory.cast_adr_to_ptr(addr, lltype.Ptr(self.HDR))
-        hdr.forw = 0
+        hdr.forw = NULL
         hdr.typeid = typeid
 
 class DeferredRefcountingGC(GCBase):



More information about the Pypy-commit mailing list