Skip to content

Commit

Permalink
[interp] avoid exception checkpoint when in thread is in GC Safe state (
Browse files Browse the repository at this point in the history
mono/mono#16955)

[interp] avoid exception checkpoint when in thread is in GC Safe state 

Usually the interpreter operates in GC Unsafe state. There is an exception however, and that is when it executes a `managed-to-native` wrapper in cooperative (or hybrid) suspend.

The wrapper does essentially:
1. enter GC Safe state via `mono_threads_enter_gc_safe_region_unbalanced`
2. call native function
3. exit GC state via `mono_threads_exit_gc_safe_region_unbalanced`

Usually upon return of a native function call, the interpreter would check for thread interruption and, if applicable, throw an exception.  That, however, would mess with the GC state as the interpreter operates in GC Safe state at this moment.

Note that ignoring thread interruption at that point shouldn't be a problem, because after 3. the `managed-to-native` wrapper will check for thread interruption anyway.

Contributes to mono/mono#16819


Commit migrated from mono/mono@e271591
  • Loading branch information
lewurm authored and monojenkins committed Sep 20, 2019
1 parent d0d16cd commit 4b19b4d
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/mono/mono/mini/interp/interp.c
Original file line number Diff line number Diff line change
Expand Up @@ -3483,7 +3483,8 @@ interp_exec_method_full (InterpFrame *frame, ThreadContext *context, FrameClause
frame->ip = ip;

sp = do_icall_wrapper (frame, csignature, opcode, sp, target_ip, save_last_error);
EXCEPTION_CHECKPOINT;
if (mono_thread_is_gc_unsafe_mode ()) /* do not enter EH in GC Safe state */
EXCEPTION_CHECKPOINT;
CHECK_RESUME_STATE (context);
ip += 4;
MINT_IN_BREAK;
Expand Down Expand Up @@ -5926,7 +5927,8 @@ interp_exec_method_full (InterpFrame *frame, ThreadContext *context, FrameClause
MINT_IN_CASE(MINT_ICALL_PPPPPP_P)
frame->ip = ip;
sp = do_icall_wrapper (frame, NULL, *ip, sp, frame->imethod->data_items [ip [1]], FALSE);
EXCEPTION_CHECKPOINT;
if (mono_thread_is_gc_unsafe_mode ()) /* do not enter EH in GC Safe state */
EXCEPTION_CHECKPOINT;
CHECK_RESUME_STATE (context);
ip += 2;
MINT_IN_BREAK;
Expand Down

0 comments on commit 4b19b4d

Please sign in to comment.