[pypy-svn] r63094 - in pypy/branch/pyjitpl5/pypy/jit/metainterp: . test

arigo at codespeak.net arigo at codespeak.net
Thu Mar 19 19:53:21 CET 2009


Author: arigo
Date: Thu Mar 19 19:53:18 2009
New Revision: 63094

Modified:
   pypy/branch/pyjitpl5/pypy/jit/metainterp/optimize.py
   pypy/branch/pyjitpl5/pypy/jit/metainterp/pyjitpl.py
   pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_optimize.py
Log:
Fixes for test_optimize.py.


Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/optimize.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/optimize.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/optimize.py	Thu Mar 19 19:53:18 2009
@@ -453,9 +453,7 @@
                                   descr=ad)
             else:
                 vtable = ld.getint()
-                if self.cpu is None:
-                    size = ConstInt(-1)     # for tests only!
-                elif self.cpu.translate_support_code:
+                if self.cpu.translate_support_code:
                     vtable_addr = self.cpu.cast_int_to_adr(vtable)
                     size = self.cpu.class_sizes[vtable_addr]
                 else:
@@ -842,7 +840,7 @@
         result.append(box)
     return result
 
-def rebuild_boxes_from_guard_failure(guard_op, metainterp, boxes_from_frame):
+def rebuild_boxes_from_guard_failure(guard_op, cpu, boxes_from_frame):
 ##    print
 ##    print guard_op.liveboxes
 ##    for op in guard_op.rebuild_ops:
@@ -856,7 +854,6 @@
         currentvalues[guard_op.liveboxes[i]] = boxes_from_frame[i]
 
     # interpret the operations stored in 'rebuild_ops'
-    cpu = metainterp.cpu
     for op in guard_op.rebuild_ops:
         argboxes = get_in_list(currentvalues, op.args)
         resbox = executor.execute_nonspec(cpu, op.opnum, argboxes, op.descr)

Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/pyjitpl.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/pyjitpl.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/pyjitpl.py	Thu Mar 19 19:53:18 2009
@@ -950,7 +950,7 @@
             boxes_from_frame.append(newbox)
         if guard_op.rebuild_ops is not None:
             newboxes = optimize.rebuild_boxes_from_guard_failure(
-                guard_op, self, boxes_from_frame)
+                guard_op, self.cpu, boxes_from_frame)
         else:
             # xxx for tests only
             newboxes = boxes_from_frame

Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_optimize.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_optimize.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_optimize.py	Thu Mar 19 19:53:18 2009
@@ -29,6 +29,8 @@
 node2_vtable = lltype.malloc(OBJECT_VTABLE, immortal=True)
 node2_vtable_adr = llmemory.cast_ptr_to_adr(node2_vtable)
 
+cpu.class_sizes = {cpu.cast_adr_to_int(node_vtable_adr): cpu.sizeof(NODE)}
+
 
 # ____________________________________________________________
 
@@ -291,7 +293,7 @@
     ops[-2].liveboxes = [sum2, n2] 
         
 def test_E_optimize_loop():
-    spec = PerfectSpecializer(Loop(E.ops))
+    spec = PerfectSpecializer(Loop(E.ops), cpu=cpu)
     spec.find_nodes()
     spec.intersect_input_and_output()
     spec.optimize_loop()
@@ -317,35 +319,19 @@
     assert guard_op.unoptboxes[1] == guard_op.rebuild_ops[1].args[0]
 
 def test_E_rebuild_after_failure():
-    class FakeMetaInterp(object):
-        def __init__(self):
-            self.class_sizes = {cpu.cast_adr_to_int(node_vtable_adr):
-                                E.size_of_node}
-            self.cpu = cpu
-            self.cpu.translate_support_code = False
-            self.ops = []
-        
-        def execute_and_record(self, opnum, args, descr):
-            self.ops.append((opnum, args, descr))
-            return 'stuff'
-
-    spec = PerfectSpecializer(Loop(E.ops))
+    spec = PerfectSpecializer(Loop(E.ops), cpu=cpu)
     spec.find_nodes()
     spec.intersect_input_and_output()
     spec.optimize_loop()
     guard_op = spec.loop.operations[-2]
     v_sum_b = BoxInt(13)
     v_v_b = BoxInt(14)
-    fake_metainterp = FakeMetaInterp()
-    newboxes = rebuild_boxes_from_guard_failure(guard_op, fake_metainterp,
+    newboxes = rebuild_boxes_from_guard_failure(guard_op, cpu,
                                                 [v_sum_b, v_v_b])
-    v_vt = ConstAddr(node_vtable_adr, cpu)
-    expected = [
-       (rop.NEW_WITH_VTABLE, [v_vt], ConstInt(-1)),    # "-1" is for testing
-       (rop.SETFIELD_GC, ['stuff', v_v_b], E.ofs_value)
-       ]
-    assert expected == fake_metainterp.ops
-    assert newboxes == [v_sum_b, 'stuff']
+    assert len(newboxes) == 2
+    assert newboxes[0] == v_sum_b
+    p = newboxes[1].getptr(lltype.Ptr(NODE))
+    assert p.value == 14
 
 # ____________________________________________________________
 
@@ -386,7 +372,7 @@
     assert not spec.nodes[F.n2].escaped
 
 def test_F_optimize_loop():
-    spec = PerfectSpecializer(Loop(F.ops))
+    spec = PerfectSpecializer(Loop(F.ops), cpu=cpu)
     spec.find_nodes()
     spec.intersect_input_and_output()
     assert spec.nodes[F.n3].escaped
@@ -419,7 +405,7 @@
     ops[2].liveboxes = [n2]
 
 def test_F2_optimize_loop():
-    spec = PerfectSpecializer(Loop(F2.ops))
+    spec = PerfectSpecializer(Loop(F2.ops), cpu=cpu)
     spec.find_nodes()
     spec.intersect_input_and_output()
     spec.optimize_loop()
@@ -449,7 +435,7 @@
     ops[-2].liveboxes = [sum2, n2] 
 
 def test_G_optimize_loop():
-    spec = PerfectSpecializer(Loop(G.ops))
+    spec = PerfectSpecializer(Loop(G.ops), cpu=cpu)
     spec.find_nodes()
     spec.intersect_input_and_output()
     spec.optimize_loop()



More information about the Pypy-commit mailing list