[pypy-commit] pypy vref-copy: a branch to experiment with speeding up sys._getframe and friends.
fijal
noreply at buildbot.pypy.org
Sat Aug 11 13:36:31 CEST 2012
Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: vref-copy
Changeset: r56704:86d4d71f2652
Date: 2012-08-11 13:34 +0200
http://bitbucket.org/pypy/pypy/changeset/86d4d71f2652/
Log: a branch to experiment with speeding up sys._getframe and friends.
diff --git a/pypy/rlib/_jit_vref.py b/pypy/rlib/_jit_vref.py
--- a/pypy/rlib/_jit_vref.py
+++ b/pypy/rlib/_jit_vref.py
@@ -26,8 +26,12 @@
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':
@@ -67,10 +71,17 @@
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
diff --git a/pypy/rlib/jit.py b/pypy/rlib/jit.py
--- a/pypy/rlib/jit.py
+++ b/pypy/rlib/jit.py
@@ -352,6 +352,17 @@
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'
diff --git a/pypy/rlib/test/test__jit_vref.py b/pypy/rlib/test/test__jit_vref.py
--- a/pypy/rlib/test/test__jit_vref.py
+++ b/pypy/rlib/test/test__jit_vref.py
@@ -14,7 +14,7 @@
from pypy.rpython.ootypesystem import ootype
class X(object):
- pass
+ x = 3
class Y(X):
pass
@@ -145,6 +145,12 @@
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
@@ -155,3 +161,6 @@
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")
diff --git a/pypy/rpython/lltypesystem/lloperation.py b/pypy/rpython/lltypesystem/lloperation.py
--- a/pypy/rpython/lltypesystem/lloperation.py
+++ b/pypy/rpython/lltypesystem/lloperation.py
@@ -432,6 +432,7 @@
'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(),
diff --git a/pypy/rpython/lltypesystem/opimpl.py b/pypy/rpython/lltypesystem/opimpl.py
--- a/pypy/rpython/lltypesystem/opimpl.py
+++ b/pypy/rpython/lltypesystem/opimpl.py
@@ -560,6 +560,9 @@
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
More information about the pypy-commit
mailing list