Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Use flag to initilize ilgen, instead of doing it lazily.
  • Loading branch information
Nathan Ricci committed Oct 25, 2022
commit 09902c041c4da5d2193d1ddb9d61ed69332687b5
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 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
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_did_embedder_request_ilgen_callbacks (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 @@ -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;
}

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_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 ();
Expand Down