[pypy-svn] r77096 - in pypy/branch/gen2-gc/pypy/rpython/memory/gc: . test

arigo at codespeak.net arigo at codespeak.net
Wed Sep 15 18:09:29 CEST 2010


Author: arigo
Date: Wed Sep 15 18:09:28 2010
New Revision: 77096

Modified:
   pypy/branch/gen2-gc/pypy/rpython/memory/gc/minimark.py
   pypy/branch/gen2-gc/pypy/rpython/memory/gc/minimarkpage.py
   pypy/branch/gen2-gc/pypy/rpython/memory/gc/test/test_direct.py
Log:
Bug fix with test.


Modified: pypy/branch/gen2-gc/pypy/rpython/memory/gc/minimark.py
==============================================================================
--- pypy/branch/gen2-gc/pypy/rpython/memory/gc/minimark.py	(original)
+++ pypy/branch/gen2-gc/pypy/rpython/memory/gc/minimark.py	Wed Sep 15 18:09:28 2010
@@ -1,6 +1,7 @@
 from pypy.rpython.lltypesystem import lltype, llmemory, llarena, llgroup
 from pypy.rpython.lltypesystem.lloperation import llop
 from pypy.rpython.memory.gc.base import MovingGCBase
+from pypy.rpython.memory.gc import minimarkpage
 from pypy.rpython.memory.support import DEFAULT_CHUNK_SIZE
 from pypy.rlib.rarithmetic import ovfcheck, LONG_BIT, intmask
 from pypy.rlib.debug import ll_assert, debug_print
@@ -77,7 +78,7 @@
         "arena_size": 65536*WORD,
 
         # The maximum size of an object allocated compactly.  All objects
-        # that are larger are just allocated with raw_malloc().
+        # that are larger or equal are just allocated with raw_malloc().
         "small_request_threshold": 32*WORD,
         }
 
@@ -85,7 +86,7 @@
                  nursery_size=32*WORD,
                  page_size=16*WORD,
                  arena_size=64*WORD,
-                 small_request_threshold=5*WORD,
+                 small_request_threshold=6*WORD,
                  ArenaCollectionClass=None):
         MovingGCBase.__init__(self, config, chunk_size)
         self.nursery_size = nursery_size
@@ -94,8 +95,7 @@
         #
         # The ArenaCollection() handles the nonmovable objects allocation.
         if ArenaCollectionClass is None:
-            from pypy.rpython.memory.gc.minimarkpage import ArenaCollection
-            ArenaCollectionClass = ArenaCollection
+            ArenaCollectionClass = minimarkpage.ArenaCollection
         self.ac = ArenaCollectionClass(arena_size, page_size,
                                        small_request_threshold)
         #
@@ -125,7 +125,7 @@
         # the start of the nursery: we actually allocate a tiny bit more for
         # the nursery than really needed, to simplify pointer arithmetic
         # in malloc_fixedsize_clear().
-        extra = self.small_request_threshold
+        extra = self.small_request_threshold - WORD
         self.nursery = llarena.arena_malloc(self.nursery_size + extra, True)
         if not self.nursery:
             raise MemoryError("cannot allocate nursery")
@@ -143,9 +143,9 @@
         size_gc_header = self.gcheaderbuilder.size_gc_header
         totalsize = size_gc_header + size
         #
-        # If totalsize is greater than small_request_threshold, ask for
-        # a rawmalloc.  The following check should be constant-folded.
-        if llmemory.raw_malloc_usage(totalsize) > self.small_request_threshold:
+        # If totalsize is greater or equal than small_request_threshold,
+        # ask for a rawmalloc.  The following check should be constant-folded.
+        if llmemory.raw_malloc_usage(totalsize)>=self.small_request_threshold:
             result = self.external_malloc(typeid, totalsize)
             #
         else:
@@ -182,7 +182,7 @@
         #
         # If totalsize is greater than small_request_threshold, ask for
         # a rawmalloc.
-        if llmemory.raw_malloc_usage(totalsize) > self.small_request_threshold:
+        if llmemory.raw_malloc_usage(totalsize)>=self.small_request_threshold:
             result = self.external_malloc(typeid, totalsize)
             #
         else:
@@ -443,6 +443,8 @@
             totalsize_incl_hash += llmemory.sizeof(lltype.Signed)
         # 
         # Allocate a new nonmovable location for it.
+        # Note that 'totalsize' must be < small_request_threshold, so
+        # 'totalsize_incl_hash <= small_request_threshold'.
         newhdr = self.ac.malloc(totalsize_incl_hash)
         newobj = newhdr + size_gc_header
         #
@@ -709,15 +711,7 @@
         #
         result = llarena.arena_malloc(nsize, False)
         #
-        # Custom hack for the hash
-        if (isinstance(size, llmemory.CompositeOffset) and
-            isinstance(size.offsets[-1], llmemory.ItemOffset) and
-            size.offsets[-1].TYPE == lltype.Signed):
-            size_of_int = llmemory.sizeof(lltype.Signed)
-            size = sum(size.offsets[1:-1], size.offsets[0])
-            llarena.arena_reserve(result + size, size_of_int)
-        #
-        llarena.arena_reserve(result, size)
+        minimarkpage.reserve_with_hash(result, size)
         self.all_objects.append(result)
         return result
 

Modified: pypy/branch/gen2-gc/pypy/rpython/memory/gc/minimarkpage.py
==============================================================================
--- pypy/branch/gen2-gc/pypy/rpython/memory/gc/minimarkpage.py	(original)
+++ pypy/branch/gen2-gc/pypy/rpython/memory/gc/minimarkpage.py	Wed Sep 15 18:09:28 2010
@@ -50,6 +50,8 @@
     _alloc_flavor_ = "raw"
 
     def __init__(self, arena_size, page_size, small_request_threshold):
+        # 'small_request_threshold' is the largest size that we
+        # can ask with self.malloc().
         self.arena_size = arena_size
         self.page_size = page_size
         self.small_request_threshold = small_request_threshold
@@ -116,7 +118,7 @@
             page.nextpage = self.full_page_for_size[size_class]
             self.full_page_for_size[size_class] = page
         #
-        llarena.arena_reserve(result, _dummy_size(size))
+        reserve_with_hash(result, _dummy_size(size))
         return result
 
 
@@ -337,3 +339,16 @@
     if isinstance(size, int):
         size = llmemory.sizeof(lltype.Char) * size
     return size
+
+def reserve_with_hash(result, size):
+    # XXX translation
+    #
+    # Custom hack for the hash
+    if (isinstance(size, llmemory.CompositeOffset) and
+            isinstance(size.offsets[-1], llmemory.ItemOffset) and
+            size.offsets[-1].TYPE == lltype.Signed):
+        size_of_int = llmemory.sizeof(lltype.Signed)
+        size = sum(size.offsets[1:-1], size.offsets[0])
+        llarena.arena_reserve(result + size, size_of_int)
+    #
+    llarena.arena_reserve(result, size)

Modified: pypy/branch/gen2-gc/pypy/rpython/memory/gc/test/test_direct.py
==============================================================================
--- pypy/branch/gen2-gc/pypy/rpython/memory/gc/test/test_direct.py	(original)
+++ pypy/branch/gen2-gc/pypy/rpython/memory/gc/test/test_direct.py	Wed Sep 15 18:09:28 2010
@@ -326,6 +326,15 @@
         self.gc.collect()
         assert hash == self.gc.identityhash(self.stackroots[-1])
         self.stackroots.pop()
+        # (6) ask for the hash of varsized objects, larger and larger
+        for i in range(10):
+            self.gc.collect()
+            p = self.malloc(VAR, i)
+            self.stackroots.append(p)
+            hash = self.gc.identityhash(p)
+            self.gc.collect()
+            assert hash == self.gc.identityhash(self.stackroots[-1])
+            self.stackroots.pop()
 
 class TestSemiSpaceGC(DirectGCTest):
     from pypy.rpython.memory.gc.semispace import SemiSpaceGC as GCClass



More information about the Pypy-commit mailing list