[pypy-commit] pypy gc_no_cleanup_nursery: Fix the *_clear variants by calling raw_memclear and use it from the JIT

fijal noreply at buildbot.pypy.org
Wed Sep 10 03:12:01 CEST 2014


Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: gc_no_cleanup_nursery
Changeset: r73411:5e81f151b049
Date: 2014-09-09 19:11 -0600
http://bitbucket.org/pypy/pypy/changeset/5e81f151b049/

Log:	Fix the *_clear variants by calling raw_memclear and use it from the
	JIT (it's important for blackhole and tracing)

diff --git a/rpython/jit/backend/llsupport/gc.py b/rpython/jit/backend/llsupport/gc.py
--- a/rpython/jit/backend/llsupport/gc.py
+++ b/rpython/jit/backend/llsupport/gc.py
@@ -423,8 +423,8 @@
                 self._random_usage_of_xmm_registers()
             type_id = rffi.cast(llgroup.HALFWORD, 0)    # missing here
             return llop1.do_malloc_fixedsize(llmemory.GCREF,
-                                                   type_id, size,
-                                                   False, False, False)
+                                             type_id, size,
+                                             False, False, False)
 
         self.generate_function('malloc_nursery', malloc_nursery_slowpath,
                                [lltype.Signed])
@@ -435,7 +435,7 @@
             assert num_elem >= 0, 'num_elem should be >= 0'
             type_id = llop.extract_ushort(llgroup.HALFWORD, tid)
             check_typeid(type_id)
-            return llop1.do_malloc_varsize(
+            return llop1.do_malloc_varsize_clear(
                 llmemory.GCREF,
                 type_id, num_elem, self.standard_array_basesize, itemsize,
                 self.standard_array_length_ofs)
@@ -449,7 +449,7 @@
             occur e.g. with arrays of floats on Win32."""
             type_id = llop.extract_ushort(llgroup.HALFWORD, tid)
             check_typeid(type_id)
-            return llop1.do_malloc_varsize(
+            return llop1.do_malloc_varsize_clear(
                 llmemory.GCREF,
                 type_id, num_elem, basesize, itemsize, lengthofs)
         self.generate_function('malloc_array_nonstandard',
@@ -491,7 +491,7 @@
                 self._random_usage_of_xmm_registers()
             type_id = llop.extract_ushort(llgroup.HALFWORD, tid)
             check_typeid(type_id)
-            return llop1.do_malloc_fixedsize(llmemory.GCREF,
+            return llop1.do_malloc_fixedsize_clear(llmemory.GCREF,
                                                    type_id, size,
                                                    False, False, False)
         self.generate_function('malloc_big_fixedsize', malloc_big_fixedsize,
@@ -502,7 +502,7 @@
         llop1 = self.llop1
         type_id = llop.extract_ushort(llgroup.HALFWORD, sizedescr.tid)
         check_typeid(type_id)
-        return llop1.do_malloc_fixedsize(llmemory.GCREF,
+        return llop1.do_malloc_fixedsize_clear(llmemory.GCREF,
                                                type_id, sizedescr.size,
                                                False, False, False)
 
@@ -511,7 +511,7 @@
         llop1 = self.llop1
         type_id = llop.extract_ushort(llgroup.HALFWORD, arraydescr.tid)
         check_typeid(type_id)
-        return llop1.do_malloc_varsize(llmemory.GCREF,
+        return llop1.do_malloc_varsize_clear(llmemory.GCREF,
                                              type_id, num_elem,
                                              arraydescr.basesize,
                                              arraydescr.itemsize,
diff --git a/rpython/jit/codewriter/codewriter.py b/rpython/jit/codewriter/codewriter.py
--- a/rpython/jit/codewriter/codewriter.py
+++ b/rpython/jit/codewriter/codewriter.py
@@ -13,7 +13,7 @@
 
 class CodeWriter(object):
     callcontrol = None    # for tests
-    debug = False
+    debug = True
 
     def __init__(self, cpu=None, jitdrivers_sd=[]):
         self.cpu = cpu
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
@@ -835,6 +835,21 @@
                   resultvar=op.result)
         self.pop_roots(hop, livevars)
 
+    def gct_do_malloc_fixedsize_clear(self, hop):
+        # used by the JIT (see rpython.jit.backend.llsupport.gc)
+        self.gct_do_malloc_fixedsize(hop)
+        if not self.malloc_zero_filled:
+            op = hop.spaceop
+            v_size = op.args[1]
+            c_fixedofs = rmodel.inputconst(lltype.Signed,
+                                           rffi.sizeof(lltype.Signed))
+            c_size = rmodel.inputconst(lltype.Signed, 1)
+            v_a = op.result
+            v_real_size = hop.genop('int_sub', [v_size, c_fixedofs],
+                                    resulttype=lltype.Signed)
+            self.emit_raw_memclear(hop.llops, v_real_size, c_size,
+                                   c_fixedofs, v_a)
+
     def gct_do_malloc_varsize(self, hop):
         # used by the JIT (see rpython.jit.backend.llsupport.gc)
         op = hop.spaceop
@@ -848,6 +863,17 @@
                   resultvar=op.result)
         self.pop_roots(hop, livevars)
 
+    def gct_do_malloc_varsize_clear(self, hop):
+        # used by the JIT (see rpython.jit.backend.llsupport.gc)
+        self.gct_do_malloc_fixedsize(hop)
+        if not self.malloc_zero_filled:
+            op = hop.spaceop
+            v_size = op.args[1]
+            c_fixedofs = op.args[2]
+            c_size = op.args[3]
+            v_a = op.result
+            self.emit_raw_memclear(hop.llops, v_size, c_size, c_fixedofs, v_a)
+
     def gct_get_write_barrier_failing_case(self, hop):
         op = hop.spaceop
         hop.genop("same_as",
@@ -1224,53 +1250,21 @@
                 v_size = llops.genop('getarraysize', [v],
                                      resulttype=lltype.Signed)
                 c_size = rmodel.inputconst(lltype.Signed, llmemory.sizeof(ITEM))
-                v_totalsize = llops.genop('int_mul', [v_size, c_size],
-                                          resulttype=lltype.Signed)
                 v_a = llops.genop('cast_ptr_to_adr', [v],
                                   resulttype=llmemory.Address)
                 c_fixedofs = rmodel.inputconst(lltype.Signed,
                                               llmemory.itemoffsetof(TYPE))
-                v_adr = llops.genop('adr_add', [v_a, c_fixedofs],
-                                    resulttype=llmemory.Address)
-                llops.genop('raw_memclear', [v_adr, v_totalsize])
+                self.emit_raw_memclear(llops, v_size, c_size, c_fixedofs, v_a)
             return
         else:
-            raise TypeError(TYPE)  
-        xxxx
-        if previous_steps is None:
-            previous_steps = []
-        assert (isinstance(TYPE, lltype.Struct) or isinstance(TYPE, lltype.Array))
-        if isinstance(TYPE, lltype.Struct):
-            for name in TYPE._names:
-                c_name = rmodel.inputconst(lltype.Void, name)
-                FIELD = getattr(TYPE, name)
-                #handle ptr field in GcStruct
-                if isinstance(FIELD, lltype.Ptr) and FIELD._needsgc():
-                    c_null = rmodel.inputconst(FIELD, lltype.nullptr(FIELD.TO))
-                    if not previous_steps:
-                        llops.genop('bare_setfield', [v, c_name, c_null])
-                    else:
-                        llops.genop('bare_setinteriorfield',
-                                [v] + previous_steps + [c_name, c_null])
-                #handle inside GcStruct field
-                elif isinstance(FIELD, lltype.Struct):
-                    gen_zero_gc_pointers(FIELD, v, llops, previous_steps + [c_name])
-                #handle inside GcArray field 
-                elif isinstance(FIELD, lltype.Array):
-                    gen_zero_gc_pointers(FIELD, v, llops, previous_steps + [c_name])
-        if isinstance(TYPE, lltype.Array):
-            ITEM = TYPE.OF
-            if previous_steps:
-                v = llop.genop('getinteriorfield',[v]+previous_steps)
-            arr_size = llops.genop('getarraysize',[v])
-            for i in range(arr_size):
-                #handle an array of GcPtr
-                if isinstance(ITEM, lltype.Ptr) and ITEM._needsgc():
-                    c_null = rmodel.inputconst(ITEM, lltype.nullptr(ITEM.TO))
-                    llops.genop('bare_setarrayitem',[v, i, c_null])
-                if isinstance(ITEM, lltype.Struct) or isinstance(ITEM, lltype.GcArray):
-                    array_item = llops.genop('getarrayitem',[v,i])
-                    gen_zero_gc_pointers(FIELD, array_item, llops, previous_steps)
+            raise TypeError(TYPE)
+
+    def emit_raw_memclear(self, llops, v_size, c_size, c_fixedofs, v_a):
+        v_totalsize = llops.genop('int_mul', [v_size, c_size],
+                                  resulttype=lltype.Signed)
+        v_adr = llops.genop('adr_add', [v_a, c_fixedofs],
+                            resulttype=llmemory.Address)
+        llops.genop('raw_memclear', [v_adr, v_totalsize])
 
 
 class TransformerLayoutBuilder(gctypelayout.TypeLayoutBuilder):
diff --git a/rpython/rtyper/lltypesystem/lloperation.py b/rpython/rtyper/lltypesystem/lloperation.py
--- a/rpython/rtyper/lltypesystem/lloperation.py
+++ b/rpython/rtyper/lltypesystem/lloperation.py
@@ -450,7 +450,9 @@
     'get_exception_addr':   LLOp(),
     'get_exc_value_addr':   LLOp(),
     'do_malloc_fixedsize':LLOp(canmallocgc=True),
+    'do_malloc_fixedsize_clear': LLOp(canmallocgc=True),
     'do_malloc_varsize':  LLOp(canmallocgc=True),
+    'do_malloc_varsize_clear':  LLOp(canmallocgc=True),
     'get_write_barrier_failing_case': LLOp(sideeffects=False),
     'get_write_barrier_from_array_failing_case': LLOp(sideeffects=False),
     'gc_get_type_info_group': LLOp(sideeffects=False),


More information about the pypy-commit mailing list