#include <mono/utils/dtrace.h>
#include <mono/utils/gc_wrapper.h>
#include <mono/utils/mono-mutex.h>
+#include <mono/utils/mono-counters.h>
#if HAVE_BOEHM_GC
static void
register_test_toggleref_callback (void);
+#define BOEHM_GC_BIT_FINALIZER_AWARE 1
+static MonoGCFinalizerCallbacks fin_callbacks;
+
static void
mono_gc_warning (char *msg, GC_word arg)
{
if (gc_initialized)
return;
+ mono_counters_init ();
+
/*
* Handle the case when we are called from a thread different from the main thread,
* confusing libgc.
for (ptr = opts; *ptr; ++ptr) {
char *opt = *ptr;
if (g_str_has_prefix (opt, "max-heap-size=")) {
- glong max_heap;
+ size_t max_heap;
opt = strchr (opt, '=') + 1;
if (*opt && mono_gc_parse_environment_string_extract_number (opt, &max_heap)) {
tid = mono_thread_info_get_tid (p);
- mono_threads_add_joinable_thread ((gpointer)tid);
+ if (p->runtime_thread)
+ mono_threads_add_joinable_thread ((gpointer)tid);
}
gboolean
mono_perfcounters->gc_gen0size = heap_size;
}
#endif
- gc_stats.major_gc_time_usecs += (mono_100ns_ticks () - gc_start_time) / 10;
+ gc_stats.major_gc_time += mono_100ns_ticks () - gc_start_time;
mono_trace_message (MONO_TRACE_GC, "gc took %d usecs", (mono_100ns_ticks () - gc_start_time) / 10);
break;
}
bytes_var = mono_mb_add_local (mb, &mono_defaults.int32_class->byval_arg);
if (atype == ATYPE_STRING) {
/* a string alloator method takes the args: (vtable, len) */
- /* bytes = (sizeof (MonoString) + ((len + 1) * 2)); */
+ /* bytes = (offsetof (MonoString, chars) + ((len + 1) * 2)); */
mono_mb_emit_ldarg (mb, 1);
mono_mb_emit_icon (mb, 1);
mono_mb_emit_byte (mb, MONO_CEE_ADD);
}
void *
-mono_gc_scan_object (void *obj)
+mono_gc_scan_object (void *obj, void *gc_data)
{
g_assert_not_reached ();
return NULL;
mono_gc_pthread_exit (void *retval)
{
pthread_exit (retval);
+ g_assert_not_reached ();
}
#endif
guint
mono_gc_get_vtable_bits (MonoClass *class)
{
+ if (fin_callbacks.is_class_finalization_aware) {
+ if (fin_callbacks.is_class_finalization_aware (class))
+ return BOEHM_GC_BIT_FINALIZER_AWARE;
+ }
return 0;
}
return G_MAXINT;
}
+void
+mono_gc_set_string_length (MonoString *str, gint32 new_length)
+{
+ mono_unichar2 *new_end = str->chars + new_length;
+
+ /* zero the discarded string. This null-delimits the string and allows
+ * the space to be reclaimed by SGen. */
+
+ memset (new_end, 0, (str->length - new_length + 1) * sizeof (mono_unichar2));
+ str->length = new_length;
+}
+
gboolean
mono_gc_user_markers_supported (void)
{
mono_gc_toggleref_register_callback (test_toggleref_callback);
}
+static gboolean
+is_finalization_aware (MonoObject *obj)
+{
+ MonoVTable *vt = obj->vtable;
+ return (vt->gc_bits & BOEHM_GC_BIT_FINALIZER_AWARE) == BOEHM_GC_BIT_FINALIZER_AWARE;
+}
+
+static void
+fin_notifier (MonoObject *obj)
+{
+ if (is_finalization_aware (obj))
+ fin_callbacks.object_queued_for_finalization (obj);
+}
+
+void
+mono_gc_register_finalizer_callbacks (MonoGCFinalizerCallbacks *callbacks)
+{
+ if (callbacks->version != MONO_GC_FINALIZER_EXTENSION_VERSION)
+ g_error ("Invalid finalizer callback version. Expected %d but got %d\n", MONO_GC_FINALIZER_EXTENSION_VERSION, callbacks->version);
+
+ fin_callbacks = *callbacks;
+
+ GC_set_finalizer_notify_proc ((void (*) (GC_PTR))fin_notifier);
+}
+
#endif /* no Boehm GC */