Skip to content

Commit

Permalink
[runtime] Make synchronized methods use the Monitor.Enter(object,bool…
Browse files Browse the repository at this point in the history
…&) overload.
  • Loading branch information
vargaz committed Aug 9, 2015
1 parent c5d8245 commit f68990d
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions mono/metadata/marshal.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -8697,7 +8697,7 @@ mono_marshal_get_synchronized_wrapper (MonoMethod *method)
MonoMethodBuilder *mb; MonoMethodBuilder *mb;
MonoMethod *res; MonoMethod *res;
GHashTable *cache; GHashTable *cache;
int i, pos, this_local, ret_local = 0; int i, pos, pos2, this_local, taken_local, ret_local = 0;
MonoGenericContext *ctx = NULL; MonoGenericContext *ctx = NULL;
MonoMethod *orig_method = NULL; MonoMethod *orig_method = NULL;
MonoGenericContainer *container = NULL; MonoGenericContainer *container = NULL;
Expand Down Expand Up @@ -8738,6 +8738,7 @@ mono_marshal_get_synchronized_wrapper (MonoMethod *method)
mb = mono_mb_new (method->klass, method->name, MONO_WRAPPER_SYNCHRONIZED); mb = mono_mb_new (method->klass, method->name, MONO_WRAPPER_SYNCHRONIZED);


#ifndef DISABLE_JIT #ifndef DISABLE_JIT
mb->skip_visibility = 1;
/* result */ /* result */
if (!MONO_TYPE_IS_VOID (sig->ret)) if (!MONO_TYPE_IS_VOID (sig->ret))
ret_local = mono_mb_add_local (mb, sig->ret); ret_local = mono_mb_add_local (mb, sig->ret);
Expand Down Expand Up @@ -8766,6 +8767,7 @@ mono_marshal_get_synchronized_wrapper (MonoMethod *method)
#ifndef DISABLE_JIT #ifndef DISABLE_JIT
/* this */ /* this */
this_local = mono_mb_add_local (mb, &mono_defaults.object_class->byval_arg); this_local = mono_mb_add_local (mb, &mono_defaults.object_class->byval_arg);
taken_local = mono_mb_add_local (mb, &mono_defaults.boolean_class->byval_arg);


clause = mono_image_alloc0 (method->klass->image, sizeof (MonoExceptionClause)); clause = mono_image_alloc0 (method->klass->image, sizeof (MonoExceptionClause));
clause->flags = MONO_EXCEPTION_CLAUSE_FINALLY; clause->flags = MONO_EXCEPTION_CLAUSE_FINALLY;
Expand All @@ -8776,7 +8778,7 @@ mono_marshal_get_synchronized_wrapper (MonoMethod *method)
if (!enter_method) { if (!enter_method) {
MonoMethodDesc *desc; MonoMethodDesc *desc;


desc = mono_method_desc_new ("Monitor:Enter", FALSE); desc = mono_method_desc_new ("Monitor:enter_with_atomic_var(object,bool&)", FALSE);
enter_method = mono_method_desc_search_in_class (desc, mono_defaults.monitor_class); enter_method = mono_method_desc_search_in_class (desc, mono_defaults.monitor_class);
g_assert (enter_method); g_assert (enter_method);
mono_method_desc_free (desc); mono_method_desc_free (desc);
Expand Down Expand Up @@ -8811,6 +8813,7 @@ mono_marshal_get_synchronized_wrapper (MonoMethod *method)


/* Call Monitor::Enter() */ /* Call Monitor::Enter() */
mono_mb_emit_ldloc (mb, this_local); mono_mb_emit_ldloc (mb, this_local);
mono_mb_emit_ldloc_addr (mb, taken_local);
mono_mb_emit_managed_call (mb, enter_method, NULL); mono_mb_emit_managed_call (mb, enter_method, NULL);


clause->try_offset = mono_mb_get_label (mb); clause->try_offset = mono_mb_get_label (mb);
Expand All @@ -8837,9 +8840,12 @@ mono_marshal_get_synchronized_wrapper (MonoMethod *method)
clause->try_len = mono_mb_get_pos (mb) - clause->try_offset; clause->try_len = mono_mb_get_pos (mb) - clause->try_offset;
clause->handler_offset = mono_mb_get_label (mb); clause->handler_offset = mono_mb_get_label (mb);


/* Call Monitor::Exit() */ /* Call Monitor::Exit() if needed */
mono_mb_emit_ldloc (mb, taken_local);
pos2 = mono_mb_emit_branch (mb, CEE_BRFALSE);
mono_mb_emit_ldloc (mb, this_local); mono_mb_emit_ldloc (mb, this_local);
mono_mb_emit_managed_call (mb, exit_method, NULL); mono_mb_emit_managed_call (mb, exit_method, NULL);
mono_mb_patch_branch (mb, pos2);
mono_mb_emit_byte (mb, CEE_ENDFINALLY); mono_mb_emit_byte (mb, CEE_ENDFINALLY);


clause->handler_len = mono_mb_get_pos (mb) - clause->handler_offset; clause->handler_len = mono_mb_get_pos (mb) - clause->handler_offset;
Expand Down

0 comments on commit f68990d

Please sign in to comment.