[pypy-svn] r62943 - pypy/branch/pyjitpl5/pypy/jit/backend/x86

fijal at codespeak.net fijal at codespeak.net
Fri Mar 13 17:54:28 CET 2009


Author: fijal
Date: Fri Mar 13 17:54:26 2009
New Revision: 62943

Modified:
   pypy/branch/pyjitpl5/pypy/jit/backend/x86/assembler.py
   pypy/branch/pyjitpl5/pypy/jit/backend/x86/inp
   pypy/branch/pyjitpl5/pypy/jit/backend/x86/runner.py
Log:
improve logging of events from x86 backend. That let's us leave almost
full traces for even complex tests that include failing guards and
catches. Note that debugging tools are not ready to parse that yet :)


Modified: pypy/branch/pyjitpl5/pypy/jit/backend/x86/assembler.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/backend/x86/assembler.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/x86/assembler.py	Fri Mar 13 17:54:26 2009
@@ -1,4 +1,4 @@
-import sys
+import sys, os
 import ctypes
 from pypy.jit.backend.x86 import symbolic
 from pypy.jit.metainterp.history import Const, ConstInt, Box, ConstPtr, BoxPtr,\
@@ -54,6 +54,20 @@
         self.malloc_func_addr = 0
         self._exception_data = lltype.nullptr(rffi.CArray(lltype.Signed))
         self._exception_addr = 0
+        self._log_fd = self._get_log()
+
+    def _get_log(self):
+        s = os.environ.get('PYPYJITLOG')
+        if not s:
+            return -1
+        s += '.ops'
+        try:
+            flags = os.O_WRONLY|os.O_CREAT|os.O_TRUNC
+            log_fd = os.open(s, flags, 0666)
+        except OSError:
+            os.write(2, "could not create log file\n")
+            return -1
+        return log_fd
 
     def make_sure_mc_exists(self):
         if self.mc is None:
@@ -79,7 +93,43 @@
             # the address of the function called by 'new': directly use
             # Boehm's GC_malloc function.
             if self.malloc_func_addr == 0:
-                self.malloc_func_addr = gc_malloc_fnaddr() 
+                self.malloc_func_addr = gc_malloc_fnaddr()
+
+    def eventually_log_operations(self, operations, guard_op):
+        if self._log_fd == -1:
+            return
+        memo = {}
+        os.write(self._log_fd, "<<<<<<<<<<\n")
+        if guard_op is not None:
+            os.write(self._log_fd, "GO(%d)\n" % guard_op._jmp_from)
+        for op in operations:
+            args = ",".join([repr_of_arg(memo, arg) for arg in op.args])
+            os.write(self._log_fd, "%s %s\n" % (op.getopname(), args))
+            if op.result is not None:
+                os.write(self._log_fd, "  => %s\n" % repr_of_arg(memo,
+                                                                 op.result))
+            if op.is_guard():
+                liveboxes_s = ",".join([repr_of_arg(memo, arg) for arg in
+                                        op.liveboxes])
+                os.write(self._log_fd, "  .. %s\n" % liveboxes_s)
+        os.write(self._log_fd, ">>>>>>>>>>\n")
+
+    def log_failure_recovery(self, gf, guard_index):
+        if self._log_fd == -1:
+            return
+        os.write(self._log_fd, 'xxxxxxxxxx\n')
+        j = 0
+        memo = {}
+        reprs = []
+        for box in gf.guard_op.liveboxes:
+            if isinstance(box, Box):
+                valuebox = gf.cpu.getvaluebox(gf.frame, gf.guard_op, j)
+                reprs.append(repr_of_arg(memo, valuebox))
+                j += 1
+        jmp = gf.guard_op._jmp_from
+        os.write(self._log_fd, "%d %d %s\n" % (guard_index, jmp,
+                                               ",".join(reprs)))
+        os.write(self._log_fd, 'xxxxxxxxxx\n')
 
     def assemble(self, operations, guard_op, verbose=False):
         self.verbose = verbose
@@ -89,19 +139,7 @@
         self.make_sure_mc_exists()
         op0 = operations[0]
         op0.position = self.mc.tell()
-        if self.verbose and we_are_translated():
-            print
-            memo = {}
-            for op in operations:
-                args = ",".join([repr_of_arg(memo, arg) for arg in op.args])
-                llop.debug_print(lltype.Void, "%s %s" % (op.getopname(), args))
-                if op.result is not None:
-                    llop.debug_print(lltype.Void, "  => %s" % repr_of_arg(memo, op.result))
-                if op.is_guard():
-                    liveboxes_s = ",".join([repr_of_arg(memo, arg) for arg in
-                                            op.liveboxes])
-                    llop.debug_print(lltype.Void, "  .. %s" % liveboxes_s)
-            print
+        self.eventually_log_operations(operations, guard_op)
         regalloc = RegAlloc(operations, guard_op, self.cpu.translate_support_code)
         if not we_are_translated():
             self._regalloc = regalloc # for debugging

Modified: pypy/branch/pyjitpl5/pypy/jit/backend/x86/inp
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/backend/x86/inp	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/x86/inp	Fri Mar 13 17:54:26 2009
@@ -1,12 +1,40 @@
-merge_point bp(0,135638976),bi(1,210),bi(2,4),bi(3,1),bi(4,1),bi(5,2),bi(6,6)
-guard_value bi(5,2),ci(7,2)
-int_le bi(2,4),ci(8,1)
-  => bi(9,0)
-int_is_true bi(9,0)
-  => bi(10,0)
-guard_false bi(10,0)
-int_mul bi(1,210),bi(2,4)
-  => bi(11,840)
-int_sub bi(2,4),ci(12,1)
-  => bi(13,3)
-jump bp(0,135638976),bi(11,840),bi(13,3),ci(14,1),ci(8,1),ci(15,2),bi(6,6)
+<<<<<<<<<<
+merge_point bi(0,7),bi(1,3),bi(2,27)
+int_add bi(2,27),bi(0,7)
+  => bi(3,34)
+int_add bi(1,3),ci(4,1)
+  => bi(5,4)
+int_eq bi(5,4),ci(6,4)
+  => bi(7,1)
+guard_true bi(7,1)
+  .. bi(0,7),bi(3,34),bi(5,4),ci(8,0)
+int_add bi(3,34),ci(9,100)
+  => bi(10,134)
+int_sub bi(0,7),ci(4,1)
+  => bi(11,6)
+int_gt bi(11,6),ci(8,0)
+  => bi(12,1)
+guard_true bi(12,1)
+  .. bi(11,6),bi(10,134),ci(8,0),ci(8,0)
+jump bi(11,6),ci(8,0),bi(10,134)
+>>>>>>>>>>
+xxxxxxxxxx
+0 -1342111720 bi(0,6),bi(1,140),bi(2,1)
+xxxxxxxxxx
+xxxxxxxxxx
+0 -1342111720 bi(0,2),bi(1,254),bi(2,1)
+xxxxxxxxxx
+<<<<<<<<<<
+GO(-1342111720)
+catch bi(0,2),bi(1,254),bi(2,1),ci(3,0)
+int_sub bi(0,2),ci(4,1)
+  => bi(5,1)
+int_gt bi(5,1),ci(3,0)
+  => bi(6,1)
+guard_true bi(6,1)
+  .. bi(5,1),bi(1,254),bi(2,1),ci(3,0)
+jump bi(5,1),bi(2,1),bi(1,254)
+>>>>>>>>>>
+xxxxxxxxxx
+2 -1342111655 bi(0,0),bi(1,255),bi(2,2)
+xxxxxxxxxx

Modified: pypy/branch/pyjitpl5/pypy/jit/backend/x86/runner.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/jit/backend/x86/runner.py	(original)
+++ pypy/branch/pyjitpl5/pypy/jit/backend/x86/runner.py	Fri Mar 13 17:54:26 2009
@@ -145,6 +145,7 @@
                 llop.debug_print(lltype.Void, '.. calling back from',
                                  guard_op, 'to the jit')
             gf = GuardFailed(self, frame_addr, guard_op)
+            self.assembler.log_failure_recovery(gf, guard_index)
             self.metainterp.handle_guard_failure(gf)
             self.return_value_type = gf.return_value_type
             if self.debug:



More information about the Pypy-commit mailing list