Author: Antonio Cuni <[email protected]>
Branch: invalidate-virtualrefs
Changeset: r44509:a092695359d8
Date: 2011-05-26 14:38 +0200
http://bitbucket.org/pypy/pypy/changeset/a092695359d8/

Log:    don't force the vref when calling finish(), and raise an exception
        if we try to force it later

diff --git a/pypy/jit/metainterp/optimizeopt/virtualize.py 
b/pypy/jit/metainterp/optimizeopt/virtualize.py
--- a/pypy/jit/metainterp/optimizeopt/virtualize.py
+++ b/pypy/jit/metainterp/optimizeopt/virtualize.py
@@ -340,8 +340,10 @@
         # op.getarg(1) should really never point to null here
         # - set 'forced' to point to the real object
         seo = self.optimizer.send_extra_operation
-        seo(ResOperation(rop.SETFIELD_GC, op.getarglist(), None,
-                         descr = vrefinfo.descr_forced))
+
+        ## seo(ResOperation(rop.SETFIELD_GC, op.getarglist(), None,
+        ##                  descr = vrefinfo.descr_forced))
+        
         # - set 'virtual_token' to TOKEN_NONE
         args = [op.getarg(0), ConstInt(vrefinfo.TOKEN_NONE)]
         seo(ResOperation(rop.SETFIELD_GC, args, None,
diff --git a/pypy/jit/metainterp/test/test_virtualref.py 
b/pypy/jit/metainterp/test/test_virtualref.py
--- a/pypy/jit/metainterp/test/test_virtualref.py
+++ b/pypy/jit/metainterp/test/test_virtualref.py
@@ -1,5 +1,6 @@
 import py
 from pypy.rpython.lltypesystem import lltype, llmemory, lloperation
+from pypy.rpython.llinterp import LLException
 from pypy.rlib.jit import JitDriver, dont_look_inside, vref_None
 from pypy.rlib.jit import virtual_ref, virtual_ref_finish, InvalidVirtualRef
 from pypy.rlib.objectmodel import compute_unique_id
@@ -573,7 +574,6 @@
         self.check_loops(new_with_vtable=2)     # vref, xy
 
     def test_cannot_use_invalid_virtualref(self):
-        py.test.skip('fixme')
         myjitdriver = JitDriver(greens = [], reds = ['n'])
         #
         class XY:
@@ -588,18 +588,12 @@
                 xy.n = n
                 vref = virtual_ref(xy)
                 virtual_ref_finish(vref, xy)
-                try:
-                    vref()
-                    res = False
-                except InvalidVirtualRef:
-                    res = True
+                vref() # raises InvalidVirtualRef when jitted
                 n -= 1
             return res
         #
-        assert fn(10)
-        res = self.meta_interp(fn, [10])
-        assert res
-
+        py.test.raises(InvalidVirtualRef, "fn(10)")
+        py.test.raises(LLException, "self.meta_interp(fn, [10])")
 
 class TestLLtype(VRefTests, LLJitMixin):
     pass
diff --git a/pypy/jit/metainterp/virtualref.py 
b/pypy/jit/metainterp/virtualref.py
--- a/pypy/jit/metainterp/virtualref.py
+++ b/pypy/jit/metainterp/virtualref.py
@@ -2,7 +2,7 @@
 from pypy.rpython.lltypesystem import lltype, llmemory, rffi, rclass
 from pypy.jit.metainterp import history
 from pypy.jit.codewriter import heaptracker
-
+from pypy.rlib.jit import InvalidVirtualRef
 
 class VirtualRefInfo:
 
@@ -146,7 +146,8 @@
                 ResumeGuardForcedDescr.force_now(self.cpu, token)
                 assert vref.virtual_token == self.TOKEN_NONE
                 assert vref.forced
-        else:
-            assert vref.forced
+        elif not vref.forced:
+            # token == TOKEN_NONE and the vref was not forced: it's invalid
+            raise InvalidVirtualRef
         return vref.forced
     force_virtual._dont_inline_ = True
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to