Commits

Maciej Fijalkowski committed 86d4d71

a branch to experiment with speeding up sys._getframe and friends.

  • Participants
  • Parent commits ed72686
  • Branches vref-copy

Comments (0)

Files changed (5)

File pypy/rlib/_jit_vref.py

         return self.s_instance
 
     def getattr(self, s_attr):
-        assert s_attr.const == 'virtual'
-        return annmodel.s_Bool
+        if s_attr.const == 'virtual':
+            return annmodel.s_Bool
+        elif s_attr.const == 'dereference_or_copy':
+            return self.s_instance
+        else:
+            raise AssertionError("Unknown attribute %s" % s_attr.const)
 
     def rtyper_makerepr(self, rtyper):
         if rtyper.type_system.name == 'lltypesystem':
 
     def rtype_getattr(self, hop):
         s_attr = hop.args_s[1]
-        assert s_attr.const == 'virtual'
+        hop.exception_cannot_occur()
         v = hop.inputarg(self, arg=0)
-        hop.exception_cannot_occur()
-        return hop.genop('jit_is_virtual', [v], resulttype = lltype.Bool)
+        if s_attr.const == 'virtual':
+            return hop.genop('jit_is_virtual', [v], resulttype = lltype.Bool)
+        elif s_attr.const == 'dereference_or_copy':
+            v_result = hop.genop('jit_dereference_or_copy', [v],
+                                 resulttype = OBJECTPTR)
+            return hop.genop('cast_pointer', [v_result],
+                             resulttype = hop.r_result)
+        else:
+            raise AssertionError("Unknown attribute %s" % s_attr.const)
 
 from pypy.rpython.ootypesystem.rclass import OBJECT
 

File pypy/rlib/jit.py

         be forced by the '()' operator."""
         return self._state == 'non-forced'
 
+    @property
+    def dereference_or_copy(self):
+        """ Get a forced version, but without forcing the original virtual.
+        Useful for things like profilers where we want the object, but
+        we don't care if modifications will be reflected in the underlaying
+        JIT code.
+        """
+        # note that this always returns the original object and never
+        # a copy when untranslated
+        return self._x
+
     def _finish(self):
         if self._state == 'non-forced':
             self._state = 'invalid'

File pypy/rlib/test/test__jit_vref.py

 from pypy.rpython.ootypesystem import ootype
 
 class X(object):
-    pass
+    x = 3
 
 class Y(X):
     pass
         x = self.interpret(f, [])
         assert x is False
 
+    def test_rtype_dereference_or_copy(self):
+        def f():
+            vref = virtual_ref(X())
+            return vref.dereference_or_copy.x
+        x = self.interpret(f, [])
+        assert x == 3
 
 class TestLLtype(BaseTestVRef, LLRtypeMixin):
     OBJECTTYPE = OBJECTPTR
     OBJECTTYPE = OBJECT 
     def castable(self, TO, var):
         return ootype.isSubclass(lltype.typeOf(var), TO)
+
+    def test_rtype_dereference_or_copy(self):
+        py.test.skip("not supported")

File pypy/rpython/lltypesystem/lloperation.py

     'jit_force_virtualizable':LLOp(canrun=True),
     'jit_force_virtual':    LLOp(canrun=True),
     'jit_is_virtual':       LLOp(canrun=True),
+    'jit_dereference_or_copy': LLOp(canrun=True),
     'jit_force_quasi_immutable': LLOp(canrun=True),
     'jit_record_known_class'  : LLOp(canrun=True),
     'get_exception_addr':   LLOp(),

File pypy/rpython/lltypesystem/opimpl.py

 def op_jit_is_virtual(x):
     return False
 
+def op_jit_dereference_or_copy(x):
+    return x
+
 def op_jit_force_quasi_immutable(*args):
     pass