Author: Carl Friedrich Bolz <[email protected]>
Branch: value-profiling
Changeset: r78937:0fbb6b5d0ff3
Date: 2015-08-12 17:45 +0200
http://bitbucket.org/pypy/pypy/changeset/0fbb6b5d0ff3/

Log:    feed the known classes to the JIT

diff --git a/pypy/interpreter/pyframe.py b/pypy/interpreter/pyframe.py
--- a/pypy/interpreter/pyframe.py
+++ b/pypy/interpreter/pyframe.py
@@ -147,9 +147,9 @@
 
     def _getlocal(self, varindex):
         from pypy.objspace.std.intobject import W_IntObject
+        # some careful logic there
         if we_are_jitted():
             vprof = self.getcode().vprofs[varindex]
-            # some careful logic there
             if vprof.can_fold_read_int():
                 return W_IntObject(vprof.read_constant_int())
             elif vprof.can_fold_read_obj():
@@ -157,6 +157,8 @@
                 if w_res is not None:
                     return w_res
         w_res = self.locals_cells_stack_w[varindex]
+        if we_are_jitted() and vprof.class_is_known():
+            jit.record_known_class(w_res, vprof.read_constant_cls())
         return w_res
 
     def _setlocal(self, varindex, value):
diff --git a/pypy/objspace/std/mapdict.py b/pypy/objspace/std/mapdict.py
--- a/pypy/objspace/std/mapdict.py
+++ b/pypy/objspace/std/mapdict.py
@@ -36,12 +36,13 @@
         if attr is None:
             return self.terminator._read_terminator(obj, selector)
         # XXX move to PlainAttribute?
-        if attr.can_fold_read_int():
-            return W_IntObject(attr.read_constant_int())
-        elif attr.can_fold_read_obj():
-            w_res = attr.try_read_constant_obj()
-            if w_res is not None:
-                return w_res
+        if jit.we_are_jitted():
+            if attr.can_fold_read_int():
+                return W_IntObject(attr.read_constant_int())
+            elif attr.can_fold_read_obj():
+                w_res = attr.try_read_constant_obj()
+                if w_res is not None:
+                    return w_res
         if (
             jit.isconstant(attr.storageindex) and
             jit.isconstant(obj) and
@@ -49,7 +50,10 @@
         ):
             return self._pure_mapdict_read_storage(obj, attr.storageindex)
         else:
-            return obj._mapdict_read_storage(attr.storageindex)
+            w_res = obj._mapdict_read_storage(attr.storageindex)
+            if jit.we_are_jitted() and attr.class_is_known():
+                jit.record_known_class(w_res, attr.read_constant_cls())
+            return w_res
 
     @jit.elidable
     def _pure_mapdict_read_storage(self, obj, storageindex):
diff --git a/pypy/objspace/std/test/test_mapdict.py 
b/pypy/objspace/std/test/test_mapdict.py
--- a/pypy/objspace/std/test/test_mapdict.py
+++ b/pypy/objspace/std/test/test_mapdict.py
@@ -350,6 +350,7 @@
         assert c.terminator.size_estimate() in [(i + 10) // 2, (i + 11) // 2]
 
 def test_value_profiling(monkeypatch):
+    monkeypatch.setattr(jit, "we_are_jitted", lambda : True)
     class Value:
         pass
     a = Value()
@@ -374,6 +375,28 @@
     assert not obj.map.can_fold_read_obj()
 
 
+def test_value_profiling_known_cls(monkeypatch):
+    class Value(object):
+        pass
+    a = Value()
+    cls = Class()
+    obj = cls.instantiate()
+    a1 = Value()
+    obj.setdictvalue(space, "a", a1)
+    obj = cls.instantiate()
+    obj.setdictvalue(space, "a", a1)
+    obj.setdictvalue(space, "a", a)
+
+    seen = []
+    def f(obj, cls):
+        seen.append((obj, cls))
+    monkeypatch.setattr(jit, "we_are_jitted", lambda : True)
+    monkeypatch.setattr(jit, "record_known_class", f)
+
+    assert obj.getdictvalue(space, "a") == a
+    assert obj.getdictvalue(space, "a") == a
+    assert seen == [(a, Value), (a, Value)]
+
 # ___________________________________________________________
 # dict tests
 
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to