Author: Armin Rigo <[email protected]>
Branch: stmgc-c7-rewindjmp
Changeset: r72883:e9aa2fdab146
Date: 2014-08-18 15:31 +0200
http://bitbucket.org/pypy/pypy/changeset/e9aa2fdab146/

Log:    Attempt to fix CALL_RELEASE_GIL with stm

diff --git a/rpython/jit/backend/llsupport/assembler.py 
b/rpython/jit/backend/llsupport/assembler.py
--- a/rpython/jit/backend/llsupport/assembler.py
+++ b/rpython/jit/backend/llsupport/assembler.py
@@ -361,6 +361,8 @@
                                                  lltype.Void))
 
     def _build_release_gil(self, gcrootmap):
+        if self.gc_ll_descr.stm:
+            return
         if gcrootmap is None or gcrootmap.is_shadow_stack:
             reacqgil_func = llhelper(self._REACQGIL0_FUNC,
                                      self._reacquire_gil_shadowstack)
diff --git a/rpython/jit/backend/llsupport/callbuilder.py 
b/rpython/jit/backend/llsupport/callbuilder.py
--- a/rpython/jit/backend/llsupport/callbuilder.py
+++ b/rpython/jit/backend/llsupport/callbuilder.py
@@ -1,5 +1,5 @@
 from rpython.rlib.clibffi import FFI_DEFAULT_ABI
-from rpython.rlib import rgil
+from rpython.rlib import rgc, rgil
 from rpython.rtyper.lltypesystem import lltype, rffi
 
 
@@ -45,7 +45,10 @@
     def emit_call_release_gil(self):
         """Emit a CALL_RELEASE_GIL, including calls to releasegil_addr
         and reacqgil_addr."""
-        fastgil = rffi.cast(lltype.Signed, rgil.gil_fetch_fastgil())
+        if rgc.stm_is_enabled():
+            fastgil = 0
+        else:
+            fastgil = rffi.cast(lltype.Signed, rgil.gil_fetch_fastgil())
         self.select_call_release_gil_mode()
         self.prepare_arguments()
         self.push_gcmap_for_call_release_gil()
diff --git a/rpython/jit/backend/x86/callbuilder.py 
b/rpython/jit/backend/x86/callbuilder.py
--- a/rpython/jit/backend/x86/callbuilder.py
+++ b/rpython/jit/backend/x86/callbuilder.py
@@ -95,6 +95,10 @@
     def call_releasegil_addr_and_move_real_arguments(self, fastgil):
         from rpython.jit.backend.x86.assembler import heap
         #
+        if self.asm.cpu.gc_ll_descr.stm:
+            self.call_stm_before_ex_call()
+            return
+        #
         if not self.asm._is_asmgcc():
             # shadowstack: change 'rpy_fastgil' to 0 (it should be
             # non-zero right now).
@@ -132,6 +136,10 @@
     def move_real_result_and_call_reacqgil_addr(self, fastgil):
         from rpython.jit.backend.x86 import rx86
         #
+        if self.asm.cpu.gc_ll_descr.stm:
+            self.call_stm_after_ex_call()
+            return
+        #
         # check if we need to call the reacqgil() function or not
         # (to acquiring the GIL, remove the asmgcc head from
         # the chained list, etc.)
@@ -482,6 +490,41 @@
             assert self.restype == INT
             self.mc.MOV_rs(eax.value, 0)
 
+    def call_stm_before_ex_call(self):
+        # XXX slowish: before any CALL_RELEASE_GIL, invoke the
+        # pypy_stm_commit_if_not_atomic() function.  Messy because
+        # we need to save the register arguments first.
+        #
+        n = min(self.next_arg_gpr, len(self.ARGUMENTS_GPR))
+        for i in range(n):
+            self.mc.PUSH_r(self.ARGUMENTS_GPR[i].value)    # PUSH gpr arg
+        m = min(self.next_arg_xmm, len(self.ARGUMENTS_XMM))
+        extra = m + ((n + m) & 1)
+        # in total the stack is moved down by (n + extra) words,
+        # which needs to be an even value for alignment:
+        assert ((n + extra) & 1) == 0
+        if extra > 0:
+            self.mc.SUB_ri(esp.value, extra * WORD)        # SUB rsp, extra
+            for i in range(m):
+                self.mc.MOVSD_sx(i * WORD, self.ARGUMENTS_XMM[i].value)
+                                                           # MOVSD [rsp+..], 
xmm
+        #
+        self.mc.CALL(imm(rstm.adr_pypy_stm_commit_if_not_atomic))
+        #
+        if extra > 0:
+            for i in range(m):
+                self.mc.MOVSD_xs(self.ARGUMENTS_XMM[i].value, i * WORD)
+            self.mc.ADD_ri(esp.value, extra * WORD)
+        for i in range(n-1, -1, -1):
+            self.mc.POP_r(self.ARGUMENTS_GPR[i].value)
+
+    def call_stm_after_ex_call(self):
+        # after any CALL_RELEASE_GIL, invoke the
+        # pypy_stm_start_if_not_atomic() function
+        self.save_result_value_reacq()
+        self.mc.CALL(imm(rstm.adr_pypy_stm_start_if_not_atomic))
+        self.restore_result_value_reacq()
+
 
 if IS_X86_32:
     CallBuilder = CallBuilder32
diff --git a/rpython/rlib/rstm.py b/rpython/rlib/rstm.py
--- a/rpython/rlib/rstm.py
+++ b/rpython/rlib/rstm.py
@@ -35,6 +35,10 @@
 
 adr_pypy__rewind_jmp_copy_stack_slice = (
     CFlexSymbolic('((long)&pypy__rewind_jmp_copy_stack_slice)'))
+adr_pypy_stm_commit_if_not_atomic = (
+    CFlexSymbolic('((long)&pypy_stm_commit_if_not_atomic)'))
+adr_pypy_stm_start_if_not_atomic = (
+    CFlexSymbolic('((long)&pypy_stm_start_if_not_atomic)'))
 
 
 def rewind_jmp_frame():
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to