[pypy-svn] r74856 - pypy/branch/blackhole-improvement/pypy/jit/metainterp

arigo at codespeak.net arigo at codespeak.net
Fri May 28 16:23:48 CEST 2010


Author: arigo
Date: Fri May 28 16:23:47 2010
New Revision: 74856

Added:
   pypy/branch/blackhole-improvement/pypy/jit/metainterp/jitexc.py
Modified:
   pypy/branch/blackhole-improvement/pypy/jit/metainterp/blackhole.py
   pypy/branch/blackhole-improvement/pypy/jit/metainterp/executor.py
   pypy/branch/blackhole-improvement/pypy/jit/metainterp/jitprof.py
   pypy/branch/blackhole-improvement/pypy/jit/metainterp/optimizeutil.py
   pypy/branch/blackhole-improvement/pypy/jit/metainterp/pyjitpl.py
   pypy/branch/blackhole-improvement/pypy/jit/metainterp/warmspot.py
Log:
More translation fixes.  The first test in test_ztranslation passes.


Modified: pypy/branch/blackhole-improvement/pypy/jit/metainterp/blackhole.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/metainterp/blackhole.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/metainterp/blackhole.py	Fri May 28 16:23:47 2010
@@ -6,9 +6,9 @@
 from pypy.rpython.lltypesystem import lltype, llmemory, rclass
 from pypy.rpython.lltypesystem.lloperation import llop
 from pypy.rpython.llinterp import LLException
-from pypy.rpython.annlowlevel import cast_instance_to_base_ptr
 from pypy.jit.codewriter.jitcode import JitCode, SwitchDictDescr
 from pypy.jit.codewriter import heaptracker
+from pypy.jit.metainterp.jitexc import JitException, get_llexception
 
 
 def arguments(*argtypes, **kwds):
@@ -20,7 +20,7 @@
         return function
     return decorate
 
-class LeaveFrame(Exception):
+class LeaveFrame(JitException):
     pass
 
 class MissingValue(object):
@@ -33,21 +33,6 @@
 
 NULL = lltype.nullptr(llmemory.GCREF.TO)
 
-def _get_standard_error(rtyper, Class):
-    exdata = rtyper.getexceptiondata()
-    clsdef = rtyper.annotator.bookkeeper.getuniqueclassdef(Class)
-    evalue = exdata.get_standard_ll_exc_instance(rtyper, clsdef)
-    return evalue
-
-def get_llexception(cpu, e):
-    if we_are_translated():
-        return cast_instance_to_base_ptr(e)
-    if isinstance(e, LLException):
-        return e.args[1]    # ok
-    if isinstance(e, OverflowError):
-        return _get_standard_error(cpu.rtyper, OverflowError)
-    raise   # leave other exceptions to be propagated
-
 # ____________________________________________________________
 
 
@@ -305,6 +290,8 @@
                 self.dispatch_loop(self, self.jitcode.code, self.position)
             except LeaveFrame:
                 break
+            except JitException:
+                raise     # go through
             except Exception, e:
                 lle = get_llexception(self.cpu, e)
                 self.handle_exception_in_frame(lle)
@@ -1183,6 +1170,8 @@
             # we now proceed to interpret the bytecode in this frame
             self.run()
         #
+        except JitException:
+            raise     # go through
         except Exception, e:
             # if we get an exception, return it to the caller frame
             current_exc = get_llexception(self.cpu, e)

Modified: pypy/branch/blackhole-improvement/pypy/jit/metainterp/executor.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/metainterp/executor.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/metainterp/executor.py	Fri May 28 16:23:47 2010
@@ -252,7 +252,7 @@
             execute = execute_by_num_args[num_args]
             #
             if execute[value] is not None:
-                raise Exception("duplicate entry for op number %d" % value)
+                raise AssertionError("duplicate entry for op number %d"% value)
             if key.endswith('_PURE'):
                 key = key[:-5]
             #
@@ -276,7 +276,14 @@
                 if func is not None:
                     execute[value] = func
                     continue
-            print "XXX warning: missing", key
+            if value in (rop.FORCE_TOKEN,
+                         rop.CALL_ASSEMBLER,
+                         rop.COND_CALL_GC_WB,
+                         rop.DEBUG_MERGE_POINT,
+                         rop.SETARRAYITEM_RAW,
+                         ):      # list of opcodes never executed by pyjitpl
+                continue
+            raise AssertionError("missing %r" % (key,))
     return execute_by_num_args
 
 def make_execute_function_with_boxes(name, func):

Added: pypy/branch/blackhole-improvement/pypy/jit/metainterp/jitexc.py
==============================================================================
--- (empty file)
+++ pypy/branch/blackhole-improvement/pypy/jit/metainterp/jitexc.py	Fri May 28 16:23:47 2010
@@ -0,0 +1,28 @@
+from pypy.rpython.annlowlevel import cast_instance_to_base_ptr
+from pypy.rpython.llinterp import LLException
+from pypy.rlib.objectmodel import we_are_translated
+
+
+class JitException(Exception):
+    """The base class for exceptions raised and caught in the JIT.
+    The point is that the places that catch any user exception should avoid
+    catching exceptions that inherit from JitException.
+    """
+    _go_through_llinterp_uncaught_ = True     # ugh
+
+
+def _get_standard_error(rtyper, Class):
+    exdata = rtyper.getexceptiondata()
+    clsdef = rtyper.annotator.bookkeeper.getuniqueclassdef(Class)
+    evalue = exdata.get_standard_ll_exc_instance(rtyper, clsdef)
+    return evalue
+
+def get_llexception(cpu, e):
+    if we_are_translated():
+        return cast_instance_to_base_ptr(e)
+    assert not isinstance(e, JitException)
+    if isinstance(e, LLException):
+        return e.args[1]    # ok
+    if isinstance(e, OverflowError):
+        return _get_standard_error(cpu.rtyper, OverflowError)
+    raise   # leave other exceptions to be propagated

Modified: pypy/branch/blackhole-improvement/pypy/jit/metainterp/jitprof.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/metainterp/jitprof.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/metainterp/jitprof.py	Fri May 28 16:23:47 2010
@@ -5,6 +5,7 @@
 import os
 import time
 from pypy.rlib.debug import debug_print
+from pypy.jit.metainterp.jitexc import JitException
 
 counters="""
 TRACING
@@ -192,5 +193,5 @@
         
         
 
-class BrokenProfilerData(Exception):
+class BrokenProfilerData(JitException):
     pass

Modified: pypy/branch/blackhole-improvement/pypy/jit/metainterp/optimizeutil.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/metainterp/optimizeutil.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/metainterp/optimizeutil.py	Fri May 28 16:23:47 2010
@@ -2,8 +2,9 @@
 from pypy.rlib.rarithmetic import intmask
 from pypy.rlib.unroll import unrolling_iterable
 from pypy.jit.metainterp import resoperation, history
+from pypy.jit.metainterp.jitexc import JitException
 
-class InvalidLoop(Exception):
+class InvalidLoop(JitException):
     """Raised when the optimize*.py detect that the loop that
     we are trying to build cannot possibly make sense as a
     long-running loop (e.g. it cannot run 2 complete iterations)."""

Modified: pypy/branch/blackhole-improvement/pypy/jit/metainterp/pyjitpl.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/metainterp/pyjitpl.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/metainterp/pyjitpl.py	Fri May 28 16:23:47 2010
@@ -15,7 +15,7 @@
 from pypy.jit.metainterp.jitprof import EmptyProfiler
 from pypy.jit.metainterp.jitprof import GUARDS, RECORDED_OPS, ABORT_ESCAPE
 from pypy.jit.metainterp.jitprof import ABORT_TOO_LONG, ABORT_BRIDGE
-from pypy.jit.metainterp.blackhole import get_llexception
+from pypy.jit.metainterp.jitexc import JitException, get_llexception
 from pypy.rlib.rarithmetic import intmask
 from pypy.rlib.objectmodel import specialize
 from pypy.rlib.jit import DEBUG_OFF, DEBUG_PROFILE, DEBUG_STEPS, DEBUG_DETAILED
@@ -1287,16 +1287,7 @@
                 assert False
 
     def finishframe_exception(self):
-        # detect and propagate some exceptions early:
-        #  - AssertionError
-        #  - all subclasses of JitException
         excvaluebox = self.last_exc_value_box
-        if we_are_translated():
-            from pypy.jit.metainterp.warmspot import JitException
-            e = self.cpu.ts.get_exception_obj(excvaluebox)
-            if isinstance(e, JitException) or isinstance(e, AssertionError):
-                raise Exception, e
-        #
         while self.framestack:
             frame = self.framestack[-1]
             code = frame.bytecode
@@ -1332,7 +1323,7 @@
                 else:
                     print " ",
                 print jitcode.name
-            raise Exception
+            raise AssertionError
 
     def create_empty_history(self):
         warmrunnerstate = self.staticdata.state
@@ -1417,6 +1408,8 @@
             op.name = self.framestack[-1].jitcode.name
 
     def execute_raised(self, exception, constant=False):
+        if isinstance(exception, JitException):
+            raise JitException, exception      # go through
         llexception = get_llexception(self.cpu, exception)
         self.execute_ll_raised(llexception, constant)
 
@@ -2006,17 +1999,17 @@
 
 # ____________________________________________________________
 
-class GenerateMergePoint(Exception):
+class GenerateMergePoint(JitException):
     def __init__(self, args, target_loop_token):
         assert target_loop_token is not None
         self.argboxes = args
         self.target_loop_token = target_loop_token
 
-class ChangeFrame(Exception):
+class ChangeFrame(JitException):
     """Raised after we mutated metainterp.framestack, in order to force
     it to reload the current top-of-stack frame that gets interpreted."""
 
-class SwitchToBlackhole(Exception):
+class SwitchToBlackhole(JitException):
     def __init__(self, reason):
         self.reason = reason
 

Modified: pypy/branch/blackhole-improvement/pypy/jit/metainterp/warmspot.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/metainterp/warmspot.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/metainterp/warmspot.py	Fri May 28 16:23:47 2010
@@ -20,6 +20,7 @@
 from pypy.jit.metainterp.pyjitpl import MetaInterpStaticData, MetaInterp
 from pypy.jit.metainterp.typesystem import LLTypeHelper, OOTypeHelper
 from pypy.jit.metainterp.jitprof import Profiler, EmptyProfiler
+from pypy.jit.metainterp.jitexc import JitException
 from pypy.jit.codewriter import support, codewriter
 from pypy.jit.codewriter.policy import JitPolicy
 from pypy.rlib.jit import DEBUG_STEPS, DEBUG_DETAILED, DEBUG_OFF, DEBUG_PROFILE
@@ -130,9 +131,6 @@
     stats.maybe_view()
     stats.check_consistency()
 
-class JitException(Exception):
-    _go_through_llinterp_uncaught_ = True     # ugh
-
 class ContinueRunningNormallyBase(JitException):
     pass
 



More information about the Pypy-commit mailing list