[pypy-svn] r74911 - pypy/branch/blackhole-improvement/pypy/jit/backend/test

arigo at codespeak.net arigo at codespeak.net
Sun May 30 13:18:38 CEST 2010


Author: arigo
Date: Sun May 30 13:18:37 2010
New Revision: 74911

Modified:
   pypy/branch/blackhole-improvement/pypy/jit/backend/test/test_ll_random.py
   pypy/branch/blackhole-improvement/pypy/jit/backend/test/test_random.py
Log:
Fix test_(ll)_random.  Seems to pass fine on x86 backend.


Modified: pypy/branch/blackhole-improvement/pypy/jit/backend/test/test_ll_random.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/backend/test/test_ll_random.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/backend/test/test_ll_random.py	Sun May 30 13:18:37 2010
@@ -3,8 +3,9 @@
 from pypy.jit.backend.test import test_random
 from pypy.jit.metainterp.resoperation import ResOperation, rop
 from pypy.jit.metainterp.history import ConstInt, ConstPtr
-from pypy.jit.metainterp.history import ConstAddr, BoxPtr, BoxInt
+from pypy.jit.metainterp.history import BoxPtr, BoxInt
 from pypy.jit.metainterp.history import BasicFailDescr
+from pypy.jit.codewriter import heaptracker
 from pypy.rpython.annlowlevel import llhelper
 from pypy.rlib.rarithmetic import intmask
 from pypy.rpython.llinterp import LLException
@@ -19,13 +20,11 @@
         self.runicodes = []
         self.structure_types = []
         self.structure_types_and_vtables = []
-        self.class_sizes_cache = []
 
     def fork(self, cpu, loop, vars):
         fork = test_random.OperationBuilder.fork(self, cpu, loop, vars)
         fork.structure_types = self.structure_types
         fork.structure_types_and_vtables = self.structure_types_and_vtables
-        fork.class_sizes_cache = self.class_sizes_cache
         return fork
 
     def get_structptr_var(self, r, must_have_vtable=False, type=lltype.Struct):
@@ -107,11 +106,7 @@
         vtable.name[len(name)] = '\x00'
         self.structure_types_and_vtables.append((S, vtable))
         #
-        vtable_adr = llmemory.cast_ptr_to_adr(vtable)
-        vtable_int = self.cpu.cast_adr_to_int(vtable_adr)
-        descr = self.cpu.sizeof(S)
-        self.class_sizes_cache.append((vtable_int, descr))
-        self.cpu.set_class_sizes(dict(self.class_sizes_cache))
+        heaptracker.register_known_gctype(self.cpu, vtable, S)
         #
         return S, vtable
 
@@ -186,6 +181,9 @@
 
 # ____________________________________________________________
 
+def ConstAddr(addr, cpu):
+    return ConstInt(llmemory.cast_adr_to_int(addr))
+
 class GuardClassOperation(test_random.GuardOperation):
     def gen_guard(self, builder, r):
         ptrvars = [(v, S) for (v, S) in builder.ptrvars
@@ -507,8 +505,6 @@
         descr = builder.cpu.calldescrof(TP, TP.ARGS, TP.RESULT)
         self.put(builder, args, descr)
         exc_box = ConstAddr(llmemory.cast_ptr_to_adr(exc), builder.cpu)
-        assert builder.cpu.get_exception()
-        builder.cpu.clear_exception()
         op = ResOperation(rop.GUARD_EXCEPTION, [exc_box], BoxPtr(),
                           descr=BasicFailDescr())
         op.fail_args = fail_subset
@@ -525,8 +521,6 @@
         args = [c_addr] + subset
         descr = builder.cpu.calldescrof(TP, TP.ARGS, TP.RESULT)
         self.put(builder, args, descr)
-        assert builder.cpu.get_exception()
-        builder.cpu.clear_exception()
         op = ResOperation(rop.GUARD_NO_EXCEPTION, [], BoxPtr(),
                           descr=BasicFailDescr())
         op._exc_box = ConstAddr(llmemory.cast_ptr_to_adr(exc), builder.cpu)
@@ -546,8 +540,6 @@
         args = [c_addr] + subset
         descr = builder.cpu.calldescrof(TP, TP.ARGS, TP.RESULT)
         self.put(builder, args, descr)
-        assert builder.cpu.get_exception()
-        builder.cpu.clear_exception()
         while True:
             _, vtableptr = builder.get_random_structure_type_and_vtable(r)
             if vtableptr != exc:

Modified: pypy/branch/blackhole-improvement/pypy/jit/backend/test/test_random.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/backend/test/test_random.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/backend/test/test_random.py	Sun May 30 13:18:37 2010
@@ -4,7 +4,7 @@
 from pypy.jit.backend.test import conftest as demo_conftest
 from pypy.jit.metainterp.history import BasicFailDescr, TreeLoop
 from pypy.jit.metainterp.history import BoxInt, ConstInt, LoopToken
-from pypy.jit.metainterp.history import BoxPtr, ConstPtr, ConstAddr
+from pypy.jit.metainterp.history import BoxPtr, ConstPtr
 from pypy.jit.metainterp.history import BoxFloat, ConstFloat, Const
 from pypy.jit.metainterp.resoperation import ResOperation, rop
 from pypy.jit.metainterp.executor import execute_nonspec
@@ -17,9 +17,16 @@
     def __init__(self, subops):
         self.operations = subops
 
+class FakeMetaInterp(object):
+    def execute_raised(self, exc, constant=False):
+        self._got_exc = exc
+    def execute_did_not_raise(self):
+        self._got_exc = None
+
 class OperationBuilder(object):
     def __init__(self, cpu, loop, vars):
         self.cpu = cpu
+        self.fakemetainterp = FakeMetaInterp()
         self.loop = loop
         self.intvars = [box for box in vars if isinstance(box, BoxInt)]
         self.boolvars = []   # subset of self.intvars
@@ -40,7 +47,8 @@
         return fork
 
     def do(self, opnum, argboxes, descr=None):
-        v_result = execute_nonspec(self.cpu, opnum, argboxes, descr)
+        v_result = execute_nonspec(self.cpu, self.fakemetainterp,
+                                   opnum, argboxes, descr)
         if isinstance(v_result, Const):
             v_result = v_result.clonebox()
         self.loop.operations.append(ResOperation(opnum, argboxes, v_result,
@@ -56,11 +64,14 @@
             if S == S2 and not (isinstance(v, ConstPtr) and
                                 isinstance(v2, ConstPtr)):
                 if r.random() < 0.5:
-                    return self.do(rop.OOIS, [v, v2])
+                    return self.do(rop.PTR_EQ, [v, v2])
                 else:
-                    return self.do(rop.OOISNOT, [v, v2])
+                    return self.do(rop.PTR_NE, [v, v2])
         v = r.choice(self.intvars)
-        return self.do(rop.INT_IS_TRUE, [v])
+        if r.random() < 0.7:
+            return self.do(rop.INT_IS_TRUE, [v])
+        else:
+            return self.do(rop.INT_IS_ZERO, [v])
 
     def subset_of_intvars(self, r):
         subset = []
@@ -79,16 +90,16 @@
         for v in op.args:
             if v in names:
                 args.append(names[v])
-            elif isinstance(v, ConstAddr):
-                try:
-                    name = ''.join([v.value.ptr.name[i]
-                                    for i in range(len(v.value.ptr.name)-1)])
-                except AttributeError:
-                    args.append('ConstAddr(...)')
-                else:
-                    args.append(
-                        'ConstAddr(llmemory.cast_ptr_to_adr(%s_vtable), cpu)'
-                        % name)
+##            elif isinstance(v, ConstAddr):
+##                try:
+##                    name = ''.join([v.value.ptr.name[i]
+##                                    for i in range(len(v.value.ptr.name)-1)])
+##                except AttributeError:
+##                    args.append('ConstAddr(...)')
+##                else:
+##                    args.append(
+##                        'ConstAddr(llmemory.cast_ptr_to_adr(%s_vtable), cpu)'
+##                        % name)
             elif isinstance(v, ConstFloat):
                 args.append('ConstFloat(%r)' % v.value)
             elif isinstance(v, ConstInt):
@@ -264,8 +275,8 @@
         fail_subset = builder.subset_of_intvars(r)
         original_intvars = builder.intvars[:]
         super(AbstractOvfOperation, self).produce_into(builder, r)
-        if builder.cpu._overflow_flag:   # overflow detected
-            del builder.cpu._overflow_flag
+        if builder.fakemetainterp._got_exc:   # overflow detected
+            assert isinstance(builder.fakemetainterp._got_exc, OverflowError)
             op = ResOperation(rop.GUARD_OVERFLOW, [], None)
             # the overflowed result should not be used any more, but can
             # be used on the failure path: recompute fail_subset including
@@ -274,6 +285,7 @@
             builder.intvars[:] = original_intvars
         else:
             op = ResOperation(rop.GUARD_NO_OVERFLOW, [], None)
+        del builder.fakemetainterp._got_exc
         op.descr = BasicFailDescr()
         op.fail_args = fail_subset
         builder.loop.operations.append(op)
@@ -585,8 +597,8 @@
     def run_loop(self):
         cpu = self.builder.cpu
         self.clear_state()
-        assert not cpu.get_exception()
-        assert not cpu.get_exc_value()
+        exc = cpu.grab_exc_value()
+        assert not exc
 
         for i, box in enumerate(self.startvars):
             if isinstance(box, BoxInt):
@@ -607,15 +619,13 @@
                                                        self.expected[v],
                                                        i)
                 )
+        exc = cpu.grab_exc_value()
         if (self.guard_op is not None and
             self.guard_op.is_guard_exception()):
             if self.guard_op.opnum == rop.GUARD_NO_EXCEPTION:
-                assert cpu.get_exception()
-                assert cpu.get_exc_value()
-            cpu.clear_exception()
+                assert exc
         else:
-            assert not cpu.get_exception()
-            assert not cpu.get_exc_value()
+            assert not exc
 
     def build_bridge(self):
         def exc_handling(guard_op):



More information about the Pypy-commit mailing list