[sgen] Move Mono-specific wbarriers to `sgen-mono.c`.
authorMark Probst <mark.probst@gmail.com>
Sun, 14 Dec 2014 01:40:55 +0000 (17:40 -0800)
committerMark Probst <mark.probst@gmail.com>
Wed, 29 Apr 2015 17:57:42 +0000 (10:57 -0700)
mono/metadata/Makefile.am
mono/metadata/sgen-gc.c
mono/metadata/sgen-mono.c [new file with mode: 0644]

index e4039ef1adaae888d2b43bfc3f77da40a2045200..9ea16570b2d5d85177eeb064d444a0f65365cc15 100644 (file)
@@ -293,7 +293,8 @@ sgen_sources = \
        sgen-qsort.h    \
        sgen-thread-pool.c      \
        sgen-thread-pool.h      \
-       sgen-tagged-pointer.h
+       sgen-tagged-pointer.h   \
+       sgen-mono.c
 
 libmonoruntime_la_SOURCES = $(common_sources) $(gc_dependent_sources) $(null_gc_sources) $(boehm_sources)
 libmonoruntime_la_CFLAGS = $(BOEHM_DEFINES)
index 39e82aed49a20cfa0a7a91019edbf31309c3f27c..e31c6beff9f6bac1876b081484b9b2f93daf00aa 100644 (file)
@@ -3614,17 +3614,6 @@ scan_thread_data (void *start_nursery, void *end_nursery, gboolean precise, Scan
        } END_FOREACH_THREAD
 }
 
-static gboolean
-ptr_on_stack (void *ptr)
-{
-       gpointer stack_start = &stack_start;
-       SgenThreadInfo *info = mono_thread_info_current ();
-
-       if (ptr >= stack_start && ptr < (gpointer)info->stack_end)
-               return TRUE;
-       return FALSE;
-}
-
 static void*
 sgen_thread_register (SgenThreadInfo* info, void *addr)
 {
@@ -3883,11 +3872,6 @@ mono_gc_wbarrier_generic_nostore (gpointer ptr)
        if (obj)
                binary_protocol_wbarrier (ptr, obj, (gpointer)LOAD_VTABLE (obj));
 
-       if (ptr_in_nursery (ptr) || ptr_on_stack (ptr)) {
-               SGEN_LOG (8, "Skipping remset at %p", ptr);
-               return;
-       }
-
        /*
         * We need to record old->old pointer locations for the
         * concurrent collector.
@@ -3947,82 +3931,6 @@ void mono_gc_wbarrier_value_copy_bitmap (gpointer _dest, gpointer _src, int size
        }
 }
 
-#ifdef SGEN_HEAVY_BINARY_PROTOCOL
-#undef HANDLE_PTR
-#define HANDLE_PTR(ptr,obj) do {                                       \
-               gpointer o = *(gpointer*)(ptr);                         \
-               if ((o)) {                                              \
-                       gpointer d = ((char*)dest) + ((char*)(ptr) - (char*)(obj)); \
-                       binary_protocol_wbarrier (d, o, (gpointer) LOAD_VTABLE (o)); \
-               }                                                       \
-       } while (0)
-
-static void
-scan_object_for_binary_protocol_copy_wbarrier (gpointer dest, char *start, mword desc)
-{
-#define SCAN_OBJECT_NOVTABLE
-#include "sgen-scan-object.h"
-}
-#endif
-
-void
-mono_gc_wbarrier_value_copy (gpointer dest, gpointer src, int count, MonoClass *klass)
-{
-       HEAVY_STAT (++stat_wbarrier_value_copy);
-       g_assert (klass->valuetype);
-
-       SGEN_LOG (8, "Adding value remset at %p, count %d, descr %p for class %s (%p)", dest, count, klass->gc_descr, klass->name, klass);
-
-       if (ptr_in_nursery (dest) || ptr_on_stack (dest) || !SGEN_CLASS_HAS_REFERENCES (klass)) {
-               size_t element_size = mono_class_value_size (klass, NULL);
-               size_t size = count * element_size;
-               mono_gc_memmove_atomic (dest, src, size);               
-               return;
-       }
-
-#ifdef SGEN_HEAVY_BINARY_PROTOCOL
-       if (binary_protocol_is_heavy_enabled ()) {
-               size_t element_size = mono_class_value_size (klass, NULL);
-               int i;
-               for (i = 0; i < count; ++i) {
-                       scan_object_for_binary_protocol_copy_wbarrier ((char*)dest + i * element_size,
-                                       (char*)src + i * element_size - sizeof (MonoObject),
-                                       (mword) klass->gc_descr);
-               }
-       }
-#endif
-
-       remset.wbarrier_value_copy (dest, src, count, klass);
-}
-
-/**
- * mono_gc_wbarrier_object_copy:
- *
- * Write barrier to call when obj is the result of a clone or copy of an object.
- */
-void
-mono_gc_wbarrier_object_copy (MonoObject* obj, MonoObject *src)
-{
-       int size;
-
-       HEAVY_STAT (++stat_wbarrier_object_copy);
-
-       if (ptr_in_nursery (obj) || ptr_on_stack (obj)) {
-               size = mono_object_class (obj)->instance_size;
-               mono_gc_memmove_aligned ((char*)obj + sizeof (MonoObject), (char*)src + sizeof (MonoObject),
-                               size - sizeof (MonoObject));
-               return; 
-       }
-
-#ifdef SGEN_HEAVY_BINARY_PROTOCOL
-       if (binary_protocol_is_heavy_enabled ())
-               scan_object_for_binary_protocol_copy_wbarrier (obj, (char*)src, (mword) src->vtable->gc_descr);
-#endif
-
-       remset.wbarrier_object_copy (obj, src);
-}
-
-
 /*
  * ######################################################################
  * ########  Other mono public interface functions.
diff --git a/mono/metadata/sgen-mono.c b/mono/metadata/sgen-mono.c
new file mode 100644 (file)
index 0000000..6c57bab
--- /dev/null
@@ -0,0 +1,112 @@
+/*
+ * sgen-mono.c: SGen features specific to Mono.
+ *
+ * Copyright (C) 2014 Xamarin Inc
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License 2.0 as published by the Free Software Foundation;
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License 2.0 along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include "config.h"
+#ifdef HAVE_SGEN_GC
+
+#include "metadata/sgen-gc.h"
+#include "metadata/sgen-protocol.h"
+
+static gboolean
+ptr_on_stack (void *ptr)
+{
+       gpointer stack_start = &stack_start;
+       SgenThreadInfo *info = mono_thread_info_current ();
+
+       if (ptr >= stack_start && ptr < (gpointer)info->stack_end)
+               return TRUE;
+       return FALSE;
+}
+
+#ifdef SGEN_HEAVY_BINARY_PROTOCOL
+#undef HANDLE_PTR
+#define HANDLE_PTR(ptr,obj) do {                                       \
+               gpointer o = *(gpointer*)(ptr);                         \
+               if ((o)) {                                              \
+                       gpointer d = ((char*)dest) + ((char*)(ptr) - (char*)(obj)); \
+                       binary_protocol_wbarrier (d, o, (gpointer) SGEN_LOAD_VTABLE (o)); \
+               }                                                       \
+       } while (0)
+
+static void
+scan_object_for_binary_protocol_copy_wbarrier (gpointer dest, char *start, mword desc)
+{
+#define SCAN_OBJECT_NOVTABLE
+#include "sgen-scan-object.h"
+}
+#endif
+
+void
+mono_gc_wbarrier_value_copy (gpointer dest, gpointer src, int count, MonoClass *klass)
+{
+       HEAVY_STAT (++stat_wbarrier_value_copy);
+       g_assert (klass->valuetype);
+
+       SGEN_LOG (8, "Adding value remset at %p, count %d, descr %p for class %s (%p)", dest, count, klass->gc_descr, klass->name, klass);
+
+       if (sgen_ptr_in_nursery (dest) || ptr_on_stack (dest) || !SGEN_CLASS_HAS_REFERENCES (klass)) {
+               size_t element_size = mono_class_value_size (klass, NULL);
+               size_t size = count * element_size;
+               mono_gc_memmove_atomic (dest, src, size);               
+               return;
+       }
+
+#ifdef SGEN_HEAVY_BINARY_PROTOCOL
+       if (binary_protocol_is_heavy_enabled ()) {
+               size_t element_size = mono_class_value_size (klass, NULL);
+               int i;
+               for (i = 0; i < count; ++i) {
+                       scan_object_for_binary_protocol_copy_wbarrier ((char*)dest + i * element_size,
+                                       (char*)src + i * element_size - sizeof (MonoObject),
+                                       (mword) klass->gc_descr);
+               }
+       }
+#endif
+
+       sgen_get_remset ()->wbarrier_value_copy (dest, src, count, klass);
+}
+
+/**
+ * mono_gc_wbarrier_object_copy:
+ *
+ * Write barrier to call when obj is the result of a clone or copy of an object.
+ */
+void
+mono_gc_wbarrier_object_copy (MonoObject* obj, MonoObject *src)
+{
+       int size;
+
+       HEAVY_STAT (++stat_wbarrier_object_copy);
+
+       if (sgen_ptr_in_nursery (obj) || ptr_on_stack (obj)) {
+               size = mono_object_class (obj)->instance_size;
+               mono_gc_memmove_aligned ((char*)obj + sizeof (MonoObject), (char*)src + sizeof (MonoObject),
+                               size - sizeof (MonoObject));
+               return; 
+       }
+
+#ifdef SGEN_HEAVY_BINARY_PROTOCOL
+       if (binary_protocol_is_heavy_enabled ())
+               scan_object_for_binary_protocol_copy_wbarrier (obj, (char*)src, (mword) src->vtable->gc_descr);
+#endif
+
+       sgen_get_remset ()->wbarrier_object_copy (obj, src);
+}
+
+#endif