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

fijal at codespeak.net fijal at codespeak.net
Wed Mar 4 09:12:15 CET 2009


Author: fijal
Date: Wed Mar  4 09:12:14 2009
New Revision: 62507

Added:
   pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_debug.py   (contents, props changed)
Modified:
   pypy/branch/pyjitpl5/pypy/jit/metainterp/dump.py
   pypy/branch/pyjitpl5/pypy/jit/metainterp/pyjitpl.py
Log:
More debug support. This allows to show how the particular loop was created
giving full (followed) call stack


Modified: pypy/branch/pyjitpl5/pypy/jit/metainterp/dump.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/metainterp/dump.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/dump.py	Wed Mar  4 09:12:14 2009
@@ -85,7 +85,6 @@
     def __repr__(self):
         return self.s
 
-
 def dump_bytecode(jitcode, file=None):
     # XXX this is not really a disassembler, but just a pretty-printer
     # for the '_source' attribute that codewriter.py attaches
@@ -134,3 +133,21 @@
 
     if src.pc != len(jitcode.code):
         print >> file, 'WARNING: the pc column is bogus! fix dump.py!'
+
+def dump_call_history(call_history):
+    indent = 0
+    for ev, code, args in call_history:
+        if ev == 'enter':
+            if args is not None:
+                args_s = [str(a) for a in args]
+            else:
+                args_s = []
+            print "%s%s(%s)" % (" "*indent, code.name, ','.join(args_s))
+            indent += 2
+        elif ev.startswith('leave'):
+            indent -= 2
+        elif ev == 'guard_failure':
+            break
+        else:
+            raise NotImplementedError(ev)
+

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	Wed Mar  4 09:12:14 2009
@@ -613,6 +613,8 @@
             check_args(*argboxes)
         self.pc = 0
         self.env = argboxes
+        if not we_are_translated():
+            self.metainterp._debug_history[-1][-1] = argboxes
         #self.starts_with_greens()
         #assert len(argboxes) == len(self.graph.getargs())
 
@@ -742,6 +744,7 @@
         self.class_sizes = populate_type_cache(graphs, self.cpu)
 
         self._virtualizabledescs = {}
+        self._debug_history = []
 
     def generate_bytecode(self, policy):
         self._codewriter = codewriter.CodeWriter(self, policy)
@@ -754,12 +757,16 @@
         return not we_are_translated()
 
     def newframe(self, jitcode):
+        if not we_are_translated():
+            self._debug_history.append(['enter', jitcode, None])
         f = MIFrame(self, jitcode)
         self.framestack.append(f)
         return f
 
     def finishframe(self, resultbox):
-        self.framestack.pop()
+        frame = self.framestack.pop()
+        if not we_are_translated():
+            self._debug_history.append(['leave', frame.jitcode, None])
         if self.framestack:
             if resultbox is not None:
                 self.framestack[-1].make_result_box(resultbox)
@@ -776,6 +783,8 @@
                 frame.exception_box = exceptionbox
                 frame.exc_value_box = excvaluebox
                 return True
+            if not we_are_translated():
+                self._debug_history.append(['leave_exc', frame.jitcode, None])
             self.framestack.pop()
         raise self.ExitFrameWithException(exceptionbox, excvaluebox)
 
@@ -862,6 +871,9 @@
                                 live_arg_boxes[num_green_args:])
         if not loop:
             raise self.ContinueRunningNormally(live_arg_boxes)
+        if not we_are_translated():
+            loop._call_history = self._debug_history
+            self.debug_history = []
         return loop
 
     def compile_bridge(self, guard_failure, original_boxes, live_arg_boxes):
@@ -879,6 +891,9 @@
                                         live_arg_boxes[num_green_args:])
         if bridge is None:
             raise self.ContinueRunningNormally(live_arg_boxes)
+        if not we_are_translated():
+            bridge._call_history = self._debug_history
+            self.debug_history = []
         guard_failure.guard_op.jump_target = bridge.operations[0]
         return bridge
 
@@ -971,7 +986,9 @@
             return False
 
     def rebuild_state_after_failure(self, key, newboxes):
-        self.framestack = []
+        if not we_are_translated():
+            self._debug_history.append(['guard_failure', None, None])
+            self.framestack = []
         nbindex = 0
         for jitcode, pc, envlength, exception_target in key:
             f = self.newframe(jitcode)

Added: pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_debug.py
==============================================================================
--- (empty file)
+++ pypy/branch/pyjitpl5/pypy/jit/metainterp/test/test_debug.py	Wed Mar  4 09:12:14 2009
@@ -0,0 +1,43 @@
+
+from pypy.jit.metainterp.test.test_basic import LLJitMixin
+from pypy.rlib.jit import JitDriver
+from pypy.jit.metainterp.policy import StopAtXPolicy
+from pypy.jit.metainterp.warmspot import get_stats
+from pypy.jit.metainterp.dump import dump_call_history
+
+class TestDebug(LLJitMixin):
+    def test_callstack(self):
+        myjitdriver = JitDriver(greens = [], reds = ['n'])
+
+        def x(n):
+            pass
+
+        def z(n):
+            x(n)
+
+        def g(n):
+            z(n)
+
+        def f(n):
+            while n > 0:
+                myjitdriver.can_enter_jit(n=n)
+                myjitdriver.jit_merge_point(n=n)
+                g(n)
+                n -= 1
+            return n
+
+        res = self.meta_interp(f, [10], policy=StopAtXPolicy(x))
+        assert res == 0
+        ch = get_stats().loops[0]._call_history
+        cmp = [(i, getattr(j, 'name', 'gf')) for i, j, _ in ch]
+        assert cmp == [
+            ('enter', 'f'),
+            ('enter', 'g'),
+            ('enter', 'z'),
+            ('leave', 'z'),
+            ('leave', 'g'),
+            ('guard_failure', 'gf'),
+            ('enter', 'f'),
+            ('leave', 'f'),
+            ]
+        dump_call_history(ch)



More information about the Pypy-commit mailing list