[pypy-commit] pypy stm-gc: Tweaks. Try to restore the write barrier.
arigo
noreply at buildbot.pypy.org
Mon Apr 16 15:51:31 CEST 2012
Author: Armin Rigo <arigo at tunes.org>
Branch: stm-gc
Changeset: r54418:6982e52364be
Date: 2012-04-15 19:53 +0200
http://bitbucket.org/pypy/pypy/changeset/6982e52364be/
Log: Tweaks. Try to restore the write barrier.
diff --git a/pypy/rpython/memory/gc/stmgc.py b/pypy/rpython/memory/gc/stmgc.py
--- a/pypy/rpython/memory/gc/stmgc.py
+++ b/pypy/rpython/memory/gc/stmgc.py
@@ -97,6 +97,7 @@
self.stm_operations = stm_operations
self.nursery_size = nursery_size
self.sharedarea = stmshared.StmGCSharedArea(self)
+ self.transactional_mode = False
#
def _get_size(obj): # indirection to hide 'self'
return self.get_size(obj)
@@ -136,9 +137,13 @@
return StmGCTLS.cast_address_to_tls_object(tls)
def enter_transactional_mode(self):
+ ll_assert(not self.transactional_mode, "already in transactional mode")
self.main_thread_tls.enter_transactional_mode()
+ self.transactional_mode = True
def leave_transactional_mode(self):
+ ll_assert(self.transactional_mode, "already in non-transactional mode")
+ self.transactional_mode = False
self.main_thread_tls.leave_transactional_mode()
# ----------
@@ -226,9 +231,10 @@
tls.global_stop = result + totalsize
- def collect(self, gen=0):
- #raise NotImplementedError
- debug_print("XXX collect() ignored")
+ def collect(self, gen=1):
+ self.get_tls().local_collection()
+ if gen > 0:
+ debug_print("XXX not doing a global collect()")
def start_transaction(self):
self.get_tls().start_transaction()
@@ -311,11 +317,10 @@
#
@dont_inline
def _stm_write_barrier_global(obj):
- if not stm_operations.in_transaction():
- return obj
# we need to find or make a local copy
hdr = self.header(obj)
if hdr.tid & GCFLAG_WAS_COPIED == 0:
+ #
# in this case, we are sure that we don't have a copy
hdr.tid |= GCFLAG_WAS_COPIED
# ^^^ non-protected write, but concurrent writes should
@@ -332,11 +337,11 @@
return localobj
#
# Here, we need to really make a local copy
- raise NotImplementedError
size = self.get_size(obj)
- tls = self.collector.get_tls()
+ totalsize = self.gcheaderbuilder.size_gc_header + size
+ tls = self.get_tls()
try:
- localobj = self._malloc_local_raw(tls, size)
+ localobj = tls.malloc_local_copy(totalsize)
except MemoryError:
# XXX
fatalerror("MemoryError in _stm_write_barrier_global -- sorry")
diff --git a/pypy/rpython/memory/gc/stmshared.py b/pypy/rpython/memory/gc/stmshared.py
--- a/pypy/rpython/memory/gc/stmshared.py
+++ b/pypy/rpython/memory/gc/stmshared.py
@@ -48,10 +48,6 @@
adr1 = adr2 - self.gc.gcheaderbuilder.size_gc_header
llarena.arena_free(llarena.getfakearenaaddress(adr1))
- def replace_special_stack(self, new_special_stack):
- self.special_stack.delete()
- self.special_stack = new_special_stack
-
def clear(self):
obj = self.chained_list
self.chained_list = NULL
diff --git a/pypy/rpython/memory/gc/stmtls.py b/pypy/rpython/memory/gc/stmtls.py
--- a/pypy/rpython/memory/gc/stmtls.py
+++ b/pypy/rpython/memory/gc/stmtls.py
@@ -39,13 +39,14 @@
# --- the local raw-malloced objects (chained list via hdr.version)
#self.rawmalloced_objects = NULL
# --- the local "normal" old objects (chained list via hdr.version)
- self.old_objects = NULL
+ #self.old_objects = NULL
# --- the local objects with weakrefs (chained list via hdr.version)
#self.young_objects_with_weakrefs = NULL
#self.old_objects_with_weakrefs = NULL
#
# --- a thread-local allocator for the shared area
- self.sharedarea_tls = None
+ from pypy.rpython.memory.gc.stmshared import StmGCThreadLocalAllocator
+ self.sharedarea_tls = StmGCThreadLocalAllocator(self.gc.sharedarea)
#
self._register_with_C_code()
@@ -155,7 +156,7 @@
#
# Move away the previous sharedarea_tls and start a new one.
from pypy.rpython.memory.gc.stmshared import StmGCThreadLocalAllocator
- previous_sharedarea_tls = self.sharedarea_tls # may be None
+ previous_sharedarea_tls = self.sharedarea_tls
self.sharedarea_tls = StmGCThreadLocalAllocator(self.gc.sharedarea)
#
# List of LOCAL objects pending a visit. Note that no GLOBAL
@@ -182,8 +183,7 @@
#
# Visit all previous OLD objects. Free the ones that have not been
# visited above, and reset GCFLAG_VISITED on the others.
- if previous_sharedarea_tls is not None:
- self.mass_free_old_local(previous_sharedarea_tls)
+ self.mass_free_old_local(previous_sharedarea_tls)
#
# All live nursery objects are out, and the rest dies. Fill
# the whole nursery with zero and reset the current nursery pointer.
@@ -234,24 +234,30 @@
"odd-valued (i.e. tagged) pointer unexpected here")
return self.nursery_start <= addr < self.nursery_top
+ def malloc_local_copy(self, totalsize):
+ """Allocate an object that will be used as a LOCAL copy of
+ some GLOBAL object."""
+ localobj = self.sharedarea_tls.malloc_object(totalsize)
+ self.sharedarea_tls.add_special(localobj)
+ return localobj
+
# ------------------------------------------------------------
def _promote_locals_to_globals(self):
ll_assert(self.local_nursery_is_empty(), "nursery must be empty [1]")
+ ll_assert(not self.sharedarea_tls.special_stack.non_empty(),
+ "special_stack should be empty here [1]")
#
- obj = self.old_objects
- self.old_objects = NULL
+ # Promote all objects in sharedarea_tls to global
+ obj = self.sharedarea_tls.chained_list
+ self.sharedarea_tls.chained_list = NULL
+ #
while obj:
hdr = self.gc.header(obj)
+ obj = hdr.version
+ ll_assert(not (hdr.tid & GCFLAG_GLOBAL), "already GLOBAL [1]")
+ hdr.version = NULL
hdr.tid |= GCFLAG_GLOBAL
- obj = hdr.version
- #
-## obj = self.rawmalloced_objects
-## self.rawmalloced_objects = NULL
-## while obj:
-## hdr = self.header(obj)
-## hdr.tid |= GCFLAG_GLOBAL
-## obj = hdr.version
def _cleanup_state(self):
#if self.rawmalloced_objects:
@@ -259,10 +265,7 @@
# if we still have a StmGCThreadLocalAllocator, free the old unused
# local objects it still contains
- if self.sharedarea_tls is not None:
- self.sharedarea_tls.clear()
- self.sharedarea_tls.delete()
- self.sharedarea_tls = None
+ self.sharedarea_tls.clear()
def collect_roots_from_stack(self):
More information about the pypy-commit
mailing list