From: Bernhard Urban Date: Mon, 13 Mar 2017 16:39:58 +0000 (+0100) Subject: [interp] lock when acquiring memory from a mempool. X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=commitdiff_plain;h=bae654cbf7a53a12a9493f7f62162379ae6b6860;p=mono.git [interp] lock when acquiring memory from a mempool. `mono_domain_alloc` does that for us. also, use proper locking around JIT code hashtable. the interpreter repurpose the JITs hashtable, so let's use the existing locks. --- diff --git a/mono/mini/interp/interp.c b/mono/mini/interp/interp.c index 395850a0709..0f0223b421c 100644 --- a/mono/mini/interp/interp.c +++ b/mono/mini/interp/interp.c @@ -253,26 +253,23 @@ ves_real_abort (int line, MonoMethod *mh, THROW_EX (mono_get_exception_execution_engine (NULL), ip); \ } while (0); -static mono_mutex_t runtime_method_lookup_section; - RuntimeMethod* mono_interp_get_runtime_method (MonoDomain *domain, MonoMethod *method, MonoError *error) { RuntimeMethod *rtm; error_init (error); - mono_os_mutex_lock (&runtime_method_lookup_section); + mono_domain_jit_code_hash_lock (domain); if ((rtm = mono_internal_hash_table_lookup (&domain->jit_code_hash, method))) { - mono_os_mutex_unlock (&runtime_method_lookup_section); + mono_domain_jit_code_hash_unlock (domain); return rtm; } - rtm = mono_mempool_alloc (domain->mp, sizeof (RuntimeMethod)); - memset (rtm, 0, sizeof (*rtm)); + rtm = mono_domain_alloc0 (domain, sizeof (RuntimeMethod)); rtm->method = method; rtm->param_count = mono_method_signature (method)->param_count; rtm->hasthis = mono_method_signature (method)->hasthis; mono_internal_hash_table_insert (&domain->jit_code_hash, method, rtm); - mono_os_mutex_unlock (&runtime_method_lookup_section); + mono_domain_jit_code_hash_unlock (domain); return rtm; } @@ -4377,7 +4374,6 @@ mono_interp_init () { mono_native_tls_alloc (&thread_context_id, NULL); mono_native_tls_set_value (thread_context_id, NULL); - mono_os_mutex_init_recursive (&runtime_method_lookup_section); mono_os_mutex_init_recursive (&create_method_pointer_mutex); mono_interp_transform_init (); @@ -4399,16 +4395,6 @@ interp_regression_step (MonoImage *image, int verbose, int *total_run, int *tota cfailed = failed = run = 0; transform_time = elapsed = 0.0; -#if 0 - /* fixme: ugly hack - delete all previously compiled methods */ - if (domain_jit_info (domain)) { - g_hash_table_destroy (domain_jit_info (domain)->jit_trampoline_hash); - domain_jit_info (domain)->jit_trampoline_hash = g_hash_table_new (mono_aligned_addr_hash, NULL); - mono_internal_hash_table_destroy (&(domain->jit_code_hash)); - mono_jit_code_hash_init (&(domain->jit_code_hash)); - } -#endif - g_timer_start (timer); for (i = 0; i < mono_image_get_table_rows (image, MONO_TABLE_METHOD); ++i) { MonoObject *exc = NULL; diff --git a/mono/mini/interp/transform.c b/mono/mini/interp/transform.c index 4b2b96b5777..bae348bc2e6 100644 --- a/mono/mini/interp/transform.c +++ b/mono/mini/interp/transform.c @@ -3191,9 +3191,9 @@ generate (MonoMethod *method, RuntimeMethod *rtm, unsigned char *is_bb_start, Mo } g_assert (td.max_stack_height <= (header->max_stack + 1)); - rtm->clauses = mono_mempool_alloc (domain->mp, header->num_clauses * sizeof(MonoExceptionClause)); + rtm->clauses = mono_domain_alloc0 (domain, header->num_clauses * sizeof (MonoExceptionClause)); memcpy (rtm->clauses, header->clauses, header->num_clauses * sizeof(MonoExceptionClause)); - rtm->code = mono_mempool_alloc (domain->mp, (td.new_ip - td.new_code) * sizeof(gushort)); + rtm->code = mono_domain_alloc0 (domain, (td.new_ip - td.new_code) * sizeof (gushort)); memcpy (rtm->code, td.new_code, (td.new_ip - td.new_code) * sizeof(gushort)); g_free (td.new_code); rtm->new_body_start = rtm->code + body_start_offset; @@ -3209,7 +3209,7 @@ generate (MonoMethod *method, RuntimeMethod *rtm, unsigned char *is_bb_start, Mo } rtm->vt_stack_size = td.max_vt_sp; rtm->alloca_size = rtm->locals_size + rtm->args_size + rtm->vt_stack_size + rtm->stack_size; - rtm->data_items = mono_mempool_alloc (domain->mp, td.n_data_items * sizeof (td.data_items [0])); + rtm->data_items = mono_domain_alloc0 (domain, td.n_data_items * sizeof (td.data_items [0])); memcpy (rtm->data_items, td.data_items, td.n_data_items * sizeof (td.data_items [0])); g_free (td.in_offsets); g_free (td.forward_refs);