Author: Armin Rigo <[email protected]>
Branch: stmgc-c4
Changeset: r65123:1bacb9bddd05
Date: 2013-06-30 18:28 +0200
http://bitbucket.org/pypy/pypy/changeset/1bacb9bddd05/
Log: The next test passes
diff --git a/rpython/memory/gc/stmgc.py b/rpython/memory/gc/stmgc.py
--- a/rpython/memory/gc/stmgc.py
+++ b/rpython/memory/gc/stmgc.py
@@ -4,7 +4,8 @@
"""
from rpython.memory.gc.base import GCBase, MovingGCBase
-from rpython.rtyper.lltypesystem import lltype, llmemory, llgroup, rffi
+from rpython.rtyper.lltypesystem import lltype, llmemory, llgroup, llarena
+from rpython.rtyper.lltypesystem import rffi
from rpython.rtyper.lltypesystem.lloperation import llop
from rpython.rlib.debug import ll_assert
@@ -62,6 +63,7 @@
offset_to_length):
# XXX be careful about overflows, and call optimized versions
totalsize = size + itemsize * length
+ totalsize = llarena.round_up_for_allocation(totalsize)
obj = llop.stm_allocate(llmemory.Address, totalsize, typeid16)
(obj + offset_to_length).signed[0] = length
return llmemory.cast_adr_to_ptr(obj, llmemory.GCREF)
diff --git a/rpython/memory/gctransform/stmframework.py
b/rpython/memory/gctransform/stmframework.py
--- a/rpython/memory/gctransform/stmframework.py
+++ b/rpython/memory/gctransform/stmframework.py
@@ -1,3 +1,6 @@
+from rpython.annotator import model as annmodel
+from rpython.rtyper.lltypesystem import lltype, llmemory, rffi
+from rpython.rtyper.lltypesystem.lloperation import llop
from rpython.memory.gctransform.framework import (
BaseFrameworkGCTransformer, BaseRootWalker, sizeofaddr)
@@ -5,8 +8,6 @@
class StmFrameworkGCTransformer(BaseFrameworkGCTransformer):
def _declare_functions(self, GCClass, getfn, s_gc, s_typeid16):
- from rpython.annotator import model as annmodel
- from rpython.rtyper.lltypesystem import lltype, llmemory, rffi
BaseFrameworkGCTransformer._declare_functions(self, GCClass, getfn,
s_gc, s_typeid16)
gc = self.gcdata.gc
@@ -48,8 +49,13 @@
class StmRootWalker(BaseRootWalker):
- def need_thread_support(self, gctransform, getfn):
- pass
+ def need_thread_support(self, gctransformer, getfn):
+ def thread_start():
+ llop.stm_initialize(lltype.Void)
+ def thread_die():
+ llop.stm_finalize(lltype.Void)
+ self.thread_start_ptr = getfn(thread_start, [], annmodel.s_None)
+ self.thread_die_ptr = getfn(thread_die, [], annmodel.s_None)
def walk_stack_roots(self, collect_stack_root):
raise NotImplementedError
diff --git a/rpython/rtyper/lltypesystem/lloperation.py
b/rpython/rtyper/lltypesystem/lloperation.py
--- a/rpython/rtyper/lltypesystem/lloperation.py
+++ b/rpython/rtyper/lltypesystem/lloperation.py
@@ -422,6 +422,7 @@
# to keep them as operations until the genc stage)
'stm_initialize': LLOp(),
+ 'stm_finalize': LLOp(),
'stm_barrier': LLOp(sideeffects=False),
'stm_allocate': LLOp(sideeffects=False),
'stm_become_inevitable': LLOp(),
@@ -432,6 +433,8 @@
'stm_hash': LLOp(sideeffects=False),
'stm_push_root': LLOp(),
'stm_pop_root_into': LLOp(),
+ 'stm_commit_transaction': LLOp(),
+ 'stm_begin_inevitable_transaction': LLOp(),
# __________ address operations __________
diff --git a/rpython/translator/c/funcgen.py b/rpython/translator/c/funcgen.py
--- a/rpython/translator/c/funcgen.py
+++ b/rpython/translator/c/funcgen.py
@@ -585,6 +585,7 @@
self.__class__.op_stm = op_stm
return self.op_stm(op)
OP_STM_INITIALIZE = _OP_STM
+ OP_STM_FINALIZE = _OP_STM
OP_STM_BECOME_INEVITABLE = _OP_STM
OP_STM_BARRIER = _OP_STM
OP_STM_PTR_EQ = _OP_STM
@@ -594,6 +595,8 @@
OP_STM_GET_TID = _OP_STM
OP_STM_HASH = _OP_STM
OP_STM_ID = _OP_STM
+ OP_STM_COMMIT_TRANSACTION = _OP_STM
+ OP_STM_BEGIN_INEVITABLE_TRANSACTION = _OP_STM
def OP_PTR_NONZERO(self, op):
diff --git a/rpython/translator/stm/funcgen.py
b/rpython/translator/stm/funcgen.py
--- a/rpython/translator/stm/funcgen.py
+++ b/rpython/translator/stm/funcgen.py
@@ -1,3 +1,4 @@
+from rpython.flowspace.model import Constant
from rpython.translator.c.support import c_string_constant, cdecl
from rpython.translator.c.node import Node, ContainerNode
from rpython.translator.c.primitive import name_small_integer
@@ -43,6 +44,9 @@
def stm_initialize(funcgen, op):
return 'stm_initialize();'
+def stm_finalize(funcgen, op):
+ return 'stm_finalize();'
+
_STM_BARRIER_FUNCS = { # XXX try to see if some combinations can be shorter
'P2R': 'stm_read_barrier',
'G2R': 'stm_read_barrier',
@@ -83,6 +87,8 @@
def stm_pop_root_into(funcgen, op):
arg0 = funcgen.expr(op.args[0])
+ if isinstance(op.args[0], Constant):
+ return '/* %s = */ stm_pop_root();' % (arg0,)
return '%s = (%s)stm_pop_root();' % (
arg0, cdecl(funcgen.lltypename(op.args[0]), ''))
@@ -107,6 +113,12 @@
result = funcgen.expr(op.result)
return '%s = stm_id((gcptr)%s);' % (result, arg0)
+def stm_commit_transaction(funcgen, op):
+ return 'stm_commit_transaction();'
+
+def stm_begin_inevitable_transaction(funcgen, op):
+ return 'stm_begin_inevitable_transaction();'
+
def op_stm(funcgen, op):
func = globals()[op.opname]
diff --git a/rpython/translator/stm/src_stm/nursery.c
b/rpython/translator/stm/src_stm/nursery.c
--- a/rpython/translator/stm/src_stm/nursery.c
+++ b/rpython/translator/stm/src_stm/nursery.c
@@ -65,6 +65,7 @@
gcptr P;
char *cur = d->nursery_current;
char *end = cur + size;
+ assert((size & 3) == 0);
d->nursery_current = end;
if (end > d->nursery_nextlimit) {
P = allocate_next_section(size, tid);
diff --git a/rpython/translator/stm/src_stm/revision
b/rpython/translator/stm/src_stm/revision
--- a/rpython/translator/stm/src_stm/revision
+++ b/rpython/translator/stm/src_stm/revision
@@ -1,1 +1,1 @@
-c856b6a0d157+
+1ba74b051c7b
diff --git a/rpython/translator/stm/test/test_ztranslated.py
b/rpython/translator/stm/test/test_ztranslated.py
--- a/rpython/translator/stm/test/test_ztranslated.py
+++ b/rpython/translator/stm/test/test_ztranslated.py
@@ -42,7 +42,7 @@
w(2, lltype.malloc(FOO))
return 0
#
- t, cbuilder = self.compile(entry_point, backendopt=True)
+ t, cbuilder = self.compile(entry_point)
assert prebuilt_hash == lltype.identityhash(prebuilt)
data = cbuilder.cmdexec('')
data = data.split()
@@ -54,6 +54,31 @@
int(data[i2 + 2])
assert int(data[i1 + 1]) == prebuilt_hash
+ def test_start_thread(self):
+ from rpython.rlib import rthread
+ class Global:
+ value = 1
+ seen = None
+ glob = Global()
+ #
+ def threadfn():
+ rthread.gc_thread_start()
+ x = Global()
+ x.value = 0
+ glob.seen = x
+ rthread.gc_thread_die()
+ def entry_point(argv):
+ glob.seen = None
+ rthread.start_new_thread(threadfn, ())
+ while glob.seen is None:
+ llop.stm_commit_transaction(lltype.Void)
+ llop.stm_begin_inevitable_transaction(lltype.Void)
+ return glob.seen.value
+ #
+ t, cbuilder = self.compile(entry_point)
+ cbuilder.cmdexec('')
+ # assert did not crash
+
def test_targetdemo(self):
t, cbuilder = self.compile(targetdemo2.entry_point)
data, dataerr = cbuilder.cmdexec('4 5000', err=True,
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit