[pypy-svn] r74110 - in pypy/branch/blackhole-improvement/pypy/jit: backend/llgraph metainterp metainterp/test

arigo at codespeak.net arigo at codespeak.net
Tue Apr 27 15:31:27 CEST 2010


Author: arigo
Date: Tue Apr 27 15:31:25 2010
New Revision: 74110

Modified:
   pypy/branch/blackhole-improvement/pypy/jit/backend/llgraph/llimpl.py
   pypy/branch/blackhole-improvement/pypy/jit/backend/llgraph/runner.py
   pypy/branch/blackhole-improvement/pypy/jit/metainterp/blackhole.py
   pypy/branch/blackhole-improvement/pypy/jit/metainterp/test/test_blackhole.py
Log:
Correctly catch the exceptions, at least when not translated for now.


Modified: pypy/branch/blackhole-improvement/pypy/jit/backend/llgraph/llimpl.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/backend/llgraph/llimpl.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/backend/llgraph/llimpl.py	Tue Apr 27 15:31:25 2010
@@ -1352,9 +1352,7 @@
 def do_call_pushfloat(x):
     _call_args_f.append(x)
 
-def _do_call_common(f, err_result=None):
-    global _last_exception
-    assert _last_exception is None, "exception left behind"
+def _do_call_common(f):
     ptr = llmemory.cast_int_to_adr(f).ptr
     FUNC = lltype.typeOf(ptr).TO
     ARGS = FUNC.ARGS
@@ -1363,30 +1361,27 @@
     del _call_args_r[:]
     del _call_args_f[:]
     assert len(ARGS) == len(args)
-    try:
-        if hasattr(ptr._obj, 'graph'):
-            llinterp = _llinterp      # it's a global set here by CPU.__init__()
-            result = llinterp.eval_graph(ptr._obj.graph, args)
-        else:
-            result = ptr._obj._callable(*args)
-    except LLException, e:
-        _last_exception = e
-        result = err_result
+    if hasattr(ptr._obj, 'graph'):
+        llinterp = _llinterp      # it's a global set here by CPU.__init__()
+        result = llinterp.eval_graph(ptr._obj.graph, args)
+        # ^^^ may raise, in which case we get an LLException
+    else:
+        result = ptr._obj._callable(*args)
     return result
 
 def do_call_void(f):
     _do_call_common(f)
 
 def do_call_int(f):
-    x = _do_call_common(f, 0)
+    x = _do_call_common(f)
     return cast_to_int(x)
 
 def do_call_float(f):
-    x = _do_call_common(f, 0)
+    x = _do_call_common(f)
     return cast_to_float(x)
 
 def do_call_ptr(f):
-    x = _do_call_common(f, lltype.nullptr(llmemory.GCREF.TO))
+    x = _do_call_common(f)
     return cast_to_ptr(x)
 
 def cast_call_args(ARGS, args_i, args_r, args_f):
@@ -1432,7 +1427,7 @@
             result = llinterp.eval_graph(mymethod.graph, myargs)
         else:
             result = meth(*args)
-    except LLException, e:
+    except XXX-LLException, e:
         _last_exception = e
         result = get_err_result_for_type(mymethod._TYPE.RESULT)
     return result

Modified: pypy/branch/blackhole-improvement/pypy/jit/backend/llgraph/runner.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/backend/llgraph/runner.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/backend/llgraph/runner.py	Tue Apr 27 15:31:25 2010
@@ -270,12 +270,6 @@
 
     # ----------
 
-    def get_exception(self):
-        return self.cast_adr_to_int(llimpl.get_exception())
-
-    def get_exc_value(self):
-        return llimpl.get_exc_value()
-
     def clear_exception(self):
         llimpl.clear_exception()
 

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	Tue Apr 27 15:31:25 2010
@@ -2,8 +2,9 @@
 from pypy.rlib.rarithmetic import intmask, LONG_BIT, r_uint
 from pypy.rlib.objectmodel import we_are_translated
 from pypy.tool.sourcetools import func_with_new_name
-from pypy.rpython.lltypesystem import lltype, llmemory
+from pypy.rpython.lltypesystem import lltype, llmemory, rclass
 from pypy.rpython.lltypesystem.lloperation import llop
+from pypy.rpython.llinterp import LLException
 from pypy.jit.codewriter.flatten import SwitchDictDescr
 
 
@@ -29,6 +30,7 @@
 
 
 class BlackholeInterpBuilder(object):
+    verbose = True
 
     def __init__(self, codewriter):
         self.cpu = codewriter.cpu
@@ -124,14 +126,27 @@
                 else:
                     raise AssertionError("bad argtype: %r" % (argtype,))
                 args += (value,)
+
+            if verbose and not we_are_translated():
+                print '\t', name, list(args),
+
             # call the method opimpl_xxx()
             try:
                 result = unboundmethod(self, *args)
-            except Exception:
+            except Exception, e:
+                if verbose and not we_are_translated():
+                    print '-> %s!' % (e.__class__.__name__,)
                 if resulttype == 'i' or resulttype == 'r' or resulttype == 'f':
                     position += 1
                 self.exception_pc = position
                 raise
+
+            if verbose and not we_are_translated():
+                if result is None:
+                    print
+                else:
+                    print '->', result
+
             if resulttype == 'i':
                 # argcode should be 'i' too
                 assert argcodes[next_argcode] == 'i'
@@ -161,6 +176,7 @@
             assert next_argcode == len(argcodes)
             return position
         #
+        verbose = self.verbose
         unboundmethod = getattr(BlackholeInterpreter, 'opimpl_' + name)
         argtypes = unrolling_iterable(unboundmethod.argtypes)
         resulttype = unboundmethod.resulttype
@@ -213,6 +229,9 @@
             #except JitException:
             #    ...
             except Exception, e:
+                if not we_are_translated():
+                    if not isinstance(e, LLException):
+                        raise
                 position = self.handle_exception_in_frame(e, code)
 
     def handle_exception_in_frame(self, e, code):
@@ -224,6 +243,8 @@
             raise e      # no 'catch_exception' insn follows: just reraise
         else:
             # else store the exception on 'self', and jump to the handler
+            if not we_are_translated():     # get the lltyped exception
+                e = e.args[1]               #   object out of the LLException
             self.exception_last_value = e
             target = ord(code[position+1]) | (ord(code[position+2])<<8)
             return target
@@ -342,6 +363,36 @@
         catch_exception, then the code in handle_exception_in_frame()
         will capture the exception and jump to 'target'."""
 
+    @arguments("i", "L", "pc", returns="L")
+    def opimpl_goto_if_exception_mismatch(self, vtable, target, pc):
+        adr = llmemory.cast_int_to_adr(vtable)
+        bounding_class = llmemory.cast_adr_to_ptr(adr, rclass.CLASSTYPE)
+        real_instance = self.exception_last_value
+        assert real_instance
+        if rclass.ll_issubclass(real_instance.typeptr, bounding_class):
+            return pc
+        else:
+            return target
+
+    @arguments(returns="i")
+    def opimpl_last_exception(self):
+        real_instance = self.exception_last_value
+        assert real_instance
+        adr = llmemory.cast_ptr_to_adr(real_instance.typeptr)
+        return llmemory.cast_adr_to_int(adr)
+
+    @arguments(returns="r")
+    def opimpl_last_exc_value(self):
+        real_instance = self.exception_last_value
+        assert real_instance
+        return lltype.cast_opaque_ptr(llmemory.GCREF, real_instance)
+
+    @arguments()
+    def opimpl_reraise(self):
+        real_instance = self.exception_last_value
+        assert real_instance
+        raise real_instance
+
     # ----------
     # the following operations are directly implemented by the backend
 

Modified: pypy/branch/blackhole-improvement/pypy/jit/metainterp/test/test_blackhole.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/metainterp/test/test_blackhole.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/metainterp/test/test_blackhole.py	Tue Apr 27 15:31:25 2010
@@ -3,6 +3,7 @@
 from pypy.jit.metainterp.blackhole import BlackholeInterpBuilder
 from pypy.jit.codewriter.assembler import JitCode
 from pypy.rpython.lltypesystem import lltype, llmemory
+from pypy.rpython.llinterp import LLException
 
 
 class FakeCodeWriter:
@@ -14,7 +15,7 @@
         assert func == 321
         assert calldescr == "<calldescr>"
         if args_i[0] < 0:
-            raise KeyError
+            raise LLException("etype", "evalue")
         return args_i[0] * 2
 
 def getblackholeinterp(insns, descrs=[]):



More information about the Pypy-commit mailing list