[pypy-svn] r79299 - pypy/branch/jit-free/pypy/rpython/memory/gc

arigo at codespeak.net arigo at codespeak.net
Sat Nov 20 15:12:46 CET 2010


Author: arigo
Date: Sat Nov 20 15:12:44 2010
New Revision: 79299

Modified:
   pypy/branch/jit-free/pypy/rpython/memory/gc/base.py
   pypy/branch/jit-free/pypy/rpython/memory/gc/inspector.py
   pypy/branch/jit-free/pypy/rpython/memory/gc/minimark.py
   pypy/branch/jit-free/pypy/rpython/memory/gc/semispace.py
Log:
If dump_rpy_heap(), for the common GCs, don't use an AddressDict
containing all objects visited so far, but use a flag in the object
header itself.


Modified: pypy/branch/jit-free/pypy/rpython/memory/gc/base.py
==============================================================================
--- pypy/branch/jit-free/pypy/rpython/memory/gc/base.py	(original)
+++ pypy/branch/jit-free/pypy/rpython/memory/gc/base.py	Sat Nov 20 15:12:44 2010
@@ -19,6 +19,7 @@
     malloc_zero_filled = False
     prebuilt_gc_objects_are_static_roots = True
     object_minimal_size = 0
+    gcflag_extra = 0   # or a real GC flag that is always 0 when not collecting
 
     def __init__(self, config, chunk_size=DEFAULT_CHUNK_SIZE,
                  translated_to_c=True):

Modified: pypy/branch/jit-free/pypy/rpython/memory/gc/inspector.py
==============================================================================
--- pypy/branch/jit-free/pypy/rpython/memory/gc/inspector.py	(original)
+++ pypy/branch/jit-free/pypy/rpython/memory/gc/inspector.py	Sat Nov 20 15:12:44 2010
@@ -107,15 +107,20 @@
 
     def __init__(self, gc, fd):
         self.gc = gc
+        self.gcflag = gc.gcflag_extra
         self.fd = rffi.cast(rffi.INT, fd)
         self.writebuffer = lltype.malloc(rffi.LONGP.TO, self.BUFSIZE,
                                          flavor='raw')
         self.buf_count = 0
-        self.seen = AddressDict()
+        if self.gcflag == 0:
+            self.seen = AddressDict()
         self.pending = AddressStack()
 
     def delete(self):
-        self.seen.delete()
+        if self.gcflag == 0:
+            self.seen.delete()
+        else:
+            self.clear_gcflag_again()
         self.pending.delete()
         lltype.free(self.writebuffer, flavor='raw')
         free_non_gc_object(self)
@@ -161,9 +166,15 @@
         self.add(obj)
 
     def add(self, obj):
-        if not self.seen.contains(obj):
-            self.seen.setitem(obj, obj)
-            self.pending.append(obj)
+        if self.gcflag == 0:
+            if not self.seen.contains(obj):
+                self.seen.setitem(obj, obj)
+                self.pending.append(obj)
+        else:
+            hdr = self.gc.header(obj)
+            if (hdr.tid & self.gcflag) == 0:
+                hdr.tid |= self.gcflag
+                self.pending.append(obj)
 
     def add_roots(self):
         self.gc.enumerate_all_roots(_hd_add_root, self)
@@ -177,9 +188,25 @@
         while pending.non_empty():
             self.writeobj(pending.pop())
 
+    def clear_gcflag_again(self):
+        self.gc.enumerate_all_roots(_hd_clear_root, self)
+        pending = self.pending
+        while pending.non_empty():
+            self.clear(pending.pop())
+
+    def clear(self, obj):
+        assert self.gcflag != 0
+        hdr = self.gc.header(obj)
+        if (hdr.tid & self.gcflag) != 0:
+            hdr.tid &= ~self.gcflag
+            self.pending.append(obj)
+
 def _hd_add_root(obj, heap_dumper):
     heap_dumper.add(obj)
 
+def _hd_clear_root(obj, heap_dumper):
+    heap_dumper.clear(obj)
+
 def dump_rpy_heap(gc, fd):
     heapdumper = HeapDumper(gc, fd)
     heapdumper.add_roots()

Modified: pypy/branch/jit-free/pypy/rpython/memory/gc/minimark.py
==============================================================================
--- pypy/branch/jit-free/pypy/rpython/memory/gc/minimark.py	(original)
+++ pypy/branch/jit-free/pypy/rpython/memory/gc/minimark.py	Sat Nov 20 15:12:44 2010
@@ -63,6 +63,7 @@
     needs_write_barrier = True
     prebuilt_gc_objects_are_static_roots = False
     malloc_zero_filled = True    # xxx experiment with False
+    gcflag_extra = GCFLAG_FINALIZATION_ORDERING
 
     # All objects start with a HDR, i.e. with a field 'tid' which contains
     # a word.  This word is divided in two halves: the lower half contains

Modified: pypy/branch/jit-free/pypy/rpython/memory/gc/semispace.py
==============================================================================
--- pypy/branch/jit-free/pypy/rpython/memory/gc/semispace.py	(original)
+++ pypy/branch/jit-free/pypy/rpython/memory/gc/semispace.py	Sat Nov 20 15:12:44 2010
@@ -42,6 +42,7 @@
     inline_simple_malloc_varsize = True
     malloc_zero_filled = True
     first_unused_gcflag = first_gcflag << 5
+    gcflag_extra = GCFLAG_FINALIZATION_ORDERING
 
     HDR = lltype.Struct('header', ('tid', lltype.Signed))   # XXX or rffi.INT?
     typeid_is_in_field = 'tid'



More information about the Pypy-commit mailing list