[runtime] Fix cpu usage greater than 100% error
[mono.git] / mono / mini / mini-runtime.c
index 33a055fd76ee64f856bcbfcf74de199604fea534..b597688610482ec362dd8d1ea444b0caed4c75ab 100644 (file)
@@ -260,7 +260,7 @@ mono_print_method_from_ip (void *ip)
        gsctx = mono_jit_info_get_generic_sharing_context (ji);
        shared_type = "";
        if (gsctx) {
-               if (gsctx->var_is_vt || gsctx->mvar_is_vt)
+               if (gsctx->is_gsharedvt)
                        shared_type = "gsharedvt ";
                else
                        shared_type = "gshared ";
@@ -1591,62 +1591,7 @@ mono_resolve_patch_target (MonoMethod *method, MonoDomain *domain, guint8 *code,
        case MONO_PATCH_INFO_NONE:
                break;
        case MONO_PATCH_INFO_RGCTX_FETCH: {
-               MonoJumpInfoRgctxEntry *entry = patch_info->data.rgctx_entry;
-               guint32 slot = -1;
-
-               switch (entry->data->type) {
-               case MONO_PATCH_INFO_CLASS:
-                       slot = mono_method_lookup_or_register_info (entry->method, entry->in_mrgctx, &entry->data->data.klass->byval_arg, entry->info_type, mono_method_get_context (entry->method));
-                       break;
-               case MONO_PATCH_INFO_METHOD:
-               case MONO_PATCH_INFO_METHODCONST:
-                       slot = mono_method_lookup_or_register_info (entry->method, entry->in_mrgctx, entry->data->data.method, entry->info_type, mono_method_get_context (entry->method));
-                       break;
-               case MONO_PATCH_INFO_FIELD:
-                       slot = mono_method_lookup_or_register_info (entry->method, entry->in_mrgctx, entry->data->data.field, entry->info_type, mono_method_get_context (entry->method));
-                       break;
-               case MONO_PATCH_INFO_SIGNATURE:
-                       slot = mono_method_lookup_or_register_info (entry->method, entry->in_mrgctx, entry->data->data.sig, entry->info_type, mono_method_get_context (entry->method));
-                       break;
-               case MONO_PATCH_INFO_GSHAREDVT_CALL: {
-                       MonoJumpInfoGSharedVtCall *call_info = g_malloc0 (sizeof (MonoJumpInfoGSharedVtCall)); //mono_domain_alloc0 (domain, sizeof (MonoJumpInfoGSharedVtCall));
-
-                       memcpy (call_info, entry->data->data.gsharedvt, sizeof (MonoJumpInfoGSharedVtCall));
-                       slot = mono_method_lookup_or_register_info (entry->method, entry->in_mrgctx, call_info, entry->info_type, mono_method_get_context (entry->method));
-                       break;
-               }
-               case MONO_PATCH_INFO_GSHAREDVT_METHOD: {
-                       MonoGSharedVtMethodInfo *info;
-                       MonoGSharedVtMethodInfo *oinfo = entry->data->data.gsharedvt_method;
-                       int i;
-
-                       /* Make a copy into the domain mempool */
-                       info = g_malloc0 (sizeof (MonoGSharedVtMethodInfo)); //mono_domain_alloc0 (domain, sizeof (MonoGSharedVtMethodInfo));
-                       info->method = oinfo->method;
-                       info->num_entries = oinfo->num_entries;
-                       info->entries = g_malloc0 (sizeof (MonoRuntimeGenericContextInfoTemplate) * info->num_entries);
-                       for (i = 0; i < oinfo->num_entries; ++i) {
-                               MonoRuntimeGenericContextInfoTemplate *otemplate = &oinfo->entries [i];
-                               MonoRuntimeGenericContextInfoTemplate *template = &info->entries [i];
-
-                               memcpy (template, otemplate, sizeof (MonoRuntimeGenericContextInfoTemplate));
-                       }
-                       slot = mono_method_lookup_or_register_info (entry->method, entry->in_mrgctx, info, entry->info_type, mono_method_get_context (entry->method));
-                       break;
-               }
-               case MONO_PATCH_INFO_VIRT_METHOD: {
-                       MonoJumpInfoVirtMethod *info;
-                       MonoJumpInfoVirtMethod *oinfo = entry->data->data.virt_method;
-
-                       info = g_malloc0 (sizeof (MonoJumpInfoVirtMethod));
-                       memcpy (info, oinfo, sizeof (MonoJumpInfoVirtMethod));
-                       slot = mono_method_lookup_or_register_info (entry->method, entry->in_mrgctx, info, entry->info_type, mono_method_get_context (entry->method));
-                       break;
-               }
-               default:
-                       g_assert_not_reached ();
-                       break;
-               }
+               int slot = mini_get_rgctx_entry_slot (patch_info->data.rgctx_entry);
 
                target = mono_create_rgctx_lazy_fetch_trampoline (slot);
                break;
@@ -1741,34 +1686,21 @@ mini_init_gsctx (MonoDomain *domain, MonoMemPool *mp, MonoGenericContext *contex
 
        if (context && context->class_inst) {
                inst = context->class_inst;
-               if (domain)
-                       gsctx->var_is_vt = mono_domain_alloc0 (domain, sizeof (gboolean) * inst->type_argc);
-               else if (mp)
-                       gsctx->var_is_vt = mono_mempool_alloc0 (mp, sizeof (gboolean) * inst->type_argc);
-               else
-                       gsctx->var_is_vt = g_new0 (gboolean, inst->type_argc);
-
                for (i = 0; i < inst->type_argc; ++i) {
                        MonoType *type = inst->type_argv [i];
 
                        if (mini_is_gsharedvt_gparam (type))
-                               gsctx->var_is_vt [i] = TRUE;
+                               gsctx->is_gsharedvt = TRUE;
                }
        }
        if (context && context->method_inst) {
                inst = context->method_inst;
-               if (domain)
-                       gsctx->mvar_is_vt = mono_domain_alloc0 (domain, sizeof (gboolean) * inst->type_argc);
-               else if (mp)
-                       gsctx->mvar_is_vt = mono_mempool_alloc0 (mp, sizeof (gboolean) * inst->type_argc);
-               else
-                       gsctx->mvar_is_vt = g_new0 (gboolean, inst->type_argc);
 
                for (i = 0; i < inst->type_argc; ++i) {
                        MonoType *type = inst->type_argv [i];
 
                        if (mini_is_gsharedvt_gparam (type))
-                               gsctx->mvar_is_vt [i] = TRUE;
+                               gsctx->is_gsharedvt = TRUE;
                }
        }
 }
@@ -2242,10 +2174,11 @@ mono_jit_runtime_invoke (MonoMethod *method, void *obj, void **params, MonoObjec
                                        return NULL;
                                } else {
                                        mono_raise_exception (jit_ex);
+                                       /* coverity[unreachable] */
                                }
                        }
 
-                       info->compiled_method = mini_add_method_trampoline (NULL, callee, info->compiled_method, mono_method_needs_static_rgctx_invoke (callee, FALSE), FALSE);
+                       info->compiled_method = mini_add_method_trampoline (callee, info->compiled_method, mono_method_needs_static_rgctx_invoke (callee, TRUE), FALSE);
                } else {
                        info->compiled_method = NULL;
                }
@@ -3423,6 +3356,8 @@ register_icalls (void)
        register_icall (mono_object_castclass_with_cache, "mono_object_castclass_with_cache", "object object ptr ptr", FALSE);
        register_icall (mono_object_isinst_with_cache, "mono_object_isinst_with_cache", "object object ptr ptr", FALSE);
        register_icall (mono_generic_class_init, "mono_generic_class_init", "void ptr", FALSE);
+       register_icall (mono_fill_class_rgctx, "mono_class_fill_rgctx", "ptr ptr int", FALSE);
+       register_icall (mono_fill_method_rgctx, "mono_method_fill_rgctx", "ptr ptr int", FALSE);
 
        register_icall (mono_debugger_agent_user_break, "mono_debugger_agent_user_break", "void", FALSE);
        register_dyn_icall (mono_create_specific_trampoline (NULL, MONO_TRAMPOLINE_GENERIC_CLASS_INIT, mono_get_root_domain (), NULL),
@@ -3517,6 +3452,7 @@ mini_cleanup (MonoDomain *domain)
 
 #ifndef MONO_CROSS_COMPILE
        mono_domain_free (domain, TRUE);
+       mono_gc_mutex_cleanup ();
 #endif
 
 #ifdef ENABLE_LLVM