[pypy-svn] r74741 - pypy/trunk/pypy/jit/metainterp

arigo at codespeak.net arigo at codespeak.net
Tue May 25 19:27:34 CEST 2010


Author: arigo
Date: Tue May 25 19:27:33 2010
New Revision: 74741

Modified:
   pypy/trunk/pypy/jit/metainterp/compile.py
   pypy/trunk/pypy/jit/metainterp/pyjitpl.py
   pypy/trunk/pypy/jit/metainterp/warmstate.py
Log:
Attempt to simplify the logic about catching ContinueRunningNormally,
resetting some counters, and re-raising the exception.  I think that the
logic was subtly broken -- there are cases in which we would actually
exit the metainterp with another exception, like DoneWithThisFrame, but
we still want to reset counters.

Did not add tests for this case because it is a rare case needing a
completely custom test, and the test would arguably not be most useful
because it makes little sense in the new way the logic is written.



Modified: pypy/trunk/pypy/jit/metainterp/compile.py
==============================================================================
--- pypy/trunk/pypy/jit/metainterp/compile.py	(original)
+++ pypy/trunk/pypy/jit/metainterp/compile.py	Tue May 25 19:27:33 2010
@@ -255,12 +255,10 @@
             counter = self._counters.see(box)
             return counter >= trace_eagerness
 
-    def reset_counter_from_failure(self, metainterp):
+    def reset_counter_from_failure(self):
         if self._counter >= 0:
             self._counter = 0
         self._counters = None
-        warmrunnerstate = metainterp.staticdata.state
-        warmrunnerstate.disable_noninlinable_function(metainterp)
 
     def compile_and_attach(self, metainterp, new_loop):
         # We managed to create a bridge.  Attach the new operations
@@ -423,6 +421,9 @@
         # general loop token
         old_loop_tokens.append(new_loop_token)
 
+    def reset_counter_from_failure(self):
+        pass
+
 
 def compile_new_bridge(metainterp, old_loop_tokens, resumekey):
     """Try to compile a new bridge leading from the beginning of the history

Modified: pypy/trunk/pypy/jit/metainterp/pyjitpl.py
==============================================================================
--- pypy/trunk/pypy/jit/metainterp/pyjitpl.py	(original)
+++ pypy/trunk/pypy/jit/metainterp/pyjitpl.py	Tue May 25 19:27:33 2010
@@ -1304,7 +1304,6 @@
         self.staticdata = staticdata
         self.cpu = staticdata.cpu
         self.portal_trace_positions = []
-        self.greenkey_of_huge_function = None
 
     def is_blackholing(self):
         return self.history is None
@@ -1503,15 +1502,20 @@
         self.staticdata.stats.aborted()
         self.staticdata.profiler.end_tracing()
         self.staticdata.profiler.start_blackhole()
+        self.resumekey.reset_counter_from_failure()
     switch_to_blackhole._dont_inline_ = True
 
     def switch_to_blackhole_if_trace_too_long(self):
         if not self.is_blackholing():
             warmrunnerstate = self.staticdata.state
             if len(self.history.operations) > warmrunnerstate.trace_limit:
-                self.greenkey_of_huge_function = self.find_biggest_function()
+                greenkey_of_huge_function = self.find_biggest_function()
                 self.portal_trace_positions = None
                 self.switch_to_blackhole(ABORT_TOO_LONG)
+                if greenkey_of_huge_function is not None:
+                    warmrunnerstate = self.staticdata.state
+                    warmrunnerstate.disable_noninlinable_function(
+                        greenkey_of_huge_function)
 
     def _interpret(self):
         # Execute the frames forward until we raise a DoneWithThisFrame,
@@ -1580,7 +1584,6 @@
                 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
@@ -1588,17 +1591,12 @@
         self.current_merge_points = [(original_greenkey, -1)]
         self.resumekey = key
         self.seen_can_enter_jit = False
-        started_as_blackhole = self.is_blackholing()
         try:
             self.prepare_resume_from_failure(key.guard_opnum)
             self.interpret()
             assert False, "should always raise"
         except GenerateMergePoint, gmp:
             return self.designate_target_loop(gmp)
-        except ContinueRunningNormallyBase:
-            if not started_as_blackhole:
-                key.reset_counter_from_failure(self)
-            raise
 
     def remove_consts_and_duplicates(self, boxes, startindex, endindex,
                                      duplicates):

Modified: pypy/trunk/pypy/jit/metainterp/warmstate.py
==============================================================================
--- pypy/trunk/pypy/jit/metainterp/warmstate.py	(original)
+++ pypy/trunk/pypy/jit/metainterp/warmstate.py	Tue May 25 19:27:33 2010
@@ -157,16 +157,14 @@
         if self.profiler is not None:
             self.profiler.set_printing(value >= DEBUG_PROFILE)
 
-    def disable_noninlinable_function(self, metainterp):
-        greenkey = metainterp.greenkey_of_huge_function
-        if greenkey is not None:
-            cell = self.jit_cell_at_key(greenkey)
-            cell.dont_trace_here = True
-            debug_start("jit-disableinlining")
-            sd = self.warmrunnerdesc.metainterp_sd
-            loc = sd.state.get_location_str(greenkey)
-            debug_print("disabled inlining", loc)
-            debug_stop("jit-disableinlining")
+    def disable_noninlinable_function(self, greenkey):
+        cell = self.jit_cell_at_key(greenkey)
+        cell.dont_trace_here = True
+        debug_start("jit-disableinlining")
+        sd = self.warmrunnerdesc.metainterp_sd
+        loc = sd.state.get_location_str(greenkey)
+        debug_print("disabled inlining", loc)
+        debug_stop("jit-disableinlining")
 
     def attach_unoptimized_bridge_from_interp(self, greenkey,
                                               entry_loop_token):
@@ -227,11 +225,6 @@
                 cell.counter = -2
                 try:
                     loop_token = metainterp.compile_and_run_once(*args)
-                except ContinueRunningNormally:
-                    # the trace got too long, reset the counter
-                    cell.counter = 0
-                    self.disable_noninlinable_function(metainterp)
-                    raise
                 finally:
                     if cell.counter == -2:
                         cell.counter = 0



More information about the Pypy-commit mailing list