Mon Apr 29 12:47:36 CEST 2002 Paolo Molaro <lupus@ximian.com>
[mono.git] / mono / metadata / object.c
index ca398914abd47958f2e0ea532c396c3f11f6a582..a7f45a0a635b177922699ee6fb9432cb2cd5abde 100644 (file)
@@ -16,6 +16,7 @@
 #include <mono/metadata/tokentype.h>
 #include <mono/metadata/loader.h>
 #include <mono/metadata/object.h>
+#include <mono/metadata/gc.h>
 #include <mono/metadata/appdomain.h>
 #if HAVE_BOEHM_GC
 #include <gc/gc.h>
@@ -339,7 +340,7 @@ mono_runtime_invoke_array (MonoMethod *method, void *obj, MonoArray *params)
        int i;
                
        if (NULL != params) {
-               pa = alloca (sizeof (gpointer) * mono_array_length (params);
+               pa = alloca (sizeof (gpointer) * mono_array_length (params));
                for (i = 0; i < mono_array_length (params); i++) {
                        if (sig->params [i]->byref) {
                                /* nothing to do */
@@ -393,7 +394,8 @@ void *
 mono_object_allocate (size_t size)
 {
 #if HAVE_BOEHM_GC
-       void *o = GC_debug_malloc (size, "object", 1);
+       /* if this is changed to GC_debug_malloc(), we need to change also metadata/gc.c */
+       void *o = GC_malloc (size);
 #else
        void *o = calloc (1, size);
 #endif
@@ -447,6 +449,9 @@ mono_object_new_specific (MonoVTable *vtable)
 
        mono_stats.new_object_count++;          /* thread safe? */
 
+       /* if the returned pointer is not the same as the address returned by GC_malloc(), 
+        * we need to change also metadata/gc.c to take into account the new offset.
+        */
        if (vtable->klass->ghcimpl)
                o = mono_object_allocate (vtable->klass->instance_size);
        else {
@@ -456,6 +461,8 @@ mono_object_new_specific (MonoVTable *vtable)
                o = (MonoObject *)(++t);
        }
        o->vtable = vtable;
+       if (vtable->klass->has_finalize)
+               mono_object_register_finalizer (o);
        
        return o;
 }
@@ -496,6 +503,8 @@ mono_object_clone (MonoObject *obj)
 
        memcpy (o, obj, size);
 
+       if (obj->vtable->klass->has_finalize)
+               mono_object_register_finalizer (o);
        return o;
 }
 
@@ -570,7 +579,7 @@ mono_array_new_full (MonoDomain *domain, MonoClass *array_class,
                len = lengths [0];
        } else {
        #if HAVE_BOEHM_GC
-               bounds = GC_debug_malloc (sizeof (MonoArrayBounds) * array_class->rank, "bounds", 0);
+               bounds = GC_malloc (sizeof (MonoArrayBounds) * array_class->rank);
        #else
                bounds = g_malloc0 (sizeof (MonoArrayBounds) * array_class->rank);
        #endif
@@ -681,7 +690,17 @@ mono_string_new_size (MonoDomain *domain, gint32 len)
 {
        MonoString *s;
 
-       s = (MonoString*)mono_object_allocate (sizeof (MonoString) + (len * 2));
+       /* 
+        * enable to get a good speedup: we still need to figure out
+        * how the sync structure is freed.
+        */
+#ifdef 0 && HAVE_BOEHM_GC
+       s = GC_malloc_atomic (sizeof (MonoString) + ((len + 1) * 2));
+       s->object.synchronisation = 0;
+       mono_string_chars (s) [len] = 0;
+#else
+       s = (MonoString*)mono_object_allocate (sizeof (MonoString) + ((len + 1) * 2));
+#endif
        if (!s)
                G_BREAKPOINT ();
 
@@ -785,6 +804,8 @@ mono_value_box (MonoDomain *domain, MonoClass *class, gpointer value)
 
        memcpy ((char *)res + sizeof (MonoObject), value, size);
 
+       if (class->has_finalize)
+               mono_object_register_finalizer (res);
        return res;
 }