2 * PLEASE NOTE: This is a research prototype.
5 * interp.c: Interpreter for CIL byte codes
8 * Paolo Molaro (lupus@ximian.com)
9 * Miguel de Icaza (miguel@ximian.com)
10 * Dietmar Maurer (dietmar@ximian.com)
12 * (C) 2001, 2002 Ximian, Inc.
27 #include <mono/utils/gc_wrapper.h>
33 # define alloca __builtin_alloca
37 /* trim excessive headers */
38 #include <mono/metadata/image.h>
39 #include <mono/metadata/assembly.h>
40 #include <mono/metadata/cil-coff.h>
41 #include <mono/metadata/mono-endian.h>
42 #include <mono/metadata/tabledefs.h>
43 #include <mono/metadata/tokentype.h>
44 #include <mono/metadata/loader.h>
45 #include <mono/metadata/threads.h>
46 #include <mono/metadata/threadpool.h>
47 #include <mono/metadata/profiler-private.h>
48 #include <mono/metadata/appdomain.h>
49 #include <mono/metadata/reflection.h>
50 #include <mono/metadata/reflection-internals.h>
51 #include <mono/metadata/exception.h>
52 #include <mono/metadata/verify.h>
53 #include <mono/metadata/opcodes.h>
54 #include <mono/metadata/debug-helpers.h>
55 #include <mono/metadata/mono-config.h>
56 #include <mono/metadata/marshal.h>
57 #include <mono/metadata/environment.h>
58 #include <mono/metadata/mono-debug.h>
64 #include <mono/mini/mini.h>
67 /* Mingw 2.1 doesnt need this any more, but leave it in for now for older versions */
70 #define finite _finite
74 #define finite isfinite
78 #define INIT_FRAME(frame,parent_frame,method_args,method_retval,domain,mono_method,error) \
80 (frame)->parent = (parent_frame); \
81 (frame)->stack_args = (method_args); \
82 (frame)->retval = (method_retval); \
83 (frame)->runtime_method = mono_interp_get_runtime_method ((domain), (mono_method), (error)); \
86 (frame)->invoke_trap = 0; \
89 void ves_exec_method (MonoInvocation *frame);
91 static char* dump_stack (stackval *stack, stackval *sp);
92 static char* dump_frame (MonoInvocation *inv);
93 static MonoArray *get_trace_ips (MonoDomain *domain, MonoInvocation *top);
94 static void ves_exec_method_with_context (MonoInvocation *frame, ThreadContext *context);
96 typedef void (*ICallMethod) (MonoInvocation *frame);
98 static guint32 die_on_exception = 0;
99 static MonoNativeTlsKey thread_context_id;
101 static char* dump_args (MonoInvocation *inv);
103 #define DEBUG_INTERP 0
106 int mono_interp_traceopt = 2;
107 /* If true, then we output the opcodes as we interpret them */
108 static int global_tracing = 1;
110 static int debug_indent_level = 0;
112 static int break_on_method = 0;
113 static int nested_trace = 0;
114 static GList *db_methods = NULL;
121 for (h = 0; h < debug_indent_level; h++)
126 db_match_method (gpointer data, gpointer user_data)
128 MonoMethod *m = (MonoMethod*)user_data;
129 MonoMethodDesc *desc = data;
131 if (mono_method_desc_full_match (desc, m))
135 static void debug_enter (MonoInvocation *frame, int *tracing)
138 g_list_foreach (db_methods, db_match_method, (gpointer)frame->runtime_method->method);
140 *tracing = nested_trace ? (global_tracing = 2, 3) : 2;
144 MonoMethod *method = frame->runtime_method->method;
145 char *mn, *args = dump_args (frame);
146 debug_indent_level++;
148 mn = mono_method_full_name (method, FALSE);
149 g_print ("(%p) Entering %s (", mono_thread_internal_current (), mn);
151 g_print ("%s)\n", args);
154 if (mono_profiler_events & MONO_PROFILE_ENTER_LEAVE)
155 mono_profiler_method_enter (frame->runtime_method->method);
159 #define DEBUG_LEAVE() \
162 args = dump_retval (frame); \
164 mn = mono_method_full_name (frame->runtime_method->method, FALSE); \
165 g_print ("(%p) Leaving %s", mono_thread_internal_current (), mn); \
167 g_print (" => %s\n", args); \
169 debug_indent_level--; \
170 if (tracing == 3) global_tracing = 0; \
172 if (mono_profiler_events & MONO_PROFILE_ENTER_LEAVE) \
173 mono_profiler_method_leave (frame->runtime_method->method);
177 int mono_interp_traceopt = 0;
178 static void debug_enter (MonoInvocation *frame, int *tracing)
181 #define DEBUG_LEAVE()
186 interp_ex_handler (MonoException *ex) {
188 ThreadContext *context = mono_native_tls_get_value (thread_context_id);
192 stack_trace = dump_frame (context->current_frame);
193 ex->stack_trace = mono_string_new (mono_domain_get(), stack_trace);
194 g_free (stack_trace);
195 if (context->current_env == NULL || strcmp(ex->object.vtable->klass->name, "ExecutionEngineException") == 0) {
196 char *strace = mono_string_to_utf8_checked (ex->stack_trace, &error);
197 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
198 fprintf(stderr, "Nothing can catch this exception: ");
199 fprintf(stderr, "%s", ex->object.vtable->klass->name);
200 if (ex->message != NULL) {
201 char *m = mono_string_to_utf8_checked (ex->message, &error);
202 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
203 fprintf(stderr, ": %s", m);
206 fprintf(stderr, "\n%s\n", strace);
208 if (ex->inner_ex != NULL) {
209 ex = (MonoException *)ex->inner_ex;
210 fprintf(stderr, "Inner exception: %s", ex->object.vtable->klass->name);
211 if (ex->message != NULL) {
212 char *m = mono_string_to_utf8_checked (ex->message, &error);
213 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
214 fprintf(stderr, ": %s", m);
217 strace = mono_string_to_utf8_checked (ex->stack_trace, &error);
218 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
219 fprintf(stderr, "\n");
220 fprintf(stderr, "%s\n", strace);
223 /* wait for other threads to also collapse */
224 // Sleep(1000); // TODO: proper sleep
227 context->env_frame->ex = ex;
228 context->search_for_handler = 1;
229 longjmp (*context->current_env, 1);
233 ves_real_abort (int line, MonoMethod *mh,
234 const unsigned short *ip, stackval *stack, stackval *sp)
237 fprintf (stderr, "Execution aborted in method: %s::%s\n", mh->klass->name, mh->name);
238 fprintf (stderr, "Line=%d IP=0x%04lx, Aborted execution\n", line,
239 ip-(const unsigned short *)mono_method_get_header_checked (mh, &error)->code);
240 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
241 g_print ("0x%04x %02x\n",
242 ip-(const unsigned short *)mono_method_get_header_checked (mh, &error)->code, *ip);
243 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
245 printf ("\t[%ld] 0x%08x %0.5f\n", sp-stack, sp[-1].data.i, sp[-1].data.f);
248 #define ves_abort() \
250 ves_real_abort(__LINE__, frame->runtime_method->method, ip, frame->stack, sp); \
251 THROW_EX (mono_get_exception_execution_engine (NULL), ip); \
254 static mono_mutex_t runtime_method_lookup_section;
257 mono_interp_get_runtime_method (MonoDomain *domain, MonoMethod *method, MonoError *error)
260 mono_error_init (error);
262 mono_os_mutex_lock (&runtime_method_lookup_section);
263 if ((rtm = mono_internal_hash_table_lookup (&domain->jit_code_hash, method))) {
264 mono_os_mutex_unlock (&runtime_method_lookup_section);
267 rtm = mono_mempool_alloc (domain->mp, sizeof (RuntimeMethod));
268 memset (rtm, 0, sizeof (*rtm));
269 rtm->method = method;
270 rtm->param_count = mono_method_signature (method)->param_count;
271 rtm->hasthis = mono_method_signature (method)->hasthis;
272 rtm->valuetype = method->klass->valuetype;
273 mono_internal_hash_table_insert (&domain->jit_code_hash, method, rtm);
274 mono_os_mutex_unlock (&runtime_method_lookup_section);
280 interp_create_trampoline (MonoDomain *domain, MonoMethod *method, MonoError *error)
282 if (method->iflags & METHOD_IMPL_ATTRIBUTE_SYNCHRONIZED)
283 method = mono_marshal_get_synchronized_wrapper (method);
284 return mono_interp_get_runtime_method (domain, method, error);
287 static inline RuntimeMethod*
288 get_virtual_method (MonoDomain *domain, RuntimeMethod *runtime_method, MonoObject *obj)
290 MonoMethod *m = runtime_method->method;
293 if ((m->flags & METHOD_ATTRIBUTE_FINAL) || !(m->flags & METHOD_ATTRIBUTE_VIRTUAL)) {
294 RuntimeMethod *ret = NULL;
295 if (mono_object_is_transparent_proxy (obj)) {
296 ret = mono_interp_get_runtime_method (domain, mono_marshal_get_remoting_invoke (m), &error);
297 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
298 } else if (m->iflags & METHOD_IMPL_ATTRIBUTE_SYNCHRONIZED) {
299 ret = mono_interp_get_runtime_method (domain, mono_marshal_get_synchronized_wrapper (m), &error);
300 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
302 ret = runtime_method;
307 int slot = mono_method_get_vtable_slot (m);
308 if (mono_class_is_interface (m->klass)) {
309 g_assert (obj->vtable->klass != m->klass);
310 /* TODO: interface offset lookup is slow, go through IMT instead */
311 slot += mono_class_interface_offset (obj->vtable->klass, m->klass);
313 MonoMethod *virtual_method = obj->vtable->klass->vtable [slot];
314 RuntimeMethod *virtual_runtime_method = mono_interp_get_runtime_method (domain, virtual_method, &error);
315 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
316 return virtual_runtime_method;
320 stackval_from_data (MonoType *type, stackval *result, char *data, gboolean pinvoke)
323 switch (type->type) {
324 case MONO_TYPE_OBJECT:
325 case MONO_TYPE_CLASS:
326 case MONO_TYPE_STRING:
327 case MONO_TYPE_ARRAY:
328 case MONO_TYPE_SZARRAY:
333 result->data.p = *(gpointer*)data;
336 switch (type->type) {
340 result->data.i = *(gint8*)data;
343 case MONO_TYPE_BOOLEAN:
344 result->data.i = *(guint8*)data;
347 result->data.i = *(gint16*)data;
351 result->data.i = *(guint16*)data;
354 result->data.i = *(gint32*)data;
358 result->data.nati = *(mono_i*)data;
361 result->data.p = *(gpointer*)data;
364 result->data.i = *(guint32*)data;
367 result->data.f = *(float*)data;
371 result->data.l = *(gint64*)data;
374 result->data.f = *(double*)data;
376 case MONO_TYPE_STRING:
377 case MONO_TYPE_SZARRAY:
378 case MONO_TYPE_CLASS:
379 case MONO_TYPE_OBJECT:
380 case MONO_TYPE_ARRAY:
381 result->data.p = *(gpointer*)data;
383 case MONO_TYPE_VALUETYPE:
384 if (type->data.klass->enumtype) {
385 stackval_from_data (mono_class_enum_basetype (type->data.klass), result, data, pinvoke);
388 mono_value_copy (result->data.vt, data, type->data.klass);
390 case MONO_TYPE_GENERICINST:
391 stackval_from_data (&type->data.generic_class->container_class->byval_arg, result, data, pinvoke);
394 g_warning ("got type 0x%02x", type->type);
395 g_assert_not_reached ();
400 stackval_to_data (MonoType *type, stackval *val, char *data, gboolean pinvoke)
403 gpointer *p = (gpointer*)data;
407 /* printf ("TODAT0 %p\n", data); */
408 switch (type->type) {
411 guint8 *p = (guint8*)data;
415 case MONO_TYPE_BOOLEAN: {
416 guint8 *p = (guint8*)data;
417 *p = (val->data.i != 0);
422 case MONO_TYPE_CHAR: {
423 guint16 *p = (guint16*)data;
428 mono_i *p = (mono_i*)data;
429 /* In theory the value used by stloc should match the local var type
430 but in practice it sometimes doesn't (a int32 gets dup'd and stloc'd into
431 a native int - both by csc and mcs). Not sure what to do about sign extension
432 as it is outside the spec... doing the obvious */
433 *p = (mono_i)val->data.nati;
437 mono_u *p = (mono_u*)data;
439 *p = (mono_u)val->data.nati;
444 gint32 *p = (gint32*)data;
450 gint64 *p = (gint64*)data;
455 float *p = (float*)data;
460 double *p = (double*)data;
464 case MONO_TYPE_STRING:
465 case MONO_TYPE_SZARRAY:
466 case MONO_TYPE_CLASS:
467 case MONO_TYPE_OBJECT:
468 case MONO_TYPE_ARRAY:
469 case MONO_TYPE_PTR: {
470 gpointer *p = (gpointer*)data;
474 case MONO_TYPE_VALUETYPE:
475 if (type->data.klass->enumtype) {
476 stackval_to_data (mono_class_enum_basetype (type->data.klass), val, data, pinvoke);
479 mono_value_copy (data, val->data.vt, type->data.klass);
481 case MONO_TYPE_GENERICINST:
482 stackval_to_data (&type->data.generic_class->container_class->byval_arg, val, data, pinvoke);
485 g_warning ("got type %x", type->type);
486 g_assert_not_reached ();
491 fill_in_trace (MonoException *exception, MonoInvocation *frame)
493 char *stack_trace = dump_frame (frame);
494 MonoDomain *domain = mono_domain_get();
495 (exception)->stack_trace = mono_string_new (domain, stack_trace);
496 (exception)->trace_ips = get_trace_ips (domain, frame);
497 g_free (stack_trace);
500 #define FILL_IN_TRACE(exception, frame) fill_in_trace(exception, frame)
502 #define THROW_EX(exception,ex_ip) \
504 frame->ip = (ex_ip); \
505 frame->ex = (MonoException*)(exception); \
506 FILL_IN_TRACE(frame->ex, frame); \
507 goto handle_exception; \
511 ves_array_create (MonoDomain *domain, MonoClass *klass, MonoMethodSignature *sig, stackval *values)
514 intptr_t *lower_bounds;
519 lengths = alloca (sizeof (uintptr_t) * klass->rank * 2);
520 for (i = 0; i < sig->param_count; ++i) {
521 lengths [i] = values->data.i;
524 if (klass->rank == sig->param_count) {
525 /* Only lengths provided. */
528 /* lower bounds are first. */
529 lower_bounds = (intptr_t *) lengths;
530 lengths += klass->rank;
532 obj = (MonoObject*) mono_array_new_full_checked (domain, klass, lengths, lower_bounds, &error);
533 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
538 ves_array_set (MonoInvocation *frame)
540 stackval *sp = frame->stack_args;
544 gint32 i, t, pos, esize;
548 o = frame->stack_args->data.p;
550 ac = o->vtable->klass;
552 g_assert (ac->rank >= 1);
555 if (ao->bounds != NULL) {
556 pos -= ao->bounds [0].lower_bound;
557 for (i = 1; i < ac->rank; i++) {
558 if ((t = sp [i].data.i - ao->bounds [i].lower_bound) >=
559 ao->bounds [i].length) {
560 frame->ex = mono_get_exception_index_out_of_range ();
561 FILL_IN_TRACE(frame->ex, frame);
564 pos = pos*ao->bounds [i].length + sp [i].data.i -
565 ao->bounds [i].lower_bound;
567 } else if (pos >= ao->max_length) {
568 frame->ex = mono_get_exception_index_out_of_range ();
569 FILL_IN_TRACE(frame->ex, frame);
573 if (sp [ac->rank].data.p && !mono_object_class (o)->element_class->valuetype) {
575 MonoObject *isinst = mono_object_isinst_checked (sp [ac->rank].data.p, mono_object_class (o)->element_class, &error);
576 mono_error_cleanup (&error);
578 frame->ex = mono_get_exception_array_type_mismatch ();
579 FILL_IN_TRACE (frame->ex, frame);
584 esize = mono_array_element_size (ac);
585 ea = mono_array_addr_with_size (ao, esize, pos);
587 mt = mono_method_signature (frame->runtime_method->method)->params [ac->rank];
588 stackval_to_data (mt, &sp [ac->rank], ea, FALSE);
592 ves_array_get (MonoInvocation *frame)
594 stackval *sp = frame->stack_args;
598 gint32 i, t, pos, esize;
602 o = frame->stack_args->data.p;
604 ac = o->vtable->klass;
606 g_assert (ac->rank >= 1);
609 if (ao->bounds != NULL) {
610 pos -= ao->bounds [0].lower_bound;
611 for (i = 1; i < ac->rank; i++) {
612 if ((t = sp [i].data.i - ao->bounds [i].lower_bound) >=
613 ao->bounds [i].length) {
614 frame->ex = mono_get_exception_index_out_of_range ();
615 FILL_IN_TRACE(frame->ex, frame);
619 pos = pos*ao->bounds [i].length + sp [i].data.i -
620 ao->bounds [i].lower_bound;
622 } else if (pos >= ao->max_length) {
623 frame->ex = mono_get_exception_index_out_of_range ();
624 FILL_IN_TRACE(frame->ex, frame);
628 esize = mono_array_element_size (ac);
629 ea = mono_array_addr_with_size (ao, esize, pos);
631 mt = mono_method_signature (frame->runtime_method->method)->ret;
632 stackval_from_data (mt, frame->retval, ea, FALSE);
636 ves_array_element_address (MonoInvocation *frame)
638 stackval *sp = frame->stack_args;
642 gint32 i, t, pos, esize;
645 o = frame->stack_args->data.p;
647 ac = o->vtable->klass;
649 g_assert (ac->rank >= 1);
652 if (ao->bounds != NULL) {
653 pos -= ao->bounds [0].lower_bound;
654 for (i = 1; i < ac->rank; i++) {
655 if ((t = sp [i].data.i - ao->bounds [i].lower_bound) >=
656 ao->bounds [i].length) {
657 frame->ex = mono_get_exception_index_out_of_range ();
658 FILL_IN_TRACE(frame->ex, frame);
661 pos = pos*ao->bounds [i].length + sp [i].data.i -
662 ao->bounds [i].lower_bound;
664 } else if (pos >= ao->max_length) {
665 frame->ex = mono_get_exception_index_out_of_range ();
666 FILL_IN_TRACE(frame->ex, frame);
670 esize = mono_array_element_size (ac);
671 ea = mono_array_addr_with_size (ao, esize, pos);
673 frame->retval->data.p = ea;
677 interp_walk_stack (MonoStackWalk func, gboolean do_il_offset, gpointer user_data)
679 ThreadContext *context = mono_native_tls_get_value (thread_context_id);
680 MonoInvocation *frame;
682 MonoMethodHeader *hd;
685 if (!context) return;
687 frame = context->current_frame;
690 gboolean managed = FALSE;
691 MonoMethod *method = frame->runtime_method->method;
692 if (!method || (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) || (method->iflags & (METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL | METHOD_IMPL_ATTRIBUTE_RUNTIME)))
695 hd = mono_method_get_header_checked (method, &error);
696 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
697 il_offset = frame->ip - (const unsigned short *)hd->code;
698 if (!method->wrapper_type)
701 if (func (method, -1, il_offset, managed, user_data))
703 frame = frame->parent;
707 static MonoPIFunc mono_interp_enter_icall_trampoline = NULL;
709 struct _MethodArguments {
717 typedef struct _MethodArguments MethodArguments;
719 // TODO: this function is also arch dependent (register width).
720 static MethodArguments* build_args_from_sig (MonoMethodSignature *sig, MonoInvocation *frame)
722 // TODO: don't malloc this data structure.
723 MethodArguments *margs = g_malloc0 (sizeof (MethodArguments));
728 for (int i = 0; i < sig->param_count; i++) {
729 guint32 ptype = sig->params [i]->byref ? MONO_TYPE_PTR : sig->params [i]->type;
731 case MONO_TYPE_BOOLEAN:
742 case MONO_TYPE_SZARRAY:
743 case MONO_TYPE_CLASS:
744 case MONO_TYPE_OBJECT:
745 case MONO_TYPE_STRING:
750 g_error ("build_args_from_sig: not implemented yet (1): 0x%x\n", ptype);
755 margs->iargs = g_malloc0 (sizeof (gpointer) * margs->ilen);
758 g_error ("build_args_from_sig: TODO, more than two iregs: %d\n", margs->ilen);
761 g_error ("build_args_from_sig: TODO, allocate floats: %d\n", margs->flen);
767 margs->iargs [0] = frame->stack_args->data.p;
771 for (int i = 0; i < sig->param_count; i++) {
772 guint32 ptype = sig->params [i]->byref ? MONO_TYPE_PTR : sig->params [i]->type;
774 case MONO_TYPE_BOOLEAN:
785 case MONO_TYPE_SZARRAY:
786 case MONO_TYPE_CLASS:
787 case MONO_TYPE_OBJECT:
788 case MONO_TYPE_STRING:
790 margs->iargs [int_i] = frame->stack_args [i].data.p;
792 g_print ("build_args_from_sig: margs->iargs[%d]: %p (frame @ %d)\n", int_i, margs->iargs[int_i], i);
797 g_error ("build_args_from_sig: not implemented yet (2): 0x%x\n", ptype);
801 if (sig->ret->type != MONO_TYPE_VOID) {
802 margs->retval = &(frame->retval->data.p);
804 margs->retval = NULL;
811 ves_pinvoke_method (MonoInvocation *frame, MonoMethodSignature *sig, MonoFuncV addr, gboolean string_ctor, ThreadContext *context)
814 MonoInvocation *old_frame = context->current_frame;
815 MonoInvocation *old_env_frame = context->env_frame;
816 jmp_buf *old_env = context->current_env;
819 context->current_frame = old_frame;
820 context->env_frame = old_env_frame;
821 context->current_env = old_env;
822 context->managed_code = 1;
827 context->env_frame = frame;
828 context->current_env = &env;
830 g_assert (!frame->runtime_method);
831 if (!mono_interp_enter_icall_trampoline) {
833 mono_interp_enter_icall_trampoline = mono_arch_get_enter_icall_trampoline (&info);
835 // mono_tramp_info_register (info, NULL);
838 MethodArguments *margs = build_args_from_sig (sig, frame);
840 g_print ("ICALL: mono_interp_enter_icall_trampoline = %p, addr = %p\n", mono_interp_enter_icall_trampoline, addr);
841 g_print ("margs(out): ilen=%d, flen=%d\n", margs->ilen, margs->flen);
844 context->current_frame = frame;
845 context->managed_code = 0;
847 mono_interp_enter_icall_trampoline (addr, margs);
849 context->managed_code = 1;
850 /* domain can only be changed by native code */
851 context->domain = mono_domain_get ();
853 if (*mono_thread_interruption_request_flag ())
854 mono_thread_interruption_checkpoint ();
856 if (!MONO_TYPE_ISSTRUCT (sig->ret))
857 stackval_from_data (sig->ret, frame->retval, (char*)&frame->retval->data.p, sig->pinvoke);
859 context->current_frame = old_frame;
860 context->env_frame = old_env_frame;
861 context->current_env = old_env;
863 g_free (margs->iargs);
864 g_free (margs->fargs);
869 interp_delegate_ctor (MonoDomain *domain, MonoObject *this, MonoObject *target, RuntimeMethod *runtime_method)
871 MonoDelegate *delegate = (MonoDelegate *)this;
874 delegate->method_info = mono_method_get_object_checked (domain, runtime_method->method, NULL, &error);
875 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
876 delegate->target = target;
878 if (target && mono_object_is_transparent_proxy (target)) {
879 MonoMethod *method = mono_marshal_get_remoting_invoke (runtime_method->method);
880 delegate->method_ptr = mono_interp_get_runtime_method (domain, method, &error);
881 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
883 delegate->method_ptr = runtime_method;
888 mono_interp_ftnptr_to_delegate (MonoClass *klass, gpointer ftn)
892 MonoDomain *domain = mono_domain_get ();
895 d = (MonoDelegate*)mono_object_new_checked (domain, klass, &error);
896 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
898 ji = mono_jit_info_table_find (domain, ftn);
900 mono_raise_exception (mono_get_exception_argument ("", "Function pointer was not created by a Delegate."));
902 /* FIXME: discard the wrapper and call the original method */
903 interp_delegate_ctor (domain, (MonoObject*)d, NULL, mono_interp_get_runtime_method (domain, ji->d.method, &error));
904 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
911 * runtime specifies that the implementation of the method is automatically
912 * provided by the runtime and is primarily used for the methods of delegates.
915 ves_runtime_method (MonoInvocation *frame, ThreadContext *context)
917 MonoMethod *method = frame->runtime_method->method;
918 const char *name = method->name;
919 MonoObject *obj = (MonoObject*) frame->stack_args->data.p;
920 MonoObject *isinst_obj;
923 mono_class_init (method->klass);
925 isinst_obj = mono_object_isinst_checked (obj, mono_defaults.multicastdelegate_class, &error);
926 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
927 if (obj && isinst_obj) {
928 if (*name == '.' && (strcmp (name, ".ctor") == 0)) {
929 interp_delegate_ctor (context->domain, obj, frame->stack_args [1].data.p, frame->stack_args[2].data.p);
934 isinst_obj = mono_object_isinst_checked (obj, mono_defaults.array_class, &error);
935 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
936 if (obj && isinst_obj) {
937 if (*name == 'S' && (strcmp (name, "Set") == 0)) {
938 ves_array_set (frame);
941 if (*name == 'G' && (strcmp (name, "Get") == 0)) {
942 ves_array_get (frame);
945 if (*name == 'A' && (strcmp (name, "Address") == 0)) {
946 ves_array_element_address (frame);
951 g_error ("Don't know how to exec runtime method %s.%s::%s",
952 method->klass->name_space, method->klass->name,
957 dump_stack (stackval *stack, stackval *sp)
960 GString *str = g_string_new ("");
963 return g_string_free (str, FALSE);
966 g_string_append_printf (str, "[%p (%lld)] ", s->data.l, s->data.l);
969 return g_string_free (str, FALSE);
973 dump_stackval (GString *str, stackval *s, MonoType *type)
975 switch (type->type) {
983 case MONO_TYPE_BOOLEAN:
984 g_string_append_printf (str, "[%d] ", s->data.i);
986 case MONO_TYPE_STRING:
987 case MONO_TYPE_SZARRAY:
988 case MONO_TYPE_CLASS:
989 case MONO_TYPE_OBJECT:
990 case MONO_TYPE_ARRAY:
994 g_string_append_printf (str, "[%p] ", s->data.p);
996 case MONO_TYPE_VALUETYPE:
997 if (type->data.klass->enumtype)
998 g_string_append_printf (str, "[%d] ", s->data.i);
1000 g_string_append_printf (str, "[vt:%p] ", s->data.p);
1004 g_string_append_printf (str, "[%g] ", s->data.f);
1009 GString *res = g_string_new ("");
1010 mono_type_get_desc (res, type, TRUE);
1011 g_string_append_printf (str, "[{%s} %lld/0x%0llx] ", res->str, s->data.l, s->data.l);
1012 g_string_free (res, TRUE);
1019 dump_args (MonoInvocation *inv)
1021 GString *str = g_string_new ("");
1023 MonoMethodSignature *signature = mono_method_signature (inv->runtime_method->method);
1025 if (signature->param_count == 0 && !signature->hasthis)
1026 return g_string_free (str, FALSE);
1028 if (signature->hasthis) {
1029 MonoMethod *method = inv->runtime_method->method;
1030 dump_stackval (str, inv->stack_args, &method->klass->byval_arg);
1033 for (i = 0; i < signature->param_count; ++i)
1034 dump_stackval (str, inv->stack_args + (!!signature->hasthis) + i, signature->params [i]);
1036 return g_string_free (str, FALSE);
1040 dump_retval (MonoInvocation *inv)
1042 GString *str = g_string_new ("");
1043 MonoType *ret = mono_method_signature (inv->runtime_method->method)->ret;
1045 if (ret->type != MONO_TYPE_VOID)
1046 dump_stackval (str, inv->retval, ret);
1048 return g_string_free (str, FALSE);
1052 dump_frame (MonoInvocation *inv)
1054 GString *str = g_string_new ("");
1059 for (i = 0; inv; inv = inv->parent) {
1060 if (inv->runtime_method != NULL) {
1061 MonoMethod *method = inv->runtime_method->method;
1065 const char * opname = "";
1067 gchar *source = NULL;
1071 if ((method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) == 0 &&
1072 (method->iflags & METHOD_IMPL_ATTRIBUTE_RUNTIME) == 0) {
1073 MonoMethodHeader *hd = mono_method_get_header_checked (method, &error);
1074 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
1078 opname = mono_interp_opname [*inv->ip];
1079 codep = inv->ip - inv->runtime_method->code;
1080 source = g_strdup_printf ("%s:%d // (TODO: proper stacktrace)", method->name, codep);
1085 MonoDebugSourceLocation *minfo = mono_debug_lookup_method (method);
1086 source = mono_debug_method_lookup_location (minfo, codep);
1090 args = dump_args (inv);
1091 name = mono_method_full_name (method, TRUE);
1093 g_string_append_printf (str, "#%d: 0x%05x %-10s in %s (%s) at %s\n", i, codep, opname, name, args, source);
1095 g_string_append_printf (str, "#%d: 0x%05x %-10s in %s (%s)\n", i, codep, opname, name, args);
1102 return g_string_free (str, FALSE);
1106 get_trace_ips (MonoDomain *domain, MonoInvocation *top)
1110 MonoInvocation *inv;
1113 for (i = 0, inv = top; inv; inv = inv->parent)
1114 if (inv->runtime_method != NULL)
1117 res = mono_array_new_checked (domain, mono_defaults.int_class, 2 * i, &error);
1118 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
1120 for (i = 0, inv = top; inv; inv = inv->parent)
1121 if (inv->runtime_method != NULL) {
1122 mono_array_set (res, gpointer, i, inv->runtime_method);
1124 mono_array_set (res, gpointer, i, (gpointer)inv->ip);
1132 #define MYGUINT64_MAX 18446744073709551615ULL
1133 #define MYGINT64_MAX 9223372036854775807LL
1134 #define MYGINT64_MIN (-MYGINT64_MAX -1LL)
1136 #define MYGUINT32_MAX 4294967295U
1137 #define MYGINT32_MAX 2147483647
1138 #define MYGINT32_MIN (-MYGINT32_MAX -1)
1140 #define CHECK_ADD_OVERFLOW(a,b) \
1141 (gint32)(b) >= 0 ? (gint32)(MYGINT32_MAX) - (gint32)(b) < (gint32)(a) ? -1 : 0 \
1142 : (gint32)(MYGINT32_MIN) - (gint32)(b) > (gint32)(a) ? +1 : 0
1144 #define CHECK_SUB_OVERFLOW(a,b) \
1145 (gint32)(b) < 0 ? (gint32)(MYGINT32_MAX) + (gint32)(b) < (gint32)(a) ? -1 : 0 \
1146 : (gint32)(MYGINT32_MIN) + (gint32)(b) > (gint32)(a) ? +1 : 0
1148 #define CHECK_ADD_OVERFLOW_UN(a,b) \
1149 (guint32)(MYGUINT32_MAX) - (guint32)(b) < (guint32)(a) ? -1 : 0
1151 #define CHECK_SUB_OVERFLOW_UN(a,b) \
1152 (guint32)(a) < (guint32)(b) ? -1 : 0
1154 #define CHECK_ADD_OVERFLOW64(a,b) \
1155 (gint64)(b) >= 0 ? (gint64)(MYGINT64_MAX) - (gint64)(b) < (gint64)(a) ? -1 : 0 \
1156 : (gint64)(MYGINT64_MIN) - (gint64)(b) > (gint64)(a) ? +1 : 0
1158 #define CHECK_SUB_OVERFLOW64(a,b) \
1159 (gint64)(b) < 0 ? (gint64)(MYGINT64_MAX) + (gint64)(b) < (gint64)(a) ? -1 : 0 \
1160 : (gint64)(MYGINT64_MIN) + (gint64)(b) > (gint64)(a) ? +1 : 0
1162 #define CHECK_ADD_OVERFLOW64_UN(a,b) \
1163 (guint64)(MYGUINT64_MAX) - (guint64)(b) < (guint64)(a) ? -1 : 0
1165 #define CHECK_SUB_OVERFLOW64_UN(a,b) \
1166 (guint64)(a) < (guint64)(b) ? -1 : 0
1168 #if SIZEOF_VOID_P == 4
1169 #define CHECK_ADD_OVERFLOW_NAT(a,b) CHECK_ADD_OVERFLOW(a,b)
1170 #define CHECK_ADD_OVERFLOW_NAT_UN(a,b) CHECK_ADD_OVERFLOW_UN(a,b)
1172 #define CHECK_ADD_OVERFLOW_NAT(a,b) CHECK_ADD_OVERFLOW64(a,b)
1173 #define CHECK_ADD_OVERFLOW_NAT_UN(a,b) CHECK_ADD_OVERFLOW64_UN(a,b)
1176 /* Resolves to TRUE if the operands would overflow */
1177 #define CHECK_MUL_OVERFLOW(a,b) \
1178 ((gint32)(a) == 0) || ((gint32)(b) == 0) ? 0 : \
1179 (((gint32)(a) > 0) && ((gint32)(b) == -1)) ? FALSE : \
1180 (((gint32)(a) < 0) && ((gint32)(b) == -1)) ? (a == - MYGINT32_MAX) : \
1181 (((gint32)(a) > 0) && ((gint32)(b) > 0)) ? (gint32)(a) > ((MYGINT32_MAX) / (gint32)(b)) : \
1182 (((gint32)(a) > 0) && ((gint32)(b) < 0)) ? (gint32)(a) > ((MYGINT32_MIN) / (gint32)(b)) : \
1183 (((gint32)(a) < 0) && ((gint32)(b) > 0)) ? (gint32)(a) < ((MYGINT32_MIN) / (gint32)(b)) : \
1184 (gint32)(a) < ((MYGINT32_MAX) / (gint32)(b))
1186 #define CHECK_MUL_OVERFLOW_UN(a,b) \
1187 ((guint32)(a) == 0) || ((guint32)(b) == 0) ? 0 : \
1188 (guint32)(b) > ((MYGUINT32_MAX) / (guint32)(a))
1190 #define CHECK_MUL_OVERFLOW64(a,b) \
1191 ((gint64)(a) == 0) || ((gint64)(b) == 0) ? 0 : \
1192 (((gint64)(a) > 0) && ((gint64)(b) == -1)) ? FALSE : \
1193 (((gint64)(a) < 0) && ((gint64)(b) == -1)) ? (a == - MYGINT64_MAX) : \
1194 (((gint64)(a) > 0) && ((gint64)(b) > 0)) ? (gint64)(a) > ((MYGINT64_MAX) / (gint64)(b)) : \
1195 (((gint64)(a) > 0) && ((gint64)(b) < 0)) ? (gint64)(a) > ((MYGINT64_MIN) / (gint64)(b)) : \
1196 (((gint64)(a) < 0) && ((gint64)(b) > 0)) ? (gint64)(a) < ((MYGINT64_MIN) / (gint64)(b)) : \
1197 (gint64)(a) < ((MYGINT64_MAX) / (gint64)(b))
1199 #define CHECK_MUL_OVERFLOW64_UN(a,b) \
1200 ((guint64)(a) == 0) || ((guint64)(b) == 0) ? 0 : \
1201 (guint64)(b) > ((MYGUINT64_MAX) / (guint64)(a))
1203 #if SIZEOF_VOID_P == 4
1204 #define CHECK_MUL_OVERFLOW_NAT(a,b) CHECK_MUL_OVERFLOW(a,b)
1205 #define CHECK_MUL_OVERFLOW_NAT_UN(a,b) CHECK_MUL_OVERFLOW_UN(a,b)
1207 #define CHECK_MUL_OVERFLOW_NAT(a,b) CHECK_MUL_OVERFLOW64(a,b)
1208 #define CHECK_MUL_OVERFLOW_NAT_UN(a,b) CHECK_MUL_OVERFLOW64_UN(a,b)
1212 interp_mono_runtime_invoke (MonoMethod *method, void *obj, void **params, MonoObject **exc, MonoError *error)
1214 MonoInvocation frame;
1215 ThreadContext * volatile context = mono_native_tls_get_value (thread_context_id);
1216 MonoObject *retval = NULL;
1217 MonoMethodSignature *sig = mono_method_signature (method);
1218 MonoClass *klass = mono_class_from_mono_type (sig->ret);
1219 int i, type, isobject = 0;
1222 stackval *args = alloca (sizeof (stackval) * (sig->param_count + !!sig->hasthis));
1223 ThreadContext context_struct;
1224 MonoInvocation *old_frame = NULL;
1227 mono_error_init (error);
1232 if (context != &context_struct) {
1233 context->domain = mono_domain_get ();
1234 context->current_frame = old_frame;
1235 context->managed_code = 0;
1237 mono_native_tls_set_value (thread_context_id, NULL);
1239 *exc = (MonoObject *)frame.ex;
1243 if (context == NULL) {
1244 context = &context_struct;
1245 context_struct.base_frame = &frame;
1246 context_struct.current_frame = NULL;
1247 context_struct.env_frame = &frame;
1248 context_struct.current_env = &env;
1249 context_struct.search_for_handler = 0;
1250 context_struct.managed_code = 0;
1251 mono_native_tls_set_value (thread_context_id, context);
1254 old_frame = context->current_frame;
1256 context->domain = mono_domain_get ();
1258 switch (sig->ret->type) {
1259 case MONO_TYPE_VOID:
1261 case MONO_TYPE_STRING:
1262 case MONO_TYPE_OBJECT:
1263 case MONO_TYPE_CLASS:
1264 case MONO_TYPE_ARRAY:
1265 case MONO_TYPE_SZARRAY:
1268 case MONO_TYPE_VALUETYPE:
1269 retval = mono_object_new_checked (context->domain, klass, error);
1270 ret = ((char*)retval) + sizeof (MonoObject);
1271 if (!sig->ret->data.klass->enumtype)
1272 result.data.vt = ret;
1275 retval = mono_object_new_checked (context->domain, klass, error);
1276 ret = ((char*)retval) + sizeof (MonoObject);
1281 args [0].data.p = obj;
1283 for (i = 0; i < sig->param_count; ++i) {
1284 int a_index = i + !!sig->hasthis;
1285 if (sig->params [i]->byref) {
1286 args [a_index].data.p = params [i];
1289 type = sig->params [i]->type;
1294 case MONO_TYPE_BOOLEAN:
1295 args [a_index].data.i = *(MonoBoolean*)params [i];
1299 case MONO_TYPE_CHAR:
1300 args [a_index].data.i = *(gint16*)params [i];
1302 #if SIZEOF_VOID_P == 4
1303 case MONO_TYPE_U: /* use VAL_POINTER? */
1308 args [a_index].data.i = *(gint32*)params [i];
1310 #if SIZEOF_VOID_P == 8
1316 args [a_index].data.l = *(gint64*)params [i];
1318 case MONO_TYPE_VALUETYPE:
1319 if (sig->params [i]->data.klass->enumtype) {
1320 type = mono_class_enum_basetype (sig->params [i]->data.klass)->type;
1323 args [a_index].data.p = params [i];
1326 case MONO_TYPE_STRING:
1327 case MONO_TYPE_CLASS:
1328 case MONO_TYPE_ARRAY:
1329 case MONO_TYPE_SZARRAY:
1330 case MONO_TYPE_OBJECT:
1331 args [a_index].data.p = params [i];
1334 g_error ("type 0x%x not handled in runtime invoke", sig->params [i]->type);
1338 if (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL)
1339 method = mono_marshal_get_native_wrapper (method, FALSE, FALSE);
1340 INIT_FRAME (&frame,context->current_frame,args,&result,mono_get_root_domain (),method,error);
1342 frame.invoke_trap = 1;
1343 context->managed_code = 1;
1344 ves_exec_method_with_context (&frame, context);
1345 context->managed_code = 0;
1346 if (context == &context_struct)
1347 mono_native_tls_set_value (thread_context_id, NULL);
1349 context->current_frame = old_frame;
1350 if (frame.ex != NULL) {
1352 *exc = (MonoObject*) frame.ex;
1355 if (context->current_env != NULL) {
1356 context->env_frame->ex = frame.ex;
1357 longjmp(*context->current_env, 1);
1360 printf("dropped exception...\n");
1362 if (sig->ret->type == MONO_TYPE_VOID && !method->string_ctor)
1364 if (isobject || method->string_ctor)
1365 return result.data.p;
1366 stackval_to_data (sig->ret, &result, ret, sig->pinvoke);
1371 do_icall (ThreadContext *context, int op, stackval *sp, gpointer ptr)
1373 MonoInvocation *old_frame = context->current_frame;
1374 MonoInvocation *old_env_frame = context->env_frame;
1375 jmp_buf *old_env = context->current_env;
1379 context->current_frame = old_frame;
1380 context->env_frame = old_env_frame;
1381 context->current_env = old_env;
1382 context->managed_code = 1;
1386 context->env_frame = context->current_frame;
1387 context->current_env = &env;
1388 context->managed_code = 0;
1391 case MINT_ICALL_V_V: {
1392 void (*func)() = ptr;
1396 case MINT_ICALL_V_P: {
1397 gpointer (*func)() = ptr;
1399 sp [-1].data.p = func ();
1402 case MINT_ICALL_P_V: {
1403 void (*func)(gpointer) = ptr;
1404 func (sp [-1].data.p);
1408 case MINT_ICALL_P_P: {
1409 gpointer (*func)(gpointer) = ptr;
1410 sp [-1].data.p = func (sp [-1].data.p);
1413 case MINT_ICALL_PP_V: {
1414 void (*func)(gpointer,gpointer) = ptr;
1416 func (sp [0].data.p, sp [1].data.p);
1419 case MINT_ICALL_PI_V: {
1420 void (*func)(gpointer,int) = ptr;
1422 func (sp [0].data.p, sp [1].data.i);
1425 case MINT_ICALL_PP_P: {
1426 gpointer (*func)(gpointer,gpointer) = ptr;
1428 sp [-1].data.p = func (sp [-1].data.p, sp [0].data.p);
1431 case MINT_ICALL_PI_P: {
1432 gpointer (*func)(gpointer,int) = ptr;
1434 sp [-1].data.p = func (sp [-1].data.p, sp [0].data.i);
1437 case MINT_ICALL_PPP_V: {
1438 void (*func)(gpointer,gpointer,gpointer) = ptr;
1440 func (sp [0].data.p, sp [1].data.p, sp [2].data.p);
1443 case MINT_ICALL_PPI_V: {
1444 void (*func)(gpointer,gpointer,int) = ptr;
1446 func (sp [0].data.p, sp [1].data.p, sp [2].data.i);
1450 g_assert_not_reached ();
1453 context->env_frame = old_env_frame;
1454 context->current_env = old_env;
1459 static mono_mutex_t create_method_pointer_mutex;
1461 static GHashTable *method_pointer_hash = NULL;
1464 interp_create_method_pointer (MonoMethod *method, MonoError *error)
1469 mono_os_mutex_lock (&create_method_pointer_mutex);
1470 if (!method_pointer_hash) {
1471 // FIXME: is registering method table as GC root really necessary?
1472 // MONO_GC_REGISTER_ROOT_FIXED (method_pointer_hash);
1473 method_pointer_hash = g_hash_table_new (NULL, NULL);
1475 addr = g_hash_table_lookup (method_pointer_hash, method);
1477 mono_os_mutex_unlock (&create_method_pointer_mutex);
1482 * If it is a static P/Invoke method, we can just return the pointer
1483 * to the method implementation.
1485 if (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL && ((MonoMethodPInvoke*) method)->addr) {
1486 ji = g_new0 (MonoJitInfo, 1);
1487 ji->d.method = method;
1489 ji->code_start = addr = ((MonoMethodPInvoke*) method)->addr;
1491 mono_jit_info_table_add (mono_get_root_domain (), ji);
1494 g_error ("FIXME: not available? figure out new API");
1496 addr = mono_arch_create_method_pointer (method);
1500 g_hash_table_insert (method_pointer_hash, method, addr);
1501 mono_os_mutex_unlock (&create_method_pointer_mutex);
1507 static int opcode_counts[512];
1509 #define COUNT_OP(op) opcode_counts[op]++
1511 #define COUNT_OP(op)
1515 #define DUMP_INSTR() \
1516 if (tracing > 1) { \
1518 if (sp > frame->stack) { \
1519 ins = dump_stack (frame->stack, sp); \
1521 ins = g_strdup (""); \
1525 char *mn = mono_method_full_name (frame->runtime_method->method, FALSE); \
1526 g_print ("(%p) %s -> ", mono_thread_internal_current (), mn); \
1528 mono_interp_dis_mintop(rtm->code, ip); \
1529 g_print ("\t%d:%s\n", vt_sp - vtalloc, ins); \
1533 #define DUMP_INSTR()
1537 #define USE_COMPUTED_GOTO 1
1539 #if USE_COMPUTED_GOTO
1540 #define MINT_IN_SWITCH(op) COUNT_OP(op); goto *in_labels[op];
1541 #define MINT_IN_CASE(x) LAB_ ## x:
1543 #define MINT_IN_BREAK if (tracing > 1) goto main_loop; else { COUNT_OP(*ip); goto *in_labels[*ip]; }
1545 #define MINT_IN_BREAK { COUNT_OP(*ip); goto *in_labels[*ip]; }
1547 #define MINT_IN_DEFAULT mint_default: if (0) goto mint_default; /* make gcc shut up */
1549 #define MINT_IN_SWITCH(op) switch (op)
1550 #define MINT_IN_CASE(x) case x:
1551 #define MINT_IN_BREAK break
1552 #define MINT_IN_DEFAULT default:
1556 * Defining this causes register allocation errors in some versions of gcc:
1557 * error: unable to find a register to spill in class `SIREG'
1559 /* #define MINT_USE_DEDICATED_IP_REG */
1562 ves_exec_method_with_context (MonoInvocation *frame, ThreadContext *context)
1564 MonoInvocation child_frame;
1565 GSList *finally_ips = NULL;
1566 const unsigned short *endfinally_ip = NULL;
1567 #if defined(__GNUC__) && defined (i386) && defined (MINT_USE_DEDICATED_IP_REG)
1568 register const unsigned short *ip asm ("%esi");
1570 register const unsigned short *ip;
1572 register stackval *sp;
1575 gint tracing = global_tracing;
1576 unsigned char *vtalloc;
1579 unsigned char *vt_sp;
1580 unsigned char *locals;
1582 MonoObject *o = NULL;
1584 #if USE_COMPUTED_GOTO
1585 static void *in_labels[] = {
1586 #define OPDEF(a,b,c,d) \
1588 #include "mintops.def"
1593 frame->ex_handler = NULL;
1595 context->current_frame = frame;
1598 debug_enter (frame, &tracing);
1601 if (!frame->runtime_method->transformed) {
1602 context->managed_code = 0;
1604 char *mn = mono_method_full_name (frame->runtime_method->method, FALSE);
1605 g_print ("(%p) Transforming %s\n", mono_thread_internal_current (), mn);
1608 frame->ex = mono_interp_transform_method (frame->runtime_method, context);
1609 context->managed_code = 1;
1617 rtm = frame->runtime_method;
1618 frame->args = alloca (rtm->alloca_size);
1619 sp = frame->stack = (stackval *)((char *)frame->args + rtm->args_size);
1622 memset(sp, 0, rtm->stack_size);
1624 vt_sp = (unsigned char *) sp + rtm->stack_size;
1628 locals = (unsigned char *) vt_sp + rtm->vt_stack_size;
1630 child_frame.parent = frame;
1636 * using while (ip < end) may result in a 15% performance drop,
1637 * but it may be useful for debug
1641 /* g_assert (sp >= frame->stack); */
1642 /* g_assert(vt_sp - vtalloc <= rtm->vt_stack_size); */
1644 MINT_IN_SWITCH (*ip) {
1645 MINT_IN_CASE(MINT_INITLOCALS)
1646 memset (locals, 0, rtm->locals_size);
1649 MINT_IN_CASE(MINT_NOP)
1652 MINT_IN_CASE(MINT_BREAK)
1654 G_BREAKPOINT (); /* this is not portable... */
1656 MINT_IN_CASE(MINT_LDNULL)
1661 MINT_IN_CASE(MINT_VTRESULT) {
1662 int ret_size = * (guint16 *)(ip + 1);
1663 unsigned char *ret_vt_sp = vt_sp;
1664 vt_sp -= READ32(ip + 2);
1666 memmove (vt_sp, ret_vt_sp, ret_size);
1667 sp [-1].data.p = vt_sp;
1668 vt_sp += (ret_size + 7) & ~7;
1673 #define LDC(n) do { sp->data.i = (n); ++ip; ++sp; } while (0)
1674 MINT_IN_CASE(MINT_LDC_I4_M1)
1677 MINT_IN_CASE(MINT_LDC_I4_0)
1680 MINT_IN_CASE(MINT_LDC_I4_1)
1683 MINT_IN_CASE(MINT_LDC_I4_2)
1686 MINT_IN_CASE(MINT_LDC_I4_3)
1689 MINT_IN_CASE(MINT_LDC_I4_4)
1692 MINT_IN_CASE(MINT_LDC_I4_5)
1695 MINT_IN_CASE(MINT_LDC_I4_6)
1698 MINT_IN_CASE(MINT_LDC_I4_7)
1701 MINT_IN_CASE(MINT_LDC_I4_8)
1704 MINT_IN_CASE(MINT_LDC_I4_S)
1705 sp->data.i = *(const short *)(ip + 1);
1709 MINT_IN_CASE(MINT_LDC_I4)
1711 sp->data.i = READ32 (ip);
1715 MINT_IN_CASE(MINT_LDC_I8)
1717 sp->data.l = READ64 (ip);
1721 MINT_IN_CASE(MINT_LDC_R4) {
1725 sp->data.f = * (float *)&val;
1730 MINT_IN_CASE(MINT_LDC_R8)
1731 sp->data.l = READ64 (ip + 1); /* note union usage */
1735 MINT_IN_CASE(MINT_DUP)
1740 MINT_IN_CASE(MINT_DUP_VT)
1741 i32 = READ32 (ip + 1);
1743 memcpy(sp->data.p, sp [-1].data.p, i32);
1744 vt_sp += (i32 + 7) & ~7;
1748 MINT_IN_CASE(MINT_POP)
1752 MINT_IN_CASE(MINT_JMP) {
1753 RuntimeMethod *new_method = rtm->data_items [* (guint16 *)(ip + 1)];
1754 if (!new_method->transformed) {
1756 frame->ex = mono_interp_transform_method (new_method, context);
1761 if (new_method->alloca_size > rtm->alloca_size)
1762 g_error ("MINT_JMP to method which needs more stack space (%d > %d)", new_method->alloca_size, rtm->alloca_size);
1763 rtm = frame->runtime_method = new_method;
1764 vt_sp = (unsigned char *) sp + rtm->stack_size;
1768 locals = vt_sp + rtm->vt_stack_size;
1769 ip = rtm->new_body_start; /* bypass storing input args from callers frame */
1772 MINT_IN_CASE(MINT_CALLI) {
1773 MonoMethodSignature *csignature;
1774 stackval *endsp = sp;
1778 csignature = rtm->data_items [* (guint16 *)(ip + 1)];
1782 child_frame.runtime_method = sp->data.p;
1785 child_frame.retval = sp;
1786 /* decrement by the actual number of args */
1787 sp -= csignature->param_count;
1788 if (csignature->hasthis)
1790 child_frame.stack_args = sp;
1791 if (csignature->hasthis && mono_object_is_transparent_proxy (sp->data.p)) {
1792 child_frame.runtime_method = mono_interp_get_runtime_method (context->domain, mono_marshal_get_remoting_invoke (child_frame.runtime_method->method), &error);
1793 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
1794 } else if (child_frame.runtime_method->method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) {
1795 child_frame.runtime_method = mono_interp_get_runtime_method (context->domain, mono_marshal_get_native_wrapper (child_frame.runtime_method->method, FALSE, FALSE), &error);
1796 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
1799 ves_exec_method_with_context (&child_frame, context);
1801 context->current_frame = frame;
1803 if (child_frame.ex) {
1805 * An exception occurred, need to run finally, fault and catch handlers..
1807 frame->ex = child_frame.ex;
1808 goto handle_finally;
1811 /* need to handle typedbyref ... */
1812 if (csignature->ret->type != MONO_TYPE_VOID) {
1818 MINT_IN_CASE(MINT_CALLI_NAT) {
1819 MonoMethodSignature *csignature;
1820 stackval *endsp = sp;
1821 unsigned char *code = NULL;
1825 csignature = rtm->data_items [* (guint16 *)(ip + 1)];
1830 child_frame.runtime_method = NULL;
1833 child_frame.retval = sp;
1834 /* decrement by the actual number of args */
1835 sp -= csignature->param_count;
1836 if (csignature->hasthis)
1838 child_frame.stack_args = sp;
1839 ves_pinvoke_method (&child_frame, csignature, (MonoFuncV) code, FALSE, context);
1841 context->current_frame = frame;
1843 if (child_frame.ex) {
1845 * An exception occurred, need to run finally, fault and catch handlers..
1847 frame->ex = child_frame.ex;
1848 if (context->search_for_handler) {
1849 context->search_for_handler = 0;
1850 goto handle_exception;
1852 goto handle_finally;
1855 /* need to handle typedbyref ... */
1856 if (csignature->ret->type != MONO_TYPE_VOID) {
1862 MINT_IN_CASE(MINT_CALL) {
1863 stackval *endsp = sp;
1867 child_frame.runtime_method = rtm->data_items [* (guint16 *)(ip + 1)];
1870 child_frame.retval = sp;
1871 /* decrement by the actual number of args */
1872 sp -= child_frame.runtime_method->param_count;
1873 if (child_frame.runtime_method->hasthis)
1875 child_frame.stack_args = sp;
1876 if (child_frame.runtime_method->hasthis && !child_frame.runtime_method->valuetype && mono_object_is_transparent_proxy (sp->data.p)) {
1877 child_frame.runtime_method = mono_interp_get_runtime_method (context->domain, mono_marshal_get_remoting_invoke (child_frame.runtime_method->method), &error);
1878 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
1880 ves_exec_method_with_context (&child_frame, context);
1882 context->current_frame = frame;
1884 if (child_frame.ex) {
1886 * An exception occurred, need to run finally, fault and catch handlers..
1888 frame->ex = child_frame.ex;
1889 goto handle_finally;
1892 /* need to handle typedbyref ... */
1897 MINT_IN_CASE(MINT_VCALL) {
1900 child_frame.runtime_method = rtm->data_items [* (guint16 *)(ip + 1)];
1904 child_frame.retval = sp;
1905 /* decrement by the actual number of args */
1906 sp -= child_frame.runtime_method->param_count;
1907 if (child_frame.runtime_method->hasthis)
1909 child_frame.stack_args = sp;
1911 if (child_frame.runtime_method->hasthis && !child_frame.runtime_method->valuetype && mono_object_is_transparent_proxy (sp->data.p)) {
1912 child_frame.runtime_method = mono_interp_get_runtime_method (context->domain, mono_marshal_get_remoting_invoke (child_frame.runtime_method->method), &error);
1913 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
1916 ves_exec_method_with_context (&child_frame, context);
1918 context->current_frame = frame;
1920 if (child_frame.ex) {
1922 * An exception occurred, need to run finally, fault and catch handlers..
1924 frame->ex = child_frame.ex;
1925 goto handle_finally;
1929 MINT_IN_CASE(MINT_CALLVIRT) {
1930 stackval *endsp = sp;
1931 MonoObject *this_arg;
1936 token = * (unsigned short *)(ip + 1);
1938 child_frame.runtime_method = rtm->data_items [token];
1940 child_frame.retval = sp;
1942 /* decrement by the actual number of args */
1943 sp -= child_frame.runtime_method->param_count + 1;
1944 child_frame.stack_args = sp;
1945 this_arg = sp->data.p;
1947 THROW_EX (mono_get_exception_null_reference(), ip - 2);
1948 child_frame.runtime_method = get_virtual_method (context->domain, child_frame.runtime_method, this_arg);
1950 if (this_arg->vtable->klass->valuetype && child_frame.runtime_method->valuetype) {
1951 sp->data.p = (char *) this_arg + sizeof (MonoObject);
1954 ves_exec_method_with_context (&child_frame, context);
1956 context->current_frame = frame;
1958 if (child_frame.ex) {
1960 * An exception occurred, need to run finally, fault and catch handlers..
1962 frame->ex = child_frame.ex;
1963 if (context->search_for_handler) {
1964 context->search_for_handler = 0;
1965 goto handle_exception;
1967 goto handle_finally;
1970 /* need to handle typedbyref ... */
1975 MINT_IN_CASE(MINT_VCALLVIRT) {
1976 MonoObject *this_arg;
1981 token = * (unsigned short *)(ip + 1);
1983 child_frame.runtime_method = rtm->data_items [token];
1985 child_frame.retval = sp;
1987 /* decrement by the actual number of args */
1988 sp -= child_frame.runtime_method->param_count + 1;
1989 child_frame.stack_args = sp;
1990 this_arg = sp->data.p;
1992 THROW_EX (mono_get_exception_null_reference(), ip - 2);
1993 child_frame.runtime_method = get_virtual_method (context->domain, child_frame.runtime_method, this_arg);
1995 if (this_arg->vtable->klass->valuetype && child_frame.runtime_method->valuetype) {
1996 sp->data.p = (char *) this_arg + sizeof (MonoObject);
1999 ves_exec_method_with_context (&child_frame, context);
2001 context->current_frame = frame;
2003 if (child_frame.ex) {
2005 * An exception occurred, need to run finally, fault and catch handlers..
2007 frame->ex = child_frame.ex;
2008 if (context->search_for_handler) {
2009 context->search_for_handler = 0;
2010 goto handle_exception;
2012 goto handle_finally;
2016 MINT_IN_CASE(MINT_CALLRUN)
2017 ves_runtime_method (frame, context);
2020 goto handle_exception;
2023 MINT_IN_CASE(MINT_RET)
2025 *frame->retval = *sp;
2026 if (sp > frame->stack)
2027 g_warning ("ret: more values on stack: %d", sp-frame->stack);
2029 MINT_IN_CASE(MINT_RET_VOID)
2030 if (sp > frame->stack)
2031 g_warning ("ret.void: more values on stack: %d", sp-frame->stack);
2033 MINT_IN_CASE(MINT_RET_VT)
2034 i32 = READ32(ip + 1);
2036 memcpy(frame->retval->data.p, sp->data.p, i32);
2037 if (sp > frame->stack)
2038 g_warning ("ret.vt: more values on stack: %d", sp-frame->stack);
2040 MINT_IN_CASE(MINT_BR_S)
2041 ip += (short) *(ip + 1);
2043 MINT_IN_CASE(MINT_BR)
2044 ip += (gint32) READ32(ip + 1);
2046 #define ZEROP_S(datamem, op) \
2048 if (sp->data.datamem op 0) \
2049 ip += * (gint16 *)(ip + 1); \
2053 #define ZEROP(datamem, op) \
2055 if (sp->data.datamem op 0) \
2056 ip += READ32(ip + 1); \
2060 MINT_IN_CASE(MINT_BRFALSE_I4_S)
2063 MINT_IN_CASE(MINT_BRFALSE_I8_S)
2066 MINT_IN_CASE(MINT_BRFALSE_R8_S)
2069 MINT_IN_CASE(MINT_BRFALSE_I4)
2072 MINT_IN_CASE(MINT_BRFALSE_I8)
2075 MINT_IN_CASE(MINT_BRFALSE_R8)
2078 MINT_IN_CASE(MINT_BRTRUE_I4_S)
2081 MINT_IN_CASE(MINT_BRTRUE_I8_S)
2084 MINT_IN_CASE(MINT_BRTRUE_R8_S)
2087 MINT_IN_CASE(MINT_BRTRUE_I4)
2090 MINT_IN_CASE(MINT_BRTRUE_I8)
2093 MINT_IN_CASE(MINT_BRTRUE_R8)
2096 #define CONDBR_S(cond) \
2099 ip += * (gint16 *)(ip + 1); \
2102 #define BRELOP_S(datamem, op) \
2103 CONDBR_S(sp[0].data.datamem op sp[1].data.datamem)
2105 #define CONDBR(cond) \
2108 ip += READ32(ip + 1); \
2112 #define BRELOP(datamem, op) \
2113 CONDBR(sp[0].data.datamem op sp[1].data.datamem)
2115 MINT_IN_CASE(MINT_BEQ_I4_S)
2118 MINT_IN_CASE(MINT_BEQ_I8_S)
2121 MINT_IN_CASE(MINT_BEQ_R8_S)
2122 CONDBR_S(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f == sp[1].data.f)
2124 MINT_IN_CASE(MINT_BEQ_I4)
2127 MINT_IN_CASE(MINT_BEQ_I8)
2130 MINT_IN_CASE(MINT_BEQ_R8)
2131 CONDBR(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f == sp[1].data.f)
2133 MINT_IN_CASE(MINT_BGE_I4_S)
2136 MINT_IN_CASE(MINT_BGE_I8_S)
2139 MINT_IN_CASE(MINT_BGE_R8_S)
2140 CONDBR_S(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f >= sp[1].data.f)
2142 MINT_IN_CASE(MINT_BGE_I4)
2145 MINT_IN_CASE(MINT_BGE_I8)
2148 MINT_IN_CASE(MINT_BGE_R8)
2149 CONDBR(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f >= sp[1].data.f)
2151 MINT_IN_CASE(MINT_BGT_I4_S)
2154 MINT_IN_CASE(MINT_BGT_I8_S)
2157 MINT_IN_CASE(MINT_BGT_R8_S)
2158 CONDBR_S(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f > sp[1].data.f)
2160 MINT_IN_CASE(MINT_BGT_I4)
2163 MINT_IN_CASE(MINT_BGT_I8)
2166 MINT_IN_CASE(MINT_BGT_R8)
2167 CONDBR(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f > sp[1].data.f)
2169 MINT_IN_CASE(MINT_BLT_I4_S)
2172 MINT_IN_CASE(MINT_BLT_I8_S)
2175 MINT_IN_CASE(MINT_BLT_R8_S)
2176 CONDBR_S(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f < sp[1].data.f)
2178 MINT_IN_CASE(MINT_BLT_I4)
2181 MINT_IN_CASE(MINT_BLT_I8)
2184 MINT_IN_CASE(MINT_BLT_R8)
2185 CONDBR(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f < sp[1].data.f)
2187 MINT_IN_CASE(MINT_BLE_I4_S)
2190 MINT_IN_CASE(MINT_BLE_I8_S)
2193 MINT_IN_CASE(MINT_BLE_R8_S)
2194 CONDBR_S(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f <= sp[1].data.f)
2196 MINT_IN_CASE(MINT_BLE_I4)
2199 MINT_IN_CASE(MINT_BLE_I8)
2202 MINT_IN_CASE(MINT_BLE_R8)
2203 CONDBR(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f <= sp[1].data.f)
2205 MINT_IN_CASE(MINT_BNE_UN_I4_S)
2208 MINT_IN_CASE(MINT_BNE_UN_I8_S)
2211 MINT_IN_CASE(MINT_BNE_UN_R8_S)
2212 CONDBR_S(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f != sp[1].data.f)
2214 MINT_IN_CASE(MINT_BNE_UN_I4)
2217 MINT_IN_CASE(MINT_BNE_UN_I8)
2220 MINT_IN_CASE(MINT_BNE_UN_R8)
2221 CONDBR(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f != sp[1].data.f)
2224 #define BRELOP_S_CAST(datamem, op, type) \
2226 if ((type) sp[0].data.datamem op (type) sp[1].data.datamem) \
2227 ip += * (gint16 *)(ip + 1); \
2231 #define BRELOP_CAST(datamem, op, type) \
2233 if ((type) sp[0].data.datamem op (type) sp[1].data.datamem) \
2234 ip += READ32(ip + 1); \
2238 MINT_IN_CASE(MINT_BGE_UN_I4_S)
2239 BRELOP_S_CAST(i, >=, guint32);
2241 MINT_IN_CASE(MINT_BGE_UN_I8_S)
2242 BRELOP_S_CAST(l, >=, guint64);
2244 MINT_IN_CASE(MINT_BGE_UN_R8_S)
2245 CONDBR_S(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f >= sp[1].data.f)
2247 MINT_IN_CASE(MINT_BGE_UN_I4)
2248 BRELOP_CAST(i, >=, guint32);
2250 MINT_IN_CASE(MINT_BGE_UN_I8)
2251 BRELOP_CAST(l, >=, guint64);
2253 MINT_IN_CASE(MINT_BGE_UN_R8)
2254 CONDBR(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f >= sp[1].data.f)
2256 MINT_IN_CASE(MINT_BGT_UN_I4_S)
2257 BRELOP_S_CAST(i, >, guint32);
2259 MINT_IN_CASE(MINT_BGT_UN_I8_S)
2260 BRELOP_S_CAST(l, >, guint64);
2262 MINT_IN_CASE(MINT_BGT_UN_R8_S)
2263 CONDBR_S(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f > sp[1].data.f)
2265 MINT_IN_CASE(MINT_BGT_UN_I4)
2266 BRELOP_CAST(i, >, guint32);
2268 MINT_IN_CASE(MINT_BGT_UN_I8)
2269 BRELOP_CAST(l, >, guint64);
2271 MINT_IN_CASE(MINT_BGT_UN_R8)
2272 CONDBR(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f > sp[1].data.f)
2274 MINT_IN_CASE(MINT_BLE_UN_I4_S)
2275 BRELOP_S_CAST(i, <=, guint32);
2277 MINT_IN_CASE(MINT_BLE_UN_I8_S)
2278 BRELOP_S_CAST(l, <=, guint64);
2280 MINT_IN_CASE(MINT_BLE_UN_R8_S)
2281 CONDBR_S(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f <= sp[1].data.f)
2283 MINT_IN_CASE(MINT_BLE_UN_I4)
2284 BRELOP_CAST(i, <=, guint32);
2286 MINT_IN_CASE(MINT_BLE_UN_I8)
2287 BRELOP_CAST(l, <=, guint64);
2289 MINT_IN_CASE(MINT_BLE_UN_R8)
2290 CONDBR(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f <= sp[1].data.f)
2292 MINT_IN_CASE(MINT_BLT_UN_I4_S)
2293 BRELOP_S_CAST(i, <, guint32);
2295 MINT_IN_CASE(MINT_BLT_UN_I8_S)
2296 BRELOP_S_CAST(l, <, guint64);
2298 MINT_IN_CASE(MINT_BLT_UN_R8_S)
2299 CONDBR_S(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f < sp[1].data.f)
2301 MINT_IN_CASE(MINT_BLT_UN_I4)
2302 BRELOP_CAST(i, <, guint32);
2304 MINT_IN_CASE(MINT_BLT_UN_I8)
2305 BRELOP_CAST(l, <, guint64);
2307 MINT_IN_CASE(MINT_BLT_UN_R8)
2308 CONDBR(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f < sp[1].data.f)
2310 MINT_IN_CASE(MINT_SWITCH) {
2312 const unsigned short *st;
2318 if ((guint32)sp->data.i < n) {
2320 ip += 2 * (guint32)sp->data.i;
2321 offset = READ32 (ip);
2328 MINT_IN_CASE(MINT_LDIND_I1)
2330 sp[-1].data.i = *(gint8*)sp[-1].data.p;
2332 MINT_IN_CASE(MINT_LDIND_U1)
2334 sp[-1].data.i = *(guint8*)sp[-1].data.p;
2336 MINT_IN_CASE(MINT_LDIND_I2)
2338 sp[-1].data.i = *(gint16*)sp[-1].data.p;
2340 MINT_IN_CASE(MINT_LDIND_U2)
2342 sp[-1].data.i = *(guint16*)sp[-1].data.p;
2344 MINT_IN_CASE(MINT_LDIND_I4) /* Fall through */
2345 MINT_IN_CASE(MINT_LDIND_U4)
2347 sp[-1].data.i = *(gint32*)sp[-1].data.p;
2349 MINT_IN_CASE(MINT_LDIND_I8)
2351 sp[-1].data.l = *(gint64*)sp[-1].data.p;
2353 MINT_IN_CASE(MINT_LDIND_I)
2355 sp[-1].data.p = *(gpointer*)sp[-1].data.p;
2357 MINT_IN_CASE(MINT_LDIND_R4)
2359 sp[-1].data.f = *(gfloat*)sp[-1].data.p;
2361 MINT_IN_CASE(MINT_LDIND_R8)
2363 sp[-1].data.f = *(gdouble*)sp[-1].data.p;
2365 MINT_IN_CASE(MINT_LDIND_REF)
2367 sp[-1].data.p = *(gpointer*)sp[-1].data.p;
2369 MINT_IN_CASE(MINT_STIND_REF)
2372 * (gpointer *) sp->data.p = sp[1].data.p;
2374 MINT_IN_CASE(MINT_STIND_I1)
2377 * (gint8 *) sp->data.p = (gint8)sp[1].data.i;
2379 MINT_IN_CASE(MINT_STIND_I2)
2382 * (gint16 *) sp->data.p = (gint16)sp[1].data.i;
2384 MINT_IN_CASE(MINT_STIND_I4)
2387 * (gint32 *) sp->data.p = sp[1].data.i;
2389 MINT_IN_CASE(MINT_STIND_I)
2392 * (mono_i *) sp->data.p = (mono_i)sp[1].data.p;
2394 MINT_IN_CASE(MINT_STIND_I8)
2397 * (gint64 *) sp->data.p = sp[1].data.l;
2399 MINT_IN_CASE(MINT_STIND_R4)
2402 * (float *) sp->data.p = (gfloat)sp[1].data.f;
2404 MINT_IN_CASE(MINT_STIND_R8)
2407 * (double *) sp->data.p = sp[1].data.f;
2409 #define BINOP(datamem, op) \
2411 sp [-1].data.datamem = sp [-1].data.datamem op sp [0].data.datamem; \
2413 MINT_IN_CASE(MINT_ADD_I4)
2416 MINT_IN_CASE(MINT_ADD_I8)
2419 MINT_IN_CASE(MINT_ADD_R8)
2422 MINT_IN_CASE(MINT_ADD1_I4)
2426 MINT_IN_CASE(MINT_SUB_I4)
2429 MINT_IN_CASE(MINT_SUB_I8)
2432 MINT_IN_CASE(MINT_SUB_R8)
2435 MINT_IN_CASE(MINT_SUB1_I4)
2439 MINT_IN_CASE(MINT_MUL_I4)
2442 MINT_IN_CASE(MINT_MUL_I8)
2445 MINT_IN_CASE(MINT_MUL_R8)
2448 MINT_IN_CASE(MINT_DIV_I4)
2449 if (sp [-1].data.i == 0)
2450 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2451 if (sp [-1].data.i == (-1))
2452 THROW_EX (mono_get_exception_overflow (), ip);
2455 MINT_IN_CASE(MINT_DIV_I8)
2456 if (sp [-1].data.l == 0)
2457 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2458 if (sp [-1].data.l == (-1))
2459 THROW_EX (mono_get_exception_overflow (), ip);
2462 MINT_IN_CASE(MINT_DIV_R8)
2466 #define BINOP_CAST(datamem, op, type) \
2468 sp [-1].data.datamem = (type)sp [-1].data.datamem op (type)sp [0].data.datamem; \
2470 MINT_IN_CASE(MINT_DIV_UN_I4)
2471 if (sp [-1].data.i == 0)
2472 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2473 BINOP_CAST(i, /, guint32);
2475 MINT_IN_CASE(MINT_DIV_UN_I8)
2476 if (sp [-1].data.l == 0)
2477 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2478 BINOP_CAST(l, /, guint64);
2480 MINT_IN_CASE(MINT_REM_I4)
2481 if (sp [-1].data.i == 0)
2482 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2485 MINT_IN_CASE(MINT_REM_I8)
2486 if (sp [-1].data.l == 0)
2487 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2490 MINT_IN_CASE(MINT_REM_R8)
2491 /* FIXME: what do we actually do here? */
2493 sp [-1].data.f = fmod (sp [-1].data.f, sp [0].data.f);
2496 MINT_IN_CASE(MINT_REM_UN_I4)
2497 if (sp [-1].data.i == 0)
2498 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2499 BINOP_CAST(i, %, guint32);
2501 MINT_IN_CASE(MINT_REM_UN_I8)
2502 if (sp [-1].data.l == 0)
2503 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2504 BINOP_CAST(l, %, guint64);
2506 MINT_IN_CASE(MINT_AND_I4)
2509 MINT_IN_CASE(MINT_AND_I8)
2512 MINT_IN_CASE(MINT_OR_I4)
2515 MINT_IN_CASE(MINT_OR_I8)
2518 MINT_IN_CASE(MINT_XOR_I4)
2521 MINT_IN_CASE(MINT_XOR_I8)
2525 #define SHIFTOP(datamem, op) \
2527 sp [-1].data.datamem = sp [-1].data.datamem op sp [0].data.i; \
2530 MINT_IN_CASE(MINT_SHL_I4)
2533 MINT_IN_CASE(MINT_SHL_I8)
2536 MINT_IN_CASE(MINT_SHR_I4)
2539 MINT_IN_CASE(MINT_SHR_I8)
2542 MINT_IN_CASE(MINT_SHR_UN_I4)
2544 sp [-1].data.i = (guint32)sp [-1].data.i >> sp [0].data.i;
2547 MINT_IN_CASE(MINT_SHR_UN_I8)
2549 sp [-1].data.l = (guint64)sp [-1].data.l >> sp [0].data.i;
2552 MINT_IN_CASE(MINT_NEG_I4)
2553 sp [-1].data.i = - sp [-1].data.i;
2556 MINT_IN_CASE(MINT_NEG_I8)
2557 sp [-1].data.l = - sp [-1].data.l;
2560 MINT_IN_CASE(MINT_NEG_R8)
2561 sp [-1].data.f = - sp [-1].data.f;
2564 MINT_IN_CASE(MINT_NOT_I4)
2565 sp [-1].data.i = ~ sp [-1].data.i;
2568 MINT_IN_CASE(MINT_NOT_I8)
2569 sp [-1].data.l = ~ sp [-1].data.l;
2572 MINT_IN_CASE(MINT_CONV_I1_I4)
2573 sp [-1].data.i = (gint8)sp [-1].data.i;
2576 MINT_IN_CASE(MINT_CONV_I1_I8)
2577 sp [-1].data.i = (gint8)sp [-1].data.l;
2580 MINT_IN_CASE(MINT_CONV_I1_R8)
2581 sp [-1].data.i = (gint8)sp [-1].data.f;
2584 MINT_IN_CASE(MINT_CONV_U1_I4)
2585 sp [-1].data.i = (guint8)sp [-1].data.i;
2588 MINT_IN_CASE(MINT_CONV_U1_I8)
2589 sp [-1].data.i = (guint8)sp [-1].data.l;
2592 MINT_IN_CASE(MINT_CONV_U1_R8)
2593 sp [-1].data.i = (guint8)sp [-1].data.f;
2596 MINT_IN_CASE(MINT_CONV_I2_I4)
2597 sp [-1].data.i = (gint16)sp [-1].data.i;
2600 MINT_IN_CASE(MINT_CONV_I2_I8)
2601 sp [-1].data.i = (gint16)sp [-1].data.l;
2604 MINT_IN_CASE(MINT_CONV_I2_R8)
2605 sp [-1].data.i = (gint16)sp [-1].data.f;
2608 MINT_IN_CASE(MINT_CONV_U2_I4)
2609 sp [-1].data.i = (guint16)sp [-1].data.i;
2612 MINT_IN_CASE(MINT_CONV_U2_I8)
2613 sp [-1].data.i = (guint16)sp [-1].data.l;
2616 MINT_IN_CASE(MINT_CONV_U2_R8)
2617 sp [-1].data.i = (guint16)sp [-1].data.f;
2620 MINT_IN_CASE(MINT_CONV_I4_R8)
2621 sp [-1].data.i = (gint32)sp [-1].data.f;
2624 MINT_IN_CASE(MINT_CONV_U4_I8)
2625 MINT_IN_CASE(MINT_CONV_I4_I8)
2626 sp [-1].data.i = (gint32)sp [-1].data.l;
2629 MINT_IN_CASE(MINT_CONV_I4_I8_SP)
2630 sp [-2].data.i = (gint32)sp [-2].data.l;
2633 MINT_IN_CASE(MINT_CONV_U4_R8)
2634 sp [-1].data.i = (guint32)sp [-1].data.f;
2637 MINT_IN_CASE(MINT_CONV_I8_I4)
2638 sp [-1].data.l = sp [-1].data.i;
2641 MINT_IN_CASE(MINT_CONV_I8_I4_SP)
2642 sp [-2].data.l = sp [-2].data.i;
2645 MINT_IN_CASE(MINT_CONV_I8_U4)
2646 sp [-1].data.l = (guint32)sp [-1].data.i;
2649 MINT_IN_CASE(MINT_CONV_I8_R8)
2650 sp [-1].data.l = (gint64)sp [-1].data.f;
2653 MINT_IN_CASE(MINT_CONV_R4_I4)
2654 sp [-1].data.f = (float)sp [-1].data.i;
2657 MINT_IN_CASE(MINT_CONV_R4_I8)
2658 sp [-1].data.f = (float)sp [-1].data.l;
2661 MINT_IN_CASE(MINT_CONV_R4_R8)
2662 sp [-1].data.f = (float)sp [-1].data.f;
2665 MINT_IN_CASE(MINT_CONV_R8_I4)
2666 sp [-1].data.f = (double)sp [-1].data.i;
2669 MINT_IN_CASE(MINT_CONV_R8_I8)
2670 sp [-1].data.f = (double)sp [-1].data.l;
2673 MINT_IN_CASE(MINT_CONV_U8_I4)
2674 sp [-1].data.l = sp [-1].data.i & 0xffffffff;
2677 MINT_IN_CASE(MINT_CONV_U8_R8)
2678 sp [-1].data.l = (guint64)sp [-1].data.f;
2682 MINT_IN_CASE(MINT_CPOBJ) {
2685 vtklass = rtm->data_items[READ32 (ip)];
2688 memcpy (sp [0].data.p, sp [1].data.p, mono_class_value_size (vtklass, NULL));
2692 MINT_IN_CASE(MINT_LDOBJ) {
2695 c = rtm->data_items[* (guint16 *)(ip + 1)];
2697 if (c->byval_arg.type != MONO_TYPE_VALUETYPE || c->byval_arg.data.klass->enumtype) {
2699 stackval_from_data (&c->byval_arg, &sp [-1], p, FALSE);
2701 size = mono_class_value_size (c, NULL);
2703 sp [-1].data.p = vt_sp;
2704 memcpy(vt_sp, p, size);
2705 vt_sp += (size + 7) & ~7;
2709 MINT_IN_CASE(MINT_LDSTR)
2710 sp->data.p = rtm->data_items [* (guint16 *)(ip + 1)];
2714 MINT_IN_CASE(MINT_NEWOBJ) {
2715 MonoClass *newobj_class;
2716 MonoMethodSignature *csig;
2717 stackval valuetype_this;
2723 token = * (guint16 *)(ip + 1);
2726 child_frame.runtime_method = rtm->data_items [token];
2727 csig = mono_method_signature (child_frame.runtime_method->method);
2728 newobj_class = child_frame.runtime_method->method->klass;
2729 /*if (profiling_classes) {
2730 guint count = GPOINTER_TO_UINT (g_hash_table_lookup (profiling_classes, newobj_class));
2732 g_hash_table_insert (profiling_classes, newobj_class, GUINT_TO_POINTER (count));
2735 if (newobj_class->parent == mono_defaults.array_class) {
2736 sp -= csig->param_count;
2737 o = ves_array_create (context->domain, newobj_class, csig, sp);
2738 goto array_constructed;
2741 g_assert (csig->hasthis);
2742 if (csig->param_count) {
2743 sp -= csig->param_count;
2744 memmove (sp + 1, sp, csig->param_count * sizeof (stackval));
2746 child_frame.stack_args = sp;
2749 * First arg is the object.
2751 if (newobj_class->valuetype) {
2752 MonoType *t = &newobj_class->byval_arg;
2753 if (!newobj_class->enumtype && (t->type == MONO_TYPE_VALUETYPE || (t->type == MONO_TYPE_GENERICINST && mono_type_generic_inst_is_valuetype (t)))) {
2755 valuetype_this.data.p = vt_sp;
2757 memset (&valuetype_this, 0, sizeof (stackval));
2758 sp->data.p = &valuetype_this;
2761 if (newobj_class != mono_defaults.string_class) {
2762 context->managed_code = 0;
2763 o = mono_object_new_checked (context->domain, newobj_class, &error);
2764 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2765 context->managed_code = 1;
2766 if (*mono_thread_interruption_request_flag ())
2767 mono_thread_interruption_checkpoint ();
2770 child_frame.retval = &retval;
2774 g_assert (csig->call_convention == MONO_CALL_DEFAULT);
2776 child_frame.ip = NULL;
2777 child_frame.ex = NULL;
2779 ves_exec_method_with_context (&child_frame, context);
2781 context->current_frame = frame;
2783 if (child_frame.ex) {
2785 * An exception occurred, need to run finally, fault and catch handlers..
2787 frame->ex = child_frame.ex;
2788 goto handle_finally;
2791 * a constructor returns void, but we need to return the object we created
2794 if (newobj_class->valuetype && !newobj_class->enumtype) {
2795 *sp = valuetype_this;
2796 } else if (newobj_class == mono_defaults.string_class) {
2804 MINT_IN_CASE(MINT_CASTCLASS)
2805 c = rtm->data_items [*(guint16 *)(ip + 1)];
2806 if ((o = sp [-1].data.p)) {
2807 MonoObject *isinst_obj = mono_object_isinst_checked (o, c, &error);
2808 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2810 THROW_EX (mono_get_exception_invalid_cast (), ip);
2814 MINT_IN_CASE(MINT_ISINST)
2815 c = rtm->data_items [*(guint16 *)(ip + 1)];
2816 if ((o = sp [-1].data.p)) {
2817 MonoObject *isinst_obj = mono_object_isinst_checked (o, c, &error);
2818 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2820 sp [-1].data.p = NULL;
2824 MINT_IN_CASE(MINT_CONV_R_UN_I4)
2825 sp [-1].data.f = (double)(guint32)sp [-1].data.i;
2828 MINT_IN_CASE(MINT_CONV_R_UN_I8)
2829 sp [-1].data.f = (double)(guint64)sp [-1].data.l;
2832 MINT_IN_CASE(MINT_UNBOX)
2833 c = rtm->data_items[*(guint16 *)(ip + 1)];
2837 THROW_EX (mono_get_exception_null_reference (), ip);
2839 MonoObject *isinst_obj = mono_object_isinst_checked (o, c, &error);
2840 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2841 if (!(isinst_obj || ((o->vtable->klass->rank == 0) && (o->vtable->klass->element_class == c->element_class))))
2842 THROW_EX (mono_get_exception_invalid_cast (), ip);
2844 if (c->byval_arg.type == MONO_TYPE_VALUETYPE && !c->enumtype) {
2845 int size = mono_class_native_size (c, NULL);
2846 sp [-1].data.p = vt_sp;
2847 vt_sp += (size + 7) & ~7;
2849 stackval_from_data (&c->byval_arg, &sp [-1], mono_object_unbox (o), FALSE);
2852 MINT_IN_CASE(MINT_THROW)
2854 frame->ex_handler = NULL;
2856 sp->data.p = mono_get_exception_null_reference ();
2857 THROW_EX ((MonoException *)sp->data.p, ip);
2859 MINT_IN_CASE(MINT_LDFLDA)
2862 THROW_EX (mono_get_exception_null_reference (), ip);
2863 sp[-1].data.p = (char *)o + * (guint16 *)(ip + 1);
2866 MINT_IN_CASE(MINT_CKNULL)
2869 THROW_EX (mono_get_exception_null_reference (), ip);
2873 #define LDFLD(datamem, fieldtype) \
2874 o = sp [-1].data.p; \
2876 THROW_EX (mono_get_exception_null_reference (), ip); \
2877 sp[-1].data.datamem = * (fieldtype *)((char *)o + * (guint16 *)(ip + 1)) ; \
2880 MINT_IN_CASE(MINT_LDFLD_I1) LDFLD(i, gint8); MINT_IN_BREAK;
2881 MINT_IN_CASE(MINT_LDFLD_U1) LDFLD(i, guint8); MINT_IN_BREAK;
2882 MINT_IN_CASE(MINT_LDFLD_I2) LDFLD(i, gint16); MINT_IN_BREAK;
2883 MINT_IN_CASE(MINT_LDFLD_U2) LDFLD(i, guint16); MINT_IN_BREAK;
2884 MINT_IN_CASE(MINT_LDFLD_I4) LDFLD(i, gint32); MINT_IN_BREAK;
2885 MINT_IN_CASE(MINT_LDFLD_I8) LDFLD(l, gint64); MINT_IN_BREAK;
2886 MINT_IN_CASE(MINT_LDFLD_R4) LDFLD(f, float); MINT_IN_BREAK;
2887 MINT_IN_CASE(MINT_LDFLD_R8) LDFLD(f, double); MINT_IN_BREAK;
2888 MINT_IN_CASE(MINT_LDFLD_O) LDFLD(p, gpointer); MINT_IN_BREAK;
2889 MINT_IN_CASE(MINT_LDFLD_P) LDFLD(p, gpointer); MINT_IN_BREAK;
2891 MINT_IN_CASE(MINT_LDFLD_VT)
2894 THROW_EX (mono_get_exception_null_reference (), ip);
2895 i32 = READ32(ip + 2);
2896 sp [-1].data.p = vt_sp;
2897 memcpy(sp [-1].data.p, (char *)o + * (guint16 *)(ip + 1), i32);
2898 vt_sp += (i32 + 7) & ~7;
2902 MINT_IN_CASE(MINT_LDRMFLD) {
2904 MonoClassField *field;
2909 THROW_EX (mono_get_exception_null_reference (), ip);
2910 field = rtm->data_items[* (guint16 *)(ip + 1)];
2912 if (mono_object_is_transparent_proxy (o)) {
2913 MonoClass *klass = ((MonoTransparentProxy*)o)->remote_class->proxy_class;
2915 addr = mono_load_remote_field_checked (o, klass, field, &tmp, &error);
2916 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2918 addr = (char*)o + field->offset;
2921 stackval_from_data (field->type, &sp [-1], addr, FALSE);
2925 MINT_IN_CASE(MINT_LDRMFLD_VT) {
2926 MonoClassField *field;
2932 THROW_EX (mono_get_exception_null_reference (), ip);
2933 field = rtm->data_items[* (guint16 *)(ip + 1)];
2934 i32 = READ32(ip + 2);
2936 if (mono_object_is_transparent_proxy (o)) {
2937 MonoClass *klass = ((MonoTransparentProxy*)o)->remote_class->proxy_class;
2938 addr = mono_load_remote_field_checked (o, klass, field, &tmp, &error);
2939 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2941 addr = (char*)o + field->offset;
2944 sp [-1].data.p = vt_sp;
2945 memcpy(sp [-1].data.p, (char *)o + * (guint16 *)(ip + 1), i32);
2946 vt_sp += (i32 + 7) & ~7;
2947 memcpy(sp [-1].data.p, addr, i32);
2951 #define STFLD(datamem, fieldtype) \
2952 o = sp [-2].data.p; \
2954 THROW_EX (mono_get_exception_null_reference (), ip); \
2956 * (fieldtype *)((char *)o + * (guint16 *)(ip + 1)) = sp[1].data.datamem; \
2959 MINT_IN_CASE(MINT_STFLD_I1) STFLD(i, gint8); MINT_IN_BREAK;
2960 MINT_IN_CASE(MINT_STFLD_U1) STFLD(i, guint8); MINT_IN_BREAK;
2961 MINT_IN_CASE(MINT_STFLD_I2) STFLD(i, gint16); MINT_IN_BREAK;
2962 MINT_IN_CASE(MINT_STFLD_U2) STFLD(i, guint16); MINT_IN_BREAK;
2963 MINT_IN_CASE(MINT_STFLD_I4) STFLD(i, gint32); MINT_IN_BREAK;
2964 MINT_IN_CASE(MINT_STFLD_I8) STFLD(l, gint64); MINT_IN_BREAK;
2965 MINT_IN_CASE(MINT_STFLD_R4) STFLD(f, float); MINT_IN_BREAK;
2966 MINT_IN_CASE(MINT_STFLD_R8) STFLD(f, double); MINT_IN_BREAK;
2967 MINT_IN_CASE(MINT_STFLD_O) STFLD(p, gpointer); MINT_IN_BREAK;
2968 MINT_IN_CASE(MINT_STFLD_P) STFLD(p, gpointer); MINT_IN_BREAK;
2970 MINT_IN_CASE(MINT_STFLD_VT)
2973 THROW_EX (mono_get_exception_null_reference (), ip);
2974 i32 = READ32(ip + 2);
2976 memcpy((char *)o + * (guint16 *)(ip + 1), sp [1].data.p, i32);
2977 vt_sp -= (i32 + 7) & ~7;
2981 MINT_IN_CASE(MINT_STRMFLD) {
2982 MonoClassField *field;
2986 THROW_EX (mono_get_exception_null_reference (), ip);
2988 field = rtm->data_items[* (guint16 *)(ip + 1)];
2991 if (mono_object_is_transparent_proxy (o)) {
2992 MonoClass *klass = ((MonoTransparentProxy*)o)->remote_class->proxy_class;
2993 mono_store_remote_field_checked (o, klass, field, &sp [-1].data, &error);
2994 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2996 stackval_to_data (field->type, &sp [-1], (char*)o + field->offset, FALSE);
3001 MINT_IN_CASE(MINT_STRMFLD_VT) {
3002 MonoClassField *field;
3006 THROW_EX (mono_get_exception_null_reference (), ip);
3007 field = rtm->data_items[* (guint16 *)(ip + 1)];
3008 i32 = READ32(ip + 2);
3011 if (mono_object_is_transparent_proxy (o)) {
3012 MonoClass *klass = ((MonoTransparentProxy*)o)->remote_class->proxy_class;
3013 mono_store_remote_field_checked (o, klass, field, &sp [-1].data, &error);
3014 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3016 memcpy((char*)o + field->offset, sp [-1].data.p, i32);
3019 vt_sp -= (i32 + 7) & ~7;
3022 MINT_IN_CASE(MINT_LDSFLDA) {
3023 MonoClassField *field = rtm->data_items[*(guint16 *)(ip + 1)];
3024 MonoVTable *vt = mono_class_vtable (context->domain, field->parent);
3027 if (!vt->initialized) {
3029 mono_runtime_class_init_full (vt, &error);
3030 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3034 if (context->domain->special_static_fields && (addr = g_hash_table_lookup (context->domain->special_static_fields, field)))
3035 sp->data.p = mono_get_special_static_data (GPOINTER_TO_UINT (addr));
3037 sp->data.p = (char*)(vt->vtable) + field->offset;
3041 MINT_IN_CASE(MINT_LDSFLD) {
3043 MonoClassField *field;
3046 field = rtm->data_items[*(guint16 *)(ip + 1)];
3047 vt = rtm->data_items [*(guint16 *)(ip + 2)];
3048 if (!vt->initialized) {
3050 mono_runtime_class_init_full (vt, &error);
3051 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3054 if (context->domain->special_static_fields && (addr = g_hash_table_lookup (context->domain->special_static_fields, field)))
3055 addr = mono_get_special_static_data (GPOINTER_TO_UINT (addr));
3057 addr = (char*)(vt->vtable) + field->offset;
3059 stackval_from_data (field->type, sp, addr, FALSE);
3063 MINT_IN_CASE(MINT_LDSFLD_I4) {
3064 MonoClassField *field = rtm->data_items[*(guint16 *)(ip + 1)];
3065 MonoVTable *vt = rtm->data_items [*(guint16 *)(ip + 2)];
3066 if (!vt->initialized) {
3068 mono_runtime_class_init_full (vt, &error);
3069 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3072 sp->data.i = * (gint32 *)((char*)(vt->vtable) + field->offset);
3076 MINT_IN_CASE(MINT_LDSFLD_O) {
3077 MonoClassField *field = rtm->data_items[*(guint16 *)(ip + 1)];
3078 MonoVTable *vt = rtm->data_items [*(guint16 *)(ip + 2)];
3079 if (!vt->initialized) {
3081 mono_runtime_class_init_full (vt, &error);
3082 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3085 sp->data.p = * (gpointer *)((char*)(vt->vtable) + field->offset);
3089 MINT_IN_CASE(MINT_LDSFLD_VT) {
3091 MonoClassField *field;
3096 token = * (guint16 *)(ip + 1);
3097 size = READ32(ip + 2);
3098 field = rtm->data_items[token];
3101 vt = mono_class_vtable (context->domain, field->parent);
3102 if (!vt->initialized) {
3104 mono_runtime_class_init_full (vt, &error);
3105 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3108 if (context->domain->special_static_fields && (addr = g_hash_table_lookup (context->domain->special_static_fields, field)))
3109 addr = mono_get_special_static_data (GPOINTER_TO_UINT (addr));
3111 addr = (char*)(vt->vtable) + field->offset;
3114 vt_sp += (size + 7) & ~7;
3115 stackval_from_data (field->type, sp, addr, FALSE);
3119 MINT_IN_CASE(MINT_STSFLD) {
3121 MonoClassField *field;
3125 token = * (guint16 *)(ip + 1);
3126 field = rtm->data_items[token];
3130 vt = mono_class_vtable (context->domain, field->parent);
3131 if (!vt->initialized) {
3133 mono_runtime_class_init_full (vt, &error);
3134 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3137 if (context->domain->special_static_fields && (addr = g_hash_table_lookup (context->domain->special_static_fields, field)))
3138 addr = mono_get_special_static_data (GPOINTER_TO_UINT (addr));
3140 addr = (char*)(vt->vtable) + field->offset;
3142 stackval_to_data (field->type, sp, addr, FALSE);
3145 MINT_IN_CASE(MINT_STSFLD_VT) {
3147 MonoClassField *field;
3152 token = * (guint16 *)(ip + 1);
3153 size = READ32(ip + 2);
3154 field = rtm->data_items[token];
3157 vt = mono_class_vtable (context->domain, field->parent);
3158 if (!vt->initialized) {
3160 mono_runtime_class_init_full (vt, &error);
3161 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3164 if (context->domain->special_static_fields && (addr = g_hash_table_lookup (context->domain->special_static_fields, field)))
3165 addr = mono_get_special_static_data (GPOINTER_TO_UINT (addr));
3167 addr = (char*)(vt->vtable) + field->offset;
3169 stackval_to_data (field->type, sp, addr, FALSE);
3170 vt_sp -= (size + 7) & ~7;
3173 MINT_IN_CASE(MINT_STOBJ_VT) {
3175 c = rtm->data_items[* (guint16 *)(ip + 1)];
3177 size = mono_class_value_size (c, NULL);
3178 memcpy(sp [-2].data.p, sp [-1].data.p, size);
3179 vt_sp -= (size + 7) & ~7;
3183 MINT_IN_CASE(MINT_STOBJ) {
3185 c = rtm->data_items[* (guint16 *)(ip + 1)];
3187 size = mono_class_value_size (c, NULL);
3188 memcpy(sp [-2].data.p, &sp [-1].data, size);
3192 MINT_IN_CASE(MINT_CONV_OVF_I4_UN_R8)
3193 if (sp [-1].data.f < 0 || sp [-1].data.f > MYGUINT32_MAX)
3194 THROW_EX (mono_get_exception_overflow (), ip);
3195 sp [-1].data.i = (guint32)sp [-1].data.f;
3198 MINT_IN_CASE(MINT_CONV_OVF_U8_I4)
3199 if (sp [-1].data.i < 0)
3200 THROW_EX (mono_get_exception_overflow (), ip);
3201 sp [-1].data.l = sp [-1].data.i;
3204 MINT_IN_CASE(MINT_CONV_OVF_U8_R8)
3205 MINT_IN_CASE(MINT_CONV_OVF_I8_UN_R8)
3206 if (sp [-1].data.f < 0 || sp [-1].data.f > 9223372036854775807LL)
3207 THROW_EX (mono_get_exception_overflow (), ip);
3208 sp [-1].data.l = (guint64)sp [-1].data.f;
3211 MINT_IN_CASE(MINT_CONV_OVF_I8_R8)
3212 if (sp [-1].data.f < MYGINT64_MIN || sp [-1].data.f > MYGINT64_MAX)
3213 THROW_EX (mono_get_exception_overflow (), ip);
3214 sp [-1].data.l = (gint64)sp [-1].data.f;
3217 MINT_IN_CASE(MINT_CONV_OVF_I4_UN_I8)
3218 if ((mono_u)sp [-1].data.l > MYGUINT32_MAX)
3219 THROW_EX (mono_get_exception_overflow (), ip);
3220 sp [-1].data.i = (mono_u)sp [-1].data.l;
3223 MINT_IN_CASE(MINT_BOX)
3224 c = rtm->data_items [* (guint16 *)(ip + 1)];
3226 if (c->byval_arg.type == MONO_TYPE_VALUETYPE && !c->enumtype) {
3227 int size = mono_class_value_size (c, NULL);
3228 sp [-1].data.p = mono_value_box_checked (context->domain, c, sp [-1].data.p, &error);
3229 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3230 size = (size + 7) & ~7;
3234 stackval_to_data (&c->byval_arg, &sp [-1], (char*)&sp [-1], FALSE);
3235 sp [-1].data.p = mono_value_box_checked (context->domain, c, &sp [-1], &error);
3236 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3240 MINT_IN_CASE(MINT_NEWARR)
3241 sp [-1].data.p = (MonoObject*) mono_array_new_checked (context->domain, rtm->data_items[*(guint16 *)(ip + 1)], sp [-1].data.i, &error);
3242 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3244 /*if (profiling_classes) {
3245 guint count = GPOINTER_TO_UINT (g_hash_table_lookup (profiling_classes, o->vtable->klass));
3247 g_hash_table_insert (profiling_classes, o->vtable->klass, GUINT_TO_POINTER (count));
3251 MINT_IN_CASE(MINT_LDLEN)
3254 THROW_EX (mono_get_exception_null_reference (), ip);
3255 sp [-1].data.nati = mono_array_length ((MonoArray *)o);
3258 MINT_IN_CASE(MINT_GETCHR) {
3262 THROW_EX (mono_get_exception_null_reference (), ip);
3263 i32 = sp [-1].data.i;
3264 if (i32 < 0 || i32 >= mono_string_length (s))
3265 THROW_EX (mono_get_exception_index_out_of_range (), ip);
3267 sp [-1].data.i = mono_string_chars(s)[i32];
3271 MINT_IN_CASE(MINT_STRLEN)
3273 sp [-1].data.i = mono_string_length ((MonoString*)sp [-1].data.p);
3275 MINT_IN_CASE(MINT_ARRAY_RANK)
3278 THROW_EX (mono_get_exception_null_reference (), ip);
3279 sp [-1].data.i = mono_object_class (sp [-1].data.p)->rank;
3282 MINT_IN_CASE(MINT_LDELEMA) {
3286 /*token = READ32 (ip)*/;
3292 aindex = sp [1].data.i;
3293 if (aindex >= mono_array_length ((MonoArray *) o))
3294 THROW_EX (mono_get_exception_index_out_of_range (), ip - 2);
3296 /* check the array element corresponds to token */
3297 esize = mono_array_element_size (((MonoArray *) o)->obj.vtable->klass);
3299 sp->data.p = mono_array_addr_with_size ((MonoArray *) o, esize, aindex);
3303 MINT_IN_CASE(MINT_LDELEM_I1) /* fall through */
3304 MINT_IN_CASE(MINT_LDELEM_U1) /* fall through */
3305 MINT_IN_CASE(MINT_LDELEM_I2) /* fall through */
3306 MINT_IN_CASE(MINT_LDELEM_U2) /* fall through */
3307 MINT_IN_CASE(MINT_LDELEM_I4) /* fall through */
3308 MINT_IN_CASE(MINT_LDELEM_U4) /* fall through */
3309 MINT_IN_CASE(MINT_LDELEM_I8) /* fall through */
3310 MINT_IN_CASE(MINT_LDELEM_I) /* fall through */
3311 MINT_IN_CASE(MINT_LDELEM_R4) /* fall through */
3312 MINT_IN_CASE(MINT_LDELEM_R8) /* fall through */
3313 MINT_IN_CASE(MINT_LDELEM_REF) {
3321 THROW_EX (mono_get_exception_null_reference (), ip);
3323 aindex = sp [1].data.i;
3324 if (aindex >= mono_array_length (o))
3325 THROW_EX (mono_get_exception_index_out_of_range (), ip);
3328 * FIXME: throw mono_get_exception_array_type_mismatch () if needed
3331 case MINT_LDELEM_I1:
3332 sp [0].data.i = mono_array_get (o, gint8, aindex);
3334 case MINT_LDELEM_U1:
3335 sp [0].data.i = mono_array_get (o, guint8, aindex);
3337 case MINT_LDELEM_I2:
3338 sp [0].data.i = mono_array_get (o, gint16, aindex);
3340 case MINT_LDELEM_U2:
3341 sp [0].data.i = mono_array_get (o, guint16, aindex);
3344 sp [0].data.nati = mono_array_get (o, mono_i, aindex);
3346 case MINT_LDELEM_I4:
3347 sp [0].data.i = mono_array_get (o, gint32, aindex);
3349 case MINT_LDELEM_U4:
3350 sp [0].data.i = mono_array_get (o, guint32, aindex);
3352 case MINT_LDELEM_I8:
3353 sp [0].data.l = mono_array_get (o, guint64, aindex);
3355 case MINT_LDELEM_R4:
3356 sp [0].data.f = mono_array_get (o, float, aindex);
3358 case MINT_LDELEM_R8:
3359 sp [0].data.f = mono_array_get (o, double, aindex);
3361 case MINT_LDELEM_REF:
3362 sp [0].data.p = mono_array_get (o, gpointer, aindex);
3372 MINT_IN_CASE(MINT_STELEM_I) /* fall through */
3373 MINT_IN_CASE(MINT_STELEM_I1) /* fall through */
3374 MINT_IN_CASE(MINT_STELEM_I2) /* fall through */
3375 MINT_IN_CASE(MINT_STELEM_I4) /* fall through */
3376 MINT_IN_CASE(MINT_STELEM_I8) /* fall through */
3377 MINT_IN_CASE(MINT_STELEM_R4) /* fall through */
3378 MINT_IN_CASE(MINT_STELEM_R8) /* fall through */
3379 MINT_IN_CASE(MINT_STELEM_REF) {
3386 THROW_EX (mono_get_exception_null_reference (), ip);
3388 aindex = sp [1].data.i;
3389 if (aindex >= mono_array_length ((MonoArray *)o))
3390 THROW_EX (mono_get_exception_index_out_of_range (), ip);
3394 mono_array_set ((MonoArray *)o, mono_i, aindex, sp [2].data.nati);
3396 case MINT_STELEM_I1:
3397 mono_array_set ((MonoArray *)o, gint8, aindex, sp [2].data.i);
3399 case MINT_STELEM_I2:
3400 mono_array_set ((MonoArray *)o, gint16, aindex, sp [2].data.i);
3402 case MINT_STELEM_I4:
3403 mono_array_set ((MonoArray *)o, gint32, aindex, sp [2].data.i);
3405 case MINT_STELEM_I8:
3406 mono_array_set ((MonoArray *)o, gint64, aindex, sp [2].data.l);
3408 case MINT_STELEM_R4:
3409 mono_array_set ((MonoArray *)o, float, aindex, sp [2].data.f);
3411 case MINT_STELEM_R8:
3412 mono_array_set ((MonoArray *)o, double, aindex, sp [2].data.f);
3414 case MINT_STELEM_REF: {
3415 MonoObject *isinst_obj = mono_object_isinst_checked (sp [2].data.p, mono_object_class (o)->element_class, &error);
3416 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3417 if (sp [2].data.p && !isinst_obj)
3418 THROW_EX (mono_get_exception_array_type_mismatch (), ip);
3419 mono_array_set ((MonoArray *)o, gpointer, aindex, sp [2].data.p);
3428 MINT_IN_CASE(MINT_CONV_OVF_I4_U4)
3429 if (sp [-1].data.i < 0)
3430 THROW_EX (mono_get_exception_overflow (), ip);
3433 MINT_IN_CASE(MINT_CONV_OVF_I4_I8)
3434 if (sp [-1].data.l < MYGINT32_MIN || sp [-1].data.l > MYGINT32_MAX)
3435 THROW_EX (mono_get_exception_overflow (), ip);
3436 sp [-1].data.i = (gint32) sp [-1].data.l;
3439 MINT_IN_CASE(MINT_CONV_OVF_I4_R8)
3440 if (sp [-1].data.f < MYGINT32_MIN || sp [-1].data.f > MYGINT32_MAX)
3441 THROW_EX (mono_get_exception_overflow (), ip);
3442 sp [-1].data.i = (gint32) sp [-1].data.f;
3445 MINT_IN_CASE(MINT_CONV_OVF_U4_I4)
3446 if (sp [-1].data.i < 0)
3447 THROW_EX (mono_get_exception_overflow (), ip);
3450 MINT_IN_CASE(MINT_CONV_OVF_U4_I8)
3451 if (sp [-1].data.l < 0 || sp [-1].data.l > MYGUINT32_MAX)
3452 THROW_EX (mono_get_exception_overflow (), ip);
3453 sp [-1].data.i = (guint32) sp [-1].data.l;
3456 MINT_IN_CASE(MINT_CONV_OVF_U4_R8)
3457 if (sp [-1].data.f < 0 || sp [-1].data.f > MYGUINT32_MAX)
3458 THROW_EX (mono_get_exception_overflow (), ip);
3459 sp [-1].data.i = (guint32) sp [-1].data.f;
3462 MINT_IN_CASE(MINT_CONV_OVF_I2_I4)
3463 if (sp [-1].data.i < -32768 || sp [-1].data.i > 32767)
3464 THROW_EX (mono_get_exception_overflow (), ip);
3467 MINT_IN_CASE(MINT_CONV_OVF_I2_I8)
3468 if (sp [-1].data.l < -32768 || sp [-1].data.l > 32767)
3469 THROW_EX (mono_get_exception_overflow (), ip);
3470 sp [-1].data.i = (gint16) sp [-1].data.l;
3473 MINT_IN_CASE(MINT_CONV_OVF_I2_R8)
3474 if (sp [-1].data.f < -32768 || sp [-1].data.f > 32767)
3475 THROW_EX (mono_get_exception_overflow (), ip);
3476 sp [-1].data.i = (gint16) sp [-1].data.f;
3479 MINT_IN_CASE(MINT_CONV_OVF_U2_I4)
3480 if (sp [-1].data.i < 0 || sp [-1].data.i > 65535)
3481 THROW_EX (mono_get_exception_overflow (), ip);
3484 MINT_IN_CASE(MINT_CONV_OVF_U2_I8)
3485 if (sp [-1].data.l < 0 || sp [-1].data.l > 65535)
3486 THROW_EX (mono_get_exception_overflow (), ip);
3487 sp [-1].data.i = (guint16) sp [-1].data.l;
3490 MINT_IN_CASE(MINT_CONV_OVF_U2_R8)
3491 if (sp [-1].data.f < 0 || sp [-1].data.f > 65535)
3492 THROW_EX (mono_get_exception_overflow (), ip);
3493 sp [-1].data.i = (guint16) sp [-1].data.f;
3496 MINT_IN_CASE(MINT_CONV_OVF_I1_I4)
3497 if (sp [-1].data.i < -128 || sp [-1].data.i > 127)
3498 THROW_EX (mono_get_exception_overflow (), ip);
3501 MINT_IN_CASE(MINT_CONV_OVF_I1_I8)
3502 if (sp [-1].data.l < -128 || sp [-1].data.l > 127)
3503 THROW_EX (mono_get_exception_overflow (), ip);
3504 sp [-1].data.i = (gint8) sp [-1].data.l;
3507 MINT_IN_CASE(MINT_CONV_OVF_I1_R8)
3508 if (sp [-1].data.f < -128 || sp [-1].data.f > 127)
3509 THROW_EX (mono_get_exception_overflow (), ip);
3510 sp [-1].data.i = (gint8) sp [-1].data.f;
3513 MINT_IN_CASE(MINT_CONV_OVF_U1_I4)
3514 if (sp [-1].data.i < 0 || sp [-1].data.i > 255)
3515 THROW_EX (mono_get_exception_overflow (), ip);
3518 MINT_IN_CASE(MINT_CONV_OVF_U1_I8)
3519 if (sp [-1].data.l < 0 || sp [-1].data.l > 255)
3520 THROW_EX (mono_get_exception_overflow (), ip);
3521 sp [-1].data.i = (guint8) sp [-1].data.l;
3524 MINT_IN_CASE(MINT_CONV_OVF_U1_R8)
3525 if (sp [-1].data.f < 0 || sp [-1].data.f > 255)
3526 THROW_EX (mono_get_exception_overflow (), ip);
3527 sp [-1].data.i = (guint8) sp [-1].data.f;
3531 MINT_IN_CASE(MINT_LDELEM)
3532 MINT_IN_CASE(MINT_STELEM)
3533 MINT_IN_CASE(MINT_UNBOX_ANY)
3535 MINT_IN_CASE(MINT_REFANYVAL) ves_abort(); MINT_IN_BREAK;
3537 MINT_IN_CASE(MINT_CKFINITE)
3538 if (!isfinite(sp [-1].data.f))
3539 THROW_EX (mono_get_exception_arithmetic (), ip);
3543 MINT_IN_CASE(MINT_MKREFANY) ves_abort(); MINT_IN_BREAK;
3545 MINT_IN_CASE(MINT_LDTOKEN)
3548 * (gpointer *)sp->data.p = rtm->data_items[*(guint16 *)(ip + 1)];
3552 MINT_IN_CASE(MINT_ADD_OVF_I4)
3553 if (CHECK_ADD_OVERFLOW (sp [-2].data.i, sp [-1].data.i))
3554 THROW_EX (mono_get_exception_overflow (), ip);
3557 MINT_IN_CASE(MINT_ADD_OVF_I8)
3558 if (CHECK_ADD_OVERFLOW64 (sp [-2].data.l, sp [-1].data.l))
3559 THROW_EX (mono_get_exception_overflow (), ip);
3562 MINT_IN_CASE(MINT_ADD_OVF_UN_I4)
3563 if (CHECK_ADD_OVERFLOW_UN (sp [-2].data.i, sp [-1].data.i))
3564 THROW_EX (mono_get_exception_overflow (), ip);
3565 BINOP_CAST(i, +, guint32);
3567 MINT_IN_CASE(MINT_ADD_OVF_UN_I8)
3568 if (CHECK_ADD_OVERFLOW64_UN (sp [-2].data.l, sp [-1].data.l))
3569 THROW_EX (mono_get_exception_overflow (), ip);
3570 BINOP_CAST(l, +, guint64);
3572 MINT_IN_CASE(MINT_MUL_OVF_I4)
3573 if (CHECK_MUL_OVERFLOW (sp [-2].data.i, sp [-1].data.i))
3574 THROW_EX (mono_get_exception_overflow (), ip);
3577 MINT_IN_CASE(MINT_MUL_OVF_I8)
3578 if (CHECK_MUL_OVERFLOW64 (sp [-2].data.l, sp [-1].data.l))
3579 THROW_EX (mono_get_exception_overflow (), ip);
3582 MINT_IN_CASE(MINT_MUL_OVF_UN_I4)
3583 if (CHECK_MUL_OVERFLOW_UN (sp [-2].data.i, sp [-1].data.i))
3584 THROW_EX (mono_get_exception_overflow (), ip);
3585 BINOP_CAST(i, *, guint32);
3587 MINT_IN_CASE(MINT_MUL_OVF_UN_I8)
3588 if (CHECK_MUL_OVERFLOW64_UN (sp [-2].data.l, sp [-1].data.l))
3589 THROW_EX (mono_get_exception_overflow (), ip);
3590 BINOP_CAST(l, *, guint64);
3592 MINT_IN_CASE(MINT_SUB_OVF_I4)
3593 if (CHECK_SUB_OVERFLOW (sp [-2].data.i, sp [-1].data.i))
3594 THROW_EX (mono_get_exception_overflow (), ip);
3597 MINT_IN_CASE(MINT_SUB_OVF_I8)
3598 if (CHECK_SUB_OVERFLOW64 (sp [-2].data.l, sp [-1].data.l))
3599 THROW_EX (mono_get_exception_overflow (), ip);
3602 MINT_IN_CASE(MINT_SUB_OVF_UN_I4)
3603 if (CHECK_SUB_OVERFLOW_UN (sp [-2].data.i, sp [-1].data.i))
3604 THROW_EX (mono_get_exception_overflow (), ip);
3605 BINOP_CAST(i, -, guint32);
3607 MINT_IN_CASE(MINT_SUB_OVF_UN_I8)
3608 if (CHECK_SUB_OVERFLOW64_UN (sp [-2].data.l, sp [-1].data.l))
3609 THROW_EX (mono_get_exception_overflow (), ip);
3610 BINOP_CAST(l, -, guint64);
3612 MINT_IN_CASE(MINT_ENDFINALLY)
3614 ip = finally_ips->data;
3615 finally_ips = g_slist_remove (finally_ips, ip);
3622 MINT_IN_CASE(MINT_LEAVE) /* Fall through */
3623 MINT_IN_CASE(MINT_LEAVE_S)
3624 while (sp > frame->stack) {
3628 if (*ip == MINT_LEAVE_S) {
3629 ip += (short) *(ip + 1);
3631 ip += (gint32) READ32 (ip + 1);
3634 if (frame->ex_handler != NULL && MONO_OFFSET_IN_HANDLER(frame->ex_handler, frame->ip - rtm->code)) {
3635 frame->ex_handler = NULL;
3638 goto handle_finally;
3640 MINT_IN_CASE(MINT_ICALL_V_V)
3641 MINT_IN_CASE(MINT_ICALL_V_P)
3642 MINT_IN_CASE(MINT_ICALL_P_V)
3643 MINT_IN_CASE(MINT_ICALL_P_P)
3644 MINT_IN_CASE(MINT_ICALL_PP_V)
3645 MINT_IN_CASE(MINT_ICALL_PI_V)
3646 MINT_IN_CASE(MINT_ICALL_PP_P)
3647 MINT_IN_CASE(MINT_ICALL_PI_P)
3648 MINT_IN_CASE(MINT_ICALL_PPP_V)
3649 MINT_IN_CASE(MINT_ICALL_PPI_V)
3650 sp = do_icall (context, *ip, sp, rtm->data_items [*(guint16 *)(ip + 1)]);
3651 if (frame->ex != NULL)
3652 goto handle_exception;
3655 MINT_IN_CASE(MINT_MONO_LDPTR)
3656 sp->data.p = rtm->data_items [*(guint16 *)(ip + 1)];
3660 MINT_IN_CASE(MINT_MONO_NEWOBJ)
3661 sp->data.p = mono_object_new_checked (context->domain, rtm->data_items [*(guint16 *)(ip + 1)], &error);
3662 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3666 MINT_IN_CASE(MINT_MONO_FREE)
3669 g_error ("that doesn't seem right");
3670 g_free (sp->data.p);
3672 MINT_IN_CASE(MINT_MONO_RETOBJ)
3675 stackval_from_data (mono_method_signature (frame->runtime_method->method)->ret, frame->retval, sp->data.p,
3676 mono_method_signature (frame->runtime_method->method)->pinvoke);
3677 if (sp > frame->stack)
3678 g_warning ("retobj: more values on stack: %d", sp-frame->stack);
3681 #define RELOP(datamem, op) \
3683 sp [-1].data.i = sp [-1].data.datamem op sp [0].data.datamem; \
3685 MINT_IN_CASE(MINT_CEQ_I4)
3688 MINT_IN_CASE(MINT_CEQ0_I4)
3689 sp [-1].data.i = (sp [-1].data.i == 0);
3692 MINT_IN_CASE(MINT_CEQ_I8)
3695 MINT_IN_CASE(MINT_CEQ_R8)
3697 if (isunordered (sp [-1].data.f, sp [0].data.f))
3700 sp [-1].data.i = sp [-1].data.f == sp [0].data.f;
3703 MINT_IN_CASE(MINT_CGT_I4)
3706 MINT_IN_CASE(MINT_CGT_I8)
3709 MINT_IN_CASE(MINT_CGT_R8)
3711 if (isunordered (sp [-1].data.f, sp [0].data.f))
3714 sp [-1].data.i = sp [-1].data.f > sp [0].data.f;
3718 #define RELOP_CAST(datamem, op, type) \
3720 sp [-1].data.i = (type)sp [-1].data.datamem op (type)sp [0].data.datamem; \
3723 MINT_IN_CASE(MINT_CGT_UN_I4)
3724 RELOP_CAST(i, >, guint32);
3726 MINT_IN_CASE(MINT_CGT_UN_I8)
3727 RELOP_CAST(l, >, guint64);
3729 MINT_IN_CASE(MINT_CGT_UN_R8)
3731 if (isunordered (sp [-1].data.f, sp [0].data.f))
3734 sp [-1].data.i = sp [-1].data.f > sp [0].data.f;
3737 MINT_IN_CASE(MINT_CLT_I4)
3740 MINT_IN_CASE(MINT_CLT_I8)
3743 MINT_IN_CASE(MINT_CLT_R8)
3745 if (isunordered (sp [-1].data.f, sp [0].data.f))
3748 sp [-1].data.i = sp [-1].data.f < sp [0].data.f;
3751 MINT_IN_CASE(MINT_CLT_UN_I4)
3752 RELOP_CAST(i, <, guint32);
3754 MINT_IN_CASE(MINT_CLT_UN_I8)
3755 RELOP_CAST(l, <, guint64);
3757 MINT_IN_CASE(MINT_CLT_UN_R8)
3759 if (isunordered (sp [-1].data.f, sp [0].data.f))
3762 sp [-1].data.i = sp [-1].data.f < sp [0].data.f;
3765 MINT_IN_CASE(MINT_LDFTN) {
3766 sp->data.p = rtm->data_items [* (guint16 *)(ip + 1)];
3771 MINT_IN_CASE(MINT_LDVIRTFTN) {
3772 RuntimeMethod *m = rtm->data_items [* (guint16 *)(ip + 1)];
3776 THROW_EX (mono_get_exception_null_reference (), ip - 2);
3778 sp->data.p = get_virtual_method (context->domain, m, sp->data.p);
3783 MINT_IN_CASE(MINT_LDTHISA)
3784 g_error ("should not happen");
3785 // sp->data.p = &frame->obj;
3790 #define LDARG(datamem, argtype) \
3791 sp->data.datamem = * (argtype *)(frame->args + * (guint16 *)(ip + 1)); \
3795 MINT_IN_CASE(MINT_LDARG_I1) LDARG(i, gint8); MINT_IN_BREAK;
3796 MINT_IN_CASE(MINT_LDARG_U1) LDARG(i, guint8); MINT_IN_BREAK;
3797 MINT_IN_CASE(MINT_LDARG_I2) LDARG(i, gint16); MINT_IN_BREAK;
3798 MINT_IN_CASE(MINT_LDARG_U2) LDARG(i, guint16); MINT_IN_BREAK;
3799 MINT_IN_CASE(MINT_LDARG_I4) LDARG(i, gint32); MINT_IN_BREAK;
3800 MINT_IN_CASE(MINT_LDARG_I8) LDARG(l, gint64); MINT_IN_BREAK;
3801 MINT_IN_CASE(MINT_LDARG_R4) LDARG(f, float); MINT_IN_BREAK;
3802 MINT_IN_CASE(MINT_LDARG_R8) LDARG(f, double); MINT_IN_BREAK;
3803 MINT_IN_CASE(MINT_LDARG_O) LDARG(p, gpointer); MINT_IN_BREAK;
3804 MINT_IN_CASE(MINT_LDARG_P) LDARG(p, gpointer); MINT_IN_BREAK;
3806 MINT_IN_CASE(MINT_LDARG_VT)
3808 i32 = READ32(ip + 2);
3809 memcpy(sp->data.p, frame->args + * (guint16 *)(ip + 1), i32);
3810 vt_sp += (i32 + 7) & ~7;
3815 #define STARG(datamem, argtype) \
3817 * (argtype *)(frame->args + * (guint16 *)(ip + 1)) = sp->data.datamem; \
3820 MINT_IN_CASE(MINT_STARG_I1) STARG(i, gint8); MINT_IN_BREAK;
3821 MINT_IN_CASE(MINT_STARG_U1) STARG(i, guint8); MINT_IN_BREAK;
3822 MINT_IN_CASE(MINT_STARG_I2) STARG(i, gint16); MINT_IN_BREAK;
3823 MINT_IN_CASE(MINT_STARG_U2) STARG(i, guint16); MINT_IN_BREAK;
3824 MINT_IN_CASE(MINT_STARG_I4) STARG(i, gint32); MINT_IN_BREAK;
3825 MINT_IN_CASE(MINT_STARG_I8) STARG(l, gint64); MINT_IN_BREAK;
3826 MINT_IN_CASE(MINT_STARG_R4) STARG(f, float); MINT_IN_BREAK;
3827 MINT_IN_CASE(MINT_STARG_R8) STARG(f, double); MINT_IN_BREAK;
3828 MINT_IN_CASE(MINT_STARG_O) STARG(p, gpointer); MINT_IN_BREAK;
3829 MINT_IN_CASE(MINT_STARG_P) STARG(p, gpointer); MINT_IN_BREAK;
3831 MINT_IN_CASE(MINT_STARG_VT)
3832 i32 = READ32(ip + 2);
3834 memcpy(frame->args + * (guint16 *)(ip + 1), sp->data.p, i32);
3835 vt_sp -= (i32 + 7) & ~7;
3839 #define STINARG(datamem, argtype) \
3841 int n = * (guint16 *)(ip + 1); \
3842 * (argtype *)(frame->args + rtm->arg_offsets [n]) = frame->stack_args [n].data.datamem; \
3846 MINT_IN_CASE(MINT_STINARG_I1) STINARG(i, gint8); MINT_IN_BREAK;
3847 MINT_IN_CASE(MINT_STINARG_U1) STINARG(i, guint8); MINT_IN_BREAK;
3848 MINT_IN_CASE(MINT_STINARG_I2) STINARG(i, gint16); MINT_IN_BREAK;
3849 MINT_IN_CASE(MINT_STINARG_U2) STINARG(i, guint16); MINT_IN_BREAK;
3850 MINT_IN_CASE(MINT_STINARG_I4) STINARG(i, gint32); MINT_IN_BREAK;
3851 MINT_IN_CASE(MINT_STINARG_I8) STINARG(l, gint64); MINT_IN_BREAK;
3852 MINT_IN_CASE(MINT_STINARG_R4) STINARG(f, float); MINT_IN_BREAK;
3853 MINT_IN_CASE(MINT_STINARG_R8) STINARG(f, double); MINT_IN_BREAK;
3854 MINT_IN_CASE(MINT_STINARG_O) STINARG(p, gpointer); MINT_IN_BREAK;
3855 MINT_IN_CASE(MINT_STINARG_P) STINARG(p, gpointer); MINT_IN_BREAK;
3857 MINT_IN_CASE(MINT_STINARG_VT) {
3858 int n = * (guint16 *)(ip + 1);
3859 i32 = READ32(ip + 2);
3860 memcpy (frame->args + rtm->arg_offsets [n], frame->stack_args [n].data.p, i32);
3865 MINT_IN_CASE(MINT_LDARGA)
3866 sp->data.p = frame->args + * (guint16 *)(ip + 1);
3871 #define LDLOC(datamem, argtype) \
3872 sp->data.datamem = * (argtype *)(locals + * (guint16 *)(ip + 1)); \
3876 MINT_IN_CASE(MINT_LDLOC_I1) LDLOC(i, gint8); MINT_IN_BREAK;
3877 MINT_IN_CASE(MINT_LDLOC_U1) LDLOC(i, guint8); MINT_IN_BREAK;
3878 MINT_IN_CASE(MINT_LDLOC_I2) LDLOC(i, gint16); MINT_IN_BREAK;
3879 MINT_IN_CASE(MINT_LDLOC_U2) LDLOC(i, guint16); MINT_IN_BREAK;
3880 MINT_IN_CASE(MINT_LDLOC_I4) LDLOC(i, gint32); MINT_IN_BREAK;
3881 MINT_IN_CASE(MINT_LDLOC_I8) LDLOC(l, gint64); MINT_IN_BREAK;
3882 MINT_IN_CASE(MINT_LDLOC_R4) LDLOC(f, float); MINT_IN_BREAK;
3883 MINT_IN_CASE(MINT_LDLOC_R8) LDLOC(f, double); MINT_IN_BREAK;
3884 MINT_IN_CASE(MINT_LDLOC_O) LDLOC(p, gpointer); MINT_IN_BREAK;
3885 MINT_IN_CASE(MINT_LDLOC_P) LDLOC(p, gpointer); MINT_IN_BREAK;
3887 MINT_IN_CASE(MINT_LDLOC_VT)
3889 i32 = READ32(ip + 2);
3890 memcpy(sp->data.p, locals + * (guint16 *)(ip + 1), i32);
3891 vt_sp += (i32 + 7) & ~7;
3896 MINT_IN_CASE(MINT_LDLOCA_S)
3897 sp->data.p = locals + * (guint16 *)(ip + 1);
3902 #define STLOC(datamem, argtype) \
3904 * (argtype *)(locals + * (guint16 *)(ip + 1)) = sp->data.datamem; \
3907 MINT_IN_CASE(MINT_STLOC_I1) STLOC(i, gint8); MINT_IN_BREAK;
3908 MINT_IN_CASE(MINT_STLOC_U1) STLOC(i, guint8); MINT_IN_BREAK;
3909 MINT_IN_CASE(MINT_STLOC_I2) STLOC(i, gint16); MINT_IN_BREAK;
3910 MINT_IN_CASE(MINT_STLOC_U2) STLOC(i, guint16); MINT_IN_BREAK;
3911 MINT_IN_CASE(MINT_STLOC_I4) STLOC(i, gint32); MINT_IN_BREAK;
3912 MINT_IN_CASE(MINT_STLOC_I8) STLOC(l, gint64); MINT_IN_BREAK;
3913 MINT_IN_CASE(MINT_STLOC_R4) STLOC(f, float); MINT_IN_BREAK;
3914 MINT_IN_CASE(MINT_STLOC_R8) STLOC(f, double); MINT_IN_BREAK;
3915 MINT_IN_CASE(MINT_STLOC_O) STLOC(p, gpointer); MINT_IN_BREAK;
3916 MINT_IN_CASE(MINT_STLOC_P) STLOC(p, gpointer); MINT_IN_BREAK;
3918 #define STLOC_NP(datamem, argtype) \
3919 * (argtype *)(locals + * (guint16 *)(ip + 1)) = sp [-1].data.datamem; \
3922 MINT_IN_CASE(MINT_STLOC_NP_I4) STLOC_NP(i, gint32); MINT_IN_BREAK;
3923 MINT_IN_CASE(MINT_STLOC_NP_O) STLOC_NP(p, gpointer); MINT_IN_BREAK;
3925 MINT_IN_CASE(MINT_STLOC_VT)
3926 i32 = READ32(ip + 2);
3928 memcpy(locals + * (guint16 *)(ip + 1), sp->data.p, i32);
3929 vt_sp -= (i32 + 7) & ~7;
3933 MINT_IN_CASE(MINT_LOCALLOC)
3934 if (sp != frame->stack + 1) /*FIX?*/
3935 THROW_EX (mono_get_exception_execution_engine (NULL), ip);
3936 sp [-1].data.p = alloca (sp [-1].data.i);
3940 MINT_IN_CASE(MINT_ENDFILTER) ves_abort(); MINT_IN_BREAK;
3942 MINT_IN_CASE(MINT_INITOBJ)
3944 memset (sp->data.vt, 0, READ32(ip + 1));
3947 MINT_IN_CASE(MINT_CPBLK)
3949 if (!sp [0].data.p || !sp [1].data.p)
3950 THROW_EX (mono_get_exception_null_reference(), ip - 1);
3952 /* FIXME: value and size may be int64... */
3953 memcpy (sp [0].data.p, sp [1].data.p, sp [2].data.i);
3956 MINT_IN_CASE(MINT_CONSTRAINED_) {
3958 /* FIXME: implement */
3960 token = READ32 (ip);
3965 MINT_IN_CASE(MINT_INITBLK)
3968 THROW_EX (mono_get_exception_null_reference(), ip - 1);
3970 /* FIXME: value and size may be int64... */
3971 memset (sp [0].data.p, sp [1].data.i, sp [2].data.i);
3974 MINT_IN_CASE(MINT_NO_)
3975 /* FIXME: implement */
3979 MINT_IN_CASE(MINT_RETHROW)
3981 * need to clarify what this should actually do:
3982 * start the search from the last found handler in
3983 * this method or continue in the caller or what.
3984 * Also, do we need to run finally/fault handlers after a retrow?
3985 * Well, this implementation will follow the usual search
3986 * for an handler, considering the current ip as throw spot.
3987 * We need to NULL frame->ex_handler for the later code to
3988 * actually run the new found handler.
3990 frame->ex_handler = NULL;
3991 THROW_EX (frame->ex, ip - 1);
3994 g_print ("Unimplemented opcode: %04x %s at 0x%x\n", *ip, mono_interp_opname[*ip], ip-rtm->code);
3995 THROW_EX (mono_get_exception_execution_engine ("Unimplemented opcode"), ip);
3999 g_assert_not_reached ();
4001 * Exception handling code.
4002 * The exception object is stored in frame->ex.
4009 MonoInvocation *inv;
4010 MonoExceptionClause *clause;
4016 g_print ("* Handling exception '%s' at IL_%04x\n",
4017 frame->ex == NULL ? "** Unknown **" : mono_object_class (frame->ex)->name,
4018 rtm == NULL ? 0 : frame->ip - rtm->code);
4020 if (die_on_exception)
4023 for (inv = frame; inv; inv = inv->parent) {
4025 if (inv->runtime_method == NULL)
4027 method = inv->runtime_method->method;
4028 if (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL)
4030 if (method->iflags & (METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL | METHOD_IMPL_ATTRIBUTE_RUNTIME))
4032 if (inv->ip == NULL)
4034 ip_offset = inv->ip - inv->runtime_method->code;
4035 inv->ex_handler = NULL; /* clear this in case we are trhowing an exception while handling one - this one wins */
4036 for (i = 0; i < inv->runtime_method->num_clauses; ++i) {
4037 clause = &inv->runtime_method->clauses [i];
4038 if (clause->flags <= 1 && MONO_OFFSET_IN_CLAUSE (clause, ip_offset)) {
4039 if (!clause->flags) {
4040 MonoObject *isinst_obj = mono_object_isinst_checked ((MonoObject*)frame->ex, clause->data.catch_class, &error);
4041 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4044 * OK, we found an handler, now we need to execute the finally
4045 * and fault blocks before branching to the handler code.
4047 inv->ex_handler = clause;
4050 g_print ("* Found handler at '%s'\n", method->name);
4052 goto handle_finally;
4055 /* FIXME: handle filter clauses */
4062 * If we get here, no handler was found: print a stack trace.
4064 for (inv = frame; inv; inv = inv->parent) {
4065 if (inv->invoke_trap)
4066 goto handle_finally;
4069 ex_obj = (MonoObject*)frame->ex;
4070 mono_unhandled_exception (ex_obj);
4077 MonoExceptionClause *clause;
4078 GSList *old_list = finally_ips;
4079 MonoMethod *method = frame->runtime_method->method;
4080 MonoMethodHeader *header = mono_method_get_header_checked (method, &error);
4081 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4085 g_print ("* Handle finally IL_%04x\n", endfinally_ip == NULL ? 0 : endfinally_ip - rtm->code);
4087 if (rtm == NULL || (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL)
4088 || (method->iflags & (METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL | METHOD_IMPL_ATTRIBUTE_RUNTIME))) {
4091 ip_offset = frame->ip - rtm->code;
4093 if (endfinally_ip != NULL)
4094 finally_ips = g_slist_prepend(finally_ips, (void *)endfinally_ip);
4095 for (i = 0; i < header->num_clauses; ++i)
4096 if (frame->ex_handler == &rtm->clauses [i])
4100 clause = &rtm->clauses [i];
4101 if (MONO_OFFSET_IN_CLAUSE (clause, ip_offset) && (endfinally_ip == NULL || !(MONO_OFFSET_IN_CLAUSE (clause, endfinally_ip - rtm->code)))) {
4102 if (clause->flags == MONO_EXCEPTION_CLAUSE_FINALLY) {
4103 ip = rtm->code + clause->handler_offset;
4104 finally_ips = g_slist_prepend (finally_ips, (gpointer) ip);
4107 g_print ("* Found finally at IL_%04x with exception: %s\n", clause->handler_offset, frame->ex? "yes": "no");
4113 endfinally_ip = NULL;
4115 if (old_list != finally_ips && finally_ips) {
4116 ip = finally_ips->data;
4117 finally_ips = g_slist_remove (finally_ips, ip);
4118 sp = frame->stack; /* spec says stack should be empty at endfinally so it should be at the start too */
4123 * If an exception is set, we need to execute the fault handler, too,
4124 * otherwise, we continue normally.
4134 MonoExceptionClause *clause;
4135 MonoMethod *method = frame->runtime_method->method;
4136 MonoMethodHeader *header = mono_method_get_header_checked (method, &error);
4137 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4141 g_print ("* Handle fault\n");
4143 ip_offset = frame->ip - rtm->code;
4144 for (i = 0; i < header->num_clauses; ++i) {
4145 clause = &rtm->clauses [i];
4146 if (clause->flags == MONO_EXCEPTION_CLAUSE_FAULT && MONO_OFFSET_IN_CLAUSE (clause, ip_offset)) {
4147 ip = rtm->code + clause->handler_offset;
4150 g_print ("* Executing handler at IL_%04x\n", clause->handler_offset);
4156 * If the handler for the exception was found in this method, we jump
4157 * to it right away, otherwise we return and let the caller run
4158 * the finally, fault and catch blocks.
4159 * This same code should be present in the endfault opcode, but it
4160 * is corrently not assigned in the ECMA specs: LAMESPEC.
4162 if (frame->ex_handler) {
4165 g_print ("* Executing handler at IL_%04x\n", frame->ex_handler->handler_offset);
4167 ip = rtm->code + frame->ex_handler->handler_offset;
4169 vt_sp = (unsigned char *) sp + rtm->stack_size;
4170 sp->data.p = frame->ex;
4181 ves_exec_method (MonoInvocation *frame)
4183 ThreadContext *context = mono_native_tls_get_value (thread_context_id);
4184 ThreadContext context_struct;
4191 mono_unhandled_exception ((MonoObject*)frame->ex);
4194 if (context == NULL) {
4195 context = &context_struct;
4196 context_struct.domain = mono_domain_get ();
4197 context_struct.base_frame = frame;
4198 context_struct.current_frame = NULL;
4199 context_struct.env_frame = frame;
4200 context_struct.current_env = &env;
4201 context_struct.search_for_handler = 0;
4202 context_struct.managed_code = 0;
4203 mono_native_tls_set_value (thread_context_id, context);
4206 frame->parent = context->current_frame;
4207 frame->runtime_method = mono_interp_get_runtime_method (context->domain, frame->method, &error);
4208 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4209 context->managed_code = 1;
4210 ves_exec_method_with_context (frame, context);
4211 context->managed_code = 0;
4213 if (context != &context_struct && context->current_env) {
4214 context->env_frame->ex = frame->ex;
4215 longjmp (*context->current_env, 1);
4218 mono_unhandled_exception ((MonoObject*)frame->ex);
4220 if (context->base_frame == frame)
4221 mono_native_tls_set_value (thread_context_id, NULL);
4223 context->current_frame = frame->parent;
4227 ves_exec (MonoDomain *domain, MonoAssembly *assembly, int argc, char *argv[])
4229 MonoImage *image = mono_assembly_get_image (assembly);
4234 method = mono_get_method_checked (image, mono_image_get_entry_point (image), NULL, NULL, &error);
4235 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4238 g_error ("No entry point method found in %s", mono_image_get_filename (image));
4240 rval = mono_runtime_run_main_checked (method, argc, argv, &error);
4241 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4249 "mint %s, the Mono ECMA CLI interpreter, (C) 2001, 2002 Ximian, Inc.\n\n"
4250 "Usage is: mint [options] executable args...\n\n", VERSION);
4252 "Runtime Debugging:\n"
4257 " --noptr\t\t\tdon't print pointer addresses in trace output\n"
4260 " --traceclassinit\n"
4263 " --debug method_name\n"
4270 " --config filename load the specified config file instead of the default\n"
4271 " --workers n maximum number of worker threads\n"
4277 interp_ves_icall_get_frame_info (gint32 skip, MonoBoolean need_file_info,
4278 MonoReflectionMethod **method,
4279 gint32 *iloffset, gint32 *native_offset,
4280 MonoString **file, gint32 *line, gint32 *column)
4282 ThreadContext *context = mono_native_tls_get_value (thread_context_id);
4283 MonoInvocation *inv = context->current_frame;
4287 for (i = 0; inv && i < skip; inv = inv->parent)
4288 if (inv->runtime_method != NULL)
4299 *method = mono_method_get_object_checked (context->domain, inv->runtime_method->method, NULL, &error);
4300 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4305 if (need_file_info) {
4309 *file = mono_string_new (mono_domain_get (), "unknown");
4316 interp_ves_icall_get_trace (MonoException *exc, gint32 skip, MonoBoolean need_file_info)
4318 MonoDomain *domain = mono_domain_get ();
4320 MonoArray *ta = exc->trace_ips;
4325 /* Exception is not thrown yet */
4326 MonoArray *array = mono_array_new_checked (domain, mono_defaults.stack_frame_class, 0, &error);
4327 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4331 len = mono_array_length (ta);
4333 res = mono_array_new_checked (domain, mono_defaults.stack_frame_class, len > skip ? len - skip : 0, &error);
4334 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4336 for (i = skip; i < len / 2; i++) {
4337 MonoStackFrame *sf = (MonoStackFrame *)mono_object_new_checked (domain, mono_defaults.stack_frame_class, &error);
4338 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4339 gushort *ip = mono_array_get (ta, gpointer, 2 * i + 1);
4340 RuntimeMethod *rtm = mono_array_get (ta, gpointer, 2 * i);
4343 sf->method = mono_method_get_object_checked (domain, rtm->method, NULL, &error);
4344 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4345 sf->native_offset = ip - rtm->code;
4349 sf->il_offset = mono_debug_il_offset_from_address (ji->method, sf->native_offset, domain);
4351 if (need_file_info) {
4354 filename = mono_debug_source_location_from_address (ji->method, sf->native_offset, &sf->line, domain);
4356 sf->filename = filename? mono_string_new (domain, filename): NULL;
4363 mono_array_set (res, gpointer, i, sf);
4370 ves_icall_System_Delegate_CreateDelegate_internal (MonoReflectionType *type, MonoObject *target, MonoReflectionMethod *info)
4372 MonoClass *delegate_class = mono_class_from_mono_type (type->type);
4373 MonoObject *delegate;
4376 g_assert (delegate_class->parent == mono_defaults.multicastdelegate_class);
4378 delegate = mono_object_new_checked (mono_object_domain (type), delegate_class, &error);
4379 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4381 interp_delegate_ctor (mono_object_domain (type), delegate, target, mono_interp_get_runtime_method (mono_get_root_domain (), info->method, &error));
4382 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4390 mono_native_tls_alloc (&thread_context_id, NULL);
4391 mono_native_tls_set_value (thread_context_id, NULL);
4392 mono_os_mutex_init_recursive (&runtime_method_lookup_section);
4393 mono_os_mutex_init_recursive (&create_method_pointer_mutex);
4395 mono_interp_transform_init ();
4398 typedef int (*TestMethod) (void);
4401 interp_regression_step (MonoImage *image, int verbose, int *total_run, int *total, GTimer *timer, MonoDomain *domain)
4403 int result, expected, failed, cfailed, run;
4404 double elapsed, transform_time;
4406 MonoObject *result_obj;
4407 static gboolean filter_method_init = FALSE;
4408 static const char *filter_method = NULL;
4410 g_print ("Test run: image=%s\n", mono_image_get_filename (image));
4411 cfailed = failed = run = 0;
4412 transform_time = elapsed = 0.0;
4415 /* fixme: ugly hack - delete all previously compiled methods */
4416 if (domain_jit_info (domain)) {
4417 g_hash_table_destroy (domain_jit_info (domain)->jit_trampoline_hash);
4418 domain_jit_info (domain)->jit_trampoline_hash = g_hash_table_new (mono_aligned_addr_hash, NULL);
4419 mono_internal_hash_table_destroy (&(domain->jit_code_hash));
4420 mono_jit_code_hash_init (&(domain->jit_code_hash));
4424 g_timer_start (timer);
4425 for (i = 0; i < mono_image_get_table_rows (image, MONO_TABLE_METHOD); ++i) {
4427 MonoMethod *method = mono_get_method_checked (image, MONO_TOKEN_METHOD_DEF | (i + 1), NULL, NULL, &error);
4429 mono_error_cleanup (&error); /* FIXME don't swallow the error */
4433 if (!filter_method_init) {
4434 filter_method = g_getenv ("INTERP_FILTER_METHOD");
4435 filter_method_init = TRUE;
4437 gboolean filter = FALSE;
4438 if (filter_method) {
4439 const char *name = filter_method;
4441 if ((strchr (name, '.') > name) || strchr (name, ':')) {
4442 MonoMethodDesc *desc = mono_method_desc_new (name, TRUE);
4443 filter = mono_method_desc_full_match (desc, method);
4444 mono_method_desc_free (desc);
4446 filter = strcmp (method->name, name) == 0;
4448 } else { // no filter
4451 if (strncmp (method->name, "test_", 5) == 0 && filter) {
4452 MonoError interp_error;
4453 MonoObject *exc = NULL;
4455 result_obj = interp_mono_runtime_invoke (method, NULL, NULL, &exc, &interp_error);
4456 if (!mono_error_ok (&interp_error)) {
4458 g_print ("Test '%s' execution failed.\n", method->name);
4459 } else if (exc != NULL) {
4460 g_print ("Exception in Test '%s' occured:\n", method->name);
4461 mono_object_describe (exc);
4465 result = *(gint32 *) mono_object_unbox (result_obj);
4466 expected = atoi (method->name + 5); // FIXME: oh no.
4469 if (result != expected) {
4471 g_print ("Test '%s' failed result (got %d, expected %d).\n", method->name, result, expected);
4476 g_timer_stop (timer);
4477 elapsed = g_timer_elapsed (timer, NULL);
4478 if (failed > 0 || cfailed > 0){
4479 g_print ("Results: total tests: %d, failed: %d, cfailed: %d (pass: %.2f%%)\n",
4480 run, failed, cfailed, 100.0*(run-failed-cfailed)/run);
4482 g_print ("Results: total tests: %d, all pass \n", run);
4485 g_print ("Elapsed time: %f secs (%f, %f)\n\n", elapsed,
4486 elapsed - transform_time, transform_time);
4487 *total += failed + cfailed;
4491 interp_regression (MonoImage *image, int verbose, int *total_run)
4494 GTimer *timer = g_timer_new ();
4495 MonoDomain *domain = mono_domain_get ();
4499 /* load the metadata */
4500 for (i = 0; i < mono_image_get_table_rows (image, MONO_TABLE_METHOD); ++i) {
4502 method = mono_get_method_checked (image, MONO_TOKEN_METHOD_DEF | (i + 1), NULL, NULL, &error);
4504 mono_error_cleanup (&error);
4507 mono_class_init (method->klass);
4512 interp_regression_step (image, verbose, total_run, &total, timer, domain);
4514 g_timer_destroy (timer);
4519 interp_regression_list (int verbose, int count, char *images [])
4521 int i, total, total_run, run;
4523 total_run = total = 0;
4524 for (i = 0; i < count; ++i) {
4525 MonoAssembly *ass = mono_assembly_open (images [i], NULL);
4527 g_warning ("failed to load assembly: %s", images [i]);
4530 total += interp_regression (mono_assembly_get_image (ass), verbose, &run);
4534 g_print ("Overall results: tests: %d, failed: %d (pass: %.2f%%)\n", total_run, total, 100.0*(total_run-total)/total_run);
4536 g_print ("Overall results: tests: %d, 100%% pass\n", total_run);