[pypy-svn] pypy lltrace: Checkin of in-progress changes.

arigo commits-noreply at bitbucket.org
Thu Feb 24 16:28:11 CET 2011


Author: Armin Rigo <arigo at tunes.org>
Branch: lltrace
Changeset: r42258:994df461b5d5
Date: 2011-02-24 15:33 +0100
http://bitbucket.org/pypy/pypy/changeset/994df461b5d5/

Log:	Checkin of in-progress changes.

diff --git a/pypy/jit/backend/x86/assembler.py b/pypy/jit/backend/x86/assembler.py
--- a/pypy/jit/backend/x86/assembler.py
+++ b/pypy/jit/backend/x86/assembler.py
@@ -1335,6 +1335,25 @@
         base_loc, ofs_loc, value_loc, size_loc, baseofs = arglocs
         assert isinstance(baseofs, ImmedLoc)
         assert isinstance(size_loc, ImmedLoc)
+        #
+        # XXX
+        if op.getopname() == 'setarrayitem_gc':
+            # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ but we may get
+            # it as a setarrayitem_raw!!!!!!  fix this
+            from pypy.jit.backend.llsupport.descr import BaseArrayDescr
+            arraydescr = op.getdescr()
+            assert isinstance(arraydescr, BaseArrayDescr)
+            ofs = arraydescr.get_ofs_length(self.cpu.translate_support_code)
+            self.mc.CMP(addr_add_const(base_loc, ofs), ofs_loc)
+            self.mc.J_il8(rx86.Conditions['A'], 0)
+            ja_location = self.mc.get_relative_pos()
+            self.mc.writechar(chr(0xCC))    # INT3
+            # patch the JA above
+            offset = self.mc.get_relative_pos() - ja_location
+            assert 0 < offset <= 127
+            self.mc.overwrite(ja_location-1, chr(offset))
+        # XXX
+        #
         scale = _get_scale(size_loc.value)
         dest_addr = AddressLoc(base_loc, ofs_loc, scale, baseofs.value)
         self.save_into_mem(dest_addr, value_loc, size_loc)

diff --git a/pypy/jit/backend/llsupport/llmodel.py b/pypy/jit/backend/llsupport/llmodel.py
--- a/pypy/jit/backend/llsupport/llmodel.py
+++ b/pypy/jit/backend/llsupport/llmodel.py
@@ -4,6 +4,7 @@
 from pypy.rpython.llinterp import LLInterpreter, LLException
 from pypy.rpython.annlowlevel import llhelper
 from pypy.rlib.objectmodel import we_are_translated, specialize
+from pypy.rlib.debug import ll_assert
 from pypy.jit.metainterp.history import BoxInt, BoxPtr, set_future_values,\
      BoxFloat
 from pypy.jit.metainterp import history
@@ -277,6 +278,13 @@
 
     # ____________________________________________________________
 
+    @specialize.argtype(2)
+    def _checkarraybound(self, arraydescr, array, itemindex):
+        if lltype.typeOf(array) == llmemory.GCREF:
+            length = self.bh_arraylen_gc(arraydescr, array)
+            ll_assert(0 <= itemindex < length,
+                      "bh_setarrayitem_gc: index out of bound")
+
     def bh_arraylen_gc(self, arraydescr, array):
         assert isinstance(arraydescr, BaseArrayDescr)
         ofs = arraydescr.get_ofs_length(self.translate_support_code)
@@ -284,6 +292,7 @@
 
     @specialize.argtype(2)
     def bh_getarrayitem_gc_i(self, arraydescr, gcref, itemindex):
+        self._checkarraybound(arraydescr, gcref, itemindex)
         ofs, size, sign = self.unpack_arraydescr_size(arraydescr)
         # --- start of GC unsafe code (no GC operation!) ---
         items = rffi.ptradd(rffi.cast(rffi.CCHARP, gcref), ofs)
@@ -303,6 +312,7 @@
             raise NotImplementedError("size = %d" % size)
 
     def bh_getarrayitem_gc_r(self, arraydescr, gcref, itemindex):
+        self._checkarraybound(arraydescr, gcref, itemindex)
         ofs = self.unpack_arraydescr(arraydescr)
         # --- start of GC unsafe code (no GC operation!) ---
         items = rffi.ptradd(rffi.cast(rffi.CCHARP, gcref), ofs)
@@ -313,6 +323,7 @@
 
     @specialize.argtype(2)
     def bh_getarrayitem_gc_f(self, arraydescr, gcref, itemindex):
+        self._checkarraybound(arraydescr, gcref, itemindex)
         ofs = self.unpack_arraydescr(arraydescr)
         # --- start of GC unsafe code (no GC operation!) ---
         items = rffi.ptradd(rffi.cast(rffi.CCHARP, gcref), ofs)
@@ -323,6 +334,7 @@
 
     @specialize.argtype(2)
     def bh_setarrayitem_gc_i(self, arraydescr, gcref, itemindex, newvalue):
+        self._checkarraybound(arraydescr, gcref, itemindex)
         ofs, size, sign = self.unpack_arraydescr_size(arraydescr)
         # --- start of GC unsafe code (no GC operation!) ---
         items = rffi.ptradd(rffi.cast(rffi.CCHARP, gcref), ofs)
@@ -339,6 +351,7 @@
             raise NotImplementedError("size = %d" % size)
 
     def bh_setarrayitem_gc_r(self, arraydescr, gcref, itemindex, newvalue):
+        self._checkarraybound(arraydescr, gcref, itemindex)
         ofs = self.unpack_arraydescr(arraydescr)
         self.gc_ll_descr.do_write_barrier(gcref, newvalue)
         # --- start of GC unsafe code (no GC operation!) ---
@@ -351,6 +364,7 @@
 
     @specialize.argtype(2)
     def bh_setarrayitem_gc_f(self, arraydescr, gcref, itemindex, newvalue):
+        self._checkarraybound(arraydescr, gcref, itemindex)
         ofs = self.unpack_arraydescr(arraydescr)
         # --- start of GC unsafe code (no GC operation!) ---
         items = rffi.ptradd(rffi.cast(rffi.CCHARP, gcref), ofs)


More information about the Pypy-commit mailing list