[pypy-commit] pypy stm: - mallocs of GC objects is supported by the STM system (for now
arigo
noreply at buildbot.pypy.org
Fri Oct 28 18:53:05 CEST 2011
Author: Armin Rigo <arigo at tunes.org>
Branch: stm
Changeset: r48580:1cffa0d605b4
Date: 2011-10-28 18:52 +0200
http://bitbucket.org/pypy/pypy/changeset/1cffa0d605b4/
Log: - mallocs of GC objects is supported by the STM system (for now
with Boehm)
- fix: don't store ophandler on self.__class__, because it is
typically a method bound to the current self
diff --git a/pypy/translator/stm/llstminterp.py b/pypy/translator/stm/llstminterp.py
--- a/pypy/translator/stm/llstminterp.py
+++ b/pypy/translator/stm/llstminterp.py
@@ -23,7 +23,7 @@
final_stm_mode = stm_mode
assert llinterp.stm_mode == final_stm_mode, (
"llinterp.stm_mode is %r after eval_graph, but should be %r" % (
- llinterp.stm_mode, stm_mode))
+ llinterp.stm_mode, final_stm_mode))
return res
finally:
llinterp.frame_class = LLFrame
@@ -53,9 +53,8 @@
if ophandler is None:
ophandler = LLFrame.getoperationhandler(self, opname)
if op_in_set(opname, ALWAYS_ALLOW_OPERATIONS):
- # always allow this, so store it back on self.__class__
- setattr(self.__class__, 'opstm_' + opname,
- staticmethod(ophandler))
+ # always allow this, so store it back on 'self'
+ setattr(self, 'opstm_' + opname, ophandler)
else:
# only allow this if we're not in the "regular_transaction"
# mode; check every time, so don't store it on self.__class__
@@ -109,3 +108,8 @@
def opstm_stm_try_inevitable(self):
self.check_stm_mode(lambda m: m != "not_in_transaction")
self.llinterpreter.stm_mode = "inevitable_transaction"
+
+ def opstm_malloc(self, TYPE, flags):
+ if flags['flavor'] != 'gc':
+ self.check_stm_mode(lambda m: m != "regular_transaction")
+ return LLFrame.op_malloc(self, TYPE, flags)
diff --git a/pypy/translator/stm/test/test_transform.py b/pypy/translator/stm/test/test_transform.py
--- a/pypy/translator/stm/test/test_transform.py
+++ b/pypy/translator/stm/test/test_transform.py
@@ -57,6 +57,19 @@
res = eval_stm_func(func, [13], final_stm_mode="inevitable_transaction")
assert res == 14
+def test_supported_malloc():
+ S = lltype.GcStruct('S', ('x', lltype.Signed)) # GC structure
+ def func():
+ lltype.malloc(S)
+ eval_stm_func(func, [], final_stm_mode="regular_transaction")
+
+def test_unsupported_malloc():
+ S = lltype.Struct('S', ('x', lltype.Signed)) # non-GC structure
+ def func():
+ lltype.malloc(S, flavor='raw')
+ eval_stm_func(func, [], final_stm_mode="inevitable_transaction")
+test_unsupported_malloc.dont_track_allocations = True
+
# ____________________________________________________________
class TestTransformSingleThread(StandaloneTests):
diff --git a/pypy/translator/stm/transform.py b/pypy/translator/stm/transform.py
--- a/pypy/translator/stm/transform.py
+++ b/pypy/translator/stm/transform.py
@@ -9,7 +9,6 @@
'same_as', 'cast_*',
'direct_call',
'debug_print', 'debug_assert',
- 'malloc', 'malloc_varsize',
])
def op_in_set(opname, set):
@@ -52,7 +51,13 @@
meth = turn_inevitable_and_proceed
setattr(self.__class__, 'stt_' + op.opname,
staticmethod(meth))
- meth(newoperations, op)
+ res = meth(newoperations, op)
+ if res is True:
+ newoperations.append(op)
+ elif res is False:
+ turn_inevitable_and_proceed(newoperations, op)
+ else:
+ assert res is None
block.operations = newoperations
def transform_graph(self, graph):
@@ -93,7 +98,11 @@
def stt_stm_transaction_boundary(self, newoperations, op):
self.seen_transaction_boundary = True
- newoperations.append(op)
+ return True
+
+ def stt_malloc(self, newoperations, op):
+ flags = op.args[1].value
+ return flags['flavor'] == 'gc'
def transform_graph(graph):
More information about the pypy-commit
mailing list