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,obj_this,method_args,method_retval,domain,mono_method,error) \
80 (frame)->parent = (parent_frame); \
81 (frame)->obj = (obj_this); \
82 (frame)->stack_args = (method_args); \
83 (frame)->retval = (method_retval); \
84 (frame)->runtime_method = mono_interp_get_runtime_method ((domain), (mono_method), (error)); \
87 (frame)->invoke_trap = 0; \
90 void ves_exec_method (MonoInvocation *frame);
92 static char* dump_stack (stackval *stack, stackval *sp);
93 static char* dump_frame (MonoInvocation *inv);
94 static MonoArray *get_trace_ips (MonoDomain *domain, MonoInvocation *top);
95 static void ves_exec_method_with_context (MonoInvocation *frame, ThreadContext *context);
97 typedef void (*ICallMethod) (MonoInvocation *frame);
99 static guint32 die_on_exception = 0;
100 static MonoNativeTlsKey thread_context_id;
102 static char* dump_args (MonoInvocation *inv);
104 #define DEBUG_INTERP 0
107 int mono_interp_traceopt = 2;
108 /* If true, then we output the opcodes as we interpret them */
109 static int global_tracing = 1;
111 static int debug_indent_level = 0;
113 static int break_on_method = 0;
114 static int nested_trace = 0;
115 static GList *db_methods = NULL;
122 for (h = 0; h < debug_indent_level; h++)
127 db_match_method (gpointer data, gpointer user_data)
129 MonoMethod *m = (MonoMethod*)user_data;
130 MonoMethodDesc *desc = data;
132 if (mono_method_desc_full_match (desc, m))
136 static void debug_enter (MonoInvocation *frame, int *tracing)
139 g_list_foreach (db_methods, db_match_method, (gpointer)frame->runtime_method->method);
141 *tracing = nested_trace ? (global_tracing = 2, 3) : 2;
145 MonoMethod *method = frame->runtime_method->method;
146 char *mn, *args = dump_args (frame);
147 debug_indent_level++;
149 mn = mono_method_full_name (method, FALSE);
150 g_print ("(%p) Entering %s (", mono_thread_internal_current (), mn);
152 g_print ("%s)\n", args);
155 if (mono_profiler_events & MONO_PROFILE_ENTER_LEAVE)
156 mono_profiler_method_enter (frame->runtime_method->method);
160 #define DEBUG_LEAVE() \
163 args = dump_retval (frame); \
165 mn = mono_method_full_name (frame->runtime_method->method, FALSE); \
166 g_print ("(%p) Leaving %s", mono_thread_internal_current (), mn); \
168 g_print (" => %s\n", args); \
170 debug_indent_level--; \
171 if (tracing == 3) global_tracing = 0; \
173 if (mono_profiler_events & MONO_PROFILE_ENTER_LEAVE) \
174 mono_profiler_method_leave (frame->runtime_method->method);
178 int mono_interp_traceopt = 0;
179 static void debug_enter (MonoInvocation *frame, int *tracing)
182 #define DEBUG_LEAVE()
187 interp_ex_handler (MonoException *ex) {
189 ThreadContext *context = mono_native_tls_get_value (thread_context_id);
193 stack_trace = dump_frame (context->current_frame);
194 ex->stack_trace = mono_string_new (mono_domain_get(), stack_trace);
195 g_free (stack_trace);
196 if (context->current_env == NULL || strcmp(ex->object.vtable->klass->name, "ExecutionEngineException") == 0) {
197 char *strace = mono_string_to_utf8_checked (ex->stack_trace, &error);
198 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
199 fprintf(stderr, "Nothing can catch this exception: ");
200 fprintf(stderr, "%s", ex->object.vtable->klass->name);
201 if (ex->message != NULL) {
202 char *m = mono_string_to_utf8_checked (ex->message, &error);
203 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
204 fprintf(stderr, ": %s", m);
207 fprintf(stderr, "\n%s\n", strace);
209 if (ex->inner_ex != NULL) {
210 ex = (MonoException *)ex->inner_ex;
211 fprintf(stderr, "Inner exception: %s", ex->object.vtable->klass->name);
212 if (ex->message != NULL) {
213 char *m = mono_string_to_utf8_checked (ex->message, &error);
214 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
215 fprintf(stderr, ": %s", m);
218 strace = mono_string_to_utf8_checked (ex->stack_trace, &error);
219 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
220 fprintf(stderr, "\n");
221 fprintf(stderr, "%s\n", strace);
224 /* wait for other threads to also collapse */
225 // Sleep(1000); // TODO: proper sleep
228 context->env_frame->ex = ex;
229 context->search_for_handler = 1;
230 longjmp (*context->current_env, 1);
234 ves_real_abort (int line, MonoMethod *mh,
235 const unsigned short *ip, stackval *stack, stackval *sp)
238 fprintf (stderr, "Execution aborted in method: %s::%s\n", mh->klass->name, mh->name);
239 fprintf (stderr, "Line=%d IP=0x%04lx, Aborted execution\n", line,
240 ip-(const unsigned short *)mono_method_get_header_checked (mh, &error)->code);
241 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
242 g_print ("0x%04x %02x\n",
243 ip-(const unsigned short *)mono_method_get_header_checked (mh, &error)->code, *ip);
244 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
246 printf ("\t[%ld] 0x%08x %0.5f\n", sp-stack, sp[-1].data.i, sp[-1].data.f);
249 #define ves_abort() \
251 ves_real_abort(__LINE__, frame->runtime_method->method, ip, frame->stack, sp); \
252 THROW_EX (mono_get_exception_execution_engine (NULL), ip); \
255 static mono_mutex_t runtime_method_lookup_section;
258 mono_interp_get_runtime_method (MonoDomain *domain, MonoMethod *method, MonoError *error)
261 mono_error_init (error);
263 mono_os_mutex_lock (&runtime_method_lookup_section);
264 if ((rtm = mono_internal_hash_table_lookup (&domain->jit_code_hash, method))) {
265 mono_os_mutex_unlock (&runtime_method_lookup_section);
268 rtm = mono_mempool_alloc (domain->mp, sizeof (RuntimeMethod));
269 memset (rtm, 0, sizeof (*rtm));
270 rtm->method = method;
271 rtm->param_count = mono_method_signature (method)->param_count;
272 rtm->hasthis = mono_method_signature (method)->hasthis;
273 rtm->valuetype = method->klass->valuetype;
274 mono_internal_hash_table_insert (&domain->jit_code_hash, method, rtm);
275 mono_os_mutex_unlock (&runtime_method_lookup_section);
281 interp_create_trampoline (MonoDomain *domain, MonoMethod *method, MonoError *error)
283 if (method->iflags & METHOD_IMPL_ATTRIBUTE_SYNCHRONIZED)
284 method = mono_marshal_get_synchronized_wrapper (method);
285 return mono_interp_get_runtime_method (domain, method, error);
288 static inline RuntimeMethod*
289 get_virtual_method (MonoDomain *domain, RuntimeMethod *runtime_method, MonoObject *obj)
291 MonoMethod *m = runtime_method->method;
294 if ((m->flags & METHOD_ATTRIBUTE_FINAL) || !(m->flags & METHOD_ATTRIBUTE_VIRTUAL)) {
295 RuntimeMethod *ret = NULL;
296 if (mono_object_is_transparent_proxy (obj)) {
297 ret = mono_interp_get_runtime_method (domain, mono_marshal_get_remoting_invoke (m), &error);
298 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
299 } else if (m->iflags & METHOD_IMPL_ATTRIBUTE_SYNCHRONIZED) {
300 ret = mono_interp_get_runtime_method (domain, mono_marshal_get_synchronized_wrapper (m), &error);
301 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
303 ret = runtime_method;
308 int slot = mono_method_get_vtable_slot (m);
309 if (mono_class_is_interface (m->klass)) {
310 g_assert (obj->vtable->klass != m->klass);
311 /* TODO: interface offset lookup is slow, go through IMT instead */
312 slot += mono_class_interface_offset (obj->vtable->klass, m->klass);
314 MonoMethod *virtual_method = obj->vtable->klass->vtable [slot];
315 RuntimeMethod *virtual_runtime_method = mono_interp_get_runtime_method (domain, virtual_method, &error);
316 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
317 return virtual_runtime_method;
321 stackval_from_data (MonoType *type, stackval *result, char *data, gboolean pinvoke)
324 switch (type->type) {
325 case MONO_TYPE_OBJECT:
326 case MONO_TYPE_CLASS:
327 case MONO_TYPE_STRING:
328 case MONO_TYPE_ARRAY:
329 case MONO_TYPE_SZARRAY:
334 result->data.p = *(gpointer*)data;
337 switch (type->type) {
341 result->data.i = *(gint8*)data;
344 case MONO_TYPE_BOOLEAN:
345 result->data.i = *(guint8*)data;
348 result->data.i = *(gint16*)data;
352 result->data.i = *(guint16*)data;
355 result->data.i = *(gint32*)data;
359 result->data.nati = *(mono_i*)data;
362 result->data.p = *(gpointer*)data;
365 result->data.i = *(guint32*)data;
368 result->data.f = *(float*)data;
372 result->data.l = *(gint64*)data;
375 result->data.f = *(double*)data;
377 case MONO_TYPE_STRING:
378 case MONO_TYPE_SZARRAY:
379 case MONO_TYPE_CLASS:
380 case MONO_TYPE_OBJECT:
381 case MONO_TYPE_ARRAY:
382 result->data.p = *(gpointer*)data;
384 case MONO_TYPE_VALUETYPE:
385 if (type->data.klass->enumtype) {
386 stackval_from_data (mono_class_enum_basetype (type->data.klass), result, data, pinvoke);
392 size = mono_class_native_size (type->data.klass, NULL);
394 size = mono_class_value_size (type->data.klass, NULL);
395 memcpy (result->data.vt, data, size);
399 g_warning ("got type 0x%02x", type->type);
400 g_assert_not_reached ();
405 stackval_to_data (MonoType *type, stackval *val, char *data, gboolean pinvoke)
408 gpointer *p = (gpointer*)data;
412 /* printf ("TODAT0 %p\n", data); */
413 switch (type->type) {
416 guint8 *p = (guint8*)data;
420 case MONO_TYPE_BOOLEAN: {
421 guint8 *p = (guint8*)data;
422 *p = (val->data.i != 0);
427 case MONO_TYPE_CHAR: {
428 guint16 *p = (guint16*)data;
433 mono_i *p = (mono_i*)data;
434 /* In theory the value used by stloc should match the local var type
435 but in practice it sometimes doesn't (a int32 gets dup'd and stloc'd into
436 a native int - both by csc and mcs). Not sure what to do about sign extension
437 as it is outside the spec... doing the obvious */
438 *p = (mono_i)val->data.nati;
442 mono_u *p = (mono_u*)data;
444 *p = (mono_u)val->data.nati;
449 gint32 *p = (gint32*)data;
455 gint64 *p = (gint64*)data;
460 float *p = (float*)data;
465 double *p = (double*)data;
469 case MONO_TYPE_STRING:
470 case MONO_TYPE_SZARRAY:
471 case MONO_TYPE_CLASS:
472 case MONO_TYPE_OBJECT:
473 case MONO_TYPE_ARRAY:
474 case MONO_TYPE_PTR: {
475 gpointer *p = (gpointer*)data;
479 case MONO_TYPE_VALUETYPE:
480 if (type->data.klass->enumtype) {
481 stackval_to_data (mono_class_enum_basetype (type->data.klass), val, data, pinvoke);
487 size = mono_class_native_size (type->data.klass, NULL);
489 size = mono_class_value_size (type->data.klass, NULL);
491 memcpy (data, val->data.p, size);
494 case MONO_TYPE_GENERICINST:
495 stackval_to_data (&type->data.generic_class->container_class->byval_arg, val, data, pinvoke);
498 g_warning ("got type %x", type->type);
499 g_assert_not_reached ();
504 fill_in_trace (MonoException *exception, MonoInvocation *frame)
506 char *stack_trace = dump_frame (frame);
507 MonoDomain *domain = mono_domain_get();
508 (exception)->stack_trace = mono_string_new (domain, stack_trace);
509 (exception)->trace_ips = get_trace_ips (domain, frame);
510 g_free (stack_trace);
513 #define FILL_IN_TRACE(exception, frame) fill_in_trace(exception, frame)
515 #define THROW_EX(exception,ex_ip) \
517 frame->ip = (ex_ip); \
518 frame->ex = (MonoException*)(exception); \
519 FILL_IN_TRACE(frame->ex, frame); \
520 goto handle_exception; \
524 ves_array_create (MonoDomain *domain, MonoClass *klass, MonoMethodSignature *sig, stackval *values)
527 intptr_t *lower_bounds;
532 lengths = alloca (sizeof (uintptr_t) * klass->rank * 2);
533 for (i = 0; i < sig->param_count; ++i) {
534 lengths [i] = values->data.i;
537 if (klass->rank == sig->param_count) {
538 /* Only lengths provided. */
541 /* lower bounds are first. */
542 lower_bounds = (intptr_t *) lengths;
543 lengths += klass->rank;
545 obj = (MonoObject*) mono_array_new_full_checked (domain, klass, lengths, lower_bounds, &error);
546 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
551 ves_array_set (MonoInvocation *frame)
553 stackval *sp = frame->stack_args;
557 gint32 i, t, pos, esize;
563 ac = o->vtable->klass;
565 g_assert (ac->rank >= 1);
568 if (ao->bounds != NULL) {
569 pos -= ao->bounds [0].lower_bound;
570 for (i = 1; i < ac->rank; i++) {
571 if ((t = sp [i].data.i - ao->bounds [i].lower_bound) >=
572 ao->bounds [i].length) {
573 frame->ex = mono_get_exception_index_out_of_range ();
574 FILL_IN_TRACE(frame->ex, frame);
577 pos = pos*ao->bounds [i].length + sp [i].data.i -
578 ao->bounds [i].lower_bound;
580 } else if (pos >= ao->max_length) {
581 frame->ex = mono_get_exception_index_out_of_range ();
582 FILL_IN_TRACE(frame->ex, frame);
586 if (sp [ac->rank].data.p && !mono_object_class (o)->element_class->valuetype) {
588 MonoObject *isinst = mono_object_isinst_checked (sp [ac->rank].data.p, mono_object_class (o)->element_class, &error);
589 mono_error_cleanup (&error);
591 frame->ex = mono_get_exception_array_type_mismatch ();
592 FILL_IN_TRACE (frame->ex, frame);
597 esize = mono_array_element_size (ac);
598 ea = mono_array_addr_with_size (ao, esize, pos);
600 mt = mono_method_signature (frame->runtime_method->method)->params [ac->rank];
601 stackval_to_data (mt, &sp [ac->rank], ea, FALSE);
605 ves_array_get (MonoInvocation *frame)
607 stackval *sp = frame->stack_args;
611 gint32 i, t, pos, esize;
617 ac = o->vtable->klass;
619 g_assert (ac->rank >= 1);
622 if (ao->bounds != NULL) {
623 pos -= ao->bounds [0].lower_bound;
624 for (i = 1; i < ac->rank; i++) {
625 if ((t = sp [i].data.i - ao->bounds [i].lower_bound) >=
626 ao->bounds [i].length) {
627 frame->ex = mono_get_exception_index_out_of_range ();
628 FILL_IN_TRACE(frame->ex, frame);
632 pos = pos*ao->bounds [i].length + sp [i].data.i -
633 ao->bounds [i].lower_bound;
635 } else if (pos >= ao->max_length) {
636 frame->ex = mono_get_exception_index_out_of_range ();
637 FILL_IN_TRACE(frame->ex, frame);
641 esize = mono_array_element_size (ac);
642 ea = mono_array_addr_with_size (ao, esize, pos);
644 mt = mono_method_signature (frame->runtime_method->method)->ret;
645 stackval_from_data (mt, frame->retval, ea, FALSE);
649 ves_array_element_address (MonoInvocation *frame)
651 stackval *sp = frame->stack_args;
655 gint32 i, t, pos, esize;
660 ac = o->vtable->klass;
662 g_assert (ac->rank >= 1);
665 if (ao->bounds != NULL) {
666 pos -= ao->bounds [0].lower_bound;
667 for (i = 1; i < ac->rank; i++) {
668 if ((t = sp [i].data.i - ao->bounds [i].lower_bound) >=
669 ao->bounds [i].length) {
670 frame->ex = mono_get_exception_index_out_of_range ();
671 FILL_IN_TRACE(frame->ex, frame);
674 pos = pos*ao->bounds [i].length + sp [i].data.i -
675 ao->bounds [i].lower_bound;
677 } else if (pos >= ao->max_length) {
678 frame->ex = mono_get_exception_index_out_of_range ();
679 FILL_IN_TRACE(frame->ex, frame);
683 esize = mono_array_element_size (ac);
684 ea = mono_array_addr_with_size (ao, esize, pos);
686 frame->retval->data.p = ea;
690 interp_walk_stack (MonoStackWalk func, gboolean do_il_offset, gpointer user_data)
692 ThreadContext *context = mono_native_tls_get_value (thread_context_id);
693 MonoInvocation *frame;
695 MonoMethodHeader *hd;
698 if (!context) return;
700 frame = context->current_frame;
703 gboolean managed = FALSE;
704 MonoMethod *method = frame->runtime_method->method;
705 if (!method || (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) || (method->iflags & (METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL | METHOD_IMPL_ATTRIBUTE_RUNTIME)))
708 hd = mono_method_get_header_checked (method, &error);
709 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
710 il_offset = frame->ip - (const unsigned short *)hd->code;
711 if (!method->wrapper_type)
714 if (func (method, -1, il_offset, managed, user_data))
716 frame = frame->parent;
720 static MonoPIFunc mono_interp_enter_icall_trampoline = NULL;
722 struct _MethodArguments {
730 typedef struct _MethodArguments MethodArguments;
732 // TODO: this function is also arch dependent (register width).
733 static MethodArguments* build_args_from_sig (MonoMethodSignature *sig, MonoInvocation *frame)
735 // TODO: don't malloc this data structure.
736 MethodArguments *margs = g_malloc0 (sizeof (MethodArguments));
741 for (int i = 0; i < sig->param_count; i++) {
742 guint32 ptype = sig->params [i]->byref ? MONO_TYPE_PTR : sig->params [i]->type;
744 case MONO_TYPE_BOOLEAN:
755 case MONO_TYPE_SZARRAY:
756 case MONO_TYPE_CLASS:
757 case MONO_TYPE_OBJECT:
758 case MONO_TYPE_STRING:
763 g_error ("build_args_from_sig: not implemented yet (1): 0x%x\n", ptype);
768 margs->iargs = g_malloc0 (sizeof (gpointer) * margs->ilen);
771 g_error ("build_args_from_sig: TODO, more than two iregs: %d\n", margs->ilen);
774 g_error ("build_args_from_sig: TODO, allocate floats: %d\n", margs->flen);
780 margs->iargs [0] = frame->obj;
784 for (int i = 0; i < sig->param_count; i++) {
785 guint32 ptype = sig->params [i]->byref ? MONO_TYPE_PTR : sig->params [i]->type;
787 case MONO_TYPE_BOOLEAN:
798 case MONO_TYPE_SZARRAY:
799 case MONO_TYPE_CLASS:
800 case MONO_TYPE_OBJECT:
801 case MONO_TYPE_STRING:
803 margs->iargs [int_i] = frame->stack_args [i].data.p;
805 g_print ("build_args_from_sig: margs->iargs[%d]: %p (frame @ %d)\n", int_i, margs->iargs[int_i], i);
810 g_error ("build_args_from_sig: not implemented yet (2): 0x%x\n", ptype);
814 if (sig->ret->type != MONO_TYPE_VOID) {
815 margs->retval = &(frame->retval->data.p);
817 margs->retval = NULL;
824 ves_pinvoke_method (MonoInvocation *frame, MonoMethodSignature *sig, MonoFuncV addr, gboolean string_ctor, ThreadContext *context)
827 MonoInvocation *old_frame = context->current_frame;
828 MonoInvocation *old_env_frame = context->env_frame;
829 jmp_buf *old_env = context->current_env;
832 context->current_frame = old_frame;
833 context->env_frame = old_env_frame;
834 context->current_env = old_env;
835 context->managed_code = 1;
840 context->env_frame = frame;
841 context->current_env = &env;
843 g_assert (!frame->runtime_method);
844 if (!mono_interp_enter_icall_trampoline) {
846 mono_interp_enter_icall_trampoline = mono_arch_get_enter_icall_trampoline (&info);
848 // mono_tramp_info_register (info, NULL);
851 MethodArguments *margs = build_args_from_sig (sig, frame);
853 g_print ("ICALL: mono_interp_enter_icall_trampoline = %p, addr = %p\n", mono_interp_enter_icall_trampoline, addr);
854 g_print ("margs(out): ilen=%d, flen=%d\n", margs->ilen, margs->flen);
857 context->current_frame = frame;
858 context->managed_code = 0;
860 mono_interp_enter_icall_trampoline (addr, margs);
862 context->managed_code = 1;
863 /* domain can only be changed by native code */
864 context->domain = mono_domain_get ();
866 if (*mono_thread_interruption_request_flag ())
867 mono_thread_interruption_checkpoint ();
869 if (!MONO_TYPE_ISSTRUCT (sig->ret))
870 stackval_from_data (sig->ret, frame->retval, (char*)&frame->retval->data.p, sig->pinvoke);
872 context->current_frame = old_frame;
873 context->env_frame = old_env_frame;
874 context->current_env = old_env;
876 g_free (margs->iargs);
877 g_free (margs->fargs);
882 interp_delegate_ctor (MonoDomain *domain, MonoObject *this, MonoObject *target, RuntimeMethod *runtime_method)
884 MonoDelegate *delegate = (MonoDelegate *)this;
887 delegate->method_info = mono_method_get_object_checked (domain, runtime_method->method, NULL, &error);
888 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
889 delegate->target = target;
891 if (target && mono_object_is_transparent_proxy (target)) {
892 MonoMethod *method = mono_marshal_get_remoting_invoke (runtime_method->method);
893 delegate->method_ptr = mono_interp_get_runtime_method (domain, method, &error);
894 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
896 delegate->method_ptr = runtime_method;
901 mono_interp_ftnptr_to_delegate (MonoClass *klass, gpointer ftn)
905 MonoDomain *domain = mono_domain_get ();
908 d = (MonoDelegate*)mono_object_new_checked (domain, klass, &error);
909 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
911 ji = mono_jit_info_table_find (domain, ftn);
913 mono_raise_exception (mono_get_exception_argument ("", "Function pointer was not created by a Delegate."));
915 /* FIXME: discard the wrapper and call the original method */
916 interp_delegate_ctor (domain, (MonoObject*)d, NULL, mono_interp_get_runtime_method (domain, ji->d.method, &error));
917 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
924 * runtime specifies that the implementation of the method is automatically
925 * provided by the runtime and is primarily used for the methods of delegates.
928 ves_runtime_method (MonoInvocation *frame, ThreadContext *context)
930 MonoMethod *method = frame->runtime_method->method;
931 const char *name = method->name;
932 MonoObject *obj = (MonoObject*)frame->obj;
933 MonoObject *isinst_obj;
936 mono_class_init (method->klass);
938 isinst_obj = mono_object_isinst_checked (obj, mono_defaults.multicastdelegate_class, &error);
939 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
940 if (obj && isinst_obj) {
941 if (*name == '.' && (strcmp (name, ".ctor") == 0)) {
942 interp_delegate_ctor (context->domain, obj, frame->stack_args[0].data.p, frame->stack_args[1].data.p);
947 isinst_obj = mono_object_isinst_checked (obj, mono_defaults.array_class, &error);
948 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
949 if (obj && isinst_obj) {
950 if (*name == 'S' && (strcmp (name, "Set") == 0)) {
951 ves_array_set (frame);
954 if (*name == 'G' && (strcmp (name, "Get") == 0)) {
955 ves_array_get (frame);
958 if (*name == 'A' && (strcmp (name, "Address") == 0)) {
959 ves_array_element_address (frame);
964 g_error ("Don't know how to exec runtime method %s.%s::%s",
965 method->klass->name_space, method->klass->name,
970 dump_stack (stackval *stack, stackval *sp)
973 GString *str = g_string_new ("");
976 return g_string_free (str, FALSE);
979 g_string_append_printf (str, "[%p (%lld)] ", s->data.l, s->data.l);
982 return g_string_free (str, FALSE);
986 dump_stackval (GString *str, stackval *s, MonoType *type)
988 switch (type->type) {
996 case MONO_TYPE_BOOLEAN:
997 g_string_append_printf (str, "[%d] ", s->data.i);
999 case MONO_TYPE_STRING:
1000 case MONO_TYPE_SZARRAY:
1001 case MONO_TYPE_CLASS:
1002 case MONO_TYPE_OBJECT:
1003 case MONO_TYPE_ARRAY:
1007 g_string_append_printf (str, "[%p] ", s->data.p);
1009 case MONO_TYPE_VALUETYPE:
1010 if (type->data.klass->enumtype)
1011 g_string_append_printf (str, "[%d] ", s->data.i);
1013 g_string_append_printf (str, "[vt:%p] ", s->data.p);
1017 g_string_append_printf (str, "[%g] ", s->data.f);
1022 GString *res = g_string_new ("");
1023 mono_type_get_desc (res, type, TRUE);
1024 g_string_append_printf (str, "[{%s} %lld/0x%0llx] ", res->str, s->data.l, s->data.l);
1025 g_string_free (res, TRUE);
1032 dump_args (MonoInvocation *inv)
1034 GString *str = g_string_new ("");
1036 MonoMethodSignature *signature = mono_method_signature (inv->runtime_method->method);
1038 if (signature->param_count == 0)
1039 return g_string_free (str, FALSE);
1041 if (signature->hasthis)
1042 g_string_append_printf (str, "%p ", inv->obj);
1044 for (i = 0; i < signature->param_count; ++i)
1045 dump_stackval (str, inv->stack_args + i, signature->params [i]);
1047 return g_string_free (str, FALSE);
1051 dump_retval (MonoInvocation *inv)
1053 GString *str = g_string_new ("");
1054 MonoType *ret = mono_method_signature (inv->runtime_method->method)->ret;
1056 if (ret->type != MONO_TYPE_VOID)
1057 dump_stackval (str, inv->retval, ret);
1059 return g_string_free (str, FALSE);
1063 dump_frame (MonoInvocation *inv)
1065 GString *str = g_string_new ("");
1070 for (i = 0; inv; inv = inv->parent) {
1071 if (inv->runtime_method != NULL) {
1072 MonoMethod *method = inv->runtime_method->method;
1076 const char * opname = "";
1078 gchar *source = NULL;
1082 if ((method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) == 0 &&
1083 (method->iflags & METHOD_IMPL_ATTRIBUTE_RUNTIME) == 0) {
1084 MonoMethodHeader *hd = mono_method_get_header_checked (method, &error);
1085 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
1089 opname = mono_interp_opname [*inv->ip];
1090 codep = inv->ip - inv->runtime_method->code;
1091 source = g_strdup_printf ("%s:%d // (TODO: proper stacktrace)", method->name, codep);
1096 MonoDebugSourceLocation *minfo = mono_debug_lookup_method (method);
1097 source = mono_debug_method_lookup_location (minfo, codep);
1101 args = dump_args (inv);
1102 name = mono_method_full_name (method, TRUE);
1104 g_string_append_printf (str, "#%d: 0x%05x %-10s in %s (%s) at %s\n", i, codep, opname, name, args, source);
1106 g_string_append_printf (str, "#%d: 0x%05x %-10s in %s (%s)\n", i, codep, opname, name, args);
1113 return g_string_free (str, FALSE);
1117 get_trace_ips (MonoDomain *domain, MonoInvocation *top)
1121 MonoInvocation *inv;
1124 for (i = 0, inv = top; inv; inv = inv->parent)
1125 if (inv->runtime_method != NULL)
1128 res = mono_array_new_checked (domain, mono_defaults.int_class, 2 * i, &error);
1129 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
1131 for (i = 0, inv = top; inv; inv = inv->parent)
1132 if (inv->runtime_method != NULL) {
1133 mono_array_set (res, gpointer, i, inv->runtime_method);
1135 mono_array_set (res, gpointer, i, (gpointer)inv->ip);
1143 #define MYGUINT64_MAX 18446744073709551615ULL
1144 #define MYGINT64_MAX 9223372036854775807LL
1145 #define MYGINT64_MIN (-MYGINT64_MAX -1LL)
1147 #define MYGUINT32_MAX 4294967295U
1148 #define MYGINT32_MAX 2147483647
1149 #define MYGINT32_MIN (-MYGINT32_MAX -1)
1151 #define CHECK_ADD_OVERFLOW(a,b) \
1152 (gint32)(b) >= 0 ? (gint32)(MYGINT32_MAX) - (gint32)(b) < (gint32)(a) ? -1 : 0 \
1153 : (gint32)(MYGINT32_MIN) - (gint32)(b) > (gint32)(a) ? +1 : 0
1155 #define CHECK_SUB_OVERFLOW(a,b) \
1156 (gint32)(b) < 0 ? (gint32)(MYGINT32_MAX) + (gint32)(b) < (gint32)(a) ? -1 : 0 \
1157 : (gint32)(MYGINT32_MIN) + (gint32)(b) > (gint32)(a) ? +1 : 0
1159 #define CHECK_ADD_OVERFLOW_UN(a,b) \
1160 (guint32)(MYGUINT32_MAX) - (guint32)(b) < (guint32)(a) ? -1 : 0
1162 #define CHECK_SUB_OVERFLOW_UN(a,b) \
1163 (guint32)(a) < (guint32)(b) ? -1 : 0
1165 #define CHECK_ADD_OVERFLOW64(a,b) \
1166 (gint64)(b) >= 0 ? (gint64)(MYGINT64_MAX) - (gint64)(b) < (gint64)(a) ? -1 : 0 \
1167 : (gint64)(MYGINT64_MIN) - (gint64)(b) > (gint64)(a) ? +1 : 0
1169 #define CHECK_SUB_OVERFLOW64(a,b) \
1170 (gint64)(b) < 0 ? (gint64)(MYGINT64_MAX) + (gint64)(b) < (gint64)(a) ? -1 : 0 \
1171 : (gint64)(MYGINT64_MIN) + (gint64)(b) > (gint64)(a) ? +1 : 0
1173 #define CHECK_ADD_OVERFLOW64_UN(a,b) \
1174 (guint64)(MYGUINT64_MAX) - (guint64)(b) < (guint64)(a) ? -1 : 0
1176 #define CHECK_SUB_OVERFLOW64_UN(a,b) \
1177 (guint64)(a) < (guint64)(b) ? -1 : 0
1179 #if SIZEOF_VOID_P == 4
1180 #define CHECK_ADD_OVERFLOW_NAT(a,b) CHECK_ADD_OVERFLOW(a,b)
1181 #define CHECK_ADD_OVERFLOW_NAT_UN(a,b) CHECK_ADD_OVERFLOW_UN(a,b)
1183 #define CHECK_ADD_OVERFLOW_NAT(a,b) CHECK_ADD_OVERFLOW64(a,b)
1184 #define CHECK_ADD_OVERFLOW_NAT_UN(a,b) CHECK_ADD_OVERFLOW64_UN(a,b)
1187 /* Resolves to TRUE if the operands would overflow */
1188 #define CHECK_MUL_OVERFLOW(a,b) \
1189 ((gint32)(a) == 0) || ((gint32)(b) == 0) ? 0 : \
1190 (((gint32)(a) > 0) && ((gint32)(b) == -1)) ? FALSE : \
1191 (((gint32)(a) < 0) && ((gint32)(b) == -1)) ? (a == - MYGINT32_MAX) : \
1192 (((gint32)(a) > 0) && ((gint32)(b) > 0)) ? (gint32)(a) > ((MYGINT32_MAX) / (gint32)(b)) : \
1193 (((gint32)(a) > 0) && ((gint32)(b) < 0)) ? (gint32)(a) > ((MYGINT32_MIN) / (gint32)(b)) : \
1194 (((gint32)(a) < 0) && ((gint32)(b) > 0)) ? (gint32)(a) < ((MYGINT32_MIN) / (gint32)(b)) : \
1195 (gint32)(a) < ((MYGINT32_MAX) / (gint32)(b))
1197 #define CHECK_MUL_OVERFLOW_UN(a,b) \
1198 ((guint32)(a) == 0) || ((guint32)(b) == 0) ? 0 : \
1199 (guint32)(b) > ((MYGUINT32_MAX) / (guint32)(a))
1201 #define CHECK_MUL_OVERFLOW64(a,b) \
1202 ((gint64)(a) == 0) || ((gint64)(b) == 0) ? 0 : \
1203 (((gint64)(a) > 0) && ((gint64)(b) == -1)) ? FALSE : \
1204 (((gint64)(a) < 0) && ((gint64)(b) == -1)) ? (a == - MYGINT64_MAX) : \
1205 (((gint64)(a) > 0) && ((gint64)(b) > 0)) ? (gint64)(a) > ((MYGINT64_MAX) / (gint64)(b)) : \
1206 (((gint64)(a) > 0) && ((gint64)(b) < 0)) ? (gint64)(a) > ((MYGINT64_MIN) / (gint64)(b)) : \
1207 (((gint64)(a) < 0) && ((gint64)(b) > 0)) ? (gint64)(a) < ((MYGINT64_MIN) / (gint64)(b)) : \
1208 (gint64)(a) < ((MYGINT64_MAX) / (gint64)(b))
1210 #define CHECK_MUL_OVERFLOW64_UN(a,b) \
1211 ((guint64)(a) == 0) || ((guint64)(b) == 0) ? 0 : \
1212 (guint64)(b) > ((MYGUINT64_MAX) / (guint64)(a))
1214 #if SIZEOF_VOID_P == 4
1215 #define CHECK_MUL_OVERFLOW_NAT(a,b) CHECK_MUL_OVERFLOW(a,b)
1216 #define CHECK_MUL_OVERFLOW_NAT_UN(a,b) CHECK_MUL_OVERFLOW_UN(a,b)
1218 #define CHECK_MUL_OVERFLOW_NAT(a,b) CHECK_MUL_OVERFLOW64(a,b)
1219 #define CHECK_MUL_OVERFLOW_NAT_UN(a,b) CHECK_MUL_OVERFLOW64_UN(a,b)
1223 interp_mono_runtime_invoke (MonoMethod *method, void *obj, void **params, MonoObject **exc, MonoError *error)
1225 MonoInvocation frame;
1226 ThreadContext * volatile context = mono_native_tls_get_value (thread_context_id);
1227 MonoObject *retval = NULL;
1228 MonoMethodSignature *sig = mono_method_signature (method);
1229 MonoClass *klass = mono_class_from_mono_type (sig->ret);
1230 int i, type, isobject = 0;
1233 stackval *args = alloca (sizeof (stackval) * sig->param_count);
1234 ThreadContext context_struct;
1235 MonoInvocation *old_frame = NULL;
1238 mono_error_init (error);
1243 if (context != &context_struct) {
1244 context->domain = mono_domain_get ();
1245 context->current_frame = old_frame;
1246 context->managed_code = 0;
1248 mono_native_tls_set_value (thread_context_id, NULL);
1250 *exc = (MonoObject *)frame.ex;
1254 if (context == NULL) {
1255 context = &context_struct;
1256 context_struct.base_frame = &frame;
1257 context_struct.current_frame = NULL;
1258 context_struct.env_frame = &frame;
1259 context_struct.current_env = &env;
1260 context_struct.search_for_handler = 0;
1261 context_struct.managed_code = 0;
1262 mono_native_tls_set_value (thread_context_id, context);
1265 old_frame = context->current_frame;
1267 context->domain = mono_domain_get ();
1269 switch (sig->ret->type) {
1270 case MONO_TYPE_VOID:
1272 case MONO_TYPE_STRING:
1273 case MONO_TYPE_OBJECT:
1274 case MONO_TYPE_CLASS:
1275 case MONO_TYPE_ARRAY:
1276 case MONO_TYPE_SZARRAY:
1279 case MONO_TYPE_VALUETYPE:
1280 retval = mono_object_new_checked (context->domain, klass, error);
1281 ret = ((char*)retval) + sizeof (MonoObject);
1282 if (!sig->ret->data.klass->enumtype)
1283 result.data.vt = ret;
1286 retval = mono_object_new_checked (context->domain, klass, error);
1287 ret = ((char*)retval) + sizeof (MonoObject);
1291 for (i = 0; i < sig->param_count; ++i) {
1292 if (sig->params [i]->byref) {
1293 args [i].data.p = params [i];
1296 type = sig->params [i]->type;
1301 case MONO_TYPE_BOOLEAN:
1302 args [i].data.i = *(MonoBoolean*)params [i];
1306 case MONO_TYPE_CHAR:
1307 args [i].data.i = *(gint16*)params [i];
1309 #if SIZEOF_VOID_P == 4
1310 case MONO_TYPE_U: /* use VAL_POINTER? */
1315 args [i].data.i = *(gint32*)params [i];
1317 #if SIZEOF_VOID_P == 8
1323 args [i].data.l = *(gint64*)params [i];
1325 case MONO_TYPE_VALUETYPE:
1326 if (sig->params [i]->data.klass->enumtype) {
1327 type = mono_class_enum_basetype (sig->params [i]->data.klass)->type;
1330 args [i].data.p = params [i];
1333 case MONO_TYPE_STRING:
1334 case MONO_TYPE_CLASS:
1335 case MONO_TYPE_ARRAY:
1336 case MONO_TYPE_SZARRAY:
1337 case MONO_TYPE_OBJECT:
1338 args [i].data.p = params [i];
1341 g_error ("type 0x%x not handled in runtime invoke", sig->params [i]->type);
1345 if (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL)
1346 method = mono_marshal_get_native_wrapper (method, FALSE, FALSE);
1347 INIT_FRAME(&frame,context->current_frame,obj,args,&result,mono_get_root_domain (),method,error);
1349 frame.invoke_trap = 1;
1350 context->managed_code = 1;
1351 ves_exec_method_with_context (&frame, context);
1352 context->managed_code = 0;
1353 if (context == &context_struct)
1354 mono_native_tls_set_value (thread_context_id, NULL);
1356 context->current_frame = old_frame;
1357 if (frame.ex != NULL) {
1359 *exc = (MonoObject*) frame.ex;
1362 if (context->current_env != NULL) {
1363 context->env_frame->ex = frame.ex;
1364 longjmp(*context->current_env, 1);
1367 printf("dropped exception...\n");
1369 if (sig->ret->type == MONO_TYPE_VOID && !method->string_ctor)
1371 if (isobject || method->string_ctor)
1372 return result.data.p;
1373 stackval_to_data (sig->ret, &result, ret, sig->pinvoke);
1378 do_icall (ThreadContext *context, int op, stackval *sp, gpointer ptr)
1380 MonoInvocation *old_frame = context->current_frame;
1381 MonoInvocation *old_env_frame = context->env_frame;
1382 jmp_buf *old_env = context->current_env;
1386 context->current_frame = old_frame;
1387 context->env_frame = old_env_frame;
1388 context->current_env = old_env;
1389 context->managed_code = 1;
1393 context->env_frame = context->current_frame;
1394 context->current_env = &env;
1395 context->managed_code = 0;
1398 case MINT_ICALL_V_V: {
1399 void (*func)() = ptr;
1403 case MINT_ICALL_V_P: {
1404 gpointer (*func)() = ptr;
1406 sp [-1].data.p = func ();
1409 case MINT_ICALL_P_V: {
1410 void (*func)(gpointer) = ptr;
1411 func (sp [-1].data.p);
1415 case MINT_ICALL_P_P: {
1416 gpointer (*func)(gpointer) = ptr;
1417 sp [-1].data.p = func (sp [-1].data.p);
1420 case MINT_ICALL_PP_V: {
1421 void (*func)(gpointer,gpointer) = ptr;
1423 func (sp [0].data.p, sp [1].data.p);
1426 case MINT_ICALL_PI_V: {
1427 void (*func)(gpointer,int) = ptr;
1429 func (sp [0].data.p, sp [1].data.i);
1432 case MINT_ICALL_PP_P: {
1433 gpointer (*func)(gpointer,gpointer) = ptr;
1435 sp [-1].data.p = func (sp [-1].data.p, sp [0].data.p);
1438 case MINT_ICALL_PI_P: {
1439 gpointer (*func)(gpointer,int) = ptr;
1441 sp [-1].data.p = func (sp [-1].data.p, sp [0].data.i);
1444 case MINT_ICALL_PPP_V: {
1445 void (*func)(gpointer,gpointer,gpointer) = ptr;
1447 func (sp [0].data.p, sp [1].data.p, sp [2].data.p);
1450 case MINT_ICALL_PPI_V: {
1451 void (*func)(gpointer,gpointer,int) = ptr;
1453 func (sp [0].data.p, sp [1].data.p, sp [2].data.i);
1457 g_assert_not_reached ();
1460 context->env_frame = old_env_frame;
1461 context->current_env = old_env;
1466 static mono_mutex_t create_method_pointer_mutex;
1468 static GHashTable *method_pointer_hash = NULL;
1471 interp_create_method_pointer (MonoMethod *method, MonoError *error)
1476 mono_os_mutex_lock (&create_method_pointer_mutex);
1477 if (!method_pointer_hash) {
1478 // FIXME: is registering method table as GC root really necessary?
1479 // MONO_GC_REGISTER_ROOT_FIXED (method_pointer_hash);
1480 method_pointer_hash = g_hash_table_new (NULL, NULL);
1482 addr = g_hash_table_lookup (method_pointer_hash, method);
1484 mono_os_mutex_unlock (&create_method_pointer_mutex);
1489 * If it is a static P/Invoke method, we can just return the pointer
1490 * to the method implementation.
1492 if (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL && ((MonoMethodPInvoke*) method)->addr) {
1493 ji = g_new0 (MonoJitInfo, 1);
1494 ji->d.method = method;
1496 ji->code_start = addr = ((MonoMethodPInvoke*) method)->addr;
1498 mono_jit_info_table_add (mono_get_root_domain (), ji);
1501 g_error ("FIXME: not available? figure out new API");
1503 addr = mono_arch_create_method_pointer (method);
1507 g_hash_table_insert (method_pointer_hash, method, addr);
1508 mono_os_mutex_unlock (&create_method_pointer_mutex);
1514 static int opcode_counts[512];
1516 #define COUNT_OP(op) opcode_counts[op]++
1518 #define COUNT_OP(op)
1522 #define DUMP_INSTR() \
1523 if (tracing > 1) { \
1525 if (sp > frame->stack) { \
1526 ins = dump_stack (frame->stack, sp); \
1528 ins = g_strdup (""); \
1532 char *mn = mono_method_full_name (frame->runtime_method->method, FALSE); \
1533 g_print ("(%p) %s -> ", mono_thread_internal_current (), mn); \
1535 mono_interp_dis_mintop(rtm->code, ip); \
1536 g_print ("\t%d:%s\n", vt_sp - vtalloc, ins); \
1540 #define DUMP_INSTR()
1544 #define USE_COMPUTED_GOTO 1
1546 #if USE_COMPUTED_GOTO
1547 #define MINT_IN_SWITCH(op) COUNT_OP(op); goto *in_labels[op];
1548 #define MINT_IN_CASE(x) LAB_ ## x:
1550 #define MINT_IN_BREAK if (tracing > 1) goto main_loop; else { COUNT_OP(*ip); goto *in_labels[*ip]; }
1552 #define MINT_IN_BREAK { COUNT_OP(*ip); goto *in_labels[*ip]; }
1554 #define MINT_IN_DEFAULT mint_default: if (0) goto mint_default; /* make gcc shut up */
1556 #define MINT_IN_SWITCH(op) switch (op)
1557 #define MINT_IN_CASE(x) case x:
1558 #define MINT_IN_BREAK break
1559 #define MINT_IN_DEFAULT default:
1563 * Defining this causes register allocation errors in some versions of gcc:
1564 * error: unable to find a register to spill in class `SIREG'
1566 /* #define MINT_USE_DEDICATED_IP_REG */
1569 ves_exec_method_with_context (MonoInvocation *frame, ThreadContext *context)
1571 MonoInvocation child_frame;
1572 GSList *finally_ips = NULL;
1573 const unsigned short *endfinally_ip = NULL;
1574 #if defined(__GNUC__) && defined (i386) && defined (MINT_USE_DEDICATED_IP_REG)
1575 register const unsigned short *ip asm ("%esi");
1577 register const unsigned short *ip;
1579 register stackval *sp;
1582 gint tracing = global_tracing;
1583 unsigned char *vtalloc;
1586 unsigned char *vt_sp;
1587 unsigned char *locals;
1589 MonoObject *o = NULL;
1591 #if USE_COMPUTED_GOTO
1592 static void *in_labels[] = {
1593 #define OPDEF(a,b,c,d) \
1595 #include "mintops.def"
1600 frame->ex_handler = NULL;
1602 context->current_frame = frame;
1605 debug_enter (frame, &tracing);
1608 if (!frame->runtime_method->transformed) {
1609 context->managed_code = 0;
1611 char *mn = mono_method_full_name (frame->runtime_method->method, FALSE);
1612 g_print ("(%p) Transforming %s\n", mono_thread_internal_current (), mn);
1615 frame->ex = mono_interp_transform_method (frame->runtime_method, context);
1616 context->managed_code = 1;
1624 rtm = frame->runtime_method;
1625 frame->args = alloca (rtm->alloca_size);
1626 sp = frame->stack = (stackval *)((char *)frame->args + rtm->args_size);
1629 memset(sp, 0, rtm->stack_size);
1631 vt_sp = (unsigned char *) sp + rtm->stack_size;
1635 locals = (unsigned char *) vt_sp + rtm->vt_stack_size;
1637 child_frame.parent = frame;
1643 * using while (ip < end) may result in a 15% performance drop,
1644 * but it may be useful for debug
1648 /* g_assert (sp >= frame->stack); */
1649 /* g_assert(vt_sp - vtalloc <= rtm->vt_stack_size); */
1651 MINT_IN_SWITCH (*ip) {
1652 MINT_IN_CASE(MINT_INITLOCALS)
1653 memset (locals, 0, rtm->locals_size);
1656 MINT_IN_CASE(MINT_NOP)
1659 MINT_IN_CASE(MINT_BREAK)
1661 G_BREAKPOINT (); /* this is not portable... */
1663 MINT_IN_CASE(MINT_LDNULL)
1668 MINT_IN_CASE(MINT_VTRESULT) {
1669 int ret_size = * (guint16 *)(ip + 1);
1670 unsigned char *ret_vt_sp = vt_sp;
1671 vt_sp -= READ32(ip + 2);
1673 memmove (vt_sp, ret_vt_sp, ret_size);
1674 sp [-1].data.p = vt_sp;
1675 vt_sp += (ret_size + 7) & ~7;
1680 #define LDC(n) do { sp->data.i = (n); ++ip; ++sp; } while (0)
1681 MINT_IN_CASE(MINT_LDC_I4_M1)
1684 MINT_IN_CASE(MINT_LDC_I4_0)
1687 MINT_IN_CASE(MINT_LDC_I4_1)
1690 MINT_IN_CASE(MINT_LDC_I4_2)
1693 MINT_IN_CASE(MINT_LDC_I4_3)
1696 MINT_IN_CASE(MINT_LDC_I4_4)
1699 MINT_IN_CASE(MINT_LDC_I4_5)
1702 MINT_IN_CASE(MINT_LDC_I4_6)
1705 MINT_IN_CASE(MINT_LDC_I4_7)
1708 MINT_IN_CASE(MINT_LDC_I4_8)
1711 MINT_IN_CASE(MINT_LDC_I4_S)
1712 sp->data.i = *(const short *)(ip + 1);
1716 MINT_IN_CASE(MINT_LDC_I4)
1718 sp->data.i = READ32 (ip);
1722 MINT_IN_CASE(MINT_LDC_I8)
1724 sp->data.l = READ64 (ip);
1728 MINT_IN_CASE(MINT_LDC_R4) {
1732 sp->data.f = * (float *)&val;
1737 MINT_IN_CASE(MINT_LDC_R8)
1738 sp->data.l = READ64 (ip + 1); /* note union usage */
1742 MINT_IN_CASE(MINT_DUP)
1747 MINT_IN_CASE(MINT_DUP_VT)
1748 i32 = READ32 (ip + 1);
1750 memcpy(sp->data.p, sp [-1].data.p, i32);
1751 vt_sp += (i32 + 7) & ~7;
1755 MINT_IN_CASE(MINT_POP)
1759 MINT_IN_CASE(MINT_JMP) {
1760 RuntimeMethod *new_method = rtm->data_items [* (guint16 *)(ip + 1)];
1761 if (!new_method->transformed) {
1763 frame->ex = mono_interp_transform_method (new_method, context);
1768 if (new_method->alloca_size > rtm->alloca_size)
1769 g_error ("MINT_JMP to method which needs more stack space (%d > %d)", new_method->alloca_size, rtm->alloca_size);
1770 rtm = frame->runtime_method = new_method;
1771 vt_sp = (unsigned char *) sp + rtm->stack_size;
1775 locals = vt_sp + rtm->vt_stack_size;
1776 ip = rtm->new_body_start; /* bypass storing input args from callers frame */
1779 MINT_IN_CASE(MINT_CALLI) {
1780 MonoMethodSignature *csignature;
1781 stackval *endsp = sp;
1785 csignature = rtm->data_items [* (guint16 *)(ip + 1)];
1789 child_frame.runtime_method = sp->data.p;
1792 child_frame.retval = sp;
1793 /* decrement by the actual number of args */
1794 sp -= csignature->param_count;
1795 child_frame.stack_args = sp;
1796 if (csignature->hasthis) {
1798 child_frame.obj = sp->data.p;
1800 child_frame.obj = NULL;
1802 if (csignature->hasthis && mono_object_is_transparent_proxy (child_frame.obj)) {
1803 child_frame.runtime_method = mono_interp_get_runtime_method (context->domain, mono_marshal_get_remoting_invoke (child_frame.runtime_method->method), &error);
1804 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
1805 } else if (child_frame.runtime_method->method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) {
1806 child_frame.runtime_method = mono_interp_get_runtime_method (context->domain, mono_marshal_get_native_wrapper (child_frame.runtime_method->method, FALSE, FALSE), &error);
1807 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
1810 ves_exec_method_with_context (&child_frame, context);
1812 context->current_frame = frame;
1814 if (child_frame.ex) {
1816 * An exception occurred, need to run finally, fault and catch handlers..
1818 frame->ex = child_frame.ex;
1819 goto handle_finally;
1822 /* need to handle typedbyref ... */
1823 if (csignature->ret->type != MONO_TYPE_VOID) {
1829 MINT_IN_CASE(MINT_CALLI_NAT) {
1830 MonoMethodSignature *csignature;
1831 stackval *endsp = sp;
1832 unsigned char *code = NULL;
1836 csignature = rtm->data_items [* (guint16 *)(ip + 1)];
1841 child_frame.runtime_method = NULL;
1844 child_frame.retval = sp;
1845 /* decrement by the actual number of args */
1846 sp -= csignature->param_count;
1847 child_frame.stack_args = sp;
1848 if (csignature->hasthis) {
1850 child_frame.obj = sp->data.p;
1852 child_frame.obj = NULL;
1854 ves_pinvoke_method (&child_frame, csignature, (MonoFuncV) code, FALSE, context);
1856 context->current_frame = frame;
1858 if (child_frame.ex) {
1860 * An exception occurred, need to run finally, fault and catch handlers..
1862 frame->ex = child_frame.ex;
1863 if (context->search_for_handler) {
1864 context->search_for_handler = 0;
1865 goto handle_exception;
1867 goto handle_finally;
1870 /* need to handle typedbyref ... */
1871 if (csignature->ret->type != MONO_TYPE_VOID) {
1877 MINT_IN_CASE(MINT_CALL) {
1878 stackval *endsp = sp;
1882 child_frame.runtime_method = rtm->data_items [* (guint16 *)(ip + 1)];
1885 child_frame.retval = sp;
1886 /* decrement by the actual number of args */
1887 sp -= child_frame.runtime_method->param_count;
1888 child_frame.stack_args = sp;
1889 if (child_frame.runtime_method->hasthis) {
1891 child_frame.obj = sp->data.p;
1893 child_frame.obj = NULL;
1895 if (child_frame.runtime_method->hasthis && !child_frame.runtime_method->valuetype && mono_object_is_transparent_proxy (child_frame.obj)) {
1896 child_frame.runtime_method = mono_interp_get_runtime_method (context->domain, mono_marshal_get_remoting_invoke (child_frame.runtime_method->method), &error);
1897 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
1899 ves_exec_method_with_context (&child_frame, context);
1901 context->current_frame = frame;
1903 if (child_frame.ex) {
1905 * An exception occurred, need to run finally, fault and catch handlers..
1907 frame->ex = child_frame.ex;
1908 goto handle_finally;
1911 /* need to handle typedbyref ... */
1916 MINT_IN_CASE(MINT_VCALL) {
1919 child_frame.runtime_method = rtm->data_items [* (guint16 *)(ip + 1)];
1923 child_frame.retval = sp;
1924 /* decrement by the actual number of args */
1925 sp -= child_frame.runtime_method->param_count;
1926 child_frame.stack_args = sp;
1927 if (child_frame.runtime_method->hasthis) {
1929 child_frame.obj = sp->data.p;
1931 child_frame.obj = NULL;
1934 if (child_frame.runtime_method->hasthis && !child_frame.runtime_method->valuetype && mono_object_is_transparent_proxy (child_frame.obj)) {
1935 child_frame.runtime_method = mono_interp_get_runtime_method (context->domain, mono_marshal_get_remoting_invoke (child_frame.runtime_method->method), &error);
1936 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
1939 ves_exec_method_with_context (&child_frame, context);
1941 context->current_frame = frame;
1943 if (child_frame.ex) {
1945 * An exception occurred, need to run finally, fault and catch handlers..
1947 frame->ex = child_frame.ex;
1948 goto handle_finally;
1952 MINT_IN_CASE(MINT_CALLVIRT) {
1953 stackval *endsp = sp;
1954 MonoObject *this_arg;
1959 token = * (unsigned short *)(ip + 1);
1961 child_frame.runtime_method = rtm->data_items [token];
1963 child_frame.retval = sp;
1965 /* decrement by the actual number of args */
1966 sp -= child_frame.runtime_method->param_count;
1967 child_frame.stack_args = sp;
1969 child_frame.obj = this_arg = sp->data.p;
1971 THROW_EX (mono_get_exception_null_reference(), ip - 2);
1972 child_frame.runtime_method = get_virtual_method (context->domain, child_frame.runtime_method, this_arg);
1974 if (this_arg->vtable->klass->valuetype && child_frame.runtime_method->valuetype) {
1975 child_frame.obj = (char *)this_arg + sizeof(MonoObject);
1978 ves_exec_method_with_context (&child_frame, context);
1980 context->current_frame = frame;
1982 if (child_frame.ex) {
1984 * An exception occurred, need to run finally, fault and catch handlers..
1986 frame->ex = child_frame.ex;
1987 if (context->search_for_handler) {
1988 context->search_for_handler = 0;
1989 goto handle_exception;
1991 goto handle_finally;
1994 /* need to handle typedbyref ... */
1999 MINT_IN_CASE(MINT_VCALLVIRT) {
2000 MonoObject *this_arg;
2005 token = * (unsigned short *)(ip + 1);
2007 child_frame.runtime_method = rtm->data_items [token];
2009 child_frame.retval = sp;
2011 /* decrement by the actual number of args */
2012 sp -= child_frame.runtime_method->param_count;
2013 child_frame.stack_args = sp;
2015 child_frame.obj = this_arg = sp->data.p;
2017 THROW_EX (mono_get_exception_null_reference(), ip - 2);
2018 child_frame.runtime_method = get_virtual_method (context->domain, child_frame.runtime_method, this_arg);
2020 if (this_arg->vtable->klass->valuetype && child_frame.runtime_method->valuetype) {
2021 child_frame.obj = (char *)this_arg + sizeof(MonoObject);
2024 ves_exec_method_with_context (&child_frame, context);
2026 context->current_frame = frame;
2028 if (child_frame.ex) {
2030 * An exception occurred, need to run finally, fault and catch handlers..
2032 frame->ex = child_frame.ex;
2033 if (context->search_for_handler) {
2034 context->search_for_handler = 0;
2035 goto handle_exception;
2037 goto handle_finally;
2041 MINT_IN_CASE(MINT_CALLRUN)
2042 ves_runtime_method (frame, context);
2045 goto handle_exception;
2048 MINT_IN_CASE(MINT_RET)
2050 *frame->retval = *sp;
2051 if (sp > frame->stack)
2052 g_warning ("ret: more values on stack: %d", sp-frame->stack);
2054 MINT_IN_CASE(MINT_RET_VOID)
2055 if (sp > frame->stack)
2056 g_warning ("ret.void: more values on stack: %d", sp-frame->stack);
2058 MINT_IN_CASE(MINT_RET_VT)
2059 i32 = READ32(ip + 1);
2061 memcpy(frame->retval->data.p, sp->data.p, i32);
2062 if (sp > frame->stack)
2063 g_warning ("ret.vt: more values on stack: %d", sp-frame->stack);
2065 MINT_IN_CASE(MINT_BR_S)
2066 ip += (short) *(ip + 1);
2068 MINT_IN_CASE(MINT_BR)
2069 ip += (gint32) READ32(ip + 1);
2071 #define ZEROP_S(datamem, op) \
2073 if (sp->data.datamem op 0) \
2074 ip += * (gint16 *)(ip + 1); \
2078 #define ZEROP(datamem, op) \
2080 if (sp->data.datamem op 0) \
2081 ip += READ32(ip + 1); \
2085 MINT_IN_CASE(MINT_BRFALSE_I4_S)
2088 MINT_IN_CASE(MINT_BRFALSE_I8_S)
2091 MINT_IN_CASE(MINT_BRFALSE_R8_S)
2094 MINT_IN_CASE(MINT_BRFALSE_I4)
2097 MINT_IN_CASE(MINT_BRFALSE_I8)
2100 MINT_IN_CASE(MINT_BRFALSE_R8)
2103 MINT_IN_CASE(MINT_BRTRUE_I4_S)
2106 MINT_IN_CASE(MINT_BRTRUE_I8_S)
2109 MINT_IN_CASE(MINT_BRTRUE_R8_S)
2112 MINT_IN_CASE(MINT_BRTRUE_I4)
2115 MINT_IN_CASE(MINT_BRTRUE_I8)
2118 MINT_IN_CASE(MINT_BRTRUE_R8)
2121 #define CONDBR_S(cond) \
2124 ip += * (gint16 *)(ip + 1); \
2127 #define BRELOP_S(datamem, op) \
2128 CONDBR_S(sp[0].data.datamem op sp[1].data.datamem)
2130 #define CONDBR(cond) \
2133 ip += READ32(ip + 1); \
2137 #define BRELOP(datamem, op) \
2138 CONDBR(sp[0].data.datamem op sp[1].data.datamem)
2140 MINT_IN_CASE(MINT_BEQ_I4_S)
2143 MINT_IN_CASE(MINT_BEQ_I8_S)
2146 MINT_IN_CASE(MINT_BEQ_R8_S)
2147 CONDBR_S(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f == sp[1].data.f)
2149 MINT_IN_CASE(MINT_BEQ_I4)
2152 MINT_IN_CASE(MINT_BEQ_I8)
2155 MINT_IN_CASE(MINT_BEQ_R8)
2156 CONDBR(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f == sp[1].data.f)
2158 MINT_IN_CASE(MINT_BGE_I4_S)
2161 MINT_IN_CASE(MINT_BGE_I8_S)
2164 MINT_IN_CASE(MINT_BGE_R8_S)
2165 CONDBR_S(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f >= sp[1].data.f)
2167 MINT_IN_CASE(MINT_BGE_I4)
2170 MINT_IN_CASE(MINT_BGE_I8)
2173 MINT_IN_CASE(MINT_BGE_R8)
2174 CONDBR(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f >= sp[1].data.f)
2176 MINT_IN_CASE(MINT_BGT_I4_S)
2179 MINT_IN_CASE(MINT_BGT_I8_S)
2182 MINT_IN_CASE(MINT_BGT_R8_S)
2183 CONDBR_S(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f > sp[1].data.f)
2185 MINT_IN_CASE(MINT_BGT_I4)
2188 MINT_IN_CASE(MINT_BGT_I8)
2191 MINT_IN_CASE(MINT_BGT_R8)
2192 CONDBR(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f > sp[1].data.f)
2194 MINT_IN_CASE(MINT_BLT_I4_S)
2197 MINT_IN_CASE(MINT_BLT_I8_S)
2200 MINT_IN_CASE(MINT_BLT_R8_S)
2201 CONDBR_S(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f < sp[1].data.f)
2203 MINT_IN_CASE(MINT_BLT_I4)
2206 MINT_IN_CASE(MINT_BLT_I8)
2209 MINT_IN_CASE(MINT_BLT_R8)
2210 CONDBR(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f < sp[1].data.f)
2212 MINT_IN_CASE(MINT_BLE_I4_S)
2215 MINT_IN_CASE(MINT_BLE_I8_S)
2218 MINT_IN_CASE(MINT_BLE_R8_S)
2219 CONDBR_S(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f <= sp[1].data.f)
2221 MINT_IN_CASE(MINT_BLE_I4)
2224 MINT_IN_CASE(MINT_BLE_I8)
2227 MINT_IN_CASE(MINT_BLE_R8)
2228 CONDBR(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f <= sp[1].data.f)
2230 MINT_IN_CASE(MINT_BNE_UN_I4_S)
2233 MINT_IN_CASE(MINT_BNE_UN_I8_S)
2236 MINT_IN_CASE(MINT_BNE_UN_R8_S)
2237 CONDBR_S(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f != sp[1].data.f)
2239 MINT_IN_CASE(MINT_BNE_UN_I4)
2242 MINT_IN_CASE(MINT_BNE_UN_I8)
2245 MINT_IN_CASE(MINT_BNE_UN_R8)
2246 CONDBR(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f != sp[1].data.f)
2249 #define BRELOP_S_CAST(datamem, op, type) \
2251 if ((type) sp[0].data.datamem op (type) sp[1].data.datamem) \
2252 ip += * (gint16 *)(ip + 1); \
2256 #define BRELOP_CAST(datamem, op, type) \
2258 if ((type) sp[0].data.datamem op (type) sp[1].data.datamem) \
2259 ip += READ32(ip + 1); \
2263 MINT_IN_CASE(MINT_BGE_UN_I4_S)
2264 BRELOP_S_CAST(i, >=, guint32);
2266 MINT_IN_CASE(MINT_BGE_UN_I8_S)
2267 BRELOP_S_CAST(l, >=, guint64);
2269 MINT_IN_CASE(MINT_BGE_UN_R8_S)
2270 CONDBR_S(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f >= sp[1].data.f)
2272 MINT_IN_CASE(MINT_BGE_UN_I4)
2273 BRELOP_CAST(i, >=, guint32);
2275 MINT_IN_CASE(MINT_BGE_UN_I8)
2276 BRELOP_CAST(l, >=, guint64);
2278 MINT_IN_CASE(MINT_BGE_UN_R8)
2279 CONDBR(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f >= sp[1].data.f)
2281 MINT_IN_CASE(MINT_BGT_UN_I4_S)
2282 BRELOP_S_CAST(i, >, guint32);
2284 MINT_IN_CASE(MINT_BGT_UN_I8_S)
2285 BRELOP_S_CAST(l, >, guint64);
2287 MINT_IN_CASE(MINT_BGT_UN_R8_S)
2288 CONDBR_S(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f > sp[1].data.f)
2290 MINT_IN_CASE(MINT_BGT_UN_I4)
2291 BRELOP_CAST(i, >, guint32);
2293 MINT_IN_CASE(MINT_BGT_UN_I8)
2294 BRELOP_CAST(l, >, guint64);
2296 MINT_IN_CASE(MINT_BGT_UN_R8)
2297 CONDBR(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f > sp[1].data.f)
2299 MINT_IN_CASE(MINT_BLE_UN_I4_S)
2300 BRELOP_S_CAST(i, <=, guint32);
2302 MINT_IN_CASE(MINT_BLE_UN_I8_S)
2303 BRELOP_S_CAST(l, <=, guint64);
2305 MINT_IN_CASE(MINT_BLE_UN_R8_S)
2306 CONDBR_S(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f <= sp[1].data.f)
2308 MINT_IN_CASE(MINT_BLE_UN_I4)
2309 BRELOP_CAST(i, <=, guint32);
2311 MINT_IN_CASE(MINT_BLE_UN_I8)
2312 BRELOP_CAST(l, <=, guint64);
2314 MINT_IN_CASE(MINT_BLE_UN_R8)
2315 CONDBR(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f <= sp[1].data.f)
2317 MINT_IN_CASE(MINT_BLT_UN_I4_S)
2318 BRELOP_S_CAST(i, <, guint32);
2320 MINT_IN_CASE(MINT_BLT_UN_I8_S)
2321 BRELOP_S_CAST(l, <, guint64);
2323 MINT_IN_CASE(MINT_BLT_UN_R8_S)
2324 CONDBR_S(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f < sp[1].data.f)
2326 MINT_IN_CASE(MINT_BLT_UN_I4)
2327 BRELOP_CAST(i, <, guint32);
2329 MINT_IN_CASE(MINT_BLT_UN_I8)
2330 BRELOP_CAST(l, <, guint64);
2332 MINT_IN_CASE(MINT_BLT_UN_R8)
2333 CONDBR(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f < sp[1].data.f)
2335 MINT_IN_CASE(MINT_SWITCH) {
2337 const unsigned short *st;
2343 if ((guint32)sp->data.i < n) {
2345 ip += 2 * (guint32)sp->data.i;
2346 offset = READ32 (ip);
2353 MINT_IN_CASE(MINT_LDIND_I1)
2355 sp[-1].data.i = *(gint8*)sp[-1].data.p;
2357 MINT_IN_CASE(MINT_LDIND_U1)
2359 sp[-1].data.i = *(guint8*)sp[-1].data.p;
2361 MINT_IN_CASE(MINT_LDIND_I2)
2363 sp[-1].data.i = *(gint16*)sp[-1].data.p;
2365 MINT_IN_CASE(MINT_LDIND_U2)
2367 sp[-1].data.i = *(guint16*)sp[-1].data.p;
2369 MINT_IN_CASE(MINT_LDIND_I4) /* Fall through */
2370 MINT_IN_CASE(MINT_LDIND_U4)
2372 sp[-1].data.i = *(gint32*)sp[-1].data.p;
2374 MINT_IN_CASE(MINT_LDIND_I8)
2376 sp[-1].data.l = *(gint64*)sp[-1].data.p;
2378 MINT_IN_CASE(MINT_LDIND_I)
2380 sp[-1].data.p = *(gpointer*)sp[-1].data.p;
2382 MINT_IN_CASE(MINT_LDIND_R4)
2384 sp[-1].data.f = *(gfloat*)sp[-1].data.p;
2386 MINT_IN_CASE(MINT_LDIND_R8)
2388 sp[-1].data.f = *(gdouble*)sp[-1].data.p;
2390 MINT_IN_CASE(MINT_LDIND_REF)
2392 sp[-1].data.p = *(gpointer*)sp[-1].data.p;
2394 MINT_IN_CASE(MINT_STIND_REF)
2397 * (gpointer *) sp->data.p = sp[1].data.p;
2399 MINT_IN_CASE(MINT_STIND_I1)
2402 * (gint8 *) sp->data.p = (gint8)sp[1].data.i;
2404 MINT_IN_CASE(MINT_STIND_I2)
2407 * (gint16 *) sp->data.p = (gint16)sp[1].data.i;
2409 MINT_IN_CASE(MINT_STIND_I4)
2412 * (gint32 *) sp->data.p = sp[1].data.i;
2414 MINT_IN_CASE(MINT_STIND_I)
2417 * (mono_i *) sp->data.p = (mono_i)sp[1].data.p;
2419 MINT_IN_CASE(MINT_STIND_I8)
2422 * (gint64 *) sp->data.p = sp[1].data.l;
2424 MINT_IN_CASE(MINT_STIND_R4)
2427 * (float *) sp->data.p = (gfloat)sp[1].data.f;
2429 MINT_IN_CASE(MINT_STIND_R8)
2432 * (double *) sp->data.p = sp[1].data.f;
2434 #define BINOP(datamem, op) \
2436 sp [-1].data.datamem = sp [-1].data.datamem op sp [0].data.datamem; \
2438 MINT_IN_CASE(MINT_ADD_I4)
2441 MINT_IN_CASE(MINT_ADD_I8)
2444 MINT_IN_CASE(MINT_ADD_R8)
2447 MINT_IN_CASE(MINT_ADD1_I4)
2451 MINT_IN_CASE(MINT_SUB_I4)
2454 MINT_IN_CASE(MINT_SUB_I8)
2457 MINT_IN_CASE(MINT_SUB_R8)
2460 MINT_IN_CASE(MINT_SUB1_I4)
2464 MINT_IN_CASE(MINT_MUL_I4)
2467 MINT_IN_CASE(MINT_MUL_I8)
2470 MINT_IN_CASE(MINT_MUL_R8)
2473 MINT_IN_CASE(MINT_DIV_I4)
2474 if (sp [-1].data.i == 0)
2475 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2476 if (sp [-1].data.i == (-1))
2477 THROW_EX (mono_get_exception_overflow (), ip);
2480 MINT_IN_CASE(MINT_DIV_I8)
2481 if (sp [-1].data.l == 0)
2482 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2483 if (sp [-1].data.l == (-1))
2484 THROW_EX (mono_get_exception_overflow (), ip);
2487 MINT_IN_CASE(MINT_DIV_R8)
2491 #define BINOP_CAST(datamem, op, type) \
2493 sp [-1].data.datamem = (type)sp [-1].data.datamem op (type)sp [0].data.datamem; \
2495 MINT_IN_CASE(MINT_DIV_UN_I4)
2496 if (sp [-1].data.i == 0)
2497 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2498 BINOP_CAST(i, /, guint32);
2500 MINT_IN_CASE(MINT_DIV_UN_I8)
2501 if (sp [-1].data.l == 0)
2502 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2503 BINOP_CAST(l, /, guint64);
2505 MINT_IN_CASE(MINT_REM_I4)
2506 if (sp [-1].data.i == 0)
2507 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2510 MINT_IN_CASE(MINT_REM_I8)
2511 if (sp [-1].data.l == 0)
2512 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2515 MINT_IN_CASE(MINT_REM_R8)
2516 /* FIXME: what do we actually do here? */
2518 sp [-1].data.f = fmod (sp [-1].data.f, sp [0].data.f);
2521 MINT_IN_CASE(MINT_REM_UN_I4)
2522 if (sp [-1].data.i == 0)
2523 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2524 BINOP_CAST(i, %, guint32);
2526 MINT_IN_CASE(MINT_REM_UN_I8)
2527 if (sp [-1].data.l == 0)
2528 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2529 BINOP_CAST(l, %, guint64);
2531 MINT_IN_CASE(MINT_AND_I4)
2534 MINT_IN_CASE(MINT_AND_I8)
2537 MINT_IN_CASE(MINT_OR_I4)
2540 MINT_IN_CASE(MINT_OR_I8)
2543 MINT_IN_CASE(MINT_XOR_I4)
2546 MINT_IN_CASE(MINT_XOR_I8)
2550 #define SHIFTOP(datamem, op) \
2552 sp [-1].data.datamem = sp [-1].data.datamem op sp [0].data.i; \
2555 MINT_IN_CASE(MINT_SHL_I4)
2558 MINT_IN_CASE(MINT_SHL_I8)
2561 MINT_IN_CASE(MINT_SHR_I4)
2564 MINT_IN_CASE(MINT_SHR_I8)
2567 MINT_IN_CASE(MINT_SHR_UN_I4)
2569 sp [-1].data.i = (guint32)sp [-1].data.i >> sp [0].data.i;
2572 MINT_IN_CASE(MINT_SHR_UN_I8)
2574 sp [-1].data.l = (guint64)sp [-1].data.l >> sp [0].data.i;
2577 MINT_IN_CASE(MINT_NEG_I4)
2578 sp [-1].data.i = - sp [-1].data.i;
2581 MINT_IN_CASE(MINT_NEG_I8)
2582 sp [-1].data.l = - sp [-1].data.l;
2585 MINT_IN_CASE(MINT_NEG_R8)
2586 sp [-1].data.f = - sp [-1].data.f;
2589 MINT_IN_CASE(MINT_NOT_I4)
2590 sp [-1].data.i = ~ sp [-1].data.i;
2593 MINT_IN_CASE(MINT_NOT_I8)
2594 sp [-1].data.l = ~ sp [-1].data.l;
2597 MINT_IN_CASE(MINT_CONV_I1_I4)
2598 sp [-1].data.i = (gint8)sp [-1].data.i;
2601 MINT_IN_CASE(MINT_CONV_I1_I8)
2602 sp [-1].data.i = (gint8)sp [-1].data.l;
2605 MINT_IN_CASE(MINT_CONV_I1_R8)
2606 sp [-1].data.i = (gint8)sp [-1].data.f;
2609 MINT_IN_CASE(MINT_CONV_U1_I4)
2610 sp [-1].data.i = (guint8)sp [-1].data.i;
2613 MINT_IN_CASE(MINT_CONV_U1_I8)
2614 sp [-1].data.i = (guint8)sp [-1].data.l;
2617 MINT_IN_CASE(MINT_CONV_U1_R8)
2618 sp [-1].data.i = (guint8)sp [-1].data.f;
2621 MINT_IN_CASE(MINT_CONV_I2_I4)
2622 sp [-1].data.i = (gint16)sp [-1].data.i;
2625 MINT_IN_CASE(MINT_CONV_I2_I8)
2626 sp [-1].data.i = (gint16)sp [-1].data.l;
2629 MINT_IN_CASE(MINT_CONV_I2_R8)
2630 sp [-1].data.i = (gint16)sp [-1].data.f;
2633 MINT_IN_CASE(MINT_CONV_U2_I4)
2634 sp [-1].data.i = (guint16)sp [-1].data.i;
2637 MINT_IN_CASE(MINT_CONV_U2_I8)
2638 sp [-1].data.i = (guint16)sp [-1].data.l;
2641 MINT_IN_CASE(MINT_CONV_U2_R8)
2642 sp [-1].data.i = (guint16)sp [-1].data.f;
2645 MINT_IN_CASE(MINT_CONV_I4_R8)
2646 sp [-1].data.i = (gint32)sp [-1].data.f;
2649 MINT_IN_CASE(MINT_CONV_U4_I8)
2650 MINT_IN_CASE(MINT_CONV_I4_I8)
2651 sp [-1].data.i = (gint32)sp [-1].data.l;
2654 MINT_IN_CASE(MINT_CONV_I4_I8_SP)
2655 sp [-2].data.i = (gint32)sp [-2].data.l;
2658 MINT_IN_CASE(MINT_CONV_U4_R8)
2659 sp [-1].data.i = (guint32)sp [-1].data.f;
2662 MINT_IN_CASE(MINT_CONV_I8_I4)
2663 sp [-1].data.l = sp [-1].data.i;
2666 MINT_IN_CASE(MINT_CONV_I8_I4_SP)
2667 sp [-2].data.l = sp [-2].data.i;
2670 MINT_IN_CASE(MINT_CONV_I8_U4)
2671 sp [-1].data.l = (guint32)sp [-1].data.i;
2674 MINT_IN_CASE(MINT_CONV_I8_R8)
2675 sp [-1].data.l = (gint64)sp [-1].data.f;
2678 MINT_IN_CASE(MINT_CONV_R4_I4)
2679 sp [-1].data.f = (float)sp [-1].data.i;
2682 MINT_IN_CASE(MINT_CONV_R4_I8)
2683 sp [-1].data.f = (float)sp [-1].data.l;
2686 MINT_IN_CASE(MINT_CONV_R4_R8)
2687 sp [-1].data.f = (float)sp [-1].data.f;
2690 MINT_IN_CASE(MINT_CONV_R8_I4)
2691 sp [-1].data.f = (double)sp [-1].data.i;
2694 MINT_IN_CASE(MINT_CONV_R8_I8)
2695 sp [-1].data.f = (double)sp [-1].data.l;
2698 MINT_IN_CASE(MINT_CONV_U8_I4)
2699 sp [-1].data.l = sp [-1].data.i & 0xffffffff;
2702 MINT_IN_CASE(MINT_CONV_U8_R8)
2703 sp [-1].data.l = (guint64)sp [-1].data.f;
2707 MINT_IN_CASE(MINT_CPOBJ) {
2710 vtklass = rtm->data_items[READ32 (ip)];
2713 memcpy (sp [0].data.p, sp [1].data.p, mono_class_value_size (vtklass, NULL));
2717 MINT_IN_CASE(MINT_LDOBJ) {
2720 c = rtm->data_items[* (guint16 *)(ip + 1)];
2722 if (c->byval_arg.type != MONO_TYPE_VALUETYPE || c->byval_arg.data.klass->enumtype) {
2724 stackval_from_data (&c->byval_arg, &sp [-1], p, FALSE);
2726 size = mono_class_value_size (c, NULL);
2728 sp [-1].data.p = vt_sp;
2729 memcpy(vt_sp, p, size);
2730 vt_sp += (size + 7) & ~7;
2734 MINT_IN_CASE(MINT_LDSTR)
2735 sp->data.p = rtm->data_items [* (guint16 *)(ip + 1)];
2739 MINT_IN_CASE(MINT_NEWOBJ) {
2740 MonoClass *newobj_class;
2741 MonoMethodSignature *csig;
2742 stackval valuetype_this;
2748 token = * (guint16 *)(ip + 1);
2751 child_frame.runtime_method = rtm->data_items [token];
2752 csig = mono_method_signature (child_frame.runtime_method->method);
2753 newobj_class = child_frame.runtime_method->method->klass;
2754 /*if (profiling_classes) {
2755 guint count = GPOINTER_TO_UINT (g_hash_table_lookup (profiling_classes, newobj_class));
2757 g_hash_table_insert (profiling_classes, newobj_class, GUINT_TO_POINTER (count));
2761 if (newobj_class->parent == mono_defaults.array_class) {
2762 sp -= csig->param_count;
2763 o = ves_array_create (context->domain, newobj_class, csig, sp);
2764 goto array_constructed;
2768 * First arg is the object.
2770 if (newobj_class->valuetype) {
2771 MonoType *t = &newobj_class->byval_arg;
2772 if (!newobj_class->enumtype && (t->type == MONO_TYPE_VALUETYPE || (t->type == MONO_TYPE_GENERICINST && mono_type_generic_inst_is_valuetype (t)))) {
2773 child_frame.obj = vt_sp;
2774 valuetype_this.data.p = vt_sp;
2776 memset (&valuetype_this, 0, sizeof (stackval));
2777 child_frame.obj = &valuetype_this;
2780 if (newobj_class != mono_defaults.string_class) {
2781 context->managed_code = 0;
2782 o = mono_object_new_checked (context->domain, newobj_class, &error);
2783 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2784 context->managed_code = 1;
2785 if (*mono_thread_interruption_request_flag ())
2786 mono_thread_interruption_checkpoint ();
2787 child_frame.obj = o;
2789 child_frame.retval = &retval;
2793 if (csig->param_count) {
2794 sp -= csig->param_count;
2795 child_frame.stack_args = sp;
2797 child_frame.stack_args = NULL;
2800 g_assert (csig->call_convention == MONO_CALL_DEFAULT);
2802 child_frame.ip = NULL;
2803 child_frame.ex = NULL;
2805 ves_exec_method_with_context (&child_frame, context);
2807 context->current_frame = frame;
2809 if (child_frame.ex) {
2811 * An exception occurred, need to run finally, fault and catch handlers..
2813 frame->ex = child_frame.ex;
2814 goto handle_finally;
2817 * a constructor returns void, but we need to return the object we created
2820 if (newobj_class->valuetype && !newobj_class->enumtype) {
2821 *sp = valuetype_this;
2822 } else if (newobj_class == mono_defaults.string_class) {
2830 MINT_IN_CASE(MINT_CASTCLASS)
2831 c = rtm->data_items [*(guint16 *)(ip + 1)];
2832 if ((o = sp [-1].data.p)) {
2833 MonoObject *isinst_obj = mono_object_isinst_checked (o, c, &error);
2834 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2836 THROW_EX (mono_get_exception_invalid_cast (), ip);
2840 MINT_IN_CASE(MINT_ISINST)
2841 c = rtm->data_items [*(guint16 *)(ip + 1)];
2842 if ((o = sp [-1].data.p)) {
2843 MonoObject *isinst_obj = mono_object_isinst_checked (o, c, &error);
2844 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2846 sp [-1].data.p = NULL;
2850 MINT_IN_CASE(MINT_CONV_R_UN_I4)
2851 sp [-1].data.f = (double)(guint32)sp [-1].data.i;
2854 MINT_IN_CASE(MINT_CONV_R_UN_I8)
2855 sp [-1].data.f = (double)(guint64)sp [-1].data.l;
2858 MINT_IN_CASE(MINT_UNBOX)
2859 c = rtm->data_items[*(guint16 *)(ip + 1)];
2863 THROW_EX (mono_get_exception_null_reference (), ip);
2865 MonoObject *isinst_obj = mono_object_isinst_checked (o, c, &error);
2866 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2867 if (!(isinst_obj || ((o->vtable->klass->rank == 0) && (o->vtable->klass->element_class == c->element_class))))
2868 THROW_EX (mono_get_exception_invalid_cast (), ip);
2870 if (c->byval_arg.type == MONO_TYPE_VALUETYPE && !c->enumtype) {
2871 int size = mono_class_native_size (c, NULL);
2872 sp [-1].data.p = vt_sp;
2873 vt_sp += (size + 7) & ~7;
2875 stackval_from_data (&c->byval_arg, &sp [-1], mono_object_unbox (o), FALSE);
2878 MINT_IN_CASE(MINT_THROW)
2880 frame->ex_handler = NULL;
2882 sp->data.p = mono_get_exception_null_reference ();
2883 THROW_EX ((MonoException *)sp->data.p, ip);
2885 MINT_IN_CASE(MINT_LDFLDA)
2888 THROW_EX (mono_get_exception_null_reference (), ip);
2889 sp[-1].data.p = (char *)o + * (guint16 *)(ip + 1);
2892 MINT_IN_CASE(MINT_CKNULL)
2895 THROW_EX (mono_get_exception_null_reference (), ip);
2899 #define LDFLD(datamem, fieldtype) \
2900 o = sp [-1].data.p; \
2902 THROW_EX (mono_get_exception_null_reference (), ip); \
2903 sp[-1].data.datamem = * (fieldtype *)((char *)o + * (guint16 *)(ip + 1)) ; \
2906 MINT_IN_CASE(MINT_LDFLD_I1) LDFLD(i, gint8); MINT_IN_BREAK;
2907 MINT_IN_CASE(MINT_LDFLD_U1) LDFLD(i, guint8); MINT_IN_BREAK;
2908 MINT_IN_CASE(MINT_LDFLD_I2) LDFLD(i, gint16); MINT_IN_BREAK;
2909 MINT_IN_CASE(MINT_LDFLD_U2) LDFLD(i, guint16); MINT_IN_BREAK;
2910 MINT_IN_CASE(MINT_LDFLD_I4) LDFLD(i, gint32); MINT_IN_BREAK;
2911 MINT_IN_CASE(MINT_LDFLD_I8) LDFLD(l, gint64); MINT_IN_BREAK;
2912 MINT_IN_CASE(MINT_LDFLD_R4) LDFLD(f, float); MINT_IN_BREAK;
2913 MINT_IN_CASE(MINT_LDFLD_R8) LDFLD(f, double); MINT_IN_BREAK;
2914 MINT_IN_CASE(MINT_LDFLD_O) LDFLD(p, gpointer); MINT_IN_BREAK;
2915 MINT_IN_CASE(MINT_LDFLD_P) LDFLD(p, gpointer); MINT_IN_BREAK;
2917 MINT_IN_CASE(MINT_LDFLD_VT)
2920 THROW_EX (mono_get_exception_null_reference (), ip);
2921 i32 = READ32(ip + 2);
2922 sp [-1].data.p = vt_sp;
2923 memcpy(sp [-1].data.p, (char *)o + * (guint16 *)(ip + 1), i32);
2924 vt_sp += (i32 + 7) & ~7;
2928 MINT_IN_CASE(MINT_LDRMFLD) {
2930 MonoClassField *field;
2935 THROW_EX (mono_get_exception_null_reference (), ip);
2936 field = rtm->data_items[* (guint16 *)(ip + 1)];
2938 if (mono_object_is_transparent_proxy (o)) {
2939 MonoClass *klass = ((MonoTransparentProxy*)o)->remote_class->proxy_class;
2941 addr = mono_load_remote_field_checked (o, klass, field, &tmp, &error);
2942 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2944 addr = (char*)o + field->offset;
2947 stackval_from_data (field->type, &sp [-1], addr, FALSE);
2951 MINT_IN_CASE(MINT_LDRMFLD_VT) {
2952 MonoClassField *field;
2958 THROW_EX (mono_get_exception_null_reference (), ip);
2959 field = rtm->data_items[* (guint16 *)(ip + 1)];
2960 i32 = READ32(ip + 2);
2962 if (mono_object_is_transparent_proxy (o)) {
2963 MonoClass *klass = ((MonoTransparentProxy*)o)->remote_class->proxy_class;
2964 addr = mono_load_remote_field_checked (o, klass, field, &tmp, &error);
2965 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2967 addr = (char*)o + field->offset;
2970 sp [-1].data.p = vt_sp;
2971 memcpy(sp [-1].data.p, (char *)o + * (guint16 *)(ip + 1), i32);
2972 vt_sp += (i32 + 7) & ~7;
2973 memcpy(sp [-1].data.p, addr, i32);
2977 #define STFLD(datamem, fieldtype) \
2978 o = sp [-2].data.p; \
2980 THROW_EX (mono_get_exception_null_reference (), ip); \
2982 * (fieldtype *)((char *)o + * (guint16 *)(ip + 1)) = sp[1].data.datamem; \
2985 MINT_IN_CASE(MINT_STFLD_I1) STFLD(i, gint8); MINT_IN_BREAK;
2986 MINT_IN_CASE(MINT_STFLD_U1) STFLD(i, guint8); MINT_IN_BREAK;
2987 MINT_IN_CASE(MINT_STFLD_I2) STFLD(i, gint16); MINT_IN_BREAK;
2988 MINT_IN_CASE(MINT_STFLD_U2) STFLD(i, guint16); MINT_IN_BREAK;
2989 MINT_IN_CASE(MINT_STFLD_I4) STFLD(i, gint32); MINT_IN_BREAK;
2990 MINT_IN_CASE(MINT_STFLD_I8) STFLD(l, gint64); MINT_IN_BREAK;
2991 MINT_IN_CASE(MINT_STFLD_R4) STFLD(f, float); MINT_IN_BREAK;
2992 MINT_IN_CASE(MINT_STFLD_R8) STFLD(f, double); MINT_IN_BREAK;
2993 MINT_IN_CASE(MINT_STFLD_O) STFLD(p, gpointer); MINT_IN_BREAK;
2994 MINT_IN_CASE(MINT_STFLD_P) STFLD(p, gpointer); MINT_IN_BREAK;
2996 MINT_IN_CASE(MINT_STFLD_VT)
2999 THROW_EX (mono_get_exception_null_reference (), ip);
3000 i32 = READ32(ip + 2);
3002 memcpy((char *)o + * (guint16 *)(ip + 1), sp [1].data.p, i32);
3003 vt_sp -= (i32 + 7) & ~7;
3007 MINT_IN_CASE(MINT_STRMFLD) {
3008 MonoClassField *field;
3012 THROW_EX (mono_get_exception_null_reference (), ip);
3014 field = rtm->data_items[* (guint16 *)(ip + 1)];
3017 if (mono_object_is_transparent_proxy (o)) {
3018 MonoClass *klass = ((MonoTransparentProxy*)o)->remote_class->proxy_class;
3019 mono_store_remote_field_checked (o, klass, field, &sp [-1].data, &error);
3020 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3022 stackval_to_data (field->type, &sp [-1], (char*)o + field->offset, FALSE);
3027 MINT_IN_CASE(MINT_STRMFLD_VT) {
3028 MonoClassField *field;
3032 THROW_EX (mono_get_exception_null_reference (), ip);
3033 field = rtm->data_items[* (guint16 *)(ip + 1)];
3034 i32 = READ32(ip + 2);
3037 if (mono_object_is_transparent_proxy (o)) {
3038 MonoClass *klass = ((MonoTransparentProxy*)o)->remote_class->proxy_class;
3039 mono_store_remote_field_checked (o, klass, field, &sp [-1].data, &error);
3040 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3042 memcpy((char*)o + field->offset, sp [-1].data.p, i32);
3045 vt_sp -= (i32 + 7) & ~7;
3048 MINT_IN_CASE(MINT_LDSFLDA) {
3049 MonoClassField *field = rtm->data_items[*(guint16 *)(ip + 1)];
3050 MonoVTable *vt = mono_class_vtable (context->domain, field->parent);
3053 if (!vt->initialized) {
3055 mono_runtime_class_init_full (vt, &error);
3056 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3060 if (context->domain->special_static_fields && (addr = g_hash_table_lookup (context->domain->special_static_fields, field)))
3061 sp->data.p = mono_get_special_static_data (GPOINTER_TO_UINT (addr));
3063 sp->data.p = (char*)(vt->vtable) + field->offset;
3067 MINT_IN_CASE(MINT_LDSFLD) {
3069 MonoClassField *field;
3072 field = rtm->data_items[*(guint16 *)(ip + 1)];
3073 vt = rtm->data_items [*(guint16 *)(ip + 2)];
3074 if (!vt->initialized) {
3076 mono_runtime_class_init_full (vt, &error);
3077 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3080 if (context->domain->special_static_fields && (addr = g_hash_table_lookup (context->domain->special_static_fields, field)))
3081 addr = mono_get_special_static_data (GPOINTER_TO_UINT (addr));
3083 addr = (char*)(vt->vtable) + field->offset;
3085 stackval_from_data (field->type, sp, addr, FALSE);
3089 MINT_IN_CASE(MINT_LDSFLD_I4) {
3090 MonoClassField *field = rtm->data_items[*(guint16 *)(ip + 1)];
3091 MonoVTable *vt = rtm->data_items [*(guint16 *)(ip + 2)];
3092 if (!vt->initialized) {
3094 mono_runtime_class_init_full (vt, &error);
3095 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3098 sp->data.i = * (gint32 *)((char*)(vt->vtable) + field->offset);
3102 MINT_IN_CASE(MINT_LDSFLD_O) {
3103 MonoClassField *field = rtm->data_items[*(guint16 *)(ip + 1)];
3104 MonoVTable *vt = rtm->data_items [*(guint16 *)(ip + 2)];
3105 if (!vt->initialized) {
3107 mono_runtime_class_init_full (vt, &error);
3108 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3111 sp->data.p = * (gpointer *)((char*)(vt->vtable) + field->offset);
3115 MINT_IN_CASE(MINT_LDSFLD_VT) {
3117 MonoClassField *field;
3122 token = * (guint16 *)(ip + 1);
3123 size = READ32(ip + 2);
3124 field = rtm->data_items[token];
3127 vt = mono_class_vtable (context->domain, field->parent);
3128 if (!vt->initialized) {
3130 mono_runtime_class_init_full (vt, &error);
3131 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3134 if (context->domain->special_static_fields && (addr = g_hash_table_lookup (context->domain->special_static_fields, field)))
3135 addr = mono_get_special_static_data (GPOINTER_TO_UINT (addr));
3137 addr = (char*)(vt->vtable) + field->offset;
3140 vt_sp += (size + 7) & ~7;
3141 stackval_from_data (field->type, sp, addr, FALSE);
3145 MINT_IN_CASE(MINT_STSFLD) {
3147 MonoClassField *field;
3151 token = * (guint16 *)(ip + 1);
3152 field = rtm->data_items[token];
3156 vt = mono_class_vtable (context->domain, field->parent);
3157 if (!vt->initialized) {
3159 mono_runtime_class_init_full (vt, &error);
3160 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3163 if (context->domain->special_static_fields && (addr = g_hash_table_lookup (context->domain->special_static_fields, field)))
3164 addr = mono_get_special_static_data (GPOINTER_TO_UINT (addr));
3166 addr = (char*)(vt->vtable) + field->offset;
3168 stackval_to_data (field->type, sp, addr, FALSE);
3171 MINT_IN_CASE(MINT_STSFLD_VT) {
3173 MonoClassField *field;
3178 token = * (guint16 *)(ip + 1);
3179 size = READ32(ip + 2);
3180 field = rtm->data_items[token];
3183 vt = mono_class_vtable (context->domain, field->parent);
3184 if (!vt->initialized) {
3186 mono_runtime_class_init_full (vt, &error);
3187 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3190 if (context->domain->special_static_fields && (addr = g_hash_table_lookup (context->domain->special_static_fields, field)))
3191 addr = mono_get_special_static_data (GPOINTER_TO_UINT (addr));
3193 addr = (char*)(vt->vtable) + field->offset;
3195 stackval_to_data (field->type, sp, addr, FALSE);
3196 vt_sp -= (size + 7) & ~7;
3199 MINT_IN_CASE(MINT_STOBJ_VT) {
3201 c = rtm->data_items[* (guint16 *)(ip + 1)];
3203 size = mono_class_value_size (c, NULL);
3204 memcpy(sp [-2].data.p, sp [-1].data.p, size);
3205 vt_sp -= (size + 7) & ~7;
3209 MINT_IN_CASE(MINT_STOBJ) {
3211 c = rtm->data_items[* (guint16 *)(ip + 1)];
3213 size = mono_class_value_size (c, NULL);
3214 memcpy(sp [-2].data.p, &sp [-1].data, size);
3218 MINT_IN_CASE(MINT_CONV_OVF_I4_UN_R8)
3219 if (sp [-1].data.f < 0 || sp [-1].data.f > MYGUINT32_MAX)
3220 THROW_EX (mono_get_exception_overflow (), ip);
3221 sp [-1].data.i = (guint32)sp [-1].data.f;
3224 MINT_IN_CASE(MINT_CONV_OVF_U8_I4)
3225 if (sp [-1].data.i < 0)
3226 THROW_EX (mono_get_exception_overflow (), ip);
3227 sp [-1].data.l = sp [-1].data.i;
3230 MINT_IN_CASE(MINT_CONV_OVF_U8_R8)
3231 MINT_IN_CASE(MINT_CONV_OVF_I8_UN_R8)
3232 if (sp [-1].data.f < 0 || sp [-1].data.f > 9223372036854775807LL)
3233 THROW_EX (mono_get_exception_overflow (), ip);
3234 sp [-1].data.l = (guint64)sp [-1].data.f;
3237 MINT_IN_CASE(MINT_CONV_OVF_I8_R8)
3238 if (sp [-1].data.f < MYGINT64_MIN || sp [-1].data.f > MYGINT64_MAX)
3239 THROW_EX (mono_get_exception_overflow (), ip);
3240 sp [-1].data.l = (gint64)sp [-1].data.f;
3243 MINT_IN_CASE(MINT_CONV_OVF_I4_UN_I8)
3244 if ((mono_u)sp [-1].data.l > MYGUINT32_MAX)
3245 THROW_EX (mono_get_exception_overflow (), ip);
3246 sp [-1].data.i = (mono_u)sp [-1].data.l;
3249 MINT_IN_CASE(MINT_BOX)
3250 c = rtm->data_items [* (guint16 *)(ip + 1)];
3252 if (c->byval_arg.type == MONO_TYPE_VALUETYPE && !c->enumtype) {
3253 int size = mono_class_value_size (c, NULL);
3254 sp [-1].data.p = mono_value_box_checked (context->domain, c, sp [-1].data.p, &error);
3255 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3256 size = (size + 7) & ~7;
3260 stackval_to_data (&c->byval_arg, &sp [-1], (char*)&sp [-1], FALSE);
3261 sp [-1].data.p = mono_value_box_checked (context->domain, c, &sp [-1], &error);
3262 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3266 MINT_IN_CASE(MINT_NEWARR)
3267 sp [-1].data.p = (MonoObject*) mono_array_new_checked (context->domain, rtm->data_items[*(guint16 *)(ip + 1)], sp [-1].data.i, &error);
3268 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3270 /*if (profiling_classes) {
3271 guint count = GPOINTER_TO_UINT (g_hash_table_lookup (profiling_classes, o->vtable->klass));
3273 g_hash_table_insert (profiling_classes, o->vtable->klass, GUINT_TO_POINTER (count));
3277 MINT_IN_CASE(MINT_LDLEN)
3280 THROW_EX (mono_get_exception_null_reference (), ip);
3281 sp [-1].data.nati = mono_array_length ((MonoArray *)o);
3284 MINT_IN_CASE(MINT_GETCHR) {
3288 THROW_EX (mono_get_exception_null_reference (), ip);
3289 i32 = sp [-1].data.i;
3290 if (i32 < 0 || i32 >= mono_string_length (s))
3291 THROW_EX (mono_get_exception_index_out_of_range (), ip);
3293 sp [-1].data.i = mono_string_chars(s)[i32];
3297 MINT_IN_CASE(MINT_STRLEN)
3299 sp [-1].data.i = mono_string_length ((MonoString*)sp [-1].data.p);
3301 MINT_IN_CASE(MINT_ARRAY_RANK)
3304 THROW_EX (mono_get_exception_null_reference (), ip);
3305 sp [-1].data.i = mono_object_class (sp [-1].data.p)->rank;
3308 MINT_IN_CASE(MINT_LDELEMA) {
3312 /*token = READ32 (ip)*/;
3318 aindex = sp [1].data.i;
3319 if (aindex >= mono_array_length ((MonoArray *) o))
3320 THROW_EX (mono_get_exception_index_out_of_range (), ip - 2);
3322 /* check the array element corresponds to token */
3323 esize = mono_array_element_size (((MonoArray *) o)->obj.vtable->klass);
3325 sp->data.p = mono_array_addr_with_size ((MonoArray *) o, esize, aindex);
3329 MINT_IN_CASE(MINT_LDELEM_I1) /* fall through */
3330 MINT_IN_CASE(MINT_LDELEM_U1) /* fall through */
3331 MINT_IN_CASE(MINT_LDELEM_I2) /* fall through */
3332 MINT_IN_CASE(MINT_LDELEM_U2) /* fall through */
3333 MINT_IN_CASE(MINT_LDELEM_I4) /* fall through */
3334 MINT_IN_CASE(MINT_LDELEM_U4) /* fall through */
3335 MINT_IN_CASE(MINT_LDELEM_I8) /* fall through */
3336 MINT_IN_CASE(MINT_LDELEM_I) /* fall through */
3337 MINT_IN_CASE(MINT_LDELEM_R4) /* fall through */
3338 MINT_IN_CASE(MINT_LDELEM_R8) /* fall through */
3339 MINT_IN_CASE(MINT_LDELEM_REF) {
3347 THROW_EX (mono_get_exception_null_reference (), ip);
3349 aindex = sp [1].data.i;
3350 if (aindex >= mono_array_length (o))
3351 THROW_EX (mono_get_exception_index_out_of_range (), ip);
3354 * FIXME: throw mono_get_exception_array_type_mismatch () if needed
3357 case MINT_LDELEM_I1:
3358 sp [0].data.i = mono_array_get (o, gint8, aindex);
3360 case MINT_LDELEM_U1:
3361 sp [0].data.i = mono_array_get (o, guint8, aindex);
3363 case MINT_LDELEM_I2:
3364 sp [0].data.i = mono_array_get (o, gint16, aindex);
3366 case MINT_LDELEM_U2:
3367 sp [0].data.i = mono_array_get (o, guint16, aindex);
3370 sp [0].data.nati = mono_array_get (o, mono_i, aindex);
3372 case MINT_LDELEM_I4:
3373 sp [0].data.i = mono_array_get (o, gint32, aindex);
3375 case MINT_LDELEM_U4:
3376 sp [0].data.i = mono_array_get (o, guint32, aindex);
3378 case MINT_LDELEM_I8:
3379 sp [0].data.l = mono_array_get (o, guint64, aindex);
3381 case MINT_LDELEM_R4:
3382 sp [0].data.f = mono_array_get (o, float, aindex);
3384 case MINT_LDELEM_R8:
3385 sp [0].data.f = mono_array_get (o, double, aindex);
3387 case MINT_LDELEM_REF:
3388 sp [0].data.p = mono_array_get (o, gpointer, aindex);
3398 MINT_IN_CASE(MINT_STELEM_I) /* fall through */
3399 MINT_IN_CASE(MINT_STELEM_I1) /* fall through */
3400 MINT_IN_CASE(MINT_STELEM_I2) /* fall through */
3401 MINT_IN_CASE(MINT_STELEM_I4) /* fall through */
3402 MINT_IN_CASE(MINT_STELEM_I8) /* fall through */
3403 MINT_IN_CASE(MINT_STELEM_R4) /* fall through */
3404 MINT_IN_CASE(MINT_STELEM_R8) /* fall through */
3405 MINT_IN_CASE(MINT_STELEM_REF) {
3412 THROW_EX (mono_get_exception_null_reference (), ip);
3414 aindex = sp [1].data.i;
3415 if (aindex >= mono_array_length ((MonoArray *)o))
3416 THROW_EX (mono_get_exception_index_out_of_range (), ip);
3420 mono_array_set ((MonoArray *)o, mono_i, aindex, sp [2].data.nati);
3422 case MINT_STELEM_I1:
3423 mono_array_set ((MonoArray *)o, gint8, aindex, sp [2].data.i);
3425 case MINT_STELEM_I2:
3426 mono_array_set ((MonoArray *)o, gint16, aindex, sp [2].data.i);
3428 case MINT_STELEM_I4:
3429 mono_array_set ((MonoArray *)o, gint32, aindex, sp [2].data.i);
3431 case MINT_STELEM_I8:
3432 mono_array_set ((MonoArray *)o, gint64, aindex, sp [2].data.l);
3434 case MINT_STELEM_R4:
3435 mono_array_set ((MonoArray *)o, float, aindex, sp [2].data.f);
3437 case MINT_STELEM_R8:
3438 mono_array_set ((MonoArray *)o, double, aindex, sp [2].data.f);
3440 case MINT_STELEM_REF: {
3441 MonoObject *isinst_obj = mono_object_isinst_checked (sp [2].data.p, mono_object_class (o)->element_class, &error);
3442 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3443 if (sp [2].data.p && !isinst_obj)
3444 THROW_EX (mono_get_exception_array_type_mismatch (), ip);
3445 mono_array_set ((MonoArray *)o, gpointer, aindex, sp [2].data.p);
3454 MINT_IN_CASE(MINT_CONV_OVF_I4_U4)
3455 if (sp [-1].data.i < 0)
3456 THROW_EX (mono_get_exception_overflow (), ip);
3459 MINT_IN_CASE(MINT_CONV_OVF_I4_I8)
3460 if (sp [-1].data.l < MYGINT32_MIN || sp [-1].data.l > MYGINT32_MAX)
3461 THROW_EX (mono_get_exception_overflow (), ip);
3462 sp [-1].data.i = (gint32) sp [-1].data.l;
3465 MINT_IN_CASE(MINT_CONV_OVF_I4_R8)
3466 if (sp [-1].data.f < MYGINT32_MIN || sp [-1].data.f > MYGINT32_MAX)
3467 THROW_EX (mono_get_exception_overflow (), ip);
3468 sp [-1].data.i = (gint32) sp [-1].data.f;
3471 MINT_IN_CASE(MINT_CONV_OVF_U4_I4)
3472 if (sp [-1].data.i < 0)
3473 THROW_EX (mono_get_exception_overflow (), ip);
3476 MINT_IN_CASE(MINT_CONV_OVF_U4_I8)
3477 if (sp [-1].data.l < 0 || sp [-1].data.l > MYGUINT32_MAX)
3478 THROW_EX (mono_get_exception_overflow (), ip);
3479 sp [-1].data.i = (guint32) sp [-1].data.l;
3482 MINT_IN_CASE(MINT_CONV_OVF_U4_R8)
3483 if (sp [-1].data.f < 0 || sp [-1].data.f > MYGUINT32_MAX)
3484 THROW_EX (mono_get_exception_overflow (), ip);
3485 sp [-1].data.i = (guint32) sp [-1].data.f;
3488 MINT_IN_CASE(MINT_CONV_OVF_I2_I4)
3489 if (sp [-1].data.i < -32768 || sp [-1].data.i > 32767)
3490 THROW_EX (mono_get_exception_overflow (), ip);
3493 MINT_IN_CASE(MINT_CONV_OVF_I2_I8)
3494 if (sp [-1].data.l < -32768 || sp [-1].data.l > 32767)
3495 THROW_EX (mono_get_exception_overflow (), ip);
3496 sp [-1].data.i = (gint16) sp [-1].data.l;
3499 MINT_IN_CASE(MINT_CONV_OVF_I2_R8)
3500 if (sp [-1].data.f < -32768 || sp [-1].data.f > 32767)
3501 THROW_EX (mono_get_exception_overflow (), ip);
3502 sp [-1].data.i = (gint16) sp [-1].data.f;
3505 MINT_IN_CASE(MINT_CONV_OVF_U2_I4)
3506 if (sp [-1].data.i < 0 || sp [-1].data.i > 65535)
3507 THROW_EX (mono_get_exception_overflow (), ip);
3510 MINT_IN_CASE(MINT_CONV_OVF_U2_I8)
3511 if (sp [-1].data.l < 0 || sp [-1].data.l > 65535)
3512 THROW_EX (mono_get_exception_overflow (), ip);
3513 sp [-1].data.i = (guint16) sp [-1].data.l;
3516 MINT_IN_CASE(MINT_CONV_OVF_U2_R8)
3517 if (sp [-1].data.f < 0 || sp [-1].data.f > 65535)
3518 THROW_EX (mono_get_exception_overflow (), ip);
3519 sp [-1].data.i = (guint16) sp [-1].data.f;
3522 MINT_IN_CASE(MINT_CONV_OVF_I1_I4)
3523 if (sp [-1].data.i < -128 || sp [-1].data.i > 127)
3524 THROW_EX (mono_get_exception_overflow (), ip);
3527 MINT_IN_CASE(MINT_CONV_OVF_I1_I8)
3528 if (sp [-1].data.l < -128 || sp [-1].data.l > 127)
3529 THROW_EX (mono_get_exception_overflow (), ip);
3530 sp [-1].data.i = (gint8) sp [-1].data.l;
3533 MINT_IN_CASE(MINT_CONV_OVF_I1_R8)
3534 if (sp [-1].data.f < -128 || sp [-1].data.f > 127)
3535 THROW_EX (mono_get_exception_overflow (), ip);
3536 sp [-1].data.i = (gint8) sp [-1].data.f;
3539 MINT_IN_CASE(MINT_CONV_OVF_U1_I4)
3540 if (sp [-1].data.i < 0 || sp [-1].data.i > 255)
3541 THROW_EX (mono_get_exception_overflow (), ip);
3544 MINT_IN_CASE(MINT_CONV_OVF_U1_I8)
3545 if (sp [-1].data.l < 0 || sp [-1].data.l > 255)
3546 THROW_EX (mono_get_exception_overflow (), ip);
3547 sp [-1].data.i = (guint8) sp [-1].data.l;
3550 MINT_IN_CASE(MINT_CONV_OVF_U1_R8)
3551 if (sp [-1].data.f < 0 || sp [-1].data.f > 255)
3552 THROW_EX (mono_get_exception_overflow (), ip);
3553 sp [-1].data.i = (guint8) sp [-1].data.f;
3557 MINT_IN_CASE(MINT_LDELEM)
3558 MINT_IN_CASE(MINT_STELEM)
3559 MINT_IN_CASE(MINT_UNBOX_ANY)
3561 MINT_IN_CASE(MINT_REFANYVAL) ves_abort(); MINT_IN_BREAK;
3563 MINT_IN_CASE(MINT_CKFINITE)
3564 if (!isfinite(sp [-1].data.f))
3565 THROW_EX (mono_get_exception_arithmetic (), ip);
3569 MINT_IN_CASE(MINT_MKREFANY) ves_abort(); MINT_IN_BREAK;
3571 MINT_IN_CASE(MINT_LDTOKEN)
3574 * (gpointer *)sp->data.p = rtm->data_items[*(guint16 *)(ip + 1)];
3578 MINT_IN_CASE(MINT_ADD_OVF_I4)
3579 if (CHECK_ADD_OVERFLOW (sp [-2].data.i, sp [-1].data.i))
3580 THROW_EX (mono_get_exception_overflow (), ip);
3583 MINT_IN_CASE(MINT_ADD_OVF_I8)
3584 if (CHECK_ADD_OVERFLOW64 (sp [-2].data.l, sp [-1].data.l))
3585 THROW_EX (mono_get_exception_overflow (), ip);
3588 MINT_IN_CASE(MINT_ADD_OVF_UN_I4)
3589 if (CHECK_ADD_OVERFLOW_UN (sp [-2].data.i, sp [-1].data.i))
3590 THROW_EX (mono_get_exception_overflow (), ip);
3591 BINOP_CAST(i, +, guint32);
3593 MINT_IN_CASE(MINT_ADD_OVF_UN_I8)
3594 if (CHECK_ADD_OVERFLOW64_UN (sp [-2].data.l, sp [-1].data.l))
3595 THROW_EX (mono_get_exception_overflow (), ip);
3596 BINOP_CAST(l, +, guint64);
3598 MINT_IN_CASE(MINT_MUL_OVF_I4)
3599 if (CHECK_MUL_OVERFLOW (sp [-2].data.i, sp [-1].data.i))
3600 THROW_EX (mono_get_exception_overflow (), ip);
3603 MINT_IN_CASE(MINT_MUL_OVF_I8)
3604 if (CHECK_MUL_OVERFLOW64 (sp [-2].data.l, sp [-1].data.l))
3605 THROW_EX (mono_get_exception_overflow (), ip);
3608 MINT_IN_CASE(MINT_MUL_OVF_UN_I4)
3609 if (CHECK_MUL_OVERFLOW_UN (sp [-2].data.i, sp [-1].data.i))
3610 THROW_EX (mono_get_exception_overflow (), ip);
3611 BINOP_CAST(i, *, guint32);
3613 MINT_IN_CASE(MINT_MUL_OVF_UN_I8)
3614 if (CHECK_MUL_OVERFLOW64_UN (sp [-2].data.l, sp [-1].data.l))
3615 THROW_EX (mono_get_exception_overflow (), ip);
3616 BINOP_CAST(l, *, guint64);
3618 MINT_IN_CASE(MINT_SUB_OVF_I4)
3619 if (CHECK_SUB_OVERFLOW (sp [-2].data.i, sp [-1].data.i))
3620 THROW_EX (mono_get_exception_overflow (), ip);
3623 MINT_IN_CASE(MINT_SUB_OVF_I8)
3624 if (CHECK_SUB_OVERFLOW64 (sp [-2].data.l, sp [-1].data.l))
3625 THROW_EX (mono_get_exception_overflow (), ip);
3628 MINT_IN_CASE(MINT_SUB_OVF_UN_I4)
3629 if (CHECK_SUB_OVERFLOW_UN (sp [-2].data.i, sp [-1].data.i))
3630 THROW_EX (mono_get_exception_overflow (), ip);
3631 BINOP_CAST(i, -, guint32);
3633 MINT_IN_CASE(MINT_SUB_OVF_UN_I8)
3634 if (CHECK_SUB_OVERFLOW64_UN (sp [-2].data.l, sp [-1].data.l))
3635 THROW_EX (mono_get_exception_overflow (), ip);
3636 BINOP_CAST(l, -, guint64);
3638 MINT_IN_CASE(MINT_ENDFINALLY)
3640 ip = finally_ips->data;
3641 finally_ips = g_slist_remove (finally_ips, ip);
3648 MINT_IN_CASE(MINT_LEAVE) /* Fall through */
3649 MINT_IN_CASE(MINT_LEAVE_S)
3650 while (sp > frame->stack) {
3654 if (*ip == MINT_LEAVE_S) {
3655 ip += (short) *(ip + 1);
3657 ip += (gint32) READ32 (ip + 1);
3660 if (frame->ex_handler != NULL && MONO_OFFSET_IN_HANDLER(frame->ex_handler, frame->ip - rtm->code)) {
3661 frame->ex_handler = NULL;
3664 goto handle_finally;
3666 MINT_IN_CASE(MINT_ICALL_V_V)
3667 MINT_IN_CASE(MINT_ICALL_V_P)
3668 MINT_IN_CASE(MINT_ICALL_P_V)
3669 MINT_IN_CASE(MINT_ICALL_P_P)
3670 MINT_IN_CASE(MINT_ICALL_PP_V)
3671 MINT_IN_CASE(MINT_ICALL_PI_V)
3672 MINT_IN_CASE(MINT_ICALL_PP_P)
3673 MINT_IN_CASE(MINT_ICALL_PI_P)
3674 MINT_IN_CASE(MINT_ICALL_PPP_V)
3675 MINT_IN_CASE(MINT_ICALL_PPI_V)
3676 sp = do_icall (context, *ip, sp, rtm->data_items [*(guint16 *)(ip + 1)]);
3677 if (frame->ex != NULL)
3678 goto handle_exception;
3681 MINT_IN_CASE(MINT_MONO_LDPTR)
3682 sp->data.p = rtm->data_items [*(guint16 *)(ip + 1)];
3686 MINT_IN_CASE(MINT_MONO_NEWOBJ)
3687 sp->data.p = mono_object_new_checked (context->domain, rtm->data_items [*(guint16 *)(ip + 1)], &error);
3688 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3692 MINT_IN_CASE(MINT_MONO_FREE)
3695 g_error ("that doesn't seem right");
3696 g_free (sp->data.p);
3698 MINT_IN_CASE(MINT_MONO_RETOBJ)
3701 stackval_from_data (mono_method_signature (frame->runtime_method->method)->ret, frame->retval, sp->data.p,
3702 mono_method_signature (frame->runtime_method->method)->pinvoke);
3703 if (sp > frame->stack)
3704 g_warning ("retobj: more values on stack: %d", sp-frame->stack);
3707 #define RELOP(datamem, op) \
3709 sp [-1].data.i = sp [-1].data.datamem op sp [0].data.datamem; \
3711 MINT_IN_CASE(MINT_CEQ_I4)
3714 MINT_IN_CASE(MINT_CEQ0_I4)
3715 sp [-1].data.i = (sp [-1].data.i == 0);
3718 MINT_IN_CASE(MINT_CEQ_I8)
3721 MINT_IN_CASE(MINT_CEQ_R8)
3723 if (isunordered (sp [-1].data.f, sp [0].data.f))
3726 sp [-1].data.i = sp [-1].data.f == sp [0].data.f;
3729 MINT_IN_CASE(MINT_CGT_I4)
3732 MINT_IN_CASE(MINT_CGT_I8)
3735 MINT_IN_CASE(MINT_CGT_R8)
3737 if (isunordered (sp [-1].data.f, sp [0].data.f))
3740 sp [-1].data.i = sp [-1].data.f > sp [0].data.f;
3744 #define RELOP_CAST(datamem, op, type) \
3746 sp [-1].data.i = (type)sp [-1].data.datamem op (type)sp [0].data.datamem; \
3749 MINT_IN_CASE(MINT_CGT_UN_I4)
3750 RELOP_CAST(i, >, guint32);
3752 MINT_IN_CASE(MINT_CGT_UN_I8)
3753 RELOP_CAST(l, >, guint64);
3755 MINT_IN_CASE(MINT_CGT_UN_R8)
3757 if (isunordered (sp [-1].data.f, sp [0].data.f))
3760 sp [-1].data.i = sp [-1].data.f > sp [0].data.f;
3763 MINT_IN_CASE(MINT_CLT_I4)
3766 MINT_IN_CASE(MINT_CLT_I8)
3769 MINT_IN_CASE(MINT_CLT_R8)
3771 if (isunordered (sp [-1].data.f, sp [0].data.f))
3774 sp [-1].data.i = sp [-1].data.f < sp [0].data.f;
3777 MINT_IN_CASE(MINT_CLT_UN_I4)
3778 RELOP_CAST(i, <, guint32);
3780 MINT_IN_CASE(MINT_CLT_UN_I8)
3781 RELOP_CAST(l, <, guint64);
3783 MINT_IN_CASE(MINT_CLT_UN_R8)
3785 if (isunordered (sp [-1].data.f, sp [0].data.f))
3788 sp [-1].data.i = sp [-1].data.f < sp [0].data.f;
3791 MINT_IN_CASE(MINT_LDFTN) {
3792 sp->data.p = rtm->data_items [* (guint16 *)(ip + 1)];
3797 MINT_IN_CASE(MINT_LDVIRTFTN) {
3798 RuntimeMethod *m = rtm->data_items [* (guint16 *)(ip + 1)];
3802 THROW_EX (mono_get_exception_null_reference (), ip - 2);
3804 sp->data.p = get_virtual_method (context->domain, m, sp->data.p);
3809 MINT_IN_CASE(MINT_LDTHIS)
3810 sp->data.p = frame->obj;
3814 MINT_IN_CASE(MINT_STTHIS)
3816 frame->obj = sp->data.p;
3819 MINT_IN_CASE(MINT_LDTHISA)
3820 sp->data.p = &frame->obj;
3825 #define LDARG(datamem, argtype) \
3826 sp->data.datamem = * (argtype *)(frame->args + * (guint16 *)(ip + 1)); \
3830 MINT_IN_CASE(MINT_LDARG_I1) LDARG(i, gint8); MINT_IN_BREAK;
3831 MINT_IN_CASE(MINT_LDARG_U1) LDARG(i, guint8); MINT_IN_BREAK;
3832 MINT_IN_CASE(MINT_LDARG_I2) LDARG(i, gint16); MINT_IN_BREAK;
3833 MINT_IN_CASE(MINT_LDARG_U2) LDARG(i, guint16); MINT_IN_BREAK;
3834 MINT_IN_CASE(MINT_LDARG_I4) LDARG(i, gint32); MINT_IN_BREAK;
3835 MINT_IN_CASE(MINT_LDARG_I8) LDARG(l, gint64); MINT_IN_BREAK;
3836 MINT_IN_CASE(MINT_LDARG_R4) LDARG(f, float); MINT_IN_BREAK;
3837 MINT_IN_CASE(MINT_LDARG_R8) LDARG(f, double); MINT_IN_BREAK;
3838 MINT_IN_CASE(MINT_LDARG_O) LDARG(p, gpointer); MINT_IN_BREAK;
3839 MINT_IN_CASE(MINT_LDARG_P) LDARG(p, gpointer); MINT_IN_BREAK;
3841 MINT_IN_CASE(MINT_LDARG_VT)
3843 i32 = READ32(ip + 2);
3844 memcpy(sp->data.p, frame->args + * (guint16 *)(ip + 1), i32);
3845 vt_sp += (i32 + 7) & ~7;
3850 #define STARG(datamem, argtype) \
3852 * (argtype *)(frame->args + * (guint16 *)(ip + 1)) = sp->data.datamem; \
3855 MINT_IN_CASE(MINT_STARG_I1) STARG(i, gint8); MINT_IN_BREAK;
3856 MINT_IN_CASE(MINT_STARG_U1) STARG(i, guint8); MINT_IN_BREAK;
3857 MINT_IN_CASE(MINT_STARG_I2) STARG(i, gint16); MINT_IN_BREAK;
3858 MINT_IN_CASE(MINT_STARG_U2) STARG(i, guint16); MINT_IN_BREAK;
3859 MINT_IN_CASE(MINT_STARG_I4) STARG(i, gint32); MINT_IN_BREAK;
3860 MINT_IN_CASE(MINT_STARG_I8) STARG(l, gint64); MINT_IN_BREAK;
3861 MINT_IN_CASE(MINT_STARG_R4) STARG(f, float); MINT_IN_BREAK;
3862 MINT_IN_CASE(MINT_STARG_R8) STARG(f, double); MINT_IN_BREAK;
3863 MINT_IN_CASE(MINT_STARG_O) STARG(p, gpointer); MINT_IN_BREAK;
3864 MINT_IN_CASE(MINT_STARG_P) STARG(p, gpointer); MINT_IN_BREAK;
3866 MINT_IN_CASE(MINT_STARG_VT)
3867 i32 = READ32(ip + 2);
3869 memcpy(frame->args + * (guint16 *)(ip + 1), sp->data.p, i32);
3870 vt_sp -= (i32 + 7) & ~7;
3874 #define STINARG(datamem, argtype) \
3876 int n = * (guint16 *)(ip + 1); \
3877 * (argtype *)(frame->args + rtm->arg_offsets [n]) = frame->stack_args [n].data.datamem; \
3881 MINT_IN_CASE(MINT_STINARG_I1) STINARG(i, gint8); MINT_IN_BREAK;
3882 MINT_IN_CASE(MINT_STINARG_U1) STINARG(i, guint8); MINT_IN_BREAK;
3883 MINT_IN_CASE(MINT_STINARG_I2) STINARG(i, gint16); MINT_IN_BREAK;
3884 MINT_IN_CASE(MINT_STINARG_U2) STINARG(i, guint16); MINT_IN_BREAK;
3885 MINT_IN_CASE(MINT_STINARG_I4) STINARG(i, gint32); MINT_IN_BREAK;
3886 MINT_IN_CASE(MINT_STINARG_I8) STINARG(l, gint64); MINT_IN_BREAK;
3887 MINT_IN_CASE(MINT_STINARG_R4) STINARG(f, float); MINT_IN_BREAK;
3888 MINT_IN_CASE(MINT_STINARG_R8) STINARG(f, double); MINT_IN_BREAK;
3889 MINT_IN_CASE(MINT_STINARG_O) STINARG(p, gpointer); MINT_IN_BREAK;
3890 MINT_IN_CASE(MINT_STINARG_P) STINARG(p, gpointer); MINT_IN_BREAK;
3892 MINT_IN_CASE(MINT_STINARG_VT) {
3893 int n = * (guint16 *)(ip + 1);
3894 i32 = READ32(ip + 2);
3895 memcpy (frame->args + rtm->arg_offsets [n], frame->stack_args [n].data.p, i32);
3900 MINT_IN_CASE(MINT_LDARGA)
3901 sp->data.p = frame->args + * (guint16 *)(ip + 1);
3906 #define LDLOC(datamem, argtype) \
3907 sp->data.datamem = * (argtype *)(locals + * (guint16 *)(ip + 1)); \
3911 MINT_IN_CASE(MINT_LDLOC_I1) LDLOC(i, gint8); MINT_IN_BREAK;
3912 MINT_IN_CASE(MINT_LDLOC_U1) LDLOC(i, guint8); MINT_IN_BREAK;
3913 MINT_IN_CASE(MINT_LDLOC_I2) LDLOC(i, gint16); MINT_IN_BREAK;
3914 MINT_IN_CASE(MINT_LDLOC_U2) LDLOC(i, guint16); MINT_IN_BREAK;
3915 MINT_IN_CASE(MINT_LDLOC_I4) LDLOC(i, gint32); MINT_IN_BREAK;
3916 MINT_IN_CASE(MINT_LDLOC_I8) LDLOC(l, gint64); MINT_IN_BREAK;
3917 MINT_IN_CASE(MINT_LDLOC_R4) LDLOC(f, float); MINT_IN_BREAK;
3918 MINT_IN_CASE(MINT_LDLOC_R8) LDLOC(f, double); MINT_IN_BREAK;
3919 MINT_IN_CASE(MINT_LDLOC_O) LDLOC(p, gpointer); MINT_IN_BREAK;
3920 MINT_IN_CASE(MINT_LDLOC_P) LDLOC(p, gpointer); MINT_IN_BREAK;
3922 MINT_IN_CASE(MINT_LDLOC_VT)
3924 i32 = READ32(ip + 2);
3925 memcpy(sp->data.p, locals + * (guint16 *)(ip + 1), i32);
3926 vt_sp += (i32 + 7) & ~7;
3931 MINT_IN_CASE(MINT_LDLOCA_S)
3932 sp->data.p = locals + * (guint16 *)(ip + 1);
3937 #define STLOC(datamem, argtype) \
3939 * (argtype *)(locals + * (guint16 *)(ip + 1)) = sp->data.datamem; \
3942 MINT_IN_CASE(MINT_STLOC_I1) STLOC(i, gint8); MINT_IN_BREAK;
3943 MINT_IN_CASE(MINT_STLOC_U1) STLOC(i, guint8); MINT_IN_BREAK;
3944 MINT_IN_CASE(MINT_STLOC_I2) STLOC(i, gint16); MINT_IN_BREAK;
3945 MINT_IN_CASE(MINT_STLOC_U2) STLOC(i, guint16); MINT_IN_BREAK;
3946 MINT_IN_CASE(MINT_STLOC_I4) STLOC(i, gint32); MINT_IN_BREAK;
3947 MINT_IN_CASE(MINT_STLOC_I8) STLOC(l, gint64); MINT_IN_BREAK;
3948 MINT_IN_CASE(MINT_STLOC_R4) STLOC(f, float); MINT_IN_BREAK;
3949 MINT_IN_CASE(MINT_STLOC_R8) STLOC(f, double); MINT_IN_BREAK;
3950 MINT_IN_CASE(MINT_STLOC_O) STLOC(p, gpointer); MINT_IN_BREAK;
3951 MINT_IN_CASE(MINT_STLOC_P) STLOC(p, gpointer); MINT_IN_BREAK;
3953 #define STLOC_NP(datamem, argtype) \
3954 * (argtype *)(locals + * (guint16 *)(ip + 1)) = sp [-1].data.datamem; \
3957 MINT_IN_CASE(MINT_STLOC_NP_I4) STLOC_NP(i, gint32); MINT_IN_BREAK;
3958 MINT_IN_CASE(MINT_STLOC_NP_O) STLOC_NP(p, gpointer); MINT_IN_BREAK;
3960 MINT_IN_CASE(MINT_STLOC_VT)
3961 i32 = READ32(ip + 2);
3963 memcpy(locals + * (guint16 *)(ip + 1), sp->data.p, i32);
3964 vt_sp -= (i32 + 7) & ~7;
3968 MINT_IN_CASE(MINT_LOCALLOC)
3969 if (sp != frame->stack + 1) /*FIX?*/
3970 THROW_EX (mono_get_exception_execution_engine (NULL), ip);
3971 sp [-1].data.p = alloca (sp [-1].data.i);
3975 MINT_IN_CASE(MINT_ENDFILTER) ves_abort(); MINT_IN_BREAK;
3977 MINT_IN_CASE(MINT_INITOBJ)
3979 memset (sp->data.vt, 0, READ32(ip + 1));
3982 MINT_IN_CASE(MINT_CPBLK)
3984 if (!sp [0].data.p || !sp [1].data.p)
3985 THROW_EX (mono_get_exception_null_reference(), ip - 1);
3987 /* FIXME: value and size may be int64... */
3988 memcpy (sp [0].data.p, sp [1].data.p, sp [2].data.i);
3991 MINT_IN_CASE(MINT_CONSTRAINED_) {
3993 /* FIXME: implement */
3995 token = READ32 (ip);
4000 MINT_IN_CASE(MINT_INITBLK)
4003 THROW_EX (mono_get_exception_null_reference(), ip - 1);
4005 /* FIXME: value and size may be int64... */
4006 memset (sp [0].data.p, sp [1].data.i, sp [2].data.i);
4009 MINT_IN_CASE(MINT_NO_)
4010 /* FIXME: implement */
4014 MINT_IN_CASE(MINT_RETHROW)
4016 * need to clarify what this should actually do:
4017 * start the search from the last found handler in
4018 * this method or continue in the caller or what.
4019 * Also, do we need to run finally/fault handlers after a retrow?
4020 * Well, this implementation will follow the usual search
4021 * for an handler, considering the current ip as throw spot.
4022 * We need to NULL frame->ex_handler for the later code to
4023 * actually run the new found handler.
4025 frame->ex_handler = NULL;
4026 THROW_EX (frame->ex, ip - 1);
4029 g_print ("Unimplemented opcode: %04x %s at 0x%x\n", *ip, mono_interp_opname[*ip], ip-rtm->code);
4030 THROW_EX (mono_get_exception_execution_engine ("Unimplemented opcode"), ip);
4034 g_assert_not_reached ();
4036 * Exception handling code.
4037 * The exception object is stored in frame->ex.
4044 MonoInvocation *inv;
4045 MonoExceptionClause *clause;
4051 g_print ("* Handling exception '%s' at IL_%04x\n",
4052 frame->ex == NULL ? "** Unknown **" : mono_object_class (frame->ex)->name,
4053 rtm == NULL ? 0 : frame->ip - rtm->code);
4055 if (die_on_exception)
4058 for (inv = frame; inv; inv = inv->parent) {
4060 if (inv->runtime_method == NULL)
4062 method = inv->runtime_method->method;
4063 if (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL)
4065 if (method->iflags & (METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL | METHOD_IMPL_ATTRIBUTE_RUNTIME))
4067 if (inv->ip == NULL)
4069 ip_offset = inv->ip - inv->runtime_method->code;
4070 inv->ex_handler = NULL; /* clear this in case we are trhowing an exception while handling one - this one wins */
4071 for (i = 0; i < inv->runtime_method->num_clauses; ++i) {
4072 clause = &inv->runtime_method->clauses [i];
4073 if (clause->flags <= 1 && MONO_OFFSET_IN_CLAUSE (clause, ip_offset)) {
4074 if (!clause->flags) {
4075 MonoObject *isinst_obj = mono_object_isinst_checked ((MonoObject*)frame->ex, clause->data.catch_class, &error);
4076 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4079 * OK, we found an handler, now we need to execute the finally
4080 * and fault blocks before branching to the handler code.
4082 inv->ex_handler = clause;
4085 g_print ("* Found handler at '%s'\n", method->name);
4087 goto handle_finally;
4090 /* FIXME: handle filter clauses */
4097 * If we get here, no handler was found: print a stack trace.
4099 for (inv = frame; inv; inv = inv->parent) {
4100 if (inv->invoke_trap)
4101 goto handle_finally;
4104 ex_obj = (MonoObject*)frame->ex;
4105 mono_unhandled_exception (ex_obj);
4112 MonoExceptionClause *clause;
4113 GSList *old_list = finally_ips;
4114 MonoMethod *method = frame->runtime_method->method;
4115 MonoMethodHeader *header = mono_method_get_header_checked (method, &error);
4116 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4120 g_print ("* Handle finally IL_%04x\n", endfinally_ip == NULL ? 0 : endfinally_ip - rtm->code);
4122 if (rtm == NULL || (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL)
4123 || (method->iflags & (METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL | METHOD_IMPL_ATTRIBUTE_RUNTIME))) {
4126 ip_offset = frame->ip - rtm->code;
4128 if (endfinally_ip != NULL)
4129 finally_ips = g_slist_prepend(finally_ips, (void *)endfinally_ip);
4130 for (i = 0; i < header->num_clauses; ++i)
4131 if (frame->ex_handler == &rtm->clauses [i])
4135 clause = &rtm->clauses [i];
4136 if (MONO_OFFSET_IN_CLAUSE (clause, ip_offset) && (endfinally_ip == NULL || !(MONO_OFFSET_IN_CLAUSE (clause, endfinally_ip - rtm->code)))) {
4137 if (clause->flags == MONO_EXCEPTION_CLAUSE_FINALLY) {
4138 ip = rtm->code + clause->handler_offset;
4139 finally_ips = g_slist_prepend (finally_ips, (gpointer) ip);
4142 g_print ("* Found finally at IL_%04x with exception: %s\n", clause->handler_offset, frame->ex? "yes": "no");
4148 endfinally_ip = NULL;
4150 if (old_list != finally_ips && finally_ips) {
4151 ip = finally_ips->data;
4152 finally_ips = g_slist_remove (finally_ips, ip);
4153 sp = frame->stack; /* spec says stack should be empty at endfinally so it should be at the start too */
4158 * If an exception is set, we need to execute the fault handler, too,
4159 * otherwise, we continue normally.
4169 MonoExceptionClause *clause;
4170 MonoMethod *method = frame->runtime_method->method;
4171 MonoMethodHeader *header = mono_method_get_header_checked (method, &error);
4172 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4176 g_print ("* Handle fault\n");
4178 ip_offset = frame->ip - rtm->code;
4179 for (i = 0; i < header->num_clauses; ++i) {
4180 clause = &rtm->clauses [i];
4181 if (clause->flags == MONO_EXCEPTION_CLAUSE_FAULT && MONO_OFFSET_IN_CLAUSE (clause, ip_offset)) {
4182 ip = rtm->code + clause->handler_offset;
4185 g_print ("* Executing handler at IL_%04x\n", clause->handler_offset);
4191 * If the handler for the exception was found in this method, we jump
4192 * to it right away, otherwise we return and let the caller run
4193 * the finally, fault and catch blocks.
4194 * This same code should be present in the endfault opcode, but it
4195 * is corrently not assigned in the ECMA specs: LAMESPEC.
4197 if (frame->ex_handler) {
4200 g_print ("* Executing handler at IL_%04x\n", frame->ex_handler->handler_offset);
4202 ip = rtm->code + frame->ex_handler->handler_offset;
4204 vt_sp = (unsigned char *) sp + rtm->stack_size;
4205 sp->data.p = frame->ex;
4216 ves_exec_method (MonoInvocation *frame)
4218 ThreadContext *context = mono_native_tls_get_value (thread_context_id);
4219 ThreadContext context_struct;
4226 mono_unhandled_exception ((MonoObject*)frame->ex);
4229 if (context == NULL) {
4230 context = &context_struct;
4231 context_struct.domain = mono_domain_get ();
4232 context_struct.base_frame = frame;
4233 context_struct.current_frame = NULL;
4234 context_struct.env_frame = frame;
4235 context_struct.current_env = &env;
4236 context_struct.search_for_handler = 0;
4237 context_struct.managed_code = 0;
4238 mono_native_tls_set_value (thread_context_id, context);
4241 frame->parent = context->current_frame;
4242 frame->runtime_method = mono_interp_get_runtime_method (context->domain, frame->method, &error);
4243 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4244 context->managed_code = 1;
4245 ves_exec_method_with_context (frame, context);
4246 context->managed_code = 0;
4248 if (context != &context_struct && context->current_env) {
4249 context->env_frame->ex = frame->ex;
4250 longjmp (*context->current_env, 1);
4253 mono_unhandled_exception ((MonoObject*)frame->ex);
4255 if (context->base_frame == frame)
4256 mono_native_tls_set_value (thread_context_id, NULL);
4258 context->current_frame = frame->parent;
4262 ves_exec (MonoDomain *domain, MonoAssembly *assembly, int argc, char *argv[])
4264 MonoImage *image = mono_assembly_get_image (assembly);
4269 method = mono_get_method_checked (image, mono_image_get_entry_point (image), NULL, NULL, &error);
4270 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4273 g_error ("No entry point method found in %s", mono_image_get_filename (image));
4275 rval = mono_runtime_run_main_checked (method, argc, argv, &error);
4276 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4284 "mint %s, the Mono ECMA CLI interpreter, (C) 2001, 2002 Ximian, Inc.\n\n"
4285 "Usage is: mint [options] executable args...\n\n", VERSION);
4287 "Runtime Debugging:\n"
4292 " --noptr\t\t\tdon't print pointer addresses in trace output\n"
4295 " --traceclassinit\n"
4298 " --debug method_name\n"
4305 " --config filename load the specified config file instead of the default\n"
4306 " --workers n maximum number of worker threads\n"
4312 interp_ves_icall_get_frame_info (gint32 skip, MonoBoolean need_file_info,
4313 MonoReflectionMethod **method,
4314 gint32 *iloffset, gint32 *native_offset,
4315 MonoString **file, gint32 *line, gint32 *column)
4317 ThreadContext *context = mono_native_tls_get_value (thread_context_id);
4318 MonoInvocation *inv = context->current_frame;
4322 for (i = 0; inv && i < skip; inv = inv->parent)
4323 if (inv->runtime_method != NULL)
4334 *method = mono_method_get_object_checked (context->domain, inv->runtime_method->method, NULL, &error);
4335 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4340 if (need_file_info) {
4344 *file = mono_string_new (mono_domain_get (), "unknown");
4351 interp_ves_icall_get_trace (MonoException *exc, gint32 skip, MonoBoolean need_file_info)
4353 MonoDomain *domain = mono_domain_get ();
4355 MonoArray *ta = exc->trace_ips;
4360 /* Exception is not thrown yet */
4361 MonoArray *array = mono_array_new_checked (domain, mono_defaults.stack_frame_class, 0, &error);
4362 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4366 len = mono_array_length (ta);
4368 res = mono_array_new_checked (domain, mono_defaults.stack_frame_class, len > skip ? len - skip : 0, &error);
4369 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4371 for (i = skip; i < len / 2; i++) {
4372 MonoStackFrame *sf = (MonoStackFrame *)mono_object_new_checked (domain, mono_defaults.stack_frame_class, &error);
4373 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4374 gushort *ip = mono_array_get (ta, gpointer, 2 * i + 1);
4375 RuntimeMethod *rtm = mono_array_get (ta, gpointer, 2 * i);
4378 sf->method = mono_method_get_object_checked (domain, rtm->method, NULL, &error);
4379 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4380 sf->native_offset = ip - rtm->code;
4384 sf->il_offset = mono_debug_il_offset_from_address (ji->method, sf->native_offset, domain);
4386 if (need_file_info) {
4389 filename = mono_debug_source_location_from_address (ji->method, sf->native_offset, &sf->line, domain);
4391 sf->filename = filename? mono_string_new (domain, filename): NULL;
4398 mono_array_set (res, gpointer, i, sf);
4405 ves_icall_System_Delegate_CreateDelegate_internal (MonoReflectionType *type, MonoObject *target, MonoReflectionMethod *info)
4407 MonoClass *delegate_class = mono_class_from_mono_type (type->type);
4408 MonoObject *delegate;
4411 g_assert (delegate_class->parent == mono_defaults.multicastdelegate_class);
4413 delegate = mono_object_new_checked (mono_object_domain (type), delegate_class, &error);
4414 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4416 interp_delegate_ctor (mono_object_domain (type), delegate, target, mono_interp_get_runtime_method (mono_get_root_domain (), info->method, &error));
4417 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4425 mono_native_tls_alloc (&thread_context_id, NULL);
4426 mono_native_tls_set_value (thread_context_id, NULL);
4427 mono_os_mutex_init_recursive (&runtime_method_lookup_section);
4428 mono_os_mutex_init_recursive (&create_method_pointer_mutex);
4430 mono_interp_transform_init ();
4433 typedef int (*TestMethod) (void);
4436 interp_regression_step (MonoImage *image, int verbose, int *total_run, int *total, GTimer *timer, MonoDomain *domain)
4438 int result, expected, failed, cfailed, run;
4439 double elapsed, transform_time;
4441 MonoObject *result_obj;
4442 static gboolean filter_method_init = FALSE;
4443 static const char *filter_method = NULL;
4445 g_print ("Test run: image=%s\n", mono_image_get_filename (image));
4446 cfailed = failed = run = 0;
4447 transform_time = elapsed = 0.0;
4450 /* fixme: ugly hack - delete all previously compiled methods */
4451 if (domain_jit_info (domain)) {
4452 g_hash_table_destroy (domain_jit_info (domain)->jit_trampoline_hash);
4453 domain_jit_info (domain)->jit_trampoline_hash = g_hash_table_new (mono_aligned_addr_hash, NULL);
4454 mono_internal_hash_table_destroy (&(domain->jit_code_hash));
4455 mono_jit_code_hash_init (&(domain->jit_code_hash));
4459 g_timer_start (timer);
4460 for (i = 0; i < mono_image_get_table_rows (image, MONO_TABLE_METHOD); ++i) {
4462 MonoMethod *method = mono_get_method_checked (image, MONO_TOKEN_METHOD_DEF | (i + 1), NULL, NULL, &error);
4464 mono_error_cleanup (&error); /* FIXME don't swallow the error */
4468 if (!filter_method_init) {
4469 filter_method = g_getenv ("INTERP_FILTER_METHOD");
4470 filter_method_init = TRUE;
4472 gboolean filter = FALSE;
4473 if (filter_method) {
4474 const char *name = filter_method;
4476 if ((strchr (name, '.') > name) || strchr (name, ':')) {
4477 MonoMethodDesc *desc = mono_method_desc_new (name, TRUE);
4478 filter = mono_method_desc_full_match (desc, method);
4479 mono_method_desc_free (desc);
4481 filter = strcmp (method->name, name) == 0;
4483 } else { // no filter
4486 if (strncmp (method->name, "test_", 5) == 0 && filter) {
4487 MonoError interp_error;
4488 MonoObject *exc = NULL;
4490 result_obj = interp_mono_runtime_invoke (method, NULL, NULL, &exc, &interp_error);
4491 if (!mono_error_ok (&interp_error)) {
4493 g_print ("Test '%s' execution failed.\n", method->name);
4494 } else if (exc != NULL) {
4495 g_print ("Exception in Test '%s' occured:\n", method->name);
4496 mono_object_describe (exc);
4500 result = *(gint32 *) mono_object_unbox (result_obj);
4501 expected = atoi (method->name + 5); // FIXME: oh no.
4504 if (result != expected) {
4506 g_print ("Test '%s' failed result (got %d, expected %d).\n", method->name, result, expected);
4511 g_timer_stop (timer);
4512 elapsed = g_timer_elapsed (timer, NULL);
4513 if (failed > 0 || cfailed > 0){
4514 g_print ("Results: total tests: %d, failed: %d, cfailed: %d (pass: %.2f%%)\n",
4515 run, failed, cfailed, 100.0*(run-failed-cfailed)/run);
4517 g_print ("Results: total tests: %d, all pass \n", run);
4520 g_print ("Elapsed time: %f secs (%f, %f)\n\n", elapsed,
4521 elapsed - transform_time, transform_time);
4522 *total += failed + cfailed;
4526 interp_regression (MonoImage *image, int verbose, int *total_run)
4529 GTimer *timer = g_timer_new ();
4530 MonoDomain *domain = mono_domain_get ();
4534 /* load the metadata */
4535 for (i = 0; i < mono_image_get_table_rows (image, MONO_TABLE_METHOD); ++i) {
4537 method = mono_get_method_checked (image, MONO_TOKEN_METHOD_DEF | (i + 1), NULL, NULL, &error);
4539 mono_error_cleanup (&error);
4542 mono_class_init (method->klass);
4547 interp_regression_step (image, verbose, total_run, &total, timer, domain);
4549 g_timer_destroy (timer);
4554 interp_regression_list (int verbose, int count, char *images [])
4556 int i, total, total_run, run;
4558 total_run = total = 0;
4559 for (i = 0; i < count; ++i) {
4560 MonoAssembly *ass = mono_assembly_open (images [i], NULL);
4562 g_warning ("failed to load assembly: %s", images [i]);
4565 total += interp_regression (mono_assembly_get_image (ass), verbose, &run);
4569 g_print ("Overall results: tests: %d, failed: %d (pass: %.2f%%)\n", total_run, total, 100.0*(total_run-total)/total_run);
4571 g_print ("Overall results: tests: %d, 100%% pass\n", total_run);