[pypy-commit] stmgc c7-refactor: Refactoring and small fix
arigo
noreply at buildbot.pypy.org
Tue Feb 25 10:06:08 CET 2014
Author: Armin Rigo <arigo at tunes.org>
Branch: c7-refactor
Changeset: r855:76937b4f5d6e
Date: 2014-02-25 10:05 +0100
http://bitbucket.org/pypy/stmgc/changeset/76937b4f5d6e/
Log: Refactoring and small fix
diff --git a/c7/stm/nursery.c b/c7/stm/nursery.c
--- a/c7/stm/nursery.c
+++ b/c7/stm/nursery.c
@@ -60,86 +60,88 @@
#define FLAG_SYNC_LARGE_NOW 0x01
-static void minor_young_outside_nursery(object_t *obj)
+static uintptr_t minor_record_large_overflow_object(object_t *nobj)
{
- tree_delete_item(STM_PSEGMENT->young_outside_nursery, (uintptr_t)obj);
-
- uintptr_t nobj_sync_now = (uintptr_t)obj;
+ uintptr_t nobj_sync_now = (uintptr_t)nobj;
if (STM_PSEGMENT->minor_collect_will_commit_now)
nobj_sync_now |= FLAG_SYNC_LARGE_NOW;
else
- LIST_APPEND(STM_PSEGMENT->large_overflow_objects, obj);
-
- LIST_APPEND(STM_PSEGMENT->objects_pointing_to_nursery, nobj_sync_now);
+ LIST_APPEND(STM_PSEGMENT->large_overflow_objects, nobj);
+ return nobj_sync_now;
}
static void minor_trace_if_young(object_t **pobj)
{
/* takes a normal pointer to a thread-local pointer to an object */
object_t *obj = *pobj;
+ object_t *nobj;
+ uintptr_t nobj_sync_now;
+
if (obj == NULL)
return;
assert((uintptr_t)obj < NB_PAGES * 4096UL);
- if (!_is_in_nursery(obj)) {
- if (UNLIKELY(tree_contains(STM_PSEGMENT->young_outside_nursery,
- (uintptr_t)obj))) {
- minor_young_outside_nursery(obj);
+
+ if (_is_in_nursery(obj)) {
+ /* If the object was already seen here, its first word was set
+ to GCWORD_MOVED. In that case, the forwarding location, i.e.
+ where the object moved to, is stored in the second word in 'obj'. */
+ object_t *TLPREFIX *pforwarded_array = (object_t *TLPREFIX *)obj;
+
+ if (pforwarded_array[0] == GCWORD_MOVED) {
+ *pobj = pforwarded_array[1]; /* already moved */
+ return;
}
- return; /* else old object, nothing to do */
+
+ /* We need to make a copy of this object. It goes either in
+ a largemalloc.c-managed area, or if it's small enough, in
+ one of the small uniform pages from gcpage.c.
+ */
+ char *realobj = REAL_ADDRESS(STM_SEGMENT->segment_base, obj);
+ size_t size = stmcb_size_rounded_up((struct object_s *)realobj);
+
+ if (1 /*size >= GC_MEDIUM_REQUEST*/) {
+
+ /* case 1: object is not small enough.
+ Ask gcpage.c for an allocation via largemalloc. */
+ char *allocated = allocate_outside_nursery_large(size);
+ nobj = (object_t *)(allocated - stm_object_pages);
+
+ /* Copy the object */
+ char *realnobj = REAL_ADDRESS(STM_SEGMENT->segment_base, nobj);
+ memcpy(realnobj, realobj, size);
+
+ nobj_sync_now = minor_record_large_overflow_object(nobj);
+ }
+ else {
+ /* case "small enough" */
+ abort(); //...
+ }
+
+ /* Done copying the object. */
+ //dprintf(("\t\t\t\t\t%p -> %p\n", obj, nobj));
+ pforwarded_array[0] = GCWORD_MOVED;
+ pforwarded_array[1] = nobj;
+ *pobj = nobj;
}
- /* If the object was already seen here, its first word was set
- to GCWORD_MOVED. In that case, the forwarding location, i.e.
- where the object moved to, is stored in the second word in 'obj'. */
- object_t *TLPREFIX *pforwarded_array = (object_t *TLPREFIX *)obj;
+ else {
+ /* The object was not in the nursery at all */
+ if (LIKELY(!tree_contains(STM_PSEGMENT->young_outside_nursery,
+ (uintptr_t)obj)))
+ return; /* common case: it was an old object, nothing to do */
- if (pforwarded_array[0] == GCWORD_MOVED) {
- *pobj = pforwarded_array[1]; /* already moved */
- return;
+ /* a young object outside the nursery */
+ nobj = obj;
+ tree_delete_item(STM_PSEGMENT->young_outside_nursery, (uintptr_t)nobj);
+ nobj_sync_now = minor_record_large_overflow_object(nobj);
}
- /* We need to make a copy of this object. It goes either in
- a largemalloc.c-managed area, or if it's small enough, in
- one of the small uniform pages from gcpage.c.
- */
- char *realobj = REAL_ADDRESS(STM_SEGMENT->segment_base, obj);
- size_t size = stmcb_size_rounded_up((struct object_s *)realobj);
- object_t *nobj;
- uintptr_t nobj_sync_now;
-
- if (1 /*size >= GC_MEDIUM_REQUEST*/) {
-
- /* case 1: object is not small enough.
- Ask gcpage.c for an allocation via largemalloc. */
- char *allocated = allocate_outside_nursery_large(size);
- nobj = (object_t *)(allocated - stm_object_pages);
- nobj_sync_now = (uintptr_t)nobj;
-
- /* Copy the object */
- char *realnobj = REAL_ADDRESS(STM_SEGMENT->segment_base, nobj);
- memcpy(realnobj, realobj, size);
-
- if (STM_PSEGMENT->minor_collect_will_commit_now)
- nobj_sync_now |= FLAG_SYNC_LARGE_NOW;
- else
- LIST_APPEND(STM_PSEGMENT->large_overflow_objects, nobj);
- }
- else {
- /* case "small enough" */
- abort(); //...
- }
-
+ /* Set the overflow_number if nedeed */
assert((nobj->stm_flags & -GCFLAG_OVERFLOW_NUMBER_bit0) == 0);
if (!STM_PSEGMENT->minor_collect_will_commit_now) {
nobj->stm_flags |= STM_PSEGMENT->overflow_number;
}
- /* Done copying the object. */
- //dprintf(("\t\t\t\t\t%p -> %p\n", obj, nobj));
- pforwarded_array[0] = GCWORD_MOVED;
- pforwarded_array[1] = nobj;
- *pobj = nobj;
-
/* Must trace the object later */
LIST_APPEND(STM_PSEGMENT->objects_pointing_to_nursery, nobj_sync_now);
}
More information about the pypy-commit
mailing list