Skip to content

Commit

Permalink
[release/7.0] [MONO][MARSHAL] Initialize ilgen with a flag (#83813)
Browse files Browse the repository at this point in the history
* Use flag to initilize ilgen, instead of doing it lazily.

* Formatting.

* Improve variable naming.

* Fix condition.

* Updated name in .h file.

* Updated how wasm inits ilgen.

* Updated wasi driver.

---------

Co-authored-by: Nathan Ricci <naricc@microsoft.com>
  • Loading branch information
github-actions[bot] and Nathan Ricci committed Apr 5, 2023
1 parent eacc9be commit 4a5620b
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 20 deletions.
10 changes: 2 additions & 8 deletions src/mono/mono/metadata/marshal-ilgen.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/mono/mono/metadata/marshal-ilgen.h
Original file line number Diff line number Diff line change
Expand Up @@ -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__
13 changes: 13 additions & 0 deletions src/mono/mono/metadata/marshal-lightweight.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/mono/mono/metadata/marshal-lightweight.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@
MONO_API void
mono_marshal_lightweight_init (void);

gboolean
mono_marshal_is_ilgen_requested (void);

#endif // __MONO_MARSHAL_LIGHTWEIGHT_H__
10 changes: 1 addition & 9 deletions src/mono/mono/metadata/marshal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
17 changes: 17 additions & 0 deletions src/mono/mono/mini/mini-runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include <mono/metadata/domain-internals.h>
#include <mono/metadata/profiler-private.h>
#include <mono/metadata/mono-config.h>
#include <mono/metadata/marshal-ilgen.h>
#include <mono/metadata/environment.h>
#include <mono/metadata/mono-debug.h>
#include <mono/metadata/gc-internals.h>
Expand Down Expand Up @@ -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 ();
Expand Down
1 change: 0 additions & 1 deletion src/mono/wasi/mono-wasi-driver/driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 ();
Expand Down
2 changes: 0 additions & 2 deletions src/mono/wasm/runtime/driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 ();
Expand Down

0 comments on commit 4a5620b

Please sign in to comment.