[pypy-svn] r71296 - in pypy/branch/jit-profiling-debug-vref/pypy: jit/backend jit/backend/x86 jit/metainterp rpython/lltypesystem rpython/memory/gc translator/c translator/c/src

arigo at codespeak.net arigo at codespeak.net
Thu Feb 18 16:15:46 CET 2010


Author: arigo
Date: Thu Feb 18 16:15:44 2010
New Revision: 71296

Modified:
   pypy/branch/jit-profiling-debug-vref/pypy/jit/backend/model.py
   pypy/branch/jit-profiling-debug-vref/pypy/jit/backend/x86/assembler.py
   pypy/branch/jit-profiling-debug-vref/pypy/jit/backend/x86/regalloc.py
   pypy/branch/jit-profiling-debug-vref/pypy/jit/metainterp/optimizeopt.py
   pypy/branch/jit-profiling-debug-vref/pypy/jit/metainterp/resoperation.py
   pypy/branch/jit-profiling-debug-vref/pypy/jit/metainterp/virtualref.py
   pypy/branch/jit-profiling-debug-vref/pypy/rpython/lltypesystem/rclass.py
   pypy/branch/jit-profiling-debug-vref/pypy/rpython/memory/gc/base.py
   pypy/branch/jit-profiling-debug-vref/pypy/translator/c/funcgen.py
   pypy/branch/jit-profiling-debug-vref/pypy/translator/c/src/mem.h
   pypy/branch/jit-profiling-debug-vref/pypy/translator/c/src/support.h
Log:
Merge with branch/debug-vref.


Modified: pypy/branch/jit-profiling-debug-vref/pypy/jit/backend/model.py
==============================================================================
--- pypy/branch/jit-profiling-debug-vref/pypy/jit/backend/model.py	(original)
+++ pypy/branch/jit-profiling-debug-vref/pypy/jit/backend/model.py	Thu Feb 18 16:15:44 2010
@@ -222,6 +222,9 @@
     def do_call_may_force(self, args, calldescr):
         return self.do_call(args, calldescr)
 
+    def do_assert(self, xbox):
+        assert xbox.nonnull()
+
     def force(self, force_token):
         raise NotImplementedError
 

Modified: pypy/branch/jit-profiling-debug-vref/pypy/jit/backend/x86/assembler.py
==============================================================================
--- pypy/branch/jit-profiling-debug-vref/pypy/jit/backend/x86/assembler.py	(original)
+++ pypy/branch/jit-profiling-debug-vref/pypy/jit/backend/x86/assembler.py	Thu Feb 18 16:15:44 2010
@@ -588,6 +588,18 @@
     genop_cast_ptr_to_int = genop_same_as
     genop_virtual_ref = genop_same_as
 
+    def genop_assert(self, op, arglocs, resloc):
+        mc = self._start_block()
+        mc.CMP(arglocs[0], imm8(0))
+        mc.write(constlistofchars('\x75\x00'))             # JNE later
+        jne_location = mc.get_relative_pos()
+        mc.UD2()
+        # patch the JNE above
+        offset = mc.get_relative_pos() - jne_location
+        assert 0 < offset <= 127
+        mc.overwrite(jne_location-1, [chr(offset)])
+        self._stop_block()
+
     def genop_int_mod(self, op, arglocs, resloc):
         self.mc.CDQ()
         self.mc.IDIV(ecx)

Modified: pypy/branch/jit-profiling-debug-vref/pypy/jit/backend/x86/regalloc.py
==============================================================================
--- pypy/branch/jit-profiling-debug-vref/pypy/jit/backend/x86/regalloc.py	(original)
+++ pypy/branch/jit-profiling-debug-vref/pypy/jit/backend/x86/regalloc.py	Thu Feb 18 16:15:44 2010
@@ -865,6 +865,11 @@
         else:
             self.consider_int_neg(op)
 
+    def consider_assert(self, op):
+        argloc = self.loc(op.args[0])
+        self.Perform(op, [argloc], None)
+        self.rm.possibly_free_var(op.args[0])
+
     def consider_same_as(self, op):
         argloc = self.loc(op.args[0])
         self.possibly_free_var(op.args[0])

Modified: pypy/branch/jit-profiling-debug-vref/pypy/jit/metainterp/optimizeopt.py
==============================================================================
--- pypy/branch/jit-profiling-debug-vref/pypy/jit/metainterp/optimizeopt.py	(original)
+++ pypy/branch/jit-profiling-debug-vref/pypy/jit/metainterp/optimizeopt.py	Thu Feb 18 16:15:44 2010
@@ -768,6 +768,9 @@
         # typically a PyPy PyFrame, and now is the end of its execution, so
         # forcing it now does not have catastrophic effects.
         vrefinfo = self.metainterp_sd.virtualref_info
+        # - write code to check that op.args[1] is not null
+        op1 = ResOperation(rop.ASSERT, [op.args[1]], None)
+        self.emit_operation(op1)
         # - set 'forced' to point to the real object
         op1 = ResOperation(rop.SETFIELD_GC, op.args, None,
                           descr = vrefinfo.descr_forced)
@@ -777,6 +780,11 @@
         op1 = ResOperation(rop.SETFIELD_GC, args, None,
                       descr = vrefinfo.descr_virtual_token)
         self.optimize_SETFIELD_GC(op1)
+        # - set debug stuff
+        args = [op.args[0], ConstInt(120)]
+        op1 = ResOperation(rop.SETFIELD_GC, args, None,
+                      descr = vrefinfo.descr_debug_from)
+        self.optimize_SETFIELD_GC(op1)
         # Note that in some cases the virtual in op.args[1] has been forced
         # already.  This is fine.  In that case, and *if* a residual
         # CALL_MAY_FORCE suddenly turns out to access it, then it will

Modified: pypy/branch/jit-profiling-debug-vref/pypy/jit/metainterp/resoperation.py
==============================================================================
--- pypy/branch/jit-profiling-debug-vref/pypy/jit/metainterp/resoperation.py	(original)
+++ pypy/branch/jit-profiling-debug-vref/pypy/jit/metainterp/resoperation.py	Thu Feb 18 16:15:44 2010
@@ -222,6 +222,7 @@
                             #        => result          (for mallocs)
     'DEBUG_MERGE_POINT/1',      # debugging only
     'VIRTUAL_REF_FINISH/2',
+    'ASSERT/1',
 
     '_CANRAISE_FIRST', # ----- start of can_raise operations -----
     'CALL',

Modified: pypy/branch/jit-profiling-debug-vref/pypy/jit/metainterp/virtualref.py
==============================================================================
--- pypy/branch/jit-profiling-debug-vref/pypy/jit/metainterp/virtualref.py	(original)
+++ pypy/branch/jit-profiling-debug-vref/pypy/jit/metainterp/virtualref.py	Thu Feb 18 16:15:44 2010
@@ -13,7 +13,9 @@
             ('super', rclass.OBJECT),
             ('virtual_token', lltype.Signed),
             ('virtualref_index', lltype.Signed),
-            ('forced', rclass.OBJECTPTR))
+            ('forced', rclass.OBJECTPTR),
+            ('debug_from', lltype.Signed),
+            ('debug_setforced', rclass.OBJECTPTR))
         self.jit_virtual_ref_vtable = lltype.malloc(rclass.OBJECT_VTABLE,
                                                     zero=True, flavor='raw')
         self.jit_virtual_ref_vtable.name = rclass.alloc_array_name(
@@ -27,6 +29,10 @@
         self.descr_virtualref_index = fielddescrof(self.JIT_VIRTUAL_REF,
                                                    'virtualref_index')
         self.descr_forced = fielddescrof(self.JIT_VIRTUAL_REF, 'forced')
+        self.descr_debug_from = fielddescrof(self.JIT_VIRTUAL_REF,
+                                             'debug_from')
+        self.descr_debug_setforced = fielddescrof(self.JIT_VIRTUAL_REF,
+                                                  'debug_setforced')
 
     def _freeze_(self):
         return True
@@ -73,6 +79,7 @@
         p.typeptr = self.jit_virtual_ref_vtable
         vref.virtual_token = self.TOKEN_NONE
         vref.forced = lltype.cast_opaque_ptr(rclass.OBJECTPTR, real_object)
+        vref.debug_from = 100
         return lltype.cast_opaque_ptr(llmemory.GCREF, vref)
 
     def is_virtual_ref(self, gcref):
@@ -87,6 +94,7 @@
         vref = lltype.cast_opaque_ptr(lltype.Ptr(self.JIT_VIRTUAL_REF), gcref)
         assert not vref.virtual_token
         vref.virtual_token = self.TOKEN_TRACING_RESCALL
+        vref.debug_from = 101
 
     def tracing_after_residual_call(self, gcref):
         if not self.is_virtual_ref(gcref):
@@ -97,6 +105,8 @@
             # set to TOKEN_TRACING_RESCALL and clear it.
             assert vref.virtual_token == self.TOKEN_TRACING_RESCALL
             vref.virtual_token = self.TOKEN_NONE
+            vref.debug_from = 102
+            vref.debug_setforced = vref.forced
             return False
         else:
             # marker "modified during residual call" set.
@@ -111,6 +121,8 @@
                 vref.virtual_token != self.TOKEN_TRACING_RESCALL)
         vref.virtual_token = self.TOKEN_NONE
         vref.forced = lltype.cast_opaque_ptr(rclass.OBJECTPTR, real_object)
+        vref.debug_from = 103
+        vref.debug_setforced = vref.forced
 
     def continue_tracing(self, gcref, real_object):
         if not self.is_virtual_ref(gcref):
@@ -119,6 +131,8 @@
         assert vref.virtual_token != self.TOKEN_TRACING_RESCALL
         vref.virtual_token = self.TOKEN_NONE
         vref.forced = lltype.cast_opaque_ptr(rclass.OBJECTPTR, real_object)
+        vref.debug_from = 104
+        vref.debug_setforced = vref.forced
 
     # ____________________________________________________________
 
@@ -145,11 +159,17 @@
                 # as a marker for the tracing, to tell it that this
                 # "virtual" escapes.
                 vref.virtual_token = self.TOKEN_NONE
+                vref.debug_from = 110
             else:
                 assert not vref.forced
                 from pypy.jit.metainterp.compile import ResumeGuardForcedDescr
                 ResumeGuardForcedDescr.force_now(self.cpu, token)
                 assert vref.virtual_token == self.TOKEN_NONE
-        assert vref.forced
+                assert vref.forced
+                vref.debug_from = 111
+        else:
+            assert vref.forced
+            vref.debug_from = 112
+        vref.debug_setforced = vref.forced
         return vref.forced
     force_virtual._dont_inline_ = True

Modified: pypy/branch/jit-profiling-debug-vref/pypy/rpython/lltypesystem/rclass.py
==============================================================================
--- pypy/branch/jit-profiling-debug-vref/pypy/rpython/lltypesystem/rclass.py	(original)
+++ pypy/branch/jit-profiling-debug-vref/pypy/rpython/lltypesystem/rclass.py	Thu Feb 18 16:15:44 2010
@@ -62,6 +62,7 @@
                            'typeptr': True})
 OBJECTPTR = Ptr(OBJECT)
 OBJECT_VTABLE.become(Struct('object_vtable',
+                            ('debug_minusfortytwo', Signed),
                             #('parenttypeptr', CLASSTYPE),
                             ('subclassrange_min', Signed),
                             ('subclassrange_max', Signed),
@@ -184,6 +185,7 @@
         given subclass."""
         if self.classdef is None:
             # initialize the 'subclassrange_*' and 'name' fields
+            vtable.debug_minusfortytwo = -42
             if rsubcls.classdef is not None:
                 #vtable.parenttypeptr = rsubcls.rbase.getvtable()
                 vtable.subclassrange_min = rsubcls.classdef.minid

Modified: pypy/branch/jit-profiling-debug-vref/pypy/rpython/memory/gc/base.py
==============================================================================
--- pypy/branch/jit-profiling-debug-vref/pypy/rpython/memory/gc/base.py	(original)
+++ pypy/branch/jit-profiling-debug-vref/pypy/rpython/memory/gc/base.py	Thu Feb 18 16:15:44 2010
@@ -43,7 +43,7 @@
     # collection.  It is automatically set to True by test_gc.py.  The
     # checking logic is translatable, so the flag can be set to True
     # here before translation.
-    DEBUG = False
+    DEBUG = True
 
     def set_query_functions(self, is_varsize, has_gcptr_in_varsize,
                             is_gcarrayofgcptr,
@@ -225,6 +225,8 @@
             self._debug_pending.delete()
 
     def _debug_record(self, obj):
+        tid = self.header(obj).tid
+        ll_assert(0 < tid <= 0x7FFFFFF, "not a GC pointer!!!!!")
         seen = self._debug_seen
         if not seen.contains(obj):
             seen.add(obj)

Modified: pypy/branch/jit-profiling-debug-vref/pypy/translator/c/funcgen.py
==============================================================================
--- pypy/branch/jit-profiling-debug-vref/pypy/translator/c/funcgen.py	(original)
+++ pypy/branch/jit-profiling-debug-vref/pypy/translator/c/funcgen.py	Thu Feb 18 16:15:44 2010
@@ -465,19 +465,21 @@
     def generic_get(self, op, sourceexpr):
         T = self.lltypemap(op.result)
         newvalue = self.expr(op.result, special_case_void=False)
-        result = ['%s = %s;' % (newvalue, sourceexpr)]
-        result = '\n'.join(result)
+        result = '%s = %s;' % (newvalue, sourceexpr)
         if T is Void:
             result = '/* %s */' % result
+        elif isinstance(T, Ptr) and T.TO._gckind == 'gc':
+            result = '%s RPyValidPtr(%s);' % (result, newvalue)
         return result
 
     def generic_set(self, op, targetexpr):
         newvalue = self.expr(op.args[-1], special_case_void=False)
-        result = ['%s = %s;' % (targetexpr, newvalue)]
+        result = '%s = %s;' % (targetexpr, newvalue)
         T = self.lltypemap(op.args[-1])
-        result = '\n'.join(result)
         if T is Void:
             result = '/* %s */' % result
+        elif isinstance(T, Ptr) and T.TO._gckind == 'gc':
+            result = 'RPyValidPtr(%s); %s' % (newvalue, result)
         return result
 
     def OP_GETFIELD(self, op, ampersand=''):

Modified: pypy/branch/jit-profiling-debug-vref/pypy/translator/c/src/mem.h
==============================================================================
--- pypy/branch/jit-profiling-debug-vref/pypy/translator/c/src/mem.h	(original)
+++ pypy/branch/jit-profiling-debug-vref/pypy/translator/c/src/mem.h	Thu Feb 18 16:15:44 2010
@@ -95,7 +95,7 @@
 
 #endif
 
-#define OP_RAW_FREE(p, r) PyObject_Free(p); COUNT_FREE;
+#define OP_RAW_FREE(p, r) *(int*)p = -0x22222223; PyObject_Free(p);   /* 0xdddddddd */
 
 #define OP_RAW_MEMCLEAR(p, size, r) memset((void*)p, 0, size)
 

Modified: pypy/branch/jit-profiling-debug-vref/pypy/translator/c/src/support.h
==============================================================================
--- pypy/branch/jit-profiling-debug-vref/pypy/translator/c/src/support.h	(original)
+++ pypy/branch/jit-profiling-debug-vref/pypy/translator/c/src/support.h	Thu Feb 18 16:15:44 2010
@@ -74,6 +74,7 @@
  * attackers.
  */
 #  define RPyCHECK(x)           ((x) || RPyAbort())
+#  define RPyValidPtr(x)  ((!(x))||(unsigned int)(((*(unsigned int*)(x))-1)<0x7FFFFFF)||RPyAbort())
 #  define RPyField(ptr, name)   ((RPyCHECK(ptr), (ptr))->name)
 #  define RPyItem(array, index)                                             \
      ((RPyCHECK((index) >= 0 && (index) < (array)->length),                 \
@@ -96,6 +97,7 @@
 #endif
 
 #else
+#  define RPyValidPtr(x)                     /* nothing */
 #  define RPyField(ptr, name)                ((ptr)->name)
 #  define RPyItem(array, index)              ((array)->items[index])
 #  define RPyFxItem(ptr, index, fixedsize)   ((ptr)[index])



More information about the Pypy-commit mailing list