From 09902c041c4da5d2193d1ddb9d61ed69332687b5 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 33277efff9bb94..6c9104242696ed 100644 --- a/src/mono/mono/metadata/marshal.c +++ b/src/mono/mono/metadata/marshal.c @@ -6259,15 +6259,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 c66a227a242fd9..49e79085e5439e 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 9fb168bd0f73986f2166725f561861b52a68c613 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 49e79085e5439e..b8727c1036ad98 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 bd6420ef1e39f7cdb85cb8abb29cf551d30e5db8 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 b8727c1036ad98..32f800099d2d1d 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 57d6dbf8d5d8647e51c9b7aa35961a196abda1dc 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 32f800099d2d1d..b9791ce273d570 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 1cf89794f844244a8a5faabe0ed4348ff27be6db 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 886dfa43730ae1c3605b77fe193a0d06c1e01684 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 235c2448d6de64..20458ac22b886a 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); @@ -586,7 +585,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 2067421222f9e9243e679dcc34f8ad0ec6c94482 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 013fe0538f2930..fdaf95a571f615 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 ();