Repository navigation
Closed
Labels
Milestone
Description
we have hit the sgen proble when gc collection, the whole call stack show below :
> mono-2.0-sgen.dll!copy_object_no_checks(_MonoObject * obj, _SgenGrayQueue * queue) Line 69 C
[Inline Frame] mono-2.0-sgen.dll!major_copy_or_mark_object_with_evacuation(_MonoObject * * obj, _MonoObject *) Line 86 C
mono-2.0-sgen.dll!major_scan_object_with_evacuation(_MonoObject * full_object, unsigned __int64 desc, _SgenGrayQueue * queue) Line 64 C
[Inline Frame] mono-2.0-sgen.dll!SGEN_LOAD_VTABLE_UNCHECKED(_MonoObject *) Line 23 C
[Inline Frame] mono-2.0-sgen.dll!sgen_safe_object_get_size(_MonoObject *) Line 757 C
mono-2.0-sgen.dll!sgen_cardtable_scan_object(_MonoObject * obj, unsigned __int64 block_obj_size, unsigned char * cards, ScanCopyContext ctx) Line 594 C
mono-2.0-sgen.dll!scan_card_table_for_block(_MSBlockInfo * block, CardTableScanType scan_type, ScanCopyContext ctx) Line 2625 C
mono-2.0-sgen.dll!major_scan_card_table(CardTableScanType scan_type, ScanCopyContext ctx, int job_index, int job_split_count, int block_count) Line 2667 C
mono-2.0-sgen.dll!job_scan_major_mod_union_card_table(void * worker_data_untyped, _SgenThreadPoolJob * job) Line 1483 C
mono-2.0-sgen.dll!sgen_workers_enqueue_job(int generation, _SgenThreadPoolJob * job, int enqueue) Line 185 C
mono-2.0-sgen.dll!major_copy_or_mark_from_roots(_SgenGrayQueue * gc_thread_gray_queue, unsigned __int64 * old_next_pin_slot, CopyOrMarkFromRootsMode mode, SgenObjectOperations * object_ops_nopar, SgenObjectOperations * object_ops_par) Line 2107 C
mono-2.0-sgen.dll!major_finish_collection(_SgenGrayQueue * gc_thread_gray_queue, const char * reason, int is_overflow, unsigned __int64 old_next_pin_slot, int forced) Line 2212 C
[Inline Frame] mono-2.0-sgen.dll!major_finish_concurrent_collection(int) Line 2460 C
mono-2.0-sgen.dll!sgen_perform_collection_inner(unsigned __int64 requested_size, int generation_to_collect, const char * reason, int forced_serial, int stw) Line 2549 C
[Inline Frame] mono-2.0-sgen.dll!sgen_perform_collection(unsigned __int64) Line 2636 C
mono-2.0-sgen.dll!sgen_ensure_free_space(unsigned __int64 size, int generation) Line 2511 C
mono-2.0-sgen.dll!sgen_alloc_obj_nolock(MonoVTable * vtable, unsigned __int64 size) Line 241 C
mono-2.0-sgen.dll!mono_gc_alloc_vector(MonoVTable * vtable, unsigned __int64 size, unsigned __int64 max_length) Line 1317 C
the vt is nullptr
static MONO_NEVER_INLINE GCObject *
copy_object_no_checks (GCObject *obj, SgenGrayQueue *queue)
{
GCVTable vt = SGEN_LOAD_VTABLE_UNCHECKED (obj);
gboolean has_references = SGEN_VTABLE_HAS_REFERENCES (vt);
how can I figure out the reason about it, can you give some advice or tricks to find what's wrong with it.
Reacted by David Rettenbacher
Activity
srxqds commentedon Apr 25, 2023
or any debug settings?
srxqds commentedon Apr 28, 2023
hi, @lambdageek @BrzVlad can you help me?
are there any settings to help me check this problem?
it's not reproduced stable but more common
BrzVlad commentedon Apr 28, 2023
Seems like a missing write barrier. You could try running with
MONO_GC_DEBUG=check-remset-consistency. This will look up missing cards for major->minor references.Concurrent collector requires also marking cards for major->major references. Running with
MONO_GC_PARAMS=major=marksweepmight make the crash go away.The crash seems to happen during a collection compacting the heap.
MONO_GC_PARAMS=no-evacuationmight also influence the crash.srxqds commentedon Apr 28, 2023
we are using default gc settings
steveisok commentedon Apr 28, 2023
@srxqds what's the environment where you're hitting this? Am I right in assuming .NET 8?
srxqds commentedon Apr 29, 2023
we are using the mono-6.0 version from mono/mono, the dotnet/runtime 7.0 version seams also have this problem.
so I need to find out what's the problem. I will try the advice from @BrzVlad
srxqds commentedon May 2, 2023
hi, @BrzVlad When I use
MONO_GC_DEBUG=check-remset-consistency, it check failedBrzVlad commentedon May 2, 2023
This basically means that, into an object of type
UnrealEngine.Game.UI.UUI_CommonClickat offset of 256 a object reference is stored without the proper write barrier. You could figure out the field from C# definition, although it would be best if you could break in the debugger when this heap check fails so you can investigate the type of the object in the nursery. You would want then to lookup into the code base to see where this storing happens and what goes wrong. Especially if this is done in native code.2 remaining items
srxqds commentedon May 4, 2023
and another check:
we couldn't find the
Entrytype.BrzVlad commentedon May 4, 2023
You can use
mono_value_copyif you want to copy an entire struct (containing also object fields) into another managed object. For your scenario you just need to domono_gc_wbarrier_generic_store (Value, Result).If you are not storing inside GC memory, there is no need for a write barrier. However, you would need to allocate a pinned GC handle for that object (
mono_gchandle_new). Otherwise, since the GC doesn't now that you are holding a reference to it in native code, it can just collect it and that object becomes corrupted.Not sure about this other
Entrytype. Can you attach with native debugger and obtain more information about this object ?srxqds commentedon May 5, 2023
if I do show as below, is there any problem?
I have call two
mono_gc_wbarrier_generic_storecall, will this has any ill effect?srxqds commentedon May 5, 2023
and another solution is set out variable at c# code:
this implement will solve the problem?
@BrzVlad could you give me some time to help me with these two questions?
BrzVlad commentedon May 8, 2023
In the first example, both of the write barriers are incorrect.
mono_gc_wbarrier_generic_store (placeholderPtr , result);is marking some cards that are never scanned by the GC, sinceplaceholderPtris not inside managed heap, so it is equivalent to*(MonoObject**)placeholderPtr = result. Formono_gc_wbarrier_generic_store (Ptr, placeholderPtr );,placeholderPtris not aMonoObject*so it makes no sense to emit a write barrier when storing it anywhere. Also, in this example, nothing might be keepingresultalive.The second solution looks correct.
srxqds commentedon May 8, 2023
how about change
mono_gc_wbarrier_generic_store (Ptr, placeholderPtr );tomono_gc_wbarrier_generic_store (Ptr, *(MonoObject**)placeholderPtr );I have written wrong, if it is ok, we will choose the first solution to solve, because the second solution is make copy twice times.
BrzVlad commentedon May 8, 2023
What is the point of
placeholderPtrthen ? I assume you want to do :Which should also be correct, assuming the result object is kept alive up until being store into
Ptr(which I assume is part of managed object)srxqds commentedon May 8, 2023
yeah, the
ptris from managed object likeout T valuethe
placeholderPtris the intermediate variable, sometimes we need pre-allocated and use it to restore the monoobject* value from the intermediate function call.BrzVlad commentedon Oct 21, 2024
seems like the questions in this issue were addressed