From f374d5162cf2351baa954fda39ae231cc8b8f113 Mon Sep 17 00:00:00 2001 From: Zoltan Varga Date: Sun, 14 Oct 2012 21:49:00 +0200 Subject: Add more info for collections/thread suspends to the sgen binary protocol. --- mono/metadata/sgen-gc.c | 5 +++-- mono/metadata/sgen-os-mach.c | 5 +++++ mono/metadata/sgen-protocol.c | 12 +++++++++--- mono/metadata/sgen-protocol.h | 13 ++++++++++--- tools/sgen/sgen-grep-binprot.c | 9 ++++++++- 5 files changed, 35 insertions(+), 9 deletions(-) diff --git a/mono/metadata/sgen-gc.c b/mono/metadata/sgen-gc.c index 78e1b566fbd..e967a34de51 100644 --- a/mono/metadata/sgen-gc.c +++ b/mono/metadata/sgen-gc.c @@ -2377,7 +2377,7 @@ collect_nursery (void) reset_pinned_from_failed_allocation (); - binary_protocol_collection (GENERATION_NURSERY); + binary_protocol_collection (stat_minor_gcs, GENERATION_NURSERY); check_scan_starts (); sgen_nursery_alloc_prepare_for_minor (); @@ -2622,7 +2622,7 @@ major_do_collection (const char *reason) //count_ref_nonref_objs (); //consistency_check (); - binary_protocol_collection (GENERATION_OLD); + binary_protocol_collection (stat_major_gcs, GENERATION_OLD); check_scan_starts (); sgen_gray_object_queue_init (&gray_queue); @@ -3481,6 +3481,7 @@ restart_threads_until_none_in_managed_allocator (void) if (!info->thread_is_dying && (!info->stack_start || info->in_critical_region || is_ip_in_managed_allocator (info->stopped_domain, info->stopped_ip))) { binary_protocol_thread_restart ((gpointer)mono_thread_info_get_tid (info)); + DEBUG (3, fprintf (gc_debug_file, "thread %p resumed.\n", (void*)info->info.native_handle)); result = sgen_resume_thread (info); if (result) { ++restart_count; diff --git a/mono/metadata/sgen-os-mach.c b/mono/metadata/sgen-os-mach.c index c99debf9943..1186a0dd49c 100644 --- a/mono/metadata/sgen-os-mach.c +++ b/mono/metadata/sgen-os-mach.c @@ -35,6 +35,7 @@ #include #include "metadata/sgen-gc.h" #include "metadata/sgen-archdep.h" +#include "metadata/sgen-protocol.h" #include "metadata/object-internals.h" #include "metadata/gc-internal.h" @@ -97,6 +98,10 @@ sgen_suspend_thread (SgenThreadInfo *info) if (mono_gc_get_gc_callbacks ()->thread_suspend_func) mono_gc_get_gc_callbacks ()->thread_suspend_func (info->runtime_data, &ctx, NULL); + DEBUG (1, fprintf (gc_debug_file, "thread %p stopped at %p stack_start=%p\n", (void*)info->info.native_handle, info->stopped_ip, info->stack_start)); + + binary_protocol_thread_suspend ((gpointer)mono_thread_info_get_tid (info), info->stopped_ip); + return TRUE; } diff --git a/mono/metadata/sgen-protocol.c b/mono/metadata/sgen-protocol.c index 12395fb1451..9a585c4ecc5 100644 --- a/mono/metadata/sgen-protocol.c +++ b/mono/metadata/sgen-protocol.c @@ -153,9 +153,9 @@ protocol_entry (unsigned char type, gpointer data, int size) } void -binary_protocol_collection (int generation) +binary_protocol_collection (int index, int generation) { - SGenProtocolCollection entry = { generation }; + SGenProtocolCollection entry = { index, generation }; binary_protocol_flush_buffers (FALSE); protocol_entry (SGEN_PROTOCOL_COLLECTION, &entry, sizeof (SGenProtocolCollection)); } @@ -237,12 +237,18 @@ 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 diff --git a/mono/metadata/sgen-protocol.h b/mono/metadata/sgen-protocol.h index d82eecb99ea..29373afffdc 100644 --- a/mono/metadata/sgen-protocol.h +++ b/mono/metadata/sgen-protocol.h @@ -37,6 +37,7 @@ enum { SGEN_PROTOCOL_PTR_UPDATE, SGEN_PROTOCOL_CLEANUP, SGEN_PROTOCOL_EMPTY, + SGEN_PROTOCOL_THREAD_SUSPEND, SGEN_PROTOCOL_THREAD_RESTART, SGEN_PROTOCOL_THREAD_REGISTER, SGEN_PROTOCOL_THREAD_UNREGISTER, @@ -46,7 +47,7 @@ enum { }; typedef struct { - int generation; + int index, generation; } SGenProtocolCollection; typedef struct { @@ -105,6 +106,10 @@ typedef struct { int size; } SGenProtocolEmpty; +typedef struct { + gpointer thread, stopped_ip; +} SGenProtocolThreadSuspend; + typedef struct { gpointer thread; } SGenProtocolThreadRestart; @@ -133,7 +138,7 @@ gboolean binary_protocol_is_enabled (void) MONO_INTERNAL; void binary_protocol_flush_buffers (gboolean force) MONO_INTERNAL; -void binary_protocol_collection (int generation) MONO_INTERNAL; +void binary_protocol_collection (int index, int generation) MONO_INTERNAL; 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; @@ -145,6 +150,7 @@ 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; @@ -156,7 +162,7 @@ void binary_protocol_missing_remset (gpointer obj, gpointer obj_vtable, int offs #define binary_protocol_is_enabled() FALSE #define binary_protocol_flush_buffers(force) -#define binary_protocol_collection(generation) +#define binary_protocol_collection(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) @@ -168,6 +174,7 @@ void binary_protocol_missing_remset (gpointer obj, gpointer obj_vtable, int offs #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) diff --git a/tools/sgen/sgen-grep-binprot.c b/tools/sgen/sgen-grep-binprot.c index 4e41e8a3573..2195f4ff3fb 100644 --- a/tools/sgen/sgen-grep-binprot.c +++ b/tools/sgen/sgen-grep-binprot.c @@ -31,6 +31,7 @@ read_entry (FILE *in, void **data) case SGEN_PROTOCOL_PTR_UPDATE: size = sizeof (SGenProtocolPtrUpdate); break; case SGEN_PROTOCOL_CLEANUP: size = sizeof (SGenProtocolCleanup); break; case SGEN_PROTOCOL_EMPTY: size = sizeof (SGenProtocolEmpty); break; + case SGEN_PROTOCOL_THREAD_SUSPEND: size = sizeof (SGenProtocolThreadSuspend); break; case SGEN_PROTOCOL_THREAD_RESTART: size = sizeof (SGenProtocolThreadRestart); break; case SGEN_PROTOCOL_THREAD_REGISTER: size = sizeof (SGenProtocolThreadRegister); break; case SGEN_PROTOCOL_THREAD_UNREGISTER: size = sizeof (SGenProtocolThreadUnregister); break; @@ -51,7 +52,7 @@ print_entry (int type, void *data) switch (type) { case SGEN_PROTOCOL_COLLECTION: { SGenProtocolCollection *entry = data; - printf ("collection generation %d\n", entry->generation); + printf ("collection %d generation %d\n", entry->index, entry->generation); break; } case SGEN_PROTOCOL_ALLOC: { @@ -110,6 +111,11 @@ print_entry (int type, void *data) printf ("empty start %p size %d\n", entry->start, entry->size); break; } + case SGEN_PROTOCOL_THREAD_SUSPEND: { + SGenProtocolThreadSuspend *entry = data; + printf ("thread_suspend thread %p ip %p\n", entry->thread, entry->stopped_ip); + break; + } case SGEN_PROTOCOL_THREAD_RESTART: { SGenProtocolThreadRestart *entry = data; printf ("thread_restart thread %p\n", entry->thread); @@ -147,6 +153,7 @@ is_match (gpointer ptr, int type, void *data) { switch (type) { case SGEN_PROTOCOL_COLLECTION: + case SGEN_PROTOCOL_THREAD_SUSPEND: case SGEN_PROTOCOL_THREAD_RESTART: case SGEN_PROTOCOL_THREAD_REGISTER: case SGEN_PROTOCOL_THREAD_UNREGISTER: -- cgit v1.2.3