Author: Maciej Fijalkowski <[email protected]>
Branch: jitframe-on-heap
Changeset: r60142:0d6f2ebbb86c
Date: 2013-01-17 21:56 +0200
http://bitbucket.org/pypy/pypy/changeset/0d6f2ebbb86c/

Log:    fix maybe? for now commit with debug checks

diff --git a/pypy/jit/backend/llsupport/gc.py b/pypy/jit/backend/llsupport/gc.py
--- a/pypy/jit/backend/llsupport/gc.py
+++ b/pypy/jit/backend/llsupport/gc.py
@@ -118,10 +118,12 @@
         descrs = JitFrameDescrs()
         descrs.arraydescr = cpu.arraydescrof(jitframe.JITFRAME)
         for name in ['jf_descr', 'jf_guard_exc', 'jf_force_descr',
-                     'jf_frame_info', 'jf_gcpattern']:
+                     'jf_frame_info', 'jf_gcpattern', 'jf_gcmap']:
             setattr(descrs, name, cpu.fielddescrof(jitframe.JITFRAME, name))
         descrs.jfi_frame_depth = cpu.fielddescrof(jitframe.JITFRAMEINFO,
                                                   'jfi_frame_depth')
+        descrs.jfi_gcmap = cpu.fielddescrof(jitframe.JITFRAMEINFO,
+                                            'jfi_gcmap')
         return descrs
 
     def getarraydescr_for_frame(self, type, index):
diff --git a/pypy/jit/backend/llsupport/jitframe.py 
b/pypy/jit/backend/llsupport/jitframe.py
--- a/pypy/jit/backend/llsupport/jitframe.py
+++ b/pypy/jit/backend/llsupport/jitframe.py
@@ -15,6 +15,7 @@
     # gcindexlist is a list of indexes of GC ptrs
     # in the actual array jf_frame of JITFRAME
     ('jfi_gcmap', lltype.Ptr(GCMAP)),
+    ('counter', lltype.Signed),
 )
 
 NULLFRAMEINFO = lltype.nullptr(JITFRAMEINFO)
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
@@ -52,12 +52,13 @@
         pass
 
     def _setup_frame_realloc(self):
-        FUNC_TP = lltype.Ptr(lltype.FuncType([llmemory.GCREF],
+        FUNC_TP = lltype.Ptr(lltype.FuncType([llmemory.GCREF, lltype.Signed],
                                              llmemory.GCREF))
 
-        def realloc_frame(frame):
+        def realloc_frame(frame, size):
             frame = lltype.cast_opaque_ptr(jitframe.JITFRAMEPTR, frame)
             new_frame = frame.copy()
+            assert frame.jf_frame_info.jfi_frame_depth >= size
             # XXX now we know, rewrite this
             # we need to do this, because we're not sure what things
             # are GC pointers and which ones are not
diff --git a/pypy/jit/backend/llsupport/rewrite.py 
b/pypy/jit/backend/llsupport/rewrite.py
--- a/pypy/jit/backend/llsupport/rewrite.py
+++ b/pypy/jit/backend/llsupport/rewrite.py
@@ -8,7 +8,7 @@
 from pypy.jit.backend.llsupport.descr import SizeDescr, ArrayDescr
 from pypy.jit.backend.llsupport import jitframe
 from pypy.rpython.lltypesystem import lltype, llmemory
-
+from pypy.rlib import rgc
 
 class GcRewriterAssembler(object):
     # This class performs the following rewrites on the list of operations:
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
@@ -78,6 +78,7 @@
         self.propagate_exception_path = 0
         self.gcrootmap_retaddr_forced = 0
         self.teardown()
+        self.counter = 0
 
     def set_debug(self, v):
         r = self._debug
@@ -514,6 +515,8 @@
 
         clt = CompiledLoopToken(self.cpu, looptoken.number)
         clt.frame_info = lltype.malloc(jitframe.JITFRAMEINFO)
+        clt.frame_info.counter = self.counter
+        self.counter += 1
         clt.allgcrefs = []
         clt.frame_info.jfi_frame_depth = 0 # for now
         looptoken.compiled_loop_token = clt
@@ -530,8 +533,10 @@
         #
         self._call_header_with_stack_check()
         clt._debug_nbargs = len(inputargs)
-        operations = regalloc.prepare_loop(inputargs, operations,
-                                           looptoken, clt.allgcrefs)
+        operations = regalloc.prepare_loop(inputargs, operations, looptoken,
+                                           clt.allgcrefs)
+        rgc._make_sure_does_not_move(clt.frame_info)
+        self._insert_frame_adjustment(clt.frame_info)
         looppos = self.mc.get_relative_pos()
         looptoken._x86_loop_code = looppos
         frame_depth = self._assemble(regalloc, inputargs, operations)
@@ -589,7 +594,7 @@
                                              operations,
                                              self.current_clt.allgcrefs,
                                              self.current_clt.frame_info)
-        stack_check_patch_ofs = self._check_frame_depth()
+        stack_check_patch_ofs, stack_check_patch_ofs2 = 
self._check_frame_depth()
         frame_depth = self._assemble(regalloc, inputargs, operations)
         codeendpos = self.mc.get_relative_pos()
         self.write_pending_failure_recoveries()
@@ -610,8 +615,15 @@
         frame_depth = max(self.current_clt.frame_info.jfi_frame_depth,
                           frame_depth + JITFRAME_FIXED_SIZE)
         self._patch_stackadjust(stack_check_patch_ofs + rawstart, frame_depth)
+        self._patch_stackadjust(stack_check_patch_ofs2 + rawstart, frame_depth)
         self.fixup_target_tokens(rawstart)
+        print frame_depth
+        print self.current_clt
+        print self.current_clt.frame_info
+        print self.current_clt.frame_info.jfi_frame_depth
+        print self.current_clt.frame_info.counter
         self.current_clt.frame_info.jfi_frame_depth = frame_depth
+        print self.current_clt.frame_info.jfi_frame_depth
         self._update_gcmap(self.current_clt.frame_info, regalloc)
         self.teardown()
         # oprofile support
@@ -680,12 +692,22 @@
         assert not IS_X86_32
         self.mc.J_il8(rx86.Conditions['GE'], 0)
         jg_location = self.mc.get_relative_pos()
+        self.mc.MOV_ri(esi.value, 0xffffff)
+        ofs = self.mc.get_relative_pos() - 4
         self.mc.CALL(imm(self._stack_check_failure))
         # patch the JG above
         offset = self.mc.get_relative_pos() - jg_location
         assert 0 < offset <= 127
         self.mc.overwrite(jg_location-1, chr(offset))
-        return stack_check_cmp_ofs
+        return stack_check_cmp_ofs, ofs
+
+    def _insert_frame_adjustment(self, frame_info):
+        gcmap_ofs = self.cpu.get_ofs_of_frame_field('jf_gcmap')
+        frame_info_addr = rffi.cast(lltype.Signed, frame_info)
+        frame_info_ofs = self.cpu.get_ofs_of_frame_field('jf_frame_info')
+        jfi_gc_map_ofs = self.cpu.get_ofs_of_frame_field('jfi_gcmap')
+        self.mc.MOV_bi(gcmap_ofs, frame_info_addr + jfi_gc_map_ofs)
+        self.mc.MOV_bi(frame_info_ofs, frame_info_addr)
 
     def _patch_stackadjust(self, adr, allocated_depth):
         mc = codebuf.MachineCodeBlockWrapper()
@@ -802,8 +824,6 @@
         return frame_depth
 
     def _call_header(self):
-        # NB. the shape of the frame is hard-coded in get_basic_shape() too.
-        # Also, make sure this is consistent with FRAME_FIXED_SIZE.
         # XXX should be LEA?
         self.mc.SUB_ri(esp.value, FRAME_FIXED_SIZE * WORD)
         self.mc.MOV_sr(PASS_ON_MY_FRAME * WORD, ebp.value)
@@ -1960,6 +1980,9 @@
         # exit function
         self._call_footer()
 
+    def genop_discard_label(self, op, arglocs):
+        self._insert_frame_adjustment(self.current_clt.frame_info)
+
     def implement_guard(self, guard_token, condition=None):
         # These jumps are patched later.
         if condition:
diff --git a/pypy/jit/backend/x86/regalloc.py b/pypy/jit/backend/x86/regalloc.py
--- a/pypy/jit/backend/x86/regalloc.py
+++ b/pypy/jit/backend/x86/regalloc.py
@@ -1295,39 +1295,6 @@
         # This operation is used only for testing
         self.force_spill_var(op.getarg(0))
 
-    def get_mark_gc_roots(self, gcrootmap, use_copy_area=False):
-        shape = gcrootmap.get_basic_shape()
-        for v, val in self.fm.bindings.items():
-            if (isinstance(v, BoxPtr) and self.rm.stays_alive(v)):
-                assert isinstance(val, StackLoc)
-                gcrootmap.add_frame_offset(shape, get_ebp_ofs(val.position))
-        for v, reg in self.rm.reg_bindings.items():
-            if reg is eax:
-                continue      # ok to ignore this one
-            if (isinstance(v, BoxPtr) and self.rm.stays_alive(v)):
-                #
-                # The register 'reg' is alive across this call.
-                gcrootmap = self.assembler.cpu.gc_ll_descr.gcrootmap
-                if gcrootmap is None or not gcrootmap.is_shadow_stack:
-                    #
-                    # Asmgcc: if reg is a callee-save register, we can
-                    # explicitly mark it as containing a BoxPtr.
-                    if reg in self.rm.REGLOC_TO_GCROOTMAP_REG_INDEX:
-                        gcrootmap.add_callee_save_reg(
-                            shape, self.rm.REGLOC_TO_GCROOTMAP_REG_INDEX[reg])
-                        continue
-                #
-                # Else, 'use_copy_area' must be True (otherwise this BoxPtr
-                # should not be in a register).  The copy area contains the
-                # real value of the register.
-                assert use_copy_area
-                assert reg in self.rm.REGLOC_TO_COPY_AREA_OFS
-                area_offset = self.rm.REGLOC_TO_COPY_AREA_OFS[reg]
-                gcrootmap.add_frame_offset(shape, area_offset)
-        #
-        return gcrootmap.compress_callshape(shape,
-                                            self.assembler.datablockwrapper)
-
     def consider_force_token(self, op):
         # the FORCE_TOKEN operation returns directly 'ebp'
         self.rm.force_allocate_frame_reg(op.result)
@@ -1378,9 +1345,12 @@
         # end of the same loop, i.e. if what we are compiling is a single
         # loop that ends up jumping to this LABEL, then we can now provide
         # the hints about the expected position of the spilled variables.
-        jump_op = self.final_jump_op
-        if jump_op is not None and jump_op.getdescr() is descr:
-            self._compute_hint_frame_locations_from_descr(descr)
+
+        self.PerformDiscard(op, [])
+        # XXX we never compile code like that?
+        #jump_op = self.final_jump_op
+        #if jump_op is not None and jump_op.getdescr() is descr:
+        #    self._compute_hint_frame_locations_from_descr(descr)
 
     def consider_keepalive(self, op):
         pass
diff --git a/pypy/jit/backend/x86/runner.py b/pypy/jit/backend/x86/runner.py
--- a/pypy/jit/backend/x86/runner.py
+++ b/pypy/jit/backend/x86/runner.py
@@ -205,7 +205,10 @@
     @specialize.arg(1)
     def get_ofs_of_frame_field(self, name):
         descrs = self.gc_ll_descr.getframedescrs(self)
-        base_ofs = self.unpack_arraydescr(descrs.arraydescr)
+        if name.startswith('jfi_'):
+            base_ofs = 0 # not relative to frame
+        else:
+            base_ofs = self.unpack_arraydescr(descrs.arraydescr)
         ofs = self.unpack_fielddescr(getattr(descrs, name))
         return ofs - base_ofs
 
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to