[pypy-svn] r52610 - in pypy/branch/jit-hotpath/pypy/jit: hintannotator/test rainbow timeshifter

cfbolz at codespeak.net cfbolz at codespeak.net
Sun Mar 16 17:19:35 CET 2008


Author: cfbolz
Date: Sun Mar 16 17:19:34 2008
New Revision: 52610

Modified:
   pypy/branch/jit-hotpath/pypy/jit/hintannotator/test/test_hotpath.py
   pypy/branch/jit-hotpath/pypy/jit/rainbow/rhotpath.py
   pypy/branch/jit-hotpath/pypy/jit/timeshifter/greenkey.py
Log:
make the profiling around promotes less heavy-weight


Modified: pypy/branch/jit-hotpath/pypy/jit/hintannotator/test/test_hotpath.py
==============================================================================
--- pypy/branch/jit-hotpath/pypy/jit/hintannotator/test/test_hotpath.py	(original)
+++ pypy/branch/jit-hotpath/pypy/jit/hintannotator/test/test_hotpath.py	Sun Mar 16 17:19:34 2008
@@ -11,10 +11,10 @@
 class TestHotPath(AbstractAnnotatorTest):
     type_system = 'lltype'
 
-    def hannotate(self, func, argtypes, policy=P_HOTPATH):
+    def hannotate(self, func, argtypes, policy=P_HOTPATH, backendoptimize=True):
         # change default policy
         AbstractAnnotatorTest.hannotate(self, func, argtypes, policy=policy,
-                                        backendoptimize=True)
+                                        backendoptimize=backendoptimize)
 
     def test_simple_loop(self):
         class MyJitDriver(JitDriver):
@@ -43,3 +43,24 @@
         assert len(graphs) == 1
         assert ll_function is graphs[0].func
         assert 'int_mul' not in summary(graphs[0])
+
+    def test_call(self):
+        def add(count, x, y):
+            result = x + y
+            can_enter_jit(red=(count, x, y))
+            return result
+        add._dont_inline_ = True
+        def sub(x, y):
+            return x - y
+        sub._dont_inline_ = True
+        def main(count, x, y):
+            while True:
+                jit_merge_point(red=(count, x, y))
+                count -= 1
+                if not count:
+                    break
+                if count % 3 == 0:
+                    x = add(count, x, y)
+                else:
+                    y = sub(x, y)
+        self.hannotate(main, [int, int, int])

Modified: pypy/branch/jit-hotpath/pypy/jit/rainbow/rhotpath.py
==============================================================================
--- pypy/branch/jit-hotpath/pypy/jit/rainbow/rhotpath.py	(original)
+++ pypy/branch/jit-hotpath/pypy/jit/rainbow/rhotpath.py	Sun Mar 16 17:19:34 2008
@@ -2,6 +2,7 @@
 RPython support code for the hotpath policy.
 """
 
+from pypy.jit.codegen.i386.rgenop import cast_whatever_to_int
 from pypy.jit.timeshifter import rtimeshift, rvalue
 from pypy.jit.timeshifter.greenkey import KeyDesc, GreenKey, newgreendict
 from pypy.rlib.objectmodel import we_are_translated, specialize
@@ -242,20 +243,19 @@
     def __init__(self, jitstate, hotrunnerdesc, promotebox, hotpromotiondesc):
         FallbackPoint. __init__(self, jitstate, hotrunnerdesc, promotebox)
         self.hotpromotiondesc = hotpromotiondesc
-        self.counters = newgreendict()
+        self.counters = {}
 
     @specialize.arglltype(1)
     def check_should_compile(self, value):
-        # XXX incredibly heavy for a supposely lightweight profiling
-        gv_value = self.hotrunnerdesc.interpreter.rgenop.genconst(value)
-        greenkey = GreenKey([gv_value], self.hotpromotiondesc.greenkeydesc)
-        counter = self.counters.get(greenkey, 0) + 1
+        # XXX unsafe with a moving GC
+        hash = cast_whatever_to_int(lltype.typeOf(value), value)
+        counter = self.counters.get(hash, 0) + 1
         threshold = self.hotrunnerdesc.threshold
         assert counter > 0, (
             "reaching a fallback point for an already-compiled path")
         if counter >= threshold:
             return True
-        self.counters[greenkey] = counter
+        self.counters[hash] = counter
         return False
 
     @specialize.arglltype(2)
@@ -265,10 +265,11 @@
 
     @specialize.arglltype(1)
     def compile_hot_path(self, value):
+        hash = cast_whatever_to_int(lltype.typeOf(value), value)
         gv_value = self.hotrunnerdesc.interpreter.rgenop.genconst(value)
-        self._compile_hot_path(gv_value)
+        self._compile_hot_path(gv_value, hash)
 
-    def _compile_hot_path(self, gv_value):
+    def _compile_hot_path(self, gv_value, hash):
         # clone the jitstate
         memo = rvalue.copy_memo()
         jitstate = self.saved_jitstate.clone(memo)
@@ -281,8 +282,7 @@
         self.prepare_compiler(interpreter, gv_value)
         compile(interpreter)
         # done
-        greenkey = GreenKey([gv_value], self.hotpromotiondesc.greenkeydesc)
-        self.counters[greenkey] = -1     # means "compiled"
+        self.counters[hash] = -1     # means "compiled"
 
     def prepare_compiler(self, interpreter, gv_value):
         interpreter.green_result(gv_value)

Modified: pypy/branch/jit-hotpath/pypy/jit/timeshifter/greenkey.py
==============================================================================
--- pypy/branch/jit-hotpath/pypy/jit/timeshifter/greenkey.py	(original)
+++ pypy/branch/jit-hotpath/pypy/jit/timeshifter/greenkey.py	Sun Mar 16 17:19:34 2008
@@ -4,6 +4,8 @@
 from pypy.rlib.objectmodel import r_dict
 from pypy.rpython.lltypesystem import lltype
 
+# XXX green dicts are unsafe with moving GCs
+
 class KeyDesc(object):
     __metaclass__ = cachedtype
 



More information about the Pypy-commit mailing list