Compare commits

...
Author SHA1 Message Date
Alex Rønne Petersen ff9d2c4ffc [runtime] Fix profiler reporting of object allocations.
Previously, not all allocations would be reported. For example, when using
managed allocators, we would go through mono_gc_alloc_obj () and friends which
did not call mono_profiler_allocation (). There were also some functions in
object.c which did not call it.

For SGen, we now report allocations in the client code, which is where all
object allocations ultimately end up going whether or not we're using managed
allocators. For Boehm, we call mono_profiler_allocation () in the object.c
macros. (This is not pretty, but will go away when Boehm does.)

Conflicts:

	mono/metadata/profiler-private.h
	mono/metadata/sgen-mono.c
2015-05-02 01:35:55 +02:00
4 changed files with 15 additions and 27 deletions

No files matched your search

+6 -24
View File
@@ -47,17 +47,18 @@
#ifdef HAVE_BOEHM_GC
#define NEED_TO_ZERO_PTRFREE 1
#define ALLOC_PTRFREE(obj,vt,size) do { (obj) = GC_MALLOC_ATOMIC ((size)); (obj)->vtable = (vt); (obj)->synchronisation = NULL;} while (0)
#define ALLOC_OBJECT(obj,vt,size) do { (obj) = GC_MALLOC ((size)); (obj)->vtable = (vt);} while (0)
#define ALLOC_PTRFREE(obj,vt,size) do { (obj) = GC_MALLOC_ATOMIC ((size)); (obj)->vtable = (vt); (obj)->synchronisation = NULL; mono_profiler_allocation ((obj)); } while (0)
#define ALLOC_OBJECT(obj,vt,size) do { (obj) = GC_MALLOC ((size)); (obj)->vtable = (vt); mono_profiler_allocation ((obj)); } while (0)
#ifdef HAVE_GC_GCJ_MALLOC
#define GC_NO_DESCRIPTOR ((gpointer)(0 | GC_DS_LENGTH))
#define ALLOC_TYPED(dest,size,type) do { (dest) = GC_GCJ_MALLOC ((size),(type)); } while (0)
#define ALLOC_TYPED(dest,size,type) do { (dest) = GC_GCJ_MALLOC ((size),(type)); mono_profiler_allocation ((dest)); } while (0)
#else
#define GC_NO_DESCRIPTOR (NULL)
#define ALLOC_TYPED(dest,size,type) do { (dest) = GC_MALLOC ((size)); *(gpointer*)dest = (type);} while (0)
#define ALLOC_TYPED(dest,size,type) do { (dest) = GC_MALLOC ((size)); *(gpointer*)dest = (type); mono_profiler_allocation ((dest)); } while (0)
#endif
#else
#ifdef HAVE_SGEN_GC
/* allocations are reported to the profiler in the GC functions */
#define GC_NO_DESCRIPTOR (NULL)
#define ALLOC_PTRFREE(obj,vt,size) do { (obj) = mono_gc_alloc_obj (vt, size);} while (0)
#define ALLOC_OBJECT(obj,vt,size) do { (obj) = mono_gc_alloc_obj (vt, size);} while (0)
@@ -91,8 +92,6 @@ mono_string_to_utf8_internal (MonoMemPool *mp, MonoImage *image, MonoString *s,
#define ldstr_unlock() mono_mutex_unlock (&ldstr_section)
static mono_mutex_t ldstr_section;
static gboolean profile_allocs = TRUE;
void
mono_runtime_object_init (MonoObject *this)
{
@@ -4411,7 +4410,7 @@ mono_object_allocate_ptrfree (size_t size, MonoVTable *vtable)
static inline void *
mono_object_allocate_spec (size_t size, MonoVTable *vtable)
{
void *o;
MonoObject *o;
ALLOC_TYPED (o, size, vtable);
return o;
@@ -4515,8 +4514,6 @@ mono_object_new_alloc_specific (MonoVTable *vtable)
if (G_UNLIKELY (vtable->klass->has_finalize))
mono_object_register_finalizer (o);
if (G_UNLIKELY (profile_allocs))
mono_profiler_allocation (o, vtable->klass);
return o;
}
@@ -4575,9 +4572,6 @@ mono_class_get_allocation_ftn (MonoVTable *vtable, gboolean for_box, gboolean *p
{
*pass_size_in_words = FALSE;
if (!(mono_profiler_get_events () & MONO_PROFILE_ALLOCATIONS))
profile_allocs = FALSE;
if (mono_class_has_finalizer (vtable->klass) || mono_class_is_marshalbyref (vtable->klass) || (mono_profiler_get_events () & MONO_PROFILE_ALLOCATIONS))
return mono_object_new_specific;
@@ -4654,8 +4648,6 @@ mono_object_clone (MonoObject *obj)
/* do not copy the sync state */
mono_gc_memmove_atomic ((char*)o + sizeof (MonoObject), (char*)obj + sizeof (MonoObject), size - sizeof (MonoObject));
}
if (G_UNLIKELY (profile_allocs))
mono_profiler_allocation (o, obj->vtable->klass);
if (obj->vtable->klass->has_finalize)
mono_object_register_finalizer (o);
@@ -4900,9 +4892,6 @@ mono_array_new_full (MonoDomain *domain, MonoClass *array_class, uintptr_t *leng
}
}
if (G_UNLIKELY (profile_allocs))
mono_profiler_allocation (o, array_class);
return array;
}
@@ -4970,9 +4959,6 @@ mono_array_new_specific (MonoVTable *vtable, uintptr_t n)
ao = (MonoArray*)o;
#endif
if (G_UNLIKELY (profile_allocs))
mono_profiler_allocation (o, vtable->klass);
return ao;
}
@@ -5063,8 +5049,6 @@ mono_string_new_size (MonoDomain *domain, gint32 len)
#if NEED_TO_ZERO_PTRFREE
s->chars [len] = 0;
#endif
if (G_UNLIKELY (profile_allocs))
mono_profiler_allocation ((MonoObject*)s, mono_defaults.string_class);
return s;
}
@@ -5183,8 +5167,6 @@ mono_value_box (MonoDomain *domain, MonoClass *class, gpointer value)
return NULL;
size = mono_class_instance_size (class);
res = mono_object_new_alloc_specific (vtable);
if (G_UNLIKELY (profile_allocs))
mono_profiler_allocation (res, class);
size = size - sizeof (MonoObject);
+1 -1
View File
@@ -34,7 +34,7 @@ void mono_profiler_method_start_invoke (MonoMethod *method) MONO_INTERNAL;
void mono_profiler_method_end_invoke (MonoMethod *method) MONO_INTERNAL;
void mono_profiler_code_transition (MonoMethod *method, int result) MONO_INTERNAL;
void mono_profiler_allocation (MonoObject *obj, MonoClass *klass) MONO_INTERNAL;
void mono_profiler_allocation (MonoObject *obj) MONO_INTERNAL;
void mono_profiler_monitor_event (MonoObject *obj, MonoProfilerMonitorEvent event) MONO_INTERNAL;
void mono_profiler_stat_hit (guchar *ip, void *context) MONO_INTERNAL;
void mono_profiler_stat_call_chain (int call_chain_depth, guchar **ips, void *context) MONO_INTERNAL;
+2 -2
View File
@@ -499,12 +499,12 @@ mono_profiler_code_transition (MonoMethod *method, int result)
}
void
mono_profiler_allocation (MonoObject *obj, MonoClass *klass)
mono_profiler_allocation (MonoObject *obj)
{
ProfilerDesc *prof;
for (prof = prof_list; prof; prof = prof->next) {
if ((prof->events & MONO_PROFILE_ALLOCATIONS) && prof->allocation_cb)
prof->allocation_cb (prof->profiler, obj, klass);
prof->allocation_cb (prof->profiler, obj, obj->vtable->klass);
}
}
+6
View File
@@ -505,6 +505,7 @@ mono_gc_alloc_obj (MonoVTable *vtable, size_t size)
UNLOCK_GC;
if (G_UNLIKELY (!res))
return mono_gc_out_of_memory (size);
mono_profiler_allocation ((MonoObject *) res);
return res;
}
@@ -544,6 +545,7 @@ mono_gc_alloc_vector (MonoVTable *vtable, size_t size, uintptr_t max_length)
done:
SGEN_ASSERT (6, SGEN_ALIGN_UP (size) == SGEN_ALIGN_UP (sgen_par_object_get_size (vtable, (MonoObject*)arr)), "Vector has incorrect size.");
mono_profiler_allocation (&arr->obj);
return arr;
}
@@ -589,6 +591,7 @@ mono_gc_alloc_array (MonoVTable *vtable, size_t size, uintptr_t max_length, uint
done:
SGEN_ASSERT (6, SGEN_ALIGN_UP (size) == SGEN_ALIGN_UP (sgen_par_object_get_size (vtable, (MonoObject*)arr)), "Array has incorrect size.");
mono_profiler_allocation (&arr->obj);
return arr;
}
@@ -625,6 +628,7 @@ mono_gc_alloc_string (MonoVTable *vtable, size_t size, gint32 len)
UNLOCK_GC;
mono_profiler_allocation (&str->object);
return str;
}
@@ -659,6 +663,7 @@ mono_gc_alloc_pinned_obj (MonoVTable *vtable, size_t size)
binary_protocol_alloc_pinned (p, vtable, size);
}
UNLOCK_GC;
mono_profiler_allocation ((MonoObject *) p);
return p;
}
@@ -678,6 +683,7 @@ mono_gc_alloc_mature (MonoVTable *vtable)
if (G_UNLIKELY (vtable->klass->has_finalize))
mono_object_register_finalizer ((MonoObject*)res);
mono_profiler_allocation ((MonoObject *) res);
return res;
}