Permalink
Browse files

[runtime] Make synchronized methods use the Monitor.Enter(object,bool…

…&) overload.
  • Loading branch information...
vargaz committed Aug 9, 2015
1 parent c5d8245 commit f68990d7c1cd729fe3cc3ccd7ce804a813e2c0b7
Showing with 9 additions and 3 deletions.
  1. +9 −3 mono/metadata/marshal.c
View
@@ -8697,7 +8697,7 @@ mono_marshal_get_synchronized_wrapper (MonoMethod *method)
MonoMethodBuilder *mb;
MonoMethod *res;
GHashTable *cache;
int i, pos, this_local, ret_local = 0;
int i, pos, pos2, this_local, taken_local, ret_local = 0;
MonoGenericContext *ctx = NULL;
MonoMethod *orig_method = NULL;
MonoGenericContainer *container = NULL;
@@ -8738,6 +8738,7 @@ mono_marshal_get_synchronized_wrapper (MonoMethod *method)
mb = mono_mb_new (method->klass, method->name, MONO_WRAPPER_SYNCHRONIZED);
#ifndef DISABLE_JIT
mb->skip_visibility = 1;
/* result */
if (!MONO_TYPE_IS_VOID (sig->ret))
ret_local = mono_mb_add_local (mb, sig->ret);
@@ -8766,6 +8767,7 @@ mono_marshal_get_synchronized_wrapper (MonoMethod *method)
#ifndef DISABLE_JIT
/* this */
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->flags = MONO_EXCEPTION_CLAUSE_FINALLY;
@@ -8776,7 +8778,7 @@ mono_marshal_get_synchronized_wrapper (MonoMethod *method)
if (!enter_method) {
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);
g_assert (enter_method);
mono_method_desc_free (desc);
@@ -8811,6 +8813,7 @@ mono_marshal_get_synchronized_wrapper (MonoMethod *method)
/* Call Monitor::Enter() */
mono_mb_emit_ldloc (mb, this_local);
mono_mb_emit_ldloc_addr (mb, taken_local);
mono_mb_emit_managed_call (mb, enter_method, NULL);
clause->try_offset = mono_mb_get_label (mb);
@@ -8837,9 +8840,12 @@ mono_marshal_get_synchronized_wrapper (MonoMethod *method)
clause->try_len = mono_mb_get_pos (mb) - clause->try_offset;
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_managed_call (mb, exit_method, NULL);
mono_mb_patch_branch (mb, pos2);
mono_mb_emit_byte (mb, CEE_ENDFINALLY);
clause->handler_len = mono_mb_get_pos (mb) - clause->handler_offset;

0 comments on commit f68990d

Please sign in to comment.