Skip to content

Commit 4a5620b

Browse files
github-actions[bot]Nathan Ricci
andauthored
[release/7.0] [MONO][MARSHAL] Initialize ilgen with a flag (#83813)
* 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 <[email protected]>
1 parent eacc9be commit 4a5620b

File tree

8 files changed

+40
-20
lines changed

8 files changed

+40
-20
lines changed

src/mono/mono/metadata/marshal-ilgen.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2717,13 +2717,7 @@ emit_marshal_variant_ilgen (EmitMarshalContext *m, int argnum, MonoType *t,
27172717
static MonoMarshalIlgenCallbacks *
27182718
get_marshal_cb (void)
27192719
{
2720-
if (G_UNLIKELY (!ilgen_cb_inited)) {
2721-
#ifdef ENABLE_ILGEN
2722-
mono_marshal_ilgen_init ();
2723-
#else
2724-
mono_marshal_noilgen_init_heavyweight ();
2725-
#endif
2726-
}
2720+
g_assert(ilgen_cb_inited);
27272721
return &ilgen_marshal_cb;
27282722
}
27292723

@@ -2804,7 +2798,7 @@ mono_emit_marshal_ilgen (EmitMarshalContext *m, int argnum, MonoType *t,
28042798
}
28052799

28062800
void
2807-
mono_marshal_ilgen_init (void)
2801+
mono_marshal_ilgen_init_internal (void)
28082802
{
28092803
MonoMarshalIlgenCallbacks cb;
28102804
cb.version = MONO_MARSHAL_CALLBACKS_VERSION;

src/mono/mono/metadata/marshal-ilgen.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,8 @@ mono_emit_marshal_ilgen (EmitMarshalContext *m, int argnum, MonoType *t,
3939
MonoMarshalSpec *spec, int conv_arg,
4040
MonoType **conv_arg_type, MarshalAction action, MonoMarshalLightweightCallbacks* lightweigth_cb);
4141

42+
43+
void
44+
mono_marshal_ilgen_init_internal (void);
45+
4246
#endif // __MARSHAL_ILGEN_H__

src/mono/mono/metadata/marshal-lightweight.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,19 @@ get_method_image (MonoMethod *method)
6868
return m_class_get_image (method->klass);
6969
}
7070

71+
static gboolean ilgen_callbacks_requested = FALSE;
72+
MONO_API void
73+
mono_marshal_ilgen_init (void)
74+
{
75+
ilgen_callbacks_requested = TRUE;
76+
}
77+
78+
gboolean
79+
mono_marshal_is_ilgen_requested (void)
80+
{
81+
return ilgen_callbacks_requested;
82+
}
83+
7184
/**
7285
* mono_mb_strdup:
7386
* \param mb the MethodBuilder

src/mono/mono/metadata/marshal-lightweight.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,7 @@
99
MONO_API void
1010
mono_marshal_lightweight_init (void);
1111

12+
gboolean
13+
mono_marshal_is_ilgen_requested (void);
14+
1215
#endif // __MONO_MARSHAL_LIGHTWEIGHT_H__

src/mono/mono/metadata/marshal.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6254,15 +6254,7 @@ mono_install_marshal_callbacks (MonoMarshalLightweightCallbacks *cb)
62546254
static MonoMarshalLightweightCallbacks *
62556255
get_marshal_cb (void)
62566256
{
6257-
6258-
if (G_UNLIKELY (!lightweight_cb_inited)) {
6259-
#ifdef ENABLE_ILGEN
6260-
mono_marshal_lightweight_init ();
6261-
#else
6262-
mono_marshal_noilgen_init_lightweight ();
6263-
#endif
6264-
}
6265-
6257+
g_assert (lightweight_cb_inited);
62666258
return &marshal_lightweight_cb;
62676259
}
62686260

src/mono/mono/mini/mini-runtime.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include <mono/metadata/domain-internals.h>
4242
#include <mono/metadata/profiler-private.h>
4343
#include <mono/metadata/mono-config.h>
44+
#include <mono/metadata/marshal-ilgen.h>
4445
#include <mono/metadata/environment.h>
4546
#include <mono/metadata/mono-debug.h>
4647
#include <mono/metadata/gc-internals.h>
@@ -4467,6 +4468,22 @@ mini_init (const char *filename)
44674468

44684469
mono_component_event_pipe_100ns_ticks_start ();
44694470

4471+
4472+
#ifdef ENABLE_ILGEN
4473+
mono_marshal_lightweight_init ();
4474+
mono_marshal_ilgen_init_internal ();
4475+
#else
4476+
if (mono_marshal_is_ilgen_requested ())
4477+
{
4478+
mono_marshal_lightweight_init ();
4479+
mono_marshal_ilgen_init_internal ();
4480+
}
4481+
else{
4482+
mono_marshal_noilgen_init_lightweight();
4483+
mono_marshal_noilgen_init_heavyweight ();
4484+
}
4485+
#endif
4486+
44704487
MONO_VES_INIT_BEGIN ();
44714488

44724489
CHECKED_MONO_INIT ();

src/mono/wasi/mono-wasi-driver/driver.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,6 @@ mono_wasm_load_runtime (const char *argv, int debug_level)
481481
mono_jit_set_aot_mode (MONO_AOT_MODE_INTERP_ONLY);
482482

483483
mono_ee_interp_init (interp_opts);
484-
mono_marshal_lightweight_init ();
485484
mono_marshal_ilgen_init ();
486485
mono_method_builder_ilgen_init ();
487486
mono_sgen_mono_ilgen_init ();

src/mono/wasm/runtime/driver.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ int mono_wasm_register_root (char *start, size_t size, const char *name);
5555
void mono_wasm_deregister_root (char *addr);
5656

5757
void mono_ee_interp_init (const char *opts);
58-
void mono_marshal_lightweight_init (void);
5958
void mono_marshal_ilgen_init (void);
6059
void mono_method_builder_ilgen_init (void);
6160
void mono_sgen_mono_ilgen_init (void);
@@ -595,7 +594,6 @@ mono_wasm_load_runtime (const char *unused, int debug_level)
595594
#endif
596595
#ifdef NEED_INTERP
597596
mono_ee_interp_init (interp_opts);
598-
mono_marshal_lightweight_init ();
599597
mono_marshal_ilgen_init();
600598
mono_method_builder_ilgen_init ();
601599
mono_sgen_mono_ilgen_init ();

0 commit comments

Comments
 (0)