[pypy-svn] r68877 - pypy/branch/logging2/pypy/jit/metainterp

arigo at codespeak.net arigo at codespeak.net
Sat Oct 31 11:53:55 CET 2009


Author: arigo
Date: Sat Oct 31 11:53:55 2009
New Revision: 68877

Modified:
   pypy/branch/logging2/pypy/jit/metainterp/compile.py
   pypy/branch/logging2/pypy/jit/metainterp/history.py
   pypy/branch/logging2/pypy/jit/metainterp/policy.py
   pypy/branch/logging2/pypy/jit/metainterp/pyjitpl.py
Log:
Add debug_start/stop/print in pyjitpl.
The next step is to try to remove jitprof.py.


Modified: pypy/branch/logging2/pypy/jit/metainterp/compile.py
==============================================================================
--- pypy/branch/logging2/pypy/jit/metainterp/compile.py	(original)
+++ pypy/branch/logging2/pypy/jit/metainterp/compile.py	Sat Oct 31 11:53:55 2009
@@ -5,7 +5,7 @@
 from pypy.conftest import option
 
 from pypy.jit.metainterp.resoperation import ResOperation, rop
-from pypy.jit.metainterp.history import TreeLoop, log, Box, History, LoopToken
+from pypy.jit.metainterp.history import TreeLoop, Box, History, LoopToken
 from pypy.jit.metainterp.history import AbstractFailDescr, BoxInt
 from pypy.jit.metainterp.history import BoxPtr, BoxObj, BoxFloat, Const
 from pypy.jit.metainterp import history

Modified: pypy/branch/logging2/pypy/jit/metainterp/history.py
==============================================================================
--- pypy/branch/logging2/pypy/jit/metainterp/history.py	(original)
+++ pypy/branch/logging2/pypy/jit/metainterp/history.py	Sat Oct 31 11:53:55 2009
@@ -3,18 +3,13 @@
 from pypy.rpython.lltypesystem import lltype, llmemory, rffi
 from pypy.rpython.ootypesystem import ootype
 from pypy.rlib.objectmodel import we_are_translated, r_dict, Symbolic
-from pypy.rlib.objectmodel import compute_hash
+from pypy.rlib.objectmodel import compute_hash, compute_unique_id
 from pypy.rlib.rarithmetic import intmask
 from pypy.tool.uid import uid
 from pypy.conftest import option
 
 from pypy.jit.metainterp.resoperation import ResOperation, rop
 
-import py
-from pypy.tool.ansi_print import ansi_log
-log = py.log.Producer('compiler')
-py.log.setconsumer('compiler', ansi_log)
-
 # ____________________________________________________________
 
 INT   = 'i'
@@ -69,14 +64,9 @@
     except AttributeError:
         return box.value
 
-class ReprRPython:
-    def __init__(self):
-        self.seen = {}
-    def repr_rpython(self, box, typechars):
-        n = self.seen.setdefault(box, len(self.seen))
-        return '%s/%s%d' % (box._get_hash_(), typechars, n)
-
-repr_rpython = ReprRPython().repr_rpython
+def repr_rpython(box, typechars):
+    return '%s/%s%d' % (box._get_hash_(), typechars,
+                        compute_unique_id(box))
 
 
 class AbstractValue(object):

Modified: pypy/branch/logging2/pypy/jit/metainterp/policy.py
==============================================================================
--- pypy/branch/logging2/pypy/jit/metainterp/policy.py	(original)
+++ pypy/branch/logging2/pypy/jit/metainterp/policy.py	Sat Oct 31 11:53:55 2009
@@ -77,8 +77,9 @@
                     getkind(v.concretetype, supports_floats)
                 getkind(op.result.concretetype, supports_floats)
     except NotImplementedError, e:
-        history.log.WARNING('%s, ignoring graph' % (e,))
-        history.log.WARNING('  %s' % (graph,))
+        from pypy.jit.metainterp.codewriter import log
+        log.WARNING('%s, ignoring graph' % (e,))
+        log.WARNING('  %s' % (graph,))
         return True
     return False
 

Modified: pypy/branch/logging2/pypy/jit/metainterp/pyjitpl.py
==============================================================================
--- pypy/branch/logging2/pypy/jit/metainterp/pyjitpl.py	(original)
+++ pypy/branch/logging2/pypy/jit/metainterp/pyjitpl.py	Sat Oct 31 11:53:55 2009
@@ -3,7 +3,7 @@
 from pypy.rpython.ootypesystem import ootype
 from pypy.rlib.objectmodel import we_are_translated
 from pypy.rlib.unroll import unrolling_iterable
-from pypy.rlib.debug import debug_print
+from pypy.rlib.debug import debug_start, debug_stop, debug_print
 
 from pypy.jit.metainterp import history, compile, resume
 from pypy.jit.metainterp.history import Const, ConstInt, Box
@@ -875,12 +875,10 @@
         self.pc = pc
         self.exception_target = exception_target
         self.env = env
-        if self.metainterp.staticdata.state.debug_level >= DEBUG_DETAILED:
-            values = ' '.join([box.repr_rpython() for box in self.env])
-            log = self.metainterp.staticdata.log
-            log('setup_resume_at_op  %s:%d [%s] %d' % (self.jitcode.name,
-                                                       self.pc, values,
-                                                       self.exception_target))
+        ##  values = ' '.join([box.repr_rpython() for box in self.env])
+        ##  log('setup_resume_at_op  %s:%d [%s] %d' % (self.jitcode.name,
+        ##                                             self.pc, values,
+        ##                                             self.exception_target))
 
     def run_one_step(self):
         # Execute the frame forward.  This method contains a loop that leaves
@@ -1022,7 +1020,7 @@
         if not self.globaldata.initialized:
             self._setup_class_sizes()
             self.cpu.setup_once()
-            self.log(self.jit_starting_line)
+            debug_print(self.jit_starting_line)
             if not self.profiler.initialized:
                 self.profiler.start()
                 self.profiler.initialized = True
@@ -1078,12 +1076,8 @@
 
     # ---------------- logging ------------------------
 
-    def log(self, msg, event_kind='info'):
-        if self.state.debug_level > DEBUG_PROFILE:
-            if not we_are_translated():
-                getattr(history.log, event_kind)(msg)
-            else:
-                debug_print(msg)
+    def log(self, msg):
+        debug_print(msg)
 
 # ____________________________________________________________
 
@@ -1136,12 +1130,6 @@
     def is_blackholing(self):
         return self.history is None
 
-    def blackholing_text(self):
-        if self.history is None:
-            return " (BlackHole)"
-        else:
-            return ""
-
     def newframe(self, jitcode):
         if jitcode is self.staticdata.portal_code:
             self.in_recursion += 1
@@ -1333,9 +1321,11 @@
             op.name = self.framestack[-1].jitcode.name
 
     def switch_to_blackhole(self):
+        debug_print('~~~ ABORTING TRACING')
+        debug_stop('jit-tracing')
+        debug_start('jit-blackhole')
         self.history = None   # start blackholing
         self.staticdata.stats.aborted()
-        self.staticdata.log('~~~ ABORTING TRACING', event_kind='event')
         self.staticdata.profiler.end_tracing()
         self.staticdata.profiler.start_blackhole()
 
@@ -1350,8 +1340,6 @@
         # Execute the frames forward until we raise a DoneWithThisFrame,
         # a ContinueRunningNormally, or a GenerateMergePoint exception.
         self.staticdata.stats.entered()
-        self.staticdata.log('~~~ ENTER' + self.blackholing_text(),
-                            event_kind='event')
         try:
             while True:
                 self.framestack[-1].run_one_step()
@@ -1363,8 +1351,6 @@
                 self.staticdata.profiler.end_blackhole()
             else:
                 self.staticdata.profiler.end_tracing()
-            self.staticdata.log('~~~ LEAVE' + self.blackholing_text(),
-                                event_kind='event')
 
     def interpret(self):
         if we_are_translated():
@@ -1375,11 +1361,22 @@
             except:
                 import sys
                 if sys.exc_info()[0] is not None:
-                    history.log.info(sys.exc_info()[0].__name__)
+                    codewriter.log.info(sys.exc_info()[0].__name__)
                 raise
 
     def compile_and_run_once(self, *args):
-        self.staticdata.log('Switching from interpreter to compiler')
+        self.staticdata._setup_once()
+        debug_start('jit-tracing')
+        self.create_empty_history()
+        try:
+            return self._compile_and_run_once(*args)
+        finally:
+            if self.history is None:
+                debug_stop('jit-blackhole')
+            else:
+                debug_stop('jit-tracing')
+
+    def _compile_and_run_once(self, *args):
         original_boxes = self.initialize_state_from_start(*args)
         self.current_merge_points = [(original_boxes, 0)]
         num_green_args = self.staticdata.num_green_args
@@ -1395,9 +1392,24 @@
             return self.designate_target_loop(gmp)
 
     def handle_guard_failure(self, key):
-        from pypy.jit.metainterp.warmspot import ContinueRunningNormallyBase
         assert isinstance(key, compile.ResumeGuardDescr)
-        resumedescr = self.initialize_state_from_guard_failure(key)
+        warmrunnerstate = self.staticdata.state
+        must_compile = warmrunnerstate.must_compile_from_failure(key)
+        if must_compile:
+            debug_start('jit-tracing')
+        else:
+            debug_start('jit-blackhole')
+        self.initialize_state_from_guard_failure(key, must_compile)
+        try:
+            return self._handle_guard_failure(key)
+        finally:
+            if self.history is None:
+                debug_stop('jit-blackhole')
+            else:
+                debug_stop('jit-tracing')
+
+    def _handle_guard_failure(self, key):
+        from pypy.jit.metainterp.warmspot import ContinueRunningNormallyBase
         original_greenkey = key.original_greenkey
         # notice that here we just put the greenkey
         # use -1 to mark that we will have to give up
@@ -1415,7 +1427,7 @@
         except ContinueRunningNormallyBase:
             if not started_as_blackhole:
                 warmrunnerstate = self.staticdata.state
-                warmrunnerstate.reset_counter_from_failure(resumedescr)
+                warmrunnerstate.reset_counter_from_failure(key)
             raise
 
     def forget_consts(self, boxes, startindex=0):
@@ -1577,9 +1589,7 @@
 
     def initialize_state_from_start(self, *args):
         self.in_recursion = -1 # always one portal around
-        self.staticdata._setup_once()
         self.staticdata.profiler.start_tracing()
-        self.create_empty_history()
         num_green_args = self.staticdata.num_green_args
         original_boxes = []
         self._initialize_from_start(original_boxes, num_green_args, *args)
@@ -1591,12 +1601,11 @@
         self.initialize_virtualizable(original_boxes)
         return original_boxes
 
-    def initialize_state_from_guard_failure(self, resumedescr):
+    def initialize_state_from_guard_failure(self, resumedescr, must_compile):
         # guard failure: rebuild a complete MIFrame stack
         self.in_recursion = -1 # always one portal around
         inputargs = self.load_values_from_failure(resumedescr)
         warmrunnerstate = self.staticdata.state
-        must_compile = warmrunnerstate.must_compile_from_failure(resumedescr)
         if must_compile:
             self.history = history.History(self.cpu)
             self.history.inputargs = inputargs
@@ -1605,7 +1614,6 @@
             self.staticdata.profiler.start_blackhole()
             self.history = None   # this means that is_blackholing() is true
         self.rebuild_state_after_failure(resumedescr, inputargs)
-        return resumedescr
 
     def load_values_from_failure(self, resumedescr):
         cpu = self.cpu



More information about the Pypy-commit mailing list