Precise mode in Boehm GC under Mono isn't just GC_MALLOC_ATOMIC
. It's only true for arrays of fundamental types.
For managed types, GC_gcj_malloc
is used. Mono's compiler generates an object descriptor for every managed type and it then simply calls GC_gcj_malloc
with an argument of size, and a pointer to the managed type's descriptor. Boehm GC then refers to the descriptor during mark phase to trace the managed pointers.
You will end up with just the root pointers sitting on the stack as raw pointers (GC_gcj_malloc
returns a void* and there's no way to tell the GC where the pointers are on the stack via some sort of a stack descriptor prior to GC collect). This is the reason Mono (prior to SGen) says they scan the stack in conservative mode.
If you want to implement this under C++, you won't be able to simply rely on the C++ compiler to generate the object descriptor for you. What I envisioned a long time ago was to write an intermediate compiler that parses all your C++ header files for class definitions that have been marked as managed class (e.g. _ref class MyManagedObject
where _ref
is simply a #define
to nothing) and generate a header file containing those object descriptors. You would then use the GC_make_descriptor
and GC_malloc_explicitly_typed
functions to allocate your objects in precise mode rather than GC_gcj_malloc
as you would not have control over how your C++ compiler allocates its vtable.
*EDIT: See Managed C++ for GCC (open source GPL v3).