[pypy-svn] r58804 - pypy/branch/gc-experiments/pypy/rpython/memory/gc

arigo at codespeak.net arigo at codespeak.net
Wed Oct 8 13:46:21 CEST 2008


Author: arigo
Date: Wed Oct  8 13:46:20 2008
New Revision: 58804

Modified:
   pypy/branch/gc-experiments/pypy/rpython/memory/gc/base.py
   pypy/branch/gc-experiments/pypy/rpython/memory/gc/markcompact.py
   pypy/branch/gc-experiments/pypy/rpython/memory/gc/semispace.py
Log:
(fijal, arigo)
More shuffling.  Trying to minimize the size of the diff for semispace.py.


Modified: pypy/branch/gc-experiments/pypy/rpython/memory/gc/base.py
==============================================================================
--- pypy/branch/gc-experiments/pypy/rpython/memory/gc/base.py	(original)
+++ pypy/branch/gc-experiments/pypy/rpython/memory/gc/base.py	Wed Oct  8 13:46:20 2008
@@ -66,6 +66,23 @@
     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 get_size(self, obj):
+        typeid = self.get_type_id(obj)
+        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.varsize_item_sizes(typeid)
+            size = llarena.round_up_for_allocation(size)
+            # XXX maybe we should parametrize round_up_for_allocation()
+            # per GC; if we do, we also need to fix the call in
+            # gctypelayout.encode_type_shape()
+        return size
+
     def malloc(self, typeid, length=0, zero=False):
         """For testing.  The interface used by the gctransformer is
         the four malloc_[fixed,var]size[_clear]() functions.
@@ -193,19 +210,6 @@
     def debug_check_object(self, obj):
         pass
 
-    def get_size(self, obj):
-        typeid = self.get_type_id(obj)
-        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.varsize_item_sizes(typeid)
-            size = llarena.round_up_for_allocation(size)
-            # XXX maybe we should parametrize round_up_for_allocation()
-            # per GC; if we do, we also need to fix the call in
-            # gctypelayout.encode_type_shape()
-        return size
-
     def execute_finalizers(self):
         self.finalizer_lock_count += 1
         try:
@@ -219,6 +223,7 @@
         finally:
             self.finalizer_lock_count -= 1
 
+
 class MovingGCBase(GCBase):
     moving_gc = True
 
@@ -231,14 +236,6 @@
     def can_move(self, addr):
         return True
 
-    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, flags=0):
-        hdr = llmemory.cast_adr_to_ptr(addr, lltype.Ptr(self.HDR))
-        hdr.tid = typeid | flags
-
     def id(self, ptr):
         # Default implementation for id(), assuming that "external" objects
         # never move.  Overriden in the HybridGC.

Modified: pypy/branch/gc-experiments/pypy/rpython/memory/gc/markcompact.py
==============================================================================
--- pypy/branch/gc-experiments/pypy/rpython/memory/gc/markcompact.py	(original)
+++ pypy/branch/gc-experiments/pypy/rpython/memory/gc/markcompact.py	Wed Oct  8 13:46:20 2008
@@ -64,8 +64,8 @@
     first_unused_gcflag = first_gcflag << 2
 
     def __init__(self, chunk_size=DEFAULT_CHUNK_SIZE, space_size=4096):
-        self.space_size = space_size
         MovingGCBase.__init__(self, chunk_size)
+        self.space_size = space_size
         self.red_zone = 0
 
     def setup(self):

Modified: pypy/branch/gc-experiments/pypy/rpython/memory/gc/semispace.py
==============================================================================
--- pypy/branch/gc-experiments/pypy/rpython/memory/gc/semispace.py	(original)
+++ pypy/branch/gc-experiments/pypy/rpython/memory/gc/semispace.py	Wed Oct  8 13:46:20 2008
@@ -13,8 +13,6 @@
 
 import sys, os
 
-DEBUG_PRINT = False
-memoryError = MemoryError()
 TYPEID_MASK = 0xffff
 first_gcflag = 1 << 16
 GCFLAG_FORWARDED = first_gcflag
@@ -23,13 +21,15 @@
 GCFLAG_EXTERNAL = first_gcflag << 1
 GCFLAG_FINALIZATION_ORDERING = first_gcflag << 2
 
+DEBUG_PRINT = False
+memoryError = MemoryError()
+
 class SemiSpaceGC(MovingGCBase):
     _alloc_flavor_ = "raw"
     inline_simple_malloc = True
     inline_simple_malloc_varsize = True
     malloc_zero_filled = True
     first_unused_gcflag = first_gcflag << 3
-
     total_collection_time = 0.0
     total_collection_count = 0
 
@@ -63,22 +63,6 @@
         self.objects_with_finalizers = self.AddressDeque()
         self.objects_with_weakrefs = self.AddressStack()
 
-    def init_gc_object_immortal(self, addr, typeid, flags=0):
-        hdr = llmemory.cast_adr_to_ptr(addr, lltype.Ptr(self.HDR))
-        hdr.tid = typeid | flags | GCFLAG_EXTERNAL | GCFLAG_FORWARDED
-        # immortal objects always have GCFLAG_FORWARDED set;
-        # see get_forwarding_address().
-
-    def get_type_id(self, addr):
-        tid = self.header(addr).tid
-        ll_assert(tid & (GCFLAG_FORWARDED|GCFLAG_EXTERNAL) != GCFLAG_FORWARDED,
-                  "get_type_id on forwarded obj")
-        # Non-prebuilt forwarded objects are overwritten with a FORWARDSTUB.
-        # Although calling get_type_id() on a forwarded object works by itself,
-        # we catch it as an error because it's likely that what is then
-        # done with the typeid is bogus.
-        return tid & TYPEID_MASK
-
     # This class only defines the malloc_{fixed,var}size_clear() methods
     # because the spaces are filled with zeroes in advance.
 
@@ -395,6 +379,26 @@
         stub = llmemory.cast_adr_to_ptr(obj, self.FORWARDSTUBPTR)
         stub.forw = newobj
 
+    def get_type_id(self, addr):
+        tid = self.header(addr).tid
+        ll_assert(tid & (GCFLAG_FORWARDED|GCFLAG_EXTERNAL) != GCFLAG_FORWARDED,
+                  "get_type_id on forwarded obj")
+        # Non-prebuilt forwarded objects are overwritten with a FORWARDSTUB.
+        # Although calling get_type_id() on a forwarded object works by itself,
+        # we catch it as an error because it's likely that what is then
+        # done with the typeid is bogus.
+        return tid & TYPEID_MASK
+
+    def init_gc_object(self, addr, typeid, flags=0):
+        hdr = llmemory.cast_adr_to_ptr(addr, lltype.Ptr(self.HDR))
+        hdr.tid = typeid | flags
+
+    def init_gc_object_immortal(self, addr, typeid, flags=0):
+        hdr = llmemory.cast_adr_to_ptr(addr, lltype.Ptr(self.HDR))
+        hdr.tid = typeid | flags | GCFLAG_EXTERNAL | GCFLAG_FORWARDED
+        # immortal objects always have GCFLAG_FORWARDED set;
+        # see get_forwarding_address().
+
     def deal_with_objects_with_finalizers(self, scan):
         # walk over list of objects with finalizers
         # if it is not copied, add it to the list of to-be-called finalizers
@@ -553,4 +557,3 @@
 
     STATISTICS_NUMBERS = 0
 
-



More information about the Pypy-commit mailing list