[pypy-commit] pypy remember-tracing-counts: I think I don't understand prebuilt instances in rpython but seems to work

fijal noreply at buildbot.pypy.org
Mon Sep 14 14:20:21 CEST 2015


Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: remember-tracing-counts
Changeset: r79623:58ad0b9810dc
Date: 2015-09-14 14:20 +0200
http://bitbucket.org/pypy/pypy/changeset/58ad0b9810dc/

Log:	I think I don't understand prebuilt instances in rpython but seems
	to work

diff --git a/rpython/jit/metainterp/compile.py b/rpython/jit/metainterp/compile.py
--- a/rpython/jit/metainterp/compile.py
+++ b/rpython/jit/metainterp/compile.py
@@ -738,6 +738,9 @@
         metainterp.handle_guard_failure(self, deadframe)
     _trace_and_compile_from_bridge._dont_inline_ = True
 
+    def get_hash(self):
+        return self.status & self.ST_SHIFT_MASK
+
     def must_compile(self, deadframe, metainterp_sd, jitdriver_sd):
         jitcounter = metainterp_sd.warmrunnerdesc.jitcounter
         #
diff --git a/rpython/jit/metainterp/test/test_jitiface.py b/rpython/jit/metainterp/test/test_jitiface.py
--- a/rpython/jit/metainterp/test/test_jitiface.py
+++ b/rpython/jit/metainterp/test/test_jitiface.py
@@ -1,12 +1,13 @@
 
 import py
-from rpython.rlib.jit import JitDriver, JitHookInterface, Counters
+from rpython.rlib.jit import JitDriver, JitHookInterface, Counters, dont_look_inside
 from rpython.rlib import jit_hooks
 from rpython.jit.metainterp.test.support import LLJitMixin
 from rpython.jit.codewriter.policy import JitPolicy
 from rpython.jit.metainterp.resoperation import rop
 from rpython.rtyper.annlowlevel import hlstr, cast_instance_to_gcref
 from rpython.jit.metainterp.jitprof import Profiler, EmptyProfiler
+from rpython.jit.codewriter.policy import JitPolicy
 
 
 class JitHookInterfaceTests(object):
@@ -226,6 +227,58 @@
         self.meta_interp(main, [1, 1], inline=True)
         self.check_resops(call_assembler_n=8)
 
+    def test_trace_next_iteration_hash(self):
+        driver = JitDriver(greens = ['s'], reds = ['i'], name="name")
+        class Hashes(object):
+            check = False
+            
+            def __init__(self):
+                self.l = []
+                self.t = []
+
+        hashes = Hashes()
+
+        class Hooks(object):
+            def before_compile(self, debug_info):
+                pass
+
+            def after_compile(self, debug_info):
+                for op in debug_info.operations:
+                    if op.is_guard():
+                        hashes.l.append(op.getdescr().get_hash())
+
+            def before_compile_bridge(self, debug_info):
+                pass
+
+            def after_compile_bridge(self, debug_info):
+                hashes.t.append(debug_info.fail_descr.get_hash())
+
+        hooks = Hooks()
+
+        @dont_look_inside
+        def foo():
+            if hashes.l:
+                for item in hashes.l:
+                    jit_hooks.trace_next_iteration_hash("name", item)
+
+        def loop(i, s):
+            while i > 0:
+                driver.jit_merge_point(s=s, i=i)
+                foo()
+                if i == 3:
+                    i -= 1
+                i -= 1
+
+        def main(s, check):
+            hashes.check = check
+            loop(10, s)
+
+        self.meta_interp(main, [1, 0], policy=JitPolicy(hooks))
+        assert len(hashes.l) == 4
+        assert len(hashes.t) == 0
+        self.meta_interp(main, [1, 1], policy=JitPolicy(hooks))
+        assert len(hashes.t) == 1
+
 class LLJitHookInterfaceTests(JitHookInterfaceTests):
     # use this for any backend, instead of the super class
     
diff --git a/rpython/jit/metainterp/warmspot.py b/rpython/jit/metainterp/warmspot.py
--- a/rpython/jit/metainterp/warmspot.py
+++ b/rpython/jit/metainterp/warmspot.py
@@ -618,7 +618,7 @@
                 jitdrivers_by_name[name] = jd
         m = _find_jit_markers(self.translator.graphs,
                               ('get_jitcell_at_key', 'trace_next_iteration',
-                               'dont_trace_here'))
+                               'dont_trace_here', 'trace_next_iteration_hash'))
         accessors = {}
 
         def get_accessor(name, jitdriver_name, function, ARGS, green_arg_spec):
@@ -663,6 +663,8 @@
                 func = JitCell.get_jitcell
             elif op.args[0].value == 'dont_trace_here':
                 func = JitCell.dont_trace_here
+            elif op.args[0].value == 'trace_next_iteration_hash':
+                func = JitCell.trace_next_iteration_hash
             else:
                 func = JitCell._trace_next_iteration
             argspec = jitdrivers_by_name[jitdriver_name]._green_args_spec
diff --git a/rpython/jit/metainterp/warmstate.py b/rpython/jit/metainterp/warmstate.py
--- a/rpython/jit/metainterp/warmstate.py
+++ b/rpython/jit/metainterp/warmstate.py
@@ -553,6 +553,10 @@
                 jitcounter.change_current_fraction(hash, 0.98)
 
             @staticmethod
+            def trace_next_iteration_hash(hash):
+                jitcounter.change_current_fraction(hash, 0.98)
+
+            @staticmethod
             def ensure_jit_cell_at_key(greenkey):
                 greenargs = unwrap_greenkey(greenkey)
                 return JitCell._ensure_jit_cell_at_key(*greenargs)
diff --git a/rpython/rlib/jit_hooks.py b/rpython/rlib/jit_hooks.py
--- a/rpython/rlib/jit_hooks.py
+++ b/rpython/rlib/jit_hooks.py
@@ -157,3 +157,4 @@
 get_jitcell_at_key = _new_hook('get_jitcell_at_key', SomePtr(llmemory.GCREF))
 trace_next_iteration = _new_hook('trace_next_iteration', None)
 dont_trace_here = _new_hook('dont_trace_here', None)
+trace_next_iteration_hash = _new_hook('trace_next_iteration_hash', None)


More information about the pypy-commit mailing list