ji.type = patch_type;
ji.data.target = data;
- target = mono_resolve_patch_target (NULL, NULL, &ji, FALSE, error);
+ target = mono_resolve_patch_target_ext (cfg->mem_manager, NULL, NULL, &ji, FALSE, error);
mono_error_assert_ok (error);
EMIT_NEW_PCONST (cfg, ins, target);
jit_mm->method_code_hash = g_hash_table_new (NULL, NULL);
code_slot = (guint8 **)g_hash_table_lookup (jit_mm->method_code_hash, method);
if (!code_slot) {
- code_slot = (guint8 **)m_method_alloc0 (method, sizeof (gpointer));
+ code_slot = (guint8 **)mono_mem_manager_alloc0 (jit_mm->mem_manager, sizeof (gpointer));
g_hash_table_insert (jit_mm->method_code_hash, method, code_slot);
}
jit_mm_unlock (jit_mm);
guint8 *code, *start;
gboolean vtable_is_32bit = ((gsize)(vtable) == (gsize)(int)(gsize)(vtable));
GSList *unwind_ops;
+ MonoMemoryManager *mem_manager = m_class_get_mem_manager (vtable->klass);
for (i = 0; i < count; ++i) {
MonoIMTCheckItem *item = imt_entries [i];
if (fail_tramp) {
code = (guint8 *)mini_alloc_generic_virtual_trampoline (vtable, size + MONO_TRAMPOLINE_UNWINDINFO_SIZE(0));
} else {
- MonoMemoryManager *mem_manager = m_class_get_mem_manager (vtable->klass);
code = (guint8 *)mono_mem_manager_code_reserve (mem_manager, size + MONO_TRAMPOLINE_UNWINDINFO_SIZE(0));
}
start = code;
MONO_PROFILER_RAISE (jit_code_buffer, (start, code - start, MONO_PROFILER_CODE_BUFFER_IMT_TRAMPOLINE, NULL));
- mono_tramp_info_register (mono_tramp_info_create (NULL, start, code - start, NULL, unwind_ops), NULL);
+ mono_tramp_info_register (mono_tramp_info_create (NULL, start, code - start, NULL, unwind_ops), mem_manager);
return start;
}
char * cond;
#endif
GSList *unwind_ops;
+ MonoMemoryManager *mem_manager = m_class_get_mem_manager (vtable->klass);
size = BASE_SIZE;
constant_pool_starts = g_new0 (guint32*, count);
if (fail_tramp) {
code = (arminstr_t *)mini_alloc_generic_virtual_trampoline (vtable, size);
} else {
- MonoMemoryManager *mem_manager = m_class_get_mem_manager (vtable->klass);
code = mono_mem_manager_code_reserve (mem_manager, size);
}
start = code;
g_assert (DISTANCE (start, code) <= size);
- mono_tramp_info_register (mono_tramp_info_create (NULL, (guint8*)start, DISTANCE (start, code), NULL, unwind_ops), NULL);
+ mono_tramp_info_register (mono_tramp_info_create (NULL, (guint8*)start, DISTANCE (start, code), NULL, unwind_ops), mem_manager);
return start;
}
{
MonoRuntimeGenericContext *rgctx, *new_rgctx;
gpointer info;
- // FIXME:
- MonoJitMemoryManager *jit_mm = get_default_jit_mm ();
+ MonoJitMemoryManager *jit_mm = jit_mm_for_class (class_vtable->klass);
error_init (error);
int i;
int size = 0;
guint8 *code, *start;
+ MonoMemoryManager *mem_manager = m_class_get_mem_manager (vtable->klass);
for (i = 0; i < count; ++i) {
MonoIMTCheckItem *item = imt_entries [i];
if (fail_tramp) {
code = (guint8 *)mini_alloc_generic_virtual_trampoline (vtable, size);
} else {
- MonoMemoryManager *mem_manager = m_class_get_mem_manager (vtable->klass);
code = mono_mem_manager_code_reserve (mem_manager, size);
}
start = code;
mono_arch_flush_icache (start, size);
MONO_PROFILER_RAISE (jit_code_buffer, (start, code - start, MONO_PROFILER_CODE_BUFFER_IMT_TRAMPOLINE, NULL));
- mono_tramp_info_register (mono_tramp_info_create (NULL, start, code - start, NULL, NULL), NULL);
+ mono_tramp_info_register (mono_tramp_info_create (NULL, start, code - start, NULL, NULL), mem_manager);
return start;
}
}
static void
-register_trampoline_jit_info (MonoDomain *domain, MonoTrampInfo *info)
+register_trampoline_jit_info (MonoMemoryManager *mem_manager, MonoTrampInfo *info)
{
MonoJitInfo *ji;
- ji = (MonoJitInfo *)mono_mem_manager_alloc0 (get_default_mem_manager (), mono_jit_info_size ((MonoJitInfoFlags)0, 0, 0));
+ ji = (MonoJitInfo *)mono_mem_manager_alloc0 (mem_manager, mono_jit_info_size ((MonoJitInfoFlags)0, 0, 0));
mono_jit_info_init (ji, NULL, (guint8*)MINI_FTNPTR_TO_ADDR (info->code), info->code_size, (MonoJitInfoFlags)0, 0, 0);
ji->d.tramp_info = info;
ji->is_trampoline = TRUE;
* Frees INFO.
*/
static void
-mono_tramp_info_register_internal (MonoTrampInfo *info, MonoDomain *domain, gboolean aot)
+mono_tramp_info_register_internal (MonoTrampInfo *info, MonoMemoryManager *mem_manager, gboolean aot)
{
MonoTrampInfo *copy;
+ MonoDomain *domain = mono_get_root_domain ();
if (!info)
return;
- if (!domain)
- domain = mono_get_root_domain ();
-
- // domain might be unset during startup
- if (domain) {
+ if (mem_manager) {
copy = mono_mem_manager_alloc0 (get_default_mem_manager (), sizeof (MonoTrampInfo));
} else {
copy = g_new0 (MonoTrampInfo, 1);
if (info->unwind_ops) {
copy->uw_info = mono_unwind_ops_encode (info->unwind_ops, ©->uw_info_len);
copy->owns_uw_info = TRUE;
- if (domain) {
- /* Move unwind info into the domain's memory pool so that it is removed once the domain is released. */
+ if (mem_manager) {
guint8 *temp = copy->uw_info;
- copy->uw_info = mono_mem_manager_alloc (get_default_mem_manager (), copy->uw_info_len);
+ copy->uw_info = mono_mem_manager_alloc (mem_manager, copy->uw_info_len);
memcpy (copy->uw_info, temp, copy->uw_info_len);
g_free (temp);
}
#endif
if (!domain) {
- /* If no root domain has been created yet, postpone the registration. */
+ /* If no domain has been created yet, postpone the registration. */
mono_jit_lock ();
tramp_infos = g_slist_prepend (tramp_infos, copy);
mono_jit_unlock ();
} else if (copy->uw_info || info->method) {
/* Only register trampolines that have unwind info */
- register_trampoline_jit_info (domain, copy);
+ register_trampoline_jit_info (mem_manager ? mem_manager : get_default_mem_manager (), copy);
}
if (mono_jit_map_is_enabled ())
}
void
-mono_tramp_info_register (MonoTrampInfo *info, MonoDomain *domain)
+mono_tramp_info_register (MonoTrampInfo *info, MonoMemoryManager *mem_manager)
{
- mono_tramp_info_register_internal (info, domain, FALSE);
+ mono_tramp_info_register_internal (info, mem_manager, FALSE);
}
void
-mono_aot_tramp_info_register (MonoTrampInfo *info, MonoDomain *domain)
+mono_aot_tramp_info_register (MonoTrampInfo *info, MonoMemoryManager *mem_manager)
{
- mono_tramp_info_register_internal (info, domain, TRUE);
+ mono_tramp_info_register_internal (info, mem_manager, TRUE);
}
/* Register trampolines created before the root domain was created in the jit info tables */
for (l = tramp_infos; l; l = l->next) {
MonoTrampInfo *info = (MonoTrampInfo *)l->data;
- register_trampoline_jit_info (domain, info);
+ register_trampoline_jit_info (get_default_mem_manager (), info);
}
}
}
gpointer
-mono_resolve_patch_target (MonoMethod *method, guint8 *code, MonoJumpInfo *patch_info, gboolean run_cctors, MonoError *error)
+mono_resolve_patch_target_ext (MonoMemoryManager *mem_manager, MonoMethod *method, guint8 *code, MonoJumpInfo *patch_info, gboolean run_cctors, MonoError *error)
{
unsigned char *ip = patch_info->ip.i + code;
gconstpointer target = NULL;
break;
}
case MONO_PATCH_INFO_METHOD_PINVOKE_ADDR_CACHE: {
- target = mono_mem_manager_alloc0 (get_default_mem_manager (), sizeof (gpointer));
+ target = mono_mem_manager_alloc0 (mem_manager, sizeof (gpointer));
break;
}
case MONO_PATCH_INFO_GC_SAFE_POINT_FLAG:
break;
}
case MONO_PATCH_INFO_CASTCLASS_CACHE: {
- target = mono_mem_manager_alloc0 (get_default_mem_manager (), sizeof (gpointer));
+ target = mono_mem_manager_alloc0 (mem_manager, sizeof (gpointer));
break;
}
case MONO_PATCH_INFO_OBJC_SELECTOR_REF: {
char *s;
len = strlen ((const char *)patch_info->data.target);
- s = (char *)mono_mem_manager_alloc0 (get_default_mem_manager (), len + 1);
+ s = (char *)mono_mem_manager_alloc0 (mem_manager, len + 1);
memcpy (s, patch_info->data.target, len);
target = s;
return (gpointer)target;
}
+gpointer
+mono_resolve_patch_target (MonoMethod *method, guint8 *code, MonoJumpInfo *patch_info, gboolean run_cctors, MonoError *error)
+{
+ return mono_resolve_patch_target_ext (get_default_mem_manager (), method, code, patch_info, run_cctors, error);
+}
+
/*
* mini_register_jump_site:
*
jit_code_hash_lock (jit_mm);
ji = (MonoJitInfo *)mono_internal_hash_table_lookup (&jit_mm->jit_code_hash, method);
+ jit_code_hash_unlock (jit_mm);
if (!ji && shared) {
+ jit_mm = jit_mm_for_method (shared);
+
+ jit_code_hash_lock (jit_mm);
/* Try generic sharing */
ji = (MonoJitInfo *)mono_internal_hash_table_lookup (&jit_mm->jit_code_hash, shared);
if (ji && !ji->has_generic_jit_info)
++lookups;
if (!ji)
++failed_lookups;
+ jit_code_hash_unlock (jit_mm);
}
- jit_code_hash_unlock (jit_mm);
return ji;
}
static inline MonoJitMemoryManager*
jit_mm_for_method (MonoMethod *method)
{
- /*
- * Some places might not look up the correct memory manager because of generic instances/generic sharing etc.
- * So use the same memory manager everywhere, this is not a problem since we don't support unloading yet.
- */
- //return (MonoJitMemoryManager*)m_method_get_mem_manager (method)->runtime_info;
- return get_default_jit_mm ();
+ return (MonoJitMemoryManager*)m_method_get_mem_manager (method)->runtime_info;
+}
+
+static inline MonoJitMemoryManager*
+jit_mm_for_class (MonoClass *klass)
+{
+ return (MonoJitMemoryManager*)m_class_get_mem_manager (klass)->runtime_info;
}
static inline void
MonoJumpInfoToken* mono_jump_info_token_new (MonoMemPool *mp, MonoImage *image, guint32 token);
MonoJumpInfoToken* mono_jump_info_token_new2 (MonoMemPool *mp, MonoImage *image, guint32 token, MonoGenericContext *context);
gpointer mono_resolve_patch_target (MonoMethod *method, guint8 *code, MonoJumpInfo *patch_info, gboolean run_cctors, MonoError *error);
+gpointer mono_resolve_patch_target_ext (MonoMemoryManager *mem_manager, MonoMethod *method, guint8 *code, MonoJumpInfo *patch_info, gboolean run_cctors, MonoError *error);
void mini_register_jump_site (MonoMethod *method, gpointer ip);
void mini_patch_jump_sites (MonoMethod *method, gpointer addr);
void mini_patch_llvm_jit_callees (MonoMethod *method, gpointer addr);
int i;
int size = 0;
guchar *code, *start;
+ MonoMemoryManager *mem_manager = m_class_get_mem_manager (vtable->klass);
for (i = 0; i < count; ++i) {
MonoIMTCheckItem *item = imt_entries [i];
if (fail_tramp) {
code = (guint8 *)mini_alloc_generic_virtual_trampoline (vtable, size);
} else {
- MonoMemoryManager *mem_manager = m_class_get_mem_manager (vtable->klass);
code = mono_mem_manager_code_reserve (mem_manager, size);
}
g_assert (code - start <= size);
- mono_tramp_info_register (mono_tramp_info_create (NULL, start, code - start, NULL, NULL), NULL);
+ mono_tramp_info_register (mono_tramp_info_create (NULL, start, code - start, NULL, NULL), mem_manager);
return (start);
}
int size = 0;
guint8 *code, *start;
GSList *unwind_ops;
+ MonoMemoryManager *mem_manager = m_class_get_mem_manager (vtable->klass);
for (i = 0; i < count; ++i) {
MonoIMTCheckItem *item = imt_entries [i];
if (fail_tramp) {
code = (guint8 *)mini_alloc_generic_virtual_trampoline (vtable, size);
} else {
- MonoMemoryManager *mem_manager = m_class_get_mem_manager (vtable->klass);
code = mono_mem_manager_code_reserve (mem_manager, size);
}
start = code;
MONO_PROFILER_RAISE (jit_code_buffer, (start, code - start, MONO_PROFILER_CODE_BUFFER_IMT_TRAMPOLINE, NULL));
- mono_tramp_info_register (mono_tramp_info_create (NULL, start, code - start, NULL, unwind_ops), NULL);
+ mono_tramp_info_register (mono_tramp_info_create (NULL, start, code - start, NULL, unwind_ops), mem_manager);
return start;
}
int val);
MonoTrampInfo* mono_tramp_info_create (const char *name, guint8 *code, guint32 code_size, MonoJumpInfo *ji, GSList *unwind_ops);
void mono_tramp_info_free (MonoTrampInfo *info);
-void mono_aot_tramp_info_register (MonoTrampInfo *info, MonoDomain *domain);
-void mono_tramp_info_register (MonoTrampInfo *info, MonoDomain *domain);
+void mono_aot_tramp_info_register (MonoTrampInfo *info, MonoMemoryManager *mem_manager);
+void mono_tramp_info_register (MonoTrampInfo *info, MonoMemoryManager *mem_manager);
int mini_exception_id_by_name (const char *name);
gboolean mini_type_is_hfa (MonoType *t, int *out_nfields, int *out_esize);
mono_arch_flush_icache (start, code - start);
MONO_PROFILER_RAISE (jit_code_buffer, (start, code - start, MONO_PROFILER_CODE_BUFFER_UNBOX_TRAMPOLINE, m));
- mono_tramp_info_register (mono_tramp_info_create (NULL, start, code - start, NULL, unwind_ops), NULL);
+ mono_tramp_info_register (mono_tramp_info_create (NULL, start, code - start, NULL, unwind_ops), mem_manager);
return start;
}
mono_arch_flush_icache (start, code - start);
MONO_PROFILER_RAISE (jit_code_buffer, (start, code - start, MONO_PROFILER_CODE_BUFFER_GENERICS_TRAMPOLINE, NULL));
- mono_tramp_info_register (mono_tramp_info_create (NULL, start, code - start, NULL, unwind_ops), NULL);
+ mono_tramp_info_register (mono_tramp_info_create (NULL, start, code - start, NULL, unwind_ops), mem_manager);
return start;
}
/*g_print ("unbox trampoline at %d for %s:%s\n", this_pos, m->klass->name, m->name);
g_print ("unbox code is at %p for method at %p\n", start, addr);*/
- mono_tramp_info_register (mono_tramp_info_create (NULL, start, code - start, NULL, unwind_ops), NULL);
+ mono_tramp_info_register (mono_tramp_info_create (NULL, start, code - start, NULL, unwind_ops), mem_manager);
return start;
}
mono_arch_flush_icache (start, code - start);
MONO_PROFILER_RAISE (jit_code_buffer, (start, code - start, MONO_PROFILER_CODE_BUFFER_GENERICS_TRAMPOLINE, NULL));
- mono_tramp_info_register (mono_tramp_info_create (NULL, start, code - start, NULL, unwind_ops), NULL);
+ mono_tramp_info_register (mono_tramp_info_create (NULL, start, code - start, NULL, unwind_ops), mem_manager);
return start;
}
mono_arch_flush_icache (start, code - start);
MONO_PROFILER_RAISE (jit_code_buffer, (start, code - start, MONO_PROFILER_CODE_BUFFER_GENERICS_TRAMPOLINE, NULL));
- mono_tramp_info_register (mono_tramp_info_create (NULL, start, code - start, NULL, unwind_ops), NULL);
+ mono_tramp_info_register (mono_tramp_info_create (NULL, start, code - start, NULL, unwind_ops), mem_manager);
return start;
}
mono_arch_flush_icache (buf, code - buf);
MONO_PROFILER_RAISE (jit_code_buffer, (buf, code - buf, MONO_PROFILER_CODE_BUFFER_GENERICS_TRAMPOLINE, NULL));
- mono_tramp_info_register (mono_tramp_info_create (NULL, buf, code - buf, NULL, NULL), NULL);
+ mono_tramp_info_register (mono_tramp_info_create (NULL, buf, code - buf, NULL, NULL), mem_manager);
return buf;
}
/*g_print ("unbox trampoline at %d for %s:%s\n", this_pos, m->klass->name, m->name);
g_print ("unbox code is at %p for method at %p\n", start, addr);*/
- mono_tramp_info_register (mono_tramp_info_create (NULL, start, code - start, NULL, NULL), NULL);
+ mono_tramp_info_register (mono_tramp_info_create (NULL, start, code - start, NULL, NULL), mem_manager);
return start;
}
MONO_PROFILER_RAISE (jit_code_buffer, (start, code - start, MONO_PROFILER_CODE_BUFFER_GENERICS_TRAMPOLINE, NULL));
g_assert ((code - start) <= size);
- mono_tramp_info_register (mono_tramp_info_create (NULL, start, code - start, NULL, NULL), NULL);
+ mono_tramp_info_register (mono_tramp_info_create (NULL, start, code - start, NULL, NULL), mem_manager);
return start;
}
snprintf(trampName, sizeof(trampName), "%s_unbox_trampoline", m->name);
- mono_tramp_info_register (mono_tramp_info_create (trampName, start, code - start, NULL, NULL), NULL);
+ mono_tramp_info_register (mono_tramp_info_create (trampName, start, code - start, NULL, NULL), mem_manager);
return start;
}
mono_arch_flush_icache (start, code - start);
MONO_PROFILER_RAISE (jit_code_buffer, (start, code - start, MONO_PROFILER_CODE_BUFFER_GENERICS_TRAMPOLINE, NULL));
- mono_tramp_info_register (mono_tramp_info_create (NULL, start, code - start, NULL, NULL), NULL);
+ mono_tramp_info_register (mono_tramp_info_create (NULL, start, code - start, NULL, NULL), mem_manager);
return(start);
}
MONO_PROFILER_RAISE (jit_code_buffer, (start, code - start, MONO_PROFILER_CODE_BUFFER_UNBOX_TRAMPOLINE, m));
- mono_tramp_info_register (mono_tramp_info_create (NULL, start, code - start, NULL, unwind_ops), NULL);
+ mono_tramp_info_register (mono_tramp_info_create (NULL, start, code - start, NULL, unwind_ops), mem_manager);
return start;
}
mono_arch_flush_icache (start, code - start);
MONO_PROFILER_RAISE (jit_code_buffer, (start, code - start, MONO_PROFILER_CODE_BUFFER_GENERICS_TRAMPOLINE, NULL));
- mono_tramp_info_register (mono_tramp_info_create (NULL, start, code - start, NULL, unwind_ops), NULL);
+ mono_tramp_info_register (mono_tramp_info_create (NULL, start, code - start, NULL, unwind_ops), mem_manager);
return start;
}
mono_arch_flush_icache (start, code - start);
MONO_PROFILER_RAISE (jit_code_buffer, (start, code - start, MONO_PROFILER_CODE_BUFFER_GENERICS_TRAMPOLINE, NULL));
- mono_tramp_info_register (mono_tramp_info_create (NULL, start, code - start, NULL, unwind_ops), NULL);
+ mono_tramp_info_register (mono_tramp_info_create (NULL, start, code - start, NULL, unwind_ops), mem_manager);
return start;
}