From 7299a70ba81d0565eca42f439da198d6192ac39e Mon Sep 17 00:00:00 2001 From: Mark Probst Date: Thu, 30 Apr 2015 14:27:36 -0700 Subject: [PATCH] [sgen] Make the client interface work again. --- mono/metadata/sgen-mono.c | 36 ++++++++++++++++++++++++++++++++++ mono/sgen/sgen-client.h | 7 +++++++ mono/sgen/sgen-fin-weak-hash.c | 34 +++----------------------------- 3 files changed, 46 insertions(+), 31 deletions(-) diff --git a/mono/metadata/sgen-mono.c b/mono/metadata/sgen-mono.c index 30e6427d26d..1b9b7ca17ba 100644 --- a/mono/metadata/sgen-mono.c +++ b/mono/metadata/sgen-mono.c @@ -2663,6 +2663,42 @@ mono_gchandle_set_target (guint32 gchandle, MonoObject *obj) sgen_gchandle_set_target (gchandle, obj); } +void +sgen_client_gchandle_created (int handle_type, GCObject *obj, guint32 handle) +{ +#ifndef DISABLE_PERFCOUNTERS + mono_perfcounters->gc_num_handles++; +#endif + mono_profiler_gc_handle (MONO_PROFILER_GC_HANDLE_CREATED, handle_type, handle, obj); +} + +void +sgen_client_gchandle_destroyed (int handle_type, guint32 handle) +{ +#ifndef DISABLE_PERFCOUNTERS + mono_perfcounters->gc_num_handles--; +#endif + mono_profiler_gc_handle (MONO_PROFILER_GC_HANDLE_DESTROYED, handle_type, handle, NULL); +} + +void +sgen_client_ensure_weak_gchandles_accessible (void) +{ + /* + * During the second bridge processing step the world is + * running again. That step processes all weak links once + * more to null those that refer to dead objects. Before that + * is completed, those links must not be followed, so we + * conservatively wait for bridge processing when any weak + * link is dereferenced. + */ + /* FIXME: A GC can occur after this check fails, in which case we + * should wait for bridge processing but would fail to do so. + */ + if (G_UNLIKELY (bridge_processing_in_progress)) + mono_gc_wait_for_bridge_processing (); +} + gboolean mono_gc_set_allow_synchronous_major (gboolean flag) { diff --git a/mono/sgen/sgen-client.h b/mono/sgen/sgen-client.h index a8ccd9e0912..5c803b50ae5 100644 --- a/mono/sgen/sgen-client.h +++ b/mono/sgen/sgen-client.h @@ -93,6 +93,13 @@ void sgen_client_clear_unreachable_ephemerons (ScanCopyContext ctx); gpointer sgen_client_default_metadata (void); gpointer sgen_client_metadata_for_object (GCObject *obj); +/* + * No action required. + */ +void sgen_client_gchandle_created (int handle_type, GCObject *obj, guint32 handle); +void sgen_client_gchandle_destroyed (int handle_type, guint32 handle); +void sgen_client_ensure_weak_gchandles_accessible (void); + /* * This is called for objects that are larger than one card. If it's possible to scan only * parts of the object based on which cards are marked, do so and return TRUE. Otherwise, diff --git a/mono/sgen/sgen-fin-weak-hash.c b/mono/sgen/sgen-fin-weak-hash.c index cc467219a6f..184305e412e 100644 --- a/mono/sgen/sgen-fin-weak-hash.c +++ b/mono/sgen/sgen-fin-weak-hash.c @@ -34,10 +34,6 @@ #include "mono/sgen/sgen-client.h" #include "mono/sgen/gc-internal-agnostic.h" #include "mono/utils/mono-membar.h" -// FIXME: remove! -#ifndef SGEN_WITHOUT_MONO -#include "mono/metadata/gc-internal.h" -#endif #define ptr_in_nursery sgen_ptr_in_nursery @@ -861,11 +857,8 @@ retry: binary_protocol_dislink_add ((gpointer)&handles->entries [bucket] [offset], obj, track); /* Ensure that a GC handle cannot be given to another thread without the slot having been set. */ mono_memory_write_barrier (); -#ifndef DISABLE_PERFCOUNTERS - mono_perfcounters->gc_num_handles++; -#endif res = MONO_GC_HANDLE (index, handles->type); - mono_profiler_gc_handle (MONO_PROFILER_GC_HANDLE_CREATED, handles->type, res, obj); + sgen_client_gchandle_created (handles->type, obj, res); return res; } @@ -961,24 +954,6 @@ mono_gchandle_new_weakref (GCObject *obj, gboolean track_resurrection) return alloc_handle (gc_handles_for_type (track_resurrection ? HANDLE_WEAK_TRACK : HANDLE_WEAK), obj, track_resurrection); } -static void -ensure_weak_links_accessible (void) -{ - /* - * During the second bridge processing step the world is - * running again. That step processes all weak links once - * more to null those that refer to dead objects. Before that - * is completed, those links must not be followed, so we - * conservatively wait for bridge processing when any weak - * link is dereferenced. - */ - /* FIXME: A GC can occur after this check fails, in which case we - * should wait for bridge processing but would fail to do so. - */ - if (G_UNLIKELY (bridge_processing_in_progress)) - mono_gc_wait_for_bridge_processing (); -} - static GCObject * link_get (volatile gpointer *link_addr, gboolean is_weak) { @@ -1013,7 +988,7 @@ retry: mono_memory_barrier (); if (is_weak) - ensure_weak_links_accessible (); + sgen_client_ensure_weak_gchandles_accessible (); if ((void*)*link_addr_volatile != ptr) goto retry; @@ -1134,10 +1109,7 @@ mono_gchandle_free (guint32 gchandle) } else { /* print a warning? */ } -#ifndef DISABLE_PERFCOUNTERS - mono_perfcounters->gc_num_handles--; -#endif - mono_profiler_gc_handle (MONO_PROFILER_GC_HANDLE_DESTROYED, handles->type, gchandle, NULL); + sgen_client_gchandle_destroyed (handles->type, gchandle); } /* -- 2.25.1