[pypy-commit] pypy default: new objects have a known class

cfbolz noreply at buildbot.pypy.org
Thu Jul 7 15:39:04 CEST 2011


Author: Carl Friedrich Bolz <cfbolz at gmx.de>
Branch: 
Changeset: r45409:01e4f337b79a
Date: 2011-07-07 15:47 +0200
http://bitbucket.org/pypy/pypy/changeset/01e4f337b79a/

Log:	new objects have a known class

diff --git a/pypy/jit/metainterp/pyjitpl.py b/pypy/jit/metainterp/pyjitpl.py
--- a/pypy/jit/metainterp/pyjitpl.py
+++ b/pypy/jit/metainterp/pyjitpl.py
@@ -365,7 +365,9 @@
     def opimpl_new_with_vtable(self, sizedescr):
         cpu = self.metainterp.cpu
         cls = heaptracker.descr2vtable(cpu, sizedescr)
-        return self.execute(rop.NEW_WITH_VTABLE, ConstInt(cls))
+        resbox = self.execute(rop.NEW_WITH_VTABLE, ConstInt(cls))
+        self.metainterp.known_class_boxes[resbox] = None
+        return resbox
 
 ##    @FixME  #arguments("box")
 ##    def opimpl_runtimenew(self, classbox):
diff --git a/pypy/jit/metainterp/test/test_ajit.py b/pypy/jit/metainterp/test/test_ajit.py
--- a/pypy/jit/metainterp/test/test_ajit.py
+++ b/pypy/jit/metainterp/test/test_ajit.py
@@ -1026,6 +1026,27 @@
             pass
         class B(A):
             pass
+        a = A()
+        b = B()
+        def fn(n):
+            if n == -7:
+                obj = None
+            elif n:
+                obj = a
+            else:
+                obj = b
+            return isinstance(obj, B) + isinstance(obj, B) + isinstance(obj, B) + isinstance(obj, B)
+        res = self.interp_operations(fn, [0])
+        assert res == 4
+        self.check_operations_history(guard_class=1, guard_nonnull=1)
+        res = self.interp_operations(fn, [1])
+        assert not res
+
+    def test_dont_record_guard_class_after_new(self):
+        class A:
+            pass
+        class B(A):
+            pass
         def fn(n):
             if n == -7:
                 obj = None
@@ -1036,7 +1057,7 @@
             return isinstance(obj, B) + isinstance(obj, B) + isinstance(obj, B) + isinstance(obj, B)
         res = self.interp_operations(fn, [0])
         assert res == 4
-        self.check_operations_history(guard_class=1, guard_nonnull=1)
+        self.check_operations_history(guard_class=0, guard_nonnull=0)
         res = self.interp_operations(fn, [1])
         assert not res
 


More information about the pypy-commit mailing list