[pypy-svn] r68965 - in pypy/branch/gc-jit-hack/pypy: rpython/lltypesystem rpython/memory/gctransform translator/c/test

arigo at codespeak.net arigo at codespeak.net
Wed Nov 4 11:27:53 CET 2009


Author: arigo
Date: Wed Nov  4 11:27:52 2009
New Revision: 68965

Modified:
   pypy/branch/gc-jit-hack/pypy/rpython/lltypesystem/lloperation.py
   pypy/branch/gc-jit-hack/pypy/rpython/memory/gctransform/framework.py
   pypy/branch/gc-jit-hack/pypy/translator/c/test/test_newgc.py
Log:
Interface resize_nursery() in framework.py, and test it in test_newgc.


Modified: pypy/branch/gc-jit-hack/pypy/rpython/lltypesystem/lloperation.py
==============================================================================
--- pypy/branch/gc-jit-hack/pypy/rpython/lltypesystem/lloperation.py	(original)
+++ pypy/branch/gc-jit-hack/pypy/rpython/lltypesystem/lloperation.py	Wed Nov  4 11:27:52 2009
@@ -467,7 +467,9 @@
     # ^^^ returns an address of nursery free pointer, for later modifications
     'gc_adr_of_nursery_top' : LLOp(),
     # ^^^ returns an address of pointer, since it can change at runtime
-    
+    'gc_resize_nursery':    LLOp(),
+
+    # ------- experimental -------
     # experimental operations in support of thread cloning, only
     # implemented by the Mark&Sweep GC
     'gc_x_swap_pool':       LLOp(canraise=(MemoryError,), canunwindgc=True),

Modified: pypy/branch/gc-jit-hack/pypy/rpython/memory/gctransform/framework.py
==============================================================================
--- pypy/branch/gc-jit-hack/pypy/rpython/memory/gctransform/framework.py	(original)
+++ pypy/branch/gc-jit-hack/pypy/rpython/memory/gctransform/framework.py	Wed Nov  4 11:27:52 2009
@@ -348,6 +348,10 @@
             self.obtainfreespace_ptr = getfn(GCClass.obtain_free_space.im_func,
                                              [s_gc, annmodel.SomeInteger()],
                                              annmodel.SomeAddress())
+        if getattr(GCClass, 'resize_nursery', False):
+            self.resizenursery_ptr = getfn(GCClass.resize_nursery.im_func,
+                                           [s_gc, annmodel.SomeInteger()],
+                                           annmodel.s_None)
 
         if GCClass.moving_gc:
             self.id_ptr = getfn(GCClass.id.im_func,
@@ -800,6 +804,16 @@
                   resultvar=hop.spaceop.result)
         self.pop_roots(hop, livevars)
 
+    def gct_gc_resize_nursery(self, hop):
+        if not hasattr(self, 'resizenursery_ptr'):
+            raise NotImplementedError("gc_resize_nursery: "
+                                      "only for generational gcs")
+        livevars = self.push_roots(hop)
+        [v_number] = hop.spaceop.args
+        hop.genop("direct_call",
+                  [self.resizenursery_ptr, self.c_const_gc, v_number])
+        self.pop_roots(hop, livevars)
+
     def gct_gc_set_max_heap_size(self, hop):
         [v_size] = hop.spaceop.args
         hop.genop("direct_call", [self.set_max_heap_size_ptr,

Modified: pypy/branch/gc-jit-hack/pypy/translator/c/test/test_newgc.py
==============================================================================
--- pypy/branch/gc-jit-hack/pypy/translator/c/test/test_newgc.py	(original)
+++ pypy/branch/gc-jit-hack/pypy/translator/c/test/test_newgc.py	Wed Nov  4 11:27:52 2009
@@ -932,10 +932,54 @@
         res = self.run('string_builder_over_allocation')
         assert res[1000] == 'y'
 
+
 class TestGenerationalGC(TestSemiSpaceGC):
     gcpolicy = "generation"
     should_be_moving = True
 
+    def define_resize_nursery(self):
+        # this is only a "does not crash" kind of test
+        from pypy.rlib.objectmodel import compute_identity_hash
+        import random
+        seed = random.randrange(0, 10000)
+        print 'resize_nursery: random seed =', seed
+        r = random.Random(seed)
+        events = []
+        maxcount = 10000000
+        for i in range(50):
+            events.append((r.randrange(0, maxcount),
+                           r.randrange(0, 9000)*1024))
+        events.sort()
+        events.append((maxcount, 0))   # sentinel
+        #
+        class A:
+            pass
+        def fn():
+            prev = None
+            i = 0
+            j = 0
+            while i < maxcount:
+                if i == events[j][0]:
+                    llop.gc_resize_nursery(lltype.Void, events[j][1])
+                    j += 1
+                a = A()
+                a.thehash = compute_identity_hash(a)
+                a.prev = prev
+                prev = a
+                i += 1
+            while i > 0:
+                i -= 1
+                assert a.thehash == compute_identity_hash(a)
+                a = a.prev
+            assert a is None
+            return 0
+        return fn
+
+    def test_resize_nursery(self):
+        res = self.run('resize_nursery')
+        assert res == 0
+
+
 class TestHybridGC(TestGenerationalGC):
     gcpolicy = "hybrid"
     should_be_moving = True



More information about the Pypy-commit mailing list