From 95d64ad162173c85a728b87fc8a2e996b280297a Mon Sep 17 00:00:00 2001 From: Nathan Ricci Date: Tue, 25 Oct 2022 15:59:21 -0400 Subject: [PATCH 1/7] Use flag to initilize ilgen, instead of doing it lazily. --- src/mono/mono/metadata/marshal-ilgen.c | 10 ++-------- src/mono/mono/metadata/marshal-ilgen.h | 4 ++++ src/mono/mono/metadata/marshal-lightweight.c | 13 +++++++++++++ src/mono/mono/metadata/marshal-lightweight.h | 3 +++ src/mono/mono/metadata/marshal.c | 10 +--------- src/mono/mono/mini/mini-runtime.c | 17 +++++++++++++++++ 6 files changed, 40 insertions(+), 17 deletions(-) diff --git a/src/mono/mono/metadata/marshal-ilgen.c b/src/mono/mono/metadata/marshal-ilgen.c index ceceb70149f21b..a67290f8580403 100644 --- a/src/mono/mono/metadata/marshal-ilgen.c +++ b/src/mono/mono/metadata/marshal-ilgen.c @@ -2717,13 +2717,7 @@ emit_marshal_variant_ilgen (EmitMarshalContext *m, int argnum, MonoType *t, static MonoMarshalIlgenCallbacks * get_marshal_cb (void) { - if (G_UNLIKELY (!ilgen_cb_inited)) { -#ifdef ENABLE_ILGEN - mono_marshal_ilgen_init (); -#else - mono_marshal_noilgen_init_heavyweight (); -#endif - } + g_assert(ilgen_cb_inited); return &ilgen_marshal_cb; } @@ -2804,7 +2798,7 @@ mono_emit_marshal_ilgen (EmitMarshalContext *m, int argnum, MonoType *t, } void -mono_marshal_ilgen_init (void) +mono_marshal_ilgen_init_internal (void) { MonoMarshalIlgenCallbacks cb; cb.version = MONO_MARSHAL_CALLBACKS_VERSION; diff --git a/src/mono/mono/metadata/marshal-ilgen.h b/src/mono/mono/metadata/marshal-ilgen.h index 1b3914588fb2e4..07ec9906dfe3ff 100644 --- a/src/mono/mono/metadata/marshal-ilgen.h +++ b/src/mono/mono/metadata/marshal-ilgen.h @@ -39,4 +39,8 @@ mono_emit_marshal_ilgen (EmitMarshalContext *m, int argnum, MonoType *t, MonoMarshalSpec *spec, int conv_arg, MonoType **conv_arg_type, MarshalAction action, MonoMarshalLightweightCallbacks* lightweigth_cb); + +void +mono_marshal_ilgen_init_internal (void); + #endif // __MARSHAL_ILGEN_H__ \ No newline at end of file diff --git a/src/mono/mono/metadata/marshal-lightweight.c b/src/mono/mono/metadata/marshal-lightweight.c index 70a8ee0ede2947..be29ff78fe5901 100644 --- a/src/mono/mono/metadata/marshal-lightweight.c +++ b/src/mono/mono/metadata/marshal-lightweight.c @@ -68,6 +68,19 @@ get_method_image (MonoMethod *method) return m_class_get_image (method->klass); } +static gboolean embedder_requests_ilgen_callbacks = FALSE; +MONO_API void +mono_marshal_ilgen_init (void) +{ + embedder_requests_ilgen_callbacks = TRUE; +} + +gboolean +mono_marshal_did_embedder_request_ilgen_callbacks (void) +{ + return embedder_requests_ilgen_callbacks; +} + /** * mono_mb_strdup: * \param mb the MethodBuilder diff --git a/src/mono/mono/metadata/marshal-lightweight.h b/src/mono/mono/metadata/marshal-lightweight.h index 8dfd4803a96496..be2cbbe9c9f972 100644 --- a/src/mono/mono/metadata/marshal-lightweight.h +++ b/src/mono/mono/metadata/marshal-lightweight.h @@ -9,4 +9,7 @@ MONO_API void mono_marshal_lightweight_init (void); +gboolean +mono_marshal_did_embedder_request_ilgen_callbacks (void); + #endif // __MONO_MARSHAL_LIGHTWEIGHT_H__ diff --git a/src/mono/mono/metadata/marshal.c b/src/mono/mono/metadata/marshal.c index f7262ee0dff8d4..d810a5a8c67829 100644 --- a/src/mono/mono/metadata/marshal.c +++ b/src/mono/mono/metadata/marshal.c @@ -6254,15 +6254,7 @@ mono_install_marshal_callbacks (MonoMarshalLightweightCallbacks *cb) static MonoMarshalLightweightCallbacks * get_marshal_cb (void) { - - if (G_UNLIKELY (!lightweight_cb_inited)) { -#ifdef ENABLE_ILGEN - mono_marshal_lightweight_init (); -#else - mono_marshal_noilgen_init_lightweight (); -#endif - } - + g_assert (lightweight_cb_inited); return &marshal_lightweight_cb; } diff --git a/src/mono/mono/mini/mini-runtime.c b/src/mono/mono/mini/mini-runtime.c index 5aa0502bc0800e..58c98caa8cce74 100644 --- a/src/mono/mono/mini/mini-runtime.c +++ b/src/mono/mono/mini/mini-runtime.c @@ -41,6 +41,7 @@ #include #include #include +#include #include #include #include @@ -4467,6 +4468,22 @@ mini_init (const char *filename) mono_component_event_pipe_100ns_ticks_start (); + +#ifdef ENABLE_ILGEN + mono_marshal_lightweight_init(); + mono_marshal_ilgen_init_internal(); +#else + if(! mono_marshal_did_embedder_request_ilgen_callbacks()) + { + mono_marshal_lightweight_init(); + mono_marshal_ilgen_init_internal(); + } + else{ + mono_marshal_noilgen_init_lightweight(); + mono_marshal_noilgen_init_heavyweight (); + } +#endif + MONO_VES_INIT_BEGIN (); CHECKED_MONO_INIT (); From b6885b9e0a5a8c711e82c07fec6a121bfcdf8a3a Mon Sep 17 00:00:00 2001 From: Nathan Ricci Date: Wed, 26 Oct 2022 13:15:10 -0400 Subject: [PATCH 2/7] Formatting. --- src/mono/mono/mini/mini-runtime.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/mono/mono/mini/mini-runtime.c b/src/mono/mono/mini/mini-runtime.c index 58c98caa8cce74..ce346ee2b46f86 100644 --- a/src/mono/mono/mini/mini-runtime.c +++ b/src/mono/mono/mini/mini-runtime.c @@ -4470,13 +4470,13 @@ mini_init (const char *filename) #ifdef ENABLE_ILGEN - mono_marshal_lightweight_init(); - mono_marshal_ilgen_init_internal(); + mono_marshal_lightweight_init (); + mono_marshal_ilgen_init_internal (); #else - if(! mono_marshal_did_embedder_request_ilgen_callbacks()) + if(! mono_marshal_did_embedder_request_ilgen_callbacks ()) { - mono_marshal_lightweight_init(); - mono_marshal_ilgen_init_internal(); + mono_marshal_lightweight_init (); + mono_marshal_ilgen_init_internal (); } else{ mono_marshal_noilgen_init_lightweight(); From eb39b4119d2b012248fd09a8f8ec1efa4ed1466f Mon Sep 17 00:00:00 2001 From: Nathan Ricci Date: Wed, 26 Oct 2022 13:20:40 -0400 Subject: [PATCH 3/7] Improve variable naming. --- src/mono/mono/metadata/marshal-lightweight.c | 8 ++++---- src/mono/mono/mini/mini-runtime.c | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/mono/mono/metadata/marshal-lightweight.c b/src/mono/mono/metadata/marshal-lightweight.c index be29ff78fe5901..cc79171907dc38 100644 --- a/src/mono/mono/metadata/marshal-lightweight.c +++ b/src/mono/mono/metadata/marshal-lightweight.c @@ -68,17 +68,17 @@ get_method_image (MonoMethod *method) return m_class_get_image (method->klass); } -static gboolean embedder_requests_ilgen_callbacks = FALSE; +static gboolean ilgen_callbacks_requested = FALSE; MONO_API void mono_marshal_ilgen_init (void) { - embedder_requests_ilgen_callbacks = TRUE; + ilgen_callbacks_requested = TRUE; } gboolean -mono_marshal_did_embedder_request_ilgen_callbacks (void) +mono_marshal_is_ilgen_requested (void) { - return embedder_requests_ilgen_callbacks; + return ilgen_callbacks_requested; } /** diff --git a/src/mono/mono/mini/mini-runtime.c b/src/mono/mono/mini/mini-runtime.c index ce346ee2b46f86..397d3a5ab5d1b9 100644 --- a/src/mono/mono/mini/mini-runtime.c +++ b/src/mono/mono/mini/mini-runtime.c @@ -4473,7 +4473,7 @@ mini_init (const char *filename) mono_marshal_lightweight_init (); mono_marshal_ilgen_init_internal (); #else - if(! mono_marshal_did_embedder_request_ilgen_callbacks ()) + if(! mono_marshal_is_ilgen_requested ()) { mono_marshal_lightweight_init (); mono_marshal_ilgen_init_internal (); From ca52dd3d79022197b6a4d2ba24308d1bbb9f69bb Mon Sep 17 00:00:00 2001 From: Nathan Ricci Date: Wed, 26 Oct 2022 13:31:09 -0400 Subject: [PATCH 4/7] Fix condition. --- src/mono/mono/mini/mini-runtime.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mono/mono/mini/mini-runtime.c b/src/mono/mono/mini/mini-runtime.c index 397d3a5ab5d1b9..0a4ef9fefbb618 100644 --- a/src/mono/mono/mini/mini-runtime.c +++ b/src/mono/mono/mini/mini-runtime.c @@ -4473,7 +4473,7 @@ mini_init (const char *filename) mono_marshal_lightweight_init (); mono_marshal_ilgen_init_internal (); #else - if(! mono_marshal_is_ilgen_requested ()) + if (mono_marshal_is_ilgen_requested ()) { mono_marshal_lightweight_init (); mono_marshal_ilgen_init_internal (); From fb09bfef48cefa3acfee092d1d27a461d1b9a6dc Mon Sep 17 00:00:00 2001 From: Nathan Ricci Date: Wed, 26 Oct 2022 14:47:20 -0400 Subject: [PATCH 5/7] Updated name in .h file. --- src/mono/mono/metadata/marshal-lightweight.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mono/mono/metadata/marshal-lightweight.h b/src/mono/mono/metadata/marshal-lightweight.h index be2cbbe9c9f972..ff33baed393c55 100644 --- a/src/mono/mono/metadata/marshal-lightweight.h +++ b/src/mono/mono/metadata/marshal-lightweight.h @@ -10,6 +10,6 @@ MONO_API void mono_marshal_lightweight_init (void); gboolean -mono_marshal_did_embedder_request_ilgen_callbacks (void); +mono_marshal_is_ilgen_requested (void); #endif // __MONO_MARSHAL_LIGHTWEIGHT_H__ From 4e27fd788c9b776b8ac5d2a6c47d56a5aeb98c85 Mon Sep 17 00:00:00 2001 From: Nathan Ricci Date: Thu, 27 Oct 2022 23:31:25 -0400 Subject: [PATCH 6/7] Updated how wasm inits ilgen. --- src/mono/wasm/runtime/driver.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/mono/wasm/runtime/driver.c b/src/mono/wasm/runtime/driver.c index e2db123f7ab5f2..5434f62585a064 100644 --- a/src/mono/wasm/runtime/driver.c +++ b/src/mono/wasm/runtime/driver.c @@ -55,7 +55,6 @@ int mono_wasm_register_root (char *start, size_t size, const char *name); void mono_wasm_deregister_root (char *addr); void mono_ee_interp_init (const char *opts); -void mono_marshal_lightweight_init (void); void mono_marshal_ilgen_init (void); void mono_method_builder_ilgen_init (void); void mono_sgen_mono_ilgen_init (void); @@ -595,7 +594,6 @@ mono_wasm_load_runtime (const char *unused, int debug_level) #endif #ifdef NEED_INTERP mono_ee_interp_init (interp_opts); - mono_marshal_lightweight_init (); mono_marshal_ilgen_init(); mono_method_builder_ilgen_init (); mono_sgen_mono_ilgen_init (); From 7fbc8759952e8f15a99aa1b4c862aa0e6e77fd59 Mon Sep 17 00:00:00 2001 From: Nathan Ricci Date: Fri, 28 Oct 2022 10:45:21 -0400 Subject: [PATCH 7/7] Updated wasi driver. --- src/mono/wasi/mono-wasi-driver/driver.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/mono/wasi/mono-wasi-driver/driver.c b/src/mono/wasi/mono-wasi-driver/driver.c index 80a0339a0df62a..d8138a46902316 100644 --- a/src/mono/wasi/mono-wasi-driver/driver.c +++ b/src/mono/wasi/mono-wasi-driver/driver.c @@ -481,7 +481,6 @@ mono_wasm_load_runtime (const char *argv, int debug_level) mono_jit_set_aot_mode (MONO_AOT_MODE_INTERP_ONLY); mono_ee_interp_init (interp_opts); - mono_marshal_lightweight_init (); mono_marshal_ilgen_init (); mono_method_builder_ilgen_init (); mono_sgen_mono_ilgen_init ();