X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mono%2Fsgen%2Fsgen-copy-object.h;h=925af17275dd67a1d2606d0c302b1ba3d7a4c38b;hb=3e6c4f526499a339783cbe427e9916bbd99d7a0e;hp=3579d09bae865777c4bb114fbc6370dd161f54df;hpb=df867664eec6ac0aa851004db0a7cb94ba381602;p=mono.git diff --git a/mono/sgen/sgen-copy-object.h b/mono/sgen/sgen-copy-object.h index 3579d09bae8..925af17275d 100644 --- a/mono/sgen/sgen-copy-object.h +++ b/mono/sgen/sgen-copy-object.h @@ -1,5 +1,6 @@ -/* - * sgen-copy-object.h: This is where objects are copied. +/** + * \file + * This is where objects are copied. * * Copyright 2001-2003 Ximian, Inc * Copyright 2003-2010 Novell, Inc. @@ -39,13 +40,11 @@ extern guint64 stat_nursery_copy_object_failed_pinned; extern guint64 stat_slots_allocated_in_vain; /* - * Copies an object and enqueues it if a queue is given. - * * This function can be used even if the vtable of obj is not valid * anymore, which is the case in the parallel collector. */ static MONO_ALWAYS_INLINE void -par_copy_object_no_checks (char *destination, GCVTable vt, void *obj, mword objsize, SgenGrayQueue *queue) +par_copy_object_no_checks (char *destination, GCVTable vt, void *obj, mword objsize) { sgen_client_pre_copy_checks (destination, vt, obj, objsize); binary_protocol_copy (obj, destination, vt, objsize); @@ -57,14 +56,10 @@ par_copy_object_no_checks (char *destination, GCVTable vt, void *obj, mword objs SGEN_ASSERT (9, sgen_vtable_get_descriptor (vt), "vtable %p has no gc descriptor", vt); sgen_client_update_copied_object (destination, vt, obj, objsize); - obj = destination; - if (queue) { - SGEN_LOG (9, "Enqueuing gray object %p (%s)", obj, sgen_client_vtable_get_name (vt)); - GRAY_OBJECT_ENQUEUE (queue, (GCObject *)obj, sgen_vtable_get_descriptor (vt)); - } } /* + * Copies an object and enqueues it if a queue is given. * This can return OBJ itself on OOM. */ static MONO_NEVER_INLINE GCObject * @@ -73,7 +68,6 @@ copy_object_no_checks (GCObject *obj, SgenGrayQueue *queue) GCVTable vt = SGEN_LOAD_VTABLE_UNCHECKED (obj); gboolean has_references = SGEN_VTABLE_HAS_REFERENCES (vt); mword objsize = SGEN_ALIGN_UP (sgen_client_par_object_get_size (vt, obj)); - /* FIXME: Does this not mark the newly allocated object? */ void *destination = COLLECTOR_SERIAL_ALLOC_FOR_PROMOTION (vt, obj, objsize, has_references); if (G_UNLIKELY (!destination)) { @@ -83,17 +77,67 @@ copy_object_no_checks (GCObject *obj, SgenGrayQueue *queue) return obj; } - if (!has_references) - queue = NULL; - - par_copy_object_no_checks ((char *)destination, vt, obj, objsize, queue); - /* FIXME: mark mod union cards if necessary */ + par_copy_object_no_checks ((char *)destination, vt, obj, objsize); /* set the forwarding pointer */ SGEN_FORWARD_OBJECT (obj, destination); + if (has_references) { + SGEN_LOG (9, "Enqueuing gray object %p (%s)", destination, sgen_client_vtable_get_name (vt)); + GRAY_OBJECT_ENQUEUE_SERIAL (queue, (GCObject *)destination, sgen_vtable_get_descriptor (vt)); + } + return (GCObject *)destination; } +#if defined(COPY_OR_MARK_PARALLEL) +static MONO_NEVER_INLINE GCObject * +copy_object_no_checks_par (GCObject *obj, SgenGrayQueue *queue) +{ + mword vtable_word = *(mword*)obj; + GCObject *destination; + + destination = (GCObject*) SGEN_VTABLE_IS_FORWARDED (vtable_word); + + if (!destination) { + GCVTable vt = (GCVTable) vtable_word; + GCObject *final_destination; + /* + * At this point we know vt is not tagged and we shouldn't access the vtable through obj + * since it could get copied at any time by another thread. + */ + gboolean has_references = SGEN_VTABLE_HAS_REFERENCES (vt); + mword objsize = SGEN_ALIGN_UP (sgen_client_par_object_get_size (vt, obj)); + destination = major_collector.alloc_object_par (vt, objsize, has_references); + + par_copy_object_no_checks ((char*)destination, vt, obj, objsize); + + /* FIXME we might need a membar here so other threads see the vtable before we forward */ + + /* set the forwarding pointer */ + SGEN_FORWARD_OBJECT_PAR (obj, destination, final_destination); + + if (destination == final_destination) { + /* In a racing case, only the worker that allocated the object enqueues it */ + if (has_references) { + SGEN_LOG (9, "Enqueuing gray object %p (%s)", destination, sgen_client_vtable_get_name (vt)); + GRAY_OBJECT_ENQUEUE_PARALLEL (queue, (GCObject *)destination, sgen_vtable_get_descriptor (vt)); + } + } else { + /* + * Unlikely case. Clear the allocated object so it doesn't confuse nursery + * card table scanning, since it can contain old invalid refs. + * FIXME make sure it is not a problem if another threads scans it while we clear + */ + mono_gc_bzero_aligned (destination, objsize); + destination = final_destination; + } + } + + return destination; +} +#endif + #undef COLLECTOR_SERIAL_ALLOC_FOR_PROMOTION #undef collector_pin_object +#undef COPY_OR_MARK_PARALLEL