Skip to content

Commit a0defb5

Browse files
authored
Merge pull request #1341 from Unity-Technologies/unity-master-fix-1273662
Unity master fix case 1273662
2 parents 2823f4f + 206dbc7 commit a0defb5

File tree

4 files changed

+21
-14
lines changed

4 files changed

+21
-14
lines changed

mono/metadata/image.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1906,6 +1906,7 @@ mono_wrapper_caches_free (MonoWrapperCaches *cache)
19061906
free_hash (cache->runtime_invoke_vtype_cache);
19071907

19081908
free_hash (cache->delegate_abstract_invoke_cache);
1909+
free_hash (cache->delegate_bound_static_invoke_cache);
19091910

19101911
free_hash (cache->runtime_invoke_direct_cache);
19111912
free_hash (cache->managed_wrapper_cache);
@@ -2076,7 +2077,6 @@ mono_image_close_except_pools (MonoImage *image)
20762077
g_hash_table_destroy (image->name_cache);
20772078
}
20782079

2079-
free_hash (image->delegate_bound_static_invoke_cache);
20802080
free_hash (image->runtime_invoke_vcall_cache);
20812081
free_hash (image->ldfld_wrapper_cache);
20822082
free_hash (image->ldflda_wrapper_cache);

mono/metadata/loader.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1976,10 +1976,6 @@ mono_free_method (MonoMethod *method)
19761976
{
19771977
MONO_PROFILER_RAISE (method_free, (method));
19781978

1979-
/* FIXME: This hack will go away when the profiler will support freeing methods */
1980-
if (G_UNLIKELY (mono_profiler_installed ()))
1981-
return;
1982-
19831979
if (method->signature) {
19841980
/*
19851981
* FIXME: This causes crashes because the types inside signatures and

mono/metadata/marshal.c

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3515,7 +3515,7 @@ free_signature_pointer_pair (SignaturePointerPair *pair)
35153515
MonoMethod *
35163516
mono_marshal_get_delegate_invoke_internal (MonoMethod *method, gboolean callvirt, gboolean static_method_with_first_arg_bound, MonoMethod *target_method)
35173517
{
3518-
MonoMethodSignature *sig, *static_sig, *invoke_sig;
3518+
MonoMethodSignature *sig, *invoke_sig;
35193519
int i;
35203520
MonoMethodBuilder *mb;
35213521
MonoMethod *res;
@@ -3568,6 +3568,13 @@ mono_marshal_get_delegate_invoke_internal (MonoMethod *method, gboolean callvirt
35683568
subtype = WRAPPER_SUBTYPE_DELEGATE_INVOKE_BOUND;
35693569
g_assert (!callvirt);
35703570
invoke_sig = mono_method_signature (target_method);
3571+
/*
3572+
* The wrapper has a different lifetime from the method to be invoked.
3573+
* If the method is dynamic we don't want to be using its signature
3574+
* in the wrapper since it could get freed early.
3575+
*/
3576+
if (method_is_dynamic(target_method))
3577+
invoke_sig = mono_metadata_signature_dup_full(target_method->klass->image, invoke_sig);
35713578
}
35723579

35733580
/*
@@ -3595,7 +3602,11 @@ mono_marshal_get_delegate_invoke_internal (MonoMethod *method, gboolean callvirt
35953602
return res;
35963603
cache_key = method->klass;
35973604
} else if (static_method_with_first_arg_bound) {
3598-
cache = get_cache (&method->klass->image->delegate_bound_static_invoke_cache,
3605+
GHashTable **cache_ptr;
3606+
3607+
cache_ptr = &mono_method_get_wrapper_cache (target_method)->delegate_bound_static_invoke_cache;
3608+
3609+
cache = get_cache (cache_ptr,
35993610
(GHashFunc)mono_signature_hash,
36003611
(GCompareFunc)mono_metadata_signature_equal);
36013612
/*
@@ -3633,10 +3644,10 @@ mono_marshal_get_delegate_invoke_internal (MonoMethod *method, gboolean callvirt
36333644
cache_key = sig;
36343645
}
36353646

3636-
static_sig = mono_metadata_signature_dup_full (method->klass->image, sig);
3637-
static_sig->hasthis = 0;
3638-
if (!static_method_with_first_arg_bound)
3639-
invoke_sig = static_sig;
3647+
if (!static_method_with_first_arg_bound) {
3648+
invoke_sig = mono_metadata_signature_dup_full(method->klass->image, sig);
3649+
invoke_sig->hasthis = 0;
3650+
}
36403651

36413652
if (static_method_with_first_arg_bound)
36423653
name = mono_signature_to_name (invoke_sig, "invoke_bound");
@@ -12393,8 +12404,8 @@ mono_marshal_free_dynamic_wrappers (MonoMethod *method)
1239312404
if (image->wrapper_caches.delegate_abstract_invoke_cache)
1239412405
g_hash_table_foreach_remove (image->wrapper_caches.delegate_abstract_invoke_cache, signature_pointer_pair_matches_pointer, method);
1239512406
// FIXME: Need to clear the caches in other images as well
12396-
if (image->delegate_bound_static_invoke_cache)
12397-
g_hash_table_remove (image->delegate_bound_static_invoke_cache, mono_method_signature (method));
12407+
if (image->wrapper_caches.delegate_bound_static_invoke_cache)
12408+
g_hash_table_remove (image->wrapper_caches.delegate_bound_static_invoke_cache, mono_method_signature (method));
1239812409

1239912410
if (marshal_mutex_initialized)
1240012411
mono_marshal_unlock ();

mono/metadata/metadata-internals.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ typedef struct {
125125
* indexed by SignaturePointerPair
126126
*/
127127
GHashTable *delegate_abstract_invoke_cache;
128+
GHashTable *delegate_bound_static_invoke_cache;
128129

129130
/*
130131
* indexed by MonoMethod pointers
@@ -339,7 +340,6 @@ struct _MonoImage {
339340
/*
340341
* indexed by SignaturePointerPair
341342
*/
342-
GHashTable *delegate_bound_static_invoke_cache;
343343
GHashTable *native_func_wrapper_cache;
344344

345345
/*

0 commit comments

Comments
 (0)