[pypy-commit] pypy stmgc-c8: use stm_memclearinit instead of raw_memclear to initialize gc pointers after
Raemi
noreply at buildbot.pypy.org
Thu Mar 12 15:43:40 CET 2015
Author: Remi Meier <remi.meier at inf.ethz.ch>
Branch: stmgc-c8
Changeset: r76348:04d925289b32
Date: 2015-03-12 09:32 +0100
http://bitbucket.org/pypy/pypy/changeset/04d925289b32/
Log: use stm_memclearinit instead of raw_memclear to initialize gc
pointers after allocation
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
@@ -25,7 +25,7 @@
needs_write_barrier = "stm"
prebuilt_gc_objects_are_static_roots = False
ignore_immutable_static_roots = False
- malloc_zero_filled = True
+ malloc_zero_filled = False
object_minimal_size = 16
#gcflag_extra = GCFLAG_EXTRA
@@ -70,7 +70,7 @@
hdr._obj.typeid16 = typeid16
hdr._obj.prebuilt_hash = prebuilt_hash
- def malloc_fixedsize_clear(self, typeid16, size,
+ def malloc_fixedsize(self, typeid16, size,
needs_finalizer=False,
is_finalizer_light=False,
contains_weakptr=False):
@@ -84,7 +84,7 @@
return llop.stm_allocate_finalizer(llmemory.GCREF, size, typeid16)
return llop.stm_allocate_tid(llmemory.GCREF, size, typeid16)
- def malloc_varsize_clear(self, typeid16, length, size, itemsize,
+ def malloc_varsize(self, typeid16, length, size, itemsize,
offset_to_length):
# XXX be careful here about overflows
totalsize = size + itemsize * length
diff --git a/rpython/memory/gctransform/framework.py b/rpython/memory/gctransform/framework.py
--- a/rpython/memory/gctransform/framework.py
+++ b/rpython/memory/gctransform/framework.py
@@ -315,7 +315,7 @@
GCClass.malloc_varsize.im_func,
[s_gc, s_typeid16]
+ [annmodel.SomeInteger(nonneg=True) for i in range(4)], s_gcref)
-
+
self.collect_ptr = getfn(GCClass.collect.im_func,
[s_gc, annmodel.SomeInteger()], annmodel.s_None)
self.can_move_ptr = getfn(GCClass.can_move.im_func,
@@ -934,8 +934,13 @@
v_a = op.result
v_clear_size = hop.genop('int_sub', [v_size, c_after_header],
resulttype=lltype.Signed)
- self.emit_raw_memclear(hop.llops, v_clear_size, None,
- c_after_header, v_a)
+ if not self.translator.config.translation.stm:
+ self.emit_raw_memclear(hop.llops, v_clear_size, None,
+ c_after_header, v_a)
+ else:
+ self.emit_stm_memclearinit(hop.llops, v_clear_size, None,
+ c_after_header, v_a)
+
def gct_do_malloc_varsize(self, hop):
# used by the JIT (see rpython.jit.backend.llsupport.gc)
@@ -967,11 +972,19 @@
llmemory.sizeof(self.HDR))
v_clear_size = hop.genop('int_sub', [c_length_ofs, c_after_header],
resulttype=lltype.Signed)
- self.emit_raw_memclear(hop.llops, v_clear_size, None,
- c_after_header, v_a)
- # Clear the variable-size part
- self.emit_raw_memclear(hop.llops, v_num_elem, c_itemsize,
- c_basesize, v_a)
+
+ if not self.translator.config.translation.stm:
+ self.emit_raw_memclear(hop.llops, v_clear_size, None,
+ c_after_header, v_a)
+ # Clear the variable-size part
+ self.emit_raw_memclear(hop.llops, v_num_elem, c_itemsize,
+ c_basesize, v_a)
+ else:
+ self.emit_stm_memclearinit(hop.llops, v_clear_size, None,
+ c_after_header, v_a)
+ self.emit_stm_memclearinit(hop.llops, v_num_elem, c_itemsize,
+ c_basesize, v_a)
+
def gct_get_write_barrier_failing_case(self, hop):
op = hop.spaceop
@@ -1399,7 +1412,7 @@
[v] + previous_steps + [c_name, c_null])
else:
llops.genop('bare_setfield', [v, c_name, c_null])
-
+
return
elif isinstance(TYPE, lltype.Array):
ITEM = TYPE.OF
@@ -1407,16 +1420,20 @@
v_size = llops.genop('getarraysize', [v],
resulttype=lltype.Signed)
c_size = rmodel.inputconst(lltype.Signed, llmemory.sizeof(ITEM))
- v_a = llops.genop('cast_ptr_to_adr', [v],
- resulttype=llmemory.Address)
c_fixedofs = rmodel.inputconst(lltype.Signed,
llmemory.itemoffsetof(TYPE))
- self.emit_raw_memclear(llops, v_size, c_size, c_fixedofs, v_a)
+ if not self.translator.config.translation.stm:
+ v_a = llops.genop('cast_ptr_to_adr', [v],
+ resulttype=llmemory.Address)
+ self.emit_raw_memclear(llops, v_size, c_size, c_fixedofs, v_a)
+ else:
+ self.emit_stm_memclearinit(llops, v_size, c_size, c_fixedofs, v)
return
else:
raise TypeError(TYPE)
def emit_raw_memclear(self, llops, v_size, c_size, c_fixedofs, v_a):
+ assert not self.translator.config.translation.stm
if c_size is None:
v_totalsize = v_size
else:
@@ -1426,6 +1443,16 @@
resulttype=llmemory.Address)
llops.genop('raw_memclear', [v_adr, v_totalsize])
+ def emit_stm_memclearinit(self, llops, v_size, c_size, c_fixedofs, v_a):
+ assert self.translator.config.translation.stm
+ if c_size is None:
+ v_totalsize = v_size
+ else:
+ v_totalsize = llops.genop('int_mul', [v_size, c_size],
+ resulttype=lltype.Signed)
+ llops.genop('stm_memclearinit', [v_a, c_fixedofs, v_totalsize])
+
+
class TransformerLayoutBuilder(gctypelayout.TypeLayoutBuilder):
diff --git a/rpython/rtyper/llinterp.py b/rpython/rtyper/llinterp.py
--- a/rpython/rtyper/llinterp.py
+++ b/rpython/rtyper/llinterp.py
@@ -1005,6 +1005,7 @@
op_stm_increment_atomic = _stm_not_implemented
op_stm_decrement_atomic = _stm_not_implemented
op_stm_collect = _stm_not_implemented
+ op_stm_memclearinit = _stm_not_implemented
def op_stm_should_break_transaction(self, keep):
return False
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
@@ -446,6 +446,9 @@
'stm_stop_all_other_threads': LLOp(canmallocgc=True),
'stm_resume_all_other_threads': LLOp(),
+ # stm_memclearinit(gcref, offset, size) clears the memory in this address space
+ 'stm_memclearinit': LLOp(),
+
'stm_hint_commit_soon': LLOp(canrun=True),
'stm_increment_atomic': LLOp(),
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
@@ -294,6 +294,13 @@
typename = cdecl(funcgen.lltypename(op.result), '')
return '%s = (%s)(uintptr_t)%s;' % (result, typename, arg)
+def stm_memclearinit(funcgen, op):
+ gcref = funcgen.expr(op.args[0])
+ offset = funcgen.expr(op.args[1])
+ size = funcgen.expr(op.args[2])
+ return 'pypy_stm_memclearinit((object_t*)%s, (size_t)%s, (size_t)%s);' % (
+ gcref, offset, size)
+
def stm_hashtable_create(funcgen, op):
_STM_HASHTABLE_ENTRY = op.args[0].concretetype.TO
type_id = funcgen.db.gctransformer.get_type_id(_STM_HASHTABLE_ENTRY)
diff --git a/rpython/translator/stm/src_stm/extracode.h b/rpython/translator/stm/src_stm/extracode.h
--- a/rpython/translator/stm/src_stm/extracode.h
+++ b/rpython/translator/stm/src_stm/extracode.h
@@ -50,6 +50,12 @@
}
+void pypy_stm_memclearinit(object_t *obj, size_t offset, size_t size)
+{
+ char *realobj = STM_SEGMENT->segment_base + (uintptr_t)obj;
+ memset(realobj + offset, 0, size);
+}
+
/************************************************************/
/*** HACK: hard-coded logic to expand the marker into ***/
/*** a string, suitable for running in PyPy ***/
diff --git a/rpython/translator/stm/src_stm/stmgcintf.h b/rpython/translator/stm/src_stm/stmgcintf.h
--- a/rpython/translator/stm/src_stm/stmgcintf.h
+++ b/rpython/translator/stm/src_stm/stmgcintf.h
@@ -24,6 +24,8 @@
void pypy_stm_register_thread_local(void); /* generated into stm_prebuilt.c */
void pypy_stm_unregister_thread_local(void); /* generated into stm_prebuilt.c */
+void pypy_stm_memclearinit(object_t *obj, size_t offset, size_t size);
+
void _pypy_stm_initialize_nursery_low_fill_mark(long v_counter);
void _pypy_stm_inev_state(void);
long _pypy_stm_start_transaction(void);
More information about the pypy-commit
mailing list