3 * PLEASE NOTE: This is a research prototype.
6 * interp.c: Interpreter for CIL byte codes
9 * Paolo Molaro (lupus@ximian.com)
10 * Miguel de Icaza (miguel@ximian.com)
11 * Dietmar Maurer (dietmar@ximian.com)
13 * (C) 2001, 2002 Ximian, Inc.
28 #include <mono/utils/gc_wrapper.h>
34 # define alloca __builtin_alloca
38 /* trim excessive headers */
39 #include <mono/metadata/image.h>
40 #include <mono/metadata/assembly-internals.h>
41 #include <mono/metadata/cil-coff.h>
42 #include <mono/metadata/mono-endian.h>
43 #include <mono/metadata/tabledefs.h>
44 #include <mono/metadata/tokentype.h>
45 #include <mono/metadata/loader.h>
46 #include <mono/metadata/threads.h>
47 #include <mono/metadata/threadpool.h>
48 #include <mono/metadata/profiler-private.h>
49 #include <mono/metadata/appdomain.h>
50 #include <mono/metadata/reflection.h>
51 #include <mono/metadata/reflection-internals.h>
52 #include <mono/metadata/exception.h>
53 #include <mono/metadata/verify.h>
54 #include <mono/metadata/opcodes.h>
55 #include <mono/metadata/debug-helpers.h>
56 #include <mono/metadata/mono-config.h>
57 #include <mono/metadata/marshal.h>
58 #include <mono/metadata/environment.h>
59 #include <mono/metadata/mono-debug.h>
62 #include "interp-internals.h"
66 #include <mono/mini/mini.h>
67 #include <mono/mini/jit-icalls.h>
70 /* Mingw 2.1 doesnt need this any more, but leave it in for now for older versions */
73 #define finite _finite
77 #define finite isfinite
82 init_frame (MonoInvocation *frame, MonoInvocation *parent_frame, RuntimeMethod *rmethod, stackval *method_args, stackval *method_retval)
84 frame->parent = parent_frame;
85 frame->stack_args = method_args;
86 frame->retval = method_retval;
87 frame->runtime_method = rmethod;
90 frame->invoke_trap = 0;
93 #define INIT_FRAME(frame,parent_frame,method_args,method_retval,domain,mono_method,error) do { \
94 RuntimeMethod *_rmethod = mono_interp_get_runtime_method ((domain), (mono_method), (error)); \
95 init_frame ((frame), (parent_frame), _rmethod, (method_args), (method_retval)); \
99 * List of classes whose methods will be executed by transitioning to JITted code.
104 void ves_exec_method (MonoInvocation *frame);
106 static char* dump_stack (stackval *stack, stackval *sp);
107 static char* dump_frame (MonoInvocation *inv);
108 static MonoArray *get_trace_ips (MonoDomain *domain, MonoInvocation *top);
109 static void ves_exec_method_with_context (MonoInvocation *frame, ThreadContext *context);
111 typedef void (*ICallMethod) (MonoInvocation *frame);
113 static guint32 die_on_exception = 0;
114 static MonoNativeTlsKey thread_context_id;
116 static char* dump_args (MonoInvocation *inv);
118 #define DEBUG_INTERP 0
121 int mono_interp_traceopt = 2;
122 /* If true, then we output the opcodes as we interpret them */
123 static int global_tracing = 2;
125 static int debug_indent_level = 0;
127 static int break_on_method = 0;
128 static int nested_trace = 0;
129 static GList *db_methods = NULL;
136 for (h = 0; h < debug_indent_level; h++)
141 db_match_method (gpointer data, gpointer user_data)
143 MonoMethod *m = (MonoMethod*)user_data;
144 MonoMethodDesc *desc = data;
146 if (mono_method_desc_full_match (desc, m))
150 static void debug_enter (MonoInvocation *frame, int *tracing)
153 g_list_foreach (db_methods, db_match_method, (gpointer)frame->runtime_method->method);
155 *tracing = nested_trace ? (global_tracing = 2, 3) : 2;
159 MonoMethod *method = frame->runtime_method->method;
160 char *mn, *args = dump_args (frame);
161 debug_indent_level++;
163 mn = mono_method_full_name (method, FALSE);
164 g_print ("(%p) Entering %s (", mono_thread_internal_current (), mn);
166 g_print ("%s)\n", args);
169 if (mono_profiler_events & MONO_PROFILE_ENTER_LEAVE)
170 mono_profiler_method_enter (frame->runtime_method->method);
174 #define DEBUG_LEAVE() \
177 args = dump_retval (frame); \
179 mn = mono_method_full_name (frame->runtime_method->method, FALSE); \
180 g_print ("(%p) Leaving %s", mono_thread_internal_current (), mn); \
182 g_print (" => %s\n", args); \
184 debug_indent_level--; \
185 if (tracing == 3) global_tracing = 0; \
187 if (mono_profiler_events & MONO_PROFILE_ENTER_LEAVE) \
188 mono_profiler_method_leave (frame->runtime_method->method);
192 int mono_interp_traceopt = 0;
193 static void debug_enter (MonoInvocation *frame, int *tracing)
196 #define DEBUG_LEAVE()
201 interp_ex_handler (MonoException *ex) {
203 ThreadContext *context = mono_native_tls_get_value (thread_context_id);
207 stack_trace = dump_frame (context->current_frame);
208 ex->stack_trace = mono_string_new (mono_domain_get(), stack_trace);
209 g_free (stack_trace);
210 if (context->current_env == NULL || strcmp(ex->object.vtable->klass->name, "ExecutionEngineException") == 0) {
211 char *strace = mono_string_to_utf8_checked (ex->stack_trace, &error);
212 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
213 fprintf(stderr, "Nothing can catch this exception: ");
214 fprintf(stderr, "%s", ex->object.vtable->klass->name);
215 if (ex->message != NULL) {
216 char *m = mono_string_to_utf8_checked (ex->message, &error);
217 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
218 fprintf(stderr, ": %s", m);
221 fprintf(stderr, "\n%s\n", strace);
223 if (ex->inner_ex != NULL) {
224 ex = (MonoException *)ex->inner_ex;
225 fprintf(stderr, "Inner exception: %s", ex->object.vtable->klass->name);
226 if (ex->message != NULL) {
227 char *m = mono_string_to_utf8_checked (ex->message, &error);
228 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
229 fprintf(stderr, ": %s", m);
232 strace = mono_string_to_utf8_checked (ex->stack_trace, &error);
233 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
234 fprintf(stderr, "\n");
235 fprintf(stderr, "%s\n", strace);
238 /* wait for other threads to also collapse */
239 // Sleep(1000); // TODO: proper sleep
242 context->env_frame->ex = ex;
243 context->search_for_handler = 1;
244 longjmp (*context->current_env, 1);
248 ves_real_abort (int line, MonoMethod *mh,
249 const unsigned short *ip, stackval *stack, stackval *sp)
252 fprintf (stderr, "Execution aborted in method: %s::%s\n", mh->klass->name, mh->name);
253 fprintf (stderr, "Line=%d IP=0x%04lx, Aborted execution\n", line,
254 ip-(const unsigned short *)mono_method_get_header_checked (mh, &error)->code);
255 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
256 g_print ("0x%04x %02x\n",
257 ip-(const unsigned short *)mono_method_get_header_checked (mh, &error)->code, *ip);
258 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
260 printf ("\t[%ld] 0x%08x %0.5f\n", sp-stack, sp[-1].data.i, sp[-1].data.f);
263 #define ves_abort() \
265 ves_real_abort(__LINE__, frame->runtime_method->method, ip, frame->stack, sp); \
266 THROW_EX (mono_get_exception_execution_engine (NULL), ip); \
270 mono_interp_get_runtime_method (MonoDomain *domain, MonoMethod *method, MonoError *error)
273 MonoJitDomainInfo *info;
274 MonoMethodSignature *sig;
279 info = domain_jit_info (domain);
280 mono_domain_jit_code_hash_lock (domain);
281 rtm = mono_internal_hash_table_lookup (&info->interp_code_hash, method);
282 mono_domain_jit_code_hash_unlock (domain);
286 sig = mono_method_signature (method);
288 rtm = mono_domain_alloc0 (domain, sizeof (RuntimeMethod));
289 rtm->method = method;
290 rtm->param_count = sig->param_count;
291 rtm->hasthis = sig->hasthis;
292 rtm->rtype = mini_get_underlying_type (sig->ret);
293 rtm->param_types = mono_domain_alloc0 (domain, sizeof (MonoType*) * sig->param_count);
294 for (i = 0; i < sig->param_count; ++i)
295 rtm->param_types [i] = mini_get_underlying_type (sig->params [i]);
297 mono_domain_jit_code_hash_lock (domain);
298 if (!mono_internal_hash_table_lookup (&info->interp_code_hash, method))
299 mono_internal_hash_table_insert (&info->interp_code_hash, method, rtm);
300 mono_domain_jit_code_hash_unlock (domain);
306 mono_interp_create_trampoline (MonoDomain *domain, MonoMethod *method, MonoError *error)
308 if (method->iflags & METHOD_IMPL_ATTRIBUTE_SYNCHRONIZED)
309 method = mono_marshal_get_synchronized_wrapper (method);
310 return mono_interp_get_runtime_method (domain, method, error);
313 static inline RuntimeMethod*
314 get_virtual_method (MonoDomain *domain, RuntimeMethod *runtime_method, MonoObject *obj)
316 MonoMethod *m = runtime_method->method;
319 if ((m->flags & METHOD_ATTRIBUTE_FINAL) || !(m->flags & METHOD_ATTRIBUTE_VIRTUAL)) {
320 RuntimeMethod *ret = NULL;
321 if (mono_object_is_transparent_proxy (obj)) {
322 ret = mono_interp_get_runtime_method (domain, mono_marshal_get_remoting_invoke (m), &error);
323 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
324 } else if (m->iflags & METHOD_IMPL_ATTRIBUTE_SYNCHRONIZED) {
325 ret = mono_interp_get_runtime_method (domain, mono_marshal_get_synchronized_wrapper (m), &error);
326 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
328 ret = runtime_method;
333 mono_class_setup_vtable (obj->vtable->klass);
335 int slot = mono_method_get_vtable_slot (m);
336 if (mono_class_is_interface (m->klass)) {
337 g_assert (obj->vtable->klass != m->klass);
338 /* TODO: interface offset lookup is slow, go through IMT instead */
339 gboolean non_exact_match;
340 slot += mono_class_interface_offset_with_variance (obj->vtable->klass, m->klass, &non_exact_match);
343 MonoMethod *virtual_method = obj->vtable->klass->vtable [slot];
344 if (m->is_inflated && mono_method_get_context (m)->method_inst) {
345 MonoGenericContext context = { NULL, NULL };
347 if (mono_class_is_ginst (virtual_method->klass))
348 context.class_inst = mono_class_get_generic_class (virtual_method->klass)->context.class_inst;
349 else if (mono_class_is_gtd (virtual_method->klass))
350 context.class_inst = mono_class_get_generic_container (virtual_method->klass)->context.class_inst;
351 context.method_inst = mono_method_get_context (m)->method_inst;
353 virtual_method = mono_class_inflate_generic_method_checked (virtual_method, &context, &error);
354 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
357 if (virtual_method->iflags & METHOD_IMPL_ATTRIBUTE_SYNCHRONIZED) {
358 virtual_method = mono_marshal_get_synchronized_wrapper (virtual_method);
361 RuntimeMethod *virtual_runtime_method = mono_interp_get_runtime_method (domain, virtual_method, &error);
362 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
363 return virtual_runtime_method;
367 stackval_from_data (MonoType *type, stackval *result, char *data, gboolean pinvoke)
370 switch (type->type) {
371 case MONO_TYPE_OBJECT:
372 case MONO_TYPE_CLASS:
373 case MONO_TYPE_STRING:
374 case MONO_TYPE_ARRAY:
375 case MONO_TYPE_SZARRAY:
380 result->data.p = *(gpointer*)data;
383 switch (type->type) {
387 result->data.i = *(gint8*)data;
390 case MONO_TYPE_BOOLEAN:
391 result->data.i = *(guint8*)data;
394 result->data.i = *(gint16*)data;
398 result->data.i = *(guint16*)data;
401 result->data.i = *(gint32*)data;
405 result->data.nati = *(mono_i*)data;
408 result->data.p = *(gpointer*)data;
411 result->data.i = *(guint32*)data;
414 result->data.f = *(float*)data;
418 result->data.l = *(gint64*)data;
421 result->data.f = *(double*)data;
423 case MONO_TYPE_STRING:
424 case MONO_TYPE_SZARRAY:
425 case MONO_TYPE_CLASS:
426 case MONO_TYPE_OBJECT:
427 case MONO_TYPE_ARRAY:
428 result->data.p = *(gpointer*)data;
430 case MONO_TYPE_VALUETYPE:
431 if (type->data.klass->enumtype) {
432 stackval_from_data (mono_class_enum_basetype (type->data.klass), result, data, pinvoke);
435 mono_value_copy (result->data.vt, data, type->data.klass);
437 case MONO_TYPE_GENERICINST:
438 stackval_from_data (&type->data.generic_class->container_class->byval_arg, result, data, pinvoke);
441 g_warning ("got type 0x%02x", type->type);
442 g_assert_not_reached ();
447 stackval_to_data (MonoType *type, stackval *val, char *data, gboolean pinvoke)
450 gpointer *p = (gpointer*)data;
454 /* printf ("TODAT0 %p\n", data); */
455 switch (type->type) {
458 guint8 *p = (guint8*)data;
462 case MONO_TYPE_BOOLEAN: {
463 guint8 *p = (guint8*)data;
464 *p = (val->data.i != 0);
469 case MONO_TYPE_CHAR: {
470 guint16 *p = (guint16*)data;
475 mono_i *p = (mono_i*)data;
476 /* In theory the value used by stloc should match the local var type
477 but in practice it sometimes doesn't (a int32 gets dup'd and stloc'd into
478 a native int - both by csc and mcs). Not sure what to do about sign extension
479 as it is outside the spec... doing the obvious */
480 *p = (mono_i)val->data.nati;
484 mono_u *p = (mono_u*)data;
486 *p = (mono_u)val->data.nati;
491 gint32 *p = (gint32*)data;
497 gint64 *p = (gint64*)data;
502 float *p = (float*)data;
507 double *p = (double*)data;
511 case MONO_TYPE_STRING:
512 case MONO_TYPE_SZARRAY:
513 case MONO_TYPE_CLASS:
514 case MONO_TYPE_OBJECT:
515 case MONO_TYPE_ARRAY: {
516 gpointer *p = (gpointer *) data;
517 mono_gc_wbarrier_generic_store (p, val->data.p);
520 case MONO_TYPE_PTR: {
521 gpointer *p = (gpointer *) data;
525 case MONO_TYPE_VALUETYPE:
526 if (type->data.klass->enumtype) {
527 stackval_to_data (mono_class_enum_basetype (type->data.klass), val, data, pinvoke);
530 mono_value_copy (data, val->data.vt, type->data.klass);
532 case MONO_TYPE_GENERICINST:
533 stackval_to_data (&type->data.generic_class->container_class->byval_arg, val, data, pinvoke);
536 g_warning ("got type %x", type->type);
537 g_assert_not_reached ();
542 fill_in_trace (MonoException *exception, MonoInvocation *frame)
544 char *stack_trace = dump_frame (frame);
545 MonoDomain *domain = mono_domain_get();
546 (exception)->stack_trace = mono_string_new (domain, stack_trace);
547 (exception)->trace_ips = get_trace_ips (domain, frame);
548 g_free (stack_trace);
551 #define FILL_IN_TRACE(exception, frame) fill_in_trace(exception, frame)
553 #define THROW_EX(exception,ex_ip) \
555 frame->ip = (ex_ip); \
556 frame->ex = (MonoException*)(exception); \
557 FILL_IN_TRACE(frame->ex, frame); \
558 goto handle_exception; \
562 ves_array_create (MonoInvocation *frame, MonoDomain *domain, MonoClass *klass, MonoMethodSignature *sig, stackval *values)
565 intptr_t *lower_bounds;
570 lengths = alloca (sizeof (uintptr_t) * klass->rank * 2);
571 for (i = 0; i < sig->param_count; ++i) {
572 lengths [i] = values->data.i;
575 if (klass->rank == sig->param_count) {
576 /* Only lengths provided. */
579 /* lower bounds are first. */
580 lower_bounds = (intptr_t *) lengths;
581 lengths += klass->rank;
583 obj = (MonoObject*) mono_array_new_full_checked (domain, klass, lengths, lower_bounds, &error);
584 if (!mono_error_ok (&error)) {
585 frame->ex = mono_error_convert_to_exception (&error);
586 FILL_IN_TRACE (frame->ex, frame);
588 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
593 ves_array_calculate_index (MonoArray *ao, stackval *sp, MonoInvocation *frame)
595 g_assert (!frame->ex);
596 MonoClass *ac = ((MonoObject *) ao)->vtable->klass;
600 for (gint32 i = 0; i < ac->rank; i++) {
601 guint32 idx = sp [i].data.i;
602 guint32 lower = ao->bounds [i].lower_bound;
603 guint32 len = ao->bounds [i].length;
604 if (idx < lower || (idx - lower) >= len) {
605 frame->ex = mono_get_exception_index_out_of_range ();
606 FILL_IN_TRACE (frame->ex, frame);
609 pos = (pos * len) + idx - lower;
613 if (pos >= ao->max_length) {
614 frame->ex = mono_get_exception_index_out_of_range ();
615 FILL_IN_TRACE (frame->ex, frame);
623 ves_array_set (MonoInvocation *frame)
625 stackval *sp = frame->stack_args + 1;
627 MonoObject *o = frame->stack_args->data.p;
628 MonoArray *ao = (MonoArray *) o;
629 MonoClass *ac = o->vtable->klass;
631 g_assert (ac->rank >= 1);
633 gint32 pos = ves_array_calculate_index (ao, sp, frame);
637 if (sp [ac->rank].data.p && !mono_object_class (o)->element_class->valuetype) {
639 MonoObject *isinst = mono_object_isinst_checked (sp [ac->rank].data.p, mono_object_class (o)->element_class, &error);
640 mono_error_cleanup (&error);
642 frame->ex = mono_get_exception_array_type_mismatch ();
643 FILL_IN_TRACE (frame->ex, frame);
648 gint32 esize = mono_array_element_size (ac);
649 gpointer ea = mono_array_addr_with_size (ao, esize, pos);
651 MonoType *mt = mono_method_signature (frame->runtime_method->method)->params [ac->rank];
652 stackval_to_data (mt, &sp [ac->rank], ea, FALSE);
656 ves_array_get (MonoInvocation *frame)
658 stackval *sp = frame->stack_args + 1;
660 MonoObject *o = frame->stack_args->data.p;
661 MonoArray *ao = (MonoArray *) o;
662 MonoClass *ac = o->vtable->klass;
664 g_assert (ac->rank >= 1);
666 gint32 pos = ves_array_calculate_index (ao, sp, frame);
670 gint32 esize = mono_array_element_size (ac);
671 gpointer ea = mono_array_addr_with_size (ao, esize, pos);
673 MonoType *mt = mono_method_signature (frame->runtime_method->method)->ret;
674 stackval_from_data (mt, frame->retval, ea, FALSE);
678 ves_array_element_address (MonoInvocation *frame, MonoClass *required_type, MonoArray *ao, stackval *sp, gboolean needs_typecheck)
680 MonoClass *ac = ((MonoObject *) ao)->vtable->klass;
682 g_assert (ac->rank >= 1);
684 gint32 pos = ves_array_calculate_index (ao, sp, frame);
688 if (needs_typecheck && !mono_class_is_assignable_from (mono_object_class ((MonoObject *) ao)->element_class, required_type->element_class)) {
689 frame->ex = mono_get_exception_array_type_mismatch ();
690 FILL_IN_TRACE (frame->ex, frame);
693 gint32 esize = mono_array_element_size (ac);
694 return mono_array_addr_with_size (ao, esize, pos);
698 interp_walk_stack_with_ctx (MonoInternalStackWalk func, MonoContext *ctx, MonoUnwindOptions options, void *user_data)
701 ThreadContext *context = mono_native_tls_get_value (thread_context_id);
703 MonoInvocation *frame = context->current_frame;
706 MonoStackFrameInfo fi;
707 memset (&fi, 0, sizeof (MonoStackFrameInfo));
709 /* TODO: hack to make some asserts happy. */
710 fi.ji = (MonoJitInfo *) frame->runtime_method;
712 if (frame->runtime_method)
713 fi.method = fi.actual_method = frame->runtime_method->method;
715 if (!fi.method || (fi.method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) || (fi.method->iflags & (METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL | METHOD_IMPL_ATTRIBUTE_RUNTIME))) {
717 fi.type = FRAME_TYPE_MANAGED_TO_NATIVE;
719 MonoMethodHeader *hd = mono_method_get_header_checked (fi.method, &error);
720 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
721 fi.type = FRAME_TYPE_MANAGED;
722 fi.il_offset = frame->ip - (const unsigned short *) hd->code;
723 if (!fi.method->wrapper_type)
727 if (func (&fi, ctx, user_data))
729 frame = frame->parent;
733 static MonoPIFunc mono_interp_enter_icall_trampoline = NULL;
735 struct _MethodArguments {
744 typedef struct _MethodArguments MethodArguments;
746 // TODO: this function is also arch dependent (register width).
747 static MethodArguments* build_args_from_sig (MonoMethodSignature *sig, MonoInvocation *frame)
749 // TODO: don't malloc this data structure.
750 MethodArguments *margs = g_malloc0 (sizeof (MethodArguments));
755 for (int i = 0; i < sig->param_count; i++) {
756 guint32 ptype = sig->params [i]->byref ? MONO_TYPE_PTR : sig->params [i]->type;
758 case MONO_TYPE_BOOLEAN:
769 case MONO_TYPE_SZARRAY:
770 case MONO_TYPE_CLASS:
771 case MONO_TYPE_OBJECT:
772 case MONO_TYPE_STRING:
774 case MONO_TYPE_VALUETYPE:
775 case MONO_TYPE_GENERICINST:
783 g_error ("build_args_from_sig: not implemented yet (1): 0x%x\n", ptype);
788 margs->iargs = g_malloc0 (sizeof (gpointer) * margs->ilen);
791 margs->fargs = g_malloc0 (sizeof (double) * margs->flen);
793 if (margs->ilen > 12)
794 g_error ("build_args_from_sig: TODO, allocate gregs: %d\n", margs->ilen);
797 g_error ("build_args_from_sig: TODO, allocate fregs: %d\n", margs->flen);
804 margs->iargs [0] = frame->stack_args->data.p;
808 for (int i = 0; i < sig->param_count; i++) {
809 guint32 ptype = sig->params [i]->byref ? MONO_TYPE_PTR : sig->params [i]->type;
811 case MONO_TYPE_BOOLEAN:
822 case MONO_TYPE_SZARRAY:
823 case MONO_TYPE_CLASS:
824 case MONO_TYPE_OBJECT:
825 case MONO_TYPE_STRING:
827 case MONO_TYPE_VALUETYPE:
828 case MONO_TYPE_GENERICINST:
829 margs->iargs [int_i] = frame->stack_args [i].data.p;
831 g_print ("build_args_from_sig: margs->iargs [%d]: %p (frame @ %d)\n", int_i, margs->iargs [int_i], i);
837 if (ptype == MONO_TYPE_R4)
838 * (float *) &(margs->fargs [int_f]) = (float) frame->stack_args [i].data.f;
840 margs->fargs [int_f] = frame->stack_args [i].data.f;
842 g_print ("build_args_from_sig: margs->fargs [%d]: %p (%f) (frame @ %d)\n", int_f, margs->fargs [int_f], margs->fargs [int_f], i);
847 g_error ("build_args_from_sig: not implemented yet (2): 0x%x\n", ptype);
851 switch (sig->ret->type) {
852 case MONO_TYPE_BOOLEAN:
863 case MONO_TYPE_SZARRAY:
864 case MONO_TYPE_CLASS:
865 case MONO_TYPE_OBJECT:
866 case MONO_TYPE_STRING:
868 case MONO_TYPE_VALUETYPE:
869 case MONO_TYPE_GENERICINST:
870 margs->retval = &(frame->retval->data.p);
874 margs->retval = &(frame->retval->data.p);
875 margs->is_float_ret = 1;
878 margs->retval = NULL;
881 g_error ("build_args_from_sig: ret type not implemented yet: 0x%x\n", sig->ret->type);
888 ves_pinvoke_method (MonoInvocation *frame, MonoMethodSignature *sig, MonoFuncV addr, gboolean string_ctor, ThreadContext *context)
891 MonoInvocation *old_frame = context->current_frame;
892 MonoInvocation *old_env_frame = context->env_frame;
893 jmp_buf *old_env = context->current_env;
896 context->current_frame = old_frame;
897 context->env_frame = old_env_frame;
898 context->current_env = old_env;
899 context->managed_code = 1;
904 context->env_frame = frame;
905 context->current_env = &env;
907 g_assert (!frame->runtime_method);
908 if (!mono_interp_enter_icall_trampoline) {
910 mono_interp_enter_icall_trampoline = mono_arch_get_enter_icall_trampoline (&info);
912 // mono_tramp_info_register (info, NULL);
915 MethodArguments *margs = build_args_from_sig (sig, frame);
917 g_print ("ICALL: mono_interp_enter_icall_trampoline = %p, addr = %p\n", mono_interp_enter_icall_trampoline, addr);
918 g_print ("margs(out): ilen=%d, flen=%d\n", margs->ilen, margs->flen);
921 context->current_frame = frame;
922 context->managed_code = 0;
924 mono_interp_enter_icall_trampoline (addr, margs);
926 context->managed_code = 1;
927 /* domain can only be changed by native code */
928 context->domain = mono_domain_get ();
930 if (*mono_thread_interruption_request_flag ()) {
931 MonoException *exc = mono_thread_interruption_checkpoint ();
934 context->search_for_handler = 1;
938 if (!frame->ex && !MONO_TYPE_ISSTRUCT (sig->ret))
939 stackval_from_data (sig->ret, frame->retval, (char*)&frame->retval->data.p, sig->pinvoke);
941 context->current_frame = old_frame;
942 context->env_frame = old_env_frame;
943 context->current_env = old_env;
945 g_free (margs->iargs);
946 g_free (margs->fargs);
951 mono_interp_init_delegate (MonoDelegate *del)
955 /* shouldn't need a write barrier because we don't write a MonoObject into the field */
956 del->method = ((RuntimeMethod *) del->method_ptr)->method;
961 * runtime specifies that the implementation of the method is automatically
962 * provided by the runtime and is primarily used for the methods of delegates.
965 ves_runtime_method (MonoInvocation *frame, ThreadContext *context)
967 MonoMethod *method = frame->runtime_method->method;
968 const char *name = method->name;
969 MonoObject *obj = (MonoObject*) frame->stack_args->data.p;
970 MonoObject *isinst_obj;
973 mono_class_init (method->klass);
975 if (method->klass == mono_defaults.array_class) {
976 if (!strcmp (method->name, "UnsafeMov")) {
977 /* TODO: layout checks */
978 MonoType *mt = mono_method_signature (method)->ret;
979 stackval_from_data (mt, frame->retval, (char *) frame->stack_args, FALSE);
984 isinst_obj = mono_object_isinst_checked (obj, mono_defaults.array_class, &error);
985 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
986 if (obj && isinst_obj) {
987 if (*name == 'S' && (strcmp (name, "Set") == 0)) {
988 ves_array_set (frame);
991 if (*name == 'G' && (strcmp (name, "Get") == 0)) {
992 ves_array_get (frame);
997 g_error ("Don't know how to exec runtime method %s.%s::%s",
998 method->klass->name_space, method->klass->name,
1003 dump_stack (stackval *stack, stackval *sp)
1005 stackval *s = stack;
1006 GString *str = g_string_new ("");
1009 return g_string_free (str, FALSE);
1012 g_string_append_printf (str, "[%p (%lld)] ", s->data.l, s->data.l);
1015 return g_string_free (str, FALSE);
1019 dump_stackval (GString *str, stackval *s, MonoType *type)
1021 switch (type->type) {
1028 case MONO_TYPE_CHAR:
1029 case MONO_TYPE_BOOLEAN:
1030 g_string_append_printf (str, "[%d] ", s->data.i);
1032 case MONO_TYPE_STRING:
1033 case MONO_TYPE_SZARRAY:
1034 case MONO_TYPE_CLASS:
1035 case MONO_TYPE_OBJECT:
1036 case MONO_TYPE_ARRAY:
1040 g_string_append_printf (str, "[%p] ", s->data.p);
1042 case MONO_TYPE_VALUETYPE:
1043 if (type->data.klass->enumtype)
1044 g_string_append_printf (str, "[%d] ", s->data.i);
1046 g_string_append_printf (str, "[vt:%p] ", s->data.p);
1050 g_string_append_printf (str, "[%g] ", s->data.f);
1055 GString *res = g_string_new ("");
1056 mono_type_get_desc (res, type, TRUE);
1057 g_string_append_printf (str, "[{%s} %lld/0x%0llx] ", res->str, s->data.l, s->data.l);
1058 g_string_free (res, TRUE);
1065 dump_args (MonoInvocation *inv)
1067 GString *str = g_string_new ("");
1069 MonoMethodSignature *signature = mono_method_signature (inv->runtime_method->method);
1071 if (signature->param_count == 0 && !signature->hasthis)
1072 return g_string_free (str, FALSE);
1074 if (signature->hasthis) {
1075 MonoMethod *method = inv->runtime_method->method;
1076 dump_stackval (str, inv->stack_args, &method->klass->byval_arg);
1079 for (i = 0; i < signature->param_count; ++i)
1080 dump_stackval (str, inv->stack_args + (!!signature->hasthis) + i, signature->params [i]);
1082 return g_string_free (str, FALSE);
1086 dump_retval (MonoInvocation *inv)
1088 GString *str = g_string_new ("");
1089 MonoType *ret = mono_method_signature (inv->runtime_method->method)->ret;
1091 if (ret->type != MONO_TYPE_VOID)
1092 dump_stackval (str, inv->retval, ret);
1094 return g_string_free (str, FALSE);
1098 dump_frame (MonoInvocation *inv)
1100 GString *str = g_string_new ("");
1105 for (i = 0; inv; inv = inv->parent) {
1106 if (inv->runtime_method != NULL) {
1107 MonoMethod *method = inv->runtime_method->method;
1111 const char * opname = "";
1113 gchar *source = NULL;
1117 if ((method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) == 0 &&
1118 (method->iflags & METHOD_IMPL_ATTRIBUTE_RUNTIME) == 0) {
1119 MonoMethodHeader *hd = mono_method_get_header_checked (method, &error);
1120 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
1124 opname = mono_interp_opname [*inv->ip];
1125 codep = inv->ip - inv->runtime_method->code;
1126 source = g_strdup_printf ("%s:%d // (TODO: proper stacktrace)", method->name, codep);
1131 MonoDebugSourceLocation *minfo = mono_debug_lookup_method (method);
1132 source = mono_debug_method_lookup_location (minfo, codep);
1136 args = dump_args (inv);
1137 name = mono_method_full_name (method, TRUE);
1139 g_string_append_printf (str, "#%d: 0x%05x %-10s in %s (%s) at %s\n", i, codep, opname, name, args, source);
1141 g_string_append_printf (str, "#%d: 0x%05x %-10s in %s (%s)\n", i, codep, opname, name, args);
1148 return g_string_free (str, FALSE);
1152 get_trace_ips (MonoDomain *domain, MonoInvocation *top)
1156 MonoInvocation *inv;
1159 for (i = 0, inv = top; inv; inv = inv->parent)
1160 if (inv->runtime_method != NULL)
1163 res = mono_array_new_checked (domain, mono_defaults.int_class, 2 * i, &error);
1164 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
1166 for (i = 0, inv = top; inv; inv = inv->parent)
1167 if (inv->runtime_method != NULL) {
1168 mono_array_set (res, gpointer, i, inv->runtime_method);
1170 mono_array_set (res, gpointer, i, (gpointer)inv->ip);
1178 #define MYGUINT64_MAX 18446744073709551615ULL
1179 #define MYGINT64_MAX 9223372036854775807LL
1180 #define MYGINT64_MIN (-MYGINT64_MAX -1LL)
1182 #define MYGUINT32_MAX 4294967295U
1183 #define MYGINT32_MAX 2147483647
1184 #define MYGINT32_MIN (-MYGINT32_MAX -1)
1186 #define CHECK_ADD_OVERFLOW(a,b) \
1187 (gint32)(b) >= 0 ? (gint32)(MYGINT32_MAX) - (gint32)(b) < (gint32)(a) ? -1 : 0 \
1188 : (gint32)(MYGINT32_MIN) - (gint32)(b) > (gint32)(a) ? +1 : 0
1190 #define CHECK_SUB_OVERFLOW(a,b) \
1191 (gint32)(b) < 0 ? (gint32)(MYGINT32_MAX) + (gint32)(b) < (gint32)(a) ? -1 : 0 \
1192 : (gint32)(MYGINT32_MIN) + (gint32)(b) > (gint32)(a) ? +1 : 0
1194 #define CHECK_ADD_OVERFLOW_UN(a,b) \
1195 (guint32)(MYGUINT32_MAX) - (guint32)(b) < (guint32)(a) ? -1 : 0
1197 #define CHECK_SUB_OVERFLOW_UN(a,b) \
1198 (guint32)(a) < (guint32)(b) ? -1 : 0
1200 #define CHECK_ADD_OVERFLOW64(a,b) \
1201 (gint64)(b) >= 0 ? (gint64)(MYGINT64_MAX) - (gint64)(b) < (gint64)(a) ? -1 : 0 \
1202 : (gint64)(MYGINT64_MIN) - (gint64)(b) > (gint64)(a) ? +1 : 0
1204 #define CHECK_SUB_OVERFLOW64(a,b) \
1205 (gint64)(b) < 0 ? (gint64)(MYGINT64_MAX) + (gint64)(b) < (gint64)(a) ? -1 : 0 \
1206 : (gint64)(MYGINT64_MIN) + (gint64)(b) > (gint64)(a) ? +1 : 0
1208 #define CHECK_ADD_OVERFLOW64_UN(a,b) \
1209 (guint64)(MYGUINT64_MAX) - (guint64)(b) < (guint64)(a) ? -1 : 0
1211 #define CHECK_SUB_OVERFLOW64_UN(a,b) \
1212 (guint64)(a) < (guint64)(b) ? -1 : 0
1214 #if SIZEOF_VOID_P == 4
1215 #define CHECK_ADD_OVERFLOW_NAT(a,b) CHECK_ADD_OVERFLOW(a,b)
1216 #define CHECK_ADD_OVERFLOW_NAT_UN(a,b) CHECK_ADD_OVERFLOW_UN(a,b)
1218 #define CHECK_ADD_OVERFLOW_NAT(a,b) CHECK_ADD_OVERFLOW64(a,b)
1219 #define CHECK_ADD_OVERFLOW_NAT_UN(a,b) CHECK_ADD_OVERFLOW64_UN(a,b)
1222 /* Resolves to TRUE if the operands would overflow */
1223 #define CHECK_MUL_OVERFLOW(a,b) \
1224 ((gint32)(a) == 0) || ((gint32)(b) == 0) ? 0 : \
1225 (((gint32)(a) > 0) && ((gint32)(b) == -1)) ? FALSE : \
1226 (((gint32)(a) < 0) && ((gint32)(b) == -1)) ? (a == - MYGINT32_MAX) : \
1227 (((gint32)(a) > 0) && ((gint32)(b) > 0)) ? (gint32)(a) > ((MYGINT32_MAX) / (gint32)(b)) : \
1228 (((gint32)(a) > 0) && ((gint32)(b) < 0)) ? (gint32)(a) > ((MYGINT32_MIN) / (gint32)(b)) : \
1229 (((gint32)(a) < 0) && ((gint32)(b) > 0)) ? (gint32)(a) < ((MYGINT32_MIN) / (gint32)(b)) : \
1230 (gint32)(a) < ((MYGINT32_MAX) / (gint32)(b))
1232 #define CHECK_MUL_OVERFLOW_UN(a,b) \
1233 ((guint32)(a) == 0) || ((guint32)(b) == 0) ? 0 : \
1234 (guint32)(b) > ((MYGUINT32_MAX) / (guint32)(a))
1236 #define CHECK_MUL_OVERFLOW64(a,b) \
1237 ((gint64)(a) == 0) || ((gint64)(b) == 0) ? 0 : \
1238 (((gint64)(a) > 0) && ((gint64)(b) == -1)) ? FALSE : \
1239 (((gint64)(a) < 0) && ((gint64)(b) == -1)) ? (a == - MYGINT64_MAX) : \
1240 (((gint64)(a) > 0) && ((gint64)(b) > 0)) ? (gint64)(a) > ((MYGINT64_MAX) / (gint64)(b)) : \
1241 (((gint64)(a) > 0) && ((gint64)(b) < 0)) ? (gint64)(a) > ((MYGINT64_MIN) / (gint64)(b)) : \
1242 (((gint64)(a) < 0) && ((gint64)(b) > 0)) ? (gint64)(a) < ((MYGINT64_MIN) / (gint64)(b)) : \
1243 (gint64)(a) < ((MYGINT64_MAX) / (gint64)(b))
1245 #define CHECK_MUL_OVERFLOW64_UN(a,b) \
1246 ((guint64)(a) == 0) || ((guint64)(b) == 0) ? 0 : \
1247 (guint64)(b) > ((MYGUINT64_MAX) / (guint64)(a))
1249 #if SIZEOF_VOID_P == 4
1250 #define CHECK_MUL_OVERFLOW_NAT(a,b) CHECK_MUL_OVERFLOW(a,b)
1251 #define CHECK_MUL_OVERFLOW_NAT_UN(a,b) CHECK_MUL_OVERFLOW_UN(a,b)
1253 #define CHECK_MUL_OVERFLOW_NAT(a,b) CHECK_MUL_OVERFLOW64(a,b)
1254 #define CHECK_MUL_OVERFLOW_NAT_UN(a,b) CHECK_MUL_OVERFLOW64_UN(a,b)
1258 mono_interp_runtime_invoke (MonoMethod *method, void *obj, void **params, MonoObject **exc, MonoError *error)
1260 MonoInvocation frame;
1261 ThreadContext * volatile context = mono_native_tls_get_value (thread_context_id);
1262 MonoObject *retval = NULL;
1263 MonoMethodSignature *sig = mono_method_signature (method);
1264 MonoClass *klass = mono_class_from_mono_type (sig->ret);
1265 int i, type, isobject = 0;
1268 stackval *args = alloca (sizeof (stackval) * (sig->param_count + !!sig->hasthis));
1269 ThreadContext context_struct;
1270 MonoInvocation *old_frame = NULL;
1280 if (context != &context_struct) {
1281 context->domain = mono_domain_get ();
1282 context->current_frame = old_frame;
1283 context->managed_code = 0;
1285 mono_native_tls_set_value (thread_context_id, NULL);
1287 *exc = (MonoObject *)frame.ex;
1291 if (context == NULL) {
1292 context = &context_struct;
1293 context_struct.base_frame = &frame;
1294 context_struct.current_frame = NULL;
1295 context_struct.env_frame = &frame;
1296 context_struct.current_env = &env;
1297 context_struct.search_for_handler = 0;
1298 context_struct.managed_code = 0;
1299 mono_native_tls_set_value (thread_context_id, context);
1302 old_frame = context->current_frame;
1304 context->domain = mono_domain_get ();
1306 switch (sig->ret->type) {
1307 case MONO_TYPE_VOID:
1309 case MONO_TYPE_STRING:
1310 case MONO_TYPE_OBJECT:
1311 case MONO_TYPE_CLASS:
1312 case MONO_TYPE_ARRAY:
1313 case MONO_TYPE_SZARRAY:
1316 case MONO_TYPE_VALUETYPE:
1317 retval = mono_object_new_checked (context->domain, klass, error);
1318 ret = mono_object_unbox (retval);
1319 if (!sig->ret->data.klass->enumtype)
1320 result.data.vt = ret;
1322 result.data.vt = alloca (mono_class_instance_size (klass));
1324 case MONO_TYPE_GENERICINST:
1325 if (!MONO_TYPE_IS_REFERENCE (sig->ret)) {
1326 retval = mono_object_new_checked (context->domain, klass, error);
1327 ret = mono_object_unbox (retval);
1328 if (!sig->ret->data.klass->enumtype)
1329 result.data.vt = ret;
1331 result.data.vt = alloca (mono_class_instance_size (klass));
1338 retval = mono_object_new_checked (context->domain, mono_defaults.int_class, error);
1339 ret = mono_object_unbox (retval);
1342 retval = mono_object_new_checked (context->domain, klass, error);
1343 ret = mono_object_unbox (retval);
1348 args [0].data.p = obj;
1350 for (i = 0; i < sig->param_count; ++i) {
1351 int a_index = i + !!sig->hasthis;
1352 if (sig->params [i]->byref) {
1353 args [a_index].data.p = params [i];
1356 type = sig->params [i]->type;
1361 case MONO_TYPE_BOOLEAN:
1362 args [a_index].data.i = *(MonoBoolean*)params [i];
1366 case MONO_TYPE_CHAR:
1367 args [a_index].data.i = *(gint16*)params [i];
1369 #if SIZEOF_VOID_P == 4
1370 case MONO_TYPE_U: /* use VAL_POINTER? */
1375 args [a_index].data.i = *(gint32*)params [i];
1377 #if SIZEOF_VOID_P == 8
1383 args [a_index].data.l = *(gint64*)params [i];
1386 args [a_index].data.f = *(gfloat *) params [i];
1389 args [a_index].data.f = *(gdouble *) params [i];
1391 case MONO_TYPE_VALUETYPE:
1392 if (sig->params [i]->data.klass->enumtype) {
1393 type = mono_class_enum_basetype (sig->params [i]->data.klass)->type;
1396 args [a_index].data.p = params [i];
1399 case MONO_TYPE_STRING:
1401 case MONO_TYPE_CLASS:
1402 case MONO_TYPE_ARRAY:
1403 case MONO_TYPE_SZARRAY:
1404 case MONO_TYPE_OBJECT:
1405 case MONO_TYPE_GENERICINST:
1406 args [a_index].data.p = params [i];
1409 g_error ("type 0x%x not handled in runtime invoke", sig->params [i]->type);
1413 if (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL)
1414 method = mono_marshal_get_native_wrapper (method, FALSE, FALSE);
1415 INIT_FRAME (&frame,context->current_frame,args,&result,mono_get_root_domain (),method,error);
1417 frame.invoke_trap = 1;
1418 context->managed_code = 1;
1419 ves_exec_method_with_context (&frame, context);
1420 context->managed_code = 0;
1421 if (context == &context_struct)
1422 mono_native_tls_set_value (thread_context_id, NULL);
1424 context->current_frame = old_frame;
1425 if (frame.ex != NULL) {
1427 *exc = (MonoObject*) frame.ex;
1430 if (context->current_env != NULL) {
1431 context->env_frame->ex = frame.ex;
1432 longjmp(*context->current_env, 1);
1435 printf("dropped exception...\n");
1437 if (sig->ret->type == MONO_TYPE_VOID && !method->string_ctor)
1439 if (isobject || method->string_ctor)
1440 return result.data.p;
1441 stackval_to_data (sig->ret, &result, ret, sig->pinvoke);
1446 RuntimeMethod *rmethod;
1450 gpointer *many_args;
1453 /* Main function for entering the interpreter from compiled code */
1455 interp_entry (InterpEntryData *data)
1457 MonoInvocation frame;
1458 RuntimeMethod *rmethod = data->rmethod;
1459 ThreadContext *context = mono_native_tls_get_value (thread_context_id);
1460 ThreadContext context_struct;
1461 MonoInvocation *old_frame;
1465 MonoMethodSignature *sig;
1469 method = rmethod->method;
1470 sig = mono_method_signature (method);
1472 // FIXME: Optimize this
1474 //printf ("%s\n", mono_method_full_name (method, 1));
1477 if (context == NULL) {
1478 context = &context_struct;
1479 memset (context, 0, sizeof (ThreadContext));
1480 context_struct.base_frame = &frame;
1481 context_struct.env_frame = &frame;
1482 mono_native_tls_set_value (thread_context_id, context);
1485 old_frame = context->current_frame;
1486 context->domain = mono_domain_get ();
1488 args = alloca (sizeof (stackval) * (sig->param_count + (sig->hasthis ? 1 : 0)));
1490 args [0].data.p = data->this_arg;
1493 if (data->many_args)
1494 params = data->many_args;
1496 params = data->args;
1497 for (i = 0; i < sig->param_count; ++i) {
1498 int a_index = i + (sig->hasthis ? 1 : 0);
1499 if (sig->params [i]->byref) {
1500 args [a_index].data.p = params [i];
1503 type = rmethod->param_types [i];
1504 switch (type->type) {
1507 args [a_index].data.i = *(MonoBoolean*)params [i];
1511 args [a_index].data.i = *(gint16*)params [i];
1514 #if SIZEOF_VOID_P == 4
1515 args [a_index].data.p = GINT_TO_POINTER (*(guint32*)params [i]);
1517 args [a_index].data.p = GINT_TO_POINTER (*(guint64*)params [i]);
1521 #if SIZEOF_VOID_P == 4
1522 args [a_index].data.p = GINT_TO_POINTER (*(gint32*)params [i]);
1524 args [a_index].data.p = GINT_TO_POINTER (*(gint64*)params [i]);
1528 args [a_index].data.i = *(guint32*)params [i];
1531 args [a_index].data.i = *(gint32*)params [i];
1534 args [a_index].data.l = *(guint64*)params [i];
1537 args [a_index].data.l = *(gint64*)params [i];
1540 case MONO_TYPE_OBJECT:
1541 args [a_index].data.p = *(MonoObject**)params [i];
1543 case MONO_TYPE_VALUETYPE:
1544 args [a_index].data.p = params [i];
1546 case MONO_TYPE_GENERICINST:
1547 if (MONO_TYPE_IS_REFERENCE (type))
1548 args [a_index].data.p = params [i];
1550 args [a_index].data.vt = params [i];
1553 printf ("%s\n", mono_type_full_name (sig->params [i]));
1559 init_frame (&frame, context->current_frame, data->rmethod, args, &result);
1560 context->managed_code = 1;
1562 type = rmethod->rtype;
1563 switch (type->type) {
1564 case MONO_TYPE_GENERICINST:
1565 if (!MONO_TYPE_IS_REFERENCE (type))
1566 frame.retval->data.vt = data->res;
1568 case MONO_TYPE_VALUETYPE:
1569 frame.retval->data.vt = data->res;
1575 ves_exec_method_with_context (&frame, context);
1576 context->managed_code = 0;
1577 if (context == &context_struct)
1578 mono_native_tls_set_value (thread_context_id, NULL);
1580 context->current_frame = old_frame;
1583 g_assert (frame.ex == NULL);
1585 type = rmethod->rtype;
1586 switch (type->type) {
1587 case MONO_TYPE_VOID:
1590 *(gint8*)data->res = frame.retval->data.i;
1593 *(guint8*)data->res = frame.retval->data.i;
1596 *(gint16*)data->res = frame.retval->data.i;
1599 *(guint16*)data->res = frame.retval->data.i;
1602 *(gint32*)data->res = frame.retval->data.i;
1605 *(guint64*)data->res = frame.retval->data.i;
1608 *(gint64*)data->res = frame.retval->data.i;
1611 *(guint64*)data->res = frame.retval->data.i;
1614 #if SIZEOF_VOID_P == 8
1615 *(gint64*)data->res = (gint64)frame.retval->data.p;
1617 *(gint32*)data->res = (gint32)frame.retval->data.p;
1621 #if SIZEOF_VOID_P == 8
1622 *(guint64*)data->res = (guint64)frame.retval->data.p;
1624 *(guint32*)data->res = (guint32)frame.retval->data.p;
1627 case MONO_TYPE_OBJECT:
1628 /* No need for a write barrier */
1629 *(MonoObject**)data->res = (MonoObject*)frame.retval->data.p;
1631 case MONO_TYPE_GENERICINST:
1632 if (MONO_TYPE_IS_REFERENCE (type)) {
1633 *(MonoObject**)data->res = *(MonoObject**)frame.retval->data.p;
1635 /* Already set before the call */
1638 case MONO_TYPE_VALUETYPE:
1639 /* Already set before the call */
1642 printf ("%s\n", mono_type_full_name (sig->ret));
1649 do_icall (ThreadContext *context, int op, stackval *sp, gpointer ptr)
1651 MonoInvocation *old_frame = context->current_frame;
1652 MonoInvocation *old_env_frame = context->env_frame;
1653 jmp_buf *old_env = context->current_env;
1657 context->current_frame = old_frame;
1658 context->env_frame = old_env_frame;
1659 context->current_env = old_env;
1660 context->managed_code = 1;
1664 context->env_frame = context->current_frame;
1665 context->current_env = &env;
1666 context->managed_code = 0;
1669 case MINT_ICALL_V_V: {
1670 void (*func)() = ptr;
1674 case MINT_ICALL_V_P: {
1675 gpointer (*func)() = ptr;
1677 sp [-1].data.p = func ();
1680 case MINT_ICALL_P_V: {
1681 void (*func)(gpointer) = ptr;
1682 func (sp [-1].data.p);
1686 case MINT_ICALL_P_P: {
1687 gpointer (*func)(gpointer) = ptr;
1688 sp [-1].data.p = func (sp [-1].data.p);
1691 case MINT_ICALL_PP_V: {
1692 void (*func)(gpointer,gpointer) = ptr;
1694 func (sp [0].data.p, sp [1].data.p);
1697 case MINT_ICALL_PI_V: {
1698 void (*func)(gpointer,int) = ptr;
1700 func (sp [0].data.p, sp [1].data.i);
1703 case MINT_ICALL_PP_P: {
1704 gpointer (*func)(gpointer,gpointer) = ptr;
1706 sp [-1].data.p = func (sp [-1].data.p, sp [0].data.p);
1709 case MINT_ICALL_PI_P: {
1710 gpointer (*func)(gpointer,int) = ptr;
1712 sp [-1].data.p = func (sp [-1].data.p, sp [0].data.i);
1715 case MINT_ICALL_PPP_V: {
1716 void (*func)(gpointer,gpointer,gpointer) = ptr;
1718 func (sp [0].data.p, sp [1].data.p, sp [2].data.p);
1721 case MINT_ICALL_PPI_V: {
1722 void (*func)(gpointer,gpointer,int) = ptr;
1724 func (sp [0].data.p, sp [1].data.p, sp [2].data.i);
1728 g_assert_not_reached ();
1731 context->env_frame = old_env_frame;
1732 context->current_env = old_env;
1738 * These functions are the entry points into the interpreter from compiled code.
1739 * They are called by the interp_in wrappers. They have the following signature:
1740 * void (<optional this_arg>, <optional retval pointer>, <arg1>, ..., <argn>, <method ptr>)
1741 * They pack up their arguments into an InterpEntryData structure and call interp_entry ().
1742 * It would be possible for the wrappers to pack up the arguments etc, but that would make them bigger, and there are
1743 * more wrappers then these functions.
1744 * this/static * ret/void * 16 arguments -> 64 functions.
1747 #define MAX_INTERP_ENTRY_ARGS 8
1749 #define INTERP_ENTRY_BASE(_method, _this_arg, _res) \
1750 InterpEntryData data; \
1751 (data).rmethod = (_method); \
1752 (data).res = (_res); \
1753 (data).this_arg = (_this_arg); \
1754 (data).many_args = NULL;
1756 #define INTERP_ENTRY0(_this_arg, _res, _method) { \
1757 INTERP_ENTRY_BASE (_method, _this_arg, _res); \
1758 interp_entry (&data); \
1760 #define INTERP_ENTRY1(_this_arg, _res, _method) { \
1761 INTERP_ENTRY_BASE (_method, _this_arg, _res); \
1762 (data).args [0] = arg1; \
1763 interp_entry (&data); \
1765 #define INTERP_ENTRY2(_this_arg, _res, _method) { \
1766 INTERP_ENTRY_BASE (_method, _this_arg, _res); \
1767 (data).args [0] = arg1; \
1768 (data).args [1] = arg2; \
1769 interp_entry (&data); \
1771 #define INTERP_ENTRY3(_this_arg, _res, _method) { \
1772 INTERP_ENTRY_BASE (_method, _this_arg, _res); \
1773 (data).args [0] = arg1; \
1774 (data).args [1] = arg2; \
1775 (data).args [2] = arg3; \
1776 interp_entry (&data); \
1778 #define INTERP_ENTRY4(_this_arg, _res, _method) { \
1779 INTERP_ENTRY_BASE (_method, _this_arg, _res); \
1780 (data).args [0] = arg1; \
1781 (data).args [1] = arg2; \
1782 (data).args [2] = arg3; \
1783 (data).args [3] = arg4; \
1784 interp_entry (&data); \
1786 #define INTERP_ENTRY5(_this_arg, _res, _method) { \
1787 INTERP_ENTRY_BASE (_method, _this_arg, _res); \
1788 (data).args [0] = arg1; \
1789 (data).args [1] = arg2; \
1790 (data).args [2] = arg3; \
1791 (data).args [3] = arg4; \
1792 (data).args [4] = arg5; \
1793 interp_entry (&data); \
1795 #define INTERP_ENTRY6(_this_arg, _res, _method) { \
1796 INTERP_ENTRY_BASE (_method, _this_arg, _res); \
1797 (data).args [0] = arg1; \
1798 (data).args [1] = arg2; \
1799 (data).args [2] = arg3; \
1800 (data).args [3] = arg4; \
1801 (data).args [4] = arg5; \
1802 (data).args [5] = arg6; \
1803 interp_entry (&data); \
1805 #define INTERP_ENTRY7(_this_arg, _res, _method) { \
1806 INTERP_ENTRY_BASE (_method, _this_arg, _res); \
1807 (data).args [0] = arg1; \
1808 (data).args [1] = arg2; \
1809 (data).args [2] = arg3; \
1810 (data).args [3] = arg4; \
1811 (data).args [4] = arg5; \
1812 (data).args [5] = arg6; \
1813 (data).args [6] = arg7; \
1814 interp_entry (&data); \
1816 #define INTERP_ENTRY8(_this_arg, _res, _method) { \
1817 INTERP_ENTRY_BASE (_method, _this_arg, _res); \
1818 (data).args [0] = arg1; \
1819 (data).args [1] = arg2; \
1820 (data).args [2] = arg3; \
1821 (data).args [3] = arg4; \
1822 (data).args [4] = arg5; \
1823 (data).args [5] = arg6; \
1824 (data).args [6] = arg7; \
1825 (data).args [7] = arg8; \
1826 interp_entry (&data); \
1829 #define ARGLIST0 RuntimeMethod *rmethod
1830 #define ARGLIST1 gpointer arg1, RuntimeMethod *rmethod
1831 #define ARGLIST2 gpointer arg1, gpointer arg2, RuntimeMethod *rmethod
1832 #define ARGLIST3 gpointer arg1, gpointer arg2, gpointer arg3, RuntimeMethod *rmethod
1833 #define ARGLIST4 gpointer arg1, gpointer arg2, gpointer arg3, gpointer arg4, RuntimeMethod *rmethod
1834 #define ARGLIST5 gpointer arg1, gpointer arg2, gpointer arg3, gpointer arg4, gpointer arg5, RuntimeMethod *rmethod
1835 #define ARGLIST6 gpointer arg1, gpointer arg2, gpointer arg3, gpointer arg4, gpointer arg5, gpointer arg6, RuntimeMethod *rmethod
1836 #define ARGLIST7 gpointer arg1, gpointer arg2, gpointer arg3, gpointer arg4, gpointer arg5, gpointer arg6, gpointer arg7, RuntimeMethod *rmethod
1837 #define ARGLIST8 gpointer arg1, gpointer arg2, gpointer arg3, gpointer arg4, gpointer arg5, gpointer arg6, gpointer arg7, gpointer arg8, RuntimeMethod *rmethod
1839 static void interp_entry_static_0 (ARGLIST0) INTERP_ENTRY0 (NULL, NULL, rmethod)
1840 static void interp_entry_static_1 (ARGLIST1) INTERP_ENTRY1 (NULL, NULL, rmethod)
1841 static void interp_entry_static_2 (ARGLIST2) INTERP_ENTRY2 (NULL, NULL, rmethod)
1842 static void interp_entry_static_3 (ARGLIST3) INTERP_ENTRY3 (NULL, NULL, rmethod)
1843 static void interp_entry_static_4 (ARGLIST4) INTERP_ENTRY4 (NULL, NULL, rmethod)
1844 static void interp_entry_static_5 (ARGLIST5) INTERP_ENTRY5 (NULL, NULL, rmethod)
1845 static void interp_entry_static_6 (ARGLIST6) INTERP_ENTRY6 (NULL, NULL, rmethod)
1846 static void interp_entry_static_7 (ARGLIST7) INTERP_ENTRY7 (NULL, NULL, rmethod)
1847 static void interp_entry_static_8 (ARGLIST8) INTERP_ENTRY8 (NULL, NULL, rmethod)
1848 static void interp_entry_static_ret_0 (gpointer res, ARGLIST0) INTERP_ENTRY0 (NULL, res, rmethod)
1849 static void interp_entry_static_ret_1 (gpointer res, ARGLIST1) INTERP_ENTRY1 (NULL, res, rmethod)
1850 static void interp_entry_static_ret_2 (gpointer res, ARGLIST2) INTERP_ENTRY2 (NULL, res, rmethod)
1851 static void interp_entry_static_ret_3 (gpointer res, ARGLIST3) INTERP_ENTRY3 (NULL, res, rmethod)
1852 static void interp_entry_static_ret_4 (gpointer res, ARGLIST4) INTERP_ENTRY4 (NULL, res, rmethod)
1853 static void interp_entry_static_ret_5 (gpointer res, ARGLIST5) INTERP_ENTRY5 (NULL, res, rmethod)
1854 static void interp_entry_static_ret_6 (gpointer res, ARGLIST6) INTERP_ENTRY6 (NULL, res, rmethod)
1855 static void interp_entry_static_ret_7 (gpointer res, ARGLIST7) INTERP_ENTRY7 (NULL, res, rmethod)
1856 static void interp_entry_static_ret_8 (gpointer res, ARGLIST8) INTERP_ENTRY8 (NULL, res, rmethod)
1857 static void interp_entry_instance_0 (gpointer this_arg, ARGLIST0) INTERP_ENTRY0 (this_arg, NULL, rmethod)
1858 static void interp_entry_instance_1 (gpointer this_arg, ARGLIST1) INTERP_ENTRY1 (this_arg, NULL, rmethod)
1859 static void interp_entry_instance_2 (gpointer this_arg, ARGLIST2) INTERP_ENTRY2 (this_arg, NULL, rmethod)
1860 static void interp_entry_instance_3 (gpointer this_arg, ARGLIST3) INTERP_ENTRY3 (this_arg, NULL, rmethod)
1861 static void interp_entry_instance_4 (gpointer this_arg, ARGLIST4) INTERP_ENTRY4 (this_arg, NULL, rmethod)
1862 static void interp_entry_instance_5 (gpointer this_arg, ARGLIST5) INTERP_ENTRY5 (this_arg, NULL, rmethod)
1863 static void interp_entry_instance_6 (gpointer this_arg, ARGLIST6) INTERP_ENTRY6 (this_arg, NULL, rmethod)
1864 static void interp_entry_instance_7 (gpointer this_arg, ARGLIST7) INTERP_ENTRY7 (this_arg, NULL, rmethod)
1865 static void interp_entry_instance_8 (gpointer this_arg, ARGLIST8) INTERP_ENTRY8 (this_arg, NULL, rmethod)
1866 static void interp_entry_instance_ret_0 (gpointer this_arg, gpointer res, ARGLIST0) INTERP_ENTRY0 (this_arg, res, rmethod)
1867 static void interp_entry_instance_ret_1 (gpointer this_arg, gpointer res, ARGLIST1) INTERP_ENTRY1 (this_arg, res, rmethod)
1868 static void interp_entry_instance_ret_2 (gpointer this_arg, gpointer res, ARGLIST2) INTERP_ENTRY2 (this_arg, res, rmethod)
1869 static void interp_entry_instance_ret_3 (gpointer this_arg, gpointer res, ARGLIST3) INTERP_ENTRY3 (this_arg, res, rmethod)
1870 static void interp_entry_instance_ret_4 (gpointer this_arg, gpointer res, ARGLIST4) INTERP_ENTRY4 (this_arg, res, rmethod)
1871 static void interp_entry_instance_ret_5 (gpointer this_arg, gpointer res, ARGLIST5) INTERP_ENTRY5 (this_arg, res, rmethod)
1872 static void interp_entry_instance_ret_6 (gpointer this_arg, gpointer res, ARGLIST6) INTERP_ENTRY6 (this_arg, res, rmethod)
1873 static void interp_entry_instance_ret_7 (gpointer this_arg, gpointer res, ARGLIST7) INTERP_ENTRY6 (this_arg, res, rmethod)
1874 static void interp_entry_instance_ret_8 (gpointer this_arg, gpointer res, ARGLIST8) INTERP_ENTRY6 (this_arg, res, rmethod)
1876 #define INTERP_ENTRY_FUNCLIST(type) interp_entry_ ## type ## _0, interp_entry_ ## type ## _1, interp_entry_ ## type ## _2, interp_entry_ ## type ## _3, interp_entry_ ## type ## _4, interp_entry_ ## type ## _5, interp_entry_ ## type ## _6, interp_entry_ ## type ## _7, interp_entry_ ## type ## _8
1878 gpointer entry_funcs_static [MAX_INTERP_ENTRY_ARGS + 1] = { INTERP_ENTRY_FUNCLIST (static) };
1879 gpointer entry_funcs_static_ret [MAX_INTERP_ENTRY_ARGS + 1] = { INTERP_ENTRY_FUNCLIST (static_ret) };
1880 gpointer entry_funcs_instance [MAX_INTERP_ENTRY_ARGS + 1] = { INTERP_ENTRY_FUNCLIST (instance) };
1881 gpointer entry_funcs_instance_ret [MAX_INTERP_ENTRY_ARGS + 1] = { INTERP_ENTRY_FUNCLIST (instance_ret) };
1883 /* General version for methods with more than MAX_INTERP_ENTRY_ARGS arguments */
1885 interp_entry_general (gpointer this_arg, gpointer res, gpointer *args, gpointer rmethod)
1887 INTERP_ENTRY_BASE (rmethod, this_arg, res);
1888 data.many_args = args;
1889 interp_entry (&data);
1893 * mono_interp_create_method_pointer:
1895 * Return a function pointer which can be used to call METHOD using the
1896 * interpreter. Return NULL for methods which are not supported.
1899 mono_interp_create_method_pointer (MonoMethod *method, MonoError *error)
1902 MonoMethodSignature *sig = mono_method_signature (method);
1903 MonoMethod *wrapper;
1904 RuntimeMethod *rmethod;
1906 if (method->wrapper_type && method->wrapper_type != MONO_WRAPPER_RUNTIME_INVOKE)
1909 rmethod = mono_interp_get_runtime_method (mono_domain_get (), method, error);
1910 if (rmethod->jit_entry)
1911 return rmethod->jit_entry;
1912 wrapper = mini_get_interp_in_wrapper (sig);
1914 gpointer jit_wrapper = mono_jit_compile_method_jit_only (wrapper, error);
1915 mono_error_assert_ok (error);
1917 //printf ("%s %s\n", mono_method_full_name (method, 1), mono_method_full_name (wrapper, 1));
1918 gpointer entry_func;
1919 if (sig->param_count > MAX_INTERP_ENTRY_ARGS) {
1920 entry_func = interp_entry_general;
1921 } else if (sig->hasthis) {
1922 if (sig->ret->type == MONO_TYPE_VOID)
1923 entry_func = entry_funcs_instance [sig->param_count];
1925 entry_func = entry_funcs_instance_ret [sig->param_count];
1927 if (sig->ret->type == MONO_TYPE_VOID)
1928 entry_func = entry_funcs_static [sig->param_count];
1930 entry_func = entry_funcs_static_ret [sig->param_count];
1932 g_assert (entry_func);
1934 /* This is the argument passed to the interp_in wrapper by the static rgctx trampoline */
1935 MonoFtnDesc *ftndesc = g_new0 (MonoFtnDesc, 1);
1936 ftndesc->addr = entry_func;
1937 ftndesc->arg = rmethod;
1938 mono_error_assert_ok (error);
1941 * The wrapper is called by compiled code, which doesn't pass the extra argument, so we pass it in the
1942 * rgctx register using a trampoline.
1946 g_assert (!mono_aot_only);
1947 addr = mono_arch_get_static_rgctx_trampoline (ftndesc, jit_wrapper);
1949 mono_memory_barrier ();
1950 rmethod->jit_entry = addr;
1956 static int opcode_counts[512];
1958 #define COUNT_OP(op) opcode_counts[op]++
1960 #define COUNT_OP(op)
1964 #define DUMP_INSTR() \
1965 if (tracing > 1) { \
1967 if (sp > frame->stack) { \
1968 ins = dump_stack (frame->stack, sp); \
1970 ins = g_strdup (""); \
1974 char *mn = mono_method_full_name (frame->runtime_method->method, FALSE); \
1975 g_print ("(%p) %s -> ", mono_thread_internal_current (), mn); \
1977 mono_interp_dis_mintop(rtm->code, ip); \
1978 g_print ("\t%d:%s\n", vt_sp - vtalloc, ins); \
1982 #define DUMP_INSTR()
1986 #define USE_COMPUTED_GOTO 1
1988 #if USE_COMPUTED_GOTO
1989 #define MINT_IN_SWITCH(op) COUNT_OP(op); goto *in_labels[op];
1990 #define MINT_IN_CASE(x) LAB_ ## x:
1992 #define MINT_IN_BREAK if (tracing > 1) goto main_loop; else { COUNT_OP(*ip); goto *in_labels[*ip]; }
1994 #define MINT_IN_BREAK { COUNT_OP(*ip); goto *in_labels[*ip]; }
1996 #define MINT_IN_DEFAULT mint_default: if (0) goto mint_default; /* make gcc shut up */
1998 #define MINT_IN_SWITCH(op) switch (op)
1999 #define MINT_IN_CASE(x) case x:
2000 #define MINT_IN_BREAK break
2001 #define MINT_IN_DEFAULT default:
2005 ves_exec_method_with_context (MonoInvocation *frame, ThreadContext *context);
2008 ves_exec_method_with_context_with_ip (MonoInvocation *frame, ThreadContext *context, unsigned short *start_with_ip, MonoException *filter_exception)
2010 MonoInvocation child_frame;
2011 GSList *finally_ips = NULL;
2012 const unsigned short *endfinally_ip = NULL;
2013 const unsigned short *ip = NULL;
2014 register stackval *sp;
2017 gint tracing = global_tracing;
2018 unsigned char *vtalloc;
2021 unsigned char *vt_sp;
2022 unsigned char *locals;
2024 MonoObject *o = NULL;
2026 #if USE_COMPUTED_GOTO
2027 static void *in_labels[] = {
2028 #define OPDEF(a,b,c,d) \
2030 #include "mintops.def"
2035 frame->ex_handler = NULL;
2037 context->current_frame = frame;
2040 debug_enter (frame, &tracing);
2043 if (!frame->runtime_method->transformed) {
2044 context->managed_code = 0;
2046 char *mn = mono_method_full_name (frame->runtime_method->method, TRUE);
2047 g_print ("(%p) Transforming %s\n", mono_thread_internal_current (), mn);
2050 frame->ex = mono_interp_transform_method (frame->runtime_method, context);
2051 context->managed_code = 1;
2059 rtm = frame->runtime_method;
2060 if (!start_with_ip ) {
2061 frame->args = alloca (rtm->alloca_size);
2062 memset (frame->args, 0, rtm->alloca_size);
2068 sp = frame->stack = (stackval *) ((char *) frame->args + rtm->args_size);
2069 vt_sp = (unsigned char *) sp + rtm->stack_size;
2073 locals = (unsigned char *) vt_sp + rtm->vt_stack_size;
2074 child_frame.parent = frame;
2076 if (filter_exception) {
2077 sp->data.p = filter_exception;
2082 * using while (ip < end) may result in a 15% performance drop,
2083 * but it may be useful for debug
2087 /* g_assert (sp >= frame->stack); */
2088 /* g_assert(vt_sp - vtalloc <= rtm->vt_stack_size); */
2090 MINT_IN_SWITCH (*ip) {
2091 MINT_IN_CASE(MINT_INITLOCALS)
2092 memset (locals, 0, rtm->locals_size);
2095 MINT_IN_CASE(MINT_NOP)
2098 MINT_IN_CASE(MINT_BREAK)
2100 G_BREAKPOINT (); /* this is not portable... */
2102 MINT_IN_CASE(MINT_LDNULL)
2107 MINT_IN_CASE(MINT_VTRESULT) {
2108 int ret_size = * (guint16 *)(ip + 1);
2109 unsigned char *ret_vt_sp = vt_sp;
2110 vt_sp -= READ32(ip + 2);
2112 memmove (vt_sp, ret_vt_sp, ret_size);
2113 sp [-1].data.p = vt_sp;
2114 vt_sp += (ret_size + 7) & ~7;
2119 #define LDC(n) do { sp->data.i = (n); ++ip; ++sp; } while (0)
2120 MINT_IN_CASE(MINT_LDC_I4_M1)
2123 MINT_IN_CASE(MINT_LDC_I4_0)
2126 MINT_IN_CASE(MINT_LDC_I4_1)
2129 MINT_IN_CASE(MINT_LDC_I4_2)
2132 MINT_IN_CASE(MINT_LDC_I4_3)
2135 MINT_IN_CASE(MINT_LDC_I4_4)
2138 MINT_IN_CASE(MINT_LDC_I4_5)
2141 MINT_IN_CASE(MINT_LDC_I4_6)
2144 MINT_IN_CASE(MINT_LDC_I4_7)
2147 MINT_IN_CASE(MINT_LDC_I4_8)
2150 MINT_IN_CASE(MINT_LDC_I4_S)
2151 sp->data.i = *(const short *)(ip + 1);
2155 MINT_IN_CASE(MINT_LDC_I4)
2157 sp->data.i = READ32 (ip);
2161 MINT_IN_CASE(MINT_LDC_I8)
2163 sp->data.l = READ64 (ip);
2167 MINT_IN_CASE(MINT_LDC_R4) {
2171 sp->data.f = * (float *)&val;
2176 MINT_IN_CASE(MINT_LDC_R8)
2177 sp->data.l = READ64 (ip + 1); /* note union usage */
2181 MINT_IN_CASE(MINT_DUP)
2186 MINT_IN_CASE(MINT_DUP_VT)
2187 i32 = READ32 (ip + 1);
2189 memcpy(sp->data.p, sp [-1].data.p, i32);
2190 vt_sp += (i32 + 7) & ~7;
2194 MINT_IN_CASE(MINT_POP) {
2195 guint16 u16 = (* (guint16 *)(ip + 1)) + 1;
2197 memmove (sp - u16, sp - 1, (u16 - 1) * sizeof (stackval));
2202 MINT_IN_CASE(MINT_JMP) {
2203 RuntimeMethod *new_method = rtm->data_items [* (guint16 *)(ip + 1)];
2204 if (!new_method->transformed) {
2206 frame->ex = mono_interp_transform_method (new_method, context);
2211 if (new_method->alloca_size > rtm->alloca_size)
2212 g_error ("MINT_JMP to method which needs more stack space (%d > %d)", new_method->alloca_size, rtm->alloca_size);
2213 rtm = frame->runtime_method = new_method;
2214 vt_sp = (unsigned char *) sp + rtm->stack_size;
2218 locals = vt_sp + rtm->vt_stack_size;
2219 ip = rtm->new_body_start; /* bypass storing input args from callers frame */
2222 MINT_IN_CASE(MINT_CALLI) {
2223 MonoMethodSignature *csignature;
2224 stackval *endsp = sp;
2228 csignature = rtm->data_items [* (guint16 *)(ip + 1)];
2232 child_frame.runtime_method = sp->data.p;
2235 child_frame.retval = sp;
2236 /* decrement by the actual number of args */
2237 sp -= csignature->param_count;
2238 if (csignature->hasthis)
2240 child_frame.stack_args = sp;
2242 /* `this' can be NULL for string:.ctor */
2243 if (csignature->hasthis && sp->data.p && mono_object_is_transparent_proxy (sp->data.p)) {
2244 child_frame.runtime_method = mono_interp_get_runtime_method (context->domain, mono_marshal_get_remoting_invoke (child_frame.runtime_method->method), &error);
2245 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2246 } else if (child_frame.runtime_method->method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) {
2247 child_frame.runtime_method = mono_interp_get_runtime_method (context->domain, mono_marshal_get_native_wrapper (child_frame.runtime_method->method, FALSE, FALSE), &error);
2248 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2251 if (csignature->hasthis) {
2252 MonoObject *this_arg = sp->data.p;
2254 if (this_arg->vtable->klass->valuetype) {
2255 gpointer *unboxed = mono_object_unbox (this_arg);
2256 sp [0].data.p = unboxed;
2260 ves_exec_method_with_context (&child_frame, context);
2262 context->current_frame = frame;
2264 if (child_frame.ex) {
2266 * An exception occurred, need to run finally, fault and catch handlers..
2268 frame->ex = child_frame.ex;
2269 goto handle_finally;
2272 /* need to handle typedbyref ... */
2273 if (csignature->ret->type != MONO_TYPE_VOID) {
2279 MINT_IN_CASE(MINT_CALLI_NAT) {
2280 MonoMethodSignature *csignature;
2281 stackval *endsp = sp;
2282 unsigned char *code = NULL;
2286 csignature = rtm->data_items [* (guint16 *)(ip + 1)];
2291 child_frame.runtime_method = NULL;
2294 child_frame.retval = sp;
2295 /* decrement by the actual number of args */
2296 sp -= csignature->param_count;
2297 if (csignature->hasthis)
2299 child_frame.stack_args = sp;
2300 ves_pinvoke_method (&child_frame, csignature, (MonoFuncV) code, FALSE, context);
2302 context->current_frame = frame;
2304 if (child_frame.ex) {
2306 * An exception occurred, need to run finally, fault and catch handlers..
2308 frame->ex = child_frame.ex;
2309 if (context->search_for_handler) {
2310 context->search_for_handler = 0;
2311 goto handle_exception;
2313 goto handle_finally;
2316 /* need to handle typedbyref ... */
2317 if (csignature->ret->type != MONO_TYPE_VOID) {
2323 MINT_IN_CASE(MINT_CALL) {
2324 stackval *endsp = sp;
2328 child_frame.runtime_method = rtm->data_items [* (guint16 *)(ip + 1)];
2331 child_frame.retval = sp;
2332 /* decrement by the actual number of args */
2333 sp -= child_frame.runtime_method->param_count;
2334 if (child_frame.runtime_method->hasthis)
2336 child_frame.stack_args = sp;
2338 /* `this' can be NULL for string:.ctor */
2339 if (child_frame.runtime_method->hasthis && !child_frame.runtime_method->method->klass->valuetype && sp->data.p && mono_object_is_transparent_proxy (sp->data.p)) {
2340 child_frame.runtime_method = mono_interp_get_runtime_method (context->domain, mono_marshal_get_remoting_invoke (child_frame.runtime_method->method), &error);
2341 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2344 ves_exec_method_with_context (&child_frame, context);
2346 context->current_frame = frame;
2348 if (child_frame.ex) {
2350 * An exception occurred, need to run finally, fault and catch handlers..
2352 frame->ex = child_frame.ex;
2353 goto handle_exception;;
2356 /* need to handle typedbyref ... */
2361 MINT_IN_CASE(MINT_VCALL) {
2364 child_frame.runtime_method = rtm->data_items [* (guint16 *)(ip + 1)];
2368 child_frame.retval = sp;
2369 /* decrement by the actual number of args */
2370 sp -= child_frame.runtime_method->param_count;
2371 if (child_frame.runtime_method->hasthis) {
2373 MonoObject *this_arg = sp->data.p;
2375 THROW_EX (mono_get_exception_null_reference(), ip - 2);
2377 child_frame.stack_args = sp;
2379 if (child_frame.runtime_method->hasthis && !child_frame.runtime_method->method->klass->valuetype && mono_object_is_transparent_proxy (sp->data.p)) {
2380 child_frame.runtime_method = mono_interp_get_runtime_method (context->domain, mono_marshal_get_remoting_invoke (child_frame.runtime_method->method), &error);
2381 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2384 ves_exec_method_with_context (&child_frame, context);
2386 context->current_frame = frame;
2388 if (child_frame.ex) {
2390 * An exception occurred, need to run finally, fault and catch handlers..
2392 frame->ex = child_frame.ex;
2393 goto handle_finally;
2398 MINT_IN_CASE(MINT_JIT_CALL) {
2399 MonoMethodSignature *sig;
2400 RuntimeMethod *rmethod = rtm->data_items [* (guint16 *)(ip + 1)];
2401 MonoFtnDesc ftndesc;
2402 guint8 res_buf [256];
2405 //printf ("%s\n", mono_method_full_name (rmethod->method, 1));
2408 * Call JITted code through a gsharedvt_out wrapper. These wrappers receive every argument
2409 * by ref and return a return value using an explicit return value argument.
2411 if (!rmethod->jit_wrapper) {
2412 MonoMethod *method = rmethod->method;
2415 sig = mono_method_signature (method);
2418 MonoMethod *wrapper = mini_get_gsharedvt_out_sig_wrapper (sig);
2419 //printf ("J: %s %s\n", mono_method_full_name (method, 1), mono_method_full_name (wrapper, 1));
2421 gpointer jit_wrapper = mono_jit_compile_method_jit_only (wrapper, &error);
2422 mono_error_assert_ok (&error);
2424 gpointer addr = mono_jit_compile_method_jit_only (method, &error);
2426 mono_error_assert_ok (&error);
2428 rmethod->jit_addr = addr;
2429 rmethod->jit_sig = sig;
2430 mono_memory_barrier ();
2431 rmethod->jit_wrapper = jit_wrapper;
2434 sig = rmethod->jit_sig;
2439 sp -= sig->param_count;
2443 ftndesc.addr = rmethod->jit_addr;
2446 // FIXME: Optimize this
2450 int stack_index = 0;
2451 if (rmethod->hasthis) {
2452 args [pindex ++] = sp [0].data.p;
2455 type = rmethod->rtype;
2456 if (type->type != MONO_TYPE_VOID) {
2457 if (MONO_TYPE_ISSTRUCT (type))
2458 args [pindex ++] = vt_sp;
2460 args [pindex ++] = res_buf;
2462 for (int i = 0; i < rmethod->param_count; ++i) {
2463 MonoType *t = rmethod->param_types [i];
2464 stackval *sval = &sp [stack_index + i];
2465 if (sig->params [i]->byref) {
2466 args [pindex ++] = sval->data.p;
2467 } else if (MONO_TYPE_ISSTRUCT (t)) {
2468 args [pindex ++] = sval->data.p;
2469 } else if (MONO_TYPE_IS_REFERENCE (t)) {
2470 args [pindex ++] = &sval->data.p;
2479 case MONO_TYPE_VALUETYPE:
2480 args [pindex ++] = &sval->data.i;
2483 case MONO_TYPE_FNPTR:
2486 case MONO_TYPE_OBJECT:
2487 args [pindex ++] = &sval->data.p;
2491 args [pindex ++] = &sval->data.l;
2494 printf ("%s\n", mono_type_full_name (t));
2495 g_assert_not_reached ();
2502 void (*func)(gpointer) = rmethod->jit_wrapper;
2508 void (*func)(gpointer, gpointer) = rmethod->jit_wrapper;
2510 func (args [0], &ftndesc);
2514 void (*func)(gpointer, gpointer, gpointer) = rmethod->jit_wrapper;
2516 func (args [0], args [1], &ftndesc);
2520 void (*func)(gpointer, gpointer, gpointer, gpointer) = rmethod->jit_wrapper;
2522 func (args [0], args [1], args [2], &ftndesc);
2526 void (*func)(gpointer, gpointer, gpointer, gpointer, gpointer) = rmethod->jit_wrapper;
2528 func (args [0], args [1], args [2], args [3], &ftndesc);
2532 void (*func)(gpointer, gpointer, gpointer, gpointer, gpointer, gpointer) = rmethod->jit_wrapper;
2534 func (args [0], args [1], args [2], args [3], args [4], &ftndesc);
2538 void (*func)(gpointer, gpointer, gpointer, gpointer, gpointer, gpointer, gpointer) = rmethod->jit_wrapper;
2540 func (args [0], args [1], args [2], args [3], args [4], args [5], &ftndesc);
2544 void (*func)(gpointer, gpointer, gpointer, gpointer, gpointer, gpointer, gpointer, gpointer) = rmethod->jit_wrapper;
2546 func (args [0], args [1], args [2], args [3], args [4], args [5], args [6], &ftndesc);
2550 g_assert_not_reached ();
2554 MonoType *rtype = rmethod->rtype;
2555 switch (rtype->type) {
2556 case MONO_TYPE_VOID:
2557 case MONO_TYPE_OBJECT:
2558 case MONO_TYPE_STRING:
2559 case MONO_TYPE_CLASS:
2560 case MONO_TYPE_ARRAY:
2561 case MONO_TYPE_SZARRAY:
2564 sp->data.p = *(gpointer*)res_buf;
2567 sp->data.i = *(gint8*)res_buf;
2570 sp->data.i = *(guint8*)res_buf;
2573 sp->data.i = *(gint16*)res_buf;
2576 sp->data.i = *(guint16*)res_buf;
2579 sp->data.i = *(gint32*)res_buf;
2582 sp->data.i = *(guint32*)res_buf;
2584 case MONO_TYPE_VALUETYPE:
2585 /* The result was written to vt_sp */
2588 case MONO_TYPE_GENERICINST:
2589 if (MONO_TYPE_IS_REFERENCE (rtype)) {
2590 sp->data.p = *(gpointer*)res_buf;
2592 /* The result was written to vt_sp */
2597 printf ("%s\n", mono_type_full_name (rtype));
2598 g_assert_not_reached ();
2601 if (rtype->type != MONO_TYPE_VOID)
2606 MINT_IN_CASE(MINT_CALLVIRT) {
2607 stackval *endsp = sp;
2608 MonoObject *this_arg;
2613 token = * (unsigned short *)(ip + 1);
2615 child_frame.runtime_method = rtm->data_items [token];
2617 child_frame.retval = sp;
2619 /* decrement by the actual number of args */
2620 sp -= child_frame.runtime_method->param_count + 1;
2621 child_frame.stack_args = sp;
2622 this_arg = sp->data.p;
2624 THROW_EX (mono_get_exception_null_reference(), ip - 2);
2625 child_frame.runtime_method = get_virtual_method (context->domain, child_frame.runtime_method, this_arg);
2627 MonoClass *this_class = this_arg->vtable->klass;
2628 if (this_class->valuetype && child_frame.runtime_method->method->klass->valuetype) {
2630 gpointer *unboxed = mono_object_unbox (this_arg);
2631 sp [0].data.p = unboxed;
2634 ves_exec_method_with_context (&child_frame, context);
2636 context->current_frame = frame;
2638 if (child_frame.ex) {
2640 * An exception occurred, need to run finally, fault and catch handlers..
2642 frame->ex = child_frame.ex;
2643 if (context->search_for_handler) {
2644 context->search_for_handler = 0;
2645 goto handle_exception;
2647 goto handle_finally;
2650 /* need to handle typedbyref ... */
2655 MINT_IN_CASE(MINT_VCALLVIRT) {
2656 MonoObject *this_arg;
2661 token = * (unsigned short *)(ip + 1);
2663 child_frame.runtime_method = rtm->data_items [token];
2665 child_frame.retval = sp;
2667 /* decrement by the actual number of args */
2668 sp -= child_frame.runtime_method->param_count + 1;
2669 child_frame.stack_args = sp;
2670 this_arg = sp->data.p;
2672 THROW_EX (mono_get_exception_null_reference(), ip - 2);
2673 child_frame.runtime_method = get_virtual_method (context->domain, child_frame.runtime_method, this_arg);
2675 MonoClass *this_class = this_arg->vtable->klass;
2676 if (this_class->valuetype && child_frame.runtime_method->method->klass->valuetype) {
2677 gpointer *unboxed = mono_object_unbox (this_arg);
2678 sp [0].data.p = unboxed;
2681 ves_exec_method_with_context (&child_frame, context);
2683 context->current_frame = frame;
2685 if (child_frame.ex) {
2687 * An exception occurred, need to run finally, fault and catch handlers..
2689 frame->ex = child_frame.ex;
2690 if (context->search_for_handler) {
2691 context->search_for_handler = 0;
2692 goto handle_exception;
2694 goto handle_finally;
2698 MINT_IN_CASE(MINT_CALLRUN)
2699 ves_runtime_method (frame, context);
2702 goto handle_exception;
2705 MINT_IN_CASE(MINT_RET)
2707 *frame->retval = *sp;
2708 if (sp > frame->stack)
2709 g_warning ("ret: more values on stack: %d", sp-frame->stack);
2711 MINT_IN_CASE(MINT_RET_VOID)
2712 if (sp > frame->stack)
2713 g_warning ("ret.void: more values on stack: %d", sp-frame->stack);
2715 MINT_IN_CASE(MINT_RET_VT)
2716 i32 = READ32(ip + 1);
2718 memcpy(frame->retval->data.p, sp->data.p, i32);
2719 if (sp > frame->stack)
2720 g_warning ("ret.vt: more values on stack: %d", sp-frame->stack);
2722 MINT_IN_CASE(MINT_BR_S)
2723 ip += (short) *(ip + 1);
2725 MINT_IN_CASE(MINT_BR)
2726 ip += (gint32) READ32(ip + 1);
2728 #define ZEROP_S(datamem, op) \
2730 if (sp->data.datamem op 0) \
2731 ip += * (gint16 *)(ip + 1); \
2735 #define ZEROP(datamem, op) \
2737 if (sp->data.datamem op 0) \
2738 ip += READ32(ip + 1); \
2742 MINT_IN_CASE(MINT_BRFALSE_I4_S)
2745 MINT_IN_CASE(MINT_BRFALSE_I8_S)
2748 MINT_IN_CASE(MINT_BRFALSE_R8_S)
2751 MINT_IN_CASE(MINT_BRFALSE_I4)
2754 MINT_IN_CASE(MINT_BRFALSE_I8)
2757 MINT_IN_CASE(MINT_BRFALSE_R8)
2760 MINT_IN_CASE(MINT_BRTRUE_I4_S)
2763 MINT_IN_CASE(MINT_BRTRUE_I8_S)
2766 MINT_IN_CASE(MINT_BRTRUE_R8_S)
2769 MINT_IN_CASE(MINT_BRTRUE_I4)
2772 MINT_IN_CASE(MINT_BRTRUE_I8)
2775 MINT_IN_CASE(MINT_BRTRUE_R8)
2778 #define CONDBR_S(cond) \
2781 ip += * (gint16 *)(ip + 1); \
2784 #define BRELOP_S(datamem, op) \
2785 CONDBR_S(sp[0].data.datamem op sp[1].data.datamem)
2787 #define CONDBR(cond) \
2790 ip += READ32(ip + 1); \
2794 #define BRELOP(datamem, op) \
2795 CONDBR(sp[0].data.datamem op sp[1].data.datamem)
2797 MINT_IN_CASE(MINT_BEQ_I4_S)
2800 MINT_IN_CASE(MINT_BEQ_I8_S)
2803 MINT_IN_CASE(MINT_BEQ_R8_S)
2804 CONDBR_S(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f == sp[1].data.f)
2806 MINT_IN_CASE(MINT_BEQ_I4)
2809 MINT_IN_CASE(MINT_BEQ_I8)
2812 MINT_IN_CASE(MINT_BEQ_R8)
2813 CONDBR(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f == sp[1].data.f)
2815 MINT_IN_CASE(MINT_BGE_I4_S)
2818 MINT_IN_CASE(MINT_BGE_I8_S)
2821 MINT_IN_CASE(MINT_BGE_R8_S)
2822 CONDBR_S(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f >= sp[1].data.f)
2824 MINT_IN_CASE(MINT_BGE_I4)
2827 MINT_IN_CASE(MINT_BGE_I8)
2830 MINT_IN_CASE(MINT_BGE_R8)
2831 CONDBR(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f >= sp[1].data.f)
2833 MINT_IN_CASE(MINT_BGT_I4_S)
2836 MINT_IN_CASE(MINT_BGT_I8_S)
2839 MINT_IN_CASE(MINT_BGT_R8_S)
2840 CONDBR_S(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f > sp[1].data.f)
2842 MINT_IN_CASE(MINT_BGT_I4)
2845 MINT_IN_CASE(MINT_BGT_I8)
2848 MINT_IN_CASE(MINT_BGT_R8)
2849 CONDBR(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f > sp[1].data.f)
2851 MINT_IN_CASE(MINT_BLT_I4_S)
2854 MINT_IN_CASE(MINT_BLT_I8_S)
2857 MINT_IN_CASE(MINT_BLT_R8_S)
2858 CONDBR_S(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f < sp[1].data.f)
2860 MINT_IN_CASE(MINT_BLT_I4)
2863 MINT_IN_CASE(MINT_BLT_I8)
2866 MINT_IN_CASE(MINT_BLT_R8)
2867 CONDBR(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f < sp[1].data.f)
2869 MINT_IN_CASE(MINT_BLE_I4_S)
2872 MINT_IN_CASE(MINT_BLE_I8_S)
2875 MINT_IN_CASE(MINT_BLE_R8_S)
2876 CONDBR_S(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f <= sp[1].data.f)
2878 MINT_IN_CASE(MINT_BLE_I4)
2881 MINT_IN_CASE(MINT_BLE_I8)
2884 MINT_IN_CASE(MINT_BLE_R8)
2885 CONDBR(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f <= sp[1].data.f)
2887 MINT_IN_CASE(MINT_BNE_UN_I4_S)
2890 MINT_IN_CASE(MINT_BNE_UN_I8_S)
2893 MINT_IN_CASE(MINT_BNE_UN_R8_S)
2894 CONDBR_S(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f != sp[1].data.f)
2896 MINT_IN_CASE(MINT_BNE_UN_I4)
2899 MINT_IN_CASE(MINT_BNE_UN_I8)
2902 MINT_IN_CASE(MINT_BNE_UN_R8)
2903 CONDBR(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f != sp[1].data.f)
2906 #define BRELOP_S_CAST(datamem, op, type) \
2908 if ((type) sp[0].data.datamem op (type) sp[1].data.datamem) \
2909 ip += * (gint16 *)(ip + 1); \
2913 #define BRELOP_CAST(datamem, op, type) \
2915 if ((type) sp[0].data.datamem op (type) sp[1].data.datamem) \
2916 ip += READ32(ip + 1); \
2920 MINT_IN_CASE(MINT_BGE_UN_I4_S)
2921 BRELOP_S_CAST(i, >=, guint32);
2923 MINT_IN_CASE(MINT_BGE_UN_I8_S)
2924 BRELOP_S_CAST(l, >=, guint64);
2926 MINT_IN_CASE(MINT_BGE_UN_R8_S)
2927 CONDBR_S(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f >= sp[1].data.f)
2929 MINT_IN_CASE(MINT_BGE_UN_I4)
2930 BRELOP_CAST(i, >=, guint32);
2932 MINT_IN_CASE(MINT_BGE_UN_I8)
2933 BRELOP_CAST(l, >=, guint64);
2935 MINT_IN_CASE(MINT_BGE_UN_R8)
2936 CONDBR(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f >= sp[1].data.f)
2938 MINT_IN_CASE(MINT_BGT_UN_I4_S)
2939 BRELOP_S_CAST(i, >, guint32);
2941 MINT_IN_CASE(MINT_BGT_UN_I8_S)
2942 BRELOP_S_CAST(l, >, guint64);
2944 MINT_IN_CASE(MINT_BGT_UN_R8_S)
2945 CONDBR_S(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f > sp[1].data.f)
2947 MINT_IN_CASE(MINT_BGT_UN_I4)
2948 BRELOP_CAST(i, >, guint32);
2950 MINT_IN_CASE(MINT_BGT_UN_I8)
2951 BRELOP_CAST(l, >, guint64);
2953 MINT_IN_CASE(MINT_BGT_UN_R8)
2954 CONDBR(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f > sp[1].data.f)
2956 MINT_IN_CASE(MINT_BLE_UN_I4_S)
2957 BRELOP_S_CAST(i, <=, guint32);
2959 MINT_IN_CASE(MINT_BLE_UN_I8_S)
2960 BRELOP_S_CAST(l, <=, guint64);
2962 MINT_IN_CASE(MINT_BLE_UN_R8_S)
2963 CONDBR_S(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f <= sp[1].data.f)
2965 MINT_IN_CASE(MINT_BLE_UN_I4)
2966 BRELOP_CAST(i, <=, guint32);
2968 MINT_IN_CASE(MINT_BLE_UN_I8)
2969 BRELOP_CAST(l, <=, guint64);
2971 MINT_IN_CASE(MINT_BLE_UN_R8)
2972 CONDBR(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f <= sp[1].data.f)
2974 MINT_IN_CASE(MINT_BLT_UN_I4_S)
2975 BRELOP_S_CAST(i, <, guint32);
2977 MINT_IN_CASE(MINT_BLT_UN_I8_S)
2978 BRELOP_S_CAST(l, <, guint64);
2980 MINT_IN_CASE(MINT_BLT_UN_R8_S)
2981 CONDBR_S(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f < sp[1].data.f)
2983 MINT_IN_CASE(MINT_BLT_UN_I4)
2984 BRELOP_CAST(i, <, guint32);
2986 MINT_IN_CASE(MINT_BLT_UN_I8)
2987 BRELOP_CAST(l, <, guint64);
2989 MINT_IN_CASE(MINT_BLT_UN_R8)
2990 CONDBR(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f < sp[1].data.f)
2992 MINT_IN_CASE(MINT_SWITCH) {
2994 const unsigned short *st;
3000 if ((guint32)sp->data.i < n) {
3002 ip += 2 * (guint32)sp->data.i;
3003 offset = READ32 (ip);
3010 MINT_IN_CASE(MINT_LDIND_I1)
3012 sp[-1].data.i = *(gint8*)sp[-1].data.p;
3014 MINT_IN_CASE(MINT_LDIND_U1)
3016 sp[-1].data.i = *(guint8*)sp[-1].data.p;
3018 MINT_IN_CASE(MINT_LDIND_I2)
3020 sp[-1].data.i = *(gint16*)sp[-1].data.p;
3022 MINT_IN_CASE(MINT_LDIND_U2)
3024 sp[-1].data.i = *(guint16*)sp[-1].data.p;
3026 MINT_IN_CASE(MINT_LDIND_I4) /* Fall through */
3027 MINT_IN_CASE(MINT_LDIND_U4)
3029 sp[-1].data.i = *(gint32*)sp[-1].data.p;
3031 MINT_IN_CASE(MINT_LDIND_I8)
3033 sp[-1].data.l = *(gint64*)sp[-1].data.p;
3035 MINT_IN_CASE(MINT_LDIND_I) {
3036 guint16 offset = * (guint16 *)(ip + 1);
3037 sp[-1 - offset].data.p = *(gpointer*)sp[-1 - offset].data.p;
3041 MINT_IN_CASE(MINT_LDIND_R4)
3043 sp[-1].data.f = *(gfloat*)sp[-1].data.p;
3045 MINT_IN_CASE(MINT_LDIND_R8)
3047 sp[-1].data.f = *(gdouble*)sp[-1].data.p;
3049 MINT_IN_CASE(MINT_LDIND_REF)
3051 sp[-1].data.p = *(gpointer*)sp[-1].data.p;
3053 MINT_IN_CASE(MINT_STIND_REF)
3056 mono_gc_wbarrier_generic_store (sp->data.p, sp [1].data.p);
3058 MINT_IN_CASE(MINT_STIND_I1)
3061 * (gint8 *) sp->data.p = (gint8)sp[1].data.i;
3063 MINT_IN_CASE(MINT_STIND_I2)
3066 * (gint16 *) sp->data.p = (gint16)sp[1].data.i;
3068 MINT_IN_CASE(MINT_STIND_I4)
3071 * (gint32 *) sp->data.p = sp[1].data.i;
3073 MINT_IN_CASE(MINT_STIND_I)
3076 * (mono_i *) sp->data.p = (mono_i)sp[1].data.p;
3078 MINT_IN_CASE(MINT_STIND_I8)
3081 * (gint64 *) sp->data.p = sp[1].data.l;
3083 MINT_IN_CASE(MINT_STIND_R4)
3086 * (float *) sp->data.p = (gfloat)sp[1].data.f;
3088 MINT_IN_CASE(MINT_STIND_R8)
3091 * (double *) sp->data.p = sp[1].data.f;
3093 #define BINOP(datamem, op) \
3095 sp [-1].data.datamem = sp [-1].data.datamem op sp [0].data.datamem; \
3097 MINT_IN_CASE(MINT_ADD_I4)
3100 MINT_IN_CASE(MINT_ADD_I8)
3103 MINT_IN_CASE(MINT_ADD_R8)
3106 MINT_IN_CASE(MINT_ADD1_I4)
3110 MINT_IN_CASE(MINT_SUB_I4)
3113 MINT_IN_CASE(MINT_SUB_I8)
3116 MINT_IN_CASE(MINT_SUB_R8)
3119 MINT_IN_CASE(MINT_SUB1_I4)
3123 MINT_IN_CASE(MINT_MUL_I4)
3126 MINT_IN_CASE(MINT_MUL_I8)
3129 MINT_IN_CASE(MINT_MUL_R8)
3132 MINT_IN_CASE(MINT_DIV_I4)
3133 if (sp [-1].data.i == 0)
3134 THROW_EX (mono_get_exception_divide_by_zero (), ip);
3135 if (sp [-1].data.i == (-1))
3136 THROW_EX (mono_get_exception_overflow (), ip);
3139 MINT_IN_CASE(MINT_DIV_I8)
3140 if (sp [-1].data.l == 0)
3141 THROW_EX (mono_get_exception_divide_by_zero (), ip);
3142 if (sp [-1].data.l == (-1))
3143 THROW_EX (mono_get_exception_overflow (), ip);
3146 MINT_IN_CASE(MINT_DIV_R8)
3150 #define BINOP_CAST(datamem, op, type) \
3152 sp [-1].data.datamem = (type)sp [-1].data.datamem op (type)sp [0].data.datamem; \
3154 MINT_IN_CASE(MINT_DIV_UN_I4)
3155 if (sp [-1].data.i == 0)
3156 THROW_EX (mono_get_exception_divide_by_zero (), ip);
3157 BINOP_CAST(i, /, guint32);
3159 MINT_IN_CASE(MINT_DIV_UN_I8)
3160 if (sp [-1].data.l == 0)
3161 THROW_EX (mono_get_exception_divide_by_zero (), ip);
3162 BINOP_CAST(l, /, guint64);
3164 MINT_IN_CASE(MINT_REM_I4)
3165 if (sp [-1].data.i == 0)
3166 THROW_EX (mono_get_exception_divide_by_zero (), ip);
3167 if (sp [-1].data.i == (-1))
3168 THROW_EX (mono_get_exception_overflow (), ip);
3171 MINT_IN_CASE(MINT_REM_I8)
3172 if (sp [-1].data.l == 0)
3173 THROW_EX (mono_get_exception_divide_by_zero (), ip);
3174 if (sp [-1].data.l == (-1))
3175 THROW_EX (mono_get_exception_overflow (), ip);
3178 MINT_IN_CASE(MINT_REM_R8)
3179 /* FIXME: what do we actually do here? */
3181 sp [-1].data.f = fmod (sp [-1].data.f, sp [0].data.f);
3184 MINT_IN_CASE(MINT_REM_UN_I4)
3185 if (sp [-1].data.i == 0)
3186 THROW_EX (mono_get_exception_divide_by_zero (), ip);
3187 BINOP_CAST(i, %, guint32);
3189 MINT_IN_CASE(MINT_REM_UN_I8)
3190 if (sp [-1].data.l == 0)
3191 THROW_EX (mono_get_exception_divide_by_zero (), ip);
3192 BINOP_CAST(l, %, guint64);
3194 MINT_IN_CASE(MINT_AND_I4)
3197 MINT_IN_CASE(MINT_AND_I8)
3200 MINT_IN_CASE(MINT_OR_I4)
3203 MINT_IN_CASE(MINT_OR_I8)
3206 MINT_IN_CASE(MINT_XOR_I4)
3209 MINT_IN_CASE(MINT_XOR_I8)
3213 #define SHIFTOP(datamem, op) \
3215 sp [-1].data.datamem = sp [-1].data.datamem op sp [0].data.i; \
3218 MINT_IN_CASE(MINT_SHL_I4)
3221 MINT_IN_CASE(MINT_SHL_I8)
3224 MINT_IN_CASE(MINT_SHR_I4)
3227 MINT_IN_CASE(MINT_SHR_I8)
3230 MINT_IN_CASE(MINT_SHR_UN_I4)
3232 sp [-1].data.i = (guint32)sp [-1].data.i >> sp [0].data.i;
3235 MINT_IN_CASE(MINT_SHR_UN_I8)
3237 sp [-1].data.l = (guint64)sp [-1].data.l >> sp [0].data.i;
3240 MINT_IN_CASE(MINT_NEG_I4)
3241 sp [-1].data.i = - sp [-1].data.i;
3244 MINT_IN_CASE(MINT_NEG_I8)
3245 sp [-1].data.l = - sp [-1].data.l;
3248 MINT_IN_CASE(MINT_NEG_R8)
3249 sp [-1].data.f = - sp [-1].data.f;
3252 MINT_IN_CASE(MINT_NOT_I4)
3253 sp [-1].data.i = ~ sp [-1].data.i;
3256 MINT_IN_CASE(MINT_NOT_I8)
3257 sp [-1].data.l = ~ sp [-1].data.l;
3260 MINT_IN_CASE(MINT_CONV_I1_I4)
3261 sp [-1].data.i = (gint8)sp [-1].data.i;
3264 MINT_IN_CASE(MINT_CONV_I1_I8)
3265 sp [-1].data.i = (gint8)sp [-1].data.l;
3268 MINT_IN_CASE(MINT_CONV_I1_R8)
3269 sp [-1].data.i = (gint8)sp [-1].data.f;
3272 MINT_IN_CASE(MINT_CONV_U1_I4)
3273 sp [-1].data.i = (guint8)sp [-1].data.i;
3276 MINT_IN_CASE(MINT_CONV_U1_I8)
3277 sp [-1].data.i = (guint8)sp [-1].data.l;
3280 MINT_IN_CASE(MINT_CONV_U1_R8)
3281 sp [-1].data.i = (guint8)sp [-1].data.f;
3284 MINT_IN_CASE(MINT_CONV_I2_I4)
3285 sp [-1].data.i = (gint16)sp [-1].data.i;
3288 MINT_IN_CASE(MINT_CONV_I2_I8)
3289 sp [-1].data.i = (gint16)sp [-1].data.l;
3292 MINT_IN_CASE(MINT_CONV_I2_R8)
3293 sp [-1].data.i = (gint16)sp [-1].data.f;
3296 MINT_IN_CASE(MINT_CONV_U2_I4)
3297 sp [-1].data.i = (guint16)sp [-1].data.i;
3300 MINT_IN_CASE(MINT_CONV_U2_I8)
3301 sp [-1].data.i = (guint16)sp [-1].data.l;
3304 MINT_IN_CASE(MINT_CONV_U2_R8)
3305 sp [-1].data.i = (guint16)sp [-1].data.f;
3308 MINT_IN_CASE(MINT_CONV_I4_R8)
3309 sp [-1].data.i = (gint32)sp [-1].data.f;
3312 MINT_IN_CASE(MINT_CONV_U4_I8)
3313 MINT_IN_CASE(MINT_CONV_I4_I8)
3314 sp [-1].data.i = (gint32)sp [-1].data.l;
3317 MINT_IN_CASE(MINT_CONV_I4_I8_SP)
3318 sp [-2].data.i = (gint32)sp [-2].data.l;
3321 MINT_IN_CASE(MINT_CONV_U4_R8)
3322 sp [-1].data.i = (guint32)sp [-1].data.f;
3325 MINT_IN_CASE(MINT_CONV_I8_I4)
3326 sp [-1].data.l = sp [-1].data.i;
3329 MINT_IN_CASE(MINT_CONV_I8_I4_SP)
3330 sp [-2].data.l = sp [-2].data.i;
3333 MINT_IN_CASE(MINT_CONV_I8_U4)
3334 sp [-1].data.l = (guint32)sp [-1].data.i;
3337 MINT_IN_CASE(MINT_CONV_I8_R8)
3338 sp [-1].data.l = (gint64)sp [-1].data.f;
3341 MINT_IN_CASE(MINT_CONV_R4_I4)
3342 sp [-1].data.f = (float)sp [-1].data.i;
3345 MINT_IN_CASE(MINT_CONV_R4_I8)
3346 sp [-1].data.f = (float)sp [-1].data.l;
3349 MINT_IN_CASE(MINT_CONV_R4_R8)
3350 sp [-1].data.f = (float)sp [-1].data.f;
3353 MINT_IN_CASE(MINT_CONV_R8_I4)
3354 sp [-1].data.f = (double)sp [-1].data.i;
3357 MINT_IN_CASE(MINT_CONV_R8_I8)
3358 sp [-1].data.f = (double)sp [-1].data.l;
3361 MINT_IN_CASE(MINT_CONV_U8_I4)
3362 sp [-1].data.l = sp [-1].data.i & 0xffffffff;
3365 MINT_IN_CASE(MINT_CONV_U8_R8)
3366 sp [-1].data.l = (guint64)sp [-1].data.f;
3369 MINT_IN_CASE(MINT_CPOBJ) {
3370 c = rtm->data_items[* (guint16 *)(ip + 1)];
3371 g_assert (c->byval_arg.type == MONO_TYPE_VALUETYPE);
3372 /* if this assertion fails, we need to add a write barrier */
3373 g_assert (!MONO_TYPE_IS_REFERENCE (&c->byval_arg));
3374 stackval_from_data (&c->byval_arg, &sp [-2], sp [-1].data.p, FALSE);
3379 MINT_IN_CASE(MINT_LDOBJ) {
3381 c = rtm->data_items[* (guint16 *)(ip + 1)];
3384 if (c->byval_arg.type == MONO_TYPE_VALUETYPE && !c->enumtype) {
3385 int size = mono_class_value_size (c, NULL);
3386 sp [-1].data.p = vt_sp;
3387 vt_sp += (size + 7) & ~7;
3389 stackval_from_data (&c->byval_arg, &sp [-1], p, FALSE);
3392 MINT_IN_CASE(MINT_LDSTR)
3393 sp->data.p = rtm->data_items [* (guint16 *)(ip + 1)];
3397 MINT_IN_CASE(MINT_NEWOBJ) {
3398 MonoClass *newobj_class;
3399 MonoMethodSignature *csig;
3400 stackval valuetype_this;
3406 token = * (guint16 *)(ip + 1);
3409 child_frame.ip = NULL;
3410 child_frame.ex = NULL;
3412 child_frame.runtime_method = rtm->data_items [token];
3413 csig = mono_method_signature (child_frame.runtime_method->method);
3414 newobj_class = child_frame.runtime_method->method->klass;
3415 /*if (profiling_classes) {
3416 guint count = GPOINTER_TO_UINT (g_hash_table_lookup (profiling_classes, newobj_class));
3418 g_hash_table_insert (profiling_classes, newobj_class, GUINT_TO_POINTER (count));
3421 if (newobj_class->parent == mono_defaults.array_class) {
3422 sp -= csig->param_count;
3423 child_frame.stack_args = sp;
3424 o = ves_array_create (&child_frame, context->domain, newobj_class, csig, sp);
3426 THROW_EX (child_frame.ex, ip);
3427 goto array_constructed;
3430 g_assert (csig->hasthis);
3431 if (csig->param_count) {
3432 sp -= csig->param_count;
3433 memmove (sp + 1, sp, csig->param_count * sizeof (stackval));
3435 child_frame.stack_args = sp;
3438 * First arg is the object.
3440 if (newobj_class->valuetype) {
3441 MonoType *t = &newobj_class->byval_arg;
3442 memset (&valuetype_this, 0, sizeof (stackval));
3443 if (!newobj_class->enumtype && (t->type == MONO_TYPE_VALUETYPE || (t->type == MONO_TYPE_GENERICINST && mono_type_generic_inst_is_valuetype (t)))) {
3445 valuetype_this.data.p = vt_sp;
3447 sp->data.p = &valuetype_this;
3450 if (newobj_class != mono_defaults.string_class) {
3451 context->managed_code = 0;
3452 o = mono_object_new_checked (context->domain, newobj_class, &error);
3453 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3454 context->managed_code = 1;
3455 if (*mono_thread_interruption_request_flag ())
3456 mono_thread_interruption_checkpoint ();
3460 child_frame.retval = &retval;
3464 g_assert (csig->call_convention == MONO_CALL_DEFAULT);
3466 ves_exec_method_with_context (&child_frame, context);
3468 context->current_frame = frame;
3470 if (child_frame.ex) {
3472 * An exception occurred, need to run finally, fault and catch handlers..
3474 frame->ex = child_frame.ex;
3475 goto handle_finally;
3478 * a constructor returns void, but we need to return the object we created
3481 if (newobj_class->valuetype && !newobj_class->enumtype) {
3482 *sp = valuetype_this;
3483 } else if (newobj_class == mono_defaults.string_class) {
3491 MINT_IN_CASE(MINT_CASTCLASS)
3492 c = rtm->data_items [*(guint16 *)(ip + 1)];
3493 if ((o = sp [-1].data.p)) {
3494 MonoObject *isinst_obj = mono_object_isinst_checked (o, c, &error);
3495 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3497 THROW_EX (mono_get_exception_invalid_cast (), ip);
3501 MINT_IN_CASE(MINT_ISINST)
3502 c = rtm->data_items [*(guint16 *)(ip + 1)];
3503 if ((o = sp [-1].data.p)) {
3504 MonoObject *isinst_obj = mono_object_isinst_checked (o, c, &error);
3505 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3507 sp [-1].data.p = NULL;
3511 MINT_IN_CASE(MINT_CONV_R_UN_I4)
3512 sp [-1].data.f = (double)(guint32)sp [-1].data.i;
3515 MINT_IN_CASE(MINT_CONV_R_UN_I8)
3516 sp [-1].data.f = (double)(guint64)sp [-1].data.l;
3519 MINT_IN_CASE(MINT_UNBOX)
3520 c = rtm->data_items[*(guint16 *)(ip + 1)];
3524 THROW_EX (mono_get_exception_null_reference (), ip);
3526 MonoObject *isinst_obj = mono_object_isinst_checked (o, c, &error);
3527 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3528 if (!(isinst_obj || ((o->vtable->klass->rank == 0) && (o->vtable->klass->element_class == c->element_class))))
3529 THROW_EX (mono_get_exception_invalid_cast (), ip);
3531 sp [-1].data.p = mono_object_unbox (o);
3534 MINT_IN_CASE(MINT_THROW)
3536 frame->ex_handler = NULL;
3538 sp->data.p = mono_get_exception_null_reference ();
3539 THROW_EX ((MonoException *)sp->data.p, ip);
3541 MINT_IN_CASE(MINT_LDFLDA_UNSAFE)
3543 sp[-1].data.p = (char *)o + * (guint16 *)(ip + 1);
3546 MINT_IN_CASE(MINT_LDFLDA)
3549 THROW_EX (mono_get_exception_null_reference (), ip);
3550 sp[-1].data.p = (char *)o + * (guint16 *)(ip + 1);
3553 MINT_IN_CASE(MINT_CKNULL)
3556 THROW_EX (mono_get_exception_null_reference (), ip);
3560 #define LDFLD(datamem, fieldtype) \
3561 o = sp [-1].data.p; \
3563 THROW_EX (mono_get_exception_null_reference (), ip); \
3564 sp[-1].data.datamem = * (fieldtype *)((char *)o + * (guint16 *)(ip + 1)) ; \
3567 MINT_IN_CASE(MINT_LDFLD_I1) LDFLD(i, gint8); MINT_IN_BREAK;
3568 MINT_IN_CASE(MINT_LDFLD_U1) LDFLD(i, guint8); MINT_IN_BREAK;
3569 MINT_IN_CASE(MINT_LDFLD_I2) LDFLD(i, gint16); MINT_IN_BREAK;
3570 MINT_IN_CASE(MINT_LDFLD_U2) LDFLD(i, guint16); MINT_IN_BREAK;
3571 MINT_IN_CASE(MINT_LDFLD_I4) LDFLD(i, gint32); MINT_IN_BREAK;
3572 MINT_IN_CASE(MINT_LDFLD_I8) LDFLD(l, gint64); MINT_IN_BREAK;
3573 MINT_IN_CASE(MINT_LDFLD_R4) LDFLD(f, float); MINT_IN_BREAK;
3574 MINT_IN_CASE(MINT_LDFLD_R8) LDFLD(f, double); MINT_IN_BREAK;
3575 MINT_IN_CASE(MINT_LDFLD_O) LDFLD(p, gpointer); MINT_IN_BREAK;
3576 MINT_IN_CASE(MINT_LDFLD_P) LDFLD(p, gpointer); MINT_IN_BREAK;
3578 MINT_IN_CASE(MINT_LDFLD_VT)
3581 THROW_EX (mono_get_exception_null_reference (), ip);
3582 i32 = READ32(ip + 2);
3583 sp [-1].data.p = vt_sp;
3584 memcpy(sp [-1].data.p, (char *)o + * (guint16 *)(ip + 1), i32);
3585 vt_sp += (i32 + 7) & ~7;
3589 MINT_IN_CASE(MINT_LDRMFLD) {
3591 MonoClassField *field;
3596 THROW_EX (mono_get_exception_null_reference (), ip);
3597 field = rtm->data_items[* (guint16 *)(ip + 1)];
3599 if (mono_object_is_transparent_proxy (o)) {
3600 MonoClass *klass = ((MonoTransparentProxy*)o)->remote_class->proxy_class;
3602 addr = mono_load_remote_field_checked (o, klass, field, &tmp, &error);
3603 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3605 addr = (char*)o + field->offset;
3608 stackval_from_data (field->type, &sp [-1], addr, FALSE);
3612 MINT_IN_CASE(MINT_LDRMFLD_VT) {
3613 MonoClassField *field;
3619 THROW_EX (mono_get_exception_null_reference (), ip);
3620 field = rtm->data_items[* (guint16 *)(ip + 1)];
3621 i32 = READ32(ip + 2);
3623 if (mono_object_is_transparent_proxy (o)) {
3624 MonoClass *klass = ((MonoTransparentProxy*)o)->remote_class->proxy_class;
3625 addr = mono_load_remote_field_checked (o, klass, field, &tmp, &error);
3626 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3628 addr = (char*)o + field->offset;
3631 sp [-1].data.p = vt_sp;
3632 memcpy(sp [-1].data.p, (char *)o + * (guint16 *)(ip + 1), i32);
3633 vt_sp += (i32 + 7) & ~7;
3634 memcpy(sp [-1].data.p, addr, i32);
3638 #define STFLD(datamem, fieldtype) \
3639 o = sp [-2].data.p; \
3641 THROW_EX (mono_get_exception_null_reference (), ip); \
3643 * (fieldtype *)((char *)o + * (guint16 *)(ip + 1)) = sp[1].data.datamem; \
3646 MINT_IN_CASE(MINT_STFLD_I1) STFLD(i, gint8); MINT_IN_BREAK;
3647 MINT_IN_CASE(MINT_STFLD_U1) STFLD(i, guint8); MINT_IN_BREAK;
3648 MINT_IN_CASE(MINT_STFLD_I2) STFLD(i, gint16); MINT_IN_BREAK;
3649 MINT_IN_CASE(MINT_STFLD_U2) STFLD(i, guint16); MINT_IN_BREAK;
3650 MINT_IN_CASE(MINT_STFLD_I4) STFLD(i, gint32); MINT_IN_BREAK;
3651 MINT_IN_CASE(MINT_STFLD_I8) STFLD(l, gint64); MINT_IN_BREAK;
3652 MINT_IN_CASE(MINT_STFLD_R4) STFLD(f, float); MINT_IN_BREAK;
3653 MINT_IN_CASE(MINT_STFLD_R8) STFLD(f, double); MINT_IN_BREAK;
3654 MINT_IN_CASE(MINT_STFLD_P) STFLD(p, gpointer); MINT_IN_BREAK;
3655 MINT_IN_CASE(MINT_STFLD_O)
3658 THROW_EX (mono_get_exception_null_reference (), ip);
3660 mono_gc_wbarrier_set_field (o, (char *) o + * (guint16 *)(ip + 1), sp [1].data.p);
3664 MINT_IN_CASE(MINT_STFLD_VT)
3667 THROW_EX (mono_get_exception_null_reference (), ip);
3668 i32 = READ32(ip + 2);
3670 memcpy((char *)o + * (guint16 *)(ip + 1), sp [1].data.p, i32);
3671 vt_sp -= (i32 + 7) & ~7;
3675 MINT_IN_CASE(MINT_STRMFLD) {
3676 MonoClassField *field;
3680 THROW_EX (mono_get_exception_null_reference (), ip);
3682 field = rtm->data_items[* (guint16 *)(ip + 1)];
3685 if (mono_object_is_transparent_proxy (o)) {
3686 MonoClass *klass = ((MonoTransparentProxy*)o)->remote_class->proxy_class;
3687 mono_store_remote_field_checked (o, klass, field, &sp [-1].data, &error);
3688 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3690 stackval_to_data (field->type, &sp [-1], (char*)o + field->offset, FALSE);
3695 MINT_IN_CASE(MINT_STRMFLD_VT) {
3696 MonoClassField *field;
3700 THROW_EX (mono_get_exception_null_reference (), ip);
3701 field = rtm->data_items[* (guint16 *)(ip + 1)];
3702 i32 = READ32(ip + 2);
3705 if (mono_object_is_transparent_proxy (o)) {
3706 MonoClass *klass = ((MonoTransparentProxy*)o)->remote_class->proxy_class;
3707 mono_store_remote_field_checked (o, klass, field, &sp [-1].data, &error);
3708 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3710 memcpy((char*)o + field->offset, sp [-1].data.p, i32);
3713 vt_sp -= (i32 + 7) & ~7;
3716 MINT_IN_CASE(MINT_LDSFLDA) {
3717 MonoClassField *field = rtm->data_items[*(guint16 *)(ip + 1)];
3718 sp->data.p = mono_class_static_field_address (context->domain, field);
3723 MINT_IN_CASE(MINT_LDSFLD) {
3724 MonoClassField *field = rtm->data_items [* (guint16 *)(ip + 1)];
3725 gpointer addr = mono_class_static_field_address (context->domain, field);
3726 stackval_from_data (field->type, sp, addr, FALSE);
3731 MINT_IN_CASE(MINT_LDSFLD_VT) {
3732 MonoClassField *field = rtm->data_items [* (guint16 *)(ip + 1)];
3733 gpointer addr = mono_class_static_field_address (context->domain, field);
3734 int size = READ32 (ip + 2);
3738 vt_sp += (size + 7) & ~7;
3739 stackval_from_data (field->type, sp, addr, FALSE);
3743 MINT_IN_CASE(MINT_STSFLD) {
3744 MonoClassField *field = rtm->data_items [* (guint16 *)(ip + 1)];
3745 gpointer addr = mono_class_static_field_address (context->domain, field);
3748 stackval_to_data (field->type, sp, addr, FALSE);
3751 MINT_IN_CASE(MINT_STSFLD_VT) {
3752 MonoClassField *field = rtm->data_items [* (guint16 *)(ip + 1)];
3753 gpointer addr = mono_class_static_field_address (context->domain, field);
3754 int size = READ32 (ip + 2);
3758 stackval_to_data (field->type, sp, addr, FALSE);
3759 vt_sp -= (size + 7) & ~7;
3762 MINT_IN_CASE(MINT_STOBJ_VT) {
3764 c = rtm->data_items[* (guint16 *)(ip + 1)];
3766 size = mono_class_value_size (c, NULL);
3767 memcpy(sp [-2].data.p, sp [-1].data.p, size);
3768 vt_sp -= (size + 7) & ~7;
3772 MINT_IN_CASE(MINT_STOBJ) {
3773 c = rtm->data_items[* (guint16 *)(ip + 1)];
3776 g_assert (!c->byval_arg.byref);
3777 if (MONO_TYPE_IS_REFERENCE (&c->byval_arg))
3778 mono_gc_wbarrier_generic_store (sp [-2].data.p, sp [-1].data.p);
3780 stackval_from_data (&c->byval_arg, sp [-2].data.p, (char *) &sp [-1].data.p, FALSE);
3784 MINT_IN_CASE(MINT_CONV_OVF_I4_UN_R8)
3785 if (sp [-1].data.f < 0 || sp [-1].data.f > MYGUINT32_MAX)
3786 THROW_EX (mono_get_exception_overflow (), ip);
3787 sp [-1].data.i = (guint32)sp [-1].data.f;
3790 MINT_IN_CASE(MINT_CONV_OVF_U8_I4)
3791 if (sp [-1].data.i < 0)
3792 THROW_EX (mono_get_exception_overflow (), ip);
3793 sp [-1].data.l = sp [-1].data.i;
3796 MINT_IN_CASE(MINT_CONV_OVF_U8_I8)
3797 if (sp [-1].data.l < 0)
3798 THROW_EX (mono_get_exception_overflow (), ip);
3801 MINT_IN_CASE(MINT_CONV_OVF_I8_U8)
3802 if ((guint64) sp [-1].data.l > MYGINT64_MAX)
3803 THROW_EX (mono_get_exception_overflow (), ip);
3806 MINT_IN_CASE(MINT_CONV_OVF_U8_R8)
3807 MINT_IN_CASE(MINT_CONV_OVF_I8_UN_R8)
3808 if (sp [-1].data.f < 0 || sp [-1].data.f > MYGINT64_MAX)
3809 THROW_EX (mono_get_exception_overflow (), ip);
3810 sp [-1].data.l = (guint64)sp [-1].data.f;
3813 MINT_IN_CASE(MINT_CONV_OVF_I8_R8)
3814 if (sp [-1].data.f < MYGINT64_MIN || sp [-1].data.f > MYGINT64_MAX)
3815 THROW_EX (mono_get_exception_overflow (), ip);
3816 sp [-1].data.l = (gint64)sp [-1].data.f;
3819 MINT_IN_CASE(MINT_CONV_OVF_I4_UN_I8)
3820 if ((mono_u)sp [-1].data.l > MYGUINT32_MAX)
3821 THROW_EX (mono_get_exception_overflow (), ip);
3822 sp [-1].data.i = (mono_u)sp [-1].data.l;
3825 MINT_IN_CASE(MINT_BOX) {
3826 c = rtm->data_items [* (guint16 *)(ip + 1)];
3827 guint16 offset = * (guint16 *)(ip + 2);
3829 if (c->byval_arg.type == MONO_TYPE_VALUETYPE && !c->enumtype) {
3830 int size = mono_class_value_size (c, NULL);
3831 sp [-1 - offset].data.p = mono_value_box_checked (context->domain, c, sp [-1 - offset].data.p, &error);
3832 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3833 size = (size + 7) & ~7;
3836 stackval_to_data (&c->byval_arg, &sp [-1 - offset], (char *) &sp [-1 - offset], FALSE);
3837 sp [-1 - offset].data.p = mono_value_box_checked (context->domain, c, &sp [-1 - offset], &error);
3838 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3843 MINT_IN_CASE(MINT_NEWARR)
3844 sp [-1].data.p = (MonoObject*) mono_array_new_checked (context->domain, rtm->data_items[*(guint16 *)(ip + 1)], sp [-1].data.i, &error);
3845 if (!mono_error_ok (&error)) {
3846 THROW_EX (mono_error_convert_to_exception (&error), ip);
3848 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3850 /*if (profiling_classes) {
3851 guint count = GPOINTER_TO_UINT (g_hash_table_lookup (profiling_classes, o->vtable->klass));
3853 g_hash_table_insert (profiling_classes, o->vtable->klass, GUINT_TO_POINTER (count));
3857 MINT_IN_CASE(MINT_LDLEN)
3860 THROW_EX (mono_get_exception_null_reference (), ip);
3861 sp [-1].data.nati = mono_array_length ((MonoArray *)o);
3864 MINT_IN_CASE(MINT_GETCHR) {
3868 THROW_EX (mono_get_exception_null_reference (), ip);
3869 i32 = sp [-1].data.i;
3870 if (i32 < 0 || i32 >= mono_string_length (s))
3871 THROW_EX (mono_get_exception_index_out_of_range (), ip);
3873 sp [-1].data.i = mono_string_chars(s)[i32];
3877 MINT_IN_CASE(MINT_STRLEN)
3881 THROW_EX (mono_get_exception_null_reference (), ip);
3882 sp [-1].data.i = mono_string_length ((MonoString*) o);
3884 MINT_IN_CASE(MINT_ARRAY_RANK)
3887 THROW_EX (mono_get_exception_null_reference (), ip);
3888 sp [-1].data.i = mono_object_class (sp [-1].data.p)->rank;
3891 MINT_IN_CASE(MINT_LDELEMA)
3892 MINT_IN_CASE(MINT_LDELEMA_TC) {
3893 gboolean needs_typecheck = *ip == MINT_LDELEMA_TC;
3895 MonoClass *klass = rtm->data_items [*(guint16 *) (ip + 1)];
3896 guint16 numargs = *(guint16 *) (ip + 2);
3901 sp->data.p = ves_array_element_address (frame, klass, (MonoArray *) o, &sp [1], needs_typecheck);
3903 THROW_EX (frame->ex, ip);
3908 MINT_IN_CASE(MINT_LDELEM_I1) /* fall through */
3909 MINT_IN_CASE(MINT_LDELEM_U1) /* fall through */
3910 MINT_IN_CASE(MINT_LDELEM_I2) /* fall through */
3911 MINT_IN_CASE(MINT_LDELEM_U2) /* fall through */
3912 MINT_IN_CASE(MINT_LDELEM_I4) /* fall through */
3913 MINT_IN_CASE(MINT_LDELEM_U4) /* fall through */
3914 MINT_IN_CASE(MINT_LDELEM_I8) /* fall through */
3915 MINT_IN_CASE(MINT_LDELEM_I) /* fall through */
3916 MINT_IN_CASE(MINT_LDELEM_R4) /* fall through */
3917 MINT_IN_CASE(MINT_LDELEM_R8) /* fall through */
3918 MINT_IN_CASE(MINT_LDELEM_REF) /* fall through */
3919 MINT_IN_CASE(MINT_LDELEM_VT) {
3927 THROW_EX (mono_get_exception_null_reference (), ip);
3929 aindex = sp [1].data.i;
3930 if (aindex >= mono_array_length (o))
3931 THROW_EX (mono_get_exception_index_out_of_range (), ip);
3934 * FIXME: throw mono_get_exception_array_type_mismatch () if needed
3937 case MINT_LDELEM_I1:
3938 sp [0].data.i = mono_array_get (o, gint8, aindex);
3940 case MINT_LDELEM_U1:
3941 sp [0].data.i = mono_array_get (o, guint8, aindex);
3943 case MINT_LDELEM_I2:
3944 sp [0].data.i = mono_array_get (o, gint16, aindex);
3946 case MINT_LDELEM_U2:
3947 sp [0].data.i = mono_array_get (o, guint16, aindex);
3950 sp [0].data.nati = mono_array_get (o, mono_i, aindex);
3952 case MINT_LDELEM_I4:
3953 sp [0].data.i = mono_array_get (o, gint32, aindex);
3955 case MINT_LDELEM_U4:
3956 sp [0].data.i = mono_array_get (o, guint32, aindex);
3958 case MINT_LDELEM_I8:
3959 sp [0].data.l = mono_array_get (o, guint64, aindex);
3961 case MINT_LDELEM_R4:
3962 sp [0].data.f = mono_array_get (o, float, aindex);
3964 case MINT_LDELEM_R8:
3965 sp [0].data.f = mono_array_get (o, double, aindex);
3967 case MINT_LDELEM_REF:
3968 sp [0].data.p = mono_array_get (o, gpointer, aindex);
3970 case MINT_LDELEM_VT: {
3971 MonoClass *klass_vt = rtm->data_items [*(guint16 *) (ip + 1)];
3972 i32 = READ32 (ip + 2);
3973 char *src_addr = mono_array_addr_with_size ((MonoArray *) o, i32, aindex);
3974 sp [0].data.vt = vt_sp;
3975 stackval_from_data (&klass_vt->byval_arg, sp, src_addr, FALSE);
3976 vt_sp += (i32 + 7) & ~7;
3988 MINT_IN_CASE(MINT_STELEM_I) /* fall through */
3989 MINT_IN_CASE(MINT_STELEM_I1) /* fall through */
3990 MINT_IN_CASE(MINT_STELEM_U1) /* fall through */
3991 MINT_IN_CASE(MINT_STELEM_I2) /* fall through */
3992 MINT_IN_CASE(MINT_STELEM_I4) /* fall through */
3993 MINT_IN_CASE(MINT_STELEM_I8) /* fall through */
3994 MINT_IN_CASE(MINT_STELEM_R4) /* fall through */
3995 MINT_IN_CASE(MINT_STELEM_R8) /* fall through */
3996 MINT_IN_CASE(MINT_STELEM_REF) /* fall through */
3997 MINT_IN_CASE(MINT_STELEM_VT) {
4004 THROW_EX (mono_get_exception_null_reference (), ip);
4006 aindex = sp [1].data.i;
4007 if (aindex >= mono_array_length ((MonoArray *)o))
4008 THROW_EX (mono_get_exception_index_out_of_range (), ip);
4012 mono_array_set ((MonoArray *)o, mono_i, aindex, sp [2].data.nati);
4014 case MINT_STELEM_I1:
4015 mono_array_set ((MonoArray *)o, gint8, aindex, sp [2].data.i);
4017 case MINT_STELEM_U1:
4018 mono_array_set ((MonoArray *) o, guint8, aindex, sp [2].data.i);
4020 case MINT_STELEM_I2:
4021 mono_array_set ((MonoArray *)o, gint16, aindex, sp [2].data.i);
4023 case MINT_STELEM_I4:
4024 mono_array_set ((MonoArray *)o, gint32, aindex, sp [2].data.i);
4026 case MINT_STELEM_I8:
4027 mono_array_set ((MonoArray *)o, gint64, aindex, sp [2].data.l);
4029 case MINT_STELEM_R4:
4030 mono_array_set ((MonoArray *)o, float, aindex, sp [2].data.f);
4032 case MINT_STELEM_R8:
4033 mono_array_set ((MonoArray *)o, double, aindex, sp [2].data.f);
4035 case MINT_STELEM_REF: {
4036 MonoObject *isinst_obj = mono_object_isinst_checked (sp [2].data.p, mono_object_class (o)->element_class, &error);
4037 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4038 if (sp [2].data.p && !isinst_obj)
4039 THROW_EX (mono_get_exception_array_type_mismatch (), ip);
4040 mono_array_setref ((MonoArray *) o, aindex, sp [2].data.p);
4043 case MINT_STELEM_VT: {
4044 MonoClass *klass_vt = rtm->data_items [*(guint16 *) (ip + 1)];
4045 i32 = READ32 (ip + 2);
4046 char *dst_addr = mono_array_addr_with_size ((MonoArray *) o, i32, aindex);
4048 stackval_to_data (&klass_vt->byval_arg, &sp [2], dst_addr, FALSE);
4049 vt_sp -= (i32 + 7) & ~7;
4060 MINT_IN_CASE(MINT_CONV_OVF_I4_U4)
4061 if (sp [-1].data.i < 0)
4062 THROW_EX (mono_get_exception_overflow (), ip);
4065 MINT_IN_CASE(MINT_CONV_OVF_I4_I8)
4066 if (sp [-1].data.l < MYGINT32_MIN || sp [-1].data.l > MYGINT32_MAX)
4067 THROW_EX (mono_get_exception_overflow (), ip);
4068 sp [-1].data.i = (gint32) sp [-1].data.l;
4071 MINT_IN_CASE(MINT_CONV_OVF_I4_U8)
4072 if (sp [-1].data.l < 0 || sp [-1].data.l > MYGINT32_MAX)
4073 THROW_EX (mono_get_exception_overflow (), ip);
4074 sp [-1].data.i = (gint32) sp [-1].data.l;
4077 MINT_IN_CASE(MINT_CONV_OVF_I4_R8)
4078 if (sp [-1].data.f < MYGINT32_MIN || sp [-1].data.f > MYGINT32_MAX)
4079 THROW_EX (mono_get_exception_overflow (), ip);
4080 sp [-1].data.i = (gint32) sp [-1].data.f;
4083 MINT_IN_CASE(MINT_CONV_OVF_U4_I4)
4084 if (sp [-1].data.i < 0)
4085 THROW_EX (mono_get_exception_overflow (), ip);
4088 MINT_IN_CASE(MINT_CONV_OVF_U4_I8)
4089 if (sp [-1].data.l < 0 || sp [-1].data.l > MYGUINT32_MAX)
4090 THROW_EX (mono_get_exception_overflow (), ip);
4091 sp [-1].data.i = (guint32) sp [-1].data.l;
4094 MINT_IN_CASE(MINT_CONV_OVF_U4_R8)
4095 if (sp [-1].data.f < 0 || sp [-1].data.f > MYGUINT32_MAX)
4096 THROW_EX (mono_get_exception_overflow (), ip);
4097 sp [-1].data.i = (guint32) sp [-1].data.f;
4100 MINT_IN_CASE(MINT_CONV_OVF_I2_I4)
4101 if (sp [-1].data.i < -32768 || sp [-1].data.i > 32767)
4102 THROW_EX (mono_get_exception_overflow (), ip);
4105 MINT_IN_CASE(MINT_CONV_OVF_I2_I8)
4106 if (sp [-1].data.l < -32768 || sp [-1].data.l > 32767)
4107 THROW_EX (mono_get_exception_overflow (), ip);
4108 sp [-1].data.i = (gint16) sp [-1].data.l;
4111 MINT_IN_CASE(MINT_CONV_OVF_I2_R8)
4112 if (sp [-1].data.f < -32768 || sp [-1].data.f > 32767)
4113 THROW_EX (mono_get_exception_overflow (), ip);
4114 sp [-1].data.i = (gint16) sp [-1].data.f;
4117 MINT_IN_CASE(MINT_CONV_OVF_U2_I4)
4118 if (sp [-1].data.i < 0 || sp [-1].data.i > 65535)
4119 THROW_EX (mono_get_exception_overflow (), ip);
4122 MINT_IN_CASE(MINT_CONV_OVF_U2_I8)
4123 if (sp [-1].data.l < 0 || sp [-1].data.l > 65535)
4124 THROW_EX (mono_get_exception_overflow (), ip);
4125 sp [-1].data.i = (guint16) sp [-1].data.l;
4128 MINT_IN_CASE(MINT_CONV_OVF_U2_R8)
4129 if (sp [-1].data.f < 0 || sp [-1].data.f > 65535)
4130 THROW_EX (mono_get_exception_overflow (), ip);
4131 sp [-1].data.i = (guint16) sp [-1].data.f;
4134 MINT_IN_CASE(MINT_CONV_OVF_I1_I4)
4135 if (sp [-1].data.i < -128 || sp [-1].data.i > 127)
4136 THROW_EX (mono_get_exception_overflow (), ip);
4139 MINT_IN_CASE(MINT_CONV_OVF_I1_I8)
4140 if (sp [-1].data.l < -128 || sp [-1].data.l > 127)
4141 THROW_EX (mono_get_exception_overflow (), ip);
4142 sp [-1].data.i = (gint8) sp [-1].data.l;
4145 MINT_IN_CASE(MINT_CONV_OVF_I1_R8)
4146 if (sp [-1].data.f < -128 || sp [-1].data.f > 127)
4147 THROW_EX (mono_get_exception_overflow (), ip);
4148 sp [-1].data.i = (gint8) sp [-1].data.f;
4151 MINT_IN_CASE(MINT_CONV_OVF_U1_I4)
4152 if (sp [-1].data.i < 0 || sp [-1].data.i > 255)
4153 THROW_EX (mono_get_exception_overflow (), ip);
4156 MINT_IN_CASE(MINT_CONV_OVF_U1_I8)
4157 if (sp [-1].data.l < 0 || sp [-1].data.l > 255)
4158 THROW_EX (mono_get_exception_overflow (), ip);
4159 sp [-1].data.i = (guint8) sp [-1].data.l;
4162 MINT_IN_CASE(MINT_CONV_OVF_U1_R8)
4163 if (sp [-1].data.f < 0 || sp [-1].data.f > 255)
4164 THROW_EX (mono_get_exception_overflow (), ip);
4165 sp [-1].data.i = (guint8) sp [-1].data.f;
4169 MINT_IN_CASE(MINT_LDELEM)
4170 MINT_IN_CASE(MINT_STELEM)
4171 MINT_IN_CASE(MINT_UNBOX_ANY)
4173 MINT_IN_CASE(MINT_REFANYVAL) ves_abort(); MINT_IN_BREAK;
4175 MINT_IN_CASE(MINT_CKFINITE)
4176 if (!isfinite(sp [-1].data.f))
4177 THROW_EX (mono_get_exception_arithmetic (), ip);
4181 MINT_IN_CASE(MINT_MKREFANY) ves_abort(); MINT_IN_BREAK;
4183 MINT_IN_CASE(MINT_LDTOKEN)
4186 * (gpointer *)sp->data.p = rtm->data_items[*(guint16 *)(ip + 1)];
4190 MINT_IN_CASE(MINT_ADD_OVF_I4)
4191 if (CHECK_ADD_OVERFLOW (sp [-2].data.i, sp [-1].data.i))
4192 THROW_EX (mono_get_exception_overflow (), ip);
4195 MINT_IN_CASE(MINT_ADD_OVF_I8)
4196 if (CHECK_ADD_OVERFLOW64 (sp [-2].data.l, sp [-1].data.l))
4197 THROW_EX (mono_get_exception_overflow (), ip);
4200 MINT_IN_CASE(MINT_ADD_OVF_UN_I4)
4201 if (CHECK_ADD_OVERFLOW_UN (sp [-2].data.i, sp [-1].data.i))
4202 THROW_EX (mono_get_exception_overflow (), ip);
4203 BINOP_CAST(i, +, guint32);
4205 MINT_IN_CASE(MINT_ADD_OVF_UN_I8)
4206 if (CHECK_ADD_OVERFLOW64_UN (sp [-2].data.l, sp [-1].data.l))
4207 THROW_EX (mono_get_exception_overflow (), ip);
4208 BINOP_CAST(l, +, guint64);
4210 MINT_IN_CASE(MINT_MUL_OVF_I4)
4211 if (CHECK_MUL_OVERFLOW (sp [-2].data.i, sp [-1].data.i))
4212 THROW_EX (mono_get_exception_overflow (), ip);
4215 MINT_IN_CASE(MINT_MUL_OVF_I8)
4216 if (CHECK_MUL_OVERFLOW64 (sp [-2].data.l, sp [-1].data.l))
4217 THROW_EX (mono_get_exception_overflow (), ip);
4220 MINT_IN_CASE(MINT_MUL_OVF_UN_I4)
4221 if (CHECK_MUL_OVERFLOW_UN (sp [-2].data.i, sp [-1].data.i))
4222 THROW_EX (mono_get_exception_overflow (), ip);
4223 BINOP_CAST(i, *, guint32);
4225 MINT_IN_CASE(MINT_MUL_OVF_UN_I8)
4226 if (CHECK_MUL_OVERFLOW64_UN (sp [-2].data.l, sp [-1].data.l))
4227 THROW_EX (mono_get_exception_overflow (), ip);
4228 BINOP_CAST(l, *, guint64);
4230 MINT_IN_CASE(MINT_SUB_OVF_I4)
4231 if (CHECK_SUB_OVERFLOW (sp [-2].data.i, sp [-1].data.i))
4232 THROW_EX (mono_get_exception_overflow (), ip);
4235 MINT_IN_CASE(MINT_SUB_OVF_I8)
4236 if (CHECK_SUB_OVERFLOW64 (sp [-2].data.l, sp [-1].data.l))
4237 THROW_EX (mono_get_exception_overflow (), ip);
4240 MINT_IN_CASE(MINT_SUB_OVF_UN_I4)
4241 if (CHECK_SUB_OVERFLOW_UN (sp [-2].data.i, sp [-1].data.i))
4242 THROW_EX (mono_get_exception_overflow (), ip);
4243 BINOP_CAST(i, -, guint32);
4245 MINT_IN_CASE(MINT_SUB_OVF_UN_I8)
4246 if (CHECK_SUB_OVERFLOW64_UN (sp [-2].data.l, sp [-1].data.l))
4247 THROW_EX (mono_get_exception_overflow (), ip);
4248 BINOP_CAST(l, -, guint64);
4250 MINT_IN_CASE(MINT_ENDFINALLY)
4251 while (sp > frame->stack) {
4255 ip = finally_ips->data;
4256 finally_ips = g_slist_remove (finally_ips, ip);
4263 MINT_IN_CASE(MINT_LEAVE) /* Fall through */
4264 MINT_IN_CASE(MINT_LEAVE_S)
4265 while (sp > frame->stack) {
4269 if (*ip == MINT_LEAVE_S) {
4270 ip += (short) *(ip + 1);
4272 ip += (gint32) READ32 (ip + 1);
4275 if (frame->ex_handler != NULL && MONO_OFFSET_IN_HANDLER(frame->ex_handler, frame->ip - rtm->code)) {
4276 frame->ex_handler = NULL;
4279 goto handle_finally;
4281 MINT_IN_CASE(MINT_ICALL_V_V)
4282 MINT_IN_CASE(MINT_ICALL_V_P)
4283 MINT_IN_CASE(MINT_ICALL_P_V)
4284 MINT_IN_CASE(MINT_ICALL_P_P)
4285 MINT_IN_CASE(MINT_ICALL_PP_V)
4286 MINT_IN_CASE(MINT_ICALL_PI_V)
4287 MINT_IN_CASE(MINT_ICALL_PP_P)
4288 MINT_IN_CASE(MINT_ICALL_PI_P)
4289 MINT_IN_CASE(MINT_ICALL_PPP_V)
4290 MINT_IN_CASE(MINT_ICALL_PPI_V)
4291 sp = do_icall (context, *ip, sp, rtm->data_items [*(guint16 *)(ip + 1)]);
4292 if (frame->ex != NULL)
4293 goto handle_exception;
4296 MINT_IN_CASE(MINT_MONO_LDPTR)
4297 sp->data.p = rtm->data_items [*(guint16 *)(ip + 1)];
4301 MINT_IN_CASE(MINT_MONO_NEWOBJ)
4302 sp->data.p = mono_object_new_checked (context->domain, rtm->data_items [*(guint16 *)(ip + 1)], &error);
4303 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4307 MINT_IN_CASE(MINT_MONO_FREE)
4310 g_error ("that doesn't seem right");
4311 g_free (sp->data.p);
4313 MINT_IN_CASE(MINT_MONO_RETOBJ)
4316 stackval_from_data (mono_method_signature (frame->runtime_method->method)->ret, frame->retval, sp->data.p,
4317 mono_method_signature (frame->runtime_method->method)->pinvoke);
4318 if (sp > frame->stack)
4319 g_warning ("retobj: more values on stack: %d", sp-frame->stack);
4322 #define RELOP(datamem, op) \
4324 sp [-1].data.i = sp [-1].data.datamem op sp [0].data.datamem; \
4326 MINT_IN_CASE(MINT_CEQ_I4)
4329 MINT_IN_CASE(MINT_CEQ0_I4)
4330 sp [-1].data.i = (sp [-1].data.i == 0);
4333 MINT_IN_CASE(MINT_CEQ_I8)
4336 MINT_IN_CASE(MINT_CEQ_R8)
4338 if (isunordered (sp [-1].data.f, sp [0].data.f))
4341 sp [-1].data.i = sp [-1].data.f == sp [0].data.f;
4344 MINT_IN_CASE(MINT_CGT_I4)
4347 MINT_IN_CASE(MINT_CGT_I8)
4350 MINT_IN_CASE(MINT_CGT_R8)
4352 if (isunordered (sp [-1].data.f, sp [0].data.f))
4355 sp [-1].data.i = sp [-1].data.f > sp [0].data.f;
4359 #define RELOP_CAST(datamem, op, type) \
4361 sp [-1].data.i = (type)sp [-1].data.datamem op (type)sp [0].data.datamem; \
4364 MINT_IN_CASE(MINT_CGT_UN_I4)
4365 RELOP_CAST(i, >, guint32);
4367 MINT_IN_CASE(MINT_CGT_UN_I8)
4368 RELOP_CAST(l, >, guint64);
4370 MINT_IN_CASE(MINT_CGT_UN_R8)
4372 if (isunordered (sp [-1].data.f, sp [0].data.f))
4375 sp [-1].data.i = sp [-1].data.f > sp [0].data.f;
4378 MINT_IN_CASE(MINT_CLT_I4)
4381 MINT_IN_CASE(MINT_CLT_I8)
4384 MINT_IN_CASE(MINT_CLT_R8)
4386 if (isunordered (sp [-1].data.f, sp [0].data.f))
4389 sp [-1].data.i = sp [-1].data.f < sp [0].data.f;
4392 MINT_IN_CASE(MINT_CLT_UN_I4)
4393 RELOP_CAST(i, <, guint32);
4395 MINT_IN_CASE(MINT_CLT_UN_I8)
4396 RELOP_CAST(l, <, guint64);
4398 MINT_IN_CASE(MINT_CLT_UN_R8)
4400 if (isunordered (sp [-1].data.f, sp [0].data.f))
4403 sp [-1].data.i = sp [-1].data.f < sp [0].data.f;
4406 MINT_IN_CASE(MINT_LDFTN) {
4407 sp->data.p = rtm->data_items [* (guint16 *)(ip + 1)];
4412 MINT_IN_CASE(MINT_LDVIRTFTN) {
4413 RuntimeMethod *m = rtm->data_items [* (guint16 *)(ip + 1)];
4417 THROW_EX (mono_get_exception_null_reference (), ip - 2);
4419 sp->data.p = get_virtual_method (context->domain, m, sp->data.p);
4424 #define LDARG(datamem, argtype) \
4425 sp->data.datamem = * (argtype *)(frame->args + * (guint16 *)(ip + 1)); \
4429 MINT_IN_CASE(MINT_LDARG_I1) LDARG(i, gint8); MINT_IN_BREAK;
4430 MINT_IN_CASE(MINT_LDARG_U1) LDARG(i, guint8); MINT_IN_BREAK;
4431 MINT_IN_CASE(MINT_LDARG_I2) LDARG(i, gint16); MINT_IN_BREAK;
4432 MINT_IN_CASE(MINT_LDARG_U2) LDARG(i, guint16); MINT_IN_BREAK;
4433 MINT_IN_CASE(MINT_LDARG_I4) LDARG(i, gint32); MINT_IN_BREAK;
4434 MINT_IN_CASE(MINT_LDARG_I8) LDARG(l, gint64); MINT_IN_BREAK;
4435 MINT_IN_CASE(MINT_LDARG_R4) LDARG(f, float); MINT_IN_BREAK;
4436 MINT_IN_CASE(MINT_LDARG_R8) LDARG(f, double); MINT_IN_BREAK;
4437 MINT_IN_CASE(MINT_LDARG_O) LDARG(p, gpointer); MINT_IN_BREAK;
4438 MINT_IN_CASE(MINT_LDARG_P) LDARG(p, gpointer); MINT_IN_BREAK;
4440 MINT_IN_CASE(MINT_LDARG_VT)
4442 i32 = READ32(ip + 2);
4443 memcpy(sp->data.p, frame->args + * (guint16 *)(ip + 1), i32);
4444 vt_sp += (i32 + 7) & ~7;
4449 #define STARG(datamem, argtype) \
4451 * (argtype *)(frame->args + * (guint16 *)(ip + 1)) = sp->data.datamem; \
4454 MINT_IN_CASE(MINT_STARG_I1) STARG(i, gint8); MINT_IN_BREAK;
4455 MINT_IN_CASE(MINT_STARG_U1) STARG(i, guint8); MINT_IN_BREAK;
4456 MINT_IN_CASE(MINT_STARG_I2) STARG(i, gint16); MINT_IN_BREAK;
4457 MINT_IN_CASE(MINT_STARG_U2) STARG(i, guint16); MINT_IN_BREAK;
4458 MINT_IN_CASE(MINT_STARG_I4) STARG(i, gint32); MINT_IN_BREAK;
4459 MINT_IN_CASE(MINT_STARG_I8) STARG(l, gint64); MINT_IN_BREAK;
4460 MINT_IN_CASE(MINT_STARG_R4) STARG(f, float); MINT_IN_BREAK;
4461 MINT_IN_CASE(MINT_STARG_R8) STARG(f, double); MINT_IN_BREAK;
4462 MINT_IN_CASE(MINT_STARG_O) STARG(p, gpointer); MINT_IN_BREAK;
4463 MINT_IN_CASE(MINT_STARG_P) STARG(p, gpointer); MINT_IN_BREAK;
4465 MINT_IN_CASE(MINT_STARG_VT)
4466 i32 = READ32(ip + 2);
4468 memcpy(frame->args + * (guint16 *)(ip + 1), sp->data.p, i32);
4469 vt_sp -= (i32 + 7) & ~7;
4473 #define STINARG(datamem, argtype) \
4475 int n = * (guint16 *)(ip + 1); \
4476 * (argtype *)(frame->args + rtm->arg_offsets [n]) = frame->stack_args [n].data.datamem; \
4480 MINT_IN_CASE(MINT_STINARG_I1) STINARG(i, gint8); MINT_IN_BREAK;
4481 MINT_IN_CASE(MINT_STINARG_U1) STINARG(i, guint8); MINT_IN_BREAK;
4482 MINT_IN_CASE(MINT_STINARG_I2) STINARG(i, gint16); MINT_IN_BREAK;
4483 MINT_IN_CASE(MINT_STINARG_U2) STINARG(i, guint16); MINT_IN_BREAK;
4484 MINT_IN_CASE(MINT_STINARG_I4) STINARG(i, gint32); MINT_IN_BREAK;
4485 MINT_IN_CASE(MINT_STINARG_I8) STINARG(l, gint64); MINT_IN_BREAK;
4486 MINT_IN_CASE(MINT_STINARG_R4) STINARG(f, float); MINT_IN_BREAK;
4487 MINT_IN_CASE(MINT_STINARG_R8) STINARG(f, double); MINT_IN_BREAK;
4488 MINT_IN_CASE(MINT_STINARG_O) STINARG(p, gpointer); MINT_IN_BREAK;
4489 MINT_IN_CASE(MINT_STINARG_P) STINARG(p, gpointer); MINT_IN_BREAK;
4491 MINT_IN_CASE(MINT_STINARG_VT) {
4492 int n = * (guint16 *)(ip + 1);
4493 i32 = READ32(ip + 2);
4494 memcpy (frame->args + rtm->arg_offsets [n], frame->stack_args [n].data.p, i32);
4499 MINT_IN_CASE(MINT_LDARGA)
4500 sp->data.p = frame->args + * (guint16 *)(ip + 1);
4505 #define LDLOC(datamem, argtype) \
4506 sp->data.datamem = * (argtype *)(locals + * (guint16 *)(ip + 1)); \
4510 MINT_IN_CASE(MINT_LDLOC_I1) LDLOC(i, gint8); MINT_IN_BREAK;
4511 MINT_IN_CASE(MINT_LDLOC_U1) LDLOC(i, guint8); MINT_IN_BREAK;
4512 MINT_IN_CASE(MINT_LDLOC_I2) LDLOC(i, gint16); MINT_IN_BREAK;
4513 MINT_IN_CASE(MINT_LDLOC_U2) LDLOC(i, guint16); MINT_IN_BREAK;
4514 MINT_IN_CASE(MINT_LDLOC_I4) LDLOC(i, gint32); MINT_IN_BREAK;
4515 MINT_IN_CASE(MINT_LDLOC_I8) LDLOC(l, gint64); MINT_IN_BREAK;
4516 MINT_IN_CASE(MINT_LDLOC_R4) LDLOC(f, float); MINT_IN_BREAK;
4517 MINT_IN_CASE(MINT_LDLOC_R8) LDLOC(f, double); MINT_IN_BREAK;
4518 MINT_IN_CASE(MINT_LDLOC_O) LDLOC(p, gpointer); MINT_IN_BREAK;
4519 MINT_IN_CASE(MINT_LDLOC_P) LDLOC(p, gpointer); MINT_IN_BREAK;
4521 MINT_IN_CASE(MINT_LDLOC_VT)
4523 i32 = READ32(ip + 2);
4524 memcpy(sp->data.p, locals + * (guint16 *)(ip + 1), i32);
4525 vt_sp += (i32 + 7) & ~7;
4530 MINT_IN_CASE(MINT_LDLOCA_S)
4531 sp->data.p = locals + * (guint16 *)(ip + 1);
4536 #define STLOC(datamem, argtype) \
4538 * (argtype *)(locals + * (guint16 *)(ip + 1)) = sp->data.datamem; \
4541 MINT_IN_CASE(MINT_STLOC_I1) STLOC(i, gint8); MINT_IN_BREAK;
4542 MINT_IN_CASE(MINT_STLOC_U1) STLOC(i, guint8); MINT_IN_BREAK;
4543 MINT_IN_CASE(MINT_STLOC_I2) STLOC(i, gint16); MINT_IN_BREAK;
4544 MINT_IN_CASE(MINT_STLOC_U2) STLOC(i, guint16); MINT_IN_BREAK;
4545 MINT_IN_CASE(MINT_STLOC_I4) STLOC(i, gint32); MINT_IN_BREAK;
4546 MINT_IN_CASE(MINT_STLOC_I8) STLOC(l, gint64); MINT_IN_BREAK;
4547 MINT_IN_CASE(MINT_STLOC_R4) STLOC(f, float); MINT_IN_BREAK;
4548 MINT_IN_CASE(MINT_STLOC_R8) STLOC(f, double); MINT_IN_BREAK;
4549 MINT_IN_CASE(MINT_STLOC_O) STLOC(p, gpointer); MINT_IN_BREAK;
4550 MINT_IN_CASE(MINT_STLOC_P) STLOC(p, gpointer); MINT_IN_BREAK;
4552 #define STLOC_NP(datamem, argtype) \
4553 * (argtype *)(locals + * (guint16 *)(ip + 1)) = sp [-1].data.datamem; \
4556 MINT_IN_CASE(MINT_STLOC_NP_I4) STLOC_NP(i, gint32); MINT_IN_BREAK;
4557 MINT_IN_CASE(MINT_STLOC_NP_O) STLOC_NP(p, gpointer); MINT_IN_BREAK;
4559 MINT_IN_CASE(MINT_STLOC_VT)
4560 i32 = READ32(ip + 2);
4562 memcpy(locals + * (guint16 *)(ip + 1), sp->data.p, i32);
4563 vt_sp -= (i32 + 7) & ~7;
4567 MINT_IN_CASE(MINT_LOCALLOC) {
4568 if (sp != frame->stack + 1) /*FIX?*/
4569 THROW_EX (mono_get_exception_execution_engine (NULL), ip);
4571 int len = sp [-1].data.i;
4572 sp [-1].data.p = alloca (len);
4573 MonoMethodHeader *header = mono_method_get_header_checked (frame->runtime_method->method, &error);
4574 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4575 if (header->init_locals)
4576 memset (sp [-1].data.p, 0, len);
4580 MINT_IN_CASE(MINT_ENDFILTER)
4581 /* top of stack is result of filter */
4582 frame->retval = &sp [-1];
4584 MINT_IN_CASE(MINT_INITOBJ)
4586 memset (sp->data.vt, 0, READ32(ip + 1));
4589 MINT_IN_CASE(MINT_CPBLK)
4591 if (!sp [0].data.p || !sp [1].data.p)
4592 THROW_EX (mono_get_exception_null_reference(), ip - 1);
4594 /* FIXME: value and size may be int64... */
4595 memcpy (sp [0].data.p, sp [1].data.p, sp [2].data.i);
4598 MINT_IN_CASE(MINT_CONSTRAINED_) {
4600 /* FIXME: implement */
4602 token = READ32 (ip);
4607 MINT_IN_CASE(MINT_INITBLK)
4610 THROW_EX (mono_get_exception_null_reference(), ip - 1);
4612 /* FIXME: value and size may be int64... */
4613 memset (sp [0].data.p, sp [1].data.i, sp [2].data.i);
4616 MINT_IN_CASE(MINT_NO_)
4617 /* FIXME: implement */
4621 MINT_IN_CASE(MINT_RETHROW)
4623 * need to clarify what this should actually do:
4624 * start the search from the last found handler in
4625 * this method or continue in the caller or what.
4626 * Also, do we need to run finally/fault handlers after a retrow?
4627 * Well, this implementation will follow the usual search
4628 * for an handler, considering the current ip as throw spot.
4629 * We need to NULL frame->ex_handler for the later code to
4630 * actually run the new found handler.
4632 frame->ex_handler = NULL;
4633 THROW_EX (frame->ex, ip - 1);
4636 g_print ("Unimplemented opcode: %04x %s at 0x%x\n", *ip, mono_interp_opname[*ip], ip-rtm->code);
4637 THROW_EX (mono_get_exception_execution_engine ("Unimplemented opcode"), ip);
4641 g_assert_not_reached ();
4643 * Exception handling code.
4644 * The exception object is stored in frame->ex.
4651 MonoInvocation *inv;
4652 MonoExceptionClause *clause;
4658 g_print ("* Handling exception '%s' at IL_%04x\n",
4659 frame->ex == NULL ? "** Unknown **" : mono_object_class (frame->ex)->name,
4660 rtm == NULL ? 0 : frame->ip - rtm->code);
4662 if (die_on_exception)
4665 for (inv = frame; inv; inv = inv->parent) {
4667 if (inv->runtime_method == NULL)
4669 method = inv->runtime_method->method;
4670 if (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL)
4672 if (method->iflags & (METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL | METHOD_IMPL_ATTRIBUTE_RUNTIME))
4674 if (inv->ip == NULL)
4676 ip_offset = inv->ip - inv->runtime_method->code;
4677 inv->ex_handler = NULL; /* clear this in case we are trhowing an exception while handling one - this one wins */
4678 for (i = 0; i < inv->runtime_method->num_clauses; ++i) {
4679 clause = &inv->runtime_method->clauses [i];
4681 g_print ("* clause [%d]: %p\n", i, clause);
4683 if (!MONO_OFFSET_IN_CLAUSE (clause, ip_offset)) {
4686 if (clause->flags == MONO_EXCEPTION_CLAUSE_FILTER) {
4689 g_print ("* Filter found at '%s'\n", method->name);
4691 MonoInvocation dup_frame;
4693 memcpy (&dup_frame, inv, sizeof (MonoInvocation));
4694 dup_frame.retval = &retval;
4695 ves_exec_method_with_context_with_ip (&dup_frame, context, inv->runtime_method->code + clause->data.filter_offset, frame->ex);
4696 if (dup_frame.retval->data.i) {
4699 g_print ("* Matched Filter at '%s'\n", method->name);
4701 inv->ex_handler = clause;
4702 goto handle_finally;
4704 } else if (clause->flags == MONO_EXCEPTION_CLAUSE_NONE) {
4705 MonoObject *isinst_obj = mono_object_isinst_checked ((MonoObject*)frame->ex, clause->data.catch_class, &error);
4706 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4709 * OK, we found an handler, now we need to execute the finally
4710 * and fault blocks before branching to the handler code.
4714 g_print ("* Found handler at '%s'\n", method->name);
4716 inv->ex_handler = clause;
4717 goto handle_finally;
4723 * If we get here, no handler was found: print a stack trace.
4725 for (inv = frame; inv; inv = inv->parent) {
4726 if (inv->invoke_trap)
4727 goto handle_finally;
4730 ex_obj = (MonoObject *) frame->ex;
4731 mono_unhandled_exception (ex_obj);
4732 MonoJitTlsData *jit_tls = (MonoJitTlsData *) mono_tls_get_jit_tls ();
4733 jit_tls->abort_func (ex_obj);
4734 g_assert_not_reached ();
4740 MonoExceptionClause *clause;
4741 GSList *old_list = finally_ips;
4742 MonoMethod *method = frame->runtime_method->method;
4743 MonoMethodHeader *header = mono_method_get_header_checked (method, &error);
4744 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4748 g_print ("* Handle finally IL_%04x\n", endfinally_ip == NULL ? 0 : endfinally_ip - rtm->code);
4750 if (rtm == NULL || (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL)
4751 || (method->iflags & (METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL | METHOD_IMPL_ATTRIBUTE_RUNTIME))) {
4754 ip_offset = frame->ip - rtm->code;
4756 if (endfinally_ip != NULL)
4757 finally_ips = g_slist_prepend(finally_ips, (void *)endfinally_ip);
4758 for (i = 0; i < header->num_clauses; ++i)
4759 if (frame->ex_handler == &rtm->clauses [i])
4763 clause = &rtm->clauses [i];
4764 if (MONO_OFFSET_IN_CLAUSE (clause, ip_offset) && (endfinally_ip == NULL || !(MONO_OFFSET_IN_CLAUSE (clause, endfinally_ip - rtm->code)))) {
4765 if (clause->flags == MONO_EXCEPTION_CLAUSE_FINALLY) {
4766 ip = rtm->code + clause->handler_offset;
4767 finally_ips = g_slist_prepend (finally_ips, (gpointer) ip);
4770 g_print ("* Found finally at IL_%04x with exception: %s\n", clause->handler_offset, frame->ex? "yes": "no");
4776 endfinally_ip = NULL;
4778 if (old_list != finally_ips && finally_ips) {
4779 ip = finally_ips->data;
4780 finally_ips = g_slist_remove (finally_ips, ip);
4781 sp = frame->stack; /* spec says stack should be empty at endfinally so it should be at the start too */
4786 * If an exception is set, we need to execute the fault handler, too,
4787 * otherwise, we continue normally.
4797 MonoExceptionClause *clause;
4798 MonoMethod *method = frame->runtime_method->method;
4799 MonoMethodHeader *header = mono_method_get_header_checked (method, &error);
4800 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4804 g_print ("* Handle fault\n");
4806 ip_offset = frame->ip - rtm->code;
4807 for (i = 0; i < header->num_clauses; ++i) {
4808 clause = &rtm->clauses [i];
4809 if (clause->flags == MONO_EXCEPTION_CLAUSE_FAULT && MONO_OFFSET_IN_CLAUSE (clause, ip_offset)) {
4810 ip = rtm->code + clause->handler_offset;
4813 g_print ("* Executing handler at IL_%04x\n", clause->handler_offset);
4819 * If the handler for the exception was found in this method, we jump
4820 * to it right away, otherwise we return and let the caller run
4821 * the finally, fault and catch blocks.
4822 * This same code should be present in the endfault opcode, but it
4823 * is corrently not assigned in the ECMA specs: LAMESPEC.
4825 if (frame->ex_handler) {
4828 g_print ("* Executing handler at IL_%04x\n", frame->ex_handler->handler_offset);
4830 ip = rtm->code + frame->ex_handler->handler_offset;
4832 vt_sp = (unsigned char *) sp + rtm->stack_size;
4833 sp->data.p = frame->ex;
4844 ves_exec_method_with_context (MonoInvocation *frame, ThreadContext *context)
4846 ves_exec_method_with_context_with_ip (frame, context, NULL, NULL);
4850 ves_exec_method (MonoInvocation *frame)
4852 ThreadContext *context = mono_native_tls_get_value (thread_context_id);
4853 ThreadContext context_struct;
4860 mono_unhandled_exception ((MonoObject*)frame->ex);
4863 if (context == NULL) {
4864 context = &context_struct;
4865 context_struct.domain = mono_domain_get ();
4866 context_struct.base_frame = frame;
4867 context_struct.current_frame = NULL;
4868 context_struct.env_frame = frame;
4869 context_struct.current_env = &env;
4870 context_struct.search_for_handler = 0;
4871 context_struct.managed_code = 0;
4872 mono_native_tls_set_value (thread_context_id, context);
4875 frame->parent = context->current_frame;
4876 frame->runtime_method = mono_interp_get_runtime_method (context->domain, frame->method, &error);
4877 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4878 context->managed_code = 1;
4879 ves_exec_method_with_context (frame, context);
4880 context->managed_code = 0;
4882 if (context != &context_struct && context->current_env) {
4883 context->env_frame->ex = frame->ex;
4884 longjmp (*context->current_env, 1);
4887 mono_unhandled_exception ((MonoObject*)frame->ex);
4889 if (context->base_frame == frame)
4890 mono_native_tls_set_value (thread_context_id, NULL);
4892 context->current_frame = frame->parent;
4896 ves_exec (MonoDomain *domain, MonoAssembly *assembly, int argc, char *argv[])
4898 MonoImage *image = mono_assembly_get_image (assembly);
4903 method = mono_get_method_checked (image, mono_image_get_entry_point (image), NULL, NULL, &error);
4904 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4907 g_error ("No entry point method found in %s", mono_image_get_filename (image));
4909 rval = mono_runtime_run_main_checked (method, argc, argv, &error);
4910 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4918 "mint %s, the Mono ECMA CLI interpreter, (C) 2001, 2002 Ximian, Inc.\n\n"
4919 "Usage is: mint [options] executable args...\n\n", VERSION);
4921 "Runtime Debugging:\n"
4926 " --noptr\t\t\tdon't print pointer addresses in trace output\n"
4929 " --traceclassinit\n"
4932 " --debug method_name\n"
4939 " --config filename load the specified config file instead of the default\n"
4940 " --workers n maximum number of worker threads\n"
4946 interp_ves_icall_get_frame_info (gint32 skip, MonoBoolean need_file_info,
4947 MonoReflectionMethod **method,
4948 gint32 *iloffset, gint32 *native_offset,
4949 MonoString **file, gint32 *line, gint32 *column)
4951 ThreadContext *context = mono_native_tls_get_value (thread_context_id);
4952 MonoInvocation *inv = context->current_frame;
4956 for (i = 0; inv && i < skip; inv = inv->parent)
4957 if (inv->runtime_method != NULL)
4968 *method = mono_method_get_object_checked (context->domain, inv->runtime_method->method, NULL, &error);
4969 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4974 if (need_file_info) {
4978 *file = mono_string_new (mono_domain_get (), "unknown");
4985 interp_ves_icall_get_trace (MonoException *exc, gint32 skip, MonoBoolean need_file_info)
4987 MonoDomain *domain = mono_domain_get ();
4989 MonoArray *ta = exc->trace_ips;
4994 /* Exception is not thrown yet */
4995 MonoArray *array = mono_array_new_checked (domain, mono_defaults.stack_frame_class, 0, &error);
4996 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
5000 len = mono_array_length (ta);
5002 res = mono_array_new_checked (domain, mono_defaults.stack_frame_class, len > skip ? len - skip : 0, &error);
5003 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
5005 for (i = skip; i < len / 2; i++) {
5006 MonoStackFrame *sf = (MonoStackFrame *)mono_object_new_checked (domain, mono_defaults.stack_frame_class, &error);
5007 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
5008 gushort *ip = mono_array_get (ta, gpointer, 2 * i + 1);
5009 RuntimeMethod *rtm = mono_array_get (ta, gpointer, 2 * i);
5012 sf->method = mono_method_get_object_checked (domain, rtm->method, NULL, &error);
5013 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
5014 sf->native_offset = ip - rtm->code;
5018 sf->il_offset = mono_debug_il_offset_from_address (ji->method, sf->native_offset, domain);
5020 if (need_file_info) {
5023 filename = mono_debug_source_location_from_address (ji->method, sf->native_offset, &sf->line, domain);
5025 sf->filename = filename? mono_string_new (domain, filename): NULL;
5032 mono_array_set (res, gpointer, i, sf);
5039 mono_interp_parse_options (const char *options)
5043 args = g_strsplit (options, ",", -1);
5044 for (ptr = args; ptr && *ptr; ptr ++) {
5047 if (strncmp (arg, "jit=", 4) == 0)
5048 jit_classes = g_slist_prepend (jit_classes, arg + 4);
5055 mono_native_tls_alloc (&thread_context_id, NULL);
5056 mono_native_tls_set_value (thread_context_id, NULL);
5058 mono_interp_transform_init ();
5061 typedef int (*TestMethod) (void);
5064 interp_regression_step (MonoImage *image, int verbose, int *total_run, int *total, GTimer *timer, MonoDomain *domain)
5066 int result, expected, failed, cfailed, run;
5067 double elapsed, transform_time;
5069 MonoObject *result_obj;
5070 static gboolean filter_method_init = FALSE;
5071 static const char *filter_method = NULL;
5073 g_print ("Test run: image=%s\n", mono_image_get_filename (image));
5074 cfailed = failed = run = 0;
5075 transform_time = elapsed = 0.0;
5077 g_timer_start (timer);
5078 for (i = 0; i < mono_image_get_table_rows (image, MONO_TABLE_METHOD); ++i) {
5079 MonoObject *exc = NULL;
5081 MonoMethod *method = mono_get_method_checked (image, MONO_TOKEN_METHOD_DEF | (i + 1), NULL, NULL, &error);
5083 mono_error_cleanup (&error); /* FIXME don't swallow the error */
5087 if (!filter_method_init) {
5088 filter_method = g_getenv ("INTERP_FILTER_METHOD");
5089 filter_method_init = TRUE;
5091 gboolean filter = FALSE;
5092 if (filter_method) {
5093 const char *name = filter_method;
5095 if ((strchr (name, '.') > name) || strchr (name, ':')) {
5096 MonoMethodDesc *desc = mono_method_desc_new (name, TRUE);
5097 filter = mono_method_desc_full_match (desc, method);
5098 mono_method_desc_free (desc);
5100 filter = strcmp (method->name, name) == 0;
5102 } else { /* no filter, check for `Category' attribute on method */
5104 MonoCustomAttrInfo* ainfo = mono_custom_attrs_from_method_checked (method, &error);
5105 mono_error_cleanup (&error);
5109 for (j = 0; j < ainfo->num_attrs && filter; ++j) {
5110 MonoCustomAttrEntry *centry = &ainfo->attrs [j];
5111 if (centry->ctor == NULL)
5114 MonoClass *klass = centry->ctor->klass;
5115 if (strcmp (klass->name, "CategoryAttribute"))
5118 MonoObject *obj = mono_custom_attrs_get_attr_checked (ainfo, klass, &error);
5119 /* FIXME: there is an ordering problem if there're multiple attributes, do this instead:
5120 * MonoObject *obj = create_custom_attr (ainfo->image, centry->ctor, centry->data, centry->data_size, &error); */
5121 mono_error_cleanup (&error);
5122 MonoMethod *getter = mono_class_get_method_from_name (klass, "get_Category", -1);
5123 MonoObject *str = mono_interp_runtime_invoke (getter, obj, NULL, &exc, &error);
5124 mono_error_cleanup (&error);
5125 char *utf8_str = mono_string_to_utf8_checked ((MonoString *) str, &error);
5126 mono_error_cleanup (&error);
5127 if (!strcmp (utf8_str, "!INTERPRETER")) {
5128 g_print ("skip %s...\n", method->name);
5134 if (strncmp (method->name, "test_", 5) == 0 && filter) {
5135 MonoError interp_error;
5136 MonoObject *exc = NULL;
5138 result_obj = mono_interp_runtime_invoke (method, NULL, NULL, &exc, &interp_error);
5139 if (!mono_error_ok (&interp_error)) {
5141 g_print ("Test '%s' execution failed.\n", method->name);
5142 } else if (exc != NULL) {
5143 g_print ("Exception in Test '%s' occured:\n", method->name);
5144 mono_object_describe (exc);
5148 result = *(gint32 *) mono_object_unbox (result_obj);
5149 expected = atoi (method->name + 5); // FIXME: oh no.
5152 if (result != expected) {
5154 g_print ("Test '%s' failed result (got %d, expected %d).\n", method->name, result, expected);
5159 g_timer_stop (timer);
5160 elapsed = g_timer_elapsed (timer, NULL);
5161 if (failed > 0 || cfailed > 0){
5162 g_print ("Results: total tests: %d, failed: %d, cfailed: %d (pass: %.2f%%)\n",
5163 run, failed, cfailed, 100.0*(run-failed-cfailed)/run);
5165 g_print ("Results: total tests: %d, all pass \n", run);
5168 g_print ("Elapsed time: %f secs (%f, %f)\n\n", elapsed,
5169 elapsed - transform_time, transform_time);
5170 *total += failed + cfailed;
5175 interp_regression (MonoImage *image, int verbose, int *total_run)
5178 GTimer *timer = g_timer_new ();
5179 MonoDomain *domain = mono_domain_get ();
5183 /* load the metadata */
5184 for (i = 0; i < mono_image_get_table_rows (image, MONO_TABLE_METHOD); ++i) {
5186 method = mono_get_method_checked (image, MONO_TOKEN_METHOD_DEF | (i + 1), NULL, NULL, &error);
5188 mono_error_cleanup (&error);
5191 mono_class_init (method->klass);
5196 interp_regression_step (image, verbose, total_run, &total, timer, domain);
5198 g_timer_destroy (timer);
5203 mono_interp_regression_list (int verbose, int count, char *images [])
5205 int i, total, total_run, run;
5207 total_run = total = 0;
5208 for (i = 0; i < count; ++i) {
5209 MonoAssembly *ass = mono_assembly_open_predicate (images [i], FALSE, FALSE, NULL, NULL, NULL);
5211 g_warning ("failed to load assembly: %s", images [i]);
5214 total += interp_regression (mono_assembly_get_image (ass), verbose, &run);
5218 g_print ("Overall results: tests: %d, failed: %d (pass: %.2f%%)\n", total_run, total, 100.0*(total_run-total)/total_run);
5220 g_print ("Overall results: tests: %d, 100%% pass\n", total_run);