[pypy-commit] pypy default: Factor out this class in a file used only during tests.

arigo noreply at buildbot.pypy.org
Thu Jan 31 12:46:14 CET 2013


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r60764:2ac58df6d115
Date: 2013-01-31 12:36 +0100
http://bitbucket.org/pypy/pypy/changeset/2ac58df6d115/

Log:	Factor out this class in a file used only during tests.

diff --git a/rpython/rtyper/memory/gc/minimark.py b/rpython/rtyper/memory/gc/minimark.py
--- a/rpython/rtyper/memory/gc/minimark.py
+++ b/rpython/rtyper/memory/gc/minimark.py
@@ -47,7 +47,7 @@
 from rpython.rtyper.lltypesystem.lloperation import llop
 from rpython.rtyper.lltypesystem.llmemory import raw_malloc_usage
 from rpython.rtyper.memory.gc.base import GCBase, MovingGCBase
-from rpython.rtyper.memory.gc import minimarkpage, env
+from rpython.rtyper.memory.gc import env
 from rpython.rtyper.memory.support import mangle_hash
 from rpython.rlib.rarithmetic import ovfcheck, LONG_BIT, intmask, r_uint
 from rpython.rlib.rarithmetic import LONG_BIT_SHIFT
@@ -254,6 +254,7 @@
         #
         # The ArenaCollection() handles the nonmovable objects allocation.
         if ArenaCollectionClass is None:
+            from rpython.rtyper.memory.gc import minimarkpage
             ArenaCollectionClass = minimarkpage.ArenaCollection
         self.ac = ArenaCollectionClass(arena_size, page_size,
                                        small_request_threshold)
@@ -2033,43 +2034,3 @@
                 (obj + offset).address[0] = llmemory.NULL
         self.old_objects_with_weakrefs.delete()
         self.old_objects_with_weakrefs = new_with_weakref
-
-
-# ____________________________________________________________
-
-# For testing, a simple implementation of ArenaCollection.
-# This version could be used together with obmalloc.c, but
-# it requires an extra word per object in the 'all_objects'
-# list.
-
-class SimpleArenaCollection(object):
-
-    def __init__(self, arena_size, page_size, small_request_threshold):
-        self.arena_size = arena_size   # ignored
-        self.page_size = page_size
-        self.small_request_threshold = small_request_threshold
-        self.all_objects = []
-        self.total_memory_used = 0
-
-    def malloc(self, size):
-        nsize = raw_malloc_usage(size)
-        ll_assert(nsize > 0, "malloc: size is null or negative")
-        ll_assert(nsize <= self.small_request_threshold,"malloc: size too big")
-        ll_assert((nsize & (WORD-1)) == 0, "malloc: size is not aligned")
-        #
-        result = llarena.arena_malloc(nsize, False)
-        llarena.arena_reserve(result, size)
-        self.all_objects.append((result, nsize))
-        self.total_memory_used += nsize
-        return result
-
-    def mass_free(self, ok_to_free_func):
-        objs = self.all_objects
-        self.all_objects = []
-        self.total_memory_used = 0
-        for rawobj, nsize in objs:
-            if ok_to_free_func(rawobj):
-                llarena.arena_free(rawobj)
-            else:
-                self.all_objects.append((rawobj, nsize))
-                self.total_memory_used += nsize
diff --git a/rpython/rtyper/memory/gc/minimarktest.py b/rpython/rtyper/memory/gc/minimarktest.py
new file mode 100644
--- /dev/null
+++ b/rpython/rtyper/memory/gc/minimarktest.py
@@ -0,0 +1,44 @@
+from rpython.rtyper.lltypesystem import llarena
+from rpython.rtyper.lltypesystem.llmemory import raw_malloc_usage
+from rpython.rlib.debug import ll_assert
+from rpython.rlib.rarithmetic import LONG_BIT
+
+# For testing, a simple implementation of ArenaCollection.
+# This version could be used together with obmalloc.c, but
+# it requires an extra word per object in the 'all_objects'
+# list.
+
+WORD = LONG_BIT // 8
+
+
+class SimpleArenaCollection(object):
+
+    def __init__(self, arena_size, page_size, small_request_threshold):
+        self.arena_size = arena_size   # ignored
+        self.page_size = page_size
+        self.small_request_threshold = small_request_threshold
+        self.all_objects = []
+        self.total_memory_used = 0
+
+    def malloc(self, size):
+        nsize = raw_malloc_usage(size)
+        ll_assert(nsize > 0, "malloc: size is null or negative")
+        ll_assert(nsize <= self.small_request_threshold,"malloc: size too big")
+        ll_assert((nsize & (WORD-1)) == 0, "malloc: size is not aligned")
+        #
+        result = llarena.arena_malloc(nsize, False)
+        llarena.arena_reserve(result, size)
+        self.all_objects.append((result, nsize))
+        self.total_memory_used += nsize
+        return result
+
+    def mass_free(self, ok_to_free_func):
+        objs = self.all_objects
+        self.all_objects = []
+        self.total_memory_used = 0
+        for rawobj, nsize in objs:
+            if ok_to_free_func(rawobj):
+                llarena.arena_free(rawobj)
+            else:
+                self.all_objects.append((rawobj, nsize))
+                self.total_memory_used += nsize
diff --git a/rpython/rtyper/memory/gc/test/test_direct.py b/rpython/rtyper/memory/gc/test/test_direct.py
--- a/rpython/rtyper/memory/gc/test/test_direct.py
+++ b/rpython/rtyper/memory/gc/test/test_direct.py
@@ -481,7 +481,7 @@
 
 class TestMiniMarkGCSimple(DirectGCTest):
     from rpython.rtyper.memory.gc.minimark import MiniMarkGC as GCClass
-    from rpython.rtyper.memory.gc.minimark import SimpleArenaCollection
+    from rpython.rtyper.memory.gc.minimarktest import SimpleArenaCollection
     # test the GC itself, providing a simple class for ArenaCollection
     GC_PARAMS = {'ArenaCollectionClass': SimpleArenaCollection}
 
diff --git a/rpython/rtyper/memory/gc/test/test_inspector.py b/rpython/rtyper/memory/gc/test/test_inspector.py
--- a/rpython/rtyper/memory/gc/test/test_inspector.py
+++ b/rpython/rtyper/memory/gc/test/test_inspector.py
@@ -43,6 +43,6 @@
 
 class TestMiniMarkGCSimple(InspectorTest):
     from rpython.rtyper.memory.gc.minimark import MiniMarkGC as GCClass
-    from rpython.rtyper.memory.gc.minimark import SimpleArenaCollection
+    from rpython.rtyper.memory.gc.minimarktest import SimpleArenaCollection
     GC_PARAMS = {'ArenaCollectionClass': SimpleArenaCollection,
                  "card_page_indices": 4}


More information about the pypy-commit mailing list