[pypy-svn] r74816 - in pypy/branch/blackhole-improvement/pypy/jit/metainterp: . test

arigo at codespeak.net arigo at codespeak.net
Thu May 27 17:10:05 CEST 2010


Author: arigo
Date: Thu May 27 17:10:03 2010
New Revision: 74816

Modified:
   pypy/branch/blackhole-improvement/pypy/jit/metainterp/blackhole.py
   pypy/branch/blackhole-improvement/pypy/jit/metainterp/pyjitpl.py
   pypy/branch/blackhole-improvement/pypy/jit/metainterp/test/test_basic.py
   pypy/branch/blackhole-improvement/pypy/jit/metainterp/test/test_virtualref.py
   pypy/branch/blackhole-improvement/pypy/jit/metainterp/warmspot.py
Log:
Start working on virtualrefs.


Modified: pypy/branch/blackhole-improvement/pypy/jit/metainterp/blackhole.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/metainterp/blackhole.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/metainterp/blackhole.py	Thu May 27 17:10:03 2010
@@ -732,6 +732,9 @@
         except KeyError:
             return pc
 
+    # ----------
+    # exception handling operations
+
     @arguments("L")
     def bhimpl_catch_exception(target):
         """This is a no-op when run normally.  When an exception occurs
@@ -783,6 +786,9 @@
             etype = rclass.ll_type(e)
             raise LLException(etype, e)
 
+    # ----------
+    # the main hints and recursive calls
+
     @arguments()
     def bhimpl_can_enter_jit():
         pass
@@ -840,6 +846,17 @@
                                   greens_f + reds_f)
 
     # ----------
+    # virtual refs
+
+    @arguments("r", returns="r")
+    def bhimpl_virtual_ref(a):
+        return a
+
+    @arguments("r")
+    def bhimpl_virtual_ref_finish(a):
+        pass
+
+    # ----------
     # list operations
 
     @arguments("cpu", "r", "d", "i", returns="i")

Modified: pypy/branch/blackhole-improvement/pypy/jit/metainterp/pyjitpl.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/metainterp/pyjitpl.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/metainterp/pyjitpl.py	Thu May 27 17:10:03 2010
@@ -843,7 +843,7 @@
         assert exc_value_box is not None
         return exc_value_box
 
-    @FixME  #arguments("box")
+    @arguments("box")
     def opimpl_virtual_ref(self, box):
         # Details on the content of metainterp.virtualref_boxes:
         #
@@ -852,7 +852,7 @@
         #    the 'virtual_ref(frame)').
         #
         #  * if we detect that the virtual box escapes during tracing
-        #    already (by generating a CALl_MAY_FORCE that marks the flags
+        #    already (by generating a CALL_MAY_FORCE that marks the flags
         #    in the vref), then we replace the vref in the list with
         #    ConstPtr(NULL).
         #
@@ -874,9 +874,9 @@
             # SETFIELD_GCs.
         metainterp.virtualref_boxes.append(box)
         metainterp.virtualref_boxes.append(resbox)
-        self.make_result_box(resbox)
+        return resbox
 
-    @FixME  #arguments("box")
+    @arguments("box")
     def opimpl_virtual_ref_finish(self, box):
         # virtual_ref_finish() assumes that we have a stack-like, last-in
         # first-out order.
@@ -1111,6 +1111,7 @@
         #
         self.portal_code = codewriter.mainjitcode
         self._portal_runner_ptr = codewriter.callcontrol.portal_runner_ptr
+        self.virtualref_info = codewriter.callcontrol.virtualref_info
         RESULT = codewriter.portal_graph.getreturnvar().concretetype
         self.result_type = history.getkind(RESULT)
         #

Modified: pypy/branch/blackhole-improvement/pypy/jit/metainterp/test/test_basic.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/metainterp/test/test_basic.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/metainterp/test/test_basic.py	Thu May 27 17:10:03 2010
@@ -12,8 +12,20 @@
 from pypy.rpython.lltypesystem import lltype, llmemory
 from pypy.rpython.ootypesystem import ootype
 
-def _get_jitcodes(CPUClass, func, values, type_system):
+def _get_jitcodes(testself, CPUClass, func, values, type_system):
     from pypy.jit.codewriter import support, codewriter
+    from pypy.jit.metainterp import simple_optimize
+
+    class FakeWarmRunnerState:
+        def attach_unoptimized_bridge_from_interp(self, greenkey, newloop):
+            pass
+
+        # pick the optimizer this way
+        optimize_loop = staticmethod(simple_optimize.optimize_loop)
+        optimize_bridge = staticmethod(simple_optimize.optimize_bridge)
+
+        trace_limit = sys.maxint
+        debug_level = 2
 
     func._jit_unroll_safe_ = True
     rtyper = support.annotate(func, values, type_system=type_system)
@@ -21,12 +33,19 @@
     stats = history.Stats()
     cpu = CPUClass(rtyper, stats, None, False)
     cw = codewriter.CodeWriter(cpu, graphs[0])
+    testself.cw = cw
     cw.find_all_graphs(JitPolicy())
+    #
+    testself.warmrunnerstate = FakeWarmRunnerState()
+    testself.warmrunnerstate.cpu = cpu
+    if hasattr(testself, 'finish_setup_for_interp_operations'):
+        testself.finish_setup_for_interp_operations()
+    #
     cw.make_jitcodes(verbose=True)
-    return cw
 
-def _run_with_blackhole(cw, args):
+def _run_with_blackhole(testself, args):
     from pypy.jit.metainterp.blackhole import BlackholeInterpBuilder
+    cw = testself.cw
     blackholeinterpbuilder = BlackholeInterpBuilder(cw)
     blackholeinterp = blackholeinterpbuilder.acquire_interp()
     count_i = count_r = count_f = 0
@@ -47,8 +66,7 @@
     blackholeinterp.run()
     return blackholeinterp._final_result_anytype()
 
-def _run_with_pyjitpl(cw, args, testself):
-    from pypy.jit.metainterp import simple_optimize
+def _run_with_pyjitpl(testself, args):
 
     class DoneWithThisFrame(Exception):
         pass
@@ -57,26 +75,13 @@
         def __init__(self, cpu, *args):
             DoneWithThisFrame.__init__(self, *args)
 
-    class FakeWarmRunnerState:
-        def attach_unoptimized_bridge_from_interp(self, greenkey, newloop):
-            pass
-
-        # pick the optimizer this way
-        optimize_loop = staticmethod(simple_optimize.optimize_loop)
-        optimize_bridge = staticmethod(simple_optimize.optimize_bridge)
-
-        trace_limit = sys.maxint
-        debug_level = 2
-
+    cw = testself.cw
     opt = history.Options(listops=True)
     metainterp_sd = pyjitpl.MetaInterpStaticData(cw.cpu, opt)
     metainterp_sd.finish_setup(cw, optimizer="bogus")
-    metainterp_sd.state = FakeWarmRunnerState()
+    metainterp_sd.state = testself.warmrunnerstate
     metainterp_sd.state.cpu = metainterp_sd.cpu
     metainterp = pyjitpl.MetaInterp(metainterp_sd)
-    if hasattr(testself, 'finish_metainterp_for_interp_operations'):
-        testself.finish_metainterp_for_interp_operations(metainterp)
-
     metainterp_sd.DoneWithThisFrameInt = DoneWithThisFrame
     metainterp_sd.DoneWithThisFrameRef = DoneWithThisFrameRef
     metainterp_sd.DoneWithThisFrameFloat = DoneWithThisFrame
@@ -126,11 +131,11 @@
 
     def interp_operations(self, f, args, **kwds):
         # get the JitCodes for the function f
-        cw = _get_jitcodes(self.CPUClass, f, args, self.type_system)
+        _get_jitcodes(self, self.CPUClass, f, args, self.type_system)
         # try to run it with blackhole.py
-        result1 = _run_with_blackhole(cw, args)
+        result1 = _run_with_blackhole(self, args)
         # try to run it with pyjitpl.py
-        result2 = _run_with_pyjitpl(cw, args, self)
+        result2 = _run_with_pyjitpl(self, args)
         assert result1 == result2
         return result1
 

Modified: pypy/branch/blackhole-improvement/pypy/jit/metainterp/test/test_virtualref.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/metainterp/test/test_virtualref.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/metainterp/test/test_virtualref.py	Thu May 27 17:10:03 2010
@@ -12,9 +12,9 @@
 
 class VRefTests:
 
-    def finish_metainterp_for_interp_operations(self, metainterp):
-        self.vrefinfo = VirtualRefInfo(metainterp.staticdata.state)
-        metainterp.staticdata.virtualref_info = self.vrefinfo
+    def finish_setup_for_interp_operations(self):
+        self.vrefinfo = VirtualRefInfo(self.warmrunnerstate)
+        self.cw.setup_vrefinfo(self.vrefinfo)
 
     def test_make_vref_simple(self):
         class X:

Modified: pypy/branch/blackhole-improvement/pypy/jit/metainterp/warmspot.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/metainterp/warmspot.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/metainterp/warmspot.py	Thu May 27 17:10:03 2010
@@ -163,8 +163,8 @@
         self.make_args_specification()
         #
         from pypy.jit.metainterp.virtualref import VirtualRefInfo
-        self.metainterp_sd.virtualref_info = VirtualRefInfo(self)
-        self.codewriter.setup_vrefinfo(self.metainterp_sd.virtualref_info)
+        vrefinfo = VirtualRefInfo(self)
+        self.codewriter.setup_vrefinfo(vrefinfo)
         if self.jitdriver.virtualizables:
             from pypy.jit.metainterp.virtualizable import VirtualizableInfo
             self.metainterp_sd.virtualizable_info = VirtualizableInfo(self)
@@ -178,7 +178,7 @@
         self.codewriter.make_jitcodes(verbose=verbose)
         self.rewrite_can_enter_jit()
         self.rewrite_set_param()
-        self.rewrite_force_virtual()
+        self.rewrite_force_virtual(vrefinfo)
         self.add_finish()
         self.metainterp_sd.finish_setup(self.codewriter, optimizer=optimizer)
 
@@ -657,9 +657,8 @@
             op.opname = 'direct_call'
             op.args[:3] = [closures[funcname]]
 
-    def rewrite_force_virtual(self):
+    def rewrite_force_virtual(self, vrefinfo):
         if self.cpu.ts.name != 'lltype':
             py.test.skip("rewrite_force_virtual: port it to ootype")
         all_graphs = self.translator.graphs
-        vrefinfo = self.metainterp_sd.virtualref_info
         vrefinfo.replace_force_virtual_with_call(all_graphs)



More information about the Pypy-commit mailing list