[sgen] Inline mono_sgen_par_object_get_size().
authorMark Probst <mark.probst@gmail.com>
Wed, 28 Jul 2010 02:00:36 +0000 (04:00 +0200)
committerMark Probst <mark.probst@gmail.com>
Wed, 4 Aug 2010 01:56:10 +0000 (03:56 +0200)
Define mono_sgen_par_object_get_size() as an inline function in
sgen-gc.h.

mono/metadata/sgen-gc.c
mono/metadata/sgen-gc.h

index 9ed8254c3648a8d8f5c7e1e87a82b30448740da6..956e8fc42570e1ccaf185d2bfadd059e02149e0b 100644 (file)
@@ -449,38 +449,6 @@ safe_name (void* obj)
        return vt->klass->name;
 }
 
-/*
- * This function can be called on an object whose first word, the
- * vtable field, is not intact.  This is necessary for the parallel
- * collector.
- *
- * FIXME: put this in an internal header
- */
-guint
-mono_sgen_par_object_get_size (MonoVTable *vtable, MonoObject* o)
-{
-       MonoClass *klass = vtable->klass;
-       /*
-        * We depend on mono_string_length_fast and
-        * mono_array_length_fast not using the object's vtable.
-        */
-       if (klass == mono_defaults.string_class) {
-               return sizeof (MonoString) + 2 * mono_string_length_fast ((MonoString*) o) + 2;
-       } else if (klass->rank) {
-               MonoArray *array = (MonoArray*)o;
-               size_t size = sizeof (MonoArray) + klass->sizes.element_size * mono_array_length_fast (array);
-               if (G_UNLIKELY (array->bounds)) {
-                       size += sizeof (mono_array_size_t) - 1;
-                       size &= ~(sizeof (mono_array_size_t) - 1);
-                       size += sizeof (MonoArrayBounds) * klass->rank;
-               }
-               return size;
-       } else {
-               /* from a created object: the class must be inited already */
-               return klass->instance_size;
-       }
-}
-
 #define safe_object_get_size   mono_sgen_safe_object_get_size
 
 /*
index 961dbd5236c8d8cf46400dadab8b87e0c9f60971..f38882a9f9a78379511ef8f8e6d08dc572b8fcfa 100644 (file)
@@ -31,6 +31,7 @@
 #include <signal.h>
 #include <mono/utils/mono-compiler.h>
 #include <mono/metadata/class-internals.h>
+#include <mono/metadata/object-internals.h>
 
 /* #define SGEN_PARALLEL_MARK */
 
@@ -631,11 +632,6 @@ void mono_sgen_pin_stats_register_object (char *obj, size_t size);
 
 void mono_sgen_add_to_global_remset (gpointer ptr) MONO_INTERNAL;
 
-/* FIXME: this should be inlined */
-guint mono_sgen_par_object_get_size (MonoVTable *vtable, MonoObject* o) MONO_INTERNAL;
-
-#define mono_sgen_safe_object_get_size(o)              mono_sgen_par_object_get_size ((MonoVTable*)SGEN_LOAD_VTABLE ((o)), (o))
-
 typedef struct _SgenMajorCollector SgenMajorCollector;
 struct _SgenMajorCollector {
        size_t section_size;
@@ -671,4 +667,36 @@ struct _SgenMajorCollector {
 void mono_sgen_marksweep_init (SgenMajorCollector *collector, int nursery_bits, char *nursery_start, char *nursery_end) MONO_INTERNAL;
 void mono_sgen_copying_init (SgenMajorCollector *collector, int the_nursery_bits, char *the_nursery_start, char *the_nursery_end) MONO_INTERNAL;
 
+/*
+ * This function can be called on an object whose first word, the
+ * vtable field, is not intact.  This is necessary for the parallel
+ * collector.
+ */
+static inline guint
+mono_sgen_par_object_get_size (MonoVTable *vtable, MonoObject* o)
+{
+       MonoClass *klass = vtable->klass;
+       /*
+        * We depend on mono_string_length_fast and
+        * mono_array_length_fast not using the object's vtable.
+        */
+       if (klass == mono_defaults.string_class) {
+               return sizeof (MonoString) + 2 * mono_string_length_fast ((MonoString*) o) + 2;
+       } else if (klass->rank) {
+               MonoArray *array = (MonoArray*)o;
+               size_t size = sizeof (MonoArray) + klass->sizes.element_size * mono_array_length_fast (array);
+               if (G_UNLIKELY (array->bounds)) {
+                       size += sizeof (mono_array_size_t) - 1;
+                       size &= ~(sizeof (mono_array_size_t) - 1);
+                       size += sizeof (MonoArrayBounds) * klass->rank;
+               }
+               return size;
+       } else {
+               /* from a created object: the class must be inited already */
+               return klass->instance_size;
+       }
+}
+
+#define mono_sgen_safe_object_get_size(o)              mono_sgen_par_object_get_size ((MonoVTable*)SGEN_LOAD_VTABLE ((o)), (o))
+
 #endif /* __MONO_SGENGC_H__ */