[pypy-svn] r46384 - in pypy/dist/pypy: rlib rpython rpython/lltypesystem translator/c translator/c/test translator/cli

arigo at codespeak.net arigo at codespeak.net
Fri Sep 7 10:42:34 CEST 2007


Author: arigo
Date: Fri Sep  7 10:42:34 2007
New Revision: 46384

Modified:
   pypy/dist/pypy/rlib/rgc.py
   pypy/dist/pypy/rpython/llinterp.py
   pypy/dist/pypy/rpython/lltypesystem/lloperation.py
   pypy/dist/pypy/translator/c/gc.py
   pypy/dist/pypy/translator/c/test/test_boehm.py
   pypy/dist/pypy/translator/cli/opcodes.py
Log:
Added rgc.set_max_heap_size(), turning into an operation that
is so far only implemented by the Boehm GC policy (it is a
no-op otherwise).


Modified: pypy/dist/pypy/rlib/rgc.py
==============================================================================
--- pypy/dist/pypy/rlib/rgc.py	(original)
+++ pypy/dist/pypy/rlib/rgc.py	Fri Sep  7 10:42:34 2007
@@ -1,5 +1,16 @@
+import gc
 from pypy.rpython.extregistry import ExtRegistryEntry
 # ____________________________________________________________
+# General GC features
+
+collect = gc.collect
+
+def set_max_heap_size(nbytes):
+    """Limit the heap size to n bytes.
+    So far only implemented by the Boehm GC."""
+    pass
+
+# ____________________________________________________________
 # Framework GC features
 
 class GcPool(object):
@@ -127,7 +138,6 @@
         return rtuple.newtuple(hop.llops, r_tuple, [v_gcobject, v_pool])
 
 # Support for collection.
-import gc
 
 class CollectEntry(ExtRegistryEntry):
     _about_ = gc.collect
@@ -139,4 +149,15 @@
     def specialize_call(self, hop):
         return hop.genop('gc__collect', [], resulttype=hop.r_result)
     
+class SetMaxHeapSizeEntry(ExtRegistryEntry):
+    _about_ = set_max_heap_size
 
+    def compute_result_annotation(self, s_nbytes):
+        from pypy.annotation import model as annmodel
+        return annmodel.s_None
+
+    def specialize_call(self, hop):
+        from pypy.rpython.lltypesystem import lltype
+        [v_nbytes] = hop.inputargs(lltype.Signed)
+        return hop.genop('gc_set_max_heap_size', [v_nbytes],
+                         resulttype=lltype.Void)

Modified: pypy/dist/pypy/rpython/llinterp.py
==============================================================================
--- pypy/dist/pypy/rpython/llinterp.py	(original)
+++ pypy/dist/pypy/rpython/llinterp.py	Fri Sep  7 10:42:34 2007
@@ -741,6 +741,9 @@
     def op_gc_reload_possibly_moved(self, newaddr, ptr):
         raise NotImplementedError("gc_reload_possibly_moved")
 
+    def op_gc_set_max_heap_size(self, maxsize):
+        raise NotImplementedError("gc_set_max_heap_size")
+
     def op_yield_current_frame_to_caller(self):
         raise NotImplementedError("yield_current_frame_to_caller")
 

Modified: pypy/dist/pypy/rpython/lltypesystem/lloperation.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/lloperation.py	(original)
+++ pypy/dist/pypy/rpython/lltypesystem/lloperation.py	Fri Sep  7 10:42:34 2007
@@ -384,6 +384,7 @@
     'gc_protect':           LLOp(),
     'gc_unprotect':         LLOp(),    
     'gc_reload_possibly_moved': LLOp(),
+    'gc_set_max_heap_size': LLOp(),
     # 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/dist/pypy/translator/c/gc.py
==============================================================================
--- pypy/dist/pypy/translator/c/gc.py	(original)
+++ pypy/dist/pypy/translator/c/gc.py	Fri Sep  7 10:42:34 2007
@@ -67,6 +67,9 @@
         expr = funcgen.expr(op.args[0])
         return 'Py_XDECREF(%s);' % expr
 
+    def OP_GC_SET_MAX_HEAP_SIZE(self, funcgen, op):
+        return ''
+
 
 class RefcountingInfo:
     static_deallocator = None
@@ -223,6 +226,10 @@
     def OP_GC__COLLECT(self, funcgen, op):
         return 'GC_gcollect(); GC_invoke_finalizers();'
 
+    def OP_GC_SET_MAX_HEAP_SIZE(self, funcgen, op):
+        nbytes = funcgen.expr(op.args[0])
+        return 'GC_set_max_heap_size(%s);' % (nbytes,)
+
 class BoehmGcRuntimeTypeInfo_OpaqueNode(ContainerNode):
     nodekind = 'boehm rtti'
     globalcontainer = True

Modified: pypy/dist/pypy/translator/c/test/test_boehm.py
==============================================================================
--- pypy/dist/pypy/translator/c/test/test_boehm.py	(original)
+++ pypy/dist/pypy/translator/c/test/test_boehm.py	Fri Sep  7 10:42:34 2007
@@ -266,6 +266,23 @@
         res = c_var_size()
         assert res == 0
 
+    def test_gc_set_max_heap_size(self):
+        def g(n):
+            return 'x' * n
+        def fn():
+            from pypy.rlib import rgc
+            rgc.set_max_heap_size(500000)
+            s1 = s2 = s3 = None
+            try:
+                s1 = g(10000)
+                s2 = g(100000)
+                s3 = g(1000000)
+            except MemoryError:
+                pass
+            return (s1 is not None) + (s2 is not None) + (s3 is not None)
+        c_fn = self.getcompiled(fn, [])
+        res = c_fn()
+        assert res == 2
 
 
 class TestUsingExactBoehm(TestUsingBoehm):

Modified: pypy/dist/pypy/translator/cli/opcodes.py
==============================================================================
--- pypy/dist/pypy/translator/cli/opcodes.py	(original)
+++ pypy/dist/pypy/translator/cli/opcodes.py	Fri Sep  7 10:42:34 2007
@@ -62,6 +62,7 @@
     'cast_ptr_to_weakadr':      [PushAllArgs, 'newobj instance void class %s::.ctor(object)' % WEAKREF],
     'cast_weakadr_to_ptr':      [CastWeakAdrToPtr],
     'gc__collect':              'call void class [mscorlib]System.GC::Collect()',
+    'gc_set_max_heap_size':     Ignore,
     'resume_point':             Ignore,
     'debug_assert':             Ignore,
 



More information about the Pypy-commit mailing list