Author: Armin Rigo <[email protected]>
Branch: stm-thread
Changeset: r54923:c72735d90342
Date: 2012-05-07 10:19 +0200
http://bitbucket.org/pypy/pypy/changeset/c72735d90342/

Log:    Minimal hack to add these kind of transactions into the PyPy
        interpreter.

diff --git a/pypy/interpreter/pyopcode.py b/pypy/interpreter/pyopcode.py
--- a/pypy/interpreter/pyopcode.py
+++ b/pypy/interpreter/pyopcode.py
@@ -12,6 +12,7 @@
 from pypy.tool.sourcetools import func_with_new_name
 from pypy.rlib.objectmodel import we_are_translated
 from pypy.rlib import jit, rstackovf
+from pypy.rlib import rstm
 from pypy.rlib.rarithmetic import r_uint, intmask
 from pypy.rlib.unroll import unrolling_iterable
 from pypy.rlib.debug import check_nonneg
@@ -75,6 +76,9 @@
     ### opcode dispatch ###
 
     def dispatch(self, pycode, next_instr, ec):
+        if self.space.config.translation.stm and we_are_translated():
+            return self.dispatch_with_stm(next_instr)
+
         # For the sequel, force 'next_instr' to be unsigned for performance
         next_instr = r_uint(next_instr)
         co_code = pycode.co_code
@@ -85,6 +89,23 @@
         except ExitFrame:
             return self.popvalue()
 
+    def dispatch_with_stm(self, next_instr):
+        self.last_instr = intmask(next_instr)
+        try:
+            rstm.perform_transaction(pyframe.PyFrame._dispatch_stm_transaction,
+                                     pyframe.PyFrame, self)
+        except ExitFrame:
+            return self.popvalue()
+        assert 0, "should not be reachable"
+
+    def _dispatch_stm_transaction(self, retry_counter):
+        co_code = self.pycode.co_code
+        next_instr = r_uint(self.last_instr)
+        ec = self.space.getexecutioncontext()
+        next_instr = self.handle_bytecode(co_code, next_instr, ec)
+        self.last_instr = intmask(next_instr)
+        return 1   # loop again, unless interrupted by an ExitFrame
+
     def handle_bytecode(self, co_code, next_instr, ec):
         try:
             next_instr = self.dispatch_bytecode(co_code, next_instr, ec)
@@ -280,6 +301,9 @@
             if jit.we_are_jitted():
                 return next_instr
 
+            if rstm.is_inevitable():
+                return next_instr
+
     @jit.unroll_safe
     def unrollstack(self, unroller_kind):
         while self.blockstack_non_empty():
diff --git a/pypy/rlib/rstm.py b/pypy/rlib/rstm.py
--- a/pypy/rlib/rstm.py
+++ b/pypy/rlib/rstm.py
@@ -2,12 +2,16 @@
 from pypy.translator.stm import stmgcintf
 from pypy.rlib.debug import ll_assert
 from pypy.rlib.objectmodel import keepalive_until_here, specialize
+from pypy.rlib.objectmodel import we_are_translated
 from pypy.rpython.lltypesystem import lltype, llmemory, rffi, rclass
 from pypy.rpython.lltypesystem.lloperation import llop
 from pypy.rpython.annlowlevel import (cast_base_ptr_to_instance,
                                       cast_instance_to_base_ptr,
                                       llhelper)
 
+def is_inevitable():
+    return we_are_translated() and stmgcintf.StmOperations.is_inevitable()
+
 def before_external_call():
     llop.stm_stop_transaction(lltype.Void)
     stmgcintf.StmOperations.commit_transaction()
diff --git a/pypy/translator/goal/targetpypystandalone.py 
b/pypy/translator/goal/targetpypystandalone.py
--- a/pypy/translator/goal/targetpypystandalone.py
+++ b/pypy/translator/goal/targetpypystandalone.py
@@ -150,12 +150,11 @@
         global space, entry_point
 
         if config.translation.stm:
-            config.objspace.usemodules.transaction = True
+            #config.objspace.usemodules.transaction = True
             config.objspace.usemodules.signal = False     # XXX! FIXME
-            config.objspace.usemodules.thread = False
-            config.translation.thread = False
-        elif config.objspace.usemodules.transaction:
-            raise Exception("use --stm, not --withmod-transaction alone")
+            config.translation.thread = True
+        #elif config.objspace.usemodules.transaction:
+        #    raise Exception("use --stm, not --withmod-transaction alone")
 
         if config.objspace.allworkingmodules:
             from pypy.config.pypyoption import enable_allworkingmodules
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to