[Mono-dev] New hook for the profiler API
massi at ximian.com
Tue Jul 22 17:51:36 EDT 2008
I think I really cannot fix the profiler init sequence without adding
another hook to the profiler API, to state that the runtime is
"sufficiently initialized" so that mono_thread_attach can be called
The reason is the following: I must have the profiler initialized and
the writer thread attached before any of the following happens:
- the 1st profiler buffer is empty,
- a true garbage collection occurrs, or
- an image, module or domain is closed (unloaded).
For some reason (which I did not investigate further),
"mono_image_close" is called directly during "mono_assembly_open" when
the argument of "mono_assembly_open" is the xsp2.exe assembly.
So, basically, I must have the profiler writer thread attached before
"mono_assembly_open" returns (on the main assembly).
This is not a race condition problem: I have semaphores in place to
ensure that when I ask the thread to attach, it does so and then I can
go on, so there are no races now.
This is an event ordering issue: I cannot call "mono_thread_attach"
until I have a MonoDomain to pass to it, which should obviously be the
However, "mono_get_root_domain" returns NULL until the root domain has
been fully loaded, which is a bit *after* the profiler receives the
"mono_profiler_appdomain_loaded" event from "mono_domain_create".
I tried to fake it, and use the MonoDomain passed
to "mono_profiler_appdomain_loaded" to attach the thread when I receive
this event, but this does not work, ultimately because
"mono_defaults.thread_class" is still NULL.
In the end, it is OK to call "mono_thread_attach" only after the
runtime is properly initialized, and this is why I should add this hook.
At the beginning I thought the hook should be called at the end of
"mono_init_internal", but some testing showed that after calling
"mini_init" in driver.c is the right place.
BTW, I thought to initialize the profiler after "mono_init" has returned
(to eliminate the problem at the root), and it could work, but that way
the profiler would miss all the root appdomain initialization events,
and therefore would have no reference to the root appdomain (and its
images) when it will be unloaded, which I don't really like...
Note that this additional hook is really needed to fix the profiler, so
it should go in 2.0 too.
The attached patch shows the hook and its call.
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 2821 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20080722/28310131/attachment.bin
More information about the Mono-devel-list