2 * aot.c: mono Ahead of Time compiler
5 * Dietmar Maurer (dietmar@ximian.com)
6 * Zoltan Varga (vargaz@gmail.com)
8 * (C) 2002 Ximian, Inc.
12 #include <sys/types.h>
18 #ifndef PLATFORM_WIN32
25 #ifdef HAVE_EXECINFO_H
31 #include <limits.h> /* for PAGESIZE */
36 #ifdef HAVE_SYS_WAIT_H
37 #include <sys/wait.h> /* for WIFEXITED, WEXITSTATUS */
40 #include <mono/metadata/tabledefs.h>
41 #include <mono/metadata/class.h>
42 #include <mono/metadata/object.h>
43 #include <mono/metadata/tokentype.h>
44 #include <mono/metadata/appdomain.h>
45 #include <mono/metadata/debug-helpers.h>
46 #include <mono/metadata/assembly.h>
47 #include <mono/metadata/metadata-internals.h>
48 #include <mono/metadata/marshal.h>
49 #include <mono/metadata/gc-internal.h>
50 #include <mono/utils/mono-logger.h>
51 #include "mono/utils/mono-compiler.h"
59 #define SHARED_EXT ".dll"
60 #elif (defined(__ppc__) || defined(__ppc64__)) || defined(__MACH__)
61 #define SHARED_EXT ".dylib"
63 #define SHARED_EXT ".so"
66 #define ALIGN_PTR_TO(ptr,align) (gpointer)((((gssize)(ptr)) + (align - 1)) & (~(align - 1)))
67 #define ROUND_DOWN(VALUE,SIZE) ((VALUE) & ~((SIZE) - 1))
69 typedef struct MonoAotModule {
71 /* Optimization flags used to compile the module */
73 /* Pointer to the Global Offset Table */
76 GHashTable *name_cache;
78 MonoAssemblyName *image_names;
80 MonoAssembly *assembly;
81 MonoImage **image_table;
82 guint32 image_table_len;
92 guint8 *plt_jump_table;
93 guint32 plt_jump_table_size;
94 guint32 *code_offsets;
96 guint32 *method_info_offsets;
98 guint32 *got_info_offsets;
100 guint32 *ex_info_offsets;
101 guint32 *method_order;
102 guint32 *method_order_end;
104 guint32 *class_info_offsets;
105 guint32 *methods_loaded;
106 guint16 *class_name_table;
107 guint8 *wrapper_info;
109 guint32 num_trampolines, first_trampoline_got_offset, trampoline_index;
114 static GHashTable *aot_modules;
115 #define mono_aot_lock() EnterCriticalSection (&aot_mutex)
116 #define mono_aot_unlock() LeaveCriticalSection (&aot_mutex)
117 static CRITICAL_SECTION aot_mutex;
120 * Maps assembly names to the mono_aot_module_<NAME>_info symbols in the
121 * AOT modules registered by mono_aot_register_module ().
123 static GHashTable *static_aot_modules;
126 * Disabling this will make a copy of the loaded code and use the copy instead
127 * of the original. This will place the caller and the callee close to each
128 * other in memory, possibly improving cache behavior. Since the original
129 * code is in copy-on-write memory, this will not increase the memory usage
132 static gboolean use_loaded_code = TRUE;
135 * Whenever to AOT compile loaded assemblies on demand and store them in
136 * a cache under $HOME/.mono/aot-cache.
138 static gboolean use_aot_cache = FALSE;
141 * Whenever to spawn a new process to AOT a file or do it in-process. Only relevant if
142 * use_aot_cache is TRUE.
144 static gboolean spawn_compiler = TRUE;
147 static gint32 mono_last_aot_method = -1;
149 static gboolean make_unreadable = FALSE;
150 static guint32 n_pagefaults = 0;
151 static guint32 name_table_accesses = 0;
153 /* Used to speed-up find_aot_module () */
154 static gsize aot_code_low_addr = (gssize)-1;
155 static gsize aot_code_high_addr = 0;
157 /* Used to communicate with mono_aot_register_globals () */
158 static guint32 globals_tls_id = -1;
161 mono_aot_load_method (MonoDomain *domain, MonoAotModule *aot_module, MonoMethod *method, guint8 *code, guint8 *info, int method_index);
164 init_plt (MonoAotModule *info);
167 load_patch_info (MonoAotModule *aot_module, MonoMemPool *mp, int n_patches,
168 guint32 got_index, guint32 **got_slots,
169 guint8 *buf, guint8 **endbuf);
171 static inline gboolean
172 is_got_patch (MonoJumpInfoType patch_type)
177 /*****************************************************/
179 /*****************************************************/
182 load_image (MonoAotModule *module, int index)
184 MonoAssembly *assembly;
185 MonoImageOpenStatus status;
187 g_assert (index < module->image_table_len);
189 if (module->image_table [index])
190 return module->image_table [index];
191 if (module->out_of_date)
194 assembly = mono_assembly_load (&module->image_names [index], NULL, &status);
196 mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_AOT, "AOT module %s is unusable because dependency %s is not found.\n", module->aot_name, module->image_names [index].name);
197 module->out_of_date = TRUE;
201 if (strcmp (assembly->image->guid, module->image_guids [index])) {
202 mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_AOT, "AOT module %s is out of date (Older than dependency %s).\n", module->aot_name, module->image_names [index].name);
203 module->out_of_date = TRUE;
207 module->image_table [index] = assembly->image;
208 return assembly->image;
213 decode_value (guint8 *ptr, guint8 **rptr)
218 if ((b & 0x80) == 0){
221 } else if ((b & 0x40) == 0){
222 len = ((b & 0x3f) << 8 | ptr [1]);
224 } else if (b != 0xff) {
225 len = ((b & 0x1f) << 24) |
232 len = (ptr [1] << 24) | (ptr [2] << 16) | (ptr [3] << 8) | ptr [4];
238 //printf ("DECODE: %d.\n", len);
243 decode_method_ref_2 (MonoAotModule *module, guint8 *buf, guint8 **endbuf);
246 decode_klass_ref (MonoAotModule *module, guint8 *buf, guint8 **endbuf)
249 MonoClass *klass, *eklass;
253 token = decode_value (p, &p);
258 if (mono_metadata_token_table (token) == 0) {
259 image = load_image (module, decode_value (p, &p));
262 klass = mono_class_get (image, MONO_TOKEN_TYPE_DEF + token);
263 } else if (mono_metadata_token_table (token) == MONO_TABLE_TYPESPEC) {
264 if (token == MONO_TOKEN_TYPE_SPEC) {
265 MonoTypeEnum type = decode_value (p, &p);
267 if (type == MONO_TYPE_GENERICINST) {
270 MonoGenericContext ctx;
271 MonoGenericInst inst;
274 gclass = decode_klass_ref (module, p, &p);
275 g_assert (gclass->generic_container);
277 memset (&ctx, 0, sizeof (ctx));
278 memset (&inst, 0, sizeof (inst));
279 ctx.class_inst = &inst;
280 inst.type_argc = decode_value (p, &p);
281 inst.type_argv = g_new0 (MonoType*, inst.type_argc);
282 for (i = 0; i < inst.type_argc; ++i) {
283 MonoClass *pclass = decode_klass_ref (module, p, &p);
285 g_free (inst.type_argv);
288 inst.type_argv [i] = &pclass->byval_arg;
290 type = mono_class_inflate_generic_type (&gclass->byval_arg, &ctx);
291 klass = mono_class_from_mono_type (type);
292 mono_metadata_free_type (type);
293 } else if ((type == MONO_TYPE_VAR) || (type == MONO_TYPE_MVAR)) {
297 // FIXME: Maybe use types directly to avoid
298 // the overhead of creating MonoClass-es
300 // FIXME: Memory management
301 t = g_new0 (MonoType, 1);
303 t->data.generic_param = g_new0 (MonoGenericParam, 1);
304 t->data.generic_param->num = decode_value (p, &p);
306 is_method = decode_value (p, &p);
308 g_assert_not_reached ();
310 MonoClass *class_def = decode_klass_ref (module, p, &p);
313 g_free (t->data.generic_param);
318 g_assert (class_def->generic_container);
319 t->data.generic_param->owner = class_def->generic_container;
322 klass = mono_class_from_mono_type (t);
324 g_assert_not_reached ();
327 image = load_image (module, decode_value (p, &p));
330 klass = mono_class_get (image, token);
332 } else if (token == MONO_TOKEN_TYPE_DEF) {
334 image = load_image (module, decode_value (p, &p));
337 rank = decode_value (p, &p);
338 eklass = decode_klass_ref (module, p, &p);
339 klass = mono_array_class_get (eklass, rank);
341 g_assert_not_reached ();
344 mono_class_init (klass);
350 static MonoClassField*
351 decode_field_info (MonoAotModule *module, guint8 *buf, guint8 **endbuf)
353 MonoClass *klass = decode_klass_ref (module, buf, &buf);
359 token = MONO_TOKEN_FIELD_DEF + decode_value (buf, &buf);
363 return mono_class_get_field (klass, token);
369 * Decode a method reference, and return its image and token. This avoids loading
370 * metadata for the method if the caller does not need it. If the method has no token,
371 * then it is loaded from metadata and METHOD is set to the method instance.
373 static inline MonoImage*
374 decode_method_ref (MonoAotModule *module, guint32 *token, MonoMethod **method, guint8 *buf, guint8 **endbuf)
376 guint32 image_index, value;
382 value = decode_value (buf, &buf);
383 image_index = value >> 24;
385 if (image_index == 255) {
387 image_index = decode_value (buf, &buf);
388 *token = decode_value (buf, &buf);
390 image = load_image (module, image_index);
393 } else if (image_index == 254) {
394 /* Method on generic instance */
396 MonoGenericContext context;
399 * These methods do not have a token which resolves them, so we
400 * resolve them immediately.
402 klass = decode_klass_ref (module, buf, &buf);
406 image_index = decode_value (buf, &buf);
407 *token = decode_value (buf, &buf);
409 image = load_image (module, image_index);
413 if (klass->generic_class) {
415 *method = mono_get_method_full (image, *token, NULL, NULL);
418 g_assert (klass->generic_class);
419 context.class_inst = klass->generic_class->context.class_inst;
420 context.method_inst = NULL;
422 *method = mono_class_inflate_generic_method_full (*method, klass, &context);
425 *token = MONO_TOKEN_METHOD_DEF | (value & 0xffffff);
427 image = load_image (module, image_index);
438 * decode_method_ref_2:
440 * Similar to decode_method_ref, but resolve and return the method itself.
443 decode_method_ref_2 (MonoAotModule *module, guint8 *buf, guint8 **endbuf)
447 MonoImage *image = decode_method_ref (module, &token, &method, buf, endbuf);
453 return mono_get_method (image, token, NULL);
458 make_writable (guint8* addr, guint32 len)
460 #ifndef PLATFORM_WIN32
465 g_error ("Attempt to make AOT memory writable while running in aot-only mode.\n");
467 page_start = (guint8 *) (((gssize) (addr)) & ~ (PAGESIZE - 1));
468 pages = (addr + len - page_start + PAGESIZE - 1) / PAGESIZE;
469 err = mprotect (page_start, pages * PAGESIZE, PROT_READ | PROT_WRITE | PROT_EXEC);
474 g_assert (VirtualProtect (addr, len, PAGE_EXECUTE_READWRITE, &oldp) != 0);
480 create_cache_structure (void)
486 home = g_get_home_dir ();
490 tmp = g_build_filename (home, ".mono", NULL);
491 if (!g_file_test (tmp, G_FILE_TEST_IS_DIR)) {
492 mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_AOT, "AOT creating directory %s", tmp);
493 #ifdef PLATFORM_WIN32
496 err = mkdir (tmp, 0777);
499 mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_AOT, "AOT failed: %s", g_strerror (errno));
505 tmp = g_build_filename (home, ".mono", "aot-cache", NULL);
506 if (!g_file_test (tmp, G_FILE_TEST_IS_DIR)) {
507 mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_AOT, "AOT creating directory %s", tmp);
508 #ifdef PLATFORM_WIN32
511 err = mkdir (tmp, 0777);
514 mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_AOT, "AOT failed: %s", g_strerror (errno));
523 * load_aot_module_from_cache:
525 * Experimental code to AOT compile loaded assemblies on demand.
528 * - Add environment variable MONO_AOT_CACHE_OPTIONS
529 * - Add options for controlling the cache size
530 * - Handle full cache by deleting old assemblies lru style
531 * - Add options for excluding assemblies during development
532 * - Maybe add a threshold after an assembly is AOT compiled
533 * - invoking a new mono process is a security risk
534 * - recompile the AOT module if one of its dependencies changes
537 load_aot_module_from_cache (MonoAssembly *assembly, char **aot_name)
539 char *fname, *cmd, *tmp2, *aot_options;
548 if (assembly->image->dynamic)
551 create_cache_structure ();
553 home = g_get_home_dir ();
555 tmp2 = g_strdup_printf ("%s-%s%s", assembly->image->assembly_name, assembly->image->guid, SHARED_EXT);
556 fname = g_build_filename (home, ".mono", "aot-cache", tmp2, NULL);
560 mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_AOT, "AOT trying to load from cache: '%s'.", fname);
561 module = mono_dl_open (fname, MONO_DL_LAZY, NULL);
564 mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_AOT, "AOT not found.");
566 mono_trace (G_LOG_LEVEL_MESSAGE, MONO_TRACE_AOT, "AOT precompiling assembly '%s'... ", assembly->image->name);
568 aot_options = g_strdup_printf ("outfile=%s", fname);
570 if (spawn_compiler) {
571 /* FIXME: security */
572 /* FIXME: Has to pass the assembly loading path to the child process */
573 cmd = g_strdup_printf ("mono -O=all --aot=%s %s", aot_options, assembly->image->name);
575 res = g_spawn_command_line_sync (cmd, &out, &err, &exit_status, NULL);
577 #if !defined(PLATFORM_WIN32) && !defined(__ppc__) && !defined(__ppc64__) && !defined(__powerpc__)
579 if (!WIFEXITED (exit_status) && (WEXITSTATUS (exit_status) == 0))
580 mono_trace (G_LOG_LEVEL_MESSAGE, MONO_TRACE_AOT, "AOT failed: %s.", err);
582 mono_trace (G_LOG_LEVEL_MESSAGE, MONO_TRACE_AOT, "AOT succeeded.");
589 res = mono_compile_assembly (assembly, mono_parse_default_optimizations (NULL), aot_options);
591 mono_trace (G_LOG_LEVEL_MESSAGE, MONO_TRACE_AOT, "AOT failed.");
593 mono_trace (G_LOG_LEVEL_MESSAGE, MONO_TRACE_AOT, "AOT succeeded.");
597 module = mono_dl_open (fname, MONO_DL_LAZY, NULL);
599 g_free (aot_options);
606 find_symbol (MonoDl *module, gpointer *globals, const char *name, gpointer *value)
612 for (i = 0; globals [i]; i+= 2) {
613 if (strcmp (globals [i], name) == 0) {
614 *value = globals [i + 1];
619 mono_dl_symbol (module, name, value);
624 load_aot_module (MonoAssembly *assembly, gpointer user_data)
627 MonoAotModule *amodule;
629 gboolean usable = TRUE;
630 char *saved_guid = NULL;
631 char *aot_version = NULL;
632 char *runtime_version;
633 char *opt_flags = NULL;
635 gboolean full_aot = FALSE;
636 gpointer *plt_jump_table_addr = NULL;
637 guint32 *plt_jump_table_size = NULL;
638 guint32 *trampolines_info = NULL;
639 gpointer *got_addr = NULL;
640 gpointer *got = NULL;
641 guint32 *got_size_ptr = NULL;
644 if (mono_compile_aot)
647 if (assembly->image->aot_module)
649 * Already loaded. This can happen because the assembly loading code might invoke
650 * the assembly load hooks multiple times for the same assembly.
654 if (assembly->image->dynamic)
658 if (static_aot_modules)
659 globals = g_hash_table_lookup (static_aot_modules, assembly->aname.name);
665 /* Statically linked AOT module */
667 aot_name = g_strdup_printf ("%s", assembly->aname.name);
668 mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_AOT, "Found statically linked AOT module '%s'.\n", aot_name);
670 TlsSetValue (globals_tls_id, NULL);
673 sofile = load_aot_module_from_cache (assembly, &aot_name);
676 aot_name = g_strdup_printf ("%s%s", assembly->image->name, SHARED_EXT);
678 sofile = mono_dl_open (aot_name, MONO_DL_LAZY, &err);
681 mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_AOT, "AOT failed to load AOT module %s: %s\n", aot_name, err);
687 * If the image was compiled in no-dlsym mode, it contains no global symbols,
688 * instead it contains an ELF ctor function which is called by dlopen () which
689 * in turn calls mono_aot_register_globals () to register a table which contains
690 * the name and address of the globals.
692 globals = TlsGetValue (globals_tls_id);
693 TlsSetValue (globals_tls_id, NULL);
696 if (!sofile && !globals) {
698 fprintf (stderr, "Failed to load AOT module '%s' in aot-only mode.\n", aot_name);
705 find_symbol (sofile, globals, "mono_assembly_guid", (gpointer *) &saved_guid);
706 find_symbol (sofile, globals, "mono_aot_version", (gpointer *) &aot_version);
707 find_symbol (sofile, globals, "mono_aot_opt_flags", (gpointer *)&opt_flags);
708 find_symbol (sofile, globals, "mono_runtime_version", (gpointer *)&runtime_version);
710 if (!aot_version || strcmp (aot_version, MONO_AOT_FILE_VERSION)) {
711 mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_AOT, "AOT module %s has wrong file format version (expected %s got %s)\n", aot_name, MONO_AOT_FILE_VERSION, aot_version);
715 if (!saved_guid || strcmp (assembly->image->guid, saved_guid)) {
716 mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_AOT, "AOT module %s is out of date.\n", aot_name);
721 if (!runtime_version || ((strlen (runtime_version) > 0 && strcmp (runtime_version, FULL_VERSION)))) {
722 mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_AOT, "AOT module %s is compiled against runtime version %s while this runtime has version %s.\n", aot_name, runtime_version, FULL_VERSION);
729 find_symbol (sofile, globals, "mono_aot_full_aot", (gpointer *)&full_aot_str);
731 if (full_aot_str && !strcmp (full_aot_str, "TRUE"))
735 if (mono_aot_only && !full_aot) {
736 fprintf (stderr, "Can't use AOT image '%s' in aot-only mode because it is not compiled with --aot=full.\n", aot_name);
739 if (!mono_aot_only && full_aot) {
740 mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_AOT, "AOT module %s is compiled with --aot=full.\n", aot_name);
746 fprintf (stderr, "Failed to load AOT module '%s' while running in aot-only mode.\n", aot_name);
751 mono_dl_close (sofile);
752 assembly->image->aot_module = NULL;
756 find_symbol (sofile, globals, "got_addr", (gpointer *)&got_addr);
758 got = (gpointer*)*got_addr;
760 find_symbol (sofile, globals, "got_size", (gpointer *)&got_size_ptr);
761 g_assert (got_size_ptr);
763 amodule = g_new0 (MonoAotModule, 1);
764 amodule->aot_name = aot_name;
765 amodule->assembly = assembly;
767 amodule->got_size = *got_size_ptr;
768 amodule->got [0] = assembly->image;
769 amodule->globals = globals;
770 amodule->sofile = sofile;
772 sscanf (opt_flags, "%d", &amodule->opts);
774 /* Read image table */
776 guint32 table_len, i;
779 find_symbol (sofile, globals, "mono_image_table", (gpointer *)&table);
782 table_len = *(guint32*)table;
783 table += sizeof (guint32);
784 amodule->image_table = g_new0 (MonoImage*, table_len);
785 amodule->image_names = g_new0 (MonoAssemblyName, table_len);
786 amodule->image_guids = g_new0 (char*, table_len);
787 amodule->image_table_len = table_len;
788 for (i = 0; i < table_len; ++i) {
789 MonoAssemblyName *aname = &(amodule->image_names [i]);
791 aname->name = g_strdup (table);
792 table += strlen (table) + 1;
793 amodule->image_guids [i] = g_strdup (table);
794 table += strlen (table) + 1;
796 aname->culture = g_strdup (table);
797 table += strlen (table) + 1;
798 memcpy (aname->public_key_token, table, strlen (table) + 1);
799 table += strlen (table) + 1;
801 table = ALIGN_PTR_TO (table, 8);
802 aname->flags = *(guint32*)table;
804 aname->major = *(guint32*)table;
806 aname->minor = *(guint32*)table;
808 aname->build = *(guint32*)table;
810 aname->revision = *(guint32*)table;
815 /* Read method and method_info tables */
816 find_symbol (sofile, globals, "method_offsets", (gpointer*)&amodule->code_offsets);
817 find_symbol (sofile, globals, "methods", (gpointer*)&amodule->code);
818 find_symbol (sofile, globals, "methods_end", (gpointer*)&amodule->code_end);
819 find_symbol (sofile, globals, "method_info_offsets", (gpointer*)&amodule->method_info_offsets);
820 find_symbol (sofile, globals, "method_info", (gpointer*)&amodule->method_info);
821 find_symbol (sofile, globals, "ex_info_offsets", (gpointer*)&amodule->ex_info_offsets);
822 find_symbol (sofile, globals, "ex_info", (gpointer*)&amodule->ex_info);
823 find_symbol (sofile, globals, "method_order", (gpointer*)&amodule->method_order);
824 find_symbol (sofile, globals, "method_order_end", (gpointer*)&amodule->method_order_end);
825 find_symbol (sofile, globals, "class_info", (gpointer*)&amodule->class_info);
826 find_symbol (sofile, globals, "class_info_offsets", (gpointer*)&amodule->class_info_offsets);
827 find_symbol (sofile, globals, "class_name_table", (gpointer *)&amodule->class_name_table);
828 find_symbol (sofile, globals, "got_info", (gpointer*)&amodule->got_info);
829 find_symbol (sofile, globals, "got_info_offsets", (gpointer*)&amodule->got_info_offsets);
830 find_symbol (sofile, globals, "wrapper_info", (gpointer*)&amodule->wrapper_info);
831 find_symbol (sofile, globals, "trampolines", (gpointer*)&amodule->trampolines);
832 find_symbol (sofile, globals, "mem_end", (gpointer*)&amodule->mem_end);
834 amodule->mem_begin = amodule->code;
836 find_symbol (sofile, globals, "plt", (gpointer*)&amodule->plt);
837 find_symbol (sofile, globals, "plt_end", (gpointer*)&amodule->plt_end);
838 find_symbol (sofile, globals, "plt_info", (gpointer*)&amodule->plt_info);
840 find_symbol (sofile, globals, "plt_jump_table_addr", (gpointer *)&plt_jump_table_addr);
841 g_assert (plt_jump_table_addr);
842 amodule->plt_jump_table = (guint8*)*plt_jump_table_addr;
843 g_assert (amodule->plt_jump_table);
845 find_symbol (sofile, globals, "plt_jump_table_size", (gpointer *)&plt_jump_table_size);
846 g_assert (plt_jump_table_size);
847 amodule->plt_jump_table_size = *plt_jump_table_size;
849 find_symbol (sofile, globals, "trampolines_info", (gpointer *)&trampolines_info);
850 if (trampolines_info) {
851 amodule->num_trampolines = trampolines_info [0];
852 amodule->first_trampoline_got_offset = trampolines_info [1];
855 if (make_unreadable) {
856 #ifndef PLATFORM_WIN32
861 addr = amodule->mem_begin;
862 len = amodule->mem_end - amodule->mem_begin;
864 /* Round down in both directions to avoid modifying data which is not ours */
865 page_start = (guint8 *) (((gssize) (addr)) & ~ (PAGESIZE - 1)) + PAGESIZE;
866 pages = ((addr + len - page_start + PAGESIZE - 1) / PAGESIZE) - 1;
867 err = mprotect (page_start, pages * PAGESIZE, 0);
874 aot_code_low_addr = MIN (aot_code_low_addr, (gsize)amodule->code);
875 aot_code_high_addr = MAX (aot_code_high_addr, (gsize)amodule->code_end);
877 g_hash_table_insert (aot_modules, assembly, amodule);
880 mono_jit_info_add_aot_module (assembly->image, amodule->code, amodule->code_end);
882 assembly->image->aot_module = amodule;
885 * Since we store methoddef and classdef tokens when referring to methods/classes in
886 * referenced assemblies, we depend on the exact versions of the referenced assemblies.
887 * MS calls this 'hard binding'. This means we have to load all referenced assemblies
888 * non-lazily, since we can't handle out-of-date errors later.
890 for (i = 0; i < amodule->image_table_len; ++i)
891 load_image (amodule, i);
893 if (amodule->out_of_date) {
894 mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_AOT, "AOT Module %s is unusable because a dependency is out-of-date.\n", assembly->image->name);
896 fprintf (stderr, "Failed to load AOT module '%s' while running in aot-only mode because a dependency cannot be found or it is out of date.\n", aot_name);
901 mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_AOT, "AOT loaded AOT Module for %s.\n", assembly->image->name);
905 * mono_aot_register_globals:
907 * This is called by the ctor function in AOT images compiled with the
911 mono_aot_register_globals (gpointer *globals)
913 TlsSetValue (globals_tls_id, globals);
917 * mono_aot_register_module:
919 * This should be called by embedding code to register AOT modules statically linked
920 * into the executable. AOT_INFO should be the value of the
921 * 'mono_aot_module_<ASSEMBLY_NAME>_info' global symbol from the AOT module.
924 mono_aot_register_module (gpointer *aot_info)
932 /* Determine the assembly name */
933 find_symbol (NULL, globals, "mono_aot_assembly_name", (gpointer*)&aname);
936 /* This could be called before startup */
940 if (!static_aot_modules)
941 static_aot_modules = g_hash_table_new (g_str_hash, g_str_equal);
943 g_hash_table_insert (static_aot_modules, aname, globals);
952 InitializeCriticalSection (&aot_mutex);
953 aot_modules = g_hash_table_new (NULL, NULL);
954 globals_tls_id = TlsAlloc ();
956 mono_install_assembly_load_hook (load_aot_module, NULL);
958 if (getenv ("MONO_LASTAOT"))
959 mono_last_aot_method = atoi (getenv ("MONO_LASTAOT"));
960 if (getenv ("MONO_AOT_CACHE"))
961 use_aot_cache = TRUE;
965 decode_cached_class_info (MonoAotModule *module, MonoCachedClassInfo *info, guint8 *buf, guint8 **endbuf)
969 info->vtable_size = decode_value (buf, &buf);
970 if (info->vtable_size == -1)
973 flags = decode_value (buf, &buf);
974 info->ghcimpl = (flags >> 0) & 0x1;
975 info->has_finalize = (flags >> 1) & 0x1;
976 info->has_cctor = (flags >> 2) & 0x1;
977 info->has_nested_classes = (flags >> 3) & 0x1;
978 info->blittable = (flags >> 4) & 0x1;
979 info->has_references = (flags >> 5) & 0x1;
980 info->has_static_refs = (flags >> 6) & 0x1;
981 info->no_special_static_fields = (flags >> 7) & 0x1;
983 if (info->has_cctor) {
984 MonoImage *cctor_image = decode_method_ref (module, &info->cctor_token, NULL, buf, &buf);
988 if (info->has_finalize) {
989 info->finalize_image = decode_method_ref (module, &info->finalize_token, NULL, buf, &buf);
990 if (!info->finalize_image)
994 info->instance_size = decode_value (buf, &buf);
995 info->class_size = decode_value (buf, &buf);
996 info->packing_size = decode_value (buf, &buf);
997 info->min_align = decode_value (buf, &buf);
1005 mono_aot_get_method_from_vt_slot (MonoDomain *domain, MonoVTable *vtable, int slot)
1008 MonoClass *klass = vtable->klass;
1009 MonoAotModule *aot_module = klass->image->aot_module;
1011 MonoCachedClassInfo class_info;
1016 if (MONO_CLASS_IS_INTERFACE (klass) || klass->rank || !aot_module)
1019 info = &aot_module->class_info [aot_module->class_info_offsets [mono_metadata_token_index (klass->type_token) - 1]];
1022 err = decode_cached_class_info (aot_module, &class_info, p, &p);
1026 for (i = 0; i < slot; ++i)
1027 decode_method_ref (aot_module, &token, NULL, p, &p);
1029 image = decode_method_ref (aot_module, &token, NULL, p, &p);
1033 return mono_aot_get_method_from_token (domain, image, token);
1037 mono_aot_get_cached_class_info (MonoClass *klass, MonoCachedClassInfo *res)
1039 MonoAotModule *aot_module = klass->image->aot_module;
1043 if (klass->rank || !aot_module)
1046 p = (guint8*)&aot_module->class_info [aot_module->class_info_offsets [mono_metadata_token_index (klass->type_token) - 1]];
1048 err = decode_cached_class_info (aot_module, res, p, &p);
1056 * mono_aot_get_class_from_name:
1058 * Obtains a MonoClass with a given namespace and a given name which is located in IMAGE,
1059 * using a cache stored in the AOT file.
1060 * Stores the resulting class in *KLASS if found, stores NULL otherwise.
1062 * Returns: TRUE if the klass was found/not found in the cache, FALSE if no aot file was
1066 mono_aot_get_class_from_name (MonoImage *image, const char *name_space, const char *name, MonoClass **klass)
1068 MonoAotModule *aot_module = image->aot_module;
1069 guint16 *table, *entry;
1072 char full_name_buf [1024];
1074 const char *name2, *name_space2;
1076 guint32 cols [MONO_TYPEDEF_SIZE];
1077 GHashTable *nspace_table;
1079 if (!aot_module || !aot_module->class_name_table)
1086 /* First look in the cache */
1087 if (!aot_module->name_cache)
1088 aot_module->name_cache = g_hash_table_new (g_str_hash, g_str_equal);
1089 nspace_table = g_hash_table_lookup (aot_module->name_cache, name_space);
1091 *klass = g_hash_table_lookup (nspace_table, name);
1098 table_size = aot_module->class_name_table [0];
1099 table = aot_module->class_name_table + 1;
1101 if (name_space [0] == '\0')
1102 full_name = g_strdup_printf ("%s", name);
1104 if (strlen (name_space) + strlen (name) < 1000) {
1105 sprintf (full_name_buf, "%s.%s", name_space, name);
1106 full_name = full_name_buf;
1108 full_name = g_strdup_printf ("%s.%s", name_space, name);
1111 hash = g_str_hash (full_name) % table_size;
1112 if (full_name != full_name_buf)
1115 entry = &table [hash * 2];
1117 if (entry [0] != 0) {
1118 t = &image->tables [MONO_TABLE_TYPEDEF];
1121 guint32 index = entry [0];
1122 guint32 next = entry [1];
1123 guint32 token = mono_metadata_make_token (MONO_TABLE_TYPEDEF, index);
1125 name_table_accesses ++;
1127 mono_metadata_decode_row (t, index - 1, cols, MONO_TYPEDEF_SIZE);
1129 name2 = mono_metadata_string_heap (image, cols [MONO_TYPEDEF_NAME]);
1130 name_space2 = mono_metadata_string_heap (image, cols [MONO_TYPEDEF_NAMESPACE]);
1132 if (!strcmp (name, name2) && !strcmp (name_space, name_space2)) {
1134 *klass = mono_class_get (image, token);
1139 nspace_table = g_hash_table_lookup (aot_module->name_cache, name_space);
1140 if (!nspace_table) {
1141 nspace_table = g_hash_table_new (g_str_hash, g_str_equal);
1142 g_hash_table_insert (aot_module->name_cache, (char*)name_space2, nspace_table);
1144 g_hash_table_insert (nspace_table, (char*)name2, *klass);
1151 entry = &table [next * 2];
1164 decode_exception_debug_info (MonoAotModule *aot_module, MonoDomain *domain,
1165 MonoMethod *method, guint8* ex_info, guint8 *code)
1169 guint code_len, used_int_regs;
1171 MonoMethodHeader *header;
1173 header = mono_method_get_header (method);
1175 /* Load the method info from the AOT file */
1178 code_len = decode_value (p, &p);
1179 used_int_regs = decode_value (p, &p);
1181 /* Exception table */
1182 if (header && header->num_clauses) {
1184 mono_mempool_alloc0 (domain->mp, sizeof (MonoJitInfo) + (sizeof (MonoJitExceptionInfo) * header->num_clauses));
1185 jinfo->num_clauses = header->num_clauses;
1187 for (i = 0; i < header->num_clauses; ++i) {
1188 MonoExceptionClause *ec = &header->clauses [i];
1189 MonoJitExceptionInfo *ei = &jinfo->clauses [i];
1191 ei->flags = ec->flags;
1192 ei->exvar_offset = decode_value (p, &p);
1194 if (ei->flags == MONO_EXCEPTION_CLAUSE_FILTER)
1195 ei->data.filter = code + decode_value (p, &p);
1197 ei->data.catch_class = ec->data.catch_class;
1199 ei->try_start = code + decode_value (p, &p);
1200 ei->try_end = code + decode_value (p, &p);
1201 ei->handler_start = code + decode_value (p, &p);
1205 jinfo = mono_mempool_alloc0 (domain->mp, sizeof (MonoJitInfo));
1207 jinfo->code_size = code_len;
1208 jinfo->used_regs = used_int_regs;
1209 jinfo->method = method;
1210 jinfo->code_start = code;
1211 jinfo->domain_neutral = 0;
1213 /* Load debug info */
1214 buf_len = decode_value (p, &p);
1215 mono_debug_add_aot_method (domain, method, code, p, buf_len);
1221 mono_aot_find_jit_info (MonoDomain *domain, MonoImage *image, gpointer addr)
1223 int pos, left, right, offset, offset1, offset2, last_offset, new_offset, page_index, method_index, table_len;
1225 MonoAotModule *aot_module = image->aot_module;
1228 guint8 *code, *ex_info;
1229 guint32 *table, *ptr;
1235 if (domain != mono_get_root_domain ())
1239 offset = (guint8*)addr - aot_module->code;
1241 /* First search through the index */
1242 ptr = aot_module->method_order;
1247 if (*ptr == 0xffffff)
1251 while (*ptr != 0xffffff) {
1252 guint32 method_index = ptr [0];
1253 new_offset = aot_module->code_offsets [method_index];
1255 if (offset >= last_offset && offset < new_offset) {
1261 last_offset = new_offset;
1265 /* Skip rest of index */
1266 while (*ptr != 0xffffff)
1271 table_len = aot_module->method_order_end - table;
1273 g_assert (table <= aot_module->method_order_end);
1276 left = (page_index * 1024);
1277 right = left + 1024;
1279 if (right > table_len)
1282 offset1 = aot_module->code_offsets [table [left]];
1283 g_assert (offset1 <= offset);
1285 //printf ("Found in index: 0x%x 0x%x 0x%x\n", offset, last_offset, new_offset);
1288 //printf ("Not found in index: 0x%x\n", offset);
1293 /* Binary search inside the method_order table to find the method */
1295 pos = (left + right) / 2;
1297 g_assert (table + pos <= aot_module->method_order_end);
1299 //printf ("Pos: %5d < %5d < %5d Offset: 0x%05x < 0x%05x < 0x%05x\n", left, pos, right, aot_module->code_offsets [table [left]], offset, aot_module->code_offsets [table [right]]);
1301 offset1 = aot_module->code_offsets [table [pos]];
1302 if (table + pos + 1 >= aot_module->method_order_end)
1303 offset2 = aot_module->code_end - aot_module->code;
1305 offset2 = aot_module->code_offsets [table [pos + 1]];
1307 if (offset < offset1)
1309 else if (offset >= offset2)
1315 method_index = table [pos];
1317 /* Might be a wrapper */
1318 if (aot_module->wrappers) {
1320 method = g_hash_table_lookup (aot_module->wrappers, GUINT_TO_POINTER (method_index));
1327 token = mono_metadata_make_token (MONO_TABLE_METHOD, method_index + 1);
1328 method = mono_get_method (image, token, NULL);
1334 //printf ("F: %s\n", mono_method_full_name (method, TRUE));
1336 code = &aot_module->code [aot_module->code_offsets [method_index]];
1337 ex_info = &aot_module->ex_info [aot_module->ex_info_offsets [method_index]];
1339 jinfo = decode_exception_debug_info (aot_module, domain, method, ex_info, code);
1341 g_assert ((guint8*)addr >= (guint8*)jinfo->code_start);
1342 g_assert ((guint8*)addr < (guint8*)jinfo->code_start + jinfo->code_size);
1344 /* Add it to the normal JitInfo tables */
1345 mono_jit_info_table_add (domain, jinfo);
1350 /* Keep it in sync with the version in aot-compiler.c */
1351 static inline gboolean
1352 is_shared_got_patch (MonoJumpInfo *patch_info)
1354 switch (patch_info->type) {
1355 case MONO_PATCH_INFO_VTABLE:
1356 case MONO_PATCH_INFO_CLASS:
1357 case MONO_PATCH_INFO_IID:
1358 case MONO_PATCH_INFO_ADJUSTED_IID:
1359 case MONO_PATCH_INFO_FIELD:
1360 case MONO_PATCH_INFO_SFLDA:
1361 case MONO_PATCH_INFO_DECLSEC:
1362 case MONO_PATCH_INFO_LDTOKEN:
1363 case MONO_PATCH_INFO_TYPE_FROM_HANDLE:
1364 case MONO_PATCH_INFO_RVA:
1365 case MONO_PATCH_INFO_METHODCONST:
1373 decode_patch (MonoAotModule *aot_module, MonoMemPool *mp, MonoJumpInfo *ji, guint8 *buf, guint8 **endbuf)
1381 case MONO_PATCH_INFO_METHOD:
1382 case MONO_PATCH_INFO_METHOD_JUMP:
1383 case MONO_PATCH_INFO_ICALL_ADDR:
1384 case MONO_PATCH_INFO_METHOD_RGCTX: {
1388 image = decode_method_ref (aot_module, &token, &method, p, &p);
1392 #ifdef MONO_ARCH_HAVE_CREATE_TRAMPOLINE_FROM_TOKEN
1393 if (!method && !mono_aot_only && (ji->type == MONO_PATCH_INFO_METHOD) && (mono_metadata_token_table (token) == MONO_TABLE_METHOD)) {
1394 ji->data.target = mono_create_jit_trampoline_from_token (image, token);
1395 ji->type = MONO_PATCH_INFO_ABS;
1399 ji->data.method = method;
1401 ji->data.method = mono_get_method (image, token, NULL);
1402 g_assert (ji->data.method);
1403 mono_class_init (ji->data.method->klass);
1406 ji->data.method = mono_get_method (image, token, NULL);
1407 g_assert (ji->data.method);
1408 mono_class_init (ji->data.method->klass);
1413 case MONO_PATCH_INFO_WRAPPER: {
1414 guint32 wrapper_type;
1416 wrapper_type = decode_value (p, &p);
1418 ji->type = MONO_PATCH_INFO_METHOD;
1420 switch (wrapper_type) {
1421 case MONO_WRAPPER_REMOTING_INVOKE_WITH_CHECK: {
1422 guint32 image_index, token, value;
1424 value = decode_value (p, &p);
1425 image_index = value >> 24;
1426 token = MONO_TOKEN_METHOD_DEF | (value & 0xffffff);
1428 image = load_image (aot_module, image_index);
1431 ji->data.method = mono_get_method (image, token, NULL);
1432 g_assert (ji->data.method);
1433 mono_class_init (ji->data.method->klass);
1435 ji->data.method = mono_marshal_get_remoting_invoke_with_check (ji->data.method);
1438 case MONO_WRAPPER_PROXY_ISINST: {
1439 MonoClass *klass = decode_klass_ref (aot_module, p, &p);
1442 ji->data.method = mono_marshal_get_proxy_cancast (klass);
1445 case MONO_WRAPPER_LDFLD:
1446 case MONO_WRAPPER_LDFLDA:
1447 case MONO_WRAPPER_STFLD:
1448 case MONO_WRAPPER_ISINST: {
1449 MonoClass *klass = decode_klass_ref (aot_module, p, &p);
1452 if (wrapper_type == MONO_WRAPPER_LDFLD)
1453 ji->data.method = mono_marshal_get_ldfld_wrapper (&klass->byval_arg);
1454 else if (wrapper_type == MONO_WRAPPER_LDFLDA)
1455 ji->data.method = mono_marshal_get_ldflda_wrapper (&klass->byval_arg);
1456 else if (wrapper_type == MONO_WRAPPER_STFLD)
1457 ji->data.method = mono_marshal_get_stfld_wrapper (&klass->byval_arg);
1458 else if (wrapper_type == MONO_WRAPPER_ISINST)
1459 ji->data.method = mono_marshal_get_isinst (klass);
1461 g_assert_not_reached ();
1464 case MONO_WRAPPER_LDFLD_REMOTE:
1465 ji->data.method = mono_marshal_get_ldfld_remote_wrapper (NULL);
1467 case MONO_WRAPPER_STFLD_REMOTE:
1468 ji->data.method = mono_marshal_get_stfld_remote_wrapper (NULL);
1470 case MONO_WRAPPER_ALLOC: {
1471 int atype = decode_value (p, &p);
1473 ji->data.method = mono_gc_get_managed_allocator_by_type (atype);
1476 case MONO_WRAPPER_STELEMREF:
1477 ji->data.method = mono_marshal_get_stelemref ();
1480 g_assert_not_reached ();
1484 case MONO_PATCH_INFO_INTERNAL_METHOD:
1485 case MONO_PATCH_INFO_JIT_ICALL_ADDR: {
1486 guint32 len = decode_value (p, &p);
1488 ji->data.name = (char*)p;
1492 case MONO_PATCH_INFO_METHODCONST:
1494 ji->data.method = decode_method_ref_2 (aot_module, p, &p);
1495 if (!ji->data.method)
1498 case MONO_PATCH_INFO_VTABLE:
1499 case MONO_PATCH_INFO_CLASS:
1500 case MONO_PATCH_INFO_IID:
1501 case MONO_PATCH_INFO_ADJUSTED_IID:
1503 ji->data.klass = decode_klass_ref (aot_module, p, &p);
1504 if (!ji->data.klass)
1507 case MONO_PATCH_INFO_CLASS_INIT:
1508 case MONO_PATCH_INFO_DELEGATE_TRAMPOLINE:
1509 ji->data.klass = decode_klass_ref (aot_module, p, &p);
1510 if (!ji->data.klass)
1513 case MONO_PATCH_INFO_IMAGE:
1514 ji->data.image = load_image (aot_module, decode_value (p, &p));
1515 if (!ji->data.image)
1518 case MONO_PATCH_INFO_FIELD:
1519 case MONO_PATCH_INFO_SFLDA:
1521 ji->data.field = decode_field_info (aot_module, p, &p);
1522 if (!ji->data.field)
1525 case MONO_PATCH_INFO_SWITCH:
1526 ji->data.table = mono_mempool_alloc0 (mp, sizeof (MonoJumpInfoBBTable));
1527 ji->data.table->table_size = decode_value (p, &p);
1528 table = g_new (gpointer, ji->data.table->table_size);
1529 ji->data.table->table = (MonoBasicBlock**)table;
1530 for (i = 0; i < ji->data.table->table_size; i++)
1531 table [i] = (gpointer)(gssize)decode_value (p, &p);
1533 case MONO_PATCH_INFO_R4: {
1536 ji->data.target = mono_mempool_alloc0 (mp, sizeof (float));
1537 val = decode_value (p, &p);
1538 *(float*)ji->data.target = *(float*)&val;
1541 case MONO_PATCH_INFO_R8: {
1544 ji->data.target = mono_mempool_alloc0 (mp, sizeof (double));
1546 val [0] = decode_value (p, &p);
1547 val [1] = decode_value (p, &p);
1548 *(double*)ji->data.target = *(double*)val;
1551 case MONO_PATCH_INFO_LDSTR:
1552 image = load_image (aot_module, decode_value (p, &p));
1555 ji->data.token = mono_jump_info_token_new (mp, image, MONO_TOKEN_STRING + decode_value (p, &p));
1557 case MONO_PATCH_INFO_RVA:
1558 case MONO_PATCH_INFO_DECLSEC:
1559 case MONO_PATCH_INFO_LDTOKEN:
1560 case MONO_PATCH_INFO_TYPE_FROM_HANDLE:
1562 image = load_image (aot_module, decode_value (p, &p));
1565 ji->data.token = mono_jump_info_token_new (mp, image, decode_value (p, &p));
1567 case MONO_PATCH_INFO_EXC_NAME:
1568 ji->data.klass = decode_klass_ref (aot_module, p, &p);
1569 if (!ji->data.klass)
1571 ji->data.name = ji->data.klass->name;
1573 case MONO_PATCH_INFO_METHOD_REL:
1574 ji->data.offset = decode_value (p, &p);
1576 case MONO_PATCH_INFO_INTERRUPTION_REQUEST_FLAG:
1577 case MONO_PATCH_INFO_GENERIC_CLASS_INIT:
1579 case MONO_PATCH_INFO_RGCTX_FETCH: {
1581 MonoJumpInfoRgctxEntry *entry;
1583 entry = mono_mempool_alloc0 (mp, sizeof (MonoJumpInfoRgctxEntry));
1584 entry->method = decode_method_ref_2 (aot_module, p, &p);
1585 entry->in_mrgctx = decode_value (p, &p);
1586 entry->info_type = decode_value (p, &p);
1587 entry->data = mono_mempool_alloc0 (mp, sizeof (MonoJumpInfo));
1588 entry->data->type = decode_value (p, &p);
1590 res = decode_patch (aot_module, mp, entry->data, p, &p);
1593 ji->data.rgctx_entry = entry;
1597 g_warning ("unhandled type %d", ji->type);
1598 g_assert_not_reached ();
1610 decode_got_entry (MonoAotModule *aot_module, MonoMemPool *mp, MonoJumpInfo *ji, guint8 *buf, guint8 **endbuf, guint32 *got_offset)
1616 if (is_shared_got_patch (ji)) {
1617 *got_offset = decode_value (p, &p);
1619 if (aot_module->got [*got_offset]) {
1620 /* Already loaded */
1621 //printf ("HIT!\n");
1623 shared_p = aot_module->got_info + aot_module->got_info_offsets [*got_offset];
1625 res = decode_patch (aot_module, mp, ji, shared_p, &shared_p);
1630 res = decode_patch (aot_module, mp, ji, p, &p);
1639 static MonoJumpInfo*
1640 load_patch_info (MonoAotModule *aot_module, MonoMemPool *mp, int n_patches,
1641 guint32 got_index, guint32 **got_slots,
1642 guint8 *buf, guint8 **endbuf)
1644 MonoJumpInfo *patches;
1645 MonoJumpInfo *patch_info = NULL;
1647 guint32 last_offset;
1652 /* First load the type + offset table */
1654 patches = mono_mempool_alloc0 (mp, sizeof (MonoJumpInfo) * n_patches);
1656 for (pindex = 0; pindex < n_patches; ++pindex) {
1657 MonoJumpInfo *ji = &patches [pindex];
1662 //printf ("T: %d O: %d.\n", ji->type, ji->ip.i);
1663 ji->next = patch_info;
1667 *got_slots = g_malloc (sizeof (guint32) * n_patches);
1668 memset (*got_slots, 0xff, sizeof (guint32) * n_patches);
1670 /* Then load the other data */
1671 for (pindex = 0; pindex < n_patches; ++pindex) {
1672 MonoJumpInfo *ji = &patches [pindex];
1674 if (!decode_got_entry (aot_module, mp, ji, p, &p, (*got_slots) + pindex))
1677 if ((*got_slots) [pindex] == 0xffffffff)
1678 (*got_slots) [pindex] = got_index ++;
1685 g_free (*got_slots);
1692 register_jump_target_got_slot (MonoDomain *domain, MonoMethod *method, gpointer *got_slot)
1695 * Jump addresses cannot be patched by the trampoline code since it
1696 * does not have access to the caller's address. Instead, we collect
1697 * the addresses of the GOT slots pointing to a method, and patch
1698 * them after the method has been compiled.
1700 MonoJitDomainInfo *info = jit_domain_info (domain);
1703 mono_domain_lock (domain);
1704 if (!info->jump_target_got_slot_hash)
1705 info->jump_target_got_slot_hash = g_hash_table_new (NULL, NULL);
1706 list = g_hash_table_lookup (info->jump_target_got_slot_hash, method);
1707 list = g_slist_prepend (list, got_slot);
1708 g_hash_table_insert (info->jump_target_got_slot_hash, method, list);
1709 mono_domain_unlock (domain);
1713 mono_aot_get_method (MonoDomain *domain, MonoMethod *method)
1715 MonoClass *klass = method->klass;
1716 guint32 method_index = mono_metadata_token_index (method->token) - 1;
1717 guint8 *code, *info;
1718 MonoAotModule *aot_module = klass->image->aot_module;
1723 if (mono_profiler_get_events () & MONO_PROFILE_ENTER_LEAVE)
1726 if ((method->iflags & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL) ||
1727 (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) ||
1728 (method->iflags & METHOD_IMPL_ATTRIBUTE_RUNTIME) ||
1729 (method->flags & METHOD_ATTRIBUTE_ABSTRACT))
1732 g_assert (klass->inited);
1734 if ((domain != mono_get_root_domain ()) && (!(aot_module->opts & MONO_OPT_SHARED)))
1735 /* Non shared AOT code can't be used in other appdomains */
1738 if (aot_module->out_of_date)
1741 if (method->is_inflated) {
1742 if (!mono_method_is_generic_sharable_impl (method, FALSE))
1744 method = mono_method_get_declaring_generic_method (method);
1747 if (!method->token) {
1751 if (!method->wrapper_type || !aot_module->wrapper_info)
1754 /* Try to find the wrapper among the wrapper info */
1755 full_name = mono_method_full_name (method, TRUE);
1756 p = (char*)aot_module->wrapper_info;
1760 end = p + strlen (p) + 1;
1761 end = ALIGN_PTR_TO (end, 4);
1762 method_index = *(guint32*)end;
1764 if (strcmp (full_name, p) == 0)
1774 /* Needed by find_jit_info */
1776 if (!aot_module->wrappers)
1777 aot_module->wrappers = g_hash_table_new (NULL, NULL);
1778 g_hash_table_insert (aot_module->wrappers, GUINT_TO_POINTER (method_index), method);
1782 if (aot_module->code_offsets [method_index] == 0xffffffff) {
1783 if (mono_trace_is_traced (G_LOG_LEVEL_DEBUG, MONO_TRACE_AOT)) {
1784 char *full_name = mono_method_full_name (method, TRUE);
1785 mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_AOT, "AOT NOT FOUND: %s.\n", full_name);
1791 code = &aot_module->code [aot_module->code_offsets [method_index]];
1792 info = &aot_module->method_info [aot_module->method_info_offsets [method_index]];
1795 if (!aot_module->methods_loaded)
1796 aot_module->methods_loaded = g_new0 (guint32, klass->image->tables [MONO_TABLE_METHOD].rows + 1);
1799 if ((aot_module->methods_loaded [method_index / 32] >> (method_index % 32)) & 0x1)
1802 if (mono_last_aot_method != -1) {
1803 if (mono_jit_stats.methods_aot > mono_last_aot_method)
1806 if (mono_jit_stats.methods_aot == mono_last_aot_method)
1807 printf ("LAST AOT METHOD: %s.%s.%s.\n", klass->name_space, klass->name, method->name);
1810 return mono_aot_load_method (domain, aot_module, method, code, info, method_index);
1814 mono_aot_load_method (MonoDomain *domain, MonoAotModule *aot_module, MonoMethod *method, guint8 *code, guint8 *info, int method_index)
1816 MonoClass *klass = method->klass;
1817 MonoJumpInfo *patch_info = NULL;
1819 int i, pindex, got_index = 0, n_patches, used_strings;
1820 gboolean non_got_patches, keep_patches = TRUE;
1821 guint8 *p, *ex_info;
1822 MonoJitInfo *jinfo = NULL;
1825 decode_klass_ref (aot_module, p, &p);
1827 if (!use_loaded_code) {
1831 ex_info = &aot_module->ex_info [aot_module->ex_info_offsets [mono_metadata_token_index (method->token) - 1]];
1832 jinfo = decode_exception_debug_info (aot_module, domain, method, ex_info, code);
1835 mono_domain_lock (domain);
1836 code2 = mono_code_manager_reserve (domain->code_mp, jinfo->code_size);
1837 mono_domain_unlock (domain);
1838 memcpy (code2, code, jinfo->code_size);
1839 mono_arch_flush_icache (code2, jinfo->code_size);
1843 if (aot_module->opts & MONO_OPT_SHARED)
1844 used_strings = decode_value (p, &p);
1848 for (i = 0; i < used_strings; i++) {
1849 guint token = decode_value (p, &p);
1850 mono_ldstr (mono_get_root_domain (), klass->image, mono_metadata_token_index (token));
1853 if (aot_module->opts & MONO_OPT_SHARED)
1854 keep_patches = FALSE;
1856 n_patches = decode_value (p, &p);
1858 keep_patches = FALSE;
1861 MonoJumpInfo *patches;
1867 mp = mono_mempool_new ();
1869 got_index = decode_value (p, &p);
1871 patches = load_patch_info (aot_module, mp, n_patches, got_index, &got_slots, p, &p);
1872 if (patches == NULL)
1875 non_got_patches = FALSE;
1876 for (pindex = 0; pindex < n_patches; ++pindex) {
1877 MonoJumpInfo *ji = &patches [pindex];
1879 if (is_got_patch (ji->type)) {
1880 if (!aot_module->got [got_slots [pindex]]) {
1881 aot_module->got [got_slots [pindex]] = mono_resolve_patch_target (method, domain, code, ji, TRUE);
1882 if (ji->type == MONO_PATCH_INFO_METHOD_JUMP)
1883 register_jump_target_got_slot (domain, ji->data.method, &(aot_module->got [got_slots [pindex]]));
1885 ji->type = MONO_PATCH_INFO_NONE;
1888 non_got_patches = TRUE;
1890 if (non_got_patches) {
1892 ex_info = &aot_module->ex_info [aot_module->ex_info_offsets [mono_metadata_token_index (method->token) - 1]];
1893 jinfo = decode_exception_debug_info (aot_module, domain, method, ex_info, code);
1896 mono_arch_flush_icache (code, jinfo->code_size);
1897 make_writable (code, jinfo->code_size);
1898 mono_arch_patch_code (method, domain, code, patch_info, TRUE);
1904 mono_mempool_destroy (mp);
1909 mono_jit_stats.methods_aot++;
1911 if (mono_trace_is_traced (G_LOG_LEVEL_DEBUG, MONO_TRACE_AOT)) {
1912 char *full_name = mono_method_full_name (method, TRUE);
1915 ex_info = &aot_module->ex_info [aot_module->ex_info_offsets [method_index]];
1916 jinfo = decode_exception_debug_info (aot_module, domain, method, ex_info, code);
1919 mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_AOT, "AOT FOUND AOT compiled code for %s %p - %p %p\n", full_name, code, code + jinfo->code_size, info);
1923 aot_module->methods_loaded [method_index / 32] |= 1 << (method_index % 32);
1925 init_plt (aot_module);
1932 /* FIXME: The space in domain->mp is wasted */
1933 if (aot_module->opts & MONO_OPT_SHARED)
1934 /* No need to cache patches */
1935 mono_mempool_destroy (mp);
1944 * Same as mono_aot_get_method, but we try to avoid loading any metadata from the
1948 mono_aot_get_method_from_token (MonoDomain *domain, MonoImage *image, guint32 token)
1951 int i, method_index, pindex, got_index, n_patches, used_strings;
1952 gboolean keep_patches = TRUE;
1954 guint8 *code = NULL;
1956 MonoAotModule *aot_module = image->aot_module;
1962 if (mono_profiler_get_events () & MONO_PROFILE_ENTER_LEAVE)
1965 if (domain != mono_get_root_domain ())
1968 if (aot_module->out_of_date)
1971 if (aot_module->code_offsets [mono_metadata_token_index (token) - 1] == 0xffffffff) {
1975 method_index = mono_metadata_token_index (token) - 1;
1976 code = &aot_module->code [aot_module->code_offsets [method_index]];
1977 info = &aot_module->method_info [aot_module->method_info_offsets [method_index]];
1980 if (!aot_module->methods_loaded)
1981 aot_module->methods_loaded = g_new0 (guint32, image->tables [MONO_TABLE_METHOD].rows + 1);
1984 if ((aot_module->methods_loaded [method_index / 32] >> (method_index % 32)) & 0x1)
1987 if (mono_last_aot_method != -1) {
1988 if (mono_jit_stats.methods_aot > mono_last_aot_method)
1991 if (mono_jit_stats.methods_aot == mono_last_aot_method) {
1992 MonoMethod *method = mono_get_method (image, token, NULL);
1993 printf ("LAST AOT METHOD: %s.%s.%s.\n", method->klass->name_space, method->klass->name, method->name);
1998 klass = decode_klass_ref (aot_module, p, &p);
2000 if (mono_trace_is_traced (G_LOG_LEVEL_DEBUG, MONO_TRACE_AOT)) {
2001 MonoMethod *method = mono_get_method (image, token, NULL);
2002 char *full_name = mono_method_full_name (method, TRUE);
2003 mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_AOT, "AOT FOUND AOT compiled code for %s %p %p\n", full_name, code, info);
2007 if (aot_module->opts & MONO_OPT_SHARED)
2008 used_strings = decode_value (p, &p);
2012 for (i = 0; i < used_strings; i++) {
2013 guint string_token = decode_value (p, &p);
2014 mono_ldstr (mono_get_root_domain (), image, mono_metadata_token_index (string_token));
2017 if (aot_module->opts & MONO_OPT_SHARED)
2018 keep_patches = FALSE;
2020 keep_patches = FALSE;
2022 n_patches = decode_value (p, &p);
2025 MonoJumpInfo *patches;
2031 mp = mono_mempool_new ();
2033 got_index = decode_value (p, &p);
2035 patches = load_patch_info (aot_module, mp, n_patches, got_index, &got_slots, p, &p);
2036 if (patches == NULL)
2039 for (pindex = 0; pindex < n_patches; ++pindex) {
2040 MonoJumpInfo *ji = &patches [pindex];
2042 if (is_got_patch (ji->type)) {
2043 if (!aot_module->got [got_slots [pindex]]) {
2044 aot_module->got [got_slots [pindex]] = mono_resolve_patch_target (NULL, domain, code, ji, TRUE);
2045 if (ji->type == MONO_PATCH_INFO_METHOD_JUMP)
2046 register_jump_target_got_slot (domain, ji->data.method, &(aot_module->got [got_slots [pindex]]));
2048 ji->type = MONO_PATCH_INFO_NONE;
2055 mono_mempool_destroy (mp);
2058 mono_jit_stats.methods_aot++;
2062 aot_module->methods_loaded [method_index / 32] |= 1 << (method_index % 32);
2064 init_plt (aot_module);
2069 mono_runtime_class_init (mono_class_vtable (domain, klass));
2074 /* FIXME: The space in domain->mp is wasted */
2075 if (aot_module->opts & MONO_OPT_SHARED)
2076 /* No need to cache patches */
2077 mono_mempool_destroy (mp);
2085 } IsGotEntryUserData;
2088 check_is_got_entry (gpointer key, gpointer value, gpointer user_data)
2090 IsGotEntryUserData *data = (IsGotEntryUserData*)user_data;
2091 MonoAotModule *aot_module = (MonoAotModule*)value;
2093 if (aot_module->got && (data->addr >= (guint8*)(aot_module->got)) && (data->addr < (guint8*)(aot_module->got + aot_module->got_size)))
2098 mono_aot_is_got_entry (guint8 *code, guint8 *addr)
2100 IsGotEntryUserData user_data;
2105 user_data.addr = addr;
2106 user_data.res = FALSE;
2108 g_hash_table_foreach (aot_modules, check_is_got_entry, &user_data);
2111 return user_data.res;
2116 MonoAotModule *module;
2117 } FindAotModuleUserData;
2120 find_aot_module_cb (gpointer key, gpointer value, gpointer user_data)
2122 FindAotModuleUserData *data = (FindAotModuleUserData*)user_data;
2123 MonoAotModule *aot_module = (MonoAotModule*)value;
2125 if ((data->addr >= (guint8*)(aot_module->code)) && (data->addr < (guint8*)(aot_module->code_end)))
2126 data->module = aot_module;
2129 static inline MonoAotModule*
2130 find_aot_module (guint8 *code)
2132 FindAotModuleUserData user_data;
2137 /* Reading these need no locking */
2138 if (((gsize)code < aot_code_low_addr) || ((gsize)code > aot_code_high_addr))
2141 user_data.addr = code;
2142 user_data.module = NULL;
2145 g_hash_table_foreach (aot_modules, find_aot_module_cb, &user_data);
2148 return user_data.module;
2152 * mono_aot_set_make_unreadable:
2154 * Set whenever to make all mmaped memory unreadable. In conjuction with a
2155 * SIGSEGV handler, this is useful to find out which pages the runtime tries to read.
2158 mono_aot_set_make_unreadable (gboolean unreadable)
2160 make_unreadable = unreadable;
2164 MonoAotModule *module;
2169 find_map (gpointer key, gpointer value, gpointer user_data)
2171 MonoAotModule *module = (MonoAotModule*)value;
2172 FindMapUserData *data = (FindMapUserData*)user_data;
2175 if ((data->ptr >= module->mem_begin) && (data->ptr < module->mem_end))
2176 data->module = module;
2179 static MonoAotModule*
2180 find_module_for_addr (void *ptr)
2182 FindMapUserData data;
2184 if (!make_unreadable)
2188 data.ptr = (guint8*)ptr;
2191 g_hash_table_foreach (aot_modules, (GHFunc)find_map, &data);
2198 * mono_aot_is_pagefault:
2200 * Should be called from a SIGSEGV signal handler to find out whenever @ptr is
2201 * within memory allocated by this module.
2204 mono_aot_is_pagefault (void *ptr)
2206 if (!make_unreadable)
2209 return find_module_for_addr (ptr) != NULL;
2213 * mono_aot_handle_pagefault:
2215 * Handle a pagefault caused by an unreadable page by making it readable again.
2218 mono_aot_handle_pagefault (void *ptr)
2220 #ifndef PLATFORM_WIN32
2221 guint8* start = (guint8*)ROUND_DOWN (((gssize)ptr), PAGESIZE);
2225 res = mprotect (start, PAGESIZE, PROT_READ|PROT_WRITE|PROT_EXEC);
2226 g_assert (res == 0);
2237 printf ("\nNative stacktrace:\n\n");
2239 size = backtrace (array, 256);
2240 names = backtrace_symbols (array, size);
2241 for (i =0; i < size; ++i) {
2242 printf ("\t%s\n", names [i]);
2252 * mono_aot_plt_resolve:
2254 * This function is called by the entries in the PLT to resolve the actual method that
2255 * needs to be called. It returns a trampoline to the method and patches the PLT entry.
2258 mono_aot_plt_resolve (gpointer aot_module, guint32 plt_info_offset, guint8 *code)
2260 #ifdef MONO_ARCH_AOT_SUPPORTED
2261 guint8 *p, *target, *plt_entry;
2263 MonoAotModule *module = (MonoAotModule*)aot_module;
2267 //printf ("DYN: %p %d\n", aot_module, plt_info_offset);
2269 p = &module->plt_info [plt_info_offset];
2271 ji.type = decode_value (p, &p);
2273 mp = mono_mempool_new_size (512);
2274 res = decode_patch (module, mp, &ji, p, &p);
2275 // FIXME: Error handling (how ?)
2278 target = mono_resolve_patch_target (NULL, mono_domain_get (), NULL, &ji, TRUE);
2280 mono_mempool_destroy (mp);
2282 /* Patch the PLT entry with target which might be the actual method not a trampoline */
2283 plt_entry = mono_aot_get_plt_entry (code);
2284 g_assert (plt_entry);
2285 mono_arch_patch_plt_entry (plt_entry, target);
2289 g_assert_not_reached ();
2297 * Initialize the PLT table of the AOT module. Called lazily when the first AOT
2298 * method in the module is loaded to avoid committing memory by writing to it.
2299 * LOCKING: Assumes the AOT lock is held.
2302 init_plt (MonoAotModule *info)
2304 #ifdef MONO_ARCH_AOT_SUPPORTED
2306 guint8 *buf = info->plt;
2307 #elif defined(__x86_64__)
2309 #elif defined(__arm__)
2314 if (info->plt_inited)
2317 tramp = mono_create_specific_trampoline (info, MONO_TRAMPOLINE_AOT_PLT, mono_get_root_domain (), NULL);
2320 /* Initialize the first PLT entry */
2321 make_writable (info->plt, info->plt_end - info->plt);
2322 x86_jump_code (buf, tramp);
2323 #elif defined(__x86_64__) || defined(__arm__)
2325 * Initialize the entries in the plt_jump_table to point to the default targets.
2327 n_entries = info->plt_jump_table_size / sizeof (gpointer);
2329 /* The first entry points to the AOT trampoline */
2330 ((gpointer*)info->plt_jump_table)[0] = tramp;
2331 for (i = 1; i < n_entries; ++i)
2332 /* All the default entries point to the first entry */
2333 ((gpointer*)info->plt_jump_table)[i] = info->plt;
2335 g_assert_not_reached ();
2338 info->plt_inited = TRUE;
2343 * mono_aot_get_plt_entry:
2345 * Return the address of the PLT entry called by the code at CODE if exists.
2348 mono_aot_get_plt_entry (guint8 *code)
2350 MonoAotModule *aot_module = find_aot_module (code);
2351 #if defined(__arm__)
2358 #if defined(__i386__) || defined(__x86_64__)
2359 if (code [-5] == 0xe8) {
2360 guint32 disp = *(guint32*)(code - 4);
2361 guint8 *target = code + disp;
2363 if ((target >= (guint8*)(aot_module->plt)) && (target < (guint8*)(aot_module->plt_end)))
2366 #elif defined(__arm__)
2367 ins = ((guint32*)(gpointer)code) [-1];
2369 /* Should be a 'bl' */
2370 if ((((ins >> 25) & 0x7) == 0x5) && (((ins >> 24) & 0x1) == 0x1)) {
2371 gint32 disp = ((gint32)ins) & 0xffffff;
2372 guint8 *target = code - 4 + 8 + (disp * 4);
2374 if ((target >= (guint8*)(aot_module->plt)) && (target < (guint8*)(aot_module->plt_end)))
2378 g_assert_not_reached ();
2385 * mono_aot_get_plt_info_offset:
2387 * Return the PLT info offset belonging to the plt entry called by CODE.
2390 mono_aot_get_plt_info_offset (gssize *regs, guint8 *code)
2392 guint8 *plt_entry = mono_aot_get_plt_entry (code);
2394 g_assert (plt_entry);
2396 /* The offset is embedded inside the code after the plt entry */
2397 #if defined(__i386__)
2398 return *(guint32*)(plt_entry + 5);
2399 #elif defined(__x86_64__)
2400 return *(guint32*)(plt_entry + 6);
2401 #elif defined(__arm__)
2402 /* The offset is stored as the 5th word of the plt entry */
2403 return ((guint32*)plt_entry) [4];
2405 g_assert_not_reached ();
2411 load_named_code (MonoAotModule *amodule, const char *name)
2415 int n_patches, got_index, pindex;
2421 symbol = g_strdup_printf ("%s", name);
2422 find_symbol (amodule->sofile, amodule->globals, symbol, (gpointer *)&code);
2426 mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_AOT, "AOT FOUND function '%s' in AOT file '%s'.\n", name, amodule->aot_name);
2430 symbol = g_strdup_printf ("%s_p", name);
2431 find_symbol (amodule->sofile, amodule->globals, symbol, (gpointer *)&p);
2434 /* Nothing to patch */
2437 /* Similar to mono_aot_load_method () */
2439 n_patches = decode_value (p, &p);
2442 MonoJumpInfo *patches;
2445 mp = mono_mempool_new ();
2447 got_index = decode_value (p, &p);
2449 patches = load_patch_info (amodule, mp, n_patches, got_index, &got_slots, p, &p);
2452 for (pindex = 0; pindex < n_patches; ++pindex) {
2453 MonoJumpInfo *ji = &patches [pindex];
2457 * When this code is executed, the runtime may not yet initalized, so
2458 * resolve the patch info by hand.
2460 if (ji->type == MONO_PATCH_INFO_JIT_ICALL_ADDR) {
2461 if (!strcmp (ji->data.name, "mono_get_lmf_addr")) {
2462 target = mono_get_lmf_addr;
2463 } else if (!strcmp (ji->data.name, "mono_thread_force_interruption_checkpoint")) {
2464 target = mono_thread_force_interruption_checkpoint;
2465 } else if (!strcmp (ji->data.name, "mono_exception_from_token")) {
2466 target = mono_exception_from_token;
2467 } else if (!strcmp (ji->data.name, "mono_throw_exception")) {
2468 target = mono_get_throw_exception ();
2470 } else if (!strcmp (ji->data.name, "mono_amd64_throw_exception")) {
2471 target = mono_amd64_throw_exception;
2474 } else if (!strcmp (ji->data.name, "mono_arm_throw_exception")) {
2475 target = mono_arm_throw_exception;
2477 } else if (strstr (ji->data.name, "trampoline_func_") == ji->data.name) {
2478 int tramp_type2 = atoi (ji->data.name + strlen ("trampoline_func_"));
2479 target = (gpointer)mono_get_trampoline_func (tramp_type2);
2481 fprintf (stderr, "%s\n", ji->data.name);
2482 g_assert_not_reached ();
2486 /* Hopefully the code doesn't have patches which need method or
2489 target = mono_resolve_patch_target (NULL, NULL, code, ji, FALSE);
2492 amodule->got [got_slots [pindex]] = target;
2497 mono_mempool_destroy (mp);
2504 * Return the piece of code identified by NAME from the mscorlib AOT file.
2507 mono_aot_get_named_code (const char *name)
2510 MonoAotModule *amodule;
2512 image = mono_defaults.corlib;
2515 amodule = image->aot_module;
2518 return load_named_code (amodule, name);
2522 * Return a specific trampoline from the AOT file.
2525 mono_aot_create_specific_trampoline (MonoImage *image, gpointer arg1, MonoTrampolineType tramp_type, MonoDomain *domain, guint32 *code_len)
2527 MonoAotModule *amodule;
2528 int index, tramp_size;
2529 guint8 *code, *tramp;
2530 static gpointer generic_trampolines [MONO_TRAMPOLINE_NUM];
2532 /* Currently, we keep all trampolines in the mscorlib AOT image */
2533 image = mono_defaults.corlib;
2538 amodule = image->aot_module;
2541 if (amodule->trampoline_index == amodule->num_trampolines)
2542 g_error ("Ran out of trampolines in '%s' (%d)\n", image->name, amodule->num_trampolines);
2544 index = amodule->trampoline_index ++;
2548 if (!generic_trampolines [tramp_type]) {
2551 symbol = g_strdup_printf ("generic_trampoline_%d", tramp_type);
2552 generic_trampolines [tramp_type] = mono_aot_get_named_code (symbol);
2556 tramp = generic_trampolines [tramp_type];
2559 amodule->got [amodule->first_trampoline_got_offset + (index *2)] = tramp;
2560 amodule->got [amodule->first_trampoline_got_offset + (index *2) + 1] = arg1;
2564 #elif defined(__arm__)
2568 g_assert_not_reached ();
2571 code = amodule->trampolines + (index * tramp_size);
2573 *code_len = tramp_size;
2579 mono_aot_get_unbox_trampoline (MonoMethod *method)
2581 guint32 method_index = mono_metadata_token_index (method->token) - 1;
2582 MonoAotModule *amodule;
2586 amodule = method->klass->image->aot_module;
2589 symbol = g_strdup_printf ("unbox_trampoline_%d", method_index);
2590 code = load_named_code (amodule, symbol);
2596 * mono_aot_get_n_pagefaults:
2598 * Return the number of times handle_pagefault is called.
2601 mono_aot_get_n_pagefaults (void)
2603 return n_pagefaults;
2610 mono_aot_init (void)
2615 mono_aot_get_method (MonoDomain *domain, MonoMethod *method)
2621 mono_aot_is_got_entry (guint8 *code, guint8 *addr)
2627 mono_aot_get_cached_class_info (MonoClass *klass, MonoCachedClassInfo *res)
2633 mono_aot_get_class_from_name (MonoImage *image, const char *name_space, const char *name, MonoClass **klass)
2639 mono_aot_find_jit_info (MonoDomain *domain, MonoImage *image, gpointer addr)
2645 mono_aot_get_method_from_token (MonoDomain *domain, MonoImage *image, guint32 token)
2651 mono_aot_is_pagefault (void *ptr)
2657 mono_aot_set_make_unreadable (gboolean unreadable)
2662 mono_aot_get_n_pagefaults (void)
2668 mono_aot_handle_pagefault (void *ptr)
2673 mono_aot_get_plt_entry (guint8 *code)
2679 mono_aot_plt_resolve (gpointer aot_module, guint32 plt_info_offset, guint8 *code)
2685 mono_aot_get_method_from_vt_slot (MonoDomain *domain, MonoVTable *vtable, int slot)
2691 mono_aot_create_specific_trampolines (gpointer arg1, MonoTrampolineType tramp_type, MonoDomain *domain, guint32 *code_len)
2693 g_assert_not_reached ();
2698 mono_aot_get_named_code (char *name)
2700 g_assert_not_reached ();
2705 mono_aot_get_unbox_trampoline (MonoMethod *method)
2707 g_assert_not_reached ();