[pypy-commit] pypy even-more-jit-hooks: hack differently

fijal noreply at buildbot.pypy.org
Sun Jul 8 17:22:17 CEST 2012


Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: even-more-jit-hooks
Changeset: r55997:01df8711ba3f
Date: 2012-07-08 17:22 +0200
http://bitbucket.org/pypy/pypy/changeset/01df8711ba3f/

Log:	hack differently

diff --git a/pypy/jit/metainterp/test/test_jitiface.py b/pypy/jit/metainterp/test/test_jitiface.py
--- a/pypy/jit/metainterp/test/test_jitiface.py
+++ b/pypy/jit/metainterp/test/test_jitiface.py
@@ -164,15 +164,10 @@
 
         def main():
             loop(30)
-            stats = jit_hooks.get_stats()
-            assert jit_hooks.stats_get_counter_value(stats,
-                           Counters.TOTAL_COMPILED_LOOPS) == 1
-            assert jit_hooks.stats_get_counter_value(stats,
-                           Counters.TOTAL_COMPILED_BRIDGES) == 1
-            assert jit_hooks.stats_get_counter_value(stats,
-                           Counters.TRACING) == 2
-            assert jit_hooks.stats_get_times_value(stats,
-                                                   Counters.TRACING) >= 0
+            assert jit_hooks.stats_get_counter_value(Counters.TOTAL_COMPILED_LOOPS) == 1
+            assert jit_hooks.stats_get_counter_value(Counters.TOTAL_COMPILED_BRIDGES) == 1
+            assert jit_hooks.stats_get_counter_value(Counters.TRACING) == 2
+            assert jit_hooks.stats_get_times_value(Counters.TRACING) >= 0
 
         self.meta_interp(main, [], ProfilerClass=Profiler)
 
diff --git a/pypy/jit/metainterp/warmspot.py b/pypy/jit/metainterp/warmspot.py
--- a/pypy/jit/metainterp/warmspot.py
+++ b/pypy/jit/metainterp/warmspot.py
@@ -636,21 +636,21 @@
             self.rewrite_access_helper(op)
 
     def rewrite_access_helper(self, op):
-        ARGS = [arg.concretetype for arg in op.args[2:]]
-        RESULT = op.result.concretetype
-        FUNCPTR = lltype.Ptr(lltype.FuncType(ARGS, RESULT))
         # make sure we make a copy of function so it no longer belongs
         # to extregistry
         func = op.args[1].value
-        if func.func_name == 'get_stats':
+        if func.func_name.startswith('stats_'):
             # get special treatment since we rewrite it to a call that accepts
             # jit driver
-            def func():
-                return lltype.cast_opaque_ptr(llmemory.GCREF,
-                                              cast_instance_to_base_ptr(self))
+            def new_func(*args):
+                return func(self, *args)
+            ARGS = [lltype.Void] + [arg.concretetype for arg in op.args[2:]]
         else:
-            func = func_with_new_name(func, func.func_name + '_compiled')
-        ptr = self.helper_func(FUNCPTR, func)
+            ARGS = [arg.concretetype for arg in op.args[2:]]
+            new_func = func_with_new_name(func, func.func_name + '_compiled')
+        RESULT = op.result.concretetype
+        FUNCPTR = lltype.Ptr(lltype.FuncType(ARGS, RESULT))
+        ptr = self.helper_func(FUNCPTR, new_func)
         op.opname = 'direct_call'
         op.args = [Constant(ptr, FUNCPTR)] + op.args[2:]
 
diff --git a/pypy/module/pypyjit/interp_resop.py b/pypy/module/pypyjit/interp_resop.py
--- a/pypy/module/pypyjit/interp_resop.py
+++ b/pypy/module/pypyjit/interp_resop.py
@@ -349,23 +349,19 @@
     is eager - the attribute access is not lazy, if you need new stats
     you need to call this function again.
     """
-    stats = jit_hooks.get_stats()
-    if not stats:
-        raise OperationError(space.w_TypeError, space.wrap(
-            "JIT not enabled, not stats available"))
-    ll_times = jit_hooks.stats_get_loop_run_times(stats)
+    ll_times = jit_hooks.stats_get_loop_run_times()
     w_times = space.newdict()
     for i in range(len(ll_times)):
         space.setitem(w_times, space.wrap(ll_times[i].number),
                       space.wrap(ll_times[i].counter))
     w_counters = space.newdict()
     for i, counter_name in enumerate(Counters.counter_names):
-        v = jit_hooks.stats_get_counter_value(stats, i)
+        v = jit_hooks.stats_get_counter_value(i)
         space.setitem_str(w_counters, counter_name, space.wrap(v))
     w_counter_times = space.newdict()
-    tr_time = jit_hooks.stats_get_times_value(stats, Counters.TRACING)
+    tr_time = jit_hooks.stats_get_times_value(Counters.TRACING)
     space.setitem_str(w_counter_times, 'TRACING', space.wrap(tr_time))
-    b_time = jit_hooks.stats_get_times_value(stats, Counters.BACKEND)
+    b_time = jit_hooks.stats_get_times_value(Counters.BACKEND)
     space.setitem_str(w_counter_times, 'BACKEND', space.wrap(b_time))
     return space.wrap(W_JitInfoSnapshot(space, w_times, w_counters,
                                         w_counter_times))
@@ -374,18 +370,10 @@
     """ Set the jit debugging - completely necessary for some stats to work,
     most notably assembler counters.
     """
-    stats = jit_hooks.get_stats()
-    if not stats:
-        raise OperationError(space.w_TypeError, space.wrap(
-            "JIT not enabled, not stats available"))
-    jit_hooks.stats_set_debug(stats, True)
+    jit_hooks.stats_set_debug(True)
 
 def disable_debug(space):
     """ Disable the jit debugging. This means some very small loops will be
     marginally faster and the counters will stop working.
     """
-    stats = jit_hooks.get_stats()
-    if not stats:
-        raise OperationError(space.w_TypeError, space.wrap(
-            "JIT not enabled, not stats available"))
-    jit_hooks.stats_set_debug(stats, False)
+    jit_hooks.stats_set_debug(False)
diff --git a/pypy/rlib/jit_hooks.py b/pypy/rlib/jit_hooks.py
--- a/pypy/rlib/jit_hooks.py
+++ b/pypy/rlib/jit_hooks.py
@@ -112,37 +112,19 @@
     from pypy.jit.metainterp.history import Const
     return isinstance(_cast_to_box(llbox), Const)
 
- at register_helper(annmodel.SomePtr(llmemory.GCREF))
-def get_stats():
-    """ Returns various statistics, including how many times each loop
-    was run. Note that on this level the resulting instance is completely
-    opaque, you need to use the interface specified below.
-
-    Note that since we pass warmspot by closure, the actual implementation
-    is in warmspot.py, this is just a placeholder
-    """
-    from pypy.rpython.lltypesystem import lltype, llmemory
-    return lltype.nullptr(llmemory.GCREF.TO) # unusable without the actual JIT
-
 # ------------------------- stats interface ---------------------------
 
-def _cast_to_warmrunnerdesc(llref):
-    from pypy.jit.metainterp.warmspot import WarmRunnerDesc
-
-    ptr = lltype.cast_opaque_ptr(rclass.OBJECTPTR, llref)
-    return cast_base_ptr_to_instance(WarmRunnerDesc, ptr)
-
 @register_helper(annmodel.SomeBool())
-def stats_set_debug(llref, flag):
-    return _cast_to_warmrunnerdesc(llref).metainterp_sd.cpu.set_debug(flag)
+def stats_set_debug(warmrunnerdesc, flag):
+    return warmrunnerdesc.metainterp_sd.cpu.set_debug(flag)
 
 @register_helper(annmodel.SomeInteger())
-def stats_get_counter_value(llref, no):
-    return _cast_to_warmrunnerdesc(llref).metainterp_sd.profiler.get_counter(no)
+def stats_get_counter_value(warmrunnerdesc, no):
+    return warmrunnerdesc.metainterp_sd.profiler.get_counter(no)
 
 @register_helper(annmodel.SomeFloat())
-def stats_get_times_value(llref, no):
-    return _cast_to_warmrunnerdesc(llref).metainterp_sd.profiler.times[no]
+def stats_get_times_value(warmrunnerdesc, no):
+    return warmrunnerdesc.metainterp_sd.profiler.times[no]
 
 LOOP_RUN_CONTAINER = lltype.GcArray(lltype.Struct('elem',
                                                   ('type', lltype.Char),
@@ -150,6 +132,5 @@
                                                   ('counter', lltype.Signed)))
 
 @register_helper(lltype.Ptr(LOOP_RUN_CONTAINER))
-def stats_get_loop_run_times(llref):
-    warmrunnerdesc = _cast_to_warmrunnerdesc(llref)
+def stats_get_loop_run_times(warmrunnerdesc):
     return warmrunnerdesc.metainterp_sd.cpu.get_all_loop_runs()


More information about the pypy-commit mailing list