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 vt_sp += (ret_size + 7) & ~7;
1679 #define LDC(n) do { sp->data.i = (n); ++ip; ++sp; } while (0)
1680 MINT_IN_CASE(MINT_LDC_I4_M1)
1683 MINT_IN_CASE(MINT_LDC_I4_0)
1686 MINT_IN_CASE(MINT_LDC_I4_1)
1689 MINT_IN_CASE(MINT_LDC_I4_2)
1692 MINT_IN_CASE(MINT_LDC_I4_3)
1695 MINT_IN_CASE(MINT_LDC_I4_4)
1698 MINT_IN_CASE(MINT_LDC_I4_5)
1701 MINT_IN_CASE(MINT_LDC_I4_6)
1704 MINT_IN_CASE(MINT_LDC_I4_7)
1707 MINT_IN_CASE(MINT_LDC_I4_8)
1710 MINT_IN_CASE(MINT_LDC_I4_S)
1711 sp->data.i = *(const short *)(ip + 1);
1715 MINT_IN_CASE(MINT_LDC_I4)
1717 sp->data.i = READ32 (ip);
1721 MINT_IN_CASE(MINT_LDC_I8)
1723 sp->data.l = READ64 (ip);
1727 MINT_IN_CASE(MINT_LDC_R4) {
1731 sp->data.f = * (float *)&val;
1736 MINT_IN_CASE(MINT_LDC_R8)
1737 sp->data.l = READ64 (ip + 1); /* note union usage */
1741 MINT_IN_CASE(MINT_DUP)
1746 MINT_IN_CASE(MINT_DUP_VT)
1747 i32 = READ32 (ip + 1);
1749 memcpy(sp->data.p, sp [-1].data.p, i32);
1750 vt_sp += (i32 + 7) & ~7;
1754 MINT_IN_CASE(MINT_POP)
1758 MINT_IN_CASE(MINT_JMP) {
1759 RuntimeMethod *new_method = rtm->data_items [* (guint16 *)(ip + 1)];
1760 if (!new_method->transformed) {
1762 frame->ex = mono_interp_transform_method (new_method, context);
1767 if (new_method->alloca_size > rtm->alloca_size)
1768 g_error ("MINT_JMP to method which needs more stack space (%d > %d)", new_method->alloca_size, rtm->alloca_size);
1769 rtm = frame->runtime_method = new_method;
1770 vt_sp = (unsigned char *) sp + rtm->stack_size;
1774 locals = vt_sp + rtm->vt_stack_size;
1775 ip = rtm->new_body_start; /* bypass storing input args from callers frame */
1778 MINT_IN_CASE(MINT_CALLI) {
1779 MonoMethodSignature *csignature;
1780 stackval *endsp = sp;
1784 csignature = rtm->data_items [* (guint16 *)(ip + 1)];
1788 child_frame.runtime_method = sp->data.p;
1791 child_frame.retval = sp;
1792 /* decrement by the actual number of args */
1793 sp -= csignature->param_count;
1794 child_frame.stack_args = sp;
1795 if (csignature->hasthis) {
1797 child_frame.obj = sp->data.p;
1799 child_frame.obj = NULL;
1801 if (csignature->hasthis && mono_object_is_transparent_proxy (child_frame.obj)) {
1802 child_frame.runtime_method = mono_interp_get_runtime_method (context->domain, mono_marshal_get_remoting_invoke (child_frame.runtime_method->method), &error);
1803 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
1804 } else if (child_frame.runtime_method->method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) {
1805 child_frame.runtime_method = mono_interp_get_runtime_method (context->domain, mono_marshal_get_native_wrapper (child_frame.runtime_method->method, FALSE, FALSE), &error);
1806 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
1809 ves_exec_method_with_context (&child_frame, context);
1811 context->current_frame = frame;
1813 if (child_frame.ex) {
1815 * An exception occurred, need to run finally, fault and catch handlers..
1817 frame->ex = child_frame.ex;
1818 goto handle_finally;
1821 /* need to handle typedbyref ... */
1822 if (csignature->ret->type != MONO_TYPE_VOID) {
1828 MINT_IN_CASE(MINT_CALLI_NAT) {
1829 MonoMethodSignature *csignature;
1830 stackval *endsp = sp;
1831 unsigned char *code = NULL;
1835 csignature = rtm->data_items [* (guint16 *)(ip + 1)];
1840 child_frame.runtime_method = NULL;
1843 child_frame.retval = sp;
1844 /* decrement by the actual number of args */
1845 sp -= csignature->param_count;
1846 child_frame.stack_args = sp;
1847 if (csignature->hasthis) {
1849 child_frame.obj = sp->data.p;
1851 child_frame.obj = NULL;
1853 ves_pinvoke_method (&child_frame, csignature, (MonoFuncV) code, FALSE, context);
1855 context->current_frame = frame;
1857 if (child_frame.ex) {
1859 * An exception occurred, need to run finally, fault and catch handlers..
1861 frame->ex = child_frame.ex;
1862 if (context->search_for_handler) {
1863 context->search_for_handler = 0;
1864 goto handle_exception;
1866 goto handle_finally;
1869 /* need to handle typedbyref ... */
1870 if (csignature->ret->type != MONO_TYPE_VOID) {
1876 MINT_IN_CASE(MINT_CALL) {
1877 stackval *endsp = sp;
1881 child_frame.runtime_method = rtm->data_items [* (guint16 *)(ip + 1)];
1884 child_frame.retval = sp;
1885 /* decrement by the actual number of args */
1886 sp -= child_frame.runtime_method->param_count;
1887 child_frame.stack_args = sp;
1888 if (child_frame.runtime_method->hasthis) {
1890 child_frame.obj = sp->data.p;
1892 child_frame.obj = NULL;
1894 if (child_frame.runtime_method->hasthis && !child_frame.runtime_method->valuetype && mono_object_is_transparent_proxy (child_frame.obj)) {
1895 child_frame.runtime_method = mono_interp_get_runtime_method (context->domain, mono_marshal_get_remoting_invoke (child_frame.runtime_method->method), &error);
1896 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
1898 ves_exec_method_with_context (&child_frame, context);
1900 context->current_frame = frame;
1902 if (child_frame.ex) {
1904 * An exception occurred, need to run finally, fault and catch handlers..
1906 frame->ex = child_frame.ex;
1907 goto handle_finally;
1910 /* need to handle typedbyref ... */
1915 MINT_IN_CASE(MINT_VCALL) {
1918 child_frame.runtime_method = rtm->data_items [* (guint16 *)(ip + 1)];
1922 child_frame.retval = sp;
1923 /* decrement by the actual number of args */
1924 sp -= child_frame.runtime_method->param_count;
1925 child_frame.stack_args = sp;
1926 if (child_frame.runtime_method->hasthis) {
1928 child_frame.obj = sp->data.p;
1930 child_frame.obj = NULL;
1933 if (child_frame.runtime_method->hasthis && !child_frame.runtime_method->valuetype && mono_object_is_transparent_proxy (child_frame.obj)) {
1934 child_frame.runtime_method = mono_interp_get_runtime_method (context->domain, mono_marshal_get_remoting_invoke (child_frame.runtime_method->method), &error);
1935 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
1938 ves_exec_method_with_context (&child_frame, context);
1940 context->current_frame = frame;
1942 if (child_frame.ex) {
1944 * An exception occurred, need to run finally, fault and catch handlers..
1946 frame->ex = child_frame.ex;
1947 goto handle_finally;
1951 MINT_IN_CASE(MINT_CALLVIRT) {
1952 stackval *endsp = sp;
1953 MonoObject *this_arg;
1958 token = * (unsigned short *)(ip + 1);
1960 child_frame.runtime_method = rtm->data_items [token];
1962 child_frame.retval = sp;
1964 /* decrement by the actual number of args */
1965 sp -= child_frame.runtime_method->param_count;
1966 child_frame.stack_args = sp;
1968 child_frame.obj = this_arg = sp->data.p;
1970 THROW_EX (mono_get_exception_null_reference(), ip - 2);
1971 child_frame.runtime_method = get_virtual_method (context->domain, child_frame.runtime_method, this_arg);
1973 if (this_arg->vtable->klass->valuetype && child_frame.runtime_method->valuetype) {
1974 child_frame.obj = (char *)this_arg + sizeof(MonoObject);
1977 ves_exec_method_with_context (&child_frame, context);
1979 context->current_frame = frame;
1981 if (child_frame.ex) {
1983 * An exception occurred, need to run finally, fault and catch handlers..
1985 frame->ex = child_frame.ex;
1986 if (context->search_for_handler) {
1987 context->search_for_handler = 0;
1988 goto handle_exception;
1990 goto handle_finally;
1993 /* need to handle typedbyref ... */
1998 MINT_IN_CASE(MINT_VCALLVIRT) {
1999 MonoObject *this_arg;
2004 token = * (unsigned short *)(ip + 1);
2006 child_frame.runtime_method = rtm->data_items [token];
2008 child_frame.retval = sp;
2010 /* decrement by the actual number of args */
2011 sp -= child_frame.runtime_method->param_count;
2012 child_frame.stack_args = sp;
2014 child_frame.obj = this_arg = sp->data.p;
2016 THROW_EX (mono_get_exception_null_reference(), ip - 2);
2017 child_frame.runtime_method = get_virtual_method (context->domain, child_frame.runtime_method, this_arg);
2019 if (this_arg->vtable->klass->valuetype && child_frame.runtime_method->valuetype) {
2020 child_frame.obj = (char *)this_arg + sizeof(MonoObject);
2023 ves_exec_method_with_context (&child_frame, context);
2025 context->current_frame = frame;
2027 if (child_frame.ex) {
2029 * An exception occurred, need to run finally, fault and catch handlers..
2031 frame->ex = child_frame.ex;
2032 if (context->search_for_handler) {
2033 context->search_for_handler = 0;
2034 goto handle_exception;
2036 goto handle_finally;
2040 MINT_IN_CASE(MINT_CALLRUN)
2041 ves_runtime_method (frame, context);
2044 goto handle_exception;
2047 MINT_IN_CASE(MINT_RET)
2049 *frame->retval = *sp;
2050 if (sp > frame->stack)
2051 g_warning ("ret: more values on stack: %d", sp-frame->stack);
2053 MINT_IN_CASE(MINT_RET_VOID)
2054 if (sp > frame->stack)
2055 g_warning ("ret.void: more values on stack: %d", sp-frame->stack);
2057 MINT_IN_CASE(MINT_RET_VT)
2058 i32 = READ32(ip + 1);
2060 memcpy(frame->retval->data.p, sp->data.p, i32);
2061 if (sp > frame->stack)
2062 g_warning ("ret.vt: more values on stack: %d", sp-frame->stack);
2064 MINT_IN_CASE(MINT_BR_S)
2065 ip += (short) *(ip + 1);
2067 MINT_IN_CASE(MINT_BR)
2068 ip += (gint32) READ32(ip + 1);
2070 #define ZEROP_S(datamem, op) \
2072 if (sp->data.datamem op 0) \
2073 ip += * (gint16 *)(ip + 1); \
2077 #define ZEROP(datamem, op) \
2079 if (sp->data.datamem op 0) \
2080 ip += READ32(ip + 1); \
2084 MINT_IN_CASE(MINT_BRFALSE_I4_S)
2087 MINT_IN_CASE(MINT_BRFALSE_I8_S)
2090 MINT_IN_CASE(MINT_BRFALSE_R8_S)
2093 MINT_IN_CASE(MINT_BRFALSE_I4)
2096 MINT_IN_CASE(MINT_BRFALSE_I8)
2099 MINT_IN_CASE(MINT_BRFALSE_R8)
2102 MINT_IN_CASE(MINT_BRTRUE_I4_S)
2105 MINT_IN_CASE(MINT_BRTRUE_I8_S)
2108 MINT_IN_CASE(MINT_BRTRUE_R8_S)
2111 MINT_IN_CASE(MINT_BRTRUE_I4)
2114 MINT_IN_CASE(MINT_BRTRUE_I8)
2117 MINT_IN_CASE(MINT_BRTRUE_R8)
2120 #define CONDBR_S(cond) \
2123 ip += * (gint16 *)(ip + 1); \
2126 #define BRELOP_S(datamem, op) \
2127 CONDBR_S(sp[0].data.datamem op sp[1].data.datamem)
2129 #define CONDBR(cond) \
2132 ip += READ32(ip + 1); \
2136 #define BRELOP(datamem, op) \
2137 CONDBR(sp[0].data.datamem op sp[1].data.datamem)
2139 MINT_IN_CASE(MINT_BEQ_I4_S)
2142 MINT_IN_CASE(MINT_BEQ_I8_S)
2145 MINT_IN_CASE(MINT_BEQ_R8_S)
2146 CONDBR_S(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f == sp[1].data.f)
2148 MINT_IN_CASE(MINT_BEQ_I4)
2151 MINT_IN_CASE(MINT_BEQ_I8)
2154 MINT_IN_CASE(MINT_BEQ_R8)
2155 CONDBR(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f == sp[1].data.f)
2157 MINT_IN_CASE(MINT_BGE_I4_S)
2160 MINT_IN_CASE(MINT_BGE_I8_S)
2163 MINT_IN_CASE(MINT_BGE_R8_S)
2164 CONDBR_S(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f >= sp[1].data.f)
2166 MINT_IN_CASE(MINT_BGE_I4)
2169 MINT_IN_CASE(MINT_BGE_I8)
2172 MINT_IN_CASE(MINT_BGE_R8)
2173 CONDBR(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f >= sp[1].data.f)
2175 MINT_IN_CASE(MINT_BGT_I4_S)
2178 MINT_IN_CASE(MINT_BGT_I8_S)
2181 MINT_IN_CASE(MINT_BGT_R8_S)
2182 CONDBR_S(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f > sp[1].data.f)
2184 MINT_IN_CASE(MINT_BGT_I4)
2187 MINT_IN_CASE(MINT_BGT_I8)
2190 MINT_IN_CASE(MINT_BGT_R8)
2191 CONDBR(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f > sp[1].data.f)
2193 MINT_IN_CASE(MINT_BLT_I4_S)
2196 MINT_IN_CASE(MINT_BLT_I8_S)
2199 MINT_IN_CASE(MINT_BLT_R8_S)
2200 CONDBR_S(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f < sp[1].data.f)
2202 MINT_IN_CASE(MINT_BLT_I4)
2205 MINT_IN_CASE(MINT_BLT_I8)
2208 MINT_IN_CASE(MINT_BLT_R8)
2209 CONDBR(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f < sp[1].data.f)
2211 MINT_IN_CASE(MINT_BLE_I4_S)
2214 MINT_IN_CASE(MINT_BLE_I8_S)
2217 MINT_IN_CASE(MINT_BLE_R8_S)
2218 CONDBR_S(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f <= sp[1].data.f)
2220 MINT_IN_CASE(MINT_BLE_I4)
2223 MINT_IN_CASE(MINT_BLE_I8)
2226 MINT_IN_CASE(MINT_BLE_R8)
2227 CONDBR(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f <= sp[1].data.f)
2229 MINT_IN_CASE(MINT_BNE_UN_I4_S)
2232 MINT_IN_CASE(MINT_BNE_UN_I8_S)
2235 MINT_IN_CASE(MINT_BNE_UN_R8_S)
2236 CONDBR_S(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f != sp[1].data.f)
2238 MINT_IN_CASE(MINT_BNE_UN_I4)
2241 MINT_IN_CASE(MINT_BNE_UN_I8)
2244 MINT_IN_CASE(MINT_BNE_UN_R8)
2245 CONDBR(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f != sp[1].data.f)
2248 #define BRELOP_S_CAST(datamem, op, type) \
2250 if ((type) sp[0].data.datamem op (type) sp[1].data.datamem) \
2251 ip += * (gint16 *)(ip + 1); \
2255 #define BRELOP_CAST(datamem, op, type) \
2257 if ((type) sp[0].data.datamem op (type) sp[1].data.datamem) \
2258 ip += READ32(ip + 1); \
2262 MINT_IN_CASE(MINT_BGE_UN_I4_S)
2263 BRELOP_S_CAST(i, >=, guint32);
2265 MINT_IN_CASE(MINT_BGE_UN_I8_S)
2266 BRELOP_S_CAST(l, >=, guint64);
2268 MINT_IN_CASE(MINT_BGE_UN_R8_S)
2269 CONDBR_S(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f >= sp[1].data.f)
2271 MINT_IN_CASE(MINT_BGE_UN_I4)
2272 BRELOP_CAST(i, >=, guint32);
2274 MINT_IN_CASE(MINT_BGE_UN_I8)
2275 BRELOP_CAST(l, >=, guint64);
2277 MINT_IN_CASE(MINT_BGE_UN_R8)
2278 CONDBR(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f >= sp[1].data.f)
2280 MINT_IN_CASE(MINT_BGT_UN_I4_S)
2281 BRELOP_S_CAST(i, >, guint32);
2283 MINT_IN_CASE(MINT_BGT_UN_I8_S)
2284 BRELOP_S_CAST(l, >, guint64);
2286 MINT_IN_CASE(MINT_BGT_UN_R8_S)
2287 CONDBR_S(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f > sp[1].data.f)
2289 MINT_IN_CASE(MINT_BGT_UN_I4)
2290 BRELOP_CAST(i, >, guint32);
2292 MINT_IN_CASE(MINT_BGT_UN_I8)
2293 BRELOP_CAST(l, >, guint64);
2295 MINT_IN_CASE(MINT_BGT_UN_R8)
2296 CONDBR(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f > sp[1].data.f)
2298 MINT_IN_CASE(MINT_BLE_UN_I4_S)
2299 BRELOP_S_CAST(i, <=, guint32);
2301 MINT_IN_CASE(MINT_BLE_UN_I8_S)
2302 BRELOP_S_CAST(l, <=, guint64);
2304 MINT_IN_CASE(MINT_BLE_UN_R8_S)
2305 CONDBR_S(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f <= sp[1].data.f)
2307 MINT_IN_CASE(MINT_BLE_UN_I4)
2308 BRELOP_CAST(i, <=, guint32);
2310 MINT_IN_CASE(MINT_BLE_UN_I8)
2311 BRELOP_CAST(l, <=, guint64);
2313 MINT_IN_CASE(MINT_BLE_UN_R8)
2314 CONDBR(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f <= sp[1].data.f)
2316 MINT_IN_CASE(MINT_BLT_UN_I4_S)
2317 BRELOP_S_CAST(i, <, guint32);
2319 MINT_IN_CASE(MINT_BLT_UN_I8_S)
2320 BRELOP_S_CAST(l, <, guint64);
2322 MINT_IN_CASE(MINT_BLT_UN_R8_S)
2323 CONDBR_S(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f < sp[1].data.f)
2325 MINT_IN_CASE(MINT_BLT_UN_I4)
2326 BRELOP_CAST(i, <, guint32);
2328 MINT_IN_CASE(MINT_BLT_UN_I8)
2329 BRELOP_CAST(l, <, guint64);
2331 MINT_IN_CASE(MINT_BLT_UN_R8)
2332 CONDBR(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f < sp[1].data.f)
2334 MINT_IN_CASE(MINT_SWITCH) {
2336 const unsigned short *st;
2342 if ((guint32)sp->data.i < n) {
2344 ip += 2 * (guint32)sp->data.i;
2345 offset = READ32 (ip);
2352 MINT_IN_CASE(MINT_LDIND_I1)
2354 sp[-1].data.i = *(gint8*)sp[-1].data.p;
2356 MINT_IN_CASE(MINT_LDIND_U1)
2358 sp[-1].data.i = *(guint8*)sp[-1].data.p;
2360 MINT_IN_CASE(MINT_LDIND_I2)
2362 sp[-1].data.i = *(gint16*)sp[-1].data.p;
2364 MINT_IN_CASE(MINT_LDIND_U2)
2366 sp[-1].data.i = *(guint16*)sp[-1].data.p;
2368 MINT_IN_CASE(MINT_LDIND_I4) /* Fall through */
2369 MINT_IN_CASE(MINT_LDIND_U4)
2371 sp[-1].data.i = *(gint32*)sp[-1].data.p;
2373 MINT_IN_CASE(MINT_LDIND_I8)
2375 sp[-1].data.l = *(gint64*)sp[-1].data.p;
2377 MINT_IN_CASE(MINT_LDIND_I)
2379 sp[-1].data.p = *(gpointer*)sp[-1].data.p;
2381 MINT_IN_CASE(MINT_LDIND_R4)
2383 sp[-1].data.f = *(gfloat*)sp[-1].data.p;
2385 MINT_IN_CASE(MINT_LDIND_R8)
2387 sp[-1].data.f = *(gdouble*)sp[-1].data.p;
2389 MINT_IN_CASE(MINT_LDIND_REF)
2391 sp[-1].data.p = *(gpointer*)sp[-1].data.p;
2393 MINT_IN_CASE(MINT_STIND_REF)
2396 * (gpointer *) sp->data.p = sp[1].data.p;
2398 MINT_IN_CASE(MINT_STIND_I1)
2401 * (gint8 *) sp->data.p = (gint8)sp[1].data.i;
2403 MINT_IN_CASE(MINT_STIND_I2)
2406 * (gint16 *) sp->data.p = (gint16)sp[1].data.i;
2408 MINT_IN_CASE(MINT_STIND_I4)
2411 * (gint32 *) sp->data.p = sp[1].data.i;
2413 MINT_IN_CASE(MINT_STIND_I)
2416 * (mono_i *) sp->data.p = (mono_i)sp[1].data.p;
2418 MINT_IN_CASE(MINT_STIND_I8)
2421 * (gint64 *) sp->data.p = sp[1].data.l;
2423 MINT_IN_CASE(MINT_STIND_R4)
2426 * (float *) sp->data.p = (gfloat)sp[1].data.f;
2428 MINT_IN_CASE(MINT_STIND_R8)
2431 * (double *) sp->data.p = sp[1].data.f;
2433 #define BINOP(datamem, op) \
2435 sp [-1].data.datamem = sp [-1].data.datamem op sp [0].data.datamem; \
2437 MINT_IN_CASE(MINT_ADD_I4)
2440 MINT_IN_CASE(MINT_ADD_I8)
2443 MINT_IN_CASE(MINT_ADD_R8)
2446 MINT_IN_CASE(MINT_ADD1_I4)
2450 MINT_IN_CASE(MINT_SUB_I4)
2453 MINT_IN_CASE(MINT_SUB_I8)
2456 MINT_IN_CASE(MINT_SUB_R8)
2459 MINT_IN_CASE(MINT_SUB1_I4)
2463 MINT_IN_CASE(MINT_MUL_I4)
2466 MINT_IN_CASE(MINT_MUL_I8)
2469 MINT_IN_CASE(MINT_MUL_R8)
2472 MINT_IN_CASE(MINT_DIV_I4)
2473 if (sp [-1].data.i == 0)
2474 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2475 if (sp [-1].data.i == (-1))
2476 THROW_EX (mono_get_exception_overflow (), ip);
2479 MINT_IN_CASE(MINT_DIV_I8)
2480 if (sp [-1].data.l == 0)
2481 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2482 if (sp [-1].data.l == (-1))
2483 THROW_EX (mono_get_exception_overflow (), ip);
2486 MINT_IN_CASE(MINT_DIV_R8)
2490 #define BINOP_CAST(datamem, op, type) \
2492 sp [-1].data.datamem = (type)sp [-1].data.datamem op (type)sp [0].data.datamem; \
2494 MINT_IN_CASE(MINT_DIV_UN_I4)
2495 if (sp [-1].data.i == 0)
2496 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2497 BINOP_CAST(i, /, guint32);
2499 MINT_IN_CASE(MINT_DIV_UN_I8)
2500 if (sp [-1].data.l == 0)
2501 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2502 BINOP_CAST(l, /, guint64);
2504 MINT_IN_CASE(MINT_REM_I4)
2505 if (sp [-1].data.i == 0)
2506 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2509 MINT_IN_CASE(MINT_REM_I8)
2510 if (sp [-1].data.l == 0)
2511 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2514 MINT_IN_CASE(MINT_REM_R8)
2515 /* FIXME: what do we actually do here? */
2517 sp [-1].data.f = fmod (sp [-1].data.f, sp [0].data.f);
2520 MINT_IN_CASE(MINT_REM_UN_I4)
2521 if (sp [-1].data.i == 0)
2522 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2523 BINOP_CAST(i, %, guint32);
2525 MINT_IN_CASE(MINT_REM_UN_I8)
2526 if (sp [-1].data.l == 0)
2527 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2528 BINOP_CAST(l, %, guint64);
2530 MINT_IN_CASE(MINT_AND_I4)
2533 MINT_IN_CASE(MINT_AND_I8)
2536 MINT_IN_CASE(MINT_OR_I4)
2539 MINT_IN_CASE(MINT_OR_I8)
2542 MINT_IN_CASE(MINT_XOR_I4)
2545 MINT_IN_CASE(MINT_XOR_I8)
2549 #define SHIFTOP(datamem, op) \
2551 sp [-1].data.datamem = sp [-1].data.datamem op sp [0].data.i; \
2554 MINT_IN_CASE(MINT_SHL_I4)
2557 MINT_IN_CASE(MINT_SHL_I8)
2560 MINT_IN_CASE(MINT_SHR_I4)
2563 MINT_IN_CASE(MINT_SHR_I8)
2566 MINT_IN_CASE(MINT_SHR_UN_I4)
2568 sp [-1].data.i = (guint32)sp [-1].data.i >> sp [0].data.i;
2571 MINT_IN_CASE(MINT_SHR_UN_I8)
2573 sp [-1].data.l = (guint64)sp [-1].data.l >> sp [0].data.i;
2576 MINT_IN_CASE(MINT_NEG_I4)
2577 sp [-1].data.i = - sp [-1].data.i;
2580 MINT_IN_CASE(MINT_NEG_I8)
2581 sp [-1].data.l = - sp [-1].data.l;
2584 MINT_IN_CASE(MINT_NEG_R8)
2585 sp [-1].data.f = - sp [-1].data.f;
2588 MINT_IN_CASE(MINT_NOT_I4)
2589 sp [-1].data.i = ~ sp [-1].data.i;
2592 MINT_IN_CASE(MINT_NOT_I8)
2593 sp [-1].data.l = ~ sp [-1].data.l;
2596 MINT_IN_CASE(MINT_CONV_I1_I4)
2597 sp [-1].data.i = (gint8)sp [-1].data.i;
2600 MINT_IN_CASE(MINT_CONV_I1_I8)
2601 sp [-1].data.i = (gint8)sp [-1].data.l;
2604 MINT_IN_CASE(MINT_CONV_I1_R8)
2605 sp [-1].data.i = (gint8)sp [-1].data.f;
2608 MINT_IN_CASE(MINT_CONV_U1_I4)
2609 sp [-1].data.i = (guint8)sp [-1].data.i;
2612 MINT_IN_CASE(MINT_CONV_U1_I8)
2613 sp [-1].data.i = (guint8)sp [-1].data.l;
2616 MINT_IN_CASE(MINT_CONV_U1_R8)
2617 sp [-1].data.i = (guint8)sp [-1].data.f;
2620 MINT_IN_CASE(MINT_CONV_I2_I4)
2621 sp [-1].data.i = (gint16)sp [-1].data.i;
2624 MINT_IN_CASE(MINT_CONV_I2_I8)
2625 sp [-1].data.i = (gint16)sp [-1].data.l;
2628 MINT_IN_CASE(MINT_CONV_I2_R8)
2629 sp [-1].data.i = (gint16)sp [-1].data.f;
2632 MINT_IN_CASE(MINT_CONV_U2_I4)
2633 sp [-1].data.i = (guint16)sp [-1].data.i;
2636 MINT_IN_CASE(MINT_CONV_U2_I8)
2637 sp [-1].data.i = (guint16)sp [-1].data.l;
2640 MINT_IN_CASE(MINT_CONV_U2_R8)
2641 sp [-1].data.i = (guint16)sp [-1].data.f;
2644 MINT_IN_CASE(MINT_CONV_I4_R8)
2645 sp [-1].data.i = (gint32)sp [-1].data.f;
2648 MINT_IN_CASE(MINT_CONV_U4_I8)
2649 MINT_IN_CASE(MINT_CONV_I4_I8)
2650 sp [-1].data.i = (gint32)sp [-1].data.l;
2653 MINT_IN_CASE(MINT_CONV_I4_I8_SP)
2654 sp [-2].data.i = (gint32)sp [-2].data.l;
2657 MINT_IN_CASE(MINT_CONV_U4_R8)
2658 sp [-1].data.i = (guint32)sp [-1].data.f;
2661 MINT_IN_CASE(MINT_CONV_I8_I4)
2662 sp [-1].data.l = sp [-1].data.i;
2665 MINT_IN_CASE(MINT_CONV_I8_I4_SP)
2666 sp [-2].data.l = sp [-2].data.i;
2669 MINT_IN_CASE(MINT_CONV_I8_U4)
2670 sp [-1].data.l = (guint32)sp [-1].data.i;
2673 MINT_IN_CASE(MINT_CONV_I8_R8)
2674 sp [-1].data.l = (gint64)sp [-1].data.f;
2677 MINT_IN_CASE(MINT_CONV_R4_I4)
2678 sp [-1].data.f = (float)sp [-1].data.i;
2681 MINT_IN_CASE(MINT_CONV_R4_I8)
2682 sp [-1].data.f = (float)sp [-1].data.l;
2685 MINT_IN_CASE(MINT_CONV_R4_R8)
2686 sp [-1].data.f = (float)sp [-1].data.f;
2689 MINT_IN_CASE(MINT_CONV_R8_I4)
2690 sp [-1].data.f = (double)sp [-1].data.i;
2693 MINT_IN_CASE(MINT_CONV_R8_I8)
2694 sp [-1].data.f = (double)sp [-1].data.l;
2697 MINT_IN_CASE(MINT_CONV_U8_I4)
2698 sp [-1].data.l = sp [-1].data.i & 0xffffffff;
2701 MINT_IN_CASE(MINT_CONV_U8_R8)
2702 sp [-1].data.l = (guint64)sp [-1].data.f;
2706 MINT_IN_CASE(MINT_CPOBJ) {
2709 vtklass = rtm->data_items[READ32 (ip)];
2712 memcpy (sp [0].data.p, sp [1].data.p, mono_class_value_size (vtklass, NULL));
2716 MINT_IN_CASE(MINT_LDOBJ) {
2719 c = rtm->data_items[* (guint16 *)(ip + 1)];
2721 if (c->byval_arg.type != MONO_TYPE_VALUETYPE || c->byval_arg.data.klass->enumtype) {
2723 stackval_from_data (&c->byval_arg, &sp [-1], p, FALSE);
2725 size = mono_class_value_size (c, NULL);
2727 sp [-1].data.p = vt_sp;
2728 memcpy(vt_sp, p, size);
2729 vt_sp += (size + 7) & ~7;
2733 MINT_IN_CASE(MINT_LDSTR)
2734 sp->data.p = rtm->data_items [* (guint16 *)(ip + 1)];
2738 MINT_IN_CASE(MINT_NEWOBJ) {
2739 MonoClass *newobj_class;
2740 MonoMethodSignature *csig;
2741 stackval valuetype_this;
2747 token = * (guint16 *)(ip + 1);
2750 child_frame.runtime_method = rtm->data_items [token];
2751 csig = mono_method_signature (child_frame.runtime_method->method);
2752 newobj_class = child_frame.runtime_method->method->klass;
2753 /*if (profiling_classes) {
2754 guint count = GPOINTER_TO_UINT (g_hash_table_lookup (profiling_classes, newobj_class));
2756 g_hash_table_insert (profiling_classes, newobj_class, GUINT_TO_POINTER (count));
2760 if (newobj_class->parent == mono_defaults.array_class) {
2761 sp -= csig->param_count;
2762 o = ves_array_create (context->domain, newobj_class, csig, sp);
2763 goto array_constructed;
2767 * First arg is the object.
2769 if (newobj_class->valuetype) {
2770 MonoType *t = &newobj_class->byval_arg;
2771 if (!newobj_class->enumtype && (t->type == MONO_TYPE_VALUETYPE || (t->type == MONO_TYPE_GENERICINST && mono_type_generic_inst_is_valuetype (t)))) {
2772 child_frame.obj = vt_sp;
2773 valuetype_this.data.p = vt_sp;
2775 memset (&valuetype_this, 0, sizeof (stackval));
2776 child_frame.obj = &valuetype_this;
2779 if (newobj_class != mono_defaults.string_class) {
2780 context->managed_code = 0;
2781 o = mono_object_new_checked (context->domain, newobj_class, &error);
2782 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2783 context->managed_code = 1;
2784 if (*mono_thread_interruption_request_flag ())
2785 mono_thread_interruption_checkpoint ();
2786 child_frame.obj = o;
2788 child_frame.retval = &retval;
2792 if (csig->param_count) {
2793 sp -= csig->param_count;
2794 child_frame.stack_args = sp;
2796 child_frame.stack_args = NULL;
2799 g_assert (csig->call_convention == MONO_CALL_DEFAULT);
2801 child_frame.ip = NULL;
2802 child_frame.ex = NULL;
2804 ves_exec_method_with_context (&child_frame, context);
2806 context->current_frame = frame;
2808 if (child_frame.ex) {
2810 * An exception occurred, need to run finally, fault and catch handlers..
2812 frame->ex = child_frame.ex;
2813 goto handle_finally;
2816 * a constructor returns void, but we need to return the object we created
2819 if (newobj_class->valuetype && !newobj_class->enumtype) {
2820 *sp = valuetype_this;
2821 } else if (newobj_class == mono_defaults.string_class) {
2829 MINT_IN_CASE(MINT_CASTCLASS)
2830 c = rtm->data_items [*(guint16 *)(ip + 1)];
2831 if ((o = sp [-1].data.p)) {
2832 MonoObject *isinst_obj = mono_object_isinst_checked (o, c, &error);
2833 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2835 THROW_EX (mono_get_exception_invalid_cast (), ip);
2839 MINT_IN_CASE(MINT_ISINST)
2840 c = rtm->data_items [*(guint16 *)(ip + 1)];
2841 if ((o = sp [-1].data.p)) {
2842 MonoObject *isinst_obj = mono_object_isinst_checked (o, c, &error);
2843 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2845 sp [-1].data.p = NULL;
2849 MINT_IN_CASE(MINT_CONV_R_UN_I4)
2850 sp [-1].data.f = (double)(guint32)sp [-1].data.i;
2853 MINT_IN_CASE(MINT_CONV_R_UN_I8)
2854 sp [-1].data.f = (double)(guint64)sp [-1].data.l;
2857 MINT_IN_CASE(MINT_UNBOX)
2858 c = rtm->data_items[*(guint16 *)(ip + 1)];
2862 THROW_EX (mono_get_exception_null_reference (), ip);
2864 MonoObject *isinst_obj = mono_object_isinst_checked (o, c, &error);
2865 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2866 if (!(isinst_obj || ((o->vtable->klass->rank == 0) && (o->vtable->klass->element_class == c->element_class))))
2867 THROW_EX (mono_get_exception_invalid_cast (), ip);
2869 if (c->byval_arg.type == MONO_TYPE_VALUETYPE && !c->enumtype) {
2870 g_error ("unbox: implement vt");
2872 stackval_from_data (&c->byval_arg, &sp [-1], mono_object_unbox (o), FALSE);
2876 MINT_IN_CASE(MINT_THROW)
2878 frame->ex_handler = NULL;
2880 sp->data.p = mono_get_exception_null_reference ();
2881 THROW_EX ((MonoException *)sp->data.p, ip);
2883 MINT_IN_CASE(MINT_LDFLDA)
2886 THROW_EX (mono_get_exception_null_reference (), ip);
2887 sp[-1].data.p = (char *)o + * (guint16 *)(ip + 1);
2890 MINT_IN_CASE(MINT_CKNULL)
2893 THROW_EX (mono_get_exception_null_reference (), ip);
2897 #define LDFLD(datamem, fieldtype) \
2898 o = sp [-1].data.p; \
2900 THROW_EX (mono_get_exception_null_reference (), ip); \
2901 sp[-1].data.datamem = * (fieldtype *)((char *)o + * (guint16 *)(ip + 1)) ; \
2904 MINT_IN_CASE(MINT_LDFLD_I1) LDFLD(i, gint8); MINT_IN_BREAK;
2905 MINT_IN_CASE(MINT_LDFLD_U1) LDFLD(i, guint8); MINT_IN_BREAK;
2906 MINT_IN_CASE(MINT_LDFLD_I2) LDFLD(i, gint16); MINT_IN_BREAK;
2907 MINT_IN_CASE(MINT_LDFLD_U2) LDFLD(i, guint16); MINT_IN_BREAK;
2908 MINT_IN_CASE(MINT_LDFLD_I4) LDFLD(i, gint32); MINT_IN_BREAK;
2909 MINT_IN_CASE(MINT_LDFLD_I8) LDFLD(l, gint64); MINT_IN_BREAK;
2910 MINT_IN_CASE(MINT_LDFLD_R4) LDFLD(f, float); MINT_IN_BREAK;
2911 MINT_IN_CASE(MINT_LDFLD_R8) LDFLD(f, double); MINT_IN_BREAK;
2912 MINT_IN_CASE(MINT_LDFLD_O) LDFLD(p, gpointer); MINT_IN_BREAK;
2913 MINT_IN_CASE(MINT_LDFLD_P) LDFLD(p, gpointer); MINT_IN_BREAK;
2915 MINT_IN_CASE(MINT_LDFLD_VT)
2918 THROW_EX (mono_get_exception_null_reference (), ip);
2919 i32 = READ32(ip + 2);
2920 sp [-1].data.p = vt_sp;
2921 memcpy(sp [-1].data.p, (char *)o + * (guint16 *)(ip + 1), i32);
2922 vt_sp += (i32 + 7) & ~7;
2926 MINT_IN_CASE(MINT_LDRMFLD) {
2928 MonoClassField *field;
2933 THROW_EX (mono_get_exception_null_reference (), ip);
2934 field = rtm->data_items[* (guint16 *)(ip + 1)];
2936 if (mono_object_is_transparent_proxy (o)) {
2937 MonoClass *klass = ((MonoTransparentProxy*)o)->remote_class->proxy_class;
2939 addr = mono_load_remote_field_checked (o, klass, field, &tmp, &error);
2940 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2942 addr = (char*)o + field->offset;
2945 stackval_from_data (field->type, &sp [-1], addr, FALSE);
2949 MINT_IN_CASE(MINT_LDRMFLD_VT) {
2950 MonoClassField *field;
2956 THROW_EX (mono_get_exception_null_reference (), ip);
2957 field = rtm->data_items[* (guint16 *)(ip + 1)];
2958 i32 = READ32(ip + 2);
2960 if (mono_object_is_transparent_proxy (o)) {
2961 MonoClass *klass = ((MonoTransparentProxy*)o)->remote_class->proxy_class;
2962 addr = mono_load_remote_field_checked (o, klass, field, &tmp, &error);
2963 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2965 addr = (char*)o + field->offset;
2968 sp [-1].data.p = vt_sp;
2969 memcpy(sp [-1].data.p, (char *)o + * (guint16 *)(ip + 1), i32);
2970 vt_sp += (i32 + 7) & ~7;
2971 memcpy(sp [-1].data.p, addr, i32);
2975 #define STFLD(datamem, fieldtype) \
2976 o = sp [-2].data.p; \
2978 THROW_EX (mono_get_exception_null_reference (), ip); \
2980 * (fieldtype *)((char *)o + * (guint16 *)(ip + 1)) = sp[1].data.datamem; \
2983 MINT_IN_CASE(MINT_STFLD_I1) STFLD(i, gint8); MINT_IN_BREAK;
2984 MINT_IN_CASE(MINT_STFLD_U1) STFLD(i, guint8); MINT_IN_BREAK;
2985 MINT_IN_CASE(MINT_STFLD_I2) STFLD(i, gint16); MINT_IN_BREAK;
2986 MINT_IN_CASE(MINT_STFLD_U2) STFLD(i, guint16); MINT_IN_BREAK;
2987 MINT_IN_CASE(MINT_STFLD_I4) STFLD(i, gint32); MINT_IN_BREAK;
2988 MINT_IN_CASE(MINT_STFLD_I8) STFLD(l, gint64); MINT_IN_BREAK;
2989 MINT_IN_CASE(MINT_STFLD_R4) STFLD(f, float); MINT_IN_BREAK;
2990 MINT_IN_CASE(MINT_STFLD_R8) STFLD(f, double); MINT_IN_BREAK;
2991 MINT_IN_CASE(MINT_STFLD_O) STFLD(p, gpointer); MINT_IN_BREAK;
2992 MINT_IN_CASE(MINT_STFLD_P) STFLD(p, gpointer); MINT_IN_BREAK;
2994 MINT_IN_CASE(MINT_STFLD_VT)
2997 THROW_EX (mono_get_exception_null_reference (), ip);
2998 i32 = READ32(ip + 2);
3000 memcpy((char *)o + * (guint16 *)(ip + 1), sp [1].data.p, i32);
3001 vt_sp -= (i32 + 7) & ~7;
3005 MINT_IN_CASE(MINT_STRMFLD) {
3006 MonoClassField *field;
3010 THROW_EX (mono_get_exception_null_reference (), ip);
3012 field = rtm->data_items[* (guint16 *)(ip + 1)];
3015 if (mono_object_is_transparent_proxy (o)) {
3016 MonoClass *klass = ((MonoTransparentProxy*)o)->remote_class->proxy_class;
3017 mono_store_remote_field_checked (o, klass, field, &sp [-1].data, &error);
3018 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3020 stackval_to_data (field->type, &sp [-1], (char*)o + field->offset, FALSE);
3025 MINT_IN_CASE(MINT_STRMFLD_VT) {
3026 MonoClassField *field;
3030 THROW_EX (mono_get_exception_null_reference (), ip);
3031 field = rtm->data_items[* (guint16 *)(ip + 1)];
3032 i32 = READ32(ip + 2);
3035 if (mono_object_is_transparent_proxy (o)) {
3036 MonoClass *klass = ((MonoTransparentProxy*)o)->remote_class->proxy_class;
3037 mono_store_remote_field_checked (o, klass, field, &sp [-1].data, &error);
3038 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3040 memcpy((char*)o + field->offset, sp [-1].data.p, i32);
3043 vt_sp -= (i32 + 7) & ~7;
3046 MINT_IN_CASE(MINT_LDSFLDA) {
3047 MonoClassField *field = rtm->data_items[*(guint16 *)(ip + 1)];
3048 MonoVTable *vt = mono_class_vtable (context->domain, field->parent);
3051 if (!vt->initialized) {
3053 mono_runtime_class_init_full (vt, &error);
3054 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3058 if (context->domain->special_static_fields && (addr = g_hash_table_lookup (context->domain->special_static_fields, field)))
3059 sp->data.p = mono_get_special_static_data (GPOINTER_TO_UINT (addr));
3061 sp->data.p = (char*)(vt->vtable) + field->offset;
3065 MINT_IN_CASE(MINT_LDSFLD) {
3067 MonoClassField *field;
3070 field = rtm->data_items[*(guint16 *)(ip + 1)];
3071 vt = rtm->data_items [*(guint16 *)(ip + 2)];
3072 if (!vt->initialized) {
3074 mono_runtime_class_init_full (vt, &error);
3075 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3078 if (context->domain->special_static_fields && (addr = g_hash_table_lookup (context->domain->special_static_fields, field)))
3079 addr = mono_get_special_static_data (GPOINTER_TO_UINT (addr));
3081 addr = (char*)(vt->vtable) + field->offset;
3083 stackval_from_data (field->type, sp, addr, FALSE);
3087 MINT_IN_CASE(MINT_LDSFLD_I4) {
3088 MonoClassField *field = rtm->data_items[*(guint16 *)(ip + 1)];
3089 MonoVTable *vt = rtm->data_items [*(guint16 *)(ip + 2)];
3090 if (!vt->initialized) {
3092 mono_runtime_class_init_full (vt, &error);
3093 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3096 sp->data.i = * (gint32 *)((char*)(vt->vtable) + field->offset);
3100 MINT_IN_CASE(MINT_LDSFLD_O) {
3101 MonoClassField *field = rtm->data_items[*(guint16 *)(ip + 1)];
3102 MonoVTable *vt = rtm->data_items [*(guint16 *)(ip + 2)];
3103 if (!vt->initialized) {
3105 mono_runtime_class_init_full (vt, &error);
3106 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3109 sp->data.p = * (gpointer *)((char*)(vt->vtable) + field->offset);
3113 MINT_IN_CASE(MINT_LDSFLD_VT) {
3115 MonoClassField *field;
3120 token = * (guint16 *)(ip + 1);
3121 size = READ32(ip + 2);
3122 field = rtm->data_items[token];
3125 vt = mono_class_vtable (context->domain, field->parent);
3126 if (!vt->initialized) {
3128 mono_runtime_class_init_full (vt, &error);
3129 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3132 if (context->domain->special_static_fields && (addr = g_hash_table_lookup (context->domain->special_static_fields, field)))
3133 addr = mono_get_special_static_data (GPOINTER_TO_UINT (addr));
3135 addr = (char*)(vt->vtable) + field->offset;
3138 vt_sp += (size + 7) & ~7;
3139 stackval_from_data (field->type, sp, addr, FALSE);
3143 MINT_IN_CASE(MINT_STSFLD) {
3145 MonoClassField *field;
3149 token = * (guint16 *)(ip + 1);
3150 field = rtm->data_items[token];
3154 vt = mono_class_vtable (context->domain, field->parent);
3155 if (!vt->initialized) {
3157 mono_runtime_class_init_full (vt, &error);
3158 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3161 if (context->domain->special_static_fields && (addr = g_hash_table_lookup (context->domain->special_static_fields, field)))
3162 addr = mono_get_special_static_data (GPOINTER_TO_UINT (addr));
3164 addr = (char*)(vt->vtable) + field->offset;
3166 stackval_to_data (field->type, sp, addr, FALSE);
3169 MINT_IN_CASE(MINT_STSFLD_VT) {
3171 MonoClassField *field;
3176 token = * (guint16 *)(ip + 1);
3177 size = READ32(ip + 2);
3178 field = rtm->data_items[token];
3181 vt = mono_class_vtable (context->domain, field->parent);
3182 if (!vt->initialized) {
3184 mono_runtime_class_init_full (vt, &error);
3185 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3188 if (context->domain->special_static_fields && (addr = g_hash_table_lookup (context->domain->special_static_fields, field)))
3189 addr = mono_get_special_static_data (GPOINTER_TO_UINT (addr));
3191 addr = (char*)(vt->vtable) + field->offset;
3193 stackval_to_data (field->type, sp, addr, FALSE);
3194 vt_sp -= (size + 7) & ~7;
3197 MINT_IN_CASE(MINT_STOBJ_VT) {
3199 c = rtm->data_items[* (guint16 *)(ip + 1)];
3201 size = mono_class_value_size (c, NULL);
3202 memcpy(sp [-2].data.p, sp [-1].data.p, size);
3203 vt_sp -= (size + 7) & ~7;
3207 MINT_IN_CASE(MINT_STOBJ) {
3209 c = rtm->data_items[* (guint16 *)(ip + 1)];
3211 size = mono_class_value_size (c, NULL);
3212 memcpy(sp [-2].data.p, &sp [-1].data, size);
3216 MINT_IN_CASE(MINT_CONV_OVF_I4_UN_R8)
3217 if (sp [-1].data.f < 0 || sp [-1].data.f > MYGUINT32_MAX)
3218 THROW_EX (mono_get_exception_overflow (), ip);
3219 sp [-1].data.i = (guint32)sp [-1].data.f;
3222 MINT_IN_CASE(MINT_CONV_OVF_U8_I4)
3223 if (sp [-1].data.i < 0)
3224 THROW_EX (mono_get_exception_overflow (), ip);
3225 sp [-1].data.l = sp [-1].data.i;
3228 MINT_IN_CASE(MINT_CONV_OVF_U8_R8)
3229 MINT_IN_CASE(MINT_CONV_OVF_I8_UN_R8)
3230 if (sp [-1].data.f < 0 || sp [-1].data.f > 9223372036854775807LL)
3231 THROW_EX (mono_get_exception_overflow (), ip);
3232 sp [-1].data.l = (guint64)sp [-1].data.f;
3235 MINT_IN_CASE(MINT_CONV_OVF_I8_R8)
3236 if (sp [-1].data.f < MYGINT64_MIN || sp [-1].data.f > MYGINT64_MAX)
3237 THROW_EX (mono_get_exception_overflow (), ip);
3238 sp [-1].data.l = (gint64)sp [-1].data.f;
3241 MINT_IN_CASE(MINT_CONV_OVF_I4_UN_I8)
3242 if ((mono_u)sp [-1].data.l > MYGUINT32_MAX)
3243 THROW_EX (mono_get_exception_overflow (), ip);
3244 sp [-1].data.i = (mono_u)sp [-1].data.l;
3247 MINT_IN_CASE(MINT_BOX)
3248 c = rtm->data_items [* (guint16 *)(ip + 1)];
3250 if (c->byval_arg.type == MONO_TYPE_VALUETYPE && !c->enumtype) {
3251 int size = mono_class_value_size (c, NULL);
3252 sp [-1].data.p = mono_value_box_checked (context->domain, c, sp [-1].data.p, &error);
3253 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3254 size = (size + 7) & ~7;
3258 stackval_to_data (&c->byval_arg, &sp [-1], (char*)&sp [-1], FALSE);
3259 sp [-1].data.p = mono_value_box_checked (context->domain, c, &sp [-1], &error);
3260 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3264 MINT_IN_CASE(MINT_NEWARR)
3265 sp [-1].data.p = (MonoObject*) mono_array_new_checked (context->domain, rtm->data_items[*(guint16 *)(ip + 1)], sp [-1].data.i, &error);
3266 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3268 /*if (profiling_classes) {
3269 guint count = GPOINTER_TO_UINT (g_hash_table_lookup (profiling_classes, o->vtable->klass));
3271 g_hash_table_insert (profiling_classes, o->vtable->klass, GUINT_TO_POINTER (count));
3275 MINT_IN_CASE(MINT_LDLEN)
3278 THROW_EX (mono_get_exception_null_reference (), ip);
3279 sp [-1].data.nati = mono_array_length ((MonoArray *)o);
3282 MINT_IN_CASE(MINT_GETCHR) {
3286 THROW_EX (mono_get_exception_null_reference (), ip);
3287 i32 = sp [-1].data.i;
3288 if (i32 < 0 || i32 >= mono_string_length (s))
3289 THROW_EX (mono_get_exception_index_out_of_range (), ip);
3291 sp [-1].data.i = mono_string_chars(s)[i32];
3295 MINT_IN_CASE(MINT_STRLEN)
3297 sp [-1].data.i = mono_string_length ((MonoString*)sp [-1].data.p);
3299 MINT_IN_CASE(MINT_ARRAY_RANK)
3302 THROW_EX (mono_get_exception_null_reference (), ip);
3303 sp [-1].data.i = mono_object_class (sp [-1].data.p)->rank;
3306 MINT_IN_CASE(MINT_LDELEMA) {
3310 /*token = READ32 (ip)*/;
3316 aindex = sp [1].data.i;
3317 if (aindex >= mono_array_length ((MonoArray *) o))
3318 THROW_EX (mono_get_exception_index_out_of_range (), ip - 2);
3320 /* check the array element corresponds to token */
3321 esize = mono_array_element_size (((MonoArray *) o)->obj.vtable->klass);
3323 sp->data.p = mono_array_addr_with_size ((MonoArray *) o, esize, aindex);
3327 MINT_IN_CASE(MINT_LDELEM_I1) /* fall through */
3328 MINT_IN_CASE(MINT_LDELEM_U1) /* fall through */
3329 MINT_IN_CASE(MINT_LDELEM_I2) /* fall through */
3330 MINT_IN_CASE(MINT_LDELEM_U2) /* fall through */
3331 MINT_IN_CASE(MINT_LDELEM_I4) /* fall through */
3332 MINT_IN_CASE(MINT_LDELEM_U4) /* fall through */
3333 MINT_IN_CASE(MINT_LDELEM_I8) /* fall through */
3334 MINT_IN_CASE(MINT_LDELEM_I) /* fall through */
3335 MINT_IN_CASE(MINT_LDELEM_R4) /* fall through */
3336 MINT_IN_CASE(MINT_LDELEM_R8) /* fall through */
3337 MINT_IN_CASE(MINT_LDELEM_REF) {
3345 THROW_EX (mono_get_exception_null_reference (), ip);
3347 aindex = sp [1].data.i;
3348 if (aindex >= mono_array_length (o))
3349 THROW_EX (mono_get_exception_index_out_of_range (), ip);
3352 * FIXME: throw mono_get_exception_array_type_mismatch () if needed
3355 case MINT_LDELEM_I1:
3356 sp [0].data.i = mono_array_get (o, gint8, aindex);
3358 case MINT_LDELEM_U1:
3359 sp [0].data.i = mono_array_get (o, guint8, aindex);
3361 case MINT_LDELEM_I2:
3362 sp [0].data.i = mono_array_get (o, gint16, aindex);
3364 case MINT_LDELEM_U2:
3365 sp [0].data.i = mono_array_get (o, guint16, aindex);
3368 sp [0].data.nati = mono_array_get (o, mono_i, aindex);
3370 case MINT_LDELEM_I4:
3371 sp [0].data.i = mono_array_get (o, gint32, aindex);
3373 case MINT_LDELEM_U4:
3374 sp [0].data.i = mono_array_get (o, guint32, aindex);
3376 case MINT_LDELEM_I8:
3377 sp [0].data.l = mono_array_get (o, guint64, aindex);
3379 case MINT_LDELEM_R4:
3380 sp [0].data.f = mono_array_get (o, float, aindex);
3382 case MINT_LDELEM_R8:
3383 sp [0].data.f = mono_array_get (o, double, aindex);
3385 case MINT_LDELEM_REF:
3386 sp [0].data.p = mono_array_get (o, gpointer, aindex);
3396 MINT_IN_CASE(MINT_STELEM_I) /* fall through */
3397 MINT_IN_CASE(MINT_STELEM_I1) /* fall through */
3398 MINT_IN_CASE(MINT_STELEM_I2) /* fall through */
3399 MINT_IN_CASE(MINT_STELEM_I4) /* fall through */
3400 MINT_IN_CASE(MINT_STELEM_I8) /* fall through */
3401 MINT_IN_CASE(MINT_STELEM_R4) /* fall through */
3402 MINT_IN_CASE(MINT_STELEM_R8) /* fall through */
3403 MINT_IN_CASE(MINT_STELEM_REF) {
3410 THROW_EX (mono_get_exception_null_reference (), ip);
3412 aindex = sp [1].data.i;
3413 if (aindex >= mono_array_length ((MonoArray *)o))
3414 THROW_EX (mono_get_exception_index_out_of_range (), ip);
3418 mono_array_set ((MonoArray *)o, mono_i, aindex, sp [2].data.nati);
3420 case MINT_STELEM_I1:
3421 mono_array_set ((MonoArray *)o, gint8, aindex, sp [2].data.i);
3423 case MINT_STELEM_I2:
3424 mono_array_set ((MonoArray *)o, gint16, aindex, sp [2].data.i);
3426 case MINT_STELEM_I4:
3427 mono_array_set ((MonoArray *)o, gint32, aindex, sp [2].data.i);
3429 case MINT_STELEM_I8:
3430 mono_array_set ((MonoArray *)o, gint64, aindex, sp [2].data.l);
3432 case MINT_STELEM_R4:
3433 mono_array_set ((MonoArray *)o, float, aindex, sp [2].data.f);
3435 case MINT_STELEM_R8:
3436 mono_array_set ((MonoArray *)o, double, aindex, sp [2].data.f);
3438 case MINT_STELEM_REF: {
3439 MonoObject *isinst_obj = mono_object_isinst_checked (sp [2].data.p, mono_object_class (o)->element_class, &error);
3440 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3441 if (sp [2].data.p && !isinst_obj)
3442 THROW_EX (mono_get_exception_array_type_mismatch (), ip);
3443 mono_array_set ((MonoArray *)o, gpointer, aindex, sp [2].data.p);
3452 MINT_IN_CASE(MINT_CONV_OVF_I4_U4)
3453 if (sp [-1].data.i < 0)
3454 THROW_EX (mono_get_exception_overflow (), ip);
3457 MINT_IN_CASE(MINT_CONV_OVF_I4_I8)
3458 if (sp [-1].data.l < MYGINT32_MIN || sp [-1].data.l > MYGINT32_MAX)
3459 THROW_EX (mono_get_exception_overflow (), ip);
3460 sp [-1].data.i = (gint32) sp [-1].data.l;
3463 MINT_IN_CASE(MINT_CONV_OVF_I4_R8)
3464 if (sp [-1].data.f < MYGINT32_MIN || sp [-1].data.f > MYGINT32_MAX)
3465 THROW_EX (mono_get_exception_overflow (), ip);
3466 sp [-1].data.i = (gint32) sp [-1].data.f;
3469 MINT_IN_CASE(MINT_CONV_OVF_U4_I4)
3470 if (sp [-1].data.i < 0)
3471 THROW_EX (mono_get_exception_overflow (), ip);
3474 MINT_IN_CASE(MINT_CONV_OVF_U4_I8)
3475 if (sp [-1].data.l < 0 || sp [-1].data.l > MYGUINT32_MAX)
3476 THROW_EX (mono_get_exception_overflow (), ip);
3477 sp [-1].data.i = (guint32) sp [-1].data.l;
3480 MINT_IN_CASE(MINT_CONV_OVF_U4_R8)
3481 if (sp [-1].data.f < 0 || sp [-1].data.f > MYGUINT32_MAX)
3482 THROW_EX (mono_get_exception_overflow (), ip);
3483 sp [-1].data.i = (guint32) sp [-1].data.f;
3486 MINT_IN_CASE(MINT_CONV_OVF_I2_I4)
3487 if (sp [-1].data.i < -32768 || sp [-1].data.i > 32767)
3488 THROW_EX (mono_get_exception_overflow (), ip);
3491 MINT_IN_CASE(MINT_CONV_OVF_I2_I8)
3492 if (sp [-1].data.l < -32768 || sp [-1].data.l > 32767)
3493 THROW_EX (mono_get_exception_overflow (), ip);
3494 sp [-1].data.i = (gint16) sp [-1].data.l;
3497 MINT_IN_CASE(MINT_CONV_OVF_I2_R8)
3498 if (sp [-1].data.f < -32768 || sp [-1].data.f > 32767)
3499 THROW_EX (mono_get_exception_overflow (), ip);
3500 sp [-1].data.i = (gint16) sp [-1].data.f;
3503 MINT_IN_CASE(MINT_CONV_OVF_U2_I4)
3504 if (sp [-1].data.i < 0 || sp [-1].data.i > 65535)
3505 THROW_EX (mono_get_exception_overflow (), ip);
3508 MINT_IN_CASE(MINT_CONV_OVF_U2_I8)
3509 if (sp [-1].data.l < 0 || sp [-1].data.l > 65535)
3510 THROW_EX (mono_get_exception_overflow (), ip);
3511 sp [-1].data.i = (guint16) sp [-1].data.l;
3514 MINT_IN_CASE(MINT_CONV_OVF_U2_R8)
3515 if (sp [-1].data.f < 0 || sp [-1].data.f > 65535)
3516 THROW_EX (mono_get_exception_overflow (), ip);
3517 sp [-1].data.i = (guint16) sp [-1].data.f;
3520 MINT_IN_CASE(MINT_CONV_OVF_I1_I4)
3521 if (sp [-1].data.i < -128 || sp [-1].data.i > 127)
3522 THROW_EX (mono_get_exception_overflow (), ip);
3525 MINT_IN_CASE(MINT_CONV_OVF_I1_I8)
3526 if (sp [-1].data.l < -128 || sp [-1].data.l > 127)
3527 THROW_EX (mono_get_exception_overflow (), ip);
3528 sp [-1].data.i = (gint8) sp [-1].data.l;
3531 MINT_IN_CASE(MINT_CONV_OVF_I1_R8)
3532 if (sp [-1].data.f < -128 || sp [-1].data.f > 127)
3533 THROW_EX (mono_get_exception_overflow (), ip);
3534 sp [-1].data.i = (gint8) sp [-1].data.f;
3537 MINT_IN_CASE(MINT_CONV_OVF_U1_I4)
3538 if (sp [-1].data.i < 0 || sp [-1].data.i > 255)
3539 THROW_EX (mono_get_exception_overflow (), ip);
3542 MINT_IN_CASE(MINT_CONV_OVF_U1_I8)
3543 if (sp [-1].data.l < 0 || sp [-1].data.l > 255)
3544 THROW_EX (mono_get_exception_overflow (), ip);
3545 sp [-1].data.i = (guint8) sp [-1].data.l;
3548 MINT_IN_CASE(MINT_CONV_OVF_U1_R8)
3549 if (sp [-1].data.f < 0 || sp [-1].data.f > 255)
3550 THROW_EX (mono_get_exception_overflow (), ip);
3551 sp [-1].data.i = (guint8) sp [-1].data.f;
3555 MINT_IN_CASE(MINT_LDELEM)
3556 MINT_IN_CASE(MINT_STELEM)
3557 MINT_IN_CASE(MINT_UNBOX_ANY)
3559 MINT_IN_CASE(MINT_REFANYVAL) ves_abort(); MINT_IN_BREAK;
3561 MINT_IN_CASE(MINT_CKFINITE)
3562 if (!isfinite(sp [-1].data.f))
3563 THROW_EX (mono_get_exception_arithmetic (), ip);
3567 MINT_IN_CASE(MINT_MKREFANY) ves_abort(); MINT_IN_BREAK;
3569 MINT_IN_CASE(MINT_LDTOKEN)
3572 * (gpointer *)sp->data.p = rtm->data_items[*(guint16 *)(ip + 1)];
3576 MINT_IN_CASE(MINT_ADD_OVF_I4)
3577 if (CHECK_ADD_OVERFLOW (sp [-2].data.i, sp [-1].data.i))
3578 THROW_EX (mono_get_exception_overflow (), ip);
3581 MINT_IN_CASE(MINT_ADD_OVF_I8)
3582 if (CHECK_ADD_OVERFLOW64 (sp [-2].data.l, sp [-1].data.l))
3583 THROW_EX (mono_get_exception_overflow (), ip);
3586 MINT_IN_CASE(MINT_ADD_OVF_UN_I4)
3587 if (CHECK_ADD_OVERFLOW_UN (sp [-2].data.i, sp [-1].data.i))
3588 THROW_EX (mono_get_exception_overflow (), ip);
3589 BINOP_CAST(i, +, guint32);
3591 MINT_IN_CASE(MINT_ADD_OVF_UN_I8)
3592 if (CHECK_ADD_OVERFLOW64_UN (sp [-2].data.l, sp [-1].data.l))
3593 THROW_EX (mono_get_exception_overflow (), ip);
3594 BINOP_CAST(l, +, guint64);
3596 MINT_IN_CASE(MINT_MUL_OVF_I4)
3597 if (CHECK_MUL_OVERFLOW (sp [-2].data.i, sp [-1].data.i))
3598 THROW_EX (mono_get_exception_overflow (), ip);
3601 MINT_IN_CASE(MINT_MUL_OVF_I8)
3602 if (CHECK_MUL_OVERFLOW64 (sp [-2].data.l, sp [-1].data.l))
3603 THROW_EX (mono_get_exception_overflow (), ip);
3606 MINT_IN_CASE(MINT_MUL_OVF_UN_I4)
3607 if (CHECK_MUL_OVERFLOW_UN (sp [-2].data.i, sp [-1].data.i))
3608 THROW_EX (mono_get_exception_overflow (), ip);
3609 BINOP_CAST(i, *, guint32);
3611 MINT_IN_CASE(MINT_MUL_OVF_UN_I8)
3612 if (CHECK_MUL_OVERFLOW64_UN (sp [-2].data.l, sp [-1].data.l))
3613 THROW_EX (mono_get_exception_overflow (), ip);
3614 BINOP_CAST(l, *, guint64);
3616 MINT_IN_CASE(MINT_SUB_OVF_I4)
3617 if (CHECK_SUB_OVERFLOW (sp [-2].data.i, sp [-1].data.i))
3618 THROW_EX (mono_get_exception_overflow (), ip);
3621 MINT_IN_CASE(MINT_SUB_OVF_I8)
3622 if (CHECK_SUB_OVERFLOW64 (sp [-2].data.l, sp [-1].data.l))
3623 THROW_EX (mono_get_exception_overflow (), ip);
3626 MINT_IN_CASE(MINT_SUB_OVF_UN_I4)
3627 if (CHECK_SUB_OVERFLOW_UN (sp [-2].data.i, sp [-1].data.i))
3628 THROW_EX (mono_get_exception_overflow (), ip);
3629 BINOP_CAST(i, -, guint32);
3631 MINT_IN_CASE(MINT_SUB_OVF_UN_I8)
3632 if (CHECK_SUB_OVERFLOW64_UN (sp [-2].data.l, sp [-1].data.l))
3633 THROW_EX (mono_get_exception_overflow (), ip);
3634 BINOP_CAST(l, -, guint64);
3636 MINT_IN_CASE(MINT_ENDFINALLY)
3638 ip = finally_ips->data;
3639 finally_ips = g_slist_remove (finally_ips, ip);
3646 MINT_IN_CASE(MINT_LEAVE) /* Fall through */
3647 MINT_IN_CASE(MINT_LEAVE_S)
3648 while (sp > frame->stack) {
3652 if (*ip == MINT_LEAVE_S) {
3653 ip += (short) *(ip + 1);
3655 ip += (gint32) READ32 (ip + 1);
3658 if (frame->ex_handler != NULL && MONO_OFFSET_IN_HANDLER(frame->ex_handler, frame->ip - rtm->code)) {
3659 frame->ex_handler = NULL;
3662 goto handle_finally;
3664 MINT_IN_CASE(MINT_ICALL_V_V)
3665 MINT_IN_CASE(MINT_ICALL_V_P)
3666 MINT_IN_CASE(MINT_ICALL_P_V)
3667 MINT_IN_CASE(MINT_ICALL_P_P)
3668 MINT_IN_CASE(MINT_ICALL_PP_V)
3669 MINT_IN_CASE(MINT_ICALL_PI_V)
3670 MINT_IN_CASE(MINT_ICALL_PP_P)
3671 MINT_IN_CASE(MINT_ICALL_PI_P)
3672 MINT_IN_CASE(MINT_ICALL_PPP_V)
3673 MINT_IN_CASE(MINT_ICALL_PPI_V)
3674 sp = do_icall (context, *ip, sp, rtm->data_items [*(guint16 *)(ip + 1)]);
3675 if (frame->ex != NULL)
3676 goto handle_exception;
3679 MINT_IN_CASE(MINT_MONO_LDPTR)
3680 sp->data.p = rtm->data_items [*(guint16 *)(ip + 1)];
3684 MINT_IN_CASE(MINT_MONO_NEWOBJ)
3685 sp->data.p = mono_object_new_checked (context->domain, rtm->data_items [*(guint16 *)(ip + 1)], &error);
3686 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3690 MINT_IN_CASE(MINT_MONO_FREE)
3693 g_error ("that doesn't seem right");
3694 g_free (sp->data.p);
3696 MINT_IN_CASE(MINT_MONO_RETOBJ)
3699 stackval_from_data (mono_method_signature (frame->runtime_method->method)->ret, frame->retval, sp->data.p,
3700 mono_method_signature (frame->runtime_method->method)->pinvoke);
3701 if (sp > frame->stack)
3702 g_warning ("retobj: more values on stack: %d", sp-frame->stack);
3705 #define RELOP(datamem, op) \
3707 sp [-1].data.i = sp [-1].data.datamem op sp [0].data.datamem; \
3709 MINT_IN_CASE(MINT_CEQ_I4)
3712 MINT_IN_CASE(MINT_CEQ0_I4)
3713 sp [-1].data.i = (sp [-1].data.i == 0);
3716 MINT_IN_CASE(MINT_CEQ_I8)
3719 MINT_IN_CASE(MINT_CEQ_R8)
3721 if (isunordered (sp [-1].data.f, sp [0].data.f))
3724 sp [-1].data.i = sp [-1].data.f == sp [0].data.f;
3727 MINT_IN_CASE(MINT_CGT_I4)
3730 MINT_IN_CASE(MINT_CGT_I8)
3733 MINT_IN_CASE(MINT_CGT_R8)
3735 if (isunordered (sp [-1].data.f, sp [0].data.f))
3738 sp [-1].data.i = sp [-1].data.f > sp [0].data.f;
3742 #define RELOP_CAST(datamem, op, type) \
3744 sp [-1].data.i = (type)sp [-1].data.datamem op (type)sp [0].data.datamem; \
3747 MINT_IN_CASE(MINT_CGT_UN_I4)
3748 RELOP_CAST(i, >, guint32);
3750 MINT_IN_CASE(MINT_CGT_UN_I8)
3751 RELOP_CAST(l, >, guint64);
3753 MINT_IN_CASE(MINT_CGT_UN_R8)
3755 if (isunordered (sp [-1].data.f, sp [0].data.f))
3758 sp [-1].data.i = sp [-1].data.f > sp [0].data.f;
3761 MINT_IN_CASE(MINT_CLT_I4)
3764 MINT_IN_CASE(MINT_CLT_I8)
3767 MINT_IN_CASE(MINT_CLT_R8)
3769 if (isunordered (sp [-1].data.f, sp [0].data.f))
3772 sp [-1].data.i = sp [-1].data.f < sp [0].data.f;
3775 MINT_IN_CASE(MINT_CLT_UN_I4)
3776 RELOP_CAST(i, <, guint32);
3778 MINT_IN_CASE(MINT_CLT_UN_I8)
3779 RELOP_CAST(l, <, guint64);
3781 MINT_IN_CASE(MINT_CLT_UN_R8)
3783 if (isunordered (sp [-1].data.f, sp [0].data.f))
3786 sp [-1].data.i = sp [-1].data.f < sp [0].data.f;
3789 MINT_IN_CASE(MINT_LDFTN) {
3790 sp->data.p = rtm->data_items [* (guint16 *)(ip + 1)];
3795 MINT_IN_CASE(MINT_LDVIRTFTN) {
3796 RuntimeMethod *m = rtm->data_items [* (guint16 *)(ip + 1)];
3800 THROW_EX (mono_get_exception_null_reference (), ip - 2);
3802 sp->data.p = get_virtual_method (context->domain, m, sp->data.p);
3807 MINT_IN_CASE(MINT_LDTHIS)
3808 sp->data.p = frame->obj;
3812 MINT_IN_CASE(MINT_STTHIS)
3814 frame->obj = sp->data.p;
3817 MINT_IN_CASE(MINT_LDTHISA)
3818 sp->data.p = &frame->obj;
3823 #define LDARG(datamem, argtype) \
3824 sp->data.datamem = * (argtype *)(frame->args + * (guint16 *)(ip + 1)); \
3828 MINT_IN_CASE(MINT_LDARG_I1) LDARG(i, gint8); MINT_IN_BREAK;
3829 MINT_IN_CASE(MINT_LDARG_U1) LDARG(i, guint8); MINT_IN_BREAK;
3830 MINT_IN_CASE(MINT_LDARG_I2) LDARG(i, gint16); MINT_IN_BREAK;
3831 MINT_IN_CASE(MINT_LDARG_U2) LDARG(i, guint16); MINT_IN_BREAK;
3832 MINT_IN_CASE(MINT_LDARG_I4) LDARG(i, gint32); MINT_IN_BREAK;
3833 MINT_IN_CASE(MINT_LDARG_I8) LDARG(l, gint64); MINT_IN_BREAK;
3834 MINT_IN_CASE(MINT_LDARG_R4) LDARG(f, float); MINT_IN_BREAK;
3835 MINT_IN_CASE(MINT_LDARG_R8) LDARG(f, double); MINT_IN_BREAK;
3836 MINT_IN_CASE(MINT_LDARG_O) LDARG(p, gpointer); MINT_IN_BREAK;
3837 MINT_IN_CASE(MINT_LDARG_P) LDARG(p, gpointer); MINT_IN_BREAK;
3839 MINT_IN_CASE(MINT_LDARG_VT)
3841 i32 = READ32(ip + 2);
3842 memcpy(sp->data.p, frame->args + * (guint16 *)(ip + 1), i32);
3843 vt_sp += (i32 + 7) & ~7;
3848 #define STARG(datamem, argtype) \
3850 * (argtype *)(frame->args + * (guint16 *)(ip + 1)) = sp->data.datamem; \
3853 MINT_IN_CASE(MINT_STARG_I1) STARG(i, gint8); MINT_IN_BREAK;
3854 MINT_IN_CASE(MINT_STARG_U1) STARG(i, guint8); MINT_IN_BREAK;
3855 MINT_IN_CASE(MINT_STARG_I2) STARG(i, gint16); MINT_IN_BREAK;
3856 MINT_IN_CASE(MINT_STARG_U2) STARG(i, guint16); MINT_IN_BREAK;
3857 MINT_IN_CASE(MINT_STARG_I4) STARG(i, gint32); MINT_IN_BREAK;
3858 MINT_IN_CASE(MINT_STARG_I8) STARG(l, gint64); MINT_IN_BREAK;
3859 MINT_IN_CASE(MINT_STARG_R4) STARG(f, float); MINT_IN_BREAK;
3860 MINT_IN_CASE(MINT_STARG_R8) STARG(f, double); MINT_IN_BREAK;
3861 MINT_IN_CASE(MINT_STARG_O) STARG(p, gpointer); MINT_IN_BREAK;
3862 MINT_IN_CASE(MINT_STARG_P) STARG(p, gpointer); MINT_IN_BREAK;
3864 MINT_IN_CASE(MINT_STARG_VT)
3865 i32 = READ32(ip + 2);
3867 memcpy(frame->args + * (guint16 *)(ip + 1), sp->data.p, i32);
3868 vt_sp -= (i32 + 7) & ~7;
3872 #define STINARG(datamem, argtype) \
3874 int n = * (guint16 *)(ip + 1); \
3875 * (argtype *)(frame->args + rtm->arg_offsets [n]) = frame->stack_args [n].data.datamem; \
3879 MINT_IN_CASE(MINT_STINARG_I1) STINARG(i, gint8); MINT_IN_BREAK;
3880 MINT_IN_CASE(MINT_STINARG_U1) STINARG(i, guint8); MINT_IN_BREAK;
3881 MINT_IN_CASE(MINT_STINARG_I2) STINARG(i, gint16); MINT_IN_BREAK;
3882 MINT_IN_CASE(MINT_STINARG_U2) STINARG(i, guint16); MINT_IN_BREAK;
3883 MINT_IN_CASE(MINT_STINARG_I4) STINARG(i, gint32); MINT_IN_BREAK;
3884 MINT_IN_CASE(MINT_STINARG_I8) STINARG(l, gint64); MINT_IN_BREAK;
3885 MINT_IN_CASE(MINT_STINARG_R4) STINARG(f, float); MINT_IN_BREAK;
3886 MINT_IN_CASE(MINT_STINARG_R8) STINARG(f, double); MINT_IN_BREAK;
3887 MINT_IN_CASE(MINT_STINARG_O) STINARG(p, gpointer); MINT_IN_BREAK;
3888 MINT_IN_CASE(MINT_STINARG_P) STINARG(p, gpointer); MINT_IN_BREAK;
3890 MINT_IN_CASE(MINT_STINARG_VT) {
3891 int n = * (guint16 *)(ip + 1);
3892 i32 = READ32(ip + 2);
3893 memcpy (frame->args + rtm->arg_offsets [n], frame->stack_args [n].data.p, i32);
3898 MINT_IN_CASE(MINT_LDARGA)
3899 sp->data.p = frame->args + * (guint16 *)(ip + 1);
3904 #define LDLOC(datamem, argtype) \
3905 sp->data.datamem = * (argtype *)(locals + * (guint16 *)(ip + 1)); \
3909 MINT_IN_CASE(MINT_LDLOC_I1) LDLOC(i, gint8); MINT_IN_BREAK;
3910 MINT_IN_CASE(MINT_LDLOC_U1) LDLOC(i, guint8); MINT_IN_BREAK;
3911 MINT_IN_CASE(MINT_LDLOC_I2) LDLOC(i, gint16); MINT_IN_BREAK;
3912 MINT_IN_CASE(MINT_LDLOC_U2) LDLOC(i, guint16); MINT_IN_BREAK;
3913 MINT_IN_CASE(MINT_LDLOC_I4) LDLOC(i, gint32); MINT_IN_BREAK;
3914 MINT_IN_CASE(MINT_LDLOC_I8) LDLOC(l, gint64); MINT_IN_BREAK;
3915 MINT_IN_CASE(MINT_LDLOC_R4) LDLOC(f, float); MINT_IN_BREAK;
3916 MINT_IN_CASE(MINT_LDLOC_R8) LDLOC(f, double); MINT_IN_BREAK;
3917 MINT_IN_CASE(MINT_LDLOC_O) LDLOC(p, gpointer); MINT_IN_BREAK;
3918 MINT_IN_CASE(MINT_LDLOC_P) LDLOC(p, gpointer); MINT_IN_BREAK;
3920 MINT_IN_CASE(MINT_LDLOC_VT)
3922 i32 = READ32(ip + 2);
3923 memcpy(sp->data.p, locals + * (guint16 *)(ip + 1), i32);
3924 vt_sp += (i32 + 7) & ~7;
3929 MINT_IN_CASE(MINT_LDLOCA_S)
3930 sp->data.p = locals + * (guint16 *)(ip + 1);
3935 #define STLOC(datamem, argtype) \
3937 * (argtype *)(locals + * (guint16 *)(ip + 1)) = sp->data.datamem; \
3940 MINT_IN_CASE(MINT_STLOC_I1) STLOC(i, gint8); MINT_IN_BREAK;
3941 MINT_IN_CASE(MINT_STLOC_U1) STLOC(i, guint8); MINT_IN_BREAK;
3942 MINT_IN_CASE(MINT_STLOC_I2) STLOC(i, gint16); MINT_IN_BREAK;
3943 MINT_IN_CASE(MINT_STLOC_U2) STLOC(i, guint16); MINT_IN_BREAK;
3944 MINT_IN_CASE(MINT_STLOC_I4) STLOC(i, gint32); MINT_IN_BREAK;
3945 MINT_IN_CASE(MINT_STLOC_I8) STLOC(l, gint64); MINT_IN_BREAK;
3946 MINT_IN_CASE(MINT_STLOC_R4) STLOC(f, float); MINT_IN_BREAK;
3947 MINT_IN_CASE(MINT_STLOC_R8) STLOC(f, double); MINT_IN_BREAK;
3948 MINT_IN_CASE(MINT_STLOC_O) STLOC(p, gpointer); MINT_IN_BREAK;
3949 MINT_IN_CASE(MINT_STLOC_P) STLOC(p, gpointer); MINT_IN_BREAK;
3951 #define STLOC_NP(datamem, argtype) \
3952 * (argtype *)(locals + * (guint16 *)(ip + 1)) = sp [-1].data.datamem; \
3955 MINT_IN_CASE(MINT_STLOC_NP_I4) STLOC_NP(i, gint32); MINT_IN_BREAK;
3956 MINT_IN_CASE(MINT_STLOC_NP_O) STLOC_NP(p, gpointer); MINT_IN_BREAK;
3958 MINT_IN_CASE(MINT_STLOC_VT)
3959 i32 = READ32(ip + 2);
3961 memcpy(locals + * (guint16 *)(ip + 1), sp->data.p, i32);
3962 vt_sp -= (i32 + 7) & ~7;
3966 MINT_IN_CASE(MINT_LOCALLOC)
3967 if (sp != frame->stack + 1) /*FIX?*/
3968 THROW_EX (mono_get_exception_execution_engine (NULL), ip);
3969 sp [-1].data.p = alloca (sp [-1].data.i);
3973 MINT_IN_CASE(MINT_ENDFILTER) ves_abort(); MINT_IN_BREAK;
3975 MINT_IN_CASE(MINT_INITOBJ)
3977 memset (sp->data.vt, 0, READ32(ip + 1));
3980 MINT_IN_CASE(MINT_CPBLK)
3982 if (!sp [0].data.p || !sp [1].data.p)
3983 THROW_EX (mono_get_exception_null_reference(), ip - 1);
3985 /* FIXME: value and size may be int64... */
3986 memcpy (sp [0].data.p, sp [1].data.p, sp [2].data.i);
3989 MINT_IN_CASE(MINT_CONSTRAINED_) {
3991 /* FIXME: implement */
3993 token = READ32 (ip);
3998 MINT_IN_CASE(MINT_INITBLK)
4001 THROW_EX (mono_get_exception_null_reference(), ip - 1);
4003 /* FIXME: value and size may be int64... */
4004 memset (sp [0].data.p, sp [1].data.i, sp [2].data.i);
4007 MINT_IN_CASE(MINT_NO_)
4008 /* FIXME: implement */
4012 MINT_IN_CASE(MINT_RETHROW)
4014 * need to clarify what this should actually do:
4015 * start the search from the last found handler in
4016 * this method or continue in the caller or what.
4017 * Also, do we need to run finally/fault handlers after a retrow?
4018 * Well, this implementation will follow the usual search
4019 * for an handler, considering the current ip as throw spot.
4020 * We need to NULL frame->ex_handler for the later code to
4021 * actually run the new found handler.
4023 frame->ex_handler = NULL;
4024 THROW_EX (frame->ex, ip - 1);
4027 g_print ("Unimplemented opcode: %04x %s at 0x%x\n", *ip, mono_interp_opname[*ip], ip-rtm->code);
4028 THROW_EX (mono_get_exception_execution_engine ("Unimplemented opcode"), ip);
4032 g_assert_not_reached ();
4034 * Exception handling code.
4035 * The exception object is stored in frame->ex.
4042 MonoInvocation *inv;
4043 MonoExceptionClause *clause;
4049 g_print ("* Handling exception '%s' at IL_%04x\n",
4050 frame->ex == NULL ? "** Unknown **" : mono_object_class (frame->ex)->name,
4051 rtm == NULL ? 0 : frame->ip - rtm->code);
4053 if (die_on_exception)
4056 for (inv = frame; inv; inv = inv->parent) {
4058 if (inv->runtime_method == NULL)
4060 method = inv->runtime_method->method;
4061 if (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL)
4063 if (method->iflags & (METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL | METHOD_IMPL_ATTRIBUTE_RUNTIME))
4065 if (inv->ip == NULL)
4067 ip_offset = inv->ip - inv->runtime_method->code;
4068 inv->ex_handler = NULL; /* clear this in case we are trhowing an exception while handling one - this one wins */
4069 for (i = 0; i < inv->runtime_method->num_clauses; ++i) {
4070 clause = &inv->runtime_method->clauses [i];
4071 if (clause->flags <= 1 && MONO_OFFSET_IN_CLAUSE (clause, ip_offset)) {
4072 if (!clause->flags) {
4073 MonoObject *isinst_obj = mono_object_isinst_checked ((MonoObject*)frame->ex, clause->data.catch_class, &error);
4074 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4077 * OK, we found an handler, now we need to execute the finally
4078 * and fault blocks before branching to the handler code.
4080 inv->ex_handler = clause;
4083 g_print ("* Found handler at '%s'\n", method->name);
4085 goto handle_finally;
4088 /* FIXME: handle filter clauses */
4095 * If we get here, no handler was found: print a stack trace.
4097 for (inv = frame; inv; inv = inv->parent) {
4098 if (inv->invoke_trap)
4099 goto handle_finally;
4102 ex_obj = (MonoObject*)frame->ex;
4103 mono_unhandled_exception (ex_obj);
4110 MonoExceptionClause *clause;
4111 GSList *old_list = finally_ips;
4112 MonoMethod *method = frame->runtime_method->method;
4113 MonoMethodHeader *header = mono_method_get_header_checked (method, &error);
4114 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4118 g_print ("* Handle finally IL_%04x\n", endfinally_ip == NULL ? 0 : endfinally_ip - rtm->code);
4120 if (rtm == NULL || (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL)
4121 || (method->iflags & (METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL | METHOD_IMPL_ATTRIBUTE_RUNTIME))) {
4124 ip_offset = frame->ip - rtm->code;
4126 if (endfinally_ip != NULL)
4127 finally_ips = g_slist_prepend(finally_ips, (void *)endfinally_ip);
4128 for (i = 0; i < header->num_clauses; ++i)
4129 if (frame->ex_handler == &rtm->clauses [i])
4133 clause = &rtm->clauses [i];
4134 if (MONO_OFFSET_IN_CLAUSE (clause, ip_offset) && (endfinally_ip == NULL || !(MONO_OFFSET_IN_CLAUSE (clause, endfinally_ip - rtm->code)))) {
4135 if (clause->flags == MONO_EXCEPTION_CLAUSE_FINALLY) {
4136 ip = rtm->code + clause->handler_offset;
4137 finally_ips = g_slist_prepend (finally_ips, (gpointer) ip);
4140 g_print ("* Found finally at IL_%04x with exception: %s\n", clause->handler_offset, frame->ex? "yes": "no");
4146 endfinally_ip = NULL;
4148 if (old_list != finally_ips && finally_ips) {
4149 ip = finally_ips->data;
4150 finally_ips = g_slist_remove (finally_ips, ip);
4151 sp = frame->stack; /* spec says stack should be empty at endfinally so it should be at the start too */
4156 * If an exception is set, we need to execute the fault handler, too,
4157 * otherwise, we continue normally.
4167 MonoExceptionClause *clause;
4168 MonoMethod *method = frame->runtime_method->method;
4169 MonoMethodHeader *header = mono_method_get_header_checked (method, &error);
4170 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4174 g_print ("* Handle fault\n");
4176 ip_offset = frame->ip - rtm->code;
4177 for (i = 0; i < header->num_clauses; ++i) {
4178 clause = &rtm->clauses [i];
4179 if (clause->flags == MONO_EXCEPTION_CLAUSE_FAULT && MONO_OFFSET_IN_CLAUSE (clause, ip_offset)) {
4180 ip = rtm->code + clause->handler_offset;
4183 g_print ("* Executing handler at IL_%04x\n", clause->handler_offset);
4189 * If the handler for the exception was found in this method, we jump
4190 * to it right away, otherwise we return and let the caller run
4191 * the finally, fault and catch blocks.
4192 * This same code should be present in the endfault opcode, but it
4193 * is corrently not assigned in the ECMA specs: LAMESPEC.
4195 if (frame->ex_handler) {
4198 g_print ("* Executing handler at IL_%04x\n", frame->ex_handler->handler_offset);
4200 ip = rtm->code + frame->ex_handler->handler_offset;
4202 vt_sp = (unsigned char *) sp + rtm->stack_size;
4203 sp->data.p = frame->ex;
4214 ves_exec_method (MonoInvocation *frame)
4216 ThreadContext *context = mono_native_tls_get_value (thread_context_id);
4217 ThreadContext context_struct;
4224 mono_unhandled_exception ((MonoObject*)frame->ex);
4227 if (context == NULL) {
4228 context = &context_struct;
4229 context_struct.domain = mono_domain_get ();
4230 context_struct.base_frame = frame;
4231 context_struct.current_frame = NULL;
4232 context_struct.env_frame = frame;
4233 context_struct.current_env = &env;
4234 context_struct.search_for_handler = 0;
4235 context_struct.managed_code = 0;
4236 mono_native_tls_set_value (thread_context_id, context);
4239 frame->parent = context->current_frame;
4240 frame->runtime_method = mono_interp_get_runtime_method (context->domain, frame->method, &error);
4241 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4242 context->managed_code = 1;
4243 ves_exec_method_with_context (frame, context);
4244 context->managed_code = 0;
4246 if (context != &context_struct && context->current_env) {
4247 context->env_frame->ex = frame->ex;
4248 longjmp (*context->current_env, 1);
4251 mono_unhandled_exception ((MonoObject*)frame->ex);
4253 if (context->base_frame == frame)
4254 mono_native_tls_set_value (thread_context_id, NULL);
4256 context->current_frame = frame->parent;
4260 ves_exec (MonoDomain *domain, MonoAssembly *assembly, int argc, char *argv[])
4262 MonoImage *image = mono_assembly_get_image (assembly);
4267 method = mono_get_method_checked (image, mono_image_get_entry_point (image), NULL, NULL, &error);
4268 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4271 g_error ("No entry point method found in %s", mono_image_get_filename (image));
4273 rval = mono_runtime_run_main_checked (method, argc, argv, &error);
4274 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4282 "mint %s, the Mono ECMA CLI interpreter, (C) 2001, 2002 Ximian, Inc.\n\n"
4283 "Usage is: mint [options] executable args...\n\n", VERSION);
4285 "Runtime Debugging:\n"
4290 " --noptr\t\t\tdon't print pointer addresses in trace output\n"
4293 " --traceclassinit\n"
4296 " --debug method_name\n"
4303 " --config filename load the specified config file instead of the default\n"
4304 " --workers n maximum number of worker threads\n"
4310 interp_ves_icall_get_frame_info (gint32 skip, MonoBoolean need_file_info,
4311 MonoReflectionMethod **method,
4312 gint32 *iloffset, gint32 *native_offset,
4313 MonoString **file, gint32 *line, gint32 *column)
4315 ThreadContext *context = mono_native_tls_get_value (thread_context_id);
4316 MonoInvocation *inv = context->current_frame;
4320 for (i = 0; inv && i < skip; inv = inv->parent)
4321 if (inv->runtime_method != NULL)
4332 *method = mono_method_get_object_checked (context->domain, inv->runtime_method->method, NULL, &error);
4333 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4338 if (need_file_info) {
4342 *file = mono_string_new (mono_domain_get (), "unknown");
4349 interp_ves_icall_get_trace (MonoException *exc, gint32 skip, MonoBoolean need_file_info)
4351 MonoDomain *domain = mono_domain_get ();
4353 MonoArray *ta = exc->trace_ips;
4358 /* Exception is not thrown yet */
4359 MonoArray *array = mono_array_new_checked (domain, mono_defaults.stack_frame_class, 0, &error);
4360 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4364 len = mono_array_length (ta);
4366 res = mono_array_new_checked (domain, mono_defaults.stack_frame_class, len > skip ? len - skip : 0, &error);
4367 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4369 for (i = skip; i < len / 2; i++) {
4370 MonoStackFrame *sf = (MonoStackFrame *)mono_object_new_checked (domain, mono_defaults.stack_frame_class, &error);
4371 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4372 gushort *ip = mono_array_get (ta, gpointer, 2 * i + 1);
4373 RuntimeMethod *rtm = mono_array_get (ta, gpointer, 2 * i);
4376 sf->method = mono_method_get_object_checked (domain, rtm->method, NULL, &error);
4377 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4378 sf->native_offset = ip - rtm->code;
4382 sf->il_offset = mono_debug_il_offset_from_address (ji->method, sf->native_offset, domain);
4384 if (need_file_info) {
4387 filename = mono_debug_source_location_from_address (ji->method, sf->native_offset, &sf->line, domain);
4389 sf->filename = filename? mono_string_new (domain, filename): NULL;
4396 mono_array_set (res, gpointer, i, sf);
4403 ves_icall_System_Delegate_CreateDelegate_internal (MonoReflectionType *type, MonoObject *target, MonoReflectionMethod *info)
4405 MonoClass *delegate_class = mono_class_from_mono_type (type->type);
4406 MonoObject *delegate;
4409 g_assert (delegate_class->parent == mono_defaults.multicastdelegate_class);
4411 delegate = mono_object_new_checked (mono_object_domain (type), delegate_class, &error);
4412 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4414 interp_delegate_ctor (mono_object_domain (type), delegate, target, mono_interp_get_runtime_method (mono_get_root_domain (), info->method, &error));
4415 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4423 mono_native_tls_alloc (&thread_context_id, NULL);
4424 mono_native_tls_set_value (thread_context_id, NULL);
4425 mono_os_mutex_init_recursive (&runtime_method_lookup_section);
4426 mono_os_mutex_init_recursive (&create_method_pointer_mutex);
4428 mono_interp_transform_init ();
4431 typedef int (*TestMethod) (void);
4434 interp_regression_step (MonoImage *image, int verbose, int *total_run, int *total, GTimer *timer, MonoDomain *domain)
4436 int result, expected, failed, cfailed, run;
4437 double elapsed, transform_time;
4439 MonoObject *result_obj;
4440 static gboolean filter_method_init = FALSE;
4441 static const char *filter_method = NULL;
4443 g_print ("Test run: image=%s\n", mono_image_get_filename (image));
4444 cfailed = failed = run = 0;
4445 transform_time = elapsed = 0.0;
4448 /* fixme: ugly hack - delete all previously compiled methods */
4449 if (domain_jit_info (domain)) {
4450 g_hash_table_destroy (domain_jit_info (domain)->jit_trampoline_hash);
4451 domain_jit_info (domain)->jit_trampoline_hash = g_hash_table_new (mono_aligned_addr_hash, NULL);
4452 mono_internal_hash_table_destroy (&(domain->jit_code_hash));
4453 mono_jit_code_hash_init (&(domain->jit_code_hash));
4457 g_timer_start (timer);
4458 for (i = 0; i < mono_image_get_table_rows (image, MONO_TABLE_METHOD); ++i) {
4460 MonoMethod *method = mono_get_method_checked (image, MONO_TOKEN_METHOD_DEF | (i + 1), NULL, NULL, &error);
4462 mono_error_cleanup (&error); /* FIXME don't swallow the error */
4466 if (!filter_method_init) {
4467 filter_method = g_getenv ("INTERP_FILTER_METHOD");
4468 filter_method_init = TRUE;
4470 gboolean filter = FALSE;
4471 if (filter_method) {
4472 const char *name = filter_method;
4474 if ((strchr (name, '.') > name) || strchr (name, ':')) {
4475 MonoMethodDesc *desc = mono_method_desc_new (name, TRUE);
4476 filter = mono_method_desc_full_match (desc, method);
4477 mono_method_desc_free (desc);
4479 filter = strcmp (method->name, name) == 0;
4481 } else { // no filter
4484 if (strncmp (method->name, "test_", 5) == 0 && filter) {
4485 MonoError interp_error;
4486 MonoObject *exc = NULL;
4488 result_obj = interp_mono_runtime_invoke (method, NULL, NULL, &exc, &interp_error);
4489 if (!mono_error_ok (&interp_error)) {
4491 g_print ("Test '%s' execution failed.\n", method->name);
4492 } else if (exc != NULL) {
4493 g_print ("Exception in Test '%s' occured:\n", method->name);
4494 mono_object_describe (exc);
4498 result = *(gint32 *) mono_object_unbox (result_obj);
4499 expected = atoi (method->name + 5); // FIXME: oh no.
4502 if (result != expected) {
4504 g_print ("Test '%s' failed result (got %d, expected %d).\n", method->name, result, expected);
4509 g_timer_stop (timer);
4510 elapsed = g_timer_elapsed (timer, NULL);
4511 if (failed > 0 || cfailed > 0){
4512 g_print ("Results: total tests: %d, failed: %d, cfailed: %d (pass: %.2f%%)\n",
4513 run, failed, cfailed, 100.0*(run-failed-cfailed)/run);
4515 g_print ("Results: total tests: %d, all pass \n", run);
4518 g_print ("Elapsed time: %f secs (%f, %f)\n\n", elapsed,
4519 elapsed - transform_time, transform_time);
4520 *total += failed + cfailed;
4524 interp_regression (MonoImage *image, int verbose, int *total_run)
4527 GTimer *timer = g_timer_new ();
4528 MonoDomain *domain = mono_domain_get ();
4532 /* load the metadata */
4533 for (i = 0; i < mono_image_get_table_rows (image, MONO_TABLE_METHOD); ++i) {
4535 method = mono_get_method_checked (image, MONO_TOKEN_METHOD_DEF | (i + 1), NULL, NULL, &error);
4537 mono_error_cleanup (&error);
4540 mono_class_init (method->klass);
4545 interp_regression_step (image, verbose, total_run, &total, timer, domain);
4547 g_timer_destroy (timer);
4552 interp_regression_list (int verbose, int count, char *images [])
4554 int i, total, total_run, run;
4556 total_run = total = 0;
4557 for (i = 0; i < count; ++i) {
4558 MonoAssembly *ass = mono_assembly_open (images [i], NULL);
4560 g_warning ("failed to load assembly: %s", images [i]);
4563 total += interp_regression (mono_assembly_get_image (ass), verbose, &run);
4567 g_print ("Overall results: tests: %d, failed: %d (pass: %.2f%%)\n", total_run, total, 100.0*(total_run-total)/total_run);
4569 g_print ("Overall results: tests: %d, 100%% pass\n", total_run);