[pypy-commit] pypy gc_no_cleanup_nursery: fixes

fijal noreply at buildbot.pypy.org
Wed Sep 3 21:50:12 CEST 2014


Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: gc_no_cleanup_nursery
Changeset: r73290:6a7d16b9825a
Date: 2014-09-03 13:49 -0600
http://bitbucket.org/pypy/pypy/changeset/6a7d16b9825a/

Log:	fixes

diff --git a/rpython/memory/gctransform/framework.py b/rpython/memory/gctransform/framework.py
--- a/rpython/memory/gctransform/framework.py
+++ b/rpython/memory/gctransform/framework.py
@@ -867,6 +867,12 @@
             TYPE = v_ob.concretetype.TO
             self.gen_zero_gc_pointers(TYPE, v_ob, hop.llops)
 
+    def gct_zero_everything_inside(self, hop):
+        if not self.malloc_zero_filled:
+            v_ob = hop.spaceop.args[0]
+            TYPE = v_ob.concretetype.TO
+            self.gen_zero_gc_pointers(TYPE, v_ob, hop.llops, everything=True)
+
     def gct_gc_writebarrier_before_copy(self, hop):
         op = hop.spaceop
         if not hasattr(self, 'wb_before_copy_ptr'):
@@ -1172,21 +1178,37 @@
     def pop_roots(self, hop, livevars):
         raise NotImplementedError
 
-    def gen_zero_gc_pointers(self, TYPE, v, llops, previous_steps=None):
+    def gen_zero_gc_pointers(self, TYPE, v, llops, previous_steps=None,
+                             everything=False):
         if isinstance(TYPE, lltype.Struct):
             for name in TYPE._names:
                 FIELD = getattr(TYPE, name)
-                if isinstance(FIELD, lltype.Ptr) and FIELD._needsgc():
+                if ((isinstance(FIELD, lltype.Ptr) and FIELD._needsgc())
+                    or everything):
                     c_name = rmodel.inputconst(lltype.Void, name)
-                    c_null = rmodel.inputconst(FIELD, lltype.nullptr(FIELD.TO))
+                    c_null = rmodel.inputconst(FIELD, FIELD._defl())
                     llops.genop('bare_setfield', [v, c_name, c_null])
                 elif (isinstance(FIELD, lltype.Array) and
                       isinstance(FIELD.OF, lltype.Ptr) and FIELD.OF._needsgc()):
                     xxx
+         
             return
         elif isinstance(TYPE, lltype.Array):
             ITEM = TYPE.OF
-            if isinstance(ITEM, lltype.Ptr) and ITEM._needsgc():
+            if everything:
+                needs_clearing = True
+            elif isinstance(ITEM, lltype.Ptr) and ITEM._needsgc():
+                needs_clearing = True
+            elif isinstance(ITEM, lltype.Struct):
+                for SUBITEM in ITEM._flds.values():
+                    if isinstance(SUBITEM, lltype.Ptr) and SUBITEM._needsgc():
+                        needs_clearing = True
+                        break
+                else:
+                    needs_clearing = False
+            else:
+                needs_clearing = False
+            if needs_clearing:
                 v_size = llops.genop('getarraysize', [v],
                                      resulttype=lltype.Signed)
                 c_size = rmodel.inputconst(lltype.Signed, llmemory.sizeof(ITEM))
@@ -1199,8 +1221,6 @@
                 v_adr = llops.genop('adr_add', [v_a, c_fixedofs],
                                     resulttype=llmemory.Address)
                 llops.genop('raw_memclear', [v_adr, v_totalsize])
-            elif isinstance(ITEM, lltype.Struct):
-                xxx
             return
         else:
             raise TypeError(TYPE)  
diff --git a/rpython/translator/c/test/test_newgc.py b/rpython/translator/c/test/test_newgc.py
--- a/rpython/translator/c/test/test_newgc.py
+++ b/rpython/translator/c/test/test_newgc.py
@@ -1194,6 +1194,20 @@
     def test_gcflag_extra(self):
         self.run("gcflag_extra")
 
+    def define_check_zero_works(self):
+        S = lltype.GcStruct("s", ('x', lltype.Signed))
+        A = lltype.GcArray(lltype.Signed)
+        
+        def fn():
+            s = lltype.malloc(S, zero=True)
+            assert s.x == 0
+            a = lltype.malloc(A, 3, zero=True)
+            assert a[2] == 0
+            return 0
+        return fn
+
+    def test_check_zero_works(self):
+        self.run("check_zero_works")
 
 class TestSemiSpaceGC(UsingFrameworkTest, snippet.SemiSpaceGCTestDefines):
     gcpolicy = "semispace"
diff --git a/rpython/translator/exceptiontransform.py b/rpython/translator/exceptiontransform.py
--- a/rpython/translator/exceptiontransform.py
+++ b/rpython/translator/exceptiontransform.py
@@ -251,7 +251,7 @@
               len(block.operations) and
               (block.exits[0].args[0].concretetype is lltype.Void or
                block.exits[0].args[0] is block.operations[-1].result) and
-              block.operations[-1].opname != 'malloc'):     # special cases
+              block.operations[-1].opname not in ('malloc', 'malloc_varsize')):     # special cases
             last_operation -= 1
         lastblock = block
         for i in range(last_operation, -1, -1):
@@ -422,6 +422,7 @@
             flavor = spaceop.args[1].value['flavor']
             if flavor == 'gc':
                 insert_zeroing_op = True
+            true_zero = spaceop.args[1].value.get('zero', False)
         # NB. when inserting more special-cases here, keep in mind that
         # you also need to list the opnames in transform_block()
         # (see "special cases")
@@ -437,9 +438,12 @@
                 v_result_after = copyvar(None, v_result)
                 l0.args.append(v_result)
                 normalafterblock.inputargs.append(v_result_after)
+            if true_zero:
+                opname = "zero_everything_inside"
+            else:
+                opname = "zero_gc_pointers_inside"
             normalafterblock.operations.insert(
-                0, SpaceOperation('zero_gc_pointers_inside',
-                                  [v_result_after],
+                0, SpaceOperation(opname, [v_result_after],
                                   varoftype(lltype.Void)))
 
     def setup_excdata(self):


More information about the pypy-commit mailing list