[pypy-commit] pypy stmgc-static-barrier: If gcremovetypeptr, we can access directly the typeptr

arigo noreply at buildbot.pypy.org
Thu Aug 15 08:03:41 CEST 2013


Author: Armin Rigo <arigo at tunes.org>
Branch: stmgc-static-barrier
Changeset: r66160:c238e056d75b
Date: 2013-08-15 08:03 +0200
http://bitbucket.org/pypy/pypy/changeset/c238e056d75b/

Log:	If gcremovetypeptr, we can access directly the typeptr field even on
	a stub.

diff --git a/rpython/translator/stm/test/test_writebarrier.py b/rpython/translator/stm/test/test_writebarrier.py
--- a/rpython/translator/stm/test/test_writebarrier.py
+++ b/rpython/translator/stm/test/test_writebarrier.py
@@ -325,6 +325,42 @@
         assert res == 81
         assert self.barriers == []
 
+    def test_isinstance(self):
+        class Base: pass
+        class A(Base): pass
+
+        def f1(n):
+            if n > 1:
+                x = Base()
+            else:
+                x = A()
+            return isinstance(x, A)
+
+        res = self.interpret(f1, [5])
+        assert res == False
+        assert self.barriers == ['a2i']
+        res = self.interpret(f1, [-5])
+        assert res == True
+        assert self.barriers == ['a2i']
+
+    def test_isinstance_gcremovetypeptr(self):
+        class Base: pass
+        class A(Base): pass
+
+        def f1(n):
+            if n > 1:
+                x = Base()
+            else:
+                x = A()
+            return isinstance(x, A)
+
+        res = self.interpret(f1, [5], gcremovetypeptr=True)
+        assert res == False
+        assert self.barriers == []
+        res = self.interpret(f1, [-5], gcremovetypeptr=True)
+        assert res == True
+        assert self.barriers == []
+
 
 external_release_gil = rffi.llexternal('external_release_gil', [], lltype.Void,
                                        _callable=lambda: None,
diff --git a/rpython/translator/stm/test/transform_support.py b/rpython/translator/stm/test/transform_support.py
--- a/rpython/translator/stm/test/transform_support.py
+++ b/rpython/translator/stm/test/transform_support.py
@@ -38,7 +38,7 @@
             return 'I'     # allocated with immortal=True
         raise AssertionError("unknown category on %r" % (p,))
 
-    def interpret(self, fn, args):
+    def interpret(self, fn, args, gcremovetypeptr=False):
         self.build_state()
         clear_tcache()
         interp, self.graph = get_interpreter(fn, args, view=False)
@@ -46,6 +46,7 @@
         interp.frame_class = LLSTMFrame
         #
         self.translator = interp.typer.annotator.translator
+        self.translator.config.translation.gcremovetypeptr = gcremovetypeptr
         self.stmtransformer = STMTransformer(self.translator)
         if self.do_jit_driver:
             self.stmtransformer.transform_jit_driver()
diff --git a/rpython/translator/stm/writebarrier.py b/rpython/translator/stm/writebarrier.py
--- a/rpython/translator/stm/writebarrier.py
+++ b/rpython/translator/stm/writebarrier.py
@@ -51,6 +51,8 @@
        pointer from category x to category y if and only if y > x.
     """
     graphinfo = stmtransformer.write_analyzer.compute_graph_info(graph)
+    gcremovetypeptr = (
+        stmtransformer.translator.config.translation.gcremovetypeptr)
 
     def get_category(v):
         if isinstance(v, Constant):
@@ -85,7 +87,15 @@
                                        'getinteriorfield') and
                          op.result.concretetype is not lltype.Void and
                          op.args[0].concretetype.TO._gckind == 'gc')
-            if (op.opname in ('getarraysize', 'getinteriorarraysize')
+
+            if (gcremovetypeptr and op.opname in ('getfield', 'setfield') and
+                op.args[1].value == 'typeptr' and
+                op.args[0].concretetype.TO._hints.get('typeptr')):
+                # if gcremovetypeptr, we can access directly the typeptr
+                # field even on a stub
+                pass
+
+            elif (op.opname in ('getarraysize', 'getinteriorarraysize')
                 or (is_getter and is_immutable(op))):
                 # we can't leave getarraysize or the immutable getfields
                 # fully unmodified: we need at least immut_read_barrier


More information about the pypy-commit mailing list