From a175351f2b27cdf4a404ceb16df91b08a07f2d90 Mon Sep 17 00:00:00 2001 From: Vlad - Alexandru Ionescu Date: Thu, 24 Nov 2022 12:33:49 +0100 Subject: [PATCH 01/14] Changed how NaN values are compared due to their multiple bit representations Signed-off-by: Vlad - Alexandru Ionescu --- src/tests/JIT/opt/InstructionCombining/DivToMul.cs | 14 ++++++++++++++ src/tests/issues.targets | 3 --- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/tests/JIT/opt/InstructionCombining/DivToMul.cs b/src/tests/JIT/opt/InstructionCombining/DivToMul.cs index dc559aa4041e7..d8e42315f0415 100644 --- a/src/tests/JIT/opt/InstructionCombining/DivToMul.cs +++ b/src/tests/JIT/opt/InstructionCombining/DivToMul.cs @@ -160,6 +160,13 @@ private static void TestNotPowOfTwo_Double(double x) [MethodImpl(MethodImplOptions.NoInlining)] private static void AssertEquals(float expected, float actual) { + if (Single.IsNaN(expected) && Single.IsNaN(actual)) + { + // There can be multiple configurations for NaN values + // verifying that this values are NaNs should be enough + return; + } + int expectedi = BitConverter.SingleToInt32Bits(expected); int actuali = BitConverter.SingleToInt32Bits(actual); if (expectedi != actuali) @@ -172,6 +179,13 @@ private static void AssertEquals(float expected, float actual) [MethodImpl(MethodImplOptions.NoInlining)] private static void AssertEquals(double expected, double actual) { + if (Double.IsNaN(expected) && Double.IsNaN(actual)) + { + // There can be multiple configurations for NaN values + // verifying that this values are NaNs should be enough + return; + } + long expectedi = BitConverter.DoubleToInt64Bits(expected); long actuali = BitConverter.DoubleToInt64Bits(actual); if (expectedi != actuali) diff --git a/src/tests/issues.targets b/src/tests/issues.targets index ba1df1b8b6b70..537f6c3dc59ce 100644 --- a/src/tests/issues.targets +++ b/src/tests/issues.targets @@ -1408,9 +1408,6 @@ Crashes during LLVM AOT compilation. - - Doesn't pass after LLVM AOT compilation. - Doesn't pass after LLVM AOT compilation. From a381c06700184cce80c2e3e617c31a1573eadd4a Mon Sep 17 00:00:00 2001 From: Vlad - Alexandru Ionescu Date: Thu, 24 Nov 2022 16:38:36 +0100 Subject: [PATCH 02/14] Fixed typo Signed-off-by: Vlad - Alexandru Ionescu --- src/tests/JIT/opt/InstructionCombining/DivToMul.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tests/JIT/opt/InstructionCombining/DivToMul.cs b/src/tests/JIT/opt/InstructionCombining/DivToMul.cs index d8e42315f0415..0c7c3efe442ec 100644 --- a/src/tests/JIT/opt/InstructionCombining/DivToMul.cs +++ b/src/tests/JIT/opt/InstructionCombining/DivToMul.cs @@ -163,7 +163,7 @@ private static void AssertEquals(float expected, float actual) if (Single.IsNaN(expected) && Single.IsNaN(actual)) { // There can be multiple configurations for NaN values - // verifying that this values are NaNs should be enough + // verifying that these values are NaNs should be enough return; } @@ -182,7 +182,7 @@ private static void AssertEquals(double expected, double actual) if (Double.IsNaN(expected) && Double.IsNaN(actual)) { // There can be multiple configurations for NaN values - // verifying that this values are NaNs should be enough + // verifying that these values are NaNs should be enough return; } From fbc15264b7725349ef2847bebdd3ba459b348873 Mon Sep 17 00:00:00 2001 From: Vlad - Alexandru Ionescu Date: Wed, 15 Mar 2023 15:01:19 +0100 Subject: [PATCH 03/14] Work to make JIT virtual delegates not depend on the target_method Signed-off-by: Vlad - Alexandru Ionescu --- src/mono/mono/metadata/jit-icall-reg.h | 1 + src/mono/mono/metadata/marshal-lightweight.c | 13 +++++--- src/mono/mono/metadata/marshal.c | 35 ++++++++++++++++++-- src/mono/mono/metadata/marshal.h | 6 +++- src/tests/JIT/Delegate/Tests.cs | 18 ++++++++++ src/tests/JIT/Delegate/Tests.csproj | 12 +++++++ 6 files changed, 77 insertions(+), 8 deletions(-) create mode 100644 src/tests/JIT/Delegate/Tests.cs create mode 100644 src/tests/JIT/Delegate/Tests.csproj diff --git a/src/mono/mono/metadata/jit-icall-reg.h b/src/mono/mono/metadata/jit-icall-reg.h index 809a80403b521..f0a2e1b8ac6ee 100644 --- a/src/mono/mono/metadata/jit-icall-reg.h +++ b/src/mono/mono/metadata/jit-icall-reg.h @@ -203,6 +203,7 @@ MONO_JIT_ICALL (mono_gc_wbarrier_generic_nostore_internal) \ MONO_JIT_ICALL (mono_gc_wbarrier_range_copy) \ MONO_JIT_ICALL (mono_gchandle_get_target_internal) \ MONO_JIT_ICALL (mono_generic_class_init) \ +MONO_JIT_ICALL (mono_get_addr_compiled_method) \ MONO_JIT_ICALL (mono_get_assembly_object) \ MONO_JIT_ICALL (mono_get_method_object) \ MONO_JIT_ICALL (mono_get_native_calli_wrapper) \ diff --git a/src/mono/mono/metadata/marshal-lightweight.c b/src/mono/mono/metadata/marshal-lightweight.c index 2b8c321fce6f9..93fdc89c1182d 100644 --- a/src/mono/mono/metadata/marshal-lightweight.c +++ b/src/mono/mono/metadata/marshal-lightweight.c @@ -1909,7 +1909,7 @@ emit_delegate_end_invoke_ilgen (MonoMethodBuilder *mb, MonoMethodSignature *sig) } static void -emit_delegate_invoke_internal_ilgen (MonoMethodBuilder *mb, MonoMethodSignature *sig, MonoMethodSignature *invoke_sig, gboolean static_method_with_first_arg_bound, gboolean callvirt, gboolean closed_over_null, MonoMethod *method, MonoMethod *target_method, MonoClass *target_class, MonoGenericContext *ctx, MonoGenericContainer *container) +emit_delegate_invoke_internal_ilgen (MonoMethodBuilder *mb, MonoMethodSignature *sig, MonoMethodSignature *invoke_sig, MonoMethodSignature *target_method_sig, gboolean static_method_with_first_arg_bound, gboolean callvirt, gboolean closed_over_null, MonoMethod *method, MonoMethod *target_method, MonoClass *target_class, MonoGenericContext *ctx, MonoGenericContainer *container) { int local_i, local_len, local_delegates, local_d, local_target, local_res = 0; int pos0, pos1, pos2; @@ -2015,10 +2015,13 @@ emit_delegate_invoke_internal_ilgen (MonoMethodBuilder *mb, MonoMethodSignature mono_mb_emit_op (mb, CEE_CALL, target_method); } else { mono_mb_emit_ldarg (mb, 1); - mono_mb_emit_op (mb, CEE_CASTCLASS, target_class); - for (i = 1; i < sig->param_count; ++i) - mono_mb_emit_ldarg (mb, i + 1); - mono_mb_emit_op (mb, CEE_CALLVIRT, target_method); + for (i = 1; i <= sig->param_count; ++i) + mono_mb_emit_ldarg (mb, i); + mono_mb_emit_ldarg (mb, 0); + mono_mb_emit_ldflda (mb, MONO_STRUCT_OFFSET (MonoDelegate, method)); + mono_mb_emit_byte (mb, CEE_LDIND_I); + mono_mb_emit_icall (mb, mono_get_addr_compiled_method); + mono_mb_emit_op (mb, CEE_CALLI, target_method_sig); } } else { mono_mb_emit_byte (mb, CEE_LDNULL); diff --git a/src/mono/mono/metadata/marshal.c b/src/mono/mono/metadata/marshal.c index 5ab899e032d0e..e4885b727fcdd 100644 --- a/src/mono/mono/metadata/marshal.c +++ b/src/mono/mono/metadata/marshal.c @@ -324,6 +324,7 @@ mono_marshal_init (void) register_icall (monoeg_g_free, mono_icall_sig_void_ptr, FALSE); register_icall (mono_object_isinst_icall, mono_icall_sig_object_object_ptr, TRUE); register_icall (mono_struct_delete_old, mono_icall_sig_void_ptr_ptr, FALSE); + register_icall (mono_get_addr_compiled_method, mono_icall_sig_ptr_object_ptr, FALSE); register_icall (mono_delegate_begin_invoke, mono_icall_sig_object_object_ptr, FALSE); register_icall (mono_delegate_end_invoke, mono_icall_sig_object_object_ptr, FALSE); register_icall (mono_gc_wbarrier_generic_nostore_internal, mono_icall_sig_void_ptr, TRUE); @@ -2085,7 +2086,7 @@ free_signature_pointer_pair (SignaturePointerPair *pair) MonoMethod * mono_marshal_get_delegate_invoke_internal (MonoMethod *method, gboolean callvirt, gboolean static_method_with_first_arg_bound, MonoMethod *target_method) { - MonoMethodSignature *sig, *invoke_sig; + MonoMethodSignature *sig, *invoke_sig, *target_method_sig; MonoMethodBuilder *mb; MonoMethod *res; GHashTable *cache; @@ -2129,6 +2130,11 @@ mono_marshal_get_delegate_invoke_internal (MonoMethod *method, gboolean callvirt } closed_over_null = sig->param_count == mono_method_signature_internal (target_method)->param_count; + + /* + * We don't want to use target_method's signature because it can be freed early + */ + target_method_sig = mono_method_signature_internal (target_method); } if (static_method_with_first_arg_bound) { @@ -2239,7 +2245,7 @@ mono_marshal_get_delegate_invoke_internal (MonoMethod *method, gboolean callvirt /* FIXME: Other subtypes */ mb->mem_manager = m_method_get_mem_manager (method); - get_marshal_cb ()->emit_delegate_invoke_internal (mb, sig, invoke_sig, static_method_with_first_arg_bound, callvirt, closed_over_null, method, target_method, target_class, ctx, container); + get_marshal_cb ()->emit_delegate_invoke_internal (mb, sig, invoke_sig, target_method_sig, static_method_with_first_arg_bound, callvirt, closed_over_null, method, target_method, target_class, ctx, container); get_marshal_cb ()->mb_skip_visibility (mb); @@ -5461,6 +5467,31 @@ mono_struct_delete_old (MonoClass *klass, char *ptr) } } +void* +mono_get_addr_compiled_method (MonoObject *object, MonoMethod *method) +{ + ERROR_DECL (error); + MonoMethod *res; + gpointer addr; + + if (object == NULL) { + mono_error_set_null_reference (error); + mono_error_set_pending_exception (error); + return NULL; + } + + res = mono_object_get_virtual_method_internal (object, method); + + addr = mono_compile_method_checked (res, error); + + if (!is_ok (error)) { + mono_error_set_pending_exception (error); + return NULL; + } + + return addr; +} + void ves_icall_System_Runtime_InteropServices_Marshal_DestroyStructure (gpointer src, MonoReflectionTypeHandle type, MonoError *error) { diff --git a/src/mono/mono/metadata/marshal.h b/src/mono/mono/metadata/marshal.h index 89b306d7def0c..79162cf687e96 100644 --- a/src/mono/mono/metadata/marshal.h +++ b/src/mono/mono/metadata/marshal.h @@ -328,7 +328,7 @@ typedef struct { void (*emit_runtime_invoke_dynamic) (MonoMethodBuilder *mb); void (*emit_delegate_begin_invoke) (MonoMethodBuilder *mb, MonoMethodSignature *sig); void (*emit_delegate_end_invoke) (MonoMethodBuilder *mb, MonoMethodSignature *sig); - void (*emit_delegate_invoke_internal) (MonoMethodBuilder *mb, MonoMethodSignature *sig, MonoMethodSignature *invoke_sig, gboolean static_method_with_first_arg_bound, gboolean callvirt, gboolean closed_over_null, MonoMethod *method, MonoMethod *target_method, MonoClass *target_class, MonoGenericContext *ctx, MonoGenericContainer *container); + void (*emit_delegate_invoke_internal) (MonoMethodBuilder *mb, MonoMethodSignature *sig, MonoMethodSignature *invoke_sig, MonoMethodSignature *target_method_sig, gboolean static_method_with_first_arg_bound, gboolean callvirt, gboolean closed_over_null, MonoMethod *method, MonoMethod *target_method, MonoClass *target_class, MonoGenericContext *ctx, MonoGenericContainer *container); void (*emit_synchronized_wrapper) (MonoMethodBuilder *mb, MonoMethod *method, MonoGenericContext *ctx, MonoGenericContainer *container, MonoMethod *enter_method, MonoMethod *exit_method, MonoMethod *gettypefromhandle_method); void (*emit_unbox_wrapper) (MonoMethodBuilder *mb, MonoMethod *method); void (*emit_array_accessor_wrapper) (MonoMethodBuilder *mb, MonoMethod *method, MonoMethodSignature *sig, MonoGenericContext *ctx); @@ -621,6 +621,10 @@ ICALL_EXPORT void mono_struct_delete_old (MonoClass *klass, char *ptr); +ICALL_EXPORT +void* +mono_get_addr_compiled_method (MonoObject *object, MonoMethod *method); + int mono_emit_marshal (EmitMarshalContext *m, int argnum, MonoType *t, MonoMarshalSpec *spec, int conv_arg, diff --git a/src/tests/JIT/Delegate/Tests.cs b/src/tests/JIT/Delegate/Tests.cs new file mode 100644 index 0000000000000..606e1084baf23 --- /dev/null +++ b/src/tests/JIT/Delegate/Tests.cs @@ -0,0 +1,18 @@ +using System; +using System.Runtime.InteropServices; + +public class Tests +{ + public static int Main () { + try { + var del = (Func)Delegate.CreateDelegate (typeof (Func), null, typeof (object).GetMethod ("ToString")); + Console.WriteLine (del ("FOO")); + } catch(Exception e) { + Console.WriteLine(e); + return 0; + } + + return 100; + + } +} \ No newline at end of file diff --git a/src/tests/JIT/Delegate/Tests.csproj b/src/tests/JIT/Delegate/Tests.csproj new file mode 100644 index 0000000000000..5fa6b0c02a640 --- /dev/null +++ b/src/tests/JIT/Delegate/Tests.csproj @@ -0,0 +1,12 @@ + + + Exe + + + PdbOnly + True + + + + + From 91c392081f5860388d461cc5d412e77187f4f9be Mon Sep 17 00:00:00 2001 From: Vlad - Alexandru Ionescu Date: Thu, 16 Mar 2023 11:15:01 +0100 Subject: [PATCH 04/14] Switched order of how MonoObject is passed to the icall --- src/mono/mono/metadata/marshal-lightweight.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mono/mono/metadata/marshal-lightweight.c b/src/mono/mono/metadata/marshal-lightweight.c index 29e27a45037ab..5e9b29c945b38 100644 --- a/src/mono/mono/metadata/marshal-lightweight.c +++ b/src/mono/mono/metadata/marshal-lightweight.c @@ -2095,9 +2095,9 @@ emit_delegate_invoke_internal_ilgen (MonoMethodBuilder *mb, MonoMethodSignature mono_mb_emit_ldarg (mb, i + 1); mono_mb_emit_op (mb, CEE_CALL, target_method); } else { - mono_mb_emit_ldarg (mb, 1); for (i = 1; i <= sig->param_count; ++i) mono_mb_emit_ldarg (mb, i); + mono_mb_emit_ldarg (mb, 1); mono_mb_emit_ldarg (mb, 0); mono_mb_emit_ldflda (mb, MONO_STRUCT_OFFSET (MonoDelegate, method)); mono_mb_emit_byte (mb, CEE_LDIND_I); From 81973dbcba9f6a386e9cd2778b9fc7d9eb88af97 Mon Sep 17 00:00:00 2001 From: Vlad - Alexandru Ionescu Date: Thu, 16 Mar 2023 13:53:49 +0100 Subject: [PATCH 05/14] Initialise pointer for build warning --- src/mono/mono/metadata/marshal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mono/mono/metadata/marshal.c b/src/mono/mono/metadata/marshal.c index e80b1bdff1576..6e7db39b94ebb 100644 --- a/src/mono/mono/metadata/marshal.c +++ b/src/mono/mono/metadata/marshal.c @@ -2086,7 +2086,7 @@ free_signature_pointer_pair (SignaturePointerPair *pair) MonoMethod * mono_marshal_get_delegate_invoke_internal (MonoMethod *method, gboolean callvirt, gboolean static_method_with_first_arg_bound, MonoMethod *target_method) { - MonoMethodSignature *sig, *invoke_sig, *target_method_sig; + MonoMethodSignature *sig, *invoke_sig, *target_method_sig = NULL; MonoMethodBuilder *mb; MonoMethod *res; GHashTable *cache; From 3b0d6cb5c9807c7adaa006775859af492295b52e Mon Sep 17 00:00:00 2001 From: Vlad - Alexandru Ionescu Date: Thu, 16 Mar 2023 19:35:06 +0100 Subject: [PATCH 06/14] Check return value in the test --- src/tests/JIT/Delegate/Tests.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/tests/JIT/Delegate/Tests.cs b/src/tests/JIT/Delegate/Tests.cs index 606e1084baf23..54237bb17e513 100644 --- a/src/tests/JIT/Delegate/Tests.cs +++ b/src/tests/JIT/Delegate/Tests.cs @@ -4,15 +4,17 @@ public class Tests { public static int Main () { + int retVal = 100; try { var del = (Func)Delegate.CreateDelegate (typeof (Func), null, typeof (object).GetMethod ("ToString")); - Console.WriteLine (del ("FOO")); + if (del ("FOO") != "FOO") + retVal = 1; } catch(Exception e) { Console.WriteLine(e); - return 0; + retVal = 1; } - return 100; + return retVal; } -} \ No newline at end of file +} From f67f5fb82691fca3d06a25be7d4ec12d7ec5eb1e Mon Sep 17 00:00:00 2001 From: Vlad - Alexandru Ionescu Date: Fri, 17 Mar 2023 02:26:06 +0100 Subject: [PATCH 07/14] Retrieved method in icall and changed test location --- src/mono/mono/metadata/marshal-lightweight.c | 2 -- src/mono/mono/metadata/marshal.c | 4 ++-- src/mono/mono/metadata/marshal.h | 2 +- .../Tests.cs => Methodical/delegate/VirtualDelegate.cs} | 6 +++++- .../delegate/VirtualDelegate.csproj} | 2 +- 5 files changed, 9 insertions(+), 7 deletions(-) rename src/tests/JIT/{Delegate/Tests.cs => Methodical/delegate/VirtualDelegate.cs} (74%) rename src/tests/JIT/{Delegate/Tests.csproj => Methodical/delegate/VirtualDelegate.csproj} (84%) diff --git a/src/mono/mono/metadata/marshal-lightweight.c b/src/mono/mono/metadata/marshal-lightweight.c index 5e9b29c945b38..c917ea96817e6 100644 --- a/src/mono/mono/metadata/marshal-lightweight.c +++ b/src/mono/mono/metadata/marshal-lightweight.c @@ -2099,8 +2099,6 @@ emit_delegate_invoke_internal_ilgen (MonoMethodBuilder *mb, MonoMethodSignature mono_mb_emit_ldarg (mb, i); mono_mb_emit_ldarg (mb, 1); mono_mb_emit_ldarg (mb, 0); - mono_mb_emit_ldflda (mb, MONO_STRUCT_OFFSET (MonoDelegate, method)); - mono_mb_emit_byte (mb, CEE_LDIND_I); mono_mb_emit_icall (mb, mono_get_addr_compiled_method); mono_mb_emit_op (mb, CEE_CALLI, target_method_sig); } diff --git a/src/mono/mono/metadata/marshal.c b/src/mono/mono/metadata/marshal.c index 6e7db39b94ebb..17907b7d93613 100644 --- a/src/mono/mono/metadata/marshal.c +++ b/src/mono/mono/metadata/marshal.c @@ -5488,10 +5488,10 @@ mono_struct_delete_old (MonoClass *klass, char *ptr) } void* -mono_get_addr_compiled_method (MonoObject *object, MonoMethod *method) +mono_get_addr_compiled_method (MonoObject *object, MonoDelegate *del) { ERROR_DECL (error); - MonoMethod *res; + MonoMethod *res, *method = del->method; gpointer addr; if (object == NULL) { diff --git a/src/mono/mono/metadata/marshal.h b/src/mono/mono/metadata/marshal.h index bc2f833913203..d8022a8baff5f 100644 --- a/src/mono/mono/metadata/marshal.h +++ b/src/mono/mono/metadata/marshal.h @@ -626,7 +626,7 @@ mono_struct_delete_old (MonoClass *klass, char *ptr); ICALL_EXPORT void* -mono_get_addr_compiled_method (MonoObject *object, MonoMethod *method); +mono_get_addr_compiled_method (MonoObject *object, MonoDelegate *del); int mono_emit_marshal (EmitMarshalContext *m, int argnum, MonoType *t, diff --git a/src/tests/JIT/Delegate/Tests.cs b/src/tests/JIT/Methodical/delegate/VirtualDelegate.cs similarity index 74% rename from src/tests/JIT/Delegate/Tests.cs rename to src/tests/JIT/Methodical/delegate/VirtualDelegate.cs index 54237bb17e513..5a28c6841ad14 100644 --- a/src/tests/JIT/Delegate/Tests.cs +++ b/src/tests/JIT/Methodical/delegate/VirtualDelegate.cs @@ -1,7 +1,11 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + + using System; using System.Runtime.InteropServices; -public class Tests +public class VirtualDelegate { public static int Main () { int retVal = 100; diff --git a/src/tests/JIT/Delegate/Tests.csproj b/src/tests/JIT/Methodical/delegate/VirtualDelegate.csproj similarity index 84% rename from src/tests/JIT/Delegate/Tests.csproj rename to src/tests/JIT/Methodical/delegate/VirtualDelegate.csproj index 5fa6b0c02a640..30943a0102ed5 100644 --- a/src/tests/JIT/Delegate/Tests.csproj +++ b/src/tests/JIT/Methodical/delegate/VirtualDelegate.csproj @@ -7,6 +7,6 @@ True - + From dc2c525bdfac9faf4d697bd8d9164feef23d1431 Mon Sep 17 00:00:00 2001 From: Vlad - Alexandru Ionescu Date: Fri, 31 Mar 2023 19:05:54 +0200 Subject: [PATCH 08/14] Added check for unbox & rgctx trampolines and modified caching Signed-off-by: Vlad - Alexandru Ionescu --- src/mono/mono/metadata/loader-internals.h | 2 +- src/mono/mono/metadata/marshal-lightweight.c | 20 +++++---------- src/mono/mono/metadata/marshal.c | 26 +++++++++----------- src/mono/mono/metadata/object-internals.h | 1 + src/mono/mono/mini/mini-runtime.c | 1 + src/mono/mono/mini/mini-trampolines.c | 9 +++++++ src/mono/mono/mini/mini.h | 1 + 7 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/mono/mono/metadata/loader-internals.h b/src/mono/mono/metadata/loader-internals.h index d58404aff6b69..d3a2c94f44645 100644 --- a/src/mono/mono/metadata/loader-internals.h +++ b/src/mono/mono/metadata/loader-internals.h @@ -61,11 +61,11 @@ typedef struct { GHashTable *delegate_end_invoke_cache; GHashTable *runtime_invoke_signature_cache; GHashTable *runtime_invoke_sig_cache; + GHashTable *delegate_abstract_invoke_cache; /* * indexed by SignaturePointerPair */ - GHashTable *delegate_abstract_invoke_cache; GHashTable *delegate_bound_static_invoke_cache; /* diff --git a/src/mono/mono/metadata/marshal-lightweight.c b/src/mono/mono/metadata/marshal-lightweight.c index c917ea96817e6..06a20123dbee6 100644 --- a/src/mono/mono/metadata/marshal-lightweight.c +++ b/src/mono/mono/metadata/marshal-lightweight.c @@ -2088,20 +2088,12 @@ emit_delegate_invoke_internal_ilgen (MonoMethodBuilder *mb, MonoMethodSignature if (callvirt) { if (!closed_over_null) { - /* if target_method is not really virtual, turn it into a direct call */ - if (!(target_method->flags & METHOD_ATTRIBUTE_VIRTUAL) || m_class_is_valuetype (target_class)) { - mono_mb_emit_ldarg (mb, 1); - for (i = 1; i < sig->param_count; ++i) - mono_mb_emit_ldarg (mb, i + 1); - mono_mb_emit_op (mb, CEE_CALL, target_method); - } else { - for (i = 1; i <= sig->param_count; ++i) - mono_mb_emit_ldarg (mb, i); - mono_mb_emit_ldarg (mb, 1); - mono_mb_emit_ldarg (mb, 0); - mono_mb_emit_icall (mb, mono_get_addr_compiled_method); - mono_mb_emit_op (mb, CEE_CALLI, target_method_sig); - } + for (i = 1; i <= sig->param_count; ++i) + mono_mb_emit_ldarg (mb, i); + mono_mb_emit_ldarg (mb, 1); + mono_mb_emit_ldarg (mb, 0); + mono_mb_emit_icall (mb, mono_get_addr_compiled_method); + mono_mb_emit_op (mb, CEE_CALLI, target_method_sig); } else { mono_mb_emit_byte (mb, CEE_LDNULL); for (i = 0; i < sig->param_count; ++i) diff --git a/src/mono/mono/metadata/marshal.c b/src/mono/mono/metadata/marshal.c index 17907b7d93613..f1f44e6f7cb94 100644 --- a/src/mono/mono/metadata/marshal.c +++ b/src/mono/mono/metadata/marshal.c @@ -2194,17 +2194,16 @@ mono_marshal_get_delegate_invoke_internal (MonoMethod *method, gboolean callvirt cache_ptr = &mono_method_get_wrapper_cache (method)->delegate_abstract_invoke_cache; - /* We need to cache the signature+method pair */ + /* We need to cache the signature */ mono_marshal_lock (); - if (!*cache_ptr) - *cache_ptr = g_hash_table_new_full (signature_pointer_pair_hash, (GEqualFunc)signature_pointer_pair_equal, (GDestroyNotify)free_signature_pointer_pair, NULL); - cache = *cache_ptr; - key.sig = invoke_sig; - key.pointer = target_method; - res = (MonoMethod *)g_hash_table_lookup (cache, &key); + cache = get_cache (cache_ptr, + (GHashFunc)mono_signature_hash, + (GCompareFunc)mono_metadata_signature_equal); + res = (MonoMethod *)g_hash_table_lookup (cache, invoke_sig); mono_marshal_unlock (); if (res) return res; + cache_key = invoke_sig; } else { // Inflated methods should not be in this cache because it's not stored on the imageset. g_assert (!method->is_inflated); @@ -2257,13 +2256,6 @@ mono_marshal_get_delegate_invoke_internal (MonoMethod *method, gboolean callvirt def = mono_mb_create_and_cache_full (cache, cache_key, mb, sig, sig->param_count + 16, info, NULL); res = cache_generic_delegate_wrapper (cache, orig_method, def, ctx); - } else if (callvirt) { - new_key = g_new0 (SignaturePointerPair, 1); - *new_key = key; - - res = mono_mb_create_and_cache_full (cache, new_key, mb, sig, sig->param_count + 16, info, &found); - if (found) - g_free (new_key); } else { res = mono_mb_create_and_cache_full (cache, cache_key, mb, sig, sig->param_count + 16, info, NULL); } @@ -5493,6 +5485,7 @@ mono_get_addr_compiled_method (MonoObject *object, MonoDelegate *del) ERROR_DECL (error); MonoMethod *res, *method = del->method; gpointer addr; + gboolean need_unbox = FALSE; if (object == NULL) { mono_error_set_null_reference (error); @@ -5509,6 +5502,9 @@ mono_get_addr_compiled_method (MonoObject *object, MonoDelegate *del) return NULL; } + need_unbox = m_class_is_valuetype (res->klass) && !m_class_is_valuetype (method->klass); + addr = mono_get_runtime_callbacks ()->add_delegate_trampolines (res, addr, need_unbox); + return addr; } @@ -6287,7 +6283,7 @@ mono_marshal_free_dynamic_wrappers (MonoMethod *method) if (image->wrapper_caches.runtime_invoke_method_cache) clear_runtime_invoke_method_cache (image->wrapper_caches.runtime_invoke_method_cache, method); if (image->wrapper_caches.delegate_abstract_invoke_cache) - g_hash_table_foreach_remove (image->wrapper_caches.delegate_abstract_invoke_cache, signature_pointer_pair_matches_pointer, method); + g_hash_table_remove (image->wrapper_caches.delegate_abstract_invoke_cache, mono_method_signature_internal (method)); // FIXME: Need to clear the caches in other images as well if (image->wrapper_caches.delegate_bound_static_invoke_cache) g_hash_table_remove (image->wrapper_caches.delegate_bound_static_invoke_cache, mono_method_signature_internal (method)); diff --git a/src/mono/mono/metadata/object-internals.h b/src/mono/mono/metadata/object-internals.h index 5dccb927a284c..9aa53165b4d70 100644 --- a/src/mono/mono/metadata/object-internals.h +++ b/src/mono/mono/metadata/object-internals.h @@ -700,6 +700,7 @@ typedef struct { void (*interp_jit_info_foreach)(InterpJitInfoFunc func, gpointer user_data); gboolean (*interp_sufficient_stack)(gsize size); void (*init_class) (MonoClass *klass); + gpointer (*add_delegate_trampolines) (MonoMethod *method, gpointer compiled_method, gboolean need_unbox); MonoArray *(*get_trace) (MonoException *exc, gint32 skip, MonoBoolean need_file_info); MonoBoolean (*get_frame_info) (gint32 skip, MonoMethod **out_method, MonoDebugSourceLocation **out_location, diff --git a/src/mono/mono/mini/mini-runtime.c b/src/mono/mono/mini/mini-runtime.c index 339b1bd2bb2ed..f84425f744377 100644 --- a/src/mono/mono/mini/mini-runtime.c +++ b/src/mono/mono/mini/mini-runtime.c @@ -4582,6 +4582,7 @@ mini_init (const char *filename) callbacks.init_class = init_class; callbacks.get_trace = mono_get_trace; callbacks.get_frame_info = mono_get_frame_info; + callbacks.add_delegate_trampolines = mono_add_delegate_trampolines; mono_install_callbacks (&callbacks); diff --git a/src/mono/mono/mini/mini-trampolines.c b/src/mono/mono/mini/mini-trampolines.c index ebb21872aa232..c7662e2c31c1e 100644 --- a/src/mono/mono/mini/mini-trampolines.c +++ b/src/mono/mono/mini/mini-trampolines.c @@ -1458,6 +1458,15 @@ mono_create_delegate_trampoline (MonoClass *klass) return mono_create_delegate_trampoline_info (klass, NULL, FALSE)->invoke_impl; } +gpointer mono_add_delegate_trampolines (MonoMethod *method, gpointer compiled_method, gboolean need_unbox) +{ + gpointer addr; + + addr = mini_add_method_trampoline (method, compiled_method, mono_method_needs_static_rgctx_invoke (method, TRUE), need_unbox); + + return addr; +} + gpointer mono_create_rgctx_lazy_fetch_trampoline (guint32 offset) { diff --git a/src/mono/mono/mini/mini.h b/src/mono/mono/mini/mini.h index 41a6a3b6d8e54..722fe98092e43 100644 --- a/src/mono/mono/mini/mini.h +++ b/src/mono/mono/mini/mini.h @@ -2271,6 +2271,7 @@ gpointer mono_create_jump_trampoline (MonoMethod *method, gpointer mono_create_jit_trampoline (MonoMethod *method, MonoError *error); gpointer mono_create_jit_trampoline_from_token (MonoImage *image, guint32 token); gpointer mono_create_delegate_trampoline (MonoClass *klass); +gpointer mono_add_delegate_trampolines (MonoMethod *method, gpointer compiled_method, gboolean need_unbox); MonoDelegateTrampInfo* mono_create_delegate_trampoline_info (MonoClass *klass, MonoMethod *method, gboolean is_virtual); gpointer mono_create_rgctx_lazy_fetch_trampoline (guint32 offset); gpointer mono_create_static_rgctx_trampoline (MonoMethod *m, gpointer addr); From 4ba33665b857868e361dd05d1a1293830edae7da Mon Sep 17 00:00:00 2001 From: Vlad - Alexandru Ionescu Date: Fri, 31 Mar 2023 19:25:21 +0200 Subject: [PATCH 09/14] Deleted unused vars Signed-off-by: Vlad - Alexandru Ionescu --- src/mono/mono/metadata/marshal.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/mono/mono/metadata/marshal.c b/src/mono/mono/metadata/marshal.c index f1f44e6f7cb94..2121842ad1301 100644 --- a/src/mono/mono/metadata/marshal.c +++ b/src/mono/mono/metadata/marshal.c @@ -2091,8 +2091,6 @@ mono_marshal_get_delegate_invoke_internal (MonoMethod *method, gboolean callvirt MonoMethod *res; GHashTable *cache; gpointer cache_key = NULL; - SignaturePointerPair key = { NULL, NULL }; - SignaturePointerPair *new_key; char *name; MonoClass *target_class = NULL; gboolean closed_over_null = FALSE; @@ -2102,7 +2100,6 @@ mono_marshal_get_delegate_invoke_internal (MonoMethod *method, gboolean callvirt WrapperInfo *info; WrapperSubtype subtype = WRAPPER_SUBTYPE_NONE; MonoMemoryManager *mem_manager = NULL; - gboolean found; g_assert (method && m_class_get_parent (method->klass) == mono_defaults.multicastdelegate_class && !strcmp (method->name, "Invoke")); From 7b65607fc40f1d03d13b0ae21f47a6b8d2814f9c Mon Sep 17 00:00:00 2001 From: Vlad - Alexandru Ionescu Date: Mon, 3 Apr 2023 19:56:46 +0200 Subject: [PATCH 10/14] Added test for lazy fetch trampoline (rgctx) Signed-off-by: Vlad - Alexandru Ionescu --- src/mono/mono/metadata/marshal.c | 2 - src/mono/mono/mini/mini-trampolines.c | 6 +-- .../JIT/Methodical/delegate/GSDelegate.cs | 53 +++++++++++++++++++ .../JIT/Methodical/delegate/GSDelegate.csproj | 12 +++++ 4 files changed, 66 insertions(+), 7 deletions(-) create mode 100644 src/tests/JIT/Methodical/delegate/GSDelegate.cs create mode 100644 src/tests/JIT/Methodical/delegate/GSDelegate.csproj diff --git a/src/mono/mono/metadata/marshal.c b/src/mono/mono/metadata/marshal.c index 2121842ad1301..3ad970ba6316a 100644 --- a/src/mono/mono/metadata/marshal.c +++ b/src/mono/mono/metadata/marshal.c @@ -6279,8 +6279,6 @@ mono_marshal_free_dynamic_wrappers (MonoMethod *method) */ if (image->wrapper_caches.runtime_invoke_method_cache) clear_runtime_invoke_method_cache (image->wrapper_caches.runtime_invoke_method_cache, method); - if (image->wrapper_caches.delegate_abstract_invoke_cache) - g_hash_table_remove (image->wrapper_caches.delegate_abstract_invoke_cache, mono_method_signature_internal (method)); // FIXME: Need to clear the caches in other images as well if (image->wrapper_caches.delegate_bound_static_invoke_cache) g_hash_table_remove (image->wrapper_caches.delegate_bound_static_invoke_cache, mono_method_signature_internal (method)); diff --git a/src/mono/mono/mini/mini-trampolines.c b/src/mono/mono/mini/mini-trampolines.c index c7662e2c31c1e..ac6fc69cbbfdd 100644 --- a/src/mono/mono/mini/mini-trampolines.c +++ b/src/mono/mono/mini/mini-trampolines.c @@ -1460,11 +1460,7 @@ mono_create_delegate_trampoline (MonoClass *klass) gpointer mono_add_delegate_trampolines (MonoMethod *method, gpointer compiled_method, gboolean need_unbox) { - gpointer addr; - - addr = mini_add_method_trampoline (method, compiled_method, mono_method_needs_static_rgctx_invoke (method, TRUE), need_unbox); - - return addr; + return mini_add_method_trampoline (method, compiled_method, mono_method_needs_static_rgctx_invoke (method, TRUE), need_unbox); } gpointer diff --git a/src/tests/JIT/Methodical/delegate/GSDelegate.cs b/src/tests/JIT/Methodical/delegate/GSDelegate.cs new file mode 100644 index 0000000000000..cbf80ad8848ac --- /dev/null +++ b/src/tests/JIT/Methodical/delegate/GSDelegate.cs @@ -0,0 +1,53 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using System.Reflection; + + +public interface IGetContents { + (string, int, T) GetContents(); +} +public struct MyStruct : IGetContents { + public string s; + public int a; + public T t; + + public (string, int, T) GetContents() + { + return (s, a, t); + } +} + +public class Program { + + public delegate (string, int, T) MyDelegate(IGetContents arg); + + public static int Main(string[] args) + { + int retVal = 100; + + try { + MyStruct myStruct = new MyStruct(); + myStruct.s = "test1"; + myStruct.a = 42; + myStruct.t = "test2"; + + MethodInfo mi = typeof(IGetContents).GetMethod("GetContents"); + MyDelegate func = (MyDelegate)mi.CreateDelegate(typeof(MyDelegate)); + + (string c1, int c2, string c3) = func(myStruct); + if (c1 != "test1") + retVal = 1; + if (c2 != 42) + retVal = 2; + if (c3 != "test2") + retVal = 3; + } catch (Exception e) { + Console.WriteLine(e); + retVal = 1; + } + + return retVal; + } +} diff --git a/src/tests/JIT/Methodical/delegate/GSDelegate.csproj b/src/tests/JIT/Methodical/delegate/GSDelegate.csproj new file mode 100644 index 0000000000000..4b51e20d8da5d --- /dev/null +++ b/src/tests/JIT/Methodical/delegate/GSDelegate.csproj @@ -0,0 +1,12 @@ + + + Exe + + + PdbOnly + True + + + + + From d6e1d3df1de4d585f9a9eb1d5627aec678e698e9 Mon Sep 17 00:00:00 2001 From: Vlad - Alexandru Ionescu Date: Thu, 13 Apr 2023 02:43:07 +0300 Subject: [PATCH 11/14] Added boxing for valuetype ref Signed-off-by: Vlad - Alexandru Ionescu --- src/mono/mono/metadata/marshal-lightweight.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/mono/mono/metadata/marshal-lightweight.c b/src/mono/mono/metadata/marshal-lightweight.c index 06a20123dbee6..8528ede179d81 100644 --- a/src/mono/mono/metadata/marshal-lightweight.c +++ b/src/mono/mono/metadata/marshal-lightweight.c @@ -2091,6 +2091,10 @@ emit_delegate_invoke_internal_ilgen (MonoMethodBuilder *mb, MonoMethodSignature for (i = 1; i <= sig->param_count; ++i) mono_mb_emit_ldarg (mb, i); mono_mb_emit_ldarg (mb, 1); + if (m_type_is_byref (sig->params [0])) { + mono_mb_emit_op (mb, CEE_LDOBJ, mono_class_from_mono_type_internal (sig->params [0])); + mono_mb_emit_op (mb, CEE_BOX, mono_class_from_mono_type_internal (sig->params [0])); + } mono_mb_emit_ldarg (mb, 0); mono_mb_emit_icall (mb, mono_get_addr_compiled_method); mono_mb_emit_op (mb, CEE_CALLI, target_method_sig); From 0074bea6fcaef0b916ead18e80da9d5648ea7fbe Mon Sep 17 00:00:00 2001 From: Vlad - Alexandru Ionescu Date: Thu, 13 Apr 2023 10:24:47 +0300 Subject: [PATCH 12/14] Added RequiresProcessIsolation property for tests in merged directory Signed-off-by: Vlad - Alexandru Ionescu --- src/tests/JIT/Methodical/delegate/GSDelegate.csproj | 1 + src/tests/JIT/Methodical/delegate/VirtualDelegate.csproj | 1 + 2 files changed, 2 insertions(+) diff --git a/src/tests/JIT/Methodical/delegate/GSDelegate.csproj b/src/tests/JIT/Methodical/delegate/GSDelegate.csproj index 4b51e20d8da5d..96112c69f3c37 100644 --- a/src/tests/JIT/Methodical/delegate/GSDelegate.csproj +++ b/src/tests/JIT/Methodical/delegate/GSDelegate.csproj @@ -1,6 +1,7 @@ Exe + true PdbOnly diff --git a/src/tests/JIT/Methodical/delegate/VirtualDelegate.csproj b/src/tests/JIT/Methodical/delegate/VirtualDelegate.csproj index 30943a0102ed5..c8f15c2cc00c1 100644 --- a/src/tests/JIT/Methodical/delegate/VirtualDelegate.csproj +++ b/src/tests/JIT/Methodical/delegate/VirtualDelegate.csproj @@ -1,6 +1,7 @@ Exe + true PdbOnly From be6daed914f01151c0b5023e879b3dc0121341ac Mon Sep 17 00:00:00 2001 From: Vlad - Alexandru Ionescu Date: Wed, 19 Apr 2023 16:33:34 +0300 Subject: [PATCH 13/14] Using get_ftnptr callback and moving boxing inside the icall Signed-off-by: Vlad - Alexandru Ionescu --- src/mono/mono/metadata/icall-signatures.h | 1 + src/mono/mono/metadata/icall.c | 2 +- src/mono/mono/metadata/marshal-lightweight.c | 4 --- src/mono/mono/metadata/marshal.c | 26 +++++++++++++++----- src/mono/mono/metadata/marshal.h | 2 +- src/mono/mono/metadata/object-internals.h | 2 +- src/mono/mono/mini/mini-runtime.c | 4 +-- 7 files changed, 26 insertions(+), 15 deletions(-) diff --git a/src/mono/mono/metadata/icall-signatures.h b/src/mono/mono/metadata/icall-signatures.h index 16b35efa530ce..d45f1a569c31e 100644 --- a/src/mono/mono/metadata/icall-signatures.h +++ b/src/mono/mono/metadata/icall-signatures.h @@ -206,6 +206,7 @@ ICALL_SIG (3, (ptr, object, int)) \ ICALL_SIG (3, (ptr, ptr, int)) \ ICALL_SIG (3, (ptr, ptr, int32)) \ ICALL_SIG (3, (ptr, ptr, ptr)) \ +ICALL_SIG (3, (ptr, ptr, object)) \ ICALL_SIG (3, (ptr, ptr, ptrref)) \ ICALL_SIG (3, (ptr, uint32, ptrref)) \ ICALL_SIG (3, (uint32, double, double)) \ diff --git a/src/mono/mono/metadata/icall.c b/src/mono/mono/metadata/icall.c index 63a83b091ee51..0a7dbc9749595 100644 --- a/src/mono/mono/metadata/icall.c +++ b/src/mono/mono/metadata/icall.c @@ -6176,7 +6176,7 @@ mono_method_get_unmanaged_wrapper_ftnptr_internal (MonoMethod *method, gboolean } else { g_assert (!only_unmanaged_callers_only); } - return mono_get_runtime_callbacks ()->get_ftnptr (method, error); + return mono_get_runtime_callbacks ()->get_ftnptr (method, FALSE, error); } MonoBoolean diff --git a/src/mono/mono/metadata/marshal-lightweight.c b/src/mono/mono/metadata/marshal-lightweight.c index 8528ede179d81..06a20123dbee6 100644 --- a/src/mono/mono/metadata/marshal-lightweight.c +++ b/src/mono/mono/metadata/marshal-lightweight.c @@ -2091,10 +2091,6 @@ emit_delegate_invoke_internal_ilgen (MonoMethodBuilder *mb, MonoMethodSignature for (i = 1; i <= sig->param_count; ++i) mono_mb_emit_ldarg (mb, i); mono_mb_emit_ldarg (mb, 1); - if (m_type_is_byref (sig->params [0])) { - mono_mb_emit_op (mb, CEE_LDOBJ, mono_class_from_mono_type_internal (sig->params [0])); - mono_mb_emit_op (mb, CEE_BOX, mono_class_from_mono_type_internal (sig->params [0])); - } mono_mb_emit_ldarg (mb, 0); mono_mb_emit_icall (mb, mono_get_addr_compiled_method); mono_mb_emit_op (mb, CEE_CALLI, target_method_sig); diff --git a/src/mono/mono/metadata/marshal.c b/src/mono/mono/metadata/marshal.c index 3ad970ba6316a..977ecd9e768e7 100644 --- a/src/mono/mono/metadata/marshal.c +++ b/src/mono/mono/metadata/marshal.c @@ -324,7 +324,7 @@ mono_marshal_init (void) register_icall (monoeg_g_free, mono_icall_sig_void_ptr, FALSE); register_icall (mono_object_isinst_icall, mono_icall_sig_object_object_ptr, TRUE); register_icall (mono_struct_delete_old, mono_icall_sig_void_ptr_ptr, FALSE); - register_icall (mono_get_addr_compiled_method, mono_icall_sig_ptr_object_ptr, FALSE); + register_icall (mono_get_addr_compiled_method, mono_icall_sig_ptr_ptr_object, FALSE); register_icall (mono_delegate_begin_invoke, mono_icall_sig_object_object_ptr, FALSE); register_icall (mono_delegate_end_invoke, mono_icall_sig_object_object_ptr, FALSE); register_icall (mono_gc_wbarrier_generic_nostore_internal, mono_icall_sig_void_ptr, TRUE); @@ -5477,22 +5477,32 @@ mono_struct_delete_old (MonoClass *klass, char *ptr) } void* -mono_get_addr_compiled_method (MonoObject *object, MonoDelegate *del) +mono_get_addr_compiled_method (gpointer arg, MonoDelegate *del) { ERROR_DECL (error); MonoMethod *res, *method = del->method; gpointer addr; gboolean need_unbox = FALSE; - if (object == NULL) { + if (arg == NULL) { mono_error_set_null_reference (error); mono_error_set_pending_exception (error); return NULL; } - res = mono_object_get_virtual_method_internal (object, method); + MonoClass *klass = del->object.vtable->klass; + MonoMethod *invoke = mono_get_delegate_invoke_internal (klass); + MonoMethodSignature *invoke_sig = mono_method_signature_internal (invoke); + + MonoClass *arg_class = NULL; + if (m_type_is_byref (invoke_sig->params [0])) { + arg_class = mono_class_from_mono_type_internal (invoke_sig->params [0]); + } else { + MonoObject *object = (MonoObject*)arg; + arg_class = object->vtable->klass; + } - addr = mono_compile_method_checked (res, error); + res = mono_class_get_virtual_method (arg_class, method, error); if (!is_ok (error)) { mono_error_set_pending_exception (error); @@ -5500,7 +5510,11 @@ mono_get_addr_compiled_method (MonoObject *object, MonoDelegate *del) } need_unbox = m_class_is_valuetype (res->klass) && !m_class_is_valuetype (method->klass); - addr = mono_get_runtime_callbacks ()->add_delegate_trampolines (res, addr, need_unbox); + addr = mono_get_runtime_callbacks ()->get_ftnptr (res, need_unbox, error); + if (!is_ok (error)) { + mono_error_set_pending_exception (error); + return NULL; + } return addr; } diff --git a/src/mono/mono/metadata/marshal.h b/src/mono/mono/metadata/marshal.h index d8022a8baff5f..e6ad3153bbfda 100644 --- a/src/mono/mono/metadata/marshal.h +++ b/src/mono/mono/metadata/marshal.h @@ -626,7 +626,7 @@ mono_struct_delete_old (MonoClass *klass, char *ptr); ICALL_EXPORT void* -mono_get_addr_compiled_method (MonoObject *object, MonoDelegate *del); +mono_get_addr_compiled_method (gpointer arg, MonoDelegate *del); int mono_emit_marshal (EmitMarshalContext *m, int argnum, MonoType *t, diff --git a/src/mono/mono/metadata/object-internals.h b/src/mono/mono/metadata/object-internals.h index 9fb2baff346a0..082a7ff42f9f3 100644 --- a/src/mono/mono/metadata/object-internals.h +++ b/src/mono/mono/metadata/object-internals.h @@ -695,7 +695,7 @@ typedef struct { void (*get_jit_stats)(gint64 *methods_compiled, gint64 *cil_code_size_bytes, gint64 *native_code_size_bytes, gint64 *jit_time); void (*get_exception_stats)(guint32 *exception_count); // Same as compile_method, but returns a MonoFtnDesc in llvmonly mode - gpointer (*get_ftnptr)(MonoMethod *method, MonoError *error); + gpointer (*get_ftnptr)(MonoMethod *method, gboolean need_unbox, MonoError *error); void (*interp_jit_info_foreach)(InterpJitInfoFunc func, gpointer user_data); gboolean (*interp_sufficient_stack)(gsize size); void (*init_class) (MonoClass *klass); diff --git a/src/mono/mono/mini/mini-runtime.c b/src/mono/mono/mini/mini-runtime.c index ff9f6f0f5146f..3657d9feaa434 100644 --- a/src/mono/mono/mini/mini-runtime.c +++ b/src/mono/mono/mini/mini-runtime.c @@ -2817,11 +2817,11 @@ mono_jit_compile_method_jit_only (MonoMethod *method, MonoError *error) * On llvmonly, this returns a MonoFtnDesc, otherwise it returns a normal function pointer. */ static gpointer -get_ftnptr_for_method (MonoMethod *method, MonoError *error) +get_ftnptr_for_method (MonoMethod *method, gboolean need_unbox, MonoError *error) { if (!mono_llvm_only) { gpointer res = mono_jit_compile_method (method, error); - res = mini_add_method_trampoline (method, res, mono_method_needs_static_rgctx_invoke (method, TRUE), FALSE); + res = mini_add_method_trampoline (method, res, mono_method_needs_static_rgctx_invoke (method, TRUE), need_unbox); return res; } else { return mini_llvmonly_load_method_ftndesc (method, FALSE, FALSE, error); From 1d2c4fbf710906c9dd81ad29e8faf11a01649df7 Mon Sep 17 00:00:00 2001 From: Vlad - Alexandru Ionescu Date: Mon, 24 Apr 2023 14:08:46 +0200 Subject: [PATCH 14/14] Rremoved add_delegate_trampoline since it's not used anymore Signed-off-by: Vlad - Alexandru Ionescu --- src/mono/mono/metadata/object-internals.h | 1 - src/mono/mono/mini/mini-runtime.c | 1 - src/mono/mono/mini/mini-trampolines.c | 5 ----- src/mono/mono/mini/mini.h | 1 - 4 files changed, 8 deletions(-) diff --git a/src/mono/mono/metadata/object-internals.h b/src/mono/mono/metadata/object-internals.h index 082a7ff42f9f3..1c3bedcc66eaa 100644 --- a/src/mono/mono/metadata/object-internals.h +++ b/src/mono/mono/metadata/object-internals.h @@ -699,7 +699,6 @@ typedef struct { void (*interp_jit_info_foreach)(InterpJitInfoFunc func, gpointer user_data); gboolean (*interp_sufficient_stack)(gsize size); void (*init_class) (MonoClass *klass); - gpointer (*add_delegate_trampolines) (MonoMethod *method, gpointer compiled_method, gboolean need_unbox); MonoArray *(*get_trace) (MonoException *exc, gint32 skip, MonoBoolean need_file_info); MonoBoolean (*get_frame_info) (gint32 skip, MonoMethod **out_method, MonoDebugSourceLocation **out_location, diff --git a/src/mono/mono/mini/mini-runtime.c b/src/mono/mono/mini/mini-runtime.c index 773c1a4c01bec..cc2069539ac63 100644 --- a/src/mono/mono/mini/mini-runtime.c +++ b/src/mono/mono/mini/mini-runtime.c @@ -4561,7 +4561,6 @@ mini_init (const char *filename) callbacks.init_class = init_class; callbacks.get_trace = mono_get_trace; callbacks.get_frame_info = mono_get_frame_info; - callbacks.add_delegate_trampolines = mono_add_delegate_trampolines; mono_install_callbacks (&callbacks); diff --git a/src/mono/mono/mini/mini-trampolines.c b/src/mono/mono/mini/mini-trampolines.c index 7e28a95de562f..0d7bfe97d47b0 100644 --- a/src/mono/mono/mini/mini-trampolines.c +++ b/src/mono/mono/mini/mini-trampolines.c @@ -1468,11 +1468,6 @@ mono_create_delegate_trampoline (MonoClass *klass) return mono_create_delegate_trampoline_info (klass, NULL, FALSE)->invoke_impl; } -gpointer mono_add_delegate_trampolines (MonoMethod *method, gpointer compiled_method, gboolean need_unbox) -{ - return mini_add_method_trampoline (method, compiled_method, mono_method_needs_static_rgctx_invoke (method, TRUE), need_unbox); -} - gpointer mono_create_rgctx_lazy_fetch_trampoline (guint32 offset) { diff --git a/src/mono/mono/mini/mini.h b/src/mono/mono/mini/mini.h index c3bc0124979e0..a21e3c331af3e 100644 --- a/src/mono/mono/mini/mini.h +++ b/src/mono/mono/mini/mini.h @@ -2271,7 +2271,6 @@ gpointer mono_create_jump_trampoline (MonoMethod *method, gpointer mono_create_jit_trampoline (MonoMethod *method, MonoError *error); gpointer mono_create_jit_trampoline_from_token (MonoImage *image, guint32 token); gpointer mono_create_delegate_trampoline (MonoClass *klass); -gpointer mono_add_delegate_trampolines (MonoMethod *method, gpointer compiled_method, gboolean need_unbox); MonoDelegateTrampInfo* mono_create_delegate_trampoline_info (MonoClass *klass, MonoMethod *method, gboolean is_virtual); gpointer mono_create_rgctx_lazy_fetch_trampoline (guint32 offset); gpointer mono_create_static_rgctx_trampoline (MonoMethod *m, gpointer addr);