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

Log:    track the type of integers too

diff --git a/pypy/interpreter/test/test_valueprof.py 
b/pypy/interpreter/test/test_valueprof.py
--- a/pypy/interpreter/test/test_valueprof.py
+++ b/pypy/interpreter/test/test_valueprof.py
@@ -28,14 +28,18 @@
     v.see_write(ValueInt(1))
     assert v.read_constant_int() == 1
     assert v._vprof_status == SEEN_CONSTANT_INT
-    v.see_int(2)
-    assert v._vprof_status == SEEN_TOO_MUCH
-    v.see_int(1)
-    assert v._vprof_status == SEEN_TOO_MUCH
-    v.see_int(2)
-    assert v._vprof_status == SEEN_TOO_MUCH
-    v.see_int(3)
-    assert v._vprof_status == SEEN_TOO_MUCH
+    v.see_write(ValueInt(2))
+    assert v._vprof_status == SEEN_CONSTANT_CLASS
+    assert v._vprof_const_cls is ValueInt
+    v.see_write(ValueInt(1))
+    assert v._vprof_status == SEEN_CONSTANT_CLASS
+    assert v._vprof_const_cls is ValueInt
+    v.see_write(ValueInt(2))
+    assert v._vprof_status == SEEN_CONSTANT_CLASS
+    assert v._vprof_const_cls is ValueInt
+    v.see_write(ValueInt(3))
+    assert v._vprof_status == SEEN_CONSTANT_CLASS
+    assert v._vprof_const_cls is ValueInt
 
     v = ValueProf()
     assert v._vprof_status == SEEN_NOTHING
@@ -56,7 +60,7 @@
     v.see_write(value)
     assert v.try_read_constant_obj() is value
     assert v._vprof_status == SEEN_CONSTANT_OBJ
-    v.see_int(2)
+    v.see_write(ValueInt(2))
     assert v._vprof_status == SEEN_TOO_MUCH
 
     v = ValueProf()
@@ -103,5 +107,5 @@
     assert v._vprof_status == SEEN_CONSTANT_OBJ
     v.see_write(Value())
     assert v._vprof_status == SEEN_CONSTANT_CLASS
-    v.see_int(5)
+    v.see_write(ValueInt(5))
     assert v._vprof_status == SEEN_TOO_MUCH
diff --git a/pypy/interpreter/valueprof.py b/pypy/interpreter/valueprof.py
--- a/pypy/interpreter/valueprof.py
+++ b/pypy/interpreter/valueprof.py
@@ -33,10 +33,10 @@
         if self._vprof_status == SEEN_TOO_MUCH:
             return
         if self.is_int(w_value):
-            return self.see_int(self.get_int_val(w_value))
-        return self.see_object(w_value)
+            return self._see_int(self.get_int_val(w_value), w_value)
+        return self._see_object(w_value)
 
-    def see_int(self, value):
+    def _see_int(self, value, w_value):
         status = self._vprof_status
         if status == SEEN_NOTHING:
             self._vprof_value_int = value
@@ -45,7 +45,8 @@
             if self.read_constant_int() != value:
                 if self._vprof_counter >= 200:
                     print "NO LONGER CONSTANT", self._vprof_msg, 'int', value
-                self._vprof_status = SEEN_TOO_MUCH
+                self._vprof_status = SEEN_CONSTANT_CLASS
+                self._vprof_const_cls = type(w_value)
             else:
                 if not jit.we_are_jitted():
                     self._vprof_counter += 1
@@ -56,9 +57,10 @@
             if self._vprof_counter >= 200:
                 print "NO LONGER CONSTANT", self._vprof_msg, 'int', value
         elif status == SEEN_CONSTANT_CLASS:
-            self._vprof_status = SEEN_TOO_MUCH
+            if type(w_value) is not self._vprof_const_cls:
+                self._vprof_status = SEEN_TOO_MUCH
 
-    def see_object(self, value):
+    def _see_object(self, value):
         status = self._vprof_status
         if value is None:
             if status != SEEN_TOO_MUCH:
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to