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

arigo at codespeak.net arigo at codespeak.net
Fri May 28 13:52:19 CEST 2010


Author: arigo
Date: Fri May 28 13:52:17 2010
New Revision: 74845

Modified:
   pypy/branch/blackhole-improvement/pypy/jit/backend/llgraph/llimpl.py
   pypy/branch/blackhole-improvement/pypy/jit/codewriter/heaptracker.py
   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/pyjitpl.py
   pypy/branch/blackhole-improvement/pypy/jit/metainterp/resume.py
   pypy/branch/blackhole-improvement/pypy/jit/metainterp/test/test_ztranslation.py
Log:
Translation fixes (step 1).


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	Fri May 28 13:52:17 2010
@@ -1496,8 +1496,10 @@
 setannotation(frame_int_getvalue, annmodel.SomeInteger())
 setannotation(frame_ptr_getvalue, annmodel.SomePtr(llmemory.GCREF))
 setannotation(frame_float_getvalue, annmodel.SomeFloat())
+setannotation(frame_get_value_count, annmodel.SomeInteger())
+setannotation(frame_clear_latest_values, annmodel.s_None)
 
-setannotation(grab_exc_value, annmodel.SomePtr(llmemory.GCREF))
+setannotation(grab_exc_value, annmodel.SomePtr(rclass.OBJECTPTR))
 setannotation(force, annmodel.SomeInteger())
 setannotation(get_forced_token_frame, s_Frame)
 setannotation(get_frame_forced_token, annmodel.SomeAddress())

Modified: pypy/branch/blackhole-improvement/pypy/jit/codewriter/heaptracker.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/codewriter/heaptracker.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/codewriter/heaptracker.py	Fri May 28 13:52:17 2010
@@ -46,9 +46,10 @@
         assert sizedescr._corresponding_vtable == vtable
     else:
         assert lltype.typeOf(vtable) == VTABLETYPE
-        if not hasattr(cpu, '_all_size_descrs'):
-            cpu._all_size_descrs = []
-        cpu._all_size_descrs.append(sizedescr)
+        if not hasattr(cpu, '_all_size_descrs_with_vtable'):
+            cpu._all_size_descrs_with_vtable = []
+            cpu._vtable_to_descr_dict = None
+        cpu._all_size_descrs_with_vtable.append(sizedescr)
         sizedescr._corresponding_vtable = vtable
 
 def vtable2descr(cpu, vtable):
@@ -59,9 +60,14 @@
         # Build the dict {vtable: sizedescr} at runtime.
         # This is necessary because the 'vtables' are just pointers to
         # static data, so they can't be used as keys in prebuilt dicts.
-        XXX
+        d = cpu._vtable_to_descr_dict
+        if d is None:
+            d = cpu._vtable_to_descr_dict = {}
+            for descr in cpu._all_size_descrs_with_vtable:
+                d[descr._corresponding_vtable] = descr
+        return d[vtable]
     else:
-        for descr in cpu._all_size_descrs:
+        for descr in cpu._all_size_descrs_with_vtable:
             if descr._corresponding_vtable == vtable:
                 return descr
         raise KeyError(vtable)

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 13:52:17 2010
@@ -6,6 +6,7 @@
 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
 
@@ -40,7 +41,7 @@
 
 def get_llexception(cpu, e):
     if we_are_translated():
-        return XXX(e)
+        return cast_instance_to_base_ptr(e)
     if isinstance(e, LLException):
         return e.args[1]    # ok
     if isinstance(e, OverflowError):
@@ -376,7 +377,6 @@
             etype = rclass.ll_type(e)
             raise LLException(etype, e)
 
-    # XXX must be specialized
     def copy_constants(self, registers, constants):
         """Copy jitcode.constants[0] to registers[255],
                 jitcode.constants[1] to registers[254],
@@ -389,6 +389,7 @@
             assert j >= 0
             registers[j] = constants[i]
             i -= 1
+    copy_constants._annspecialcase_ = 'specialize:arglistitemtype(1)'
 
     # ----------
 
@@ -1172,6 +1173,7 @@
     # helpers to resume running in blackhole mode when a guard failed
 
     def _resume_mainloop(self, current_exc):
+        assert lltype.typeOf(current_exc) == rclass.OBJECTPTR
         try:
             # if there is a current exception, raise it now
             # (it may be caught by a catch_operation in this frame)
@@ -1201,7 +1203,7 @@
             caller._setup_return_value_f(self.final_result_f())
         else:
             assert kind == 'v'
-        return NULL
+        return lltype.nullptr(rclass.OBJECTPTR.TO)
 
     def _prepare_resume_from_failure(self, opnum):
         from pypy.jit.metainterp.resoperation import rop
@@ -1248,7 +1250,7 @@
         else:
             from pypy.jit.metainterp.resoperation import opname
             raise NotImplementedError(opname[opnum])
-        return NULL
+        return lltype.nullptr(rclass.OBJECTPTR.TO)
 
     # connect the return of values from the called frame to the
     # 'xxx_call_yyy' instructions from the caller frame
@@ -1298,7 +1300,6 @@
 # ____________________________________________________________
 
 def _run_forever(blackholeinterp, current_exc):
-    current_exc = lltype.cast_opaque_ptr(rclass.OBJECTPTR, current_exc)
     while True:
         current_exc = blackholeinterp._resume_mainloop(current_exc)
         blackholeinterp = blackholeinterp.nextblackholeinterp
@@ -1319,7 +1320,7 @@
         metainterp_sd.profiler.end_blackhole()
         debug_stop('jit-blackhole')
 
-def convert_and_run_from_pyjitpl(metainterp, current_exc=NULL):
+def convert_and_run_from_pyjitpl(metainterp):
     # Get a chain of blackhole interpreters and fill them by copying
     # 'metainterp.framestack'.  Note that the order is important: the
     # first one we get must be the bottom one, in order to make
@@ -1335,6 +1336,11 @@
         nextbh = curbh
     firstbh = nextbh
     #
+    if metainterp.last_exc_value_box is not None:
+        current_exc = metainterp.last_exc_value_box.getref(rclass.OBJECTPTR)
+    else:
+        current_exc = lltype.nullptr(rclass.OBJECTPTR.TO)
+    #
     try:
         _run_forever(firstbh, current_exc)
     finally:

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 13:52:17 2010
@@ -349,14 +349,14 @@
     func = get_execute_function(opnum, len(argboxes))
     return func(cpu, metainterp, *argboxes)  # note that the 'argboxes' tuple
                                              # optionally ends with the descr
-execute._annspecialcase_ = 'specialize:arg(1)'
+execute._annspecialcase_ = 'specialize:arg(2)'
 
 def execute_varargs(cpu, metainterp, opnum, argboxes, descr):
     # only for opnums with a variable arity (calls, typically)
     check_descr(descr)
     func = get_execute_function(opnum, -1)
     return func(cpu, metainterp, argboxes, descr)
-execute_varargs._annspecialcase_ = 'specialize:arg(1)'
+execute_varargs._annspecialcase_ = 'specialize:arg(2)'
 
 
 def execute_nonspec(cpu, metainterp, opnum, argboxes, descr=None):

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 13:52:17 2010
@@ -1,6 +1,5 @@
 import py, os
 from pypy.rpython.lltypesystem import lltype, llmemory
-from pypy.rpython.llinterp import LLException
 from pypy.rlib.objectmodel import we_are_translated
 from pypy.rlib.unroll import unrolling_iterable
 from pypy.rlib.debug import debug_start, debug_stop, debug_print
@@ -29,12 +28,6 @@
         return func
     return decorate
 
-class FixME:      # XXX marks deprecated ootype-only operations
-    def __init__(self, func):
-        self.func = func
-    def __getattr__(self, _):
-        raise Exception("@FixME: " + self.func.__name__)
-
 # ____________________________________________________________
 
 
@@ -94,6 +87,7 @@
             if   argcode == 'I': reg = self.registers_i[index]
             elif argcode == 'R': reg = self.registers_r[index]
             elif argcode == 'F': reg = self.registers_f[index]
+            else: raise AssertionError(argcode)
             outvalue[startindex+i] = reg
     prepare_list_of_boxes._annspecialcase_ = 'specialize:arg(4)'
 
@@ -336,20 +330,20 @@
         cls = heaptracker.descr2vtable(cpu, sizedescr)
         return self.execute(rop.NEW_WITH_VTABLE, ConstInt(cls))
 
-    @FixME  #arguments("box")
-    def opimpl_runtimenew(self, classbox):
-        self.execute(rop.RUNTIMENEW, classbox)
-
-    @FixME  #arguments("orgpc", "box", "descr")
-    def opimpl_instanceof(self, pc, objbox, typedescr):
-        clsbox = self.cls_of_box(objbox)
-        if isinstance(objbox, Box):
-            self.generate_guard(pc, rop.GUARD_CLASS, objbox, [clsbox])
-        self.execute_with_descr(rop.INSTANCEOF, typedescr, objbox)
-
-    @FixME  #arguments("box", "box")
-    def opimpl_subclassof(self, box1, box2):
-        self.execute(rop.SUBCLASSOF, box1, box2)
+##    @FixME  #arguments("box")
+##    def opimpl_runtimenew(self, classbox):
+##        self.execute(rop.RUNTIMENEW, classbox)
+
+##    @FixME  #arguments("orgpc", "box", "descr")
+##    def opimpl_instanceof(self, pc, objbox, typedescr):
+##        clsbox = self.cls_of_box(objbox)
+##        if isinstance(objbox, Box):
+##            self.generate_guard(pc, rop.GUARD_CLASS, objbox, [clsbox])
+##        self.execute_with_descr(rop.INSTANCEOF, typedescr, objbox)
+
+##    @FixME  #arguments("box", "box")
+##    def opimpl_subclassof(self, box1, box2):
+##        self.execute(rop.SUBCLASSOF, box1, box2)
 
     @arguments("descr", "box")
     def opimpl_new_array(self, itemsizedescr, countbox):
@@ -678,21 +672,21 @@
     opimpl_recursive_call_f = _opimpl_recursive_call
     opimpl_recursive_call_v = _opimpl_recursive_call
 
-    @FixME  #arguments("orgpc", "methdescr", "varargs")
-    def opimpl_oosend(self, pc, methdescr, varargs):
-        objbox = varargs[0]
-        clsbox = self.cls_of_box(objbox)
-        if isinstance(objbox, Box):
-            self.generate_guard(pc, rop.GUARD_CLASS, objbox, [clsbox])
-        oocls = clsbox.getref(ootype.Class)
-        jitcode = methdescr.get_jitcode_for_class(oocls)
-        if jitcode is not None:
-            # we should follow calls to this graph
-            return self.perform_call(jitcode, varargs)
-        else:
-            # but we should not follow calls to that graph
-            return self.execute_varargs(rop.OOSEND, varargs,
-                                        descr=methdescr, exc=True)
+##    @FixME  #arguments("orgpc", "methdescr", "varargs")
+##    def opimpl_oosend(self, pc, methdescr, varargs):
+##        objbox = varargs[0]
+##        clsbox = self.cls_of_box(objbox)
+##        if isinstance(objbox, Box):
+##            self.generate_guard(pc, rop.GUARD_CLASS, objbox, [clsbox])
+##        oocls = clsbox.getref(ootype.Class)
+##        jitcode = methdescr.get_jitcode_for_class(oocls)
+##        if jitcode is not None:
+##            # we should follow calls to this graph
+##            return self.perform_call(jitcode, varargs)
+##        else:
+##            # but we should not follow calls to that graph
+##            return self.execute_varargs(rop.OOSEND, varargs,
+##                                        descr=methdescr, exc=True)
 
     @arguments("box")
     def opimpl_strlen(self, strbox):
@@ -726,20 +720,20 @@
     def opimpl_newunicode(self, lengthbox):
         return self.execute(rop.NEWUNICODE, lengthbox)
 
-    @FixME  #arguments("descr", "varargs")
-    def opimpl_residual_oosend_canraise(self, methdescr, varargs):
-        return self.execute_varargs(rop.OOSEND, varargs, descr=methdescr,
-                                    exc=True)
-
-    @FixME  #arguments("descr", "varargs")
-    def opimpl_residual_oosend_noraise(self, methdescr, varargs):
-        return self.execute_varargs(rop.OOSEND, varargs, descr=methdescr,
-                                    exc=False)
-
-    @FixME  #arguments("descr", "varargs")
-    def opimpl_residual_oosend_pure(self, methdescr, boxes):
-        return self.execute_varargs(rop.OOSEND_PURE, boxes, descr=methdescr,
-                                    exc=False)
+##    @FixME  #arguments("descr", "varargs")
+##    def opimpl_residual_oosend_canraise(self, methdescr, varargs):
+##        return self.execute_varargs(rop.OOSEND, varargs, descr=methdescr,
+##                                    exc=True)
+
+##    @FixME  #arguments("descr", "varargs")
+##    def opimpl_residual_oosend_noraise(self, methdescr, varargs):
+##        return self.execute_varargs(rop.OOSEND, varargs, descr=methdescr,
+##                                    exc=False)
+
+##    @FixME  #arguments("descr", "varargs")
+##    def opimpl_residual_oosend_pure(self, methdescr, boxes):
+##        return self.execute_varargs(rop.OOSEND_PURE, boxes, descr=methdescr,
+##                                    exc=False)
 
     @arguments("orgpc", "box",)
     def _opimpl_guard_value(self, orgpc, box):
@@ -1420,12 +1414,15 @@
             op.name = self.framestack[-1].jitcode.name
 
     def execute_raised(self, exception, constant=False):
+        llexception = get_llexception(self.cpu, exception)
+        self.execute_ll_raised(llexception, constant)
+
+    def execute_ll_raised(self, llexception, constant=False):
         # Exception handling: when execute.do_call() gets an exception it
         # calls metainterp.execute_raised(), which puts it into
         # 'self.last_exc_value_box'.  This is used shortly afterwards
         # to generate either GUARD_EXCEPTION or GUARD_NO_EXCEPTION, and also
         # to handle the following opcodes 'goto_if_exception_mismatch'.
-        llexception = get_llexception(self.cpu, exception)
         llexception = self.cpu.ts.cast_to_ref(llexception)
         exc_value_box = self.cpu.ts.get_exc_value_box(llexception)
         if constant:
@@ -1540,10 +1537,7 @@
         # run it.
         from pypy.jit.metainterp.blackhole import convert_and_run_from_pyjitpl
         self.aborted_tracing(stb.reason)
-        current_exc = lltype.nullptr(llmemory.GCREF.TO)
-        if self.last_exc_value_box is not None:
-            current_exc = self.last_exc_value_box.getref()
-        convert_and_run_from_pyjitpl(self, current_exc)
+        convert_and_run_from_pyjitpl(self)
         assert False    # ^^^ must raise
 
     def remove_consts_and_duplicates(self, boxes, endindex, duplicates):
@@ -1632,11 +1626,7 @@
         elif opnum == rop.GUARD_NO_EXCEPTION or opnum == rop.GUARD_EXCEPTION:
             exception = self.cpu.grab_exc_value()
             if exception:
-                if not we_are_translated():
-                    from pypy.rpython.lltypesystem import rclass
-                    etype = rclass.ll_type(exception)
-                    exception = LLException(etype, exception)
-                self.execute_raised(exception)
+                self.execute_ll_raised(exception)
             else:
                 self.execute_did_not_raise()
             try:

Modified: pypy/branch/blackhole-improvement/pypy/jit/metainterp/resume.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/metainterp/resume.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/metainterp/resume.py	Fri May 28 13:52:17 2010
@@ -4,7 +4,7 @@
 from pypy.jit.metainterp.history import INT, REF, FLOAT, HOLE
 from pypy.jit.metainterp.resoperation import rop
 from pypy.jit.metainterp import jitprof
-from pypy.rpython.lltypesystem import lltype, rffi
+from pypy.rpython.lltypesystem import lltype, llmemory, rffi
 from pypy.rlib import rarithmetic
 from pypy.rlib.objectmodel import we_are_translated, specialize
 from pypy.rlib.debug import have_debug_prints
@@ -497,6 +497,7 @@
     """
     _mixin_ = True
     virtuals = None
+    virtual_default = None
 
     def _init(self, cpu, storage):
         self.cpu = cpu
@@ -509,7 +510,7 @@
 
     def _prepare_virtuals(self, virtuals):
         if virtuals:
-            self.virtuals = [None] * len(virtuals)
+            self.virtuals = [self.virtual_default] * len(virtuals)
             for i in range(len(virtuals)):
                 vinfo = virtuals[i]
                 if vinfo is not None:
@@ -751,6 +752,7 @@
     return resumereader.virtuals
 
 class ResumeDataDirectReader(AbstractResumeDataReader):
+    virtual_default = lltype.nullptr(llmemory.GCREF.TO)
     resume_after_guard_not_forced = 0
     #             0: not a GUARD_NOT_FORCED
     #             1: in handle_async_forcing

Modified: pypy/branch/blackhole-improvement/pypy/jit/metainterp/test/test_ztranslation.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/metainterp/test/test_ztranslation.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/jit/metainterp/test/test_ztranslation.py	Fri May 28 13:52:17 2010
@@ -5,7 +5,6 @@
 from pypy.rlib.jit import PARAMETERS, dont_look_inside
 from pypy.jit.metainterp.jitprof import Profiler
 from pypy.rpython.lltypesystem import lltype, llmemory
-from pypy.rpython.ootypesystem import ootype
 
 class TranslationTest:
 
@@ -40,7 +39,7 @@
         def can_inline():
             return False
 
-        jitdriver = JitDriver(greens = [], reds = ['frame', 'total'],
+        jitdriver = JitDriver(greens = [], reds = ['total', 'frame'],
                               virtualizables = ['frame'],
                               get_jitcell_at=get_jitcell_at,
                               set_jitcell_at=set_jitcell_at,



More information about the Pypy-commit mailing list