[gc] Register a critical region when executing managed allocators.
authorAlex Rønne Petersen <alexrp@xamarin.com>
Thu, 14 Apr 2016 02:12:57 +0000 (04:12 +0200)
committerAlex Rønne Petersen <alexrp@xamarin.com>
Tue, 31 May 2016 21:40:08 +0000 (23:40 +0200)
commit755056dd25052d1105aa64707775d60ca82ac62f
treea97bd0e91ca70375197c44623cf64a4da753552c
parent9dc91ef0d388c0375d9fcb37d26f3c18b1ee3efd
[gc] Register a critical region when executing managed allocators.

Previously, if we stopped a thread and it had a stack looking like this:

    ...
    profiler_signal_handler
    <signal handler called>
    managed_allocator
    ...

We would fail to identify the fact that we've just interrupted a thread that's
in a managed allocator (uninterruptible code) because we only look at the very
latest instruction pointer of the thread, which will be pointing into
profiler_signal_handler or some other function called by it. So we would
happily continue along with the STW process and proceed to doing the actual GC,
where we would see a broken heap.

We could solve this by unwinding the stack and checking all frames, but that's
complicated and error-prone. Instead, register a critical region while the
managed allocator. This way, if we don't identify it by instruction pointer, we
will identify it by the fact that the thread is in a critical region.
13 files changed:
mono/cil/cil-opcodes.xml
mono/cil/opcode.def
mono/metadata/boehm-gc.c
mono/metadata/gc-internals.h
mono/metadata/null-gc.c
mono/metadata/object-offsets.h
mono/metadata/sgen-client-mono.h
mono/metadata/sgen-mono.c
mono/mini/aot-compiler.c
mono/mini/aot-runtime.c
mono/mini/method-to-ir.c
mono/sgen/sgen-alloc.c
mono/utils/mono-tls.h