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..cc79171907dc38 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 ilgen_callbacks_requested = FALSE; +MONO_API void +mono_marshal_ilgen_init (void) +{ + ilgen_callbacks_requested = TRUE; +} + +gboolean +mono_marshal_is_ilgen_requested (void) +{ + return ilgen_callbacks_requested; +} + /** * 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..ff33baed393c55 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_is_ilgen_requested (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..0a4ef9fefbb618 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_is_ilgen_requested ()) + { + 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 (); 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 (); 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 ();