[sgen] Enable binary protocol by default, make the heavy stuff optional.
authorMark Probst <mark.probst@gmail.com>
Tue, 7 Jan 2014 20:18:15 +0000 (12:18 -0800)
committerMark Probst <mark.probst@gmail.com>
Wed, 16 Apr 2014 21:18:12 +0000 (14:18 -0700)
mono/metadata/sgen-conf.h
mono/metadata/sgen-gc.c
mono/metadata/sgen-gc.h
mono/metadata/sgen-pinning.c
mono/metadata/sgen-protocol.c
mono/metadata/sgen-protocol.h
mono/metadata/sgen-scan-object.h

index d6be54c47109f4eee2cd84d182f1846aa06400af..d22d92130ea4591deaf22bb44e7e96fdf598d91a 100644 (file)
@@ -57,10 +57,11 @@ typedef guint64 mword;
 
 /*
  * The binary protocol enables logging a lot of the GC ativity in a way that is not very
- * intrusive and produce a compact file that can be searched using a custom tool.
- *
+ * intrusive and produces a compact file that can be searched using a custom tool.  This
+ * option enables very fine-grained binary protocol events, which will make the GC a tiny
+ * bit less efficient even if no binary protocol file is generated.
  */
-//#define SGEN_BINARY_PROTOCOL
+//#define SGEN_HEAVY_BINARY_PROTOCOL
 
 /*
  * This enables checks whenever objects are enqueued in gray queues.
@@ -97,7 +98,7 @@ typedef guint64 mword;
  */
 //#define SGEN_OBJECT_LAYOUT_STATISTICS
 
-#ifndef SGEN_BINARY_PROTOCOL
+#ifndef SGEN_HEAVY_BINARY_PROTOCOL
 #ifndef HEAVY_STATISTICS
 #define MANAGED_ALLOCATION
 #ifndef XDOMAIN_CHECKS_IN_WBARRIER
index 54e9ee24fc8fa36d0a420cd2fba0d333d6d8a6a7..b93baf90c53a7ba74b1956ea8b4a8ba76196ff8f 100644 (file)
@@ -4295,8 +4295,8 @@ mono_gc_wbarrier_arrayref_copy (gpointer dest_ptr, gpointer src_ptr, int count)
                return;
        }
 
-#ifdef SGEN_BINARY_PROTOCOL
-       {
+#ifdef SGEN_HEAVY_BINARY_PROTOCOL
+       if (binary_protocol_is_heavy_enabled ()) {
                int i;
                for (i = 0; i < count; ++i) {
                        gpointer dest = (gpointer*)dest_ptr + i;
@@ -4441,7 +4441,7 @@ void mono_gc_wbarrier_value_copy_bitmap (gpointer _dest, gpointer _src, int size
        }
 }
 
-#ifdef SGEN_BINARY_PROTOCOL
+#ifdef SGEN_HEAVY_BINARY_PROTOCOL
 #undef HANDLE_PTR
 #define HANDLE_PTR(ptr,obj) do {                                       \
                gpointer o = *(gpointer*)(ptr);                         \
@@ -4474,8 +4474,8 @@ mono_gc_wbarrier_value_copy (gpointer dest, gpointer src, int count, MonoClass *
                return;
        }
 
-#ifdef SGEN_BINARY_PROTOCOL
-       {
+#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) {
@@ -4508,8 +4508,9 @@ mono_gc_wbarrier_object_copy (MonoObject* obj, MonoObject *src)
                return; 
        }
 
-#ifdef SGEN_BINARY_PROTOCOL
-       scan_object_for_binary_protocol_copy_wbarrier (obj, (char*)src, (mword) src->vtable->gc_descr);
+#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);
@@ -5270,11 +5271,9 @@ mono_gc_base_init (void)
                                        fprintf (heap_dump_file, "<sgen-dump>\n");
                                        do_pin_stats = TRUE;
                                }
-#ifdef SGEN_BINARY_PROTOCOL
                        } else if (g_str_has_prefix (opt, "binary-protocol=")) {
                                char *filename = strchr (opt, '=') + 1;
                                binary_protocol_init (filename);
-#endif
                        } else {
                                sgen_env_var_error (MONO_GC_DEBUG_NAME, "Ignoring.", "Unknown option `%s`.", opt);
 
@@ -5302,9 +5301,7 @@ mono_gc_base_init (void)
                                fprintf (stderr, "  print-allowance\n");
                                fprintf (stderr, "  print-pinning\n");
                                fprintf (stderr, "  heap-dump=<filename>\n");
-#ifdef SGEN_BINARY_PROTOCOL
                                fprintf (stderr, "  binary-protocol=<filename>\n");
-#endif
                                fprintf (stderr, "\n");
 
                                usage_printed = TRUE;
index b4b98778bfaf24106cd2b3e91e6f319fb5d0f802..64faded2d5a0b76d2e6f2a4dbaf46af04fa69d4f 100644 (file)
@@ -442,7 +442,7 @@ enum {
        GENERATION_MAX
 };
 
-#ifdef SGEN_BINARY_PROTOCOL
+#ifdef SGEN_HEAVY_BINARY_PROTOCOL
 #define BINARY_PROTOCOL_ARG(x) ,x
 #else
 #define BINARY_PROTOCOL_ARG(x)
index 9ada778bc7460520a599b808cd156eaaa734d48e..d0a38ef426eb94b8b90c82bcedd4490e3fc35ce2 100644 (file)
@@ -310,10 +310,8 @@ sgen_cement_lookup_or_register (char *obj)
                        MONO_GC_OBJ_CEMENTED ((mword)obj, sgen_safe_object_get_size ((MonoObject*)obj),
                                        vt->klass->name_space, vt->klass->name);
                }
-#ifdef SGEN_BINARY_PROTOCOL
                binary_protocol_cement (obj, (gpointer)SGEN_LOAD_VTABLE (obj),
                                sgen_safe_object_get_size ((MonoObject*)obj));
-#endif
        }
 
        return FALSE;
index c41df40339f927a4f140231ec7317e9f020a468c..1a9919266d5f8b952046665487386d76c27ca8ab 100644 (file)
@@ -29,8 +29,6 @@
 #include "utils/mono-mmap.h"
 #include "utils/mono-threads.h"
 
-#ifdef SGEN_BINARY_PROTOCOL
-
 /* If not null, dump binary protocol to this file */
 static FILE *binary_protocol_file = NULL;
 
@@ -232,6 +230,72 @@ binary_protocol_collection_end (int index, int generation)
        protocol_entry (SGEN_PROTOCOL_COLLECTION_END, &entry, sizeof (SGenProtocolCollection));
 }
 
+void
+binary_protocol_thread_suspend (gpointer thread, gpointer stopped_ip)
+{
+       SGenProtocolThreadSuspend entry = { thread, stopped_ip };
+       protocol_entry (SGEN_PROTOCOL_THREAD_SUSPEND, &entry, sizeof (SGenProtocolThreadSuspend));
+}
+
+void
+binary_protocol_thread_restart (gpointer thread)
+{
+       SGenProtocolThreadRestart entry = { thread };
+       protocol_entry (SGEN_PROTOCOL_THREAD_RESTART, &entry, sizeof (SGenProtocolThreadRestart));
+}
+
+void
+binary_protocol_thread_register (gpointer thread)
+{
+       SGenProtocolThreadRegister entry = { thread };
+       protocol_entry (SGEN_PROTOCOL_THREAD_REGISTER, &entry, sizeof (SGenProtocolThreadRegister));
+
+}
+
+void
+binary_protocol_thread_unregister (gpointer thread)
+{
+       SGenProtocolThreadUnregister entry = { thread };
+       protocol_entry (SGEN_PROTOCOL_THREAD_UNREGISTER, &entry, sizeof (SGenProtocolThreadUnregister));
+
+}
+
+void
+binary_protocol_missing_remset (gpointer obj, gpointer obj_vtable, int offset, gpointer value, gpointer value_vtable, int value_pinned)
+{
+       SGenProtocolMissingRemset entry = { obj, obj_vtable, offset, value, value_vtable, value_pinned };
+       protocol_entry (SGEN_PROTOCOL_MISSING_REMSET, &entry, sizeof (SGenProtocolMissingRemset));
+
+}
+
+void
+binary_protocol_cement (gpointer obj, gpointer vtable, int size)
+{
+       SGenProtocolCement entry = { obj, vtable, size };
+       protocol_entry (SGEN_PROTOCOL_CEMENT, &entry, sizeof (SGenProtocolCement));
+}
+
+void
+binary_protocol_cement_reset (void)
+{
+       protocol_entry (SGEN_PROTOCOL_CEMENT_RESET, NULL, 0);
+}
+
+void
+binary_protocol_domain_unload_begin (gpointer domain)
+{
+       SGenProtocolDomainUnload entry = { domain };
+       protocol_entry (SGEN_PROTOCOL_DOMAIN_UNLOAD_BEGIN, &entry, sizeof (SGenProtocolDomainUnload));
+}
+
+void
+binary_protocol_domain_unload_end (gpointer domain)
+{
+       SGenProtocolDomainUnload entry = { domain };
+       protocol_entry (SGEN_PROTOCOL_DOMAIN_UNLOAD_END, &entry, sizeof (SGenProtocolDomainUnload));
+}
+
+#ifdef SGEN_HEAVY_BINARY_PROTOCOL
 void
 binary_protocol_alloc (gpointer obj, gpointer vtable, int size)
 {
@@ -323,44 +387,6 @@ binary_protocol_empty (gpointer start, int size)
        protocol_entry (SGEN_PROTOCOL_EMPTY, &entry, sizeof (SGenProtocolEmpty));
 }
 
-void
-binary_protocol_thread_suspend (gpointer thread, gpointer stopped_ip)
-{
-       SGenProtocolThreadSuspend entry = { thread, stopped_ip };
-       protocol_entry (SGEN_PROTOCOL_THREAD_SUSPEND, &entry, sizeof (SGenProtocolThreadSuspend));
-}
-
-void
-binary_protocol_thread_restart (gpointer thread)
-{
-       SGenProtocolThreadRestart entry = { thread };
-       protocol_entry (SGEN_PROTOCOL_THREAD_RESTART, &entry, sizeof (SGenProtocolThreadRestart));
-}
-
-void
-binary_protocol_thread_register (gpointer thread)
-{
-       SGenProtocolThreadRegister entry = { thread };
-       protocol_entry (SGEN_PROTOCOL_THREAD_REGISTER, &entry, sizeof (SGenProtocolThreadRegister));
-
-}
-
-void
-binary_protocol_thread_unregister (gpointer thread)
-{
-       SGenProtocolThreadUnregister entry = { thread };
-       protocol_entry (SGEN_PROTOCOL_THREAD_UNREGISTER, &entry, sizeof (SGenProtocolThreadUnregister));
-
-}
-
-void
-binary_protocol_missing_remset (gpointer obj, gpointer obj_vtable, int offset, gpointer value, gpointer value_vtable, int value_pinned)
-{
-       SGenProtocolMissingRemset entry = { obj, obj_vtable, offset, value, value_vtable, value_pinned };
-       protocol_entry (SGEN_PROTOCOL_MISSING_REMSET, &entry, sizeof (SGenProtocolMissingRemset));
-
-}
-
 void
 binary_protocol_card_scan (gpointer start, int size)
 {
@@ -368,19 +394,6 @@ binary_protocol_card_scan (gpointer start, int size)
        protocol_entry (SGEN_PROTOCOL_CARD_SCAN, &entry, sizeof (SGenProtocolCardScan));
 }
 
-void
-binary_protocol_cement (gpointer obj, gpointer vtable, int size)
-{
-       SGenProtocolCement entry = { obj, vtable, size };
-       protocol_entry (SGEN_PROTOCOL_CEMENT, &entry, sizeof (SGenProtocolCement));
-}
-
-void
-binary_protocol_cement_reset (void)
-{
-       protocol_entry (SGEN_PROTOCOL_CEMENT_RESET, NULL, 0);
-}
-
 void
 binary_protocol_dislink_update (gpointer link, gpointer obj, int track, int staged)
 {
@@ -401,21 +414,6 @@ binary_protocol_dislink_process_staged (gpointer link, gpointer obj, int index)
        SGenProtocolDislinkProcessStaged entry = { link, obj, index };
        protocol_entry (SGEN_PROTOCOL_DISLINK_PROCESS_STAGED, &entry, sizeof (SGenProtocolDislinkProcessStaged));
 }
-
-void
-binary_protocol_domain_unload_begin (gpointer domain)
-{
-       SGenProtocolDomainUnload entry = { domain };
-       protocol_entry (SGEN_PROTOCOL_DOMAIN_UNLOAD_BEGIN, &entry, sizeof (SGenProtocolDomainUnload));
-}
-
-void
-binary_protocol_domain_unload_end (gpointer domain)
-{
-       SGenProtocolDomainUnload entry = { domain };
-       protocol_entry (SGEN_PROTOCOL_DOMAIN_UNLOAD_END, &entry, sizeof (SGenProtocolDomainUnload));
-}
-
 #endif
 
 #endif /* HAVE_SGEN_GC */
index 18355075cbf4c34c0ada8769957c4a88046ddfea..d5a9383a27bfaff9ed916b06eeb33bf18abb591b 100644 (file)
@@ -22,8 +22,6 @@
 
 #include "sgen-gc.h"
 
-#ifdef SGEN_BINARY_PROTOCOL
-
 enum {
        SGEN_PROTOCOL_COLLECTION_FORCE,
        SGEN_PROTOCOL_COLLECTION_BEGIN,
@@ -191,7 +189,7 @@ typedef struct {
        gpointer domain;
 } SGenProtocolDomainUnload;
 
-/* missing: finalizers, dislinks, roots, non-store wbarriers */
+/* missing: finalizers, roots, non-store wbarriers */
 
 void binary_protocol_init (const char *filename) MONO_INTERNAL;
 gboolean binary_protocol_is_enabled (void) MONO_INTERNAL;
@@ -201,6 +199,24 @@ void binary_protocol_flush_buffers (gboolean force) MONO_INTERNAL;
 void binary_protocol_collection_force (int generation) MONO_INTERNAL;
 void binary_protocol_collection_begin (int index, int generation) MONO_INTERNAL;
 void binary_protocol_collection_end (int index, int generation) MONO_INTERNAL;
+
+void binary_protocol_thread_suspend (gpointer thread, gpointer stopped_ip) MONO_INTERNAL;
+void binary_protocol_thread_restart (gpointer thread) MONO_INTERNAL;
+void binary_protocol_thread_register (gpointer thread) MONO_INTERNAL;
+void binary_protocol_thread_unregister (gpointer thread) MONO_INTERNAL;
+void binary_protocol_missing_remset (gpointer obj, gpointer obj_vtable, int offset,
+               gpointer value, gpointer value_vtable, int value_pinned) MONO_INTERNAL;
+
+void binary_protocol_cement (gpointer ptr, gpointer vtable, int size) MONO_INTERNAL;
+void binary_protocol_cement_reset (void) MONO_INTERNAL;
+
+void binary_protocol_domain_unload_begin (gpointer domain) MONO_INTERNAL;
+void binary_protocol_domain_unload_end (gpointer domain) MONO_INTERNAL;
+
+#ifdef SGEN_HEAVY_BINARY_PROTOCOL
+
+#define binary_protocol_is_heavy_enabled()     binary_protocol_is_enabled ()
+
 void binary_protocol_alloc (gpointer obj, gpointer vtable, int size) MONO_INTERNAL;
 void binary_protocol_alloc_pinned (gpointer obj, gpointer vtable, int size) MONO_INTERNAL;
 void binary_protocol_alloc_degraded (gpointer obj, gpointer vtable, int size) MONO_INTERNAL;
@@ -214,29 +230,15 @@ void binary_protocol_global_remset (gpointer ptr, gpointer value, gpointer value
 void binary_protocol_ptr_update (gpointer ptr, gpointer old_value, gpointer new_value, gpointer vtable, int size) MONO_INTERNAL;
 void binary_protocol_cleanup (gpointer ptr, gpointer vtable, int size) MONO_INTERNAL;
 void binary_protocol_empty (gpointer start, int size) MONO_INTERNAL;
-void binary_protocol_thread_suspend (gpointer thread, gpointer stopped_ip) MONO_INTERNAL;
-void binary_protocol_thread_restart (gpointer thread) MONO_INTERNAL;
-void binary_protocol_thread_register (gpointer thread) MONO_INTERNAL;
-void binary_protocol_thread_unregister (gpointer thread) MONO_INTERNAL;
-void binary_protocol_missing_remset (gpointer obj, gpointer obj_vtable, int offset,
-               gpointer value, gpointer value_vtable, int value_pinned) MONO_INTERNAL;
 void binary_protocol_card_scan (gpointer start, int size) MONO_INTERNAL;
-void binary_protocol_cement (gpointer ptr, gpointer vtable, int size) MONO_INTERNAL;
-void binary_protocol_cement_reset (void) MONO_INTERNAL;
 void binary_protocol_dislink_update (gpointer link, gpointer obj, int track, int staged) MONO_INTERNAL;
 void binary_protocol_dislink_update_staged (gpointer link, gpointer obj, int track, int index) MONO_INTERNAL;
 void binary_protocol_dislink_process_staged (gpointer link, gpointer obj, int index) MONO_INTERNAL;
-void binary_protocol_domain_unload_begin (gpointer domain) MONO_INTERNAL;
-void binary_protocol_domain_unload_end (gpointer domain) MONO_INTERNAL;
 
 #else
 
-#define binary_protocol_is_enabled()   FALSE
+#define binary_protocol_is_heavy_enabled()     FALSE
 
-#define binary_protocol_flush_buffers(force)
-#define binary_protocol_collection_force(generation)
-#define binary_protocol_collection_begin(index, generation)
-#define binary_protocol_collection_end(index, generation)
 #define binary_protocol_alloc(obj, vtable, size)
 #define binary_protocol_alloc_pinned(obj, vtable, size)
 #define binary_protocol_alloc_degraded(obj, vtable, size)
@@ -250,18 +252,9 @@ void binary_protocol_domain_unload_end (gpointer domain) MONO_INTERNAL;
 #define binary_protocol_ptr_update(ptr, old_value, new_value, vtable, size)
 #define binary_protocol_cleanup(ptr, vtable, size)
 #define binary_protocol_empty(start, size)
-#define binary_protocol_thread_suspend(thread, ip)
-#define binary_protocol_thread_restart(thread)
-#define binary_protocol_thread_register(thread)
-#define binary_protocol_thread_unregister(thread)
-#define binary_protocol_missing_remset(obj, obj_vtable, offset, value, value_vtable, value_pinned)
 #define binary_protocol_card_scan(start, size)
-#define binary_protocol_cement(ptr, vtable, size)
-#define binary_protocol_cement_reset()
 #define binary_protocol_dislink_update(link,obj,track,staged)
 #define binary_protocol_dislink_update_staged(link,obj,track,index)
 #define binary_protocol_dislink_process_staged(link,obj,index)
-#define binary_protocol_domain_unload_begin(domain)
-#define binary_protocol_domain_unload_end(domain)
 
 #endif
index f3c2dff92c8d68f58855181a5e1f44d33d27ad4d..7cbe57a6c83e82f9c59d6dc7345120d2e2bf7540 100644 (file)
        /* gcc should be smart enough to remove the bounds check, but it isn't:( */
        desc = vt->desc;
 
-#if defined(SGEN_BINARY_PROTOCOL) && defined(SCAN_OBJECT_PROTOCOL)
+#if defined(SGEN_HEAVY_BINARY_PROTOCOL) && defined(SCAN_OBJECT_PROTOCOL)
        binary_protocol_scan_begin (start, vt, sgen_safe_object_get_size ((MonoObject*)start));
 #endif
 #else
-#if defined(SGEN_BINARY_PROTOCOL) && defined(SCAN_OBJECT_PROTOCOL)
+#if defined(SGEN_HEAVY_BINARY_PROTOCOL) && defined(SCAN_OBJECT_PROTOCOL)
        binary_protocol_scan_vtype_begin (start + sizeof (MonoObject), size);
 #endif
 #endif