Skip to content

Commit

Permalink
[sgen] DTrace probes for finalisers and weak links.
Browse files Browse the repository at this point in the history
  • Loading branch information
schani committed Dec 9, 2012
1 parent 52d490b commit 5842ec6
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 1 deletion.
5 changes: 5 additions & 0 deletions data/mono.d
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ provider mono {
probe gc__major__swept (uintptr_t addr, uintptr_t len);

probe gc__obj__pinned (uintptr_t addr, uintptr_t size, char *ns_name, char *class_name, int generation);

probe gc__finalize__enqueue (uintptr_t addr, uintptr_t size, char *ns_name, char *class_name, int generation, int is_critical);
probe gc__finalize__invoke (uintptr_t addr, uintptr_t size, char *ns_name, char *class_name);

probe gc__weak__update (uintptr_t ref_addr, uintptr_t old_addr, uintptr_t new_addr, uintptr_t size, char *ns_name, char *class_name, int track);
};

#pragma D attributes Evolving/Evolving/Common provider mono provider
Expand Down
6 changes: 6 additions & 0 deletions mono/metadata/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <mono/utils/mono-semaphore.h>
#include <mono/utils/mono-memory-model.h>
#include <mono/utils/mono-counters.h>
#include <mono/utils/dtrace.h>

#ifndef HOST_WIN32
#include <pthread.h>
Expand Down Expand Up @@ -227,6 +228,11 @@ mono_gc_run_finalize (void *obj, void *data)

mono_runtime_class_init (o->vtable);

if (G_UNLIKELY (MONO_GC_FINALIZE_INVOKE_ENABLED ())) {
MONO_GC_FINALIZE_INVOKE ((unsigned long)o, mono_object_get_size (o),
o->vtable->klass->name_space, o->vtable->klass->name);
}

runtime_invoke (o, NULL, &exc, NULL);

if (exc)
Expand Down
12 changes: 12 additions & 0 deletions mono/metadata/sgen-fin-weak-hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

#include "metadata/sgen-gc.h"
#include "metadata/sgen-gray.h"
#include "utils/dtrace.h"

#define ptr_in_nursery sgen_ptr_in_nursery

Expand Down Expand Up @@ -583,6 +584,17 @@ sgen_process_dislink_stage_entries (void)
void
sgen_register_disappearing_link (MonoObject *obj, void **link, gboolean track, gboolean in_gc)
{
if (MONO_GC_WEAK_UPDATE_ENABLED ()) {
MonoVTable *vt = obj ? (MonoVTable*)SGEN_LOAD_VTABLE (obj) : NULL;
MONO_GC_WEAK_UPDATE ((mword)link,
*link ? (mword)DISLINK_OBJECT (link) : (mword)0,
(mword)obj,
obj ? (mword)sgen_safe_object_get_size (obj) : (mword)0,
obj ? vt->klass->name_space : NULL,
obj ? vt->klass->name : NULL,
track ? 1 : 0);
}

if (obj)
*link = HIDE_POINTER (obj, track);
else
Expand Down
10 changes: 9 additions & 1 deletion mono/metadata/sgen-gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -3377,14 +3377,22 @@ void
sgen_queue_finalization_entry (MonoObject *obj)
{
FinalizeReadyEntry *entry = sgen_alloc_internal (INTERNAL_MEM_FINALIZE_READY_ENTRY);
gboolean critical = has_critical_finalizer (obj);
entry->object = obj;
if (has_critical_finalizer (obj)) {
if (critical) {
entry->next = critical_fin_list;
critical_fin_list = entry;
} else {
entry->next = fin_ready_list;
fin_ready_list = entry;
}

if (G_UNLIKELY (MONO_GC_FINALIZE_ENQUEUE_ENABLED ())) {
int gen = sgen_ptr_in_nursery (obj) ? GENERATION_NURSERY : GENERATION_OLD;
MonoVTable *vt = (MonoVTable*)LOAD_VTABLE (obj);
MONO_GC_FINALIZE_ENQUEUE ((mword)obj, sgen_safe_object_get_size (obj),
vt->klass->name_space, vt->klass->name, gen, critical);
}
}

static inline int
Expand Down
11 changes: 11 additions & 0 deletions mono/utils/dtrace.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,17 @@
#define MONO_GC_OBJ_PINNED(addr,size,ns_name,class_name,generation)
#define MONO_GC_OBJ_PINNED_ENABLED() (0)


#define MONO_GC_FINALIZE_ENQUEUE(addr,size,ns_name,class_name,generation,is_critical)
#define MONO_GC_FINALIZE_ENQUEUE_ENABLED() (0)

#define MONO_GC_FINALIZE_INVOKE(addr,size,ns_name,class_name)
#define MONO_GC_FINALIZE_INVOKE_ENABLED() (0)


#define MONO_GC_WEAK_UPDATE(ref_addr,old_addr,new_addr,size,ns_name,class_name,track)
#define MONO_GC_WEAK_UPDATE_ENABLED() (0)

#endif

#endif

0 comments on commit 5842ec6

Please sign in to comment.