Merge pull request #4570 from lateralusX/jlorenss/visual_studio_msbuild_fix
[mono.git] / mono / mini / interp / transform.c
index 4b2b96b5777eae3556965f183816e6ff39853f36..1b1776867fcc1bfe1b585db11a1e008a96c4ea3f 100644 (file)
@@ -1,4 +1,5 @@
-/*
+/**
+ * \file
  * transform CIL into different opcodes for more
  * efficient interpretation
  *
@@ -502,7 +503,7 @@ store_arg(TransformData *td, int n)
                else
                        size = mono_class_value_size (klass, NULL);
                ADD_CODE(td, MINT_STARG_VT);
-               ADD_CODE(td, n);
+               ADD_CODE(td, td->rtm->arg_offsets [n]);
                WRITE32(td, &size);
                if (td->sp [-1].type == STACK_TYPE_VT)
                        POP_VT(td, size);
@@ -1070,15 +1071,9 @@ generate (MonoMethod *method, RuntimeMethod *rtm, unsigned char *is_bb_start, Mo
                        break;
                case CEE_LDARGA_S: {
                        /* NOTE: n includes this */
-                       int n = ((guint8 *)td.ip)[1];
-                       if (n == 0 && signature->hasthis) {
-                               g_error ("LDTHISA: NOPE");
-                               ADD_CODE(&td, MINT_LDTHISA);
-                       }
-                       else {
-                               ADD_CODE(&td, MINT_LDARGA);
-                               ADD_CODE(&td, td.rtm->arg_offsets [n]);
-                       }
+                       int n = ((guint8 *) td.ip) [1];
+                       ADD_CODE (&td, MINT_LDARGA);
+                       ADD_CODE (&td, td.rtm->arg_offsets [n]);
                        PUSH_SIMPLE_TYPE(&td, STACK_TYPE_MP);
                        td.ip += 2;
                        break;
@@ -2717,9 +2712,15 @@ generate (MonoMethod *method, RuntimeMethod *rtm, unsigned char *is_bb_start, Mo
                                klass = (MonoClass *) mono_method_get_wrapper_data (method, token + 1);
                                if (klass == mono_defaults.typehandle_class)
                                        handle = &((MonoClass *) handle)->byval_arg;
+
+                               if (generic_context) {
+                                       handle = mono_class_inflate_generic_type_checked (handle, generic_context, &error);
+                                       mono_error_cleanup (&error); /* FIXME: don't swallow the error */
+                               }
                        } else {
                                handle = mono_ldtoken (image, token, &klass, generic_context);
                        }
+                       mono_class_init (klass);
                        mt = mint_type (&klass->byval_arg);
                        g_assert (mt == MINT_TYPE_VT);
                        size = mono_class_value_size (klass, NULL);
@@ -3033,14 +3034,8 @@ generate (MonoMethod *method, RuntimeMethod *rtm, unsigned char *is_bb_start, Mo
                                break;
                        case CEE_LDARGA: {
                                int n = read16 (td.ip + 1);
-                               if (n == 0 && signature->hasthis) {
-                                       g_error ("LDTHISA: NOPE");
-                                       ADD_CODE(&td, MINT_LDTHISA);
-                               }
-                               else {
-                                       ADD_CODE(&td, MINT_LDARGA);
-                                       ADD_CODE(&td, td.rtm->arg_offsets [n]); /* FIX for large offsets */
-                               }
+                               ADD_CODE (&td, MINT_LDARGA);
+                               ADD_CODE (&td, td.rtm->arg_offsets [n]); /* FIX for large offsets */
                                PUSH_SIMPLE_TYPE(&td, STACK_TYPE_MP);
                                td.ip += 3;
                                break;
@@ -3191,9 +3186,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 +3204,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);
@@ -3314,7 +3309,7 @@ mono_interp_transform_method (RuntimeMethod *runtime_method, ThreadContext *cont
                                } else if (*name == 'E' && (strcmp (name, "EndInvoke") == 0)) {
                                        nm = mono_marshal_get_delegate_end_invoke (method);
                                }
-                       } 
+                       }
                        if (nm == NULL) {
                                runtime_method->code = g_malloc(sizeof(short));
                                runtime_method->code[0] = MINT_CALLRUN;
@@ -3331,6 +3326,24 @@ mono_interp_transform_method (RuntimeMethod *runtime_method, ThreadContext *cont
                method = nm;
                header = mono_method_get_header (nm);
                mono_os_mutex_unlock(&calc_section);
+       } else if (method->klass == mono_defaults.array_class) {
+               if (!strcmp (method->name, "UnsafeMov")) {
+                       mono_os_mutex_lock (&calc_section);
+                       if (!runtime_method->transformed) {
+                               runtime_method->code = g_malloc (sizeof (short));
+                               runtime_method->code[0] = MINT_CALLRUN;
+                               runtime_method->stack_size = sizeof (stackval); /* for tracing */
+                               runtime_method->alloca_size = runtime_method->stack_size;
+                               runtime_method->transformed = TRUE;
+                       }
+                       mono_os_mutex_unlock(&calc_section);
+                       mono_profiler_method_end_jit (method, NULL, MONO_PROFILE_OK);
+                       return NULL;
+               } else if (!strcmp (method->name, "UnsafeStore)")) {
+                       g_error ("TODO");
+               } else if (!strcmp (method->name, "UnsafeLoad)")) {
+                       g_error ("TODO");
+               }
        }
        g_assert ((signature->param_count + signature->hasthis) < 1000);
        g_assert (header->max_stack < 10000);