Commits

Carl Friedrich Bolz committed 01e4f33

new objects have a known class

Comments (0)

Files changed (2)

pypy/jit/metainterp/pyjitpl.py

     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):

pypy/jit/metainterp/test/test_ajit.py

             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
             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