2 * PLEASE NOTE: This is a research prototype.
5 * interp.c: Interpreter for CIL byte codes
8 * Paolo Molaro (lupus@ximian.com)
9 * Miguel de Icaza (miguel@ximian.com)
10 * Dietmar Maurer (dietmar@ximian.com)
12 * (C) 2001, 2002 Ximian, Inc.
27 #include <mono/utils/gc_wrapper.h>
33 # define alloca __builtin_alloca
37 /* trim excessive headers */
38 #include <mono/metadata/image.h>
39 #include <mono/metadata/assembly.h>
40 #include <mono/metadata/cil-coff.h>
41 #include <mono/metadata/mono-endian.h>
42 #include <mono/metadata/tabledefs.h>
43 #include <mono/metadata/tokentype.h>
44 #include <mono/metadata/loader.h>
45 #include <mono/metadata/threads.h>
46 #include <mono/metadata/threadpool.h>
47 #include <mono/metadata/profiler-private.h>
48 #include <mono/metadata/appdomain.h>
49 #include <mono/metadata/reflection.h>
50 #include <mono/metadata/reflection-internals.h>
51 #include <mono/metadata/exception.h>
52 #include <mono/metadata/verify.h>
53 #include <mono/metadata/opcodes.h>
54 #include <mono/metadata/debug-helpers.h>
55 #include <mono/metadata/mono-config.h>
56 #include <mono/metadata/marshal.h>
57 #include <mono/metadata/environment.h>
58 #include <mono/metadata/mono-debug.h>
64 #include <mono/mini/mini.h>
67 /* Mingw 2.1 doesnt need this any more, but leave it in for now for older versions */
70 #define finite _finite
74 #define finite isfinite
78 #define INIT_FRAME(frame,parent_frame,method_args,method_retval,domain,mono_method,error) \
80 (frame)->parent = (parent_frame); \
81 (frame)->stack_args = (method_args); \
82 (frame)->retval = (method_retval); \
83 (frame)->runtime_method = mono_interp_get_runtime_method ((domain), (mono_method), (error)); \
86 (frame)->invoke_trap = 0; \
89 void ves_exec_method (MonoInvocation *frame);
91 static char* dump_stack (stackval *stack, stackval *sp);
92 static char* dump_frame (MonoInvocation *inv);
93 static MonoArray *get_trace_ips (MonoDomain *domain, MonoInvocation *top);
94 static void ves_exec_method_with_context (MonoInvocation *frame, ThreadContext *context);
96 typedef void (*ICallMethod) (MonoInvocation *frame);
98 static guint32 die_on_exception = 0;
99 static MonoNativeTlsKey thread_context_id;
101 static char* dump_args (MonoInvocation *inv);
103 #define DEBUG_INTERP 0
106 int mono_interp_traceopt = 2;
107 /* If true, then we output the opcodes as we interpret them */
108 static int global_tracing = 1;
110 static int debug_indent_level = 0;
112 static int break_on_method = 0;
113 static int nested_trace = 0;
114 static GList *db_methods = NULL;
121 for (h = 0; h < debug_indent_level; h++)
126 db_match_method (gpointer data, gpointer user_data)
128 MonoMethod *m = (MonoMethod*)user_data;
129 MonoMethodDesc *desc = data;
131 if (mono_method_desc_full_match (desc, m))
135 static void debug_enter (MonoInvocation *frame, int *tracing)
138 g_list_foreach (db_methods, db_match_method, (gpointer)frame->runtime_method->method);
140 *tracing = nested_trace ? (global_tracing = 2, 3) : 2;
144 MonoMethod *method = frame->runtime_method->method;
145 char *mn, *args = dump_args (frame);
146 debug_indent_level++;
148 mn = mono_method_full_name (method, FALSE);
149 g_print ("(%p) Entering %s (", mono_thread_internal_current (), mn);
151 g_print ("%s)\n", args);
154 if (mono_profiler_events & MONO_PROFILE_ENTER_LEAVE)
155 mono_profiler_method_enter (frame->runtime_method->method);
159 #define DEBUG_LEAVE() \
162 args = dump_retval (frame); \
164 mn = mono_method_full_name (frame->runtime_method->method, FALSE); \
165 g_print ("(%p) Leaving %s", mono_thread_internal_current (), mn); \
167 g_print (" => %s\n", args); \
169 debug_indent_level--; \
170 if (tracing == 3) global_tracing = 0; \
172 if (mono_profiler_events & MONO_PROFILE_ENTER_LEAVE) \
173 mono_profiler_method_leave (frame->runtime_method->method);
177 int mono_interp_traceopt = 0;
178 static void debug_enter (MonoInvocation *frame, int *tracing)
181 #define DEBUG_LEAVE()
186 interp_ex_handler (MonoException *ex) {
188 ThreadContext *context = mono_native_tls_get_value (thread_context_id);
192 stack_trace = dump_frame (context->current_frame);
193 ex->stack_trace = mono_string_new (mono_domain_get(), stack_trace);
194 g_free (stack_trace);
195 if (context->current_env == NULL || strcmp(ex->object.vtable->klass->name, "ExecutionEngineException") == 0) {
196 char *strace = mono_string_to_utf8_checked (ex->stack_trace, &error);
197 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
198 fprintf(stderr, "Nothing can catch this exception: ");
199 fprintf(stderr, "%s", ex->object.vtable->klass->name);
200 if (ex->message != NULL) {
201 char *m = mono_string_to_utf8_checked (ex->message, &error);
202 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
203 fprintf(stderr, ": %s", m);
206 fprintf(stderr, "\n%s\n", strace);
208 if (ex->inner_ex != NULL) {
209 ex = (MonoException *)ex->inner_ex;
210 fprintf(stderr, "Inner exception: %s", ex->object.vtable->klass->name);
211 if (ex->message != NULL) {
212 char *m = mono_string_to_utf8_checked (ex->message, &error);
213 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
214 fprintf(stderr, ": %s", m);
217 strace = mono_string_to_utf8_checked (ex->stack_trace, &error);
218 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
219 fprintf(stderr, "\n");
220 fprintf(stderr, "%s\n", strace);
223 /* wait for other threads to also collapse */
224 // Sleep(1000); // TODO: proper sleep
227 context->env_frame->ex = ex;
228 context->search_for_handler = 1;
229 longjmp (*context->current_env, 1);
233 ves_real_abort (int line, MonoMethod *mh,
234 const unsigned short *ip, stackval *stack, stackval *sp)
237 fprintf (stderr, "Execution aborted in method: %s::%s\n", mh->klass->name, mh->name);
238 fprintf (stderr, "Line=%d IP=0x%04lx, Aborted execution\n", line,
239 ip-(const unsigned short *)mono_method_get_header_checked (mh, &error)->code);
240 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
241 g_print ("0x%04x %02x\n",
242 ip-(const unsigned short *)mono_method_get_header_checked (mh, &error)->code, *ip);
243 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
245 printf ("\t[%ld] 0x%08x %0.5f\n", sp-stack, sp[-1].data.i, sp[-1].data.f);
248 #define ves_abort() \
250 ves_real_abort(__LINE__, frame->runtime_method->method, ip, frame->stack, sp); \
251 THROW_EX (mono_get_exception_execution_engine (NULL), ip); \
254 static mono_mutex_t runtime_method_lookup_section;
257 mono_interp_get_runtime_method (MonoDomain *domain, MonoMethod *method, MonoError *error)
260 mono_error_init (error);
262 mono_os_mutex_lock (&runtime_method_lookup_section);
263 if ((rtm = mono_internal_hash_table_lookup (&domain->jit_code_hash, method))) {
264 mono_os_mutex_unlock (&runtime_method_lookup_section);
267 rtm = mono_mempool_alloc (domain->mp, sizeof (RuntimeMethod));
268 memset (rtm, 0, sizeof (*rtm));
269 rtm->method = method;
270 rtm->param_count = mono_method_signature (method)->param_count;
271 rtm->hasthis = mono_method_signature (method)->hasthis;
272 rtm->valuetype = method->klass->valuetype;
273 mono_internal_hash_table_insert (&domain->jit_code_hash, method, rtm);
274 mono_os_mutex_unlock (&runtime_method_lookup_section);
280 interp_create_trampoline (MonoDomain *domain, MonoMethod *method, MonoError *error)
282 if (method->iflags & METHOD_IMPL_ATTRIBUTE_SYNCHRONIZED)
283 method = mono_marshal_get_synchronized_wrapper (method);
284 return mono_interp_get_runtime_method (domain, method, error);
287 static inline RuntimeMethod*
288 get_virtual_method (MonoDomain *domain, RuntimeMethod *runtime_method, MonoObject *obj)
290 MonoMethod *m = runtime_method->method;
293 if ((m->flags & METHOD_ATTRIBUTE_FINAL) || !(m->flags & METHOD_ATTRIBUTE_VIRTUAL)) {
294 RuntimeMethod *ret = NULL;
295 if (mono_object_is_transparent_proxy (obj)) {
296 ret = mono_interp_get_runtime_method (domain, mono_marshal_get_remoting_invoke (m), &error);
297 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
298 } else if (m->iflags & METHOD_IMPL_ATTRIBUTE_SYNCHRONIZED) {
299 ret = mono_interp_get_runtime_method (domain, mono_marshal_get_synchronized_wrapper (m), &error);
300 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
302 ret = runtime_method;
307 int slot = mono_method_get_vtable_slot (m);
308 if (mono_class_is_interface (m->klass)) {
309 g_assert (obj->vtable->klass != m->klass);
310 /* TODO: interface offset lookup is slow, go through IMT instead */
311 slot += mono_class_interface_offset (obj->vtable->klass, m->klass);
313 MonoMethod *virtual_method = obj->vtable->klass->vtable [slot];
314 RuntimeMethod *virtual_runtime_method = mono_interp_get_runtime_method (domain, virtual_method, &error);
315 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
316 return virtual_runtime_method;
320 stackval_from_data (MonoType *type, stackval *result, char *data, gboolean pinvoke)
323 switch (type->type) {
324 case MONO_TYPE_OBJECT:
325 case MONO_TYPE_CLASS:
326 case MONO_TYPE_STRING:
327 case MONO_TYPE_ARRAY:
328 case MONO_TYPE_SZARRAY:
333 result->data.p = *(gpointer*)data;
336 switch (type->type) {
340 result->data.i = *(gint8*)data;
343 case MONO_TYPE_BOOLEAN:
344 result->data.i = *(guint8*)data;
347 result->data.i = *(gint16*)data;
351 result->data.i = *(guint16*)data;
354 result->data.i = *(gint32*)data;
358 result->data.nati = *(mono_i*)data;
361 result->data.p = *(gpointer*)data;
364 result->data.i = *(guint32*)data;
367 result->data.f = *(float*)data;
371 result->data.l = *(gint64*)data;
374 result->data.f = *(double*)data;
376 case MONO_TYPE_STRING:
377 case MONO_TYPE_SZARRAY:
378 case MONO_TYPE_CLASS:
379 case MONO_TYPE_OBJECT:
380 case MONO_TYPE_ARRAY:
381 result->data.p = *(gpointer*)data;
383 case MONO_TYPE_VALUETYPE:
384 if (type->data.klass->enumtype) {
385 stackval_from_data (mono_class_enum_basetype (type->data.klass), result, data, pinvoke);
391 size = mono_class_native_size (type->data.klass, NULL);
393 size = mono_class_value_size (type->data.klass, NULL);
394 memcpy (result->data.vt, data, size);
398 g_warning ("got type 0x%02x", type->type);
399 g_assert_not_reached ();
404 stackval_to_data (MonoType *type, stackval *val, char *data, gboolean pinvoke)
407 gpointer *p = (gpointer*)data;
411 /* printf ("TODAT0 %p\n", data); */
412 switch (type->type) {
415 guint8 *p = (guint8*)data;
419 case MONO_TYPE_BOOLEAN: {
420 guint8 *p = (guint8*)data;
421 *p = (val->data.i != 0);
426 case MONO_TYPE_CHAR: {
427 guint16 *p = (guint16*)data;
432 mono_i *p = (mono_i*)data;
433 /* In theory the value used by stloc should match the local var type
434 but in practice it sometimes doesn't (a int32 gets dup'd and stloc'd into
435 a native int - both by csc and mcs). Not sure what to do about sign extension
436 as it is outside the spec... doing the obvious */
437 *p = (mono_i)val->data.nati;
441 mono_u *p = (mono_u*)data;
443 *p = (mono_u)val->data.nati;
448 gint32 *p = (gint32*)data;
454 gint64 *p = (gint64*)data;
459 float *p = (float*)data;
464 double *p = (double*)data;
468 case MONO_TYPE_STRING:
469 case MONO_TYPE_SZARRAY:
470 case MONO_TYPE_CLASS:
471 case MONO_TYPE_OBJECT:
472 case MONO_TYPE_ARRAY:
473 case MONO_TYPE_PTR: {
474 gpointer *p = (gpointer*)data;
478 case MONO_TYPE_VALUETYPE:
479 if (type->data.klass->enumtype) {
480 stackval_to_data (mono_class_enum_basetype (type->data.klass), val, data, pinvoke);
486 size = mono_class_native_size (type->data.klass, NULL);
488 size = mono_class_value_size (type->data.klass, NULL);
490 memcpy (data, val->data.p, size);
493 case MONO_TYPE_GENERICINST:
494 stackval_to_data (&type->data.generic_class->container_class->byval_arg, val, data, pinvoke);
497 g_warning ("got type %x", type->type);
498 g_assert_not_reached ();
503 fill_in_trace (MonoException *exception, MonoInvocation *frame)
505 char *stack_trace = dump_frame (frame);
506 MonoDomain *domain = mono_domain_get();
507 (exception)->stack_trace = mono_string_new (domain, stack_trace);
508 (exception)->trace_ips = get_trace_ips (domain, frame);
509 g_free (stack_trace);
512 #define FILL_IN_TRACE(exception, frame) fill_in_trace(exception, frame)
514 #define THROW_EX(exception,ex_ip) \
516 frame->ip = (ex_ip); \
517 frame->ex = (MonoException*)(exception); \
518 FILL_IN_TRACE(frame->ex, frame); \
519 goto handle_exception; \
523 ves_array_create (MonoDomain *domain, MonoClass *klass, MonoMethodSignature *sig, stackval *values)
526 intptr_t *lower_bounds;
531 lengths = alloca (sizeof (uintptr_t) * klass->rank * 2);
532 for (i = 0; i < sig->param_count; ++i) {
533 lengths [i] = values->data.i;
536 if (klass->rank == sig->param_count) {
537 /* Only lengths provided. */
540 /* lower bounds are first. */
541 lower_bounds = (intptr_t *) lengths;
542 lengths += klass->rank;
544 obj = (MonoObject*) mono_array_new_full_checked (domain, klass, lengths, lower_bounds, &error);
545 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
550 ves_array_set (MonoInvocation *frame)
552 stackval *sp = frame->stack_args;
556 gint32 i, t, pos, esize;
560 o = frame->stack_args->data.p;
562 ac = o->vtable->klass;
564 g_assert (ac->rank >= 1);
567 if (ao->bounds != NULL) {
568 pos -= ao->bounds [0].lower_bound;
569 for (i = 1; i < ac->rank; i++) {
570 if ((t = sp [i].data.i - ao->bounds [i].lower_bound) >=
571 ao->bounds [i].length) {
572 frame->ex = mono_get_exception_index_out_of_range ();
573 FILL_IN_TRACE(frame->ex, frame);
576 pos = pos*ao->bounds [i].length + sp [i].data.i -
577 ao->bounds [i].lower_bound;
579 } else if (pos >= ao->max_length) {
580 frame->ex = mono_get_exception_index_out_of_range ();
581 FILL_IN_TRACE(frame->ex, frame);
585 if (sp [ac->rank].data.p && !mono_object_class (o)->element_class->valuetype) {
587 MonoObject *isinst = mono_object_isinst_checked (sp [ac->rank].data.p, mono_object_class (o)->element_class, &error);
588 mono_error_cleanup (&error);
590 frame->ex = mono_get_exception_array_type_mismatch ();
591 FILL_IN_TRACE (frame->ex, frame);
596 esize = mono_array_element_size (ac);
597 ea = mono_array_addr_with_size (ao, esize, pos);
599 mt = mono_method_signature (frame->runtime_method->method)->params [ac->rank];
600 stackval_to_data (mt, &sp [ac->rank], ea, FALSE);
604 ves_array_get (MonoInvocation *frame)
606 stackval *sp = frame->stack_args;
610 gint32 i, t, pos, esize;
614 o = frame->stack_args->data.p;
616 ac = o->vtable->klass;
618 g_assert (ac->rank >= 1);
621 if (ao->bounds != NULL) {
622 pos -= ao->bounds [0].lower_bound;
623 for (i = 1; i < ac->rank; i++) {
624 if ((t = sp [i].data.i - ao->bounds [i].lower_bound) >=
625 ao->bounds [i].length) {
626 frame->ex = mono_get_exception_index_out_of_range ();
627 FILL_IN_TRACE(frame->ex, frame);
631 pos = pos*ao->bounds [i].length + sp [i].data.i -
632 ao->bounds [i].lower_bound;
634 } else if (pos >= ao->max_length) {
635 frame->ex = mono_get_exception_index_out_of_range ();
636 FILL_IN_TRACE(frame->ex, frame);
640 esize = mono_array_element_size (ac);
641 ea = mono_array_addr_with_size (ao, esize, pos);
643 mt = mono_method_signature (frame->runtime_method->method)->ret;
644 stackval_from_data (mt, frame->retval, ea, FALSE);
648 ves_array_element_address (MonoInvocation *frame)
650 stackval *sp = frame->stack_args;
654 gint32 i, t, pos, esize;
657 o = frame->stack_args->data.p;
659 ac = o->vtable->klass;
661 g_assert (ac->rank >= 1);
664 if (ao->bounds != NULL) {
665 pos -= ao->bounds [0].lower_bound;
666 for (i = 1; i < ac->rank; i++) {
667 if ((t = sp [i].data.i - ao->bounds [i].lower_bound) >=
668 ao->bounds [i].length) {
669 frame->ex = mono_get_exception_index_out_of_range ();
670 FILL_IN_TRACE(frame->ex, frame);
673 pos = pos*ao->bounds [i].length + sp [i].data.i -
674 ao->bounds [i].lower_bound;
676 } else if (pos >= ao->max_length) {
677 frame->ex = mono_get_exception_index_out_of_range ();
678 FILL_IN_TRACE(frame->ex, frame);
682 esize = mono_array_element_size (ac);
683 ea = mono_array_addr_with_size (ao, esize, pos);
685 frame->retval->data.p = ea;
689 interp_walk_stack (MonoStackWalk func, gboolean do_il_offset, gpointer user_data)
691 ThreadContext *context = mono_native_tls_get_value (thread_context_id);
692 MonoInvocation *frame;
694 MonoMethodHeader *hd;
697 if (!context) return;
699 frame = context->current_frame;
702 gboolean managed = FALSE;
703 MonoMethod *method = frame->runtime_method->method;
704 if (!method || (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) || (method->iflags & (METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL | METHOD_IMPL_ATTRIBUTE_RUNTIME)))
707 hd = mono_method_get_header_checked (method, &error);
708 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
709 il_offset = frame->ip - (const unsigned short *)hd->code;
710 if (!method->wrapper_type)
713 if (func (method, -1, il_offset, managed, user_data))
715 frame = frame->parent;
719 static MonoPIFunc mono_interp_enter_icall_trampoline = NULL;
721 struct _MethodArguments {
729 typedef struct _MethodArguments MethodArguments;
731 // TODO: this function is also arch dependent (register width).
732 static MethodArguments* build_args_from_sig (MonoMethodSignature *sig, MonoInvocation *frame)
734 // TODO: don't malloc this data structure.
735 MethodArguments *margs = g_malloc0 (sizeof (MethodArguments));
740 for (int i = 0; i < sig->param_count; i++) {
741 guint32 ptype = sig->params [i]->byref ? MONO_TYPE_PTR : sig->params [i]->type;
743 case MONO_TYPE_BOOLEAN:
754 case MONO_TYPE_SZARRAY:
755 case MONO_TYPE_CLASS:
756 case MONO_TYPE_OBJECT:
757 case MONO_TYPE_STRING:
762 g_error ("build_args_from_sig: not implemented yet (1): 0x%x\n", ptype);
767 margs->iargs = g_malloc0 (sizeof (gpointer) * margs->ilen);
770 g_error ("build_args_from_sig: TODO, more than two iregs: %d\n", margs->ilen);
773 g_error ("build_args_from_sig: TODO, allocate floats: %d\n", margs->flen);
779 margs->iargs [0] = frame->stack_args->data.p;
783 for (int i = 0; i < sig->param_count; i++) {
784 guint32 ptype = sig->params [i]->byref ? MONO_TYPE_PTR : sig->params [i]->type;
786 case MONO_TYPE_BOOLEAN:
797 case MONO_TYPE_SZARRAY:
798 case MONO_TYPE_CLASS:
799 case MONO_TYPE_OBJECT:
800 case MONO_TYPE_STRING:
802 margs->iargs [int_i] = frame->stack_args [i].data.p;
804 g_print ("build_args_from_sig: margs->iargs[%d]: %p (frame @ %d)\n", int_i, margs->iargs[int_i], i);
809 g_error ("build_args_from_sig: not implemented yet (2): 0x%x\n", ptype);
813 if (sig->ret->type != MONO_TYPE_VOID) {
814 margs->retval = &(frame->retval->data.p);
816 margs->retval = NULL;
823 ves_pinvoke_method (MonoInvocation *frame, MonoMethodSignature *sig, MonoFuncV addr, gboolean string_ctor, ThreadContext *context)
826 MonoInvocation *old_frame = context->current_frame;
827 MonoInvocation *old_env_frame = context->env_frame;
828 jmp_buf *old_env = context->current_env;
831 context->current_frame = old_frame;
832 context->env_frame = old_env_frame;
833 context->current_env = old_env;
834 context->managed_code = 1;
839 context->env_frame = frame;
840 context->current_env = &env;
842 g_assert (!frame->runtime_method);
843 if (!mono_interp_enter_icall_trampoline) {
845 mono_interp_enter_icall_trampoline = mono_arch_get_enter_icall_trampoline (&info);
847 // mono_tramp_info_register (info, NULL);
850 MethodArguments *margs = build_args_from_sig (sig, frame);
852 g_print ("ICALL: mono_interp_enter_icall_trampoline = %p, addr = %p\n", mono_interp_enter_icall_trampoline, addr);
853 g_print ("margs(out): ilen=%d, flen=%d\n", margs->ilen, margs->flen);
856 context->current_frame = frame;
857 context->managed_code = 0;
859 mono_interp_enter_icall_trampoline (addr, margs);
861 context->managed_code = 1;
862 /* domain can only be changed by native code */
863 context->domain = mono_domain_get ();
865 if (*mono_thread_interruption_request_flag ())
866 mono_thread_interruption_checkpoint ();
868 if (!MONO_TYPE_ISSTRUCT (sig->ret))
869 stackval_from_data (sig->ret, frame->retval, (char*)&frame->retval->data.p, sig->pinvoke);
871 context->current_frame = old_frame;
872 context->env_frame = old_env_frame;
873 context->current_env = old_env;
875 g_free (margs->iargs);
876 g_free (margs->fargs);
881 interp_delegate_ctor (MonoDomain *domain, MonoObject *this, MonoObject *target, RuntimeMethod *runtime_method)
883 MonoDelegate *delegate = (MonoDelegate *)this;
886 delegate->method_info = mono_method_get_object_checked (domain, runtime_method->method, NULL, &error);
887 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
888 delegate->target = target;
890 if (target && mono_object_is_transparent_proxy (target)) {
891 MonoMethod *method = mono_marshal_get_remoting_invoke (runtime_method->method);
892 delegate->method_ptr = mono_interp_get_runtime_method (domain, method, &error);
893 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
895 delegate->method_ptr = runtime_method;
900 mono_interp_ftnptr_to_delegate (MonoClass *klass, gpointer ftn)
904 MonoDomain *domain = mono_domain_get ();
907 d = (MonoDelegate*)mono_object_new_checked (domain, klass, &error);
908 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
910 ji = mono_jit_info_table_find (domain, ftn);
912 mono_raise_exception (mono_get_exception_argument ("", "Function pointer was not created by a Delegate."));
914 /* FIXME: discard the wrapper and call the original method */
915 interp_delegate_ctor (domain, (MonoObject*)d, NULL, mono_interp_get_runtime_method (domain, ji->d.method, &error));
916 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
923 * runtime specifies that the implementation of the method is automatically
924 * provided by the runtime and is primarily used for the methods of delegates.
927 ves_runtime_method (MonoInvocation *frame, ThreadContext *context)
929 MonoMethod *method = frame->runtime_method->method;
930 const char *name = method->name;
931 MonoObject *obj = (MonoObject*) frame->stack_args->data.p;
932 MonoObject *isinst_obj;
935 mono_class_init (method->klass);
937 isinst_obj = mono_object_isinst_checked (obj, mono_defaults.multicastdelegate_class, &error);
938 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
939 if (obj && isinst_obj) {
940 if (*name == '.' && (strcmp (name, ".ctor") == 0)) {
941 interp_delegate_ctor (context->domain, obj, frame->stack_args [1].data.p, frame->stack_args[2].data.p);
946 isinst_obj = mono_object_isinst_checked (obj, mono_defaults.array_class, &error);
947 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
948 if (obj && isinst_obj) {
949 if (*name == 'S' && (strcmp (name, "Set") == 0)) {
950 ves_array_set (frame);
953 if (*name == 'G' && (strcmp (name, "Get") == 0)) {
954 ves_array_get (frame);
957 if (*name == 'A' && (strcmp (name, "Address") == 0)) {
958 ves_array_element_address (frame);
963 g_error ("Don't know how to exec runtime method %s.%s::%s",
964 method->klass->name_space, method->klass->name,
969 dump_stack (stackval *stack, stackval *sp)
972 GString *str = g_string_new ("");
975 return g_string_free (str, FALSE);
978 g_string_append_printf (str, "[%p (%lld)] ", s->data.l, s->data.l);
981 return g_string_free (str, FALSE);
985 dump_stackval (GString *str, stackval *s, MonoType *type)
987 switch (type->type) {
995 case MONO_TYPE_BOOLEAN:
996 g_string_append_printf (str, "[%d] ", s->data.i);
998 case MONO_TYPE_STRING:
999 case MONO_TYPE_SZARRAY:
1000 case MONO_TYPE_CLASS:
1001 case MONO_TYPE_OBJECT:
1002 case MONO_TYPE_ARRAY:
1006 g_string_append_printf (str, "[%p] ", s->data.p);
1008 case MONO_TYPE_VALUETYPE:
1009 if (type->data.klass->enumtype)
1010 g_string_append_printf (str, "[%d] ", s->data.i);
1012 g_string_append_printf (str, "[vt:%p] ", s->data.p);
1016 g_string_append_printf (str, "[%g] ", s->data.f);
1021 GString *res = g_string_new ("");
1022 mono_type_get_desc (res, type, TRUE);
1023 g_string_append_printf (str, "[{%s} %lld/0x%0llx] ", res->str, s->data.l, s->data.l);
1024 g_string_free (res, TRUE);
1031 dump_args (MonoInvocation *inv)
1033 GString *str = g_string_new ("");
1035 MonoMethodSignature *signature = mono_method_signature (inv->runtime_method->method);
1037 if (signature->param_count == 0 && !signature->hasthis)
1038 return g_string_free (str, FALSE);
1040 if (signature->hasthis) {
1041 MonoMethod *method = inv->runtime_method->method;
1042 dump_stackval (str, inv->stack_args, &method->klass->byval_arg);
1045 for (i = 0; i < signature->param_count; ++i)
1046 dump_stackval (str, inv->stack_args + (!!signature->hasthis) + i, signature->params [i]);
1048 return g_string_free (str, FALSE);
1052 dump_retval (MonoInvocation *inv)
1054 GString *str = g_string_new ("");
1055 MonoType *ret = mono_method_signature (inv->runtime_method->method)->ret;
1057 if (ret->type != MONO_TYPE_VOID)
1058 dump_stackval (str, inv->retval, ret);
1060 return g_string_free (str, FALSE);
1064 dump_frame (MonoInvocation *inv)
1066 GString *str = g_string_new ("");
1071 for (i = 0; inv; inv = inv->parent) {
1072 if (inv->runtime_method != NULL) {
1073 MonoMethod *method = inv->runtime_method->method;
1077 const char * opname = "";
1079 gchar *source = NULL;
1083 if ((method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) == 0 &&
1084 (method->iflags & METHOD_IMPL_ATTRIBUTE_RUNTIME) == 0) {
1085 MonoMethodHeader *hd = mono_method_get_header_checked (method, &error);
1086 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
1090 opname = mono_interp_opname [*inv->ip];
1091 codep = inv->ip - inv->runtime_method->code;
1092 source = g_strdup_printf ("%s:%d // (TODO: proper stacktrace)", method->name, codep);
1097 MonoDebugSourceLocation *minfo = mono_debug_lookup_method (method);
1098 source = mono_debug_method_lookup_location (minfo, codep);
1102 args = dump_args (inv);
1103 name = mono_method_full_name (method, TRUE);
1105 g_string_append_printf (str, "#%d: 0x%05x %-10s in %s (%s) at %s\n", i, codep, opname, name, args, source);
1107 g_string_append_printf (str, "#%d: 0x%05x %-10s in %s (%s)\n", i, codep, opname, name, args);
1114 return g_string_free (str, FALSE);
1118 get_trace_ips (MonoDomain *domain, MonoInvocation *top)
1122 MonoInvocation *inv;
1125 for (i = 0, inv = top; inv; inv = inv->parent)
1126 if (inv->runtime_method != NULL)
1129 res = mono_array_new_checked (domain, mono_defaults.int_class, 2 * i, &error);
1130 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
1132 for (i = 0, inv = top; inv; inv = inv->parent)
1133 if (inv->runtime_method != NULL) {
1134 mono_array_set (res, gpointer, i, inv->runtime_method);
1136 mono_array_set (res, gpointer, i, (gpointer)inv->ip);
1144 #define MYGUINT64_MAX 18446744073709551615ULL
1145 #define MYGINT64_MAX 9223372036854775807LL
1146 #define MYGINT64_MIN (-MYGINT64_MAX -1LL)
1148 #define MYGUINT32_MAX 4294967295U
1149 #define MYGINT32_MAX 2147483647
1150 #define MYGINT32_MIN (-MYGINT32_MAX -1)
1152 #define CHECK_ADD_OVERFLOW(a,b) \
1153 (gint32)(b) >= 0 ? (gint32)(MYGINT32_MAX) - (gint32)(b) < (gint32)(a) ? -1 : 0 \
1154 : (gint32)(MYGINT32_MIN) - (gint32)(b) > (gint32)(a) ? +1 : 0
1156 #define CHECK_SUB_OVERFLOW(a,b) \
1157 (gint32)(b) < 0 ? (gint32)(MYGINT32_MAX) + (gint32)(b) < (gint32)(a) ? -1 : 0 \
1158 : (gint32)(MYGINT32_MIN) + (gint32)(b) > (gint32)(a) ? +1 : 0
1160 #define CHECK_ADD_OVERFLOW_UN(a,b) \
1161 (guint32)(MYGUINT32_MAX) - (guint32)(b) < (guint32)(a) ? -1 : 0
1163 #define CHECK_SUB_OVERFLOW_UN(a,b) \
1164 (guint32)(a) < (guint32)(b) ? -1 : 0
1166 #define CHECK_ADD_OVERFLOW64(a,b) \
1167 (gint64)(b) >= 0 ? (gint64)(MYGINT64_MAX) - (gint64)(b) < (gint64)(a) ? -1 : 0 \
1168 : (gint64)(MYGINT64_MIN) - (gint64)(b) > (gint64)(a) ? +1 : 0
1170 #define CHECK_SUB_OVERFLOW64(a,b) \
1171 (gint64)(b) < 0 ? (gint64)(MYGINT64_MAX) + (gint64)(b) < (gint64)(a) ? -1 : 0 \
1172 : (gint64)(MYGINT64_MIN) + (gint64)(b) > (gint64)(a) ? +1 : 0
1174 #define CHECK_ADD_OVERFLOW64_UN(a,b) \
1175 (guint64)(MYGUINT64_MAX) - (guint64)(b) < (guint64)(a) ? -1 : 0
1177 #define CHECK_SUB_OVERFLOW64_UN(a,b) \
1178 (guint64)(a) < (guint64)(b) ? -1 : 0
1180 #if SIZEOF_VOID_P == 4
1181 #define CHECK_ADD_OVERFLOW_NAT(a,b) CHECK_ADD_OVERFLOW(a,b)
1182 #define CHECK_ADD_OVERFLOW_NAT_UN(a,b) CHECK_ADD_OVERFLOW_UN(a,b)
1184 #define CHECK_ADD_OVERFLOW_NAT(a,b) CHECK_ADD_OVERFLOW64(a,b)
1185 #define CHECK_ADD_OVERFLOW_NAT_UN(a,b) CHECK_ADD_OVERFLOW64_UN(a,b)
1188 /* Resolves to TRUE if the operands would overflow */
1189 #define CHECK_MUL_OVERFLOW(a,b) \
1190 ((gint32)(a) == 0) || ((gint32)(b) == 0) ? 0 : \
1191 (((gint32)(a) > 0) && ((gint32)(b) == -1)) ? FALSE : \
1192 (((gint32)(a) < 0) && ((gint32)(b) == -1)) ? (a == - MYGINT32_MAX) : \
1193 (((gint32)(a) > 0) && ((gint32)(b) > 0)) ? (gint32)(a) > ((MYGINT32_MAX) / (gint32)(b)) : \
1194 (((gint32)(a) > 0) && ((gint32)(b) < 0)) ? (gint32)(a) > ((MYGINT32_MIN) / (gint32)(b)) : \
1195 (((gint32)(a) < 0) && ((gint32)(b) > 0)) ? (gint32)(a) < ((MYGINT32_MIN) / (gint32)(b)) : \
1196 (gint32)(a) < ((MYGINT32_MAX) / (gint32)(b))
1198 #define CHECK_MUL_OVERFLOW_UN(a,b) \
1199 ((guint32)(a) == 0) || ((guint32)(b) == 0) ? 0 : \
1200 (guint32)(b) > ((MYGUINT32_MAX) / (guint32)(a))
1202 #define CHECK_MUL_OVERFLOW64(a,b) \
1203 ((gint64)(a) == 0) || ((gint64)(b) == 0) ? 0 : \
1204 (((gint64)(a) > 0) && ((gint64)(b) == -1)) ? FALSE : \
1205 (((gint64)(a) < 0) && ((gint64)(b) == -1)) ? (a == - MYGINT64_MAX) : \
1206 (((gint64)(a) > 0) && ((gint64)(b) > 0)) ? (gint64)(a) > ((MYGINT64_MAX) / (gint64)(b)) : \
1207 (((gint64)(a) > 0) && ((gint64)(b) < 0)) ? (gint64)(a) > ((MYGINT64_MIN) / (gint64)(b)) : \
1208 (((gint64)(a) < 0) && ((gint64)(b) > 0)) ? (gint64)(a) < ((MYGINT64_MIN) / (gint64)(b)) : \
1209 (gint64)(a) < ((MYGINT64_MAX) / (gint64)(b))
1211 #define CHECK_MUL_OVERFLOW64_UN(a,b) \
1212 ((guint64)(a) == 0) || ((guint64)(b) == 0) ? 0 : \
1213 (guint64)(b) > ((MYGUINT64_MAX) / (guint64)(a))
1215 #if SIZEOF_VOID_P == 4
1216 #define CHECK_MUL_OVERFLOW_NAT(a,b) CHECK_MUL_OVERFLOW(a,b)
1217 #define CHECK_MUL_OVERFLOW_NAT_UN(a,b) CHECK_MUL_OVERFLOW_UN(a,b)
1219 #define CHECK_MUL_OVERFLOW_NAT(a,b) CHECK_MUL_OVERFLOW64(a,b)
1220 #define CHECK_MUL_OVERFLOW_NAT_UN(a,b) CHECK_MUL_OVERFLOW64_UN(a,b)
1224 interp_mono_runtime_invoke (MonoMethod *method, void *obj, void **params, MonoObject **exc, MonoError *error)
1226 MonoInvocation frame;
1227 ThreadContext * volatile context = mono_native_tls_get_value (thread_context_id);
1228 MonoObject *retval = NULL;
1229 MonoMethodSignature *sig = mono_method_signature (method);
1230 MonoClass *klass = mono_class_from_mono_type (sig->ret);
1231 int i, type, isobject = 0;
1234 stackval *args = alloca (sizeof (stackval) * (sig->param_count + !!sig->hasthis));
1235 ThreadContext context_struct;
1236 MonoInvocation *old_frame = NULL;
1239 mono_error_init (error);
1244 if (context != &context_struct) {
1245 context->domain = mono_domain_get ();
1246 context->current_frame = old_frame;
1247 context->managed_code = 0;
1249 mono_native_tls_set_value (thread_context_id, NULL);
1251 *exc = (MonoObject *)frame.ex;
1255 if (context == NULL) {
1256 context = &context_struct;
1257 context_struct.base_frame = &frame;
1258 context_struct.current_frame = NULL;
1259 context_struct.env_frame = &frame;
1260 context_struct.current_env = &env;
1261 context_struct.search_for_handler = 0;
1262 context_struct.managed_code = 0;
1263 mono_native_tls_set_value (thread_context_id, context);
1266 old_frame = context->current_frame;
1268 context->domain = mono_domain_get ();
1270 switch (sig->ret->type) {
1271 case MONO_TYPE_VOID:
1273 case MONO_TYPE_STRING:
1274 case MONO_TYPE_OBJECT:
1275 case MONO_TYPE_CLASS:
1276 case MONO_TYPE_ARRAY:
1277 case MONO_TYPE_SZARRAY:
1280 case MONO_TYPE_VALUETYPE:
1281 retval = mono_object_new_checked (context->domain, klass, error);
1282 ret = ((char*)retval) + sizeof (MonoObject);
1283 if (!sig->ret->data.klass->enumtype)
1284 result.data.vt = ret;
1287 retval = mono_object_new_checked (context->domain, klass, error);
1288 ret = ((char*)retval) + sizeof (MonoObject);
1293 args [0].data.p = obj;
1295 for (i = 0; i < sig->param_count; ++i) {
1296 int a_index = i + !!sig->hasthis;
1297 if (sig->params [i]->byref) {
1298 args [a_index].data.p = params [i];
1301 type = sig->params [i]->type;
1306 case MONO_TYPE_BOOLEAN:
1307 args [a_index].data.i = *(MonoBoolean*)params [i];
1311 case MONO_TYPE_CHAR:
1312 args [a_index].data.i = *(gint16*)params [i];
1314 #if SIZEOF_VOID_P == 4
1315 case MONO_TYPE_U: /* use VAL_POINTER? */
1320 args [a_index].data.i = *(gint32*)params [i];
1322 #if SIZEOF_VOID_P == 8
1328 args [a_index].data.l = *(gint64*)params [i];
1330 case MONO_TYPE_VALUETYPE:
1331 if (sig->params [i]->data.klass->enumtype) {
1332 type = mono_class_enum_basetype (sig->params [i]->data.klass)->type;
1335 args [a_index].data.p = params [i];
1338 case MONO_TYPE_STRING:
1339 case MONO_TYPE_CLASS:
1340 case MONO_TYPE_ARRAY:
1341 case MONO_TYPE_SZARRAY:
1342 case MONO_TYPE_OBJECT:
1343 args [a_index].data.p = params [i];
1346 g_error ("type 0x%x not handled in runtime invoke", sig->params [i]->type);
1350 if (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL)
1351 method = mono_marshal_get_native_wrapper (method, FALSE, FALSE);
1352 INIT_FRAME (&frame,context->current_frame,args,&result,mono_get_root_domain (),method,error);
1354 frame.invoke_trap = 1;
1355 context->managed_code = 1;
1356 ves_exec_method_with_context (&frame, context);
1357 context->managed_code = 0;
1358 if (context == &context_struct)
1359 mono_native_tls_set_value (thread_context_id, NULL);
1361 context->current_frame = old_frame;
1362 if (frame.ex != NULL) {
1364 *exc = (MonoObject*) frame.ex;
1367 if (context->current_env != NULL) {
1368 context->env_frame->ex = frame.ex;
1369 longjmp(*context->current_env, 1);
1372 printf("dropped exception...\n");
1374 if (sig->ret->type == MONO_TYPE_VOID && !method->string_ctor)
1376 if (isobject || method->string_ctor)
1377 return result.data.p;
1378 stackval_to_data (sig->ret, &result, ret, sig->pinvoke);
1383 do_icall (ThreadContext *context, int op, stackval *sp, gpointer ptr)
1385 MonoInvocation *old_frame = context->current_frame;
1386 MonoInvocation *old_env_frame = context->env_frame;
1387 jmp_buf *old_env = context->current_env;
1391 context->current_frame = old_frame;
1392 context->env_frame = old_env_frame;
1393 context->current_env = old_env;
1394 context->managed_code = 1;
1398 context->env_frame = context->current_frame;
1399 context->current_env = &env;
1400 context->managed_code = 0;
1403 case MINT_ICALL_V_V: {
1404 void (*func)() = ptr;
1408 case MINT_ICALL_V_P: {
1409 gpointer (*func)() = ptr;
1411 sp [-1].data.p = func ();
1414 case MINT_ICALL_P_V: {
1415 void (*func)(gpointer) = ptr;
1416 func (sp [-1].data.p);
1420 case MINT_ICALL_P_P: {
1421 gpointer (*func)(gpointer) = ptr;
1422 sp [-1].data.p = func (sp [-1].data.p);
1425 case MINT_ICALL_PP_V: {
1426 void (*func)(gpointer,gpointer) = ptr;
1428 func (sp [0].data.p, sp [1].data.p);
1431 case MINT_ICALL_PI_V: {
1432 void (*func)(gpointer,int) = ptr;
1434 func (sp [0].data.p, sp [1].data.i);
1437 case MINT_ICALL_PP_P: {
1438 gpointer (*func)(gpointer,gpointer) = ptr;
1440 sp [-1].data.p = func (sp [-1].data.p, sp [0].data.p);
1443 case MINT_ICALL_PI_P: {
1444 gpointer (*func)(gpointer,int) = ptr;
1446 sp [-1].data.p = func (sp [-1].data.p, sp [0].data.i);
1449 case MINT_ICALL_PPP_V: {
1450 void (*func)(gpointer,gpointer,gpointer) = ptr;
1452 func (sp [0].data.p, sp [1].data.p, sp [2].data.p);
1455 case MINT_ICALL_PPI_V: {
1456 void (*func)(gpointer,gpointer,int) = ptr;
1458 func (sp [0].data.p, sp [1].data.p, sp [2].data.i);
1462 g_assert_not_reached ();
1465 context->env_frame = old_env_frame;
1466 context->current_env = old_env;
1471 static mono_mutex_t create_method_pointer_mutex;
1473 static GHashTable *method_pointer_hash = NULL;
1476 interp_create_method_pointer (MonoMethod *method, MonoError *error)
1481 mono_os_mutex_lock (&create_method_pointer_mutex);
1482 if (!method_pointer_hash) {
1483 // FIXME: is registering method table as GC root really necessary?
1484 // MONO_GC_REGISTER_ROOT_FIXED (method_pointer_hash);
1485 method_pointer_hash = g_hash_table_new (NULL, NULL);
1487 addr = g_hash_table_lookup (method_pointer_hash, method);
1489 mono_os_mutex_unlock (&create_method_pointer_mutex);
1494 * If it is a static P/Invoke method, we can just return the pointer
1495 * to the method implementation.
1497 if (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL && ((MonoMethodPInvoke*) method)->addr) {
1498 ji = g_new0 (MonoJitInfo, 1);
1499 ji->d.method = method;
1501 ji->code_start = addr = ((MonoMethodPInvoke*) method)->addr;
1503 mono_jit_info_table_add (mono_get_root_domain (), ji);
1506 g_error ("FIXME: not available? figure out new API");
1508 addr = mono_arch_create_method_pointer (method);
1512 g_hash_table_insert (method_pointer_hash, method, addr);
1513 mono_os_mutex_unlock (&create_method_pointer_mutex);
1519 static int opcode_counts[512];
1521 #define COUNT_OP(op) opcode_counts[op]++
1523 #define COUNT_OP(op)
1527 #define DUMP_INSTR() \
1528 if (tracing > 1) { \
1530 if (sp > frame->stack) { \
1531 ins = dump_stack (frame->stack, sp); \
1533 ins = g_strdup (""); \
1537 char *mn = mono_method_full_name (frame->runtime_method->method, FALSE); \
1538 g_print ("(%p) %s -> ", mono_thread_internal_current (), mn); \
1540 mono_interp_dis_mintop(rtm->code, ip); \
1541 g_print ("\t%d:%s\n", vt_sp - vtalloc, ins); \
1545 #define DUMP_INSTR()
1549 #define USE_COMPUTED_GOTO 1
1551 #if USE_COMPUTED_GOTO
1552 #define MINT_IN_SWITCH(op) COUNT_OP(op); goto *in_labels[op];
1553 #define MINT_IN_CASE(x) LAB_ ## x:
1555 #define MINT_IN_BREAK if (tracing > 1) goto main_loop; else { COUNT_OP(*ip); goto *in_labels[*ip]; }
1557 #define MINT_IN_BREAK { COUNT_OP(*ip); goto *in_labels[*ip]; }
1559 #define MINT_IN_DEFAULT mint_default: if (0) goto mint_default; /* make gcc shut up */
1561 #define MINT_IN_SWITCH(op) switch (op)
1562 #define MINT_IN_CASE(x) case x:
1563 #define MINT_IN_BREAK break
1564 #define MINT_IN_DEFAULT default:
1568 * Defining this causes register allocation errors in some versions of gcc:
1569 * error: unable to find a register to spill in class `SIREG'
1571 /* #define MINT_USE_DEDICATED_IP_REG */
1574 ves_exec_method_with_context (MonoInvocation *frame, ThreadContext *context)
1576 MonoInvocation child_frame;
1577 GSList *finally_ips = NULL;
1578 const unsigned short *endfinally_ip = NULL;
1579 #if defined(__GNUC__) && defined (i386) && defined (MINT_USE_DEDICATED_IP_REG)
1580 register const unsigned short *ip asm ("%esi");
1582 register const unsigned short *ip;
1584 register stackval *sp;
1587 gint tracing = global_tracing;
1588 unsigned char *vtalloc;
1591 unsigned char *vt_sp;
1592 unsigned char *locals;
1594 MonoObject *o = NULL;
1596 #if USE_COMPUTED_GOTO
1597 static void *in_labels[] = {
1598 #define OPDEF(a,b,c,d) \
1600 #include "mintops.def"
1605 frame->ex_handler = NULL;
1607 context->current_frame = frame;
1610 debug_enter (frame, &tracing);
1613 if (!frame->runtime_method->transformed) {
1614 context->managed_code = 0;
1616 char *mn = mono_method_full_name (frame->runtime_method->method, FALSE);
1617 g_print ("(%p) Transforming %s\n", mono_thread_internal_current (), mn);
1620 frame->ex = mono_interp_transform_method (frame->runtime_method, context);
1621 context->managed_code = 1;
1629 rtm = frame->runtime_method;
1630 frame->args = alloca (rtm->alloca_size);
1631 sp = frame->stack = (stackval *)((char *)frame->args + rtm->args_size);
1634 memset(sp, 0, rtm->stack_size);
1636 vt_sp = (unsigned char *) sp + rtm->stack_size;
1640 locals = (unsigned char *) vt_sp + rtm->vt_stack_size;
1642 child_frame.parent = frame;
1648 * using while (ip < end) may result in a 15% performance drop,
1649 * but it may be useful for debug
1653 /* g_assert (sp >= frame->stack); */
1654 /* g_assert(vt_sp - vtalloc <= rtm->vt_stack_size); */
1656 MINT_IN_SWITCH (*ip) {
1657 MINT_IN_CASE(MINT_INITLOCALS)
1658 memset (locals, 0, rtm->locals_size);
1661 MINT_IN_CASE(MINT_NOP)
1664 MINT_IN_CASE(MINT_BREAK)
1666 G_BREAKPOINT (); /* this is not portable... */
1668 MINT_IN_CASE(MINT_LDNULL)
1673 MINT_IN_CASE(MINT_VTRESULT) {
1674 int ret_size = * (guint16 *)(ip + 1);
1675 unsigned char *ret_vt_sp = vt_sp;
1676 vt_sp -= READ32(ip + 2);
1678 memmove (vt_sp, ret_vt_sp, ret_size);
1679 sp [-1].data.p = vt_sp;
1680 vt_sp += (ret_size + 7) & ~7;
1685 #define LDC(n) do { sp->data.i = (n); ++ip; ++sp; } while (0)
1686 MINT_IN_CASE(MINT_LDC_I4_M1)
1689 MINT_IN_CASE(MINT_LDC_I4_0)
1692 MINT_IN_CASE(MINT_LDC_I4_1)
1695 MINT_IN_CASE(MINT_LDC_I4_2)
1698 MINT_IN_CASE(MINT_LDC_I4_3)
1701 MINT_IN_CASE(MINT_LDC_I4_4)
1704 MINT_IN_CASE(MINT_LDC_I4_5)
1707 MINT_IN_CASE(MINT_LDC_I4_6)
1710 MINT_IN_CASE(MINT_LDC_I4_7)
1713 MINT_IN_CASE(MINT_LDC_I4_8)
1716 MINT_IN_CASE(MINT_LDC_I4_S)
1717 sp->data.i = *(const short *)(ip + 1);
1721 MINT_IN_CASE(MINT_LDC_I4)
1723 sp->data.i = READ32 (ip);
1727 MINT_IN_CASE(MINT_LDC_I8)
1729 sp->data.l = READ64 (ip);
1733 MINT_IN_CASE(MINT_LDC_R4) {
1737 sp->data.f = * (float *)&val;
1742 MINT_IN_CASE(MINT_LDC_R8)
1743 sp->data.l = READ64 (ip + 1); /* note union usage */
1747 MINT_IN_CASE(MINT_DUP)
1752 MINT_IN_CASE(MINT_DUP_VT)
1753 i32 = READ32 (ip + 1);
1755 memcpy(sp->data.p, sp [-1].data.p, i32);
1756 vt_sp += (i32 + 7) & ~7;
1760 MINT_IN_CASE(MINT_POP)
1764 MINT_IN_CASE(MINT_JMP) {
1765 RuntimeMethod *new_method = rtm->data_items [* (guint16 *)(ip + 1)];
1766 if (!new_method->transformed) {
1768 frame->ex = mono_interp_transform_method (new_method, context);
1773 if (new_method->alloca_size > rtm->alloca_size)
1774 g_error ("MINT_JMP to method which needs more stack space (%d > %d)", new_method->alloca_size, rtm->alloca_size);
1775 rtm = frame->runtime_method = new_method;
1776 vt_sp = (unsigned char *) sp + rtm->stack_size;
1780 locals = vt_sp + rtm->vt_stack_size;
1781 ip = rtm->new_body_start; /* bypass storing input args from callers frame */
1784 MINT_IN_CASE(MINT_CALLI) {
1785 MonoMethodSignature *csignature;
1786 stackval *endsp = sp;
1790 csignature = rtm->data_items [* (guint16 *)(ip + 1)];
1794 child_frame.runtime_method = sp->data.p;
1797 child_frame.retval = sp;
1798 /* decrement by the actual number of args */
1799 sp -= csignature->param_count;
1800 if (csignature->hasthis)
1802 child_frame.stack_args = sp;
1803 if (csignature->hasthis && mono_object_is_transparent_proxy (sp->data.p)) {
1804 child_frame.runtime_method = mono_interp_get_runtime_method (context->domain, mono_marshal_get_remoting_invoke (child_frame.runtime_method->method), &error);
1805 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
1806 } else if (child_frame.runtime_method->method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) {
1807 child_frame.runtime_method = mono_interp_get_runtime_method (context->domain, mono_marshal_get_native_wrapper (child_frame.runtime_method->method, FALSE, FALSE), &error);
1808 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
1811 ves_exec_method_with_context (&child_frame, context);
1813 context->current_frame = frame;
1815 if (child_frame.ex) {
1817 * An exception occurred, need to run finally, fault and catch handlers..
1819 frame->ex = child_frame.ex;
1820 goto handle_finally;
1823 /* need to handle typedbyref ... */
1824 if (csignature->ret->type != MONO_TYPE_VOID) {
1830 MINT_IN_CASE(MINT_CALLI_NAT) {
1831 MonoMethodSignature *csignature;
1832 stackval *endsp = sp;
1833 unsigned char *code = NULL;
1837 csignature = rtm->data_items [* (guint16 *)(ip + 1)];
1842 child_frame.runtime_method = NULL;
1845 child_frame.retval = sp;
1846 /* decrement by the actual number of args */
1847 sp -= csignature->param_count;
1848 if (csignature->hasthis)
1850 child_frame.stack_args = sp;
1851 ves_pinvoke_method (&child_frame, csignature, (MonoFuncV) code, FALSE, context);
1853 context->current_frame = frame;
1855 if (child_frame.ex) {
1857 * An exception occurred, need to run finally, fault and catch handlers..
1859 frame->ex = child_frame.ex;
1860 if (context->search_for_handler) {
1861 context->search_for_handler = 0;
1862 goto handle_exception;
1864 goto handle_finally;
1867 /* need to handle typedbyref ... */
1868 if (csignature->ret->type != MONO_TYPE_VOID) {
1874 MINT_IN_CASE(MINT_CALL) {
1875 stackval *endsp = sp;
1879 child_frame.runtime_method = rtm->data_items [* (guint16 *)(ip + 1)];
1882 child_frame.retval = sp;
1883 /* decrement by the actual number of args */
1884 sp -= child_frame.runtime_method->param_count;
1885 if (child_frame.runtime_method->hasthis)
1887 child_frame.stack_args = sp;
1888 if (child_frame.runtime_method->hasthis && !child_frame.runtime_method->valuetype && mono_object_is_transparent_proxy (sp->data.p)) {
1889 child_frame.runtime_method = mono_interp_get_runtime_method (context->domain, mono_marshal_get_remoting_invoke (child_frame.runtime_method->method), &error);
1890 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
1892 ves_exec_method_with_context (&child_frame, context);
1894 context->current_frame = frame;
1896 if (child_frame.ex) {
1898 * An exception occurred, need to run finally, fault and catch handlers..
1900 frame->ex = child_frame.ex;
1901 goto handle_finally;
1904 /* need to handle typedbyref ... */
1909 MINT_IN_CASE(MINT_VCALL) {
1912 child_frame.runtime_method = rtm->data_items [* (guint16 *)(ip + 1)];
1916 child_frame.retval = sp;
1917 /* decrement by the actual number of args */
1918 sp -= child_frame.runtime_method->param_count;
1919 if (child_frame.runtime_method->hasthis)
1921 child_frame.stack_args = sp;
1923 if (child_frame.runtime_method->hasthis && !child_frame.runtime_method->valuetype && mono_object_is_transparent_proxy (sp->data.p)) {
1924 child_frame.runtime_method = mono_interp_get_runtime_method (context->domain, mono_marshal_get_remoting_invoke (child_frame.runtime_method->method), &error);
1925 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
1928 ves_exec_method_with_context (&child_frame, context);
1930 context->current_frame = frame;
1932 if (child_frame.ex) {
1934 * An exception occurred, need to run finally, fault and catch handlers..
1936 frame->ex = child_frame.ex;
1937 goto handle_finally;
1941 MINT_IN_CASE(MINT_CALLVIRT) {
1942 stackval *endsp = sp;
1943 MonoObject *this_arg;
1948 token = * (unsigned short *)(ip + 1);
1950 child_frame.runtime_method = rtm->data_items [token];
1952 child_frame.retval = sp;
1954 /* decrement by the actual number of args */
1955 sp -= child_frame.runtime_method->param_count + 1;
1956 child_frame.stack_args = sp;
1957 this_arg = sp->data.p;
1959 THROW_EX (mono_get_exception_null_reference(), ip - 2);
1960 child_frame.runtime_method = get_virtual_method (context->domain, child_frame.runtime_method, this_arg);
1962 if (this_arg->vtable->klass->valuetype && child_frame.runtime_method->valuetype) {
1963 sp->data.p = (char *) this_arg + sizeof (MonoObject);
1966 ves_exec_method_with_context (&child_frame, context);
1968 context->current_frame = frame;
1970 if (child_frame.ex) {
1972 * An exception occurred, need to run finally, fault and catch handlers..
1974 frame->ex = child_frame.ex;
1975 if (context->search_for_handler) {
1976 context->search_for_handler = 0;
1977 goto handle_exception;
1979 goto handle_finally;
1982 /* need to handle typedbyref ... */
1987 MINT_IN_CASE(MINT_VCALLVIRT) {
1988 MonoObject *this_arg;
1993 token = * (unsigned short *)(ip + 1);
1995 child_frame.runtime_method = rtm->data_items [token];
1997 child_frame.retval = sp;
1999 /* decrement by the actual number of args */
2000 sp -= child_frame.runtime_method->param_count + 1;
2001 child_frame.stack_args = sp;
2002 this_arg = sp->data.p;
2004 THROW_EX (mono_get_exception_null_reference(), ip - 2);
2005 child_frame.runtime_method = get_virtual_method (context->domain, child_frame.runtime_method, this_arg);
2007 if (this_arg->vtable->klass->valuetype && child_frame.runtime_method->valuetype) {
2008 sp->data.p = (char *) this_arg + sizeof (MonoObject);
2011 ves_exec_method_with_context (&child_frame, context);
2013 context->current_frame = frame;
2015 if (child_frame.ex) {
2017 * An exception occurred, need to run finally, fault and catch handlers..
2019 frame->ex = child_frame.ex;
2020 if (context->search_for_handler) {
2021 context->search_for_handler = 0;
2022 goto handle_exception;
2024 goto handle_finally;
2028 MINT_IN_CASE(MINT_CALLRUN)
2029 ves_runtime_method (frame, context);
2032 goto handle_exception;
2035 MINT_IN_CASE(MINT_RET)
2037 *frame->retval = *sp;
2038 if (sp > frame->stack)
2039 g_warning ("ret: more values on stack: %d", sp-frame->stack);
2041 MINT_IN_CASE(MINT_RET_VOID)
2042 if (sp > frame->stack)
2043 g_warning ("ret.void: more values on stack: %d", sp-frame->stack);
2045 MINT_IN_CASE(MINT_RET_VT)
2046 i32 = READ32(ip + 1);
2048 memcpy(frame->retval->data.p, sp->data.p, i32);
2049 if (sp > frame->stack)
2050 g_warning ("ret.vt: more values on stack: %d", sp-frame->stack);
2052 MINT_IN_CASE(MINT_BR_S)
2053 ip += (short) *(ip + 1);
2055 MINT_IN_CASE(MINT_BR)
2056 ip += (gint32) READ32(ip + 1);
2058 #define ZEROP_S(datamem, op) \
2060 if (sp->data.datamem op 0) \
2061 ip += * (gint16 *)(ip + 1); \
2065 #define ZEROP(datamem, op) \
2067 if (sp->data.datamem op 0) \
2068 ip += READ32(ip + 1); \
2072 MINT_IN_CASE(MINT_BRFALSE_I4_S)
2075 MINT_IN_CASE(MINT_BRFALSE_I8_S)
2078 MINT_IN_CASE(MINT_BRFALSE_R8_S)
2081 MINT_IN_CASE(MINT_BRFALSE_I4)
2084 MINT_IN_CASE(MINT_BRFALSE_I8)
2087 MINT_IN_CASE(MINT_BRFALSE_R8)
2090 MINT_IN_CASE(MINT_BRTRUE_I4_S)
2093 MINT_IN_CASE(MINT_BRTRUE_I8_S)
2096 MINT_IN_CASE(MINT_BRTRUE_R8_S)
2099 MINT_IN_CASE(MINT_BRTRUE_I4)
2102 MINT_IN_CASE(MINT_BRTRUE_I8)
2105 MINT_IN_CASE(MINT_BRTRUE_R8)
2108 #define CONDBR_S(cond) \
2111 ip += * (gint16 *)(ip + 1); \
2114 #define BRELOP_S(datamem, op) \
2115 CONDBR_S(sp[0].data.datamem op sp[1].data.datamem)
2117 #define CONDBR(cond) \
2120 ip += READ32(ip + 1); \
2124 #define BRELOP(datamem, op) \
2125 CONDBR(sp[0].data.datamem op sp[1].data.datamem)
2127 MINT_IN_CASE(MINT_BEQ_I4_S)
2130 MINT_IN_CASE(MINT_BEQ_I8_S)
2133 MINT_IN_CASE(MINT_BEQ_R8_S)
2134 CONDBR_S(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f == sp[1].data.f)
2136 MINT_IN_CASE(MINT_BEQ_I4)
2139 MINT_IN_CASE(MINT_BEQ_I8)
2142 MINT_IN_CASE(MINT_BEQ_R8)
2143 CONDBR(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f == sp[1].data.f)
2145 MINT_IN_CASE(MINT_BGE_I4_S)
2148 MINT_IN_CASE(MINT_BGE_I8_S)
2151 MINT_IN_CASE(MINT_BGE_R8_S)
2152 CONDBR_S(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f >= sp[1].data.f)
2154 MINT_IN_CASE(MINT_BGE_I4)
2157 MINT_IN_CASE(MINT_BGE_I8)
2160 MINT_IN_CASE(MINT_BGE_R8)
2161 CONDBR(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f >= sp[1].data.f)
2163 MINT_IN_CASE(MINT_BGT_I4_S)
2166 MINT_IN_CASE(MINT_BGT_I8_S)
2169 MINT_IN_CASE(MINT_BGT_R8_S)
2170 CONDBR_S(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f > sp[1].data.f)
2172 MINT_IN_CASE(MINT_BGT_I4)
2175 MINT_IN_CASE(MINT_BGT_I8)
2178 MINT_IN_CASE(MINT_BGT_R8)
2179 CONDBR(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f > sp[1].data.f)
2181 MINT_IN_CASE(MINT_BLT_I4_S)
2184 MINT_IN_CASE(MINT_BLT_I8_S)
2187 MINT_IN_CASE(MINT_BLT_R8_S)
2188 CONDBR_S(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f < sp[1].data.f)
2190 MINT_IN_CASE(MINT_BLT_I4)
2193 MINT_IN_CASE(MINT_BLT_I8)
2196 MINT_IN_CASE(MINT_BLT_R8)
2197 CONDBR(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f < sp[1].data.f)
2199 MINT_IN_CASE(MINT_BLE_I4_S)
2202 MINT_IN_CASE(MINT_BLE_I8_S)
2205 MINT_IN_CASE(MINT_BLE_R8_S)
2206 CONDBR_S(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f <= sp[1].data.f)
2208 MINT_IN_CASE(MINT_BLE_I4)
2211 MINT_IN_CASE(MINT_BLE_I8)
2214 MINT_IN_CASE(MINT_BLE_R8)
2215 CONDBR(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f <= sp[1].data.f)
2217 MINT_IN_CASE(MINT_BNE_UN_I4_S)
2220 MINT_IN_CASE(MINT_BNE_UN_I8_S)
2223 MINT_IN_CASE(MINT_BNE_UN_R8_S)
2224 CONDBR_S(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f != sp[1].data.f)
2226 MINT_IN_CASE(MINT_BNE_UN_I4)
2229 MINT_IN_CASE(MINT_BNE_UN_I8)
2232 MINT_IN_CASE(MINT_BNE_UN_R8)
2233 CONDBR(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f != sp[1].data.f)
2236 #define BRELOP_S_CAST(datamem, op, type) \
2238 if ((type) sp[0].data.datamem op (type) sp[1].data.datamem) \
2239 ip += * (gint16 *)(ip + 1); \
2243 #define BRELOP_CAST(datamem, op, type) \
2245 if ((type) sp[0].data.datamem op (type) sp[1].data.datamem) \
2246 ip += READ32(ip + 1); \
2250 MINT_IN_CASE(MINT_BGE_UN_I4_S)
2251 BRELOP_S_CAST(i, >=, guint32);
2253 MINT_IN_CASE(MINT_BGE_UN_I8_S)
2254 BRELOP_S_CAST(l, >=, guint64);
2256 MINT_IN_CASE(MINT_BGE_UN_R8_S)
2257 CONDBR_S(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f >= sp[1].data.f)
2259 MINT_IN_CASE(MINT_BGE_UN_I4)
2260 BRELOP_CAST(i, >=, guint32);
2262 MINT_IN_CASE(MINT_BGE_UN_I8)
2263 BRELOP_CAST(l, >=, guint64);
2265 MINT_IN_CASE(MINT_BGE_UN_R8)
2266 CONDBR(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f >= sp[1].data.f)
2268 MINT_IN_CASE(MINT_BGT_UN_I4_S)
2269 BRELOP_S_CAST(i, >, guint32);
2271 MINT_IN_CASE(MINT_BGT_UN_I8_S)
2272 BRELOP_S_CAST(l, >, guint64);
2274 MINT_IN_CASE(MINT_BGT_UN_R8_S)
2275 CONDBR_S(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f > sp[1].data.f)
2277 MINT_IN_CASE(MINT_BGT_UN_I4)
2278 BRELOP_CAST(i, >, guint32);
2280 MINT_IN_CASE(MINT_BGT_UN_I8)
2281 BRELOP_CAST(l, >, guint64);
2283 MINT_IN_CASE(MINT_BGT_UN_R8)
2284 CONDBR(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f > sp[1].data.f)
2286 MINT_IN_CASE(MINT_BLE_UN_I4_S)
2287 BRELOP_S_CAST(i, <=, guint32);
2289 MINT_IN_CASE(MINT_BLE_UN_I8_S)
2290 BRELOP_S_CAST(l, <=, guint64);
2292 MINT_IN_CASE(MINT_BLE_UN_R8_S)
2293 CONDBR_S(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f <= sp[1].data.f)
2295 MINT_IN_CASE(MINT_BLE_UN_I4)
2296 BRELOP_CAST(i, <=, guint32);
2298 MINT_IN_CASE(MINT_BLE_UN_I8)
2299 BRELOP_CAST(l, <=, guint64);
2301 MINT_IN_CASE(MINT_BLE_UN_R8)
2302 CONDBR(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f <= sp[1].data.f)
2304 MINT_IN_CASE(MINT_BLT_UN_I4_S)
2305 BRELOP_S_CAST(i, <, guint32);
2307 MINT_IN_CASE(MINT_BLT_UN_I8_S)
2308 BRELOP_S_CAST(l, <, guint64);
2310 MINT_IN_CASE(MINT_BLT_UN_R8_S)
2311 CONDBR_S(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f < sp[1].data.f)
2313 MINT_IN_CASE(MINT_BLT_UN_I4)
2314 BRELOP_CAST(i, <, guint32);
2316 MINT_IN_CASE(MINT_BLT_UN_I8)
2317 BRELOP_CAST(l, <, guint64);
2319 MINT_IN_CASE(MINT_BLT_UN_R8)
2320 CONDBR(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f < sp[1].data.f)
2322 MINT_IN_CASE(MINT_SWITCH) {
2324 const unsigned short *st;
2330 if ((guint32)sp->data.i < n) {
2332 ip += 2 * (guint32)sp->data.i;
2333 offset = READ32 (ip);
2340 MINT_IN_CASE(MINT_LDIND_I1)
2342 sp[-1].data.i = *(gint8*)sp[-1].data.p;
2344 MINT_IN_CASE(MINT_LDIND_U1)
2346 sp[-1].data.i = *(guint8*)sp[-1].data.p;
2348 MINT_IN_CASE(MINT_LDIND_I2)
2350 sp[-1].data.i = *(gint16*)sp[-1].data.p;
2352 MINT_IN_CASE(MINT_LDIND_U2)
2354 sp[-1].data.i = *(guint16*)sp[-1].data.p;
2356 MINT_IN_CASE(MINT_LDIND_I4) /* Fall through */
2357 MINT_IN_CASE(MINT_LDIND_U4)
2359 sp[-1].data.i = *(gint32*)sp[-1].data.p;
2361 MINT_IN_CASE(MINT_LDIND_I8)
2363 sp[-1].data.l = *(gint64*)sp[-1].data.p;
2365 MINT_IN_CASE(MINT_LDIND_I)
2367 sp[-1].data.p = *(gpointer*)sp[-1].data.p;
2369 MINT_IN_CASE(MINT_LDIND_R4)
2371 sp[-1].data.f = *(gfloat*)sp[-1].data.p;
2373 MINT_IN_CASE(MINT_LDIND_R8)
2375 sp[-1].data.f = *(gdouble*)sp[-1].data.p;
2377 MINT_IN_CASE(MINT_LDIND_REF)
2379 sp[-1].data.p = *(gpointer*)sp[-1].data.p;
2381 MINT_IN_CASE(MINT_STIND_REF)
2384 * (gpointer *) sp->data.p = sp[1].data.p;
2386 MINT_IN_CASE(MINT_STIND_I1)
2389 * (gint8 *) sp->data.p = (gint8)sp[1].data.i;
2391 MINT_IN_CASE(MINT_STIND_I2)
2394 * (gint16 *) sp->data.p = (gint16)sp[1].data.i;
2396 MINT_IN_CASE(MINT_STIND_I4)
2399 * (gint32 *) sp->data.p = sp[1].data.i;
2401 MINT_IN_CASE(MINT_STIND_I)
2404 * (mono_i *) sp->data.p = (mono_i)sp[1].data.p;
2406 MINT_IN_CASE(MINT_STIND_I8)
2409 * (gint64 *) sp->data.p = sp[1].data.l;
2411 MINT_IN_CASE(MINT_STIND_R4)
2414 * (float *) sp->data.p = (gfloat)sp[1].data.f;
2416 MINT_IN_CASE(MINT_STIND_R8)
2419 * (double *) sp->data.p = sp[1].data.f;
2421 #define BINOP(datamem, op) \
2423 sp [-1].data.datamem = sp [-1].data.datamem op sp [0].data.datamem; \
2425 MINT_IN_CASE(MINT_ADD_I4)
2428 MINT_IN_CASE(MINT_ADD_I8)
2431 MINT_IN_CASE(MINT_ADD_R8)
2434 MINT_IN_CASE(MINT_ADD1_I4)
2438 MINT_IN_CASE(MINT_SUB_I4)
2441 MINT_IN_CASE(MINT_SUB_I8)
2444 MINT_IN_CASE(MINT_SUB_R8)
2447 MINT_IN_CASE(MINT_SUB1_I4)
2451 MINT_IN_CASE(MINT_MUL_I4)
2454 MINT_IN_CASE(MINT_MUL_I8)
2457 MINT_IN_CASE(MINT_MUL_R8)
2460 MINT_IN_CASE(MINT_DIV_I4)
2461 if (sp [-1].data.i == 0)
2462 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2463 if (sp [-1].data.i == (-1))
2464 THROW_EX (mono_get_exception_overflow (), ip);
2467 MINT_IN_CASE(MINT_DIV_I8)
2468 if (sp [-1].data.l == 0)
2469 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2470 if (sp [-1].data.l == (-1))
2471 THROW_EX (mono_get_exception_overflow (), ip);
2474 MINT_IN_CASE(MINT_DIV_R8)
2478 #define BINOP_CAST(datamem, op, type) \
2480 sp [-1].data.datamem = (type)sp [-1].data.datamem op (type)sp [0].data.datamem; \
2482 MINT_IN_CASE(MINT_DIV_UN_I4)
2483 if (sp [-1].data.i == 0)
2484 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2485 BINOP_CAST(i, /, guint32);
2487 MINT_IN_CASE(MINT_DIV_UN_I8)
2488 if (sp [-1].data.l == 0)
2489 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2490 BINOP_CAST(l, /, guint64);
2492 MINT_IN_CASE(MINT_REM_I4)
2493 if (sp [-1].data.i == 0)
2494 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2497 MINT_IN_CASE(MINT_REM_I8)
2498 if (sp [-1].data.l == 0)
2499 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2502 MINT_IN_CASE(MINT_REM_R8)
2503 /* FIXME: what do we actually do here? */
2505 sp [-1].data.f = fmod (sp [-1].data.f, sp [0].data.f);
2508 MINT_IN_CASE(MINT_REM_UN_I4)
2509 if (sp [-1].data.i == 0)
2510 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2511 BINOP_CAST(i, %, guint32);
2513 MINT_IN_CASE(MINT_REM_UN_I8)
2514 if (sp [-1].data.l == 0)
2515 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2516 BINOP_CAST(l, %, guint64);
2518 MINT_IN_CASE(MINT_AND_I4)
2521 MINT_IN_CASE(MINT_AND_I8)
2524 MINT_IN_CASE(MINT_OR_I4)
2527 MINT_IN_CASE(MINT_OR_I8)
2530 MINT_IN_CASE(MINT_XOR_I4)
2533 MINT_IN_CASE(MINT_XOR_I8)
2537 #define SHIFTOP(datamem, op) \
2539 sp [-1].data.datamem = sp [-1].data.datamem op sp [0].data.i; \
2542 MINT_IN_CASE(MINT_SHL_I4)
2545 MINT_IN_CASE(MINT_SHL_I8)
2548 MINT_IN_CASE(MINT_SHR_I4)
2551 MINT_IN_CASE(MINT_SHR_I8)
2554 MINT_IN_CASE(MINT_SHR_UN_I4)
2556 sp [-1].data.i = (guint32)sp [-1].data.i >> sp [0].data.i;
2559 MINT_IN_CASE(MINT_SHR_UN_I8)
2561 sp [-1].data.l = (guint64)sp [-1].data.l >> sp [0].data.i;
2564 MINT_IN_CASE(MINT_NEG_I4)
2565 sp [-1].data.i = - sp [-1].data.i;
2568 MINT_IN_CASE(MINT_NEG_I8)
2569 sp [-1].data.l = - sp [-1].data.l;
2572 MINT_IN_CASE(MINT_NEG_R8)
2573 sp [-1].data.f = - sp [-1].data.f;
2576 MINT_IN_CASE(MINT_NOT_I4)
2577 sp [-1].data.i = ~ sp [-1].data.i;
2580 MINT_IN_CASE(MINT_NOT_I8)
2581 sp [-1].data.l = ~ sp [-1].data.l;
2584 MINT_IN_CASE(MINT_CONV_I1_I4)
2585 sp [-1].data.i = (gint8)sp [-1].data.i;
2588 MINT_IN_CASE(MINT_CONV_I1_I8)
2589 sp [-1].data.i = (gint8)sp [-1].data.l;
2592 MINT_IN_CASE(MINT_CONV_I1_R8)
2593 sp [-1].data.i = (gint8)sp [-1].data.f;
2596 MINT_IN_CASE(MINT_CONV_U1_I4)
2597 sp [-1].data.i = (guint8)sp [-1].data.i;
2600 MINT_IN_CASE(MINT_CONV_U1_I8)
2601 sp [-1].data.i = (guint8)sp [-1].data.l;
2604 MINT_IN_CASE(MINT_CONV_U1_R8)
2605 sp [-1].data.i = (guint8)sp [-1].data.f;
2608 MINT_IN_CASE(MINT_CONV_I2_I4)
2609 sp [-1].data.i = (gint16)sp [-1].data.i;
2612 MINT_IN_CASE(MINT_CONV_I2_I8)
2613 sp [-1].data.i = (gint16)sp [-1].data.l;
2616 MINT_IN_CASE(MINT_CONV_I2_R8)
2617 sp [-1].data.i = (gint16)sp [-1].data.f;
2620 MINT_IN_CASE(MINT_CONV_U2_I4)
2621 sp [-1].data.i = (guint16)sp [-1].data.i;
2624 MINT_IN_CASE(MINT_CONV_U2_I8)
2625 sp [-1].data.i = (guint16)sp [-1].data.l;
2628 MINT_IN_CASE(MINT_CONV_U2_R8)
2629 sp [-1].data.i = (guint16)sp [-1].data.f;
2632 MINT_IN_CASE(MINT_CONV_I4_R8)
2633 sp [-1].data.i = (gint32)sp [-1].data.f;
2636 MINT_IN_CASE(MINT_CONV_U4_I8)
2637 MINT_IN_CASE(MINT_CONV_I4_I8)
2638 sp [-1].data.i = (gint32)sp [-1].data.l;
2641 MINT_IN_CASE(MINT_CONV_I4_I8_SP)
2642 sp [-2].data.i = (gint32)sp [-2].data.l;
2645 MINT_IN_CASE(MINT_CONV_U4_R8)
2646 sp [-1].data.i = (guint32)sp [-1].data.f;
2649 MINT_IN_CASE(MINT_CONV_I8_I4)
2650 sp [-1].data.l = sp [-1].data.i;
2653 MINT_IN_CASE(MINT_CONV_I8_I4_SP)
2654 sp [-2].data.l = sp [-2].data.i;
2657 MINT_IN_CASE(MINT_CONV_I8_U4)
2658 sp [-1].data.l = (guint32)sp [-1].data.i;
2661 MINT_IN_CASE(MINT_CONV_I8_R8)
2662 sp [-1].data.l = (gint64)sp [-1].data.f;
2665 MINT_IN_CASE(MINT_CONV_R4_I4)
2666 sp [-1].data.f = (float)sp [-1].data.i;
2669 MINT_IN_CASE(MINT_CONV_R4_I8)
2670 sp [-1].data.f = (float)sp [-1].data.l;
2673 MINT_IN_CASE(MINT_CONV_R4_R8)
2674 sp [-1].data.f = (float)sp [-1].data.f;
2677 MINT_IN_CASE(MINT_CONV_R8_I4)
2678 sp [-1].data.f = (double)sp [-1].data.i;
2681 MINT_IN_CASE(MINT_CONV_R8_I8)
2682 sp [-1].data.f = (double)sp [-1].data.l;
2685 MINT_IN_CASE(MINT_CONV_U8_I4)
2686 sp [-1].data.l = sp [-1].data.i & 0xffffffff;
2689 MINT_IN_CASE(MINT_CONV_U8_R8)
2690 sp [-1].data.l = (guint64)sp [-1].data.f;
2694 MINT_IN_CASE(MINT_CPOBJ) {
2697 vtklass = rtm->data_items[READ32 (ip)];
2700 memcpy (sp [0].data.p, sp [1].data.p, mono_class_value_size (vtklass, NULL));
2704 MINT_IN_CASE(MINT_LDOBJ) {
2707 c = rtm->data_items[* (guint16 *)(ip + 1)];
2709 if (c->byval_arg.type != MONO_TYPE_VALUETYPE || c->byval_arg.data.klass->enumtype) {
2711 stackval_from_data (&c->byval_arg, &sp [-1], p, FALSE);
2713 size = mono_class_value_size (c, NULL);
2715 sp [-1].data.p = vt_sp;
2716 memcpy(vt_sp, p, size);
2717 vt_sp += (size + 7) & ~7;
2721 MINT_IN_CASE(MINT_LDSTR)
2722 sp->data.p = rtm->data_items [* (guint16 *)(ip + 1)];
2726 MINT_IN_CASE(MINT_NEWOBJ) {
2727 MonoClass *newobj_class;
2728 MonoMethodSignature *csig;
2729 stackval valuetype_this;
2735 token = * (guint16 *)(ip + 1);
2738 child_frame.runtime_method = rtm->data_items [token];
2739 csig = mono_method_signature (child_frame.runtime_method->method);
2740 newobj_class = child_frame.runtime_method->method->klass;
2741 /*if (profiling_classes) {
2742 guint count = GPOINTER_TO_UINT (g_hash_table_lookup (profiling_classes, newobj_class));
2744 g_hash_table_insert (profiling_classes, newobj_class, GUINT_TO_POINTER (count));
2747 if (newobj_class->parent == mono_defaults.array_class) {
2748 sp -= csig->param_count;
2749 o = ves_array_create (context->domain, newobj_class, csig, sp);
2750 goto array_constructed;
2753 g_assert (csig->hasthis);
2754 if (csig->param_count) {
2755 sp -= csig->param_count;
2756 memmove (sp + 1, sp, csig->param_count * sizeof (stackval));
2758 child_frame.stack_args = sp;
2761 * First arg is the object.
2763 if (newobj_class->valuetype) {
2764 MonoType *t = &newobj_class->byval_arg;
2765 if (!newobj_class->enumtype && (t->type == MONO_TYPE_VALUETYPE || (t->type == MONO_TYPE_GENERICINST && mono_type_generic_inst_is_valuetype (t)))) {
2767 valuetype_this.data.p = vt_sp;
2769 memset (&valuetype_this, 0, sizeof (stackval));
2770 sp->data.p = &valuetype_this;
2773 if (newobj_class != mono_defaults.string_class) {
2774 context->managed_code = 0;
2775 o = mono_object_new_checked (context->domain, newobj_class, &error);
2776 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2777 context->managed_code = 1;
2778 if (*mono_thread_interruption_request_flag ())
2779 mono_thread_interruption_checkpoint ();
2782 child_frame.retval = &retval;
2786 g_assert (csig->call_convention == MONO_CALL_DEFAULT);
2788 child_frame.ip = NULL;
2789 child_frame.ex = NULL;
2791 ves_exec_method_with_context (&child_frame, context);
2793 context->current_frame = frame;
2795 if (child_frame.ex) {
2797 * An exception occurred, need to run finally, fault and catch handlers..
2799 frame->ex = child_frame.ex;
2800 goto handle_finally;
2803 * a constructor returns void, but we need to return the object we created
2806 if (newobj_class->valuetype && !newobj_class->enumtype) {
2807 *sp = valuetype_this;
2808 } else if (newobj_class == mono_defaults.string_class) {
2816 MINT_IN_CASE(MINT_CASTCLASS)
2817 c = rtm->data_items [*(guint16 *)(ip + 1)];
2818 if ((o = sp [-1].data.p)) {
2819 MonoObject *isinst_obj = mono_object_isinst_checked (o, c, &error);
2820 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2822 THROW_EX (mono_get_exception_invalid_cast (), ip);
2826 MINT_IN_CASE(MINT_ISINST)
2827 c = rtm->data_items [*(guint16 *)(ip + 1)];
2828 if ((o = sp [-1].data.p)) {
2829 MonoObject *isinst_obj = mono_object_isinst_checked (o, c, &error);
2830 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2832 sp [-1].data.p = NULL;
2836 MINT_IN_CASE(MINT_CONV_R_UN_I4)
2837 sp [-1].data.f = (double)(guint32)sp [-1].data.i;
2840 MINT_IN_CASE(MINT_CONV_R_UN_I8)
2841 sp [-1].data.f = (double)(guint64)sp [-1].data.l;
2844 MINT_IN_CASE(MINT_UNBOX)
2845 c = rtm->data_items[*(guint16 *)(ip + 1)];
2849 THROW_EX (mono_get_exception_null_reference (), ip);
2851 MonoObject *isinst_obj = mono_object_isinst_checked (o, c, &error);
2852 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2853 if (!(isinst_obj || ((o->vtable->klass->rank == 0) && (o->vtable->klass->element_class == c->element_class))))
2854 THROW_EX (mono_get_exception_invalid_cast (), ip);
2856 if (c->byval_arg.type == MONO_TYPE_VALUETYPE && !c->enumtype) {
2857 int size = mono_class_native_size (c, NULL);
2858 sp [-1].data.p = vt_sp;
2859 vt_sp += (size + 7) & ~7;
2861 stackval_from_data (&c->byval_arg, &sp [-1], mono_object_unbox (o), FALSE);
2864 MINT_IN_CASE(MINT_THROW)
2866 frame->ex_handler = NULL;
2868 sp->data.p = mono_get_exception_null_reference ();
2869 THROW_EX ((MonoException *)sp->data.p, ip);
2871 MINT_IN_CASE(MINT_LDFLDA)
2874 THROW_EX (mono_get_exception_null_reference (), ip);
2875 sp[-1].data.p = (char *)o + * (guint16 *)(ip + 1);
2878 MINT_IN_CASE(MINT_CKNULL)
2881 THROW_EX (mono_get_exception_null_reference (), ip);
2885 #define LDFLD(datamem, fieldtype) \
2886 o = sp [-1].data.p; \
2888 THROW_EX (mono_get_exception_null_reference (), ip); \
2889 sp[-1].data.datamem = * (fieldtype *)((char *)o + * (guint16 *)(ip + 1)) ; \
2892 MINT_IN_CASE(MINT_LDFLD_I1) LDFLD(i, gint8); MINT_IN_BREAK;
2893 MINT_IN_CASE(MINT_LDFLD_U1) LDFLD(i, guint8); MINT_IN_BREAK;
2894 MINT_IN_CASE(MINT_LDFLD_I2) LDFLD(i, gint16); MINT_IN_BREAK;
2895 MINT_IN_CASE(MINT_LDFLD_U2) LDFLD(i, guint16); MINT_IN_BREAK;
2896 MINT_IN_CASE(MINT_LDFLD_I4) LDFLD(i, gint32); MINT_IN_BREAK;
2897 MINT_IN_CASE(MINT_LDFLD_I8) LDFLD(l, gint64); MINT_IN_BREAK;
2898 MINT_IN_CASE(MINT_LDFLD_R4) LDFLD(f, float); MINT_IN_BREAK;
2899 MINT_IN_CASE(MINT_LDFLD_R8) LDFLD(f, double); MINT_IN_BREAK;
2900 MINT_IN_CASE(MINT_LDFLD_O) LDFLD(p, gpointer); MINT_IN_BREAK;
2901 MINT_IN_CASE(MINT_LDFLD_P) LDFLD(p, gpointer); MINT_IN_BREAK;
2903 MINT_IN_CASE(MINT_LDFLD_VT)
2906 THROW_EX (mono_get_exception_null_reference (), ip);
2907 i32 = READ32(ip + 2);
2908 sp [-1].data.p = vt_sp;
2909 memcpy(sp [-1].data.p, (char *)o + * (guint16 *)(ip + 1), i32);
2910 vt_sp += (i32 + 7) & ~7;
2914 MINT_IN_CASE(MINT_LDRMFLD) {
2916 MonoClassField *field;
2921 THROW_EX (mono_get_exception_null_reference (), ip);
2922 field = rtm->data_items[* (guint16 *)(ip + 1)];
2924 if (mono_object_is_transparent_proxy (o)) {
2925 MonoClass *klass = ((MonoTransparentProxy*)o)->remote_class->proxy_class;
2927 addr = mono_load_remote_field_checked (o, klass, field, &tmp, &error);
2928 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2930 addr = (char*)o + field->offset;
2933 stackval_from_data (field->type, &sp [-1], addr, FALSE);
2937 MINT_IN_CASE(MINT_LDRMFLD_VT) {
2938 MonoClassField *field;
2944 THROW_EX (mono_get_exception_null_reference (), ip);
2945 field = rtm->data_items[* (guint16 *)(ip + 1)];
2946 i32 = READ32(ip + 2);
2948 if (mono_object_is_transparent_proxy (o)) {
2949 MonoClass *klass = ((MonoTransparentProxy*)o)->remote_class->proxy_class;
2950 addr = mono_load_remote_field_checked (o, klass, field, &tmp, &error);
2951 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2953 addr = (char*)o + field->offset;
2956 sp [-1].data.p = vt_sp;
2957 memcpy(sp [-1].data.p, (char *)o + * (guint16 *)(ip + 1), i32);
2958 vt_sp += (i32 + 7) & ~7;
2959 memcpy(sp [-1].data.p, addr, i32);
2963 #define STFLD(datamem, fieldtype) \
2964 o = sp [-2].data.p; \
2966 THROW_EX (mono_get_exception_null_reference (), ip); \
2968 * (fieldtype *)((char *)o + * (guint16 *)(ip + 1)) = sp[1].data.datamem; \
2971 MINT_IN_CASE(MINT_STFLD_I1) STFLD(i, gint8); MINT_IN_BREAK;
2972 MINT_IN_CASE(MINT_STFLD_U1) STFLD(i, guint8); MINT_IN_BREAK;
2973 MINT_IN_CASE(MINT_STFLD_I2) STFLD(i, gint16); MINT_IN_BREAK;
2974 MINT_IN_CASE(MINT_STFLD_U2) STFLD(i, guint16); MINT_IN_BREAK;
2975 MINT_IN_CASE(MINT_STFLD_I4) STFLD(i, gint32); MINT_IN_BREAK;
2976 MINT_IN_CASE(MINT_STFLD_I8) STFLD(l, gint64); MINT_IN_BREAK;
2977 MINT_IN_CASE(MINT_STFLD_R4) STFLD(f, float); MINT_IN_BREAK;
2978 MINT_IN_CASE(MINT_STFLD_R8) STFLD(f, double); MINT_IN_BREAK;
2979 MINT_IN_CASE(MINT_STFLD_O) STFLD(p, gpointer); MINT_IN_BREAK;
2980 MINT_IN_CASE(MINT_STFLD_P) STFLD(p, gpointer); MINT_IN_BREAK;
2982 MINT_IN_CASE(MINT_STFLD_VT)
2985 THROW_EX (mono_get_exception_null_reference (), ip);
2986 i32 = READ32(ip + 2);
2988 memcpy((char *)o + * (guint16 *)(ip + 1), sp [1].data.p, i32);
2989 vt_sp -= (i32 + 7) & ~7;
2993 MINT_IN_CASE(MINT_STRMFLD) {
2994 MonoClassField *field;
2998 THROW_EX (mono_get_exception_null_reference (), ip);
3000 field = rtm->data_items[* (guint16 *)(ip + 1)];
3003 if (mono_object_is_transparent_proxy (o)) {
3004 MonoClass *klass = ((MonoTransparentProxy*)o)->remote_class->proxy_class;
3005 mono_store_remote_field_checked (o, klass, field, &sp [-1].data, &error);
3006 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3008 stackval_to_data (field->type, &sp [-1], (char*)o + field->offset, FALSE);
3013 MINT_IN_CASE(MINT_STRMFLD_VT) {
3014 MonoClassField *field;
3018 THROW_EX (mono_get_exception_null_reference (), ip);
3019 field = rtm->data_items[* (guint16 *)(ip + 1)];
3020 i32 = READ32(ip + 2);
3023 if (mono_object_is_transparent_proxy (o)) {
3024 MonoClass *klass = ((MonoTransparentProxy*)o)->remote_class->proxy_class;
3025 mono_store_remote_field_checked (o, klass, field, &sp [-1].data, &error);
3026 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3028 memcpy((char*)o + field->offset, sp [-1].data.p, i32);
3031 vt_sp -= (i32 + 7) & ~7;
3034 MINT_IN_CASE(MINT_LDSFLDA) {
3035 MonoClassField *field = rtm->data_items[*(guint16 *)(ip + 1)];
3036 MonoVTable *vt = mono_class_vtable (context->domain, field->parent);
3039 if (!vt->initialized) {
3041 mono_runtime_class_init_full (vt, &error);
3042 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3046 if (context->domain->special_static_fields && (addr = g_hash_table_lookup (context->domain->special_static_fields, field)))
3047 sp->data.p = mono_get_special_static_data (GPOINTER_TO_UINT (addr));
3049 sp->data.p = (char*)(vt->vtable) + field->offset;
3053 MINT_IN_CASE(MINT_LDSFLD) {
3055 MonoClassField *field;
3058 field = rtm->data_items[*(guint16 *)(ip + 1)];
3059 vt = rtm->data_items [*(guint16 *)(ip + 2)];
3060 if (!vt->initialized) {
3062 mono_runtime_class_init_full (vt, &error);
3063 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3066 if (context->domain->special_static_fields && (addr = g_hash_table_lookup (context->domain->special_static_fields, field)))
3067 addr = mono_get_special_static_data (GPOINTER_TO_UINT (addr));
3069 addr = (char*)(vt->vtable) + field->offset;
3071 stackval_from_data (field->type, sp, addr, FALSE);
3075 MINT_IN_CASE(MINT_LDSFLD_I4) {
3076 MonoClassField *field = rtm->data_items[*(guint16 *)(ip + 1)];
3077 MonoVTable *vt = rtm->data_items [*(guint16 *)(ip + 2)];
3078 if (!vt->initialized) {
3080 mono_runtime_class_init_full (vt, &error);
3081 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3084 sp->data.i = * (gint32 *)((char*)(vt->vtable) + field->offset);
3088 MINT_IN_CASE(MINT_LDSFLD_O) {
3089 MonoClassField *field = rtm->data_items[*(guint16 *)(ip + 1)];
3090 MonoVTable *vt = rtm->data_items [*(guint16 *)(ip + 2)];
3091 if (!vt->initialized) {
3093 mono_runtime_class_init_full (vt, &error);
3094 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3097 sp->data.p = * (gpointer *)((char*)(vt->vtable) + field->offset);
3101 MINT_IN_CASE(MINT_LDSFLD_VT) {
3103 MonoClassField *field;
3108 token = * (guint16 *)(ip + 1);
3109 size = READ32(ip + 2);
3110 field = rtm->data_items[token];
3113 vt = mono_class_vtable (context->domain, field->parent);
3114 if (!vt->initialized) {
3116 mono_runtime_class_init_full (vt, &error);
3117 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3120 if (context->domain->special_static_fields && (addr = g_hash_table_lookup (context->domain->special_static_fields, field)))
3121 addr = mono_get_special_static_data (GPOINTER_TO_UINT (addr));
3123 addr = (char*)(vt->vtable) + field->offset;
3126 vt_sp += (size + 7) & ~7;
3127 stackval_from_data (field->type, sp, addr, FALSE);
3131 MINT_IN_CASE(MINT_STSFLD) {
3133 MonoClassField *field;
3137 token = * (guint16 *)(ip + 1);
3138 field = rtm->data_items[token];
3142 vt = mono_class_vtable (context->domain, field->parent);
3143 if (!vt->initialized) {
3145 mono_runtime_class_init_full (vt, &error);
3146 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3149 if (context->domain->special_static_fields && (addr = g_hash_table_lookup (context->domain->special_static_fields, field)))
3150 addr = mono_get_special_static_data (GPOINTER_TO_UINT (addr));
3152 addr = (char*)(vt->vtable) + field->offset;
3154 stackval_to_data (field->type, sp, addr, FALSE);
3157 MINT_IN_CASE(MINT_STSFLD_VT) {
3159 MonoClassField *field;
3164 token = * (guint16 *)(ip + 1);
3165 size = READ32(ip + 2);
3166 field = rtm->data_items[token];
3169 vt = mono_class_vtable (context->domain, field->parent);
3170 if (!vt->initialized) {
3172 mono_runtime_class_init_full (vt, &error);
3173 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3176 if (context->domain->special_static_fields && (addr = g_hash_table_lookup (context->domain->special_static_fields, field)))
3177 addr = mono_get_special_static_data (GPOINTER_TO_UINT (addr));
3179 addr = (char*)(vt->vtable) + field->offset;
3181 stackval_to_data (field->type, sp, addr, FALSE);
3182 vt_sp -= (size + 7) & ~7;
3185 MINT_IN_CASE(MINT_STOBJ_VT) {
3187 c = rtm->data_items[* (guint16 *)(ip + 1)];
3189 size = mono_class_value_size (c, NULL);
3190 memcpy(sp [-2].data.p, sp [-1].data.p, size);
3191 vt_sp -= (size + 7) & ~7;
3195 MINT_IN_CASE(MINT_STOBJ) {
3197 c = rtm->data_items[* (guint16 *)(ip + 1)];
3199 size = mono_class_value_size (c, NULL);
3200 memcpy(sp [-2].data.p, &sp [-1].data, size);
3204 MINT_IN_CASE(MINT_CONV_OVF_I4_UN_R8)
3205 if (sp [-1].data.f < 0 || sp [-1].data.f > MYGUINT32_MAX)
3206 THROW_EX (mono_get_exception_overflow (), ip);
3207 sp [-1].data.i = (guint32)sp [-1].data.f;
3210 MINT_IN_CASE(MINT_CONV_OVF_U8_I4)
3211 if (sp [-1].data.i < 0)
3212 THROW_EX (mono_get_exception_overflow (), ip);
3213 sp [-1].data.l = sp [-1].data.i;
3216 MINT_IN_CASE(MINT_CONV_OVF_U8_R8)
3217 MINT_IN_CASE(MINT_CONV_OVF_I8_UN_R8)
3218 if (sp [-1].data.f < 0 || sp [-1].data.f > 9223372036854775807LL)
3219 THROW_EX (mono_get_exception_overflow (), ip);
3220 sp [-1].data.l = (guint64)sp [-1].data.f;
3223 MINT_IN_CASE(MINT_CONV_OVF_I8_R8)
3224 if (sp [-1].data.f < MYGINT64_MIN || sp [-1].data.f > MYGINT64_MAX)
3225 THROW_EX (mono_get_exception_overflow (), ip);
3226 sp [-1].data.l = (gint64)sp [-1].data.f;
3229 MINT_IN_CASE(MINT_CONV_OVF_I4_UN_I8)
3230 if ((mono_u)sp [-1].data.l > MYGUINT32_MAX)
3231 THROW_EX (mono_get_exception_overflow (), ip);
3232 sp [-1].data.i = (mono_u)sp [-1].data.l;
3235 MINT_IN_CASE(MINT_BOX)
3236 c = rtm->data_items [* (guint16 *)(ip + 1)];
3238 if (c->byval_arg.type == MONO_TYPE_VALUETYPE && !c->enumtype) {
3239 int size = mono_class_value_size (c, NULL);
3240 sp [-1].data.p = mono_value_box_checked (context->domain, c, sp [-1].data.p, &error);
3241 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3242 size = (size + 7) & ~7;
3246 stackval_to_data (&c->byval_arg, &sp [-1], (char*)&sp [-1], FALSE);
3247 sp [-1].data.p = mono_value_box_checked (context->domain, c, &sp [-1], &error);
3248 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3252 MINT_IN_CASE(MINT_NEWARR)
3253 sp [-1].data.p = (MonoObject*) mono_array_new_checked (context->domain, rtm->data_items[*(guint16 *)(ip + 1)], sp [-1].data.i, &error);
3254 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3256 /*if (profiling_classes) {
3257 guint count = GPOINTER_TO_UINT (g_hash_table_lookup (profiling_classes, o->vtable->klass));
3259 g_hash_table_insert (profiling_classes, o->vtable->klass, GUINT_TO_POINTER (count));
3263 MINT_IN_CASE(MINT_LDLEN)
3266 THROW_EX (mono_get_exception_null_reference (), ip);
3267 sp [-1].data.nati = mono_array_length ((MonoArray *)o);
3270 MINT_IN_CASE(MINT_GETCHR) {
3274 THROW_EX (mono_get_exception_null_reference (), ip);
3275 i32 = sp [-1].data.i;
3276 if (i32 < 0 || i32 >= mono_string_length (s))
3277 THROW_EX (mono_get_exception_index_out_of_range (), ip);
3279 sp [-1].data.i = mono_string_chars(s)[i32];
3283 MINT_IN_CASE(MINT_STRLEN)
3285 sp [-1].data.i = mono_string_length ((MonoString*)sp [-1].data.p);
3287 MINT_IN_CASE(MINT_ARRAY_RANK)
3290 THROW_EX (mono_get_exception_null_reference (), ip);
3291 sp [-1].data.i = mono_object_class (sp [-1].data.p)->rank;
3294 MINT_IN_CASE(MINT_LDELEMA) {
3298 /*token = READ32 (ip)*/;
3304 aindex = sp [1].data.i;
3305 if (aindex >= mono_array_length ((MonoArray *) o))
3306 THROW_EX (mono_get_exception_index_out_of_range (), ip - 2);
3308 /* check the array element corresponds to token */
3309 esize = mono_array_element_size (((MonoArray *) o)->obj.vtable->klass);
3311 sp->data.p = mono_array_addr_with_size ((MonoArray *) o, esize, aindex);
3315 MINT_IN_CASE(MINT_LDELEM_I1) /* fall through */
3316 MINT_IN_CASE(MINT_LDELEM_U1) /* fall through */
3317 MINT_IN_CASE(MINT_LDELEM_I2) /* fall through */
3318 MINT_IN_CASE(MINT_LDELEM_U2) /* fall through */
3319 MINT_IN_CASE(MINT_LDELEM_I4) /* fall through */
3320 MINT_IN_CASE(MINT_LDELEM_U4) /* fall through */
3321 MINT_IN_CASE(MINT_LDELEM_I8) /* fall through */
3322 MINT_IN_CASE(MINT_LDELEM_I) /* fall through */
3323 MINT_IN_CASE(MINT_LDELEM_R4) /* fall through */
3324 MINT_IN_CASE(MINT_LDELEM_R8) /* fall through */
3325 MINT_IN_CASE(MINT_LDELEM_REF) {
3333 THROW_EX (mono_get_exception_null_reference (), ip);
3335 aindex = sp [1].data.i;
3336 if (aindex >= mono_array_length (o))
3337 THROW_EX (mono_get_exception_index_out_of_range (), ip);
3340 * FIXME: throw mono_get_exception_array_type_mismatch () if needed
3343 case MINT_LDELEM_I1:
3344 sp [0].data.i = mono_array_get (o, gint8, aindex);
3346 case MINT_LDELEM_U1:
3347 sp [0].data.i = mono_array_get (o, guint8, aindex);
3349 case MINT_LDELEM_I2:
3350 sp [0].data.i = mono_array_get (o, gint16, aindex);
3352 case MINT_LDELEM_U2:
3353 sp [0].data.i = mono_array_get (o, guint16, aindex);
3356 sp [0].data.nati = mono_array_get (o, mono_i, aindex);
3358 case MINT_LDELEM_I4:
3359 sp [0].data.i = mono_array_get (o, gint32, aindex);
3361 case MINT_LDELEM_U4:
3362 sp [0].data.i = mono_array_get (o, guint32, aindex);
3364 case MINT_LDELEM_I8:
3365 sp [0].data.l = mono_array_get (o, guint64, aindex);
3367 case MINT_LDELEM_R4:
3368 sp [0].data.f = mono_array_get (o, float, aindex);
3370 case MINT_LDELEM_R8:
3371 sp [0].data.f = mono_array_get (o, double, aindex);
3373 case MINT_LDELEM_REF:
3374 sp [0].data.p = mono_array_get (o, gpointer, aindex);
3384 MINT_IN_CASE(MINT_STELEM_I) /* fall through */
3385 MINT_IN_CASE(MINT_STELEM_I1) /* fall through */
3386 MINT_IN_CASE(MINT_STELEM_I2) /* fall through */
3387 MINT_IN_CASE(MINT_STELEM_I4) /* fall through */
3388 MINT_IN_CASE(MINT_STELEM_I8) /* fall through */
3389 MINT_IN_CASE(MINT_STELEM_R4) /* fall through */
3390 MINT_IN_CASE(MINT_STELEM_R8) /* fall through */
3391 MINT_IN_CASE(MINT_STELEM_REF) {
3398 THROW_EX (mono_get_exception_null_reference (), ip);
3400 aindex = sp [1].data.i;
3401 if (aindex >= mono_array_length ((MonoArray *)o))
3402 THROW_EX (mono_get_exception_index_out_of_range (), ip);
3406 mono_array_set ((MonoArray *)o, mono_i, aindex, sp [2].data.nati);
3408 case MINT_STELEM_I1:
3409 mono_array_set ((MonoArray *)o, gint8, aindex, sp [2].data.i);
3411 case MINT_STELEM_I2:
3412 mono_array_set ((MonoArray *)o, gint16, aindex, sp [2].data.i);
3414 case MINT_STELEM_I4:
3415 mono_array_set ((MonoArray *)o, gint32, aindex, sp [2].data.i);
3417 case MINT_STELEM_I8:
3418 mono_array_set ((MonoArray *)o, gint64, aindex, sp [2].data.l);
3420 case MINT_STELEM_R4:
3421 mono_array_set ((MonoArray *)o, float, aindex, sp [2].data.f);
3423 case MINT_STELEM_R8:
3424 mono_array_set ((MonoArray *)o, double, aindex, sp [2].data.f);
3426 case MINT_STELEM_REF: {
3427 MonoObject *isinst_obj = mono_object_isinst_checked (sp [2].data.p, mono_object_class (o)->element_class, &error);
3428 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3429 if (sp [2].data.p && !isinst_obj)
3430 THROW_EX (mono_get_exception_array_type_mismatch (), ip);
3431 mono_array_set ((MonoArray *)o, gpointer, aindex, sp [2].data.p);
3440 MINT_IN_CASE(MINT_CONV_OVF_I4_U4)
3441 if (sp [-1].data.i < 0)
3442 THROW_EX (mono_get_exception_overflow (), ip);
3445 MINT_IN_CASE(MINT_CONV_OVF_I4_I8)
3446 if (sp [-1].data.l < MYGINT32_MIN || sp [-1].data.l > MYGINT32_MAX)
3447 THROW_EX (mono_get_exception_overflow (), ip);
3448 sp [-1].data.i = (gint32) sp [-1].data.l;
3451 MINT_IN_CASE(MINT_CONV_OVF_I4_R8)
3452 if (sp [-1].data.f < MYGINT32_MIN || sp [-1].data.f > MYGINT32_MAX)
3453 THROW_EX (mono_get_exception_overflow (), ip);
3454 sp [-1].data.i = (gint32) sp [-1].data.f;
3457 MINT_IN_CASE(MINT_CONV_OVF_U4_I4)
3458 if (sp [-1].data.i < 0)
3459 THROW_EX (mono_get_exception_overflow (), ip);
3462 MINT_IN_CASE(MINT_CONV_OVF_U4_I8)
3463 if (sp [-1].data.l < 0 || sp [-1].data.l > MYGUINT32_MAX)
3464 THROW_EX (mono_get_exception_overflow (), ip);
3465 sp [-1].data.i = (guint32) sp [-1].data.l;
3468 MINT_IN_CASE(MINT_CONV_OVF_U4_R8)
3469 if (sp [-1].data.f < 0 || sp [-1].data.f > MYGUINT32_MAX)
3470 THROW_EX (mono_get_exception_overflow (), ip);
3471 sp [-1].data.i = (guint32) sp [-1].data.f;
3474 MINT_IN_CASE(MINT_CONV_OVF_I2_I4)
3475 if (sp [-1].data.i < -32768 || sp [-1].data.i > 32767)
3476 THROW_EX (mono_get_exception_overflow (), ip);
3479 MINT_IN_CASE(MINT_CONV_OVF_I2_I8)
3480 if (sp [-1].data.l < -32768 || sp [-1].data.l > 32767)
3481 THROW_EX (mono_get_exception_overflow (), ip);
3482 sp [-1].data.i = (gint16) sp [-1].data.l;
3485 MINT_IN_CASE(MINT_CONV_OVF_I2_R8)
3486 if (sp [-1].data.f < -32768 || sp [-1].data.f > 32767)
3487 THROW_EX (mono_get_exception_overflow (), ip);
3488 sp [-1].data.i = (gint16) sp [-1].data.f;
3491 MINT_IN_CASE(MINT_CONV_OVF_U2_I4)
3492 if (sp [-1].data.i < 0 || sp [-1].data.i > 65535)
3493 THROW_EX (mono_get_exception_overflow (), ip);
3496 MINT_IN_CASE(MINT_CONV_OVF_U2_I8)
3497 if (sp [-1].data.l < 0 || sp [-1].data.l > 65535)
3498 THROW_EX (mono_get_exception_overflow (), ip);
3499 sp [-1].data.i = (guint16) sp [-1].data.l;
3502 MINT_IN_CASE(MINT_CONV_OVF_U2_R8)
3503 if (sp [-1].data.f < 0 || sp [-1].data.f > 65535)
3504 THROW_EX (mono_get_exception_overflow (), ip);
3505 sp [-1].data.i = (guint16) sp [-1].data.f;
3508 MINT_IN_CASE(MINT_CONV_OVF_I1_I4)
3509 if (sp [-1].data.i < -128 || sp [-1].data.i > 127)
3510 THROW_EX (mono_get_exception_overflow (), ip);
3513 MINT_IN_CASE(MINT_CONV_OVF_I1_I8)
3514 if (sp [-1].data.l < -128 || sp [-1].data.l > 127)
3515 THROW_EX (mono_get_exception_overflow (), ip);
3516 sp [-1].data.i = (gint8) sp [-1].data.l;
3519 MINT_IN_CASE(MINT_CONV_OVF_I1_R8)
3520 if (sp [-1].data.f < -128 || sp [-1].data.f > 127)
3521 THROW_EX (mono_get_exception_overflow (), ip);
3522 sp [-1].data.i = (gint8) sp [-1].data.f;
3525 MINT_IN_CASE(MINT_CONV_OVF_U1_I4)
3526 if (sp [-1].data.i < 0 || sp [-1].data.i > 255)
3527 THROW_EX (mono_get_exception_overflow (), ip);
3530 MINT_IN_CASE(MINT_CONV_OVF_U1_I8)
3531 if (sp [-1].data.l < 0 || sp [-1].data.l > 255)
3532 THROW_EX (mono_get_exception_overflow (), ip);
3533 sp [-1].data.i = (guint8) sp [-1].data.l;
3536 MINT_IN_CASE(MINT_CONV_OVF_U1_R8)
3537 if (sp [-1].data.f < 0 || sp [-1].data.f > 255)
3538 THROW_EX (mono_get_exception_overflow (), ip);
3539 sp [-1].data.i = (guint8) sp [-1].data.f;
3543 MINT_IN_CASE(MINT_LDELEM)
3544 MINT_IN_CASE(MINT_STELEM)
3545 MINT_IN_CASE(MINT_UNBOX_ANY)
3547 MINT_IN_CASE(MINT_REFANYVAL) ves_abort(); MINT_IN_BREAK;
3549 MINT_IN_CASE(MINT_CKFINITE)
3550 if (!isfinite(sp [-1].data.f))
3551 THROW_EX (mono_get_exception_arithmetic (), ip);
3555 MINT_IN_CASE(MINT_MKREFANY) ves_abort(); MINT_IN_BREAK;
3557 MINT_IN_CASE(MINT_LDTOKEN)
3560 * (gpointer *)sp->data.p = rtm->data_items[*(guint16 *)(ip + 1)];
3564 MINT_IN_CASE(MINT_ADD_OVF_I4)
3565 if (CHECK_ADD_OVERFLOW (sp [-2].data.i, sp [-1].data.i))
3566 THROW_EX (mono_get_exception_overflow (), ip);
3569 MINT_IN_CASE(MINT_ADD_OVF_I8)
3570 if (CHECK_ADD_OVERFLOW64 (sp [-2].data.l, sp [-1].data.l))
3571 THROW_EX (mono_get_exception_overflow (), ip);
3574 MINT_IN_CASE(MINT_ADD_OVF_UN_I4)
3575 if (CHECK_ADD_OVERFLOW_UN (sp [-2].data.i, sp [-1].data.i))
3576 THROW_EX (mono_get_exception_overflow (), ip);
3577 BINOP_CAST(i, +, guint32);
3579 MINT_IN_CASE(MINT_ADD_OVF_UN_I8)
3580 if (CHECK_ADD_OVERFLOW64_UN (sp [-2].data.l, sp [-1].data.l))
3581 THROW_EX (mono_get_exception_overflow (), ip);
3582 BINOP_CAST(l, +, guint64);
3584 MINT_IN_CASE(MINT_MUL_OVF_I4)
3585 if (CHECK_MUL_OVERFLOW (sp [-2].data.i, sp [-1].data.i))
3586 THROW_EX (mono_get_exception_overflow (), ip);
3589 MINT_IN_CASE(MINT_MUL_OVF_I8)
3590 if (CHECK_MUL_OVERFLOW64 (sp [-2].data.l, sp [-1].data.l))
3591 THROW_EX (mono_get_exception_overflow (), ip);
3594 MINT_IN_CASE(MINT_MUL_OVF_UN_I4)
3595 if (CHECK_MUL_OVERFLOW_UN (sp [-2].data.i, sp [-1].data.i))
3596 THROW_EX (mono_get_exception_overflow (), ip);
3597 BINOP_CAST(i, *, guint32);
3599 MINT_IN_CASE(MINT_MUL_OVF_UN_I8)
3600 if (CHECK_MUL_OVERFLOW64_UN (sp [-2].data.l, sp [-1].data.l))
3601 THROW_EX (mono_get_exception_overflow (), ip);
3602 BINOP_CAST(l, *, guint64);
3604 MINT_IN_CASE(MINT_SUB_OVF_I4)
3605 if (CHECK_SUB_OVERFLOW (sp [-2].data.i, sp [-1].data.i))
3606 THROW_EX (mono_get_exception_overflow (), ip);
3609 MINT_IN_CASE(MINT_SUB_OVF_I8)
3610 if (CHECK_SUB_OVERFLOW64 (sp [-2].data.l, sp [-1].data.l))
3611 THROW_EX (mono_get_exception_overflow (), ip);
3614 MINT_IN_CASE(MINT_SUB_OVF_UN_I4)
3615 if (CHECK_SUB_OVERFLOW_UN (sp [-2].data.i, sp [-1].data.i))
3616 THROW_EX (mono_get_exception_overflow (), ip);
3617 BINOP_CAST(i, -, guint32);
3619 MINT_IN_CASE(MINT_SUB_OVF_UN_I8)
3620 if (CHECK_SUB_OVERFLOW64_UN (sp [-2].data.l, sp [-1].data.l))
3621 THROW_EX (mono_get_exception_overflow (), ip);
3622 BINOP_CAST(l, -, guint64);
3624 MINT_IN_CASE(MINT_ENDFINALLY)
3626 ip = finally_ips->data;
3627 finally_ips = g_slist_remove (finally_ips, ip);
3634 MINT_IN_CASE(MINT_LEAVE) /* Fall through */
3635 MINT_IN_CASE(MINT_LEAVE_S)
3636 while (sp > frame->stack) {
3640 if (*ip == MINT_LEAVE_S) {
3641 ip += (short) *(ip + 1);
3643 ip += (gint32) READ32 (ip + 1);
3646 if (frame->ex_handler != NULL && MONO_OFFSET_IN_HANDLER(frame->ex_handler, frame->ip - rtm->code)) {
3647 frame->ex_handler = NULL;
3650 goto handle_finally;
3652 MINT_IN_CASE(MINT_ICALL_V_V)
3653 MINT_IN_CASE(MINT_ICALL_V_P)
3654 MINT_IN_CASE(MINT_ICALL_P_V)
3655 MINT_IN_CASE(MINT_ICALL_P_P)
3656 MINT_IN_CASE(MINT_ICALL_PP_V)
3657 MINT_IN_CASE(MINT_ICALL_PI_V)
3658 MINT_IN_CASE(MINT_ICALL_PP_P)
3659 MINT_IN_CASE(MINT_ICALL_PI_P)
3660 MINT_IN_CASE(MINT_ICALL_PPP_V)
3661 MINT_IN_CASE(MINT_ICALL_PPI_V)
3662 sp = do_icall (context, *ip, sp, rtm->data_items [*(guint16 *)(ip + 1)]);
3663 if (frame->ex != NULL)
3664 goto handle_exception;
3667 MINT_IN_CASE(MINT_MONO_LDPTR)
3668 sp->data.p = rtm->data_items [*(guint16 *)(ip + 1)];
3672 MINT_IN_CASE(MINT_MONO_NEWOBJ)
3673 sp->data.p = mono_object_new_checked (context->domain, rtm->data_items [*(guint16 *)(ip + 1)], &error);
3674 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3678 MINT_IN_CASE(MINT_MONO_FREE)
3681 g_error ("that doesn't seem right");
3682 g_free (sp->data.p);
3684 MINT_IN_CASE(MINT_MONO_RETOBJ)
3687 stackval_from_data (mono_method_signature (frame->runtime_method->method)->ret, frame->retval, sp->data.p,
3688 mono_method_signature (frame->runtime_method->method)->pinvoke);
3689 if (sp > frame->stack)
3690 g_warning ("retobj: more values on stack: %d", sp-frame->stack);
3693 #define RELOP(datamem, op) \
3695 sp [-1].data.i = sp [-1].data.datamem op sp [0].data.datamem; \
3697 MINT_IN_CASE(MINT_CEQ_I4)
3700 MINT_IN_CASE(MINT_CEQ0_I4)
3701 sp [-1].data.i = (sp [-1].data.i == 0);
3704 MINT_IN_CASE(MINT_CEQ_I8)
3707 MINT_IN_CASE(MINT_CEQ_R8)
3709 if (isunordered (sp [-1].data.f, sp [0].data.f))
3712 sp [-1].data.i = sp [-1].data.f == sp [0].data.f;
3715 MINT_IN_CASE(MINT_CGT_I4)
3718 MINT_IN_CASE(MINT_CGT_I8)
3721 MINT_IN_CASE(MINT_CGT_R8)
3723 if (isunordered (sp [-1].data.f, sp [0].data.f))
3726 sp [-1].data.i = sp [-1].data.f > sp [0].data.f;
3730 #define RELOP_CAST(datamem, op, type) \
3732 sp [-1].data.i = (type)sp [-1].data.datamem op (type)sp [0].data.datamem; \
3735 MINT_IN_CASE(MINT_CGT_UN_I4)
3736 RELOP_CAST(i, >, guint32);
3738 MINT_IN_CASE(MINT_CGT_UN_I8)
3739 RELOP_CAST(l, >, guint64);
3741 MINT_IN_CASE(MINT_CGT_UN_R8)
3743 if (isunordered (sp [-1].data.f, sp [0].data.f))
3746 sp [-1].data.i = sp [-1].data.f > sp [0].data.f;
3749 MINT_IN_CASE(MINT_CLT_I4)
3752 MINT_IN_CASE(MINT_CLT_I8)
3755 MINT_IN_CASE(MINT_CLT_R8)
3757 if (isunordered (sp [-1].data.f, sp [0].data.f))
3760 sp [-1].data.i = sp [-1].data.f < sp [0].data.f;
3763 MINT_IN_CASE(MINT_CLT_UN_I4)
3764 RELOP_CAST(i, <, guint32);
3766 MINT_IN_CASE(MINT_CLT_UN_I8)
3767 RELOP_CAST(l, <, guint64);
3769 MINT_IN_CASE(MINT_CLT_UN_R8)
3771 if (isunordered (sp [-1].data.f, sp [0].data.f))
3774 sp [-1].data.i = sp [-1].data.f < sp [0].data.f;
3777 MINT_IN_CASE(MINT_LDFTN) {
3778 sp->data.p = rtm->data_items [* (guint16 *)(ip + 1)];
3783 MINT_IN_CASE(MINT_LDVIRTFTN) {
3784 RuntimeMethod *m = rtm->data_items [* (guint16 *)(ip + 1)];
3788 THROW_EX (mono_get_exception_null_reference (), ip - 2);
3790 sp->data.p = get_virtual_method (context->domain, m, sp->data.p);
3795 MINT_IN_CASE(MINT_LDTHISA)
3796 g_error ("should not happen");
3797 // sp->data.p = &frame->obj;
3802 #define LDARG(datamem, argtype) \
3803 sp->data.datamem = * (argtype *)(frame->args + * (guint16 *)(ip + 1)); \
3807 MINT_IN_CASE(MINT_LDARG_I1) LDARG(i, gint8); MINT_IN_BREAK;
3808 MINT_IN_CASE(MINT_LDARG_U1) LDARG(i, guint8); MINT_IN_BREAK;
3809 MINT_IN_CASE(MINT_LDARG_I2) LDARG(i, gint16); MINT_IN_BREAK;
3810 MINT_IN_CASE(MINT_LDARG_U2) LDARG(i, guint16); MINT_IN_BREAK;
3811 MINT_IN_CASE(MINT_LDARG_I4) LDARG(i, gint32); MINT_IN_BREAK;
3812 MINT_IN_CASE(MINT_LDARG_I8) LDARG(l, gint64); MINT_IN_BREAK;
3813 MINT_IN_CASE(MINT_LDARG_R4) LDARG(f, float); MINT_IN_BREAK;
3814 MINT_IN_CASE(MINT_LDARG_R8) LDARG(f, double); MINT_IN_BREAK;
3815 MINT_IN_CASE(MINT_LDARG_O) LDARG(p, gpointer); MINT_IN_BREAK;
3816 MINT_IN_CASE(MINT_LDARG_P) LDARG(p, gpointer); MINT_IN_BREAK;
3818 MINT_IN_CASE(MINT_LDARG_VT)
3820 i32 = READ32(ip + 2);
3821 memcpy(sp->data.p, frame->args + * (guint16 *)(ip + 1), i32);
3822 vt_sp += (i32 + 7) & ~7;
3827 #define STARG(datamem, argtype) \
3829 * (argtype *)(frame->args + * (guint16 *)(ip + 1)) = sp->data.datamem; \
3832 MINT_IN_CASE(MINT_STARG_I1) STARG(i, gint8); MINT_IN_BREAK;
3833 MINT_IN_CASE(MINT_STARG_U1) STARG(i, guint8); MINT_IN_BREAK;
3834 MINT_IN_CASE(MINT_STARG_I2) STARG(i, gint16); MINT_IN_BREAK;
3835 MINT_IN_CASE(MINT_STARG_U2) STARG(i, guint16); MINT_IN_BREAK;
3836 MINT_IN_CASE(MINT_STARG_I4) STARG(i, gint32); MINT_IN_BREAK;
3837 MINT_IN_CASE(MINT_STARG_I8) STARG(l, gint64); MINT_IN_BREAK;
3838 MINT_IN_CASE(MINT_STARG_R4) STARG(f, float); MINT_IN_BREAK;
3839 MINT_IN_CASE(MINT_STARG_R8) STARG(f, double); MINT_IN_BREAK;
3840 MINT_IN_CASE(MINT_STARG_O) STARG(p, gpointer); MINT_IN_BREAK;
3841 MINT_IN_CASE(MINT_STARG_P) STARG(p, gpointer); MINT_IN_BREAK;
3843 MINT_IN_CASE(MINT_STARG_VT)
3844 i32 = READ32(ip + 2);
3846 memcpy(frame->args + * (guint16 *)(ip + 1), sp->data.p, i32);
3847 vt_sp -= (i32 + 7) & ~7;
3851 #define STINARG(datamem, argtype) \
3853 int n = * (guint16 *)(ip + 1); \
3854 * (argtype *)(frame->args + rtm->arg_offsets [n]) = frame->stack_args [n].data.datamem; \
3858 MINT_IN_CASE(MINT_STINARG_I1) STINARG(i, gint8); MINT_IN_BREAK;
3859 MINT_IN_CASE(MINT_STINARG_U1) STINARG(i, guint8); MINT_IN_BREAK;
3860 MINT_IN_CASE(MINT_STINARG_I2) STINARG(i, gint16); MINT_IN_BREAK;
3861 MINT_IN_CASE(MINT_STINARG_U2) STINARG(i, guint16); MINT_IN_BREAK;
3862 MINT_IN_CASE(MINT_STINARG_I4) STINARG(i, gint32); MINT_IN_BREAK;
3863 MINT_IN_CASE(MINT_STINARG_I8) STINARG(l, gint64); MINT_IN_BREAK;
3864 MINT_IN_CASE(MINT_STINARG_R4) STINARG(f, float); MINT_IN_BREAK;
3865 MINT_IN_CASE(MINT_STINARG_R8) STINARG(f, double); MINT_IN_BREAK;
3866 MINT_IN_CASE(MINT_STINARG_O) STINARG(p, gpointer); MINT_IN_BREAK;
3867 MINT_IN_CASE(MINT_STINARG_P) STINARG(p, gpointer); MINT_IN_BREAK;
3869 MINT_IN_CASE(MINT_STINARG_VT) {
3870 int n = * (guint16 *)(ip + 1);
3871 i32 = READ32(ip + 2);
3872 memcpy (frame->args + rtm->arg_offsets [n], frame->stack_args [n].data.p, i32);
3877 MINT_IN_CASE(MINT_LDARGA)
3878 sp->data.p = frame->args + * (guint16 *)(ip + 1);
3883 #define LDLOC(datamem, argtype) \
3884 sp->data.datamem = * (argtype *)(locals + * (guint16 *)(ip + 1)); \
3888 MINT_IN_CASE(MINT_LDLOC_I1) LDLOC(i, gint8); MINT_IN_BREAK;
3889 MINT_IN_CASE(MINT_LDLOC_U1) LDLOC(i, guint8); MINT_IN_BREAK;
3890 MINT_IN_CASE(MINT_LDLOC_I2) LDLOC(i, gint16); MINT_IN_BREAK;
3891 MINT_IN_CASE(MINT_LDLOC_U2) LDLOC(i, guint16); MINT_IN_BREAK;
3892 MINT_IN_CASE(MINT_LDLOC_I4) LDLOC(i, gint32); MINT_IN_BREAK;
3893 MINT_IN_CASE(MINT_LDLOC_I8) LDLOC(l, gint64); MINT_IN_BREAK;
3894 MINT_IN_CASE(MINT_LDLOC_R4) LDLOC(f, float); MINT_IN_BREAK;
3895 MINT_IN_CASE(MINT_LDLOC_R8) LDLOC(f, double); MINT_IN_BREAK;
3896 MINT_IN_CASE(MINT_LDLOC_O) LDLOC(p, gpointer); MINT_IN_BREAK;
3897 MINT_IN_CASE(MINT_LDLOC_P) LDLOC(p, gpointer); MINT_IN_BREAK;
3899 MINT_IN_CASE(MINT_LDLOC_VT)
3901 i32 = READ32(ip + 2);
3902 memcpy(sp->data.p, locals + * (guint16 *)(ip + 1), i32);
3903 vt_sp += (i32 + 7) & ~7;
3908 MINT_IN_CASE(MINT_LDLOCA_S)
3909 sp->data.p = locals + * (guint16 *)(ip + 1);
3914 #define STLOC(datamem, argtype) \
3916 * (argtype *)(locals + * (guint16 *)(ip + 1)) = sp->data.datamem; \
3919 MINT_IN_CASE(MINT_STLOC_I1) STLOC(i, gint8); MINT_IN_BREAK;
3920 MINT_IN_CASE(MINT_STLOC_U1) STLOC(i, guint8); MINT_IN_BREAK;
3921 MINT_IN_CASE(MINT_STLOC_I2) STLOC(i, gint16); MINT_IN_BREAK;
3922 MINT_IN_CASE(MINT_STLOC_U2) STLOC(i, guint16); MINT_IN_BREAK;
3923 MINT_IN_CASE(MINT_STLOC_I4) STLOC(i, gint32); MINT_IN_BREAK;
3924 MINT_IN_CASE(MINT_STLOC_I8) STLOC(l, gint64); MINT_IN_BREAK;
3925 MINT_IN_CASE(MINT_STLOC_R4) STLOC(f, float); MINT_IN_BREAK;
3926 MINT_IN_CASE(MINT_STLOC_R8) STLOC(f, double); MINT_IN_BREAK;
3927 MINT_IN_CASE(MINT_STLOC_O) STLOC(p, gpointer); MINT_IN_BREAK;
3928 MINT_IN_CASE(MINT_STLOC_P) STLOC(p, gpointer); MINT_IN_BREAK;
3930 #define STLOC_NP(datamem, argtype) \
3931 * (argtype *)(locals + * (guint16 *)(ip + 1)) = sp [-1].data.datamem; \
3934 MINT_IN_CASE(MINT_STLOC_NP_I4) STLOC_NP(i, gint32); MINT_IN_BREAK;
3935 MINT_IN_CASE(MINT_STLOC_NP_O) STLOC_NP(p, gpointer); MINT_IN_BREAK;
3937 MINT_IN_CASE(MINT_STLOC_VT)
3938 i32 = READ32(ip + 2);
3940 memcpy(locals + * (guint16 *)(ip + 1), sp->data.p, i32);
3941 vt_sp -= (i32 + 7) & ~7;
3945 MINT_IN_CASE(MINT_LOCALLOC)
3946 if (sp != frame->stack + 1) /*FIX?*/
3947 THROW_EX (mono_get_exception_execution_engine (NULL), ip);
3948 sp [-1].data.p = alloca (sp [-1].data.i);
3952 MINT_IN_CASE(MINT_ENDFILTER) ves_abort(); MINT_IN_BREAK;
3954 MINT_IN_CASE(MINT_INITOBJ)
3956 memset (sp->data.vt, 0, READ32(ip + 1));
3959 MINT_IN_CASE(MINT_CPBLK)
3961 if (!sp [0].data.p || !sp [1].data.p)
3962 THROW_EX (mono_get_exception_null_reference(), ip - 1);
3964 /* FIXME: value and size may be int64... */
3965 memcpy (sp [0].data.p, sp [1].data.p, sp [2].data.i);
3968 MINT_IN_CASE(MINT_CONSTRAINED_) {
3970 /* FIXME: implement */
3972 token = READ32 (ip);
3977 MINT_IN_CASE(MINT_INITBLK)
3980 THROW_EX (mono_get_exception_null_reference(), ip - 1);
3982 /* FIXME: value and size may be int64... */
3983 memset (sp [0].data.p, sp [1].data.i, sp [2].data.i);
3986 MINT_IN_CASE(MINT_NO_)
3987 /* FIXME: implement */
3991 MINT_IN_CASE(MINT_RETHROW)
3993 * need to clarify what this should actually do:
3994 * start the search from the last found handler in
3995 * this method or continue in the caller or what.
3996 * Also, do we need to run finally/fault handlers after a retrow?
3997 * Well, this implementation will follow the usual search
3998 * for an handler, considering the current ip as throw spot.
3999 * We need to NULL frame->ex_handler for the later code to
4000 * actually run the new found handler.
4002 frame->ex_handler = NULL;
4003 THROW_EX (frame->ex, ip - 1);
4006 g_print ("Unimplemented opcode: %04x %s at 0x%x\n", *ip, mono_interp_opname[*ip], ip-rtm->code);
4007 THROW_EX (mono_get_exception_execution_engine ("Unimplemented opcode"), ip);
4011 g_assert_not_reached ();
4013 * Exception handling code.
4014 * The exception object is stored in frame->ex.
4021 MonoInvocation *inv;
4022 MonoExceptionClause *clause;
4028 g_print ("* Handling exception '%s' at IL_%04x\n",
4029 frame->ex == NULL ? "** Unknown **" : mono_object_class (frame->ex)->name,
4030 rtm == NULL ? 0 : frame->ip - rtm->code);
4032 if (die_on_exception)
4035 for (inv = frame; inv; inv = inv->parent) {
4037 if (inv->runtime_method == NULL)
4039 method = inv->runtime_method->method;
4040 if (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL)
4042 if (method->iflags & (METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL | METHOD_IMPL_ATTRIBUTE_RUNTIME))
4044 if (inv->ip == NULL)
4046 ip_offset = inv->ip - inv->runtime_method->code;
4047 inv->ex_handler = NULL; /* clear this in case we are trhowing an exception while handling one - this one wins */
4048 for (i = 0; i < inv->runtime_method->num_clauses; ++i) {
4049 clause = &inv->runtime_method->clauses [i];
4050 if (clause->flags <= 1 && MONO_OFFSET_IN_CLAUSE (clause, ip_offset)) {
4051 if (!clause->flags) {
4052 MonoObject *isinst_obj = mono_object_isinst_checked ((MonoObject*)frame->ex, clause->data.catch_class, &error);
4053 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4056 * OK, we found an handler, now we need to execute the finally
4057 * and fault blocks before branching to the handler code.
4059 inv->ex_handler = clause;
4062 g_print ("* Found handler at '%s'\n", method->name);
4064 goto handle_finally;
4067 /* FIXME: handle filter clauses */
4074 * If we get here, no handler was found: print a stack trace.
4076 for (inv = frame; inv; inv = inv->parent) {
4077 if (inv->invoke_trap)
4078 goto handle_finally;
4081 ex_obj = (MonoObject*)frame->ex;
4082 mono_unhandled_exception (ex_obj);
4089 MonoExceptionClause *clause;
4090 GSList *old_list = finally_ips;
4091 MonoMethod *method = frame->runtime_method->method;
4092 MonoMethodHeader *header = mono_method_get_header_checked (method, &error);
4093 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4097 g_print ("* Handle finally IL_%04x\n", endfinally_ip == NULL ? 0 : endfinally_ip - rtm->code);
4099 if (rtm == NULL || (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL)
4100 || (method->iflags & (METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL | METHOD_IMPL_ATTRIBUTE_RUNTIME))) {
4103 ip_offset = frame->ip - rtm->code;
4105 if (endfinally_ip != NULL)
4106 finally_ips = g_slist_prepend(finally_ips, (void *)endfinally_ip);
4107 for (i = 0; i < header->num_clauses; ++i)
4108 if (frame->ex_handler == &rtm->clauses [i])
4112 clause = &rtm->clauses [i];
4113 if (MONO_OFFSET_IN_CLAUSE (clause, ip_offset) && (endfinally_ip == NULL || !(MONO_OFFSET_IN_CLAUSE (clause, endfinally_ip - rtm->code)))) {
4114 if (clause->flags == MONO_EXCEPTION_CLAUSE_FINALLY) {
4115 ip = rtm->code + clause->handler_offset;
4116 finally_ips = g_slist_prepend (finally_ips, (gpointer) ip);
4119 g_print ("* Found finally at IL_%04x with exception: %s\n", clause->handler_offset, frame->ex? "yes": "no");
4125 endfinally_ip = NULL;
4127 if (old_list != finally_ips && finally_ips) {
4128 ip = finally_ips->data;
4129 finally_ips = g_slist_remove (finally_ips, ip);
4130 sp = frame->stack; /* spec says stack should be empty at endfinally so it should be at the start too */
4135 * If an exception is set, we need to execute the fault handler, too,
4136 * otherwise, we continue normally.
4146 MonoExceptionClause *clause;
4147 MonoMethod *method = frame->runtime_method->method;
4148 MonoMethodHeader *header = mono_method_get_header_checked (method, &error);
4149 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4153 g_print ("* Handle fault\n");
4155 ip_offset = frame->ip - rtm->code;
4156 for (i = 0; i < header->num_clauses; ++i) {
4157 clause = &rtm->clauses [i];
4158 if (clause->flags == MONO_EXCEPTION_CLAUSE_FAULT && MONO_OFFSET_IN_CLAUSE (clause, ip_offset)) {
4159 ip = rtm->code + clause->handler_offset;
4162 g_print ("* Executing handler at IL_%04x\n", clause->handler_offset);
4168 * If the handler for the exception was found in this method, we jump
4169 * to it right away, otherwise we return and let the caller run
4170 * the finally, fault and catch blocks.
4171 * This same code should be present in the endfault opcode, but it
4172 * is corrently not assigned in the ECMA specs: LAMESPEC.
4174 if (frame->ex_handler) {
4177 g_print ("* Executing handler at IL_%04x\n", frame->ex_handler->handler_offset);
4179 ip = rtm->code + frame->ex_handler->handler_offset;
4181 vt_sp = (unsigned char *) sp + rtm->stack_size;
4182 sp->data.p = frame->ex;
4193 ves_exec_method (MonoInvocation *frame)
4195 ThreadContext *context = mono_native_tls_get_value (thread_context_id);
4196 ThreadContext context_struct;
4203 mono_unhandled_exception ((MonoObject*)frame->ex);
4206 if (context == NULL) {
4207 context = &context_struct;
4208 context_struct.domain = mono_domain_get ();
4209 context_struct.base_frame = frame;
4210 context_struct.current_frame = NULL;
4211 context_struct.env_frame = frame;
4212 context_struct.current_env = &env;
4213 context_struct.search_for_handler = 0;
4214 context_struct.managed_code = 0;
4215 mono_native_tls_set_value (thread_context_id, context);
4218 frame->parent = context->current_frame;
4219 frame->runtime_method = mono_interp_get_runtime_method (context->domain, frame->method, &error);
4220 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4221 context->managed_code = 1;
4222 ves_exec_method_with_context (frame, context);
4223 context->managed_code = 0;
4225 if (context != &context_struct && context->current_env) {
4226 context->env_frame->ex = frame->ex;
4227 longjmp (*context->current_env, 1);
4230 mono_unhandled_exception ((MonoObject*)frame->ex);
4232 if (context->base_frame == frame)
4233 mono_native_tls_set_value (thread_context_id, NULL);
4235 context->current_frame = frame->parent;
4239 ves_exec (MonoDomain *domain, MonoAssembly *assembly, int argc, char *argv[])
4241 MonoImage *image = mono_assembly_get_image (assembly);
4246 method = mono_get_method_checked (image, mono_image_get_entry_point (image), NULL, NULL, &error);
4247 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4250 g_error ("No entry point method found in %s", mono_image_get_filename (image));
4252 rval = mono_runtime_run_main_checked (method, argc, argv, &error);
4253 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4261 "mint %s, the Mono ECMA CLI interpreter, (C) 2001, 2002 Ximian, Inc.\n\n"
4262 "Usage is: mint [options] executable args...\n\n", VERSION);
4264 "Runtime Debugging:\n"
4269 " --noptr\t\t\tdon't print pointer addresses in trace output\n"
4272 " --traceclassinit\n"
4275 " --debug method_name\n"
4282 " --config filename load the specified config file instead of the default\n"
4283 " --workers n maximum number of worker threads\n"
4289 interp_ves_icall_get_frame_info (gint32 skip, MonoBoolean need_file_info,
4290 MonoReflectionMethod **method,
4291 gint32 *iloffset, gint32 *native_offset,
4292 MonoString **file, gint32 *line, gint32 *column)
4294 ThreadContext *context = mono_native_tls_get_value (thread_context_id);
4295 MonoInvocation *inv = context->current_frame;
4299 for (i = 0; inv && i < skip; inv = inv->parent)
4300 if (inv->runtime_method != NULL)
4311 *method = mono_method_get_object_checked (context->domain, inv->runtime_method->method, NULL, &error);
4312 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4317 if (need_file_info) {
4321 *file = mono_string_new (mono_domain_get (), "unknown");
4328 interp_ves_icall_get_trace (MonoException *exc, gint32 skip, MonoBoolean need_file_info)
4330 MonoDomain *domain = mono_domain_get ();
4332 MonoArray *ta = exc->trace_ips;
4337 /* Exception is not thrown yet */
4338 MonoArray *array = mono_array_new_checked (domain, mono_defaults.stack_frame_class, 0, &error);
4339 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4343 len = mono_array_length (ta);
4345 res = mono_array_new_checked (domain, mono_defaults.stack_frame_class, len > skip ? len - skip : 0, &error);
4346 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4348 for (i = skip; i < len / 2; i++) {
4349 MonoStackFrame *sf = (MonoStackFrame *)mono_object_new_checked (domain, mono_defaults.stack_frame_class, &error);
4350 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4351 gushort *ip = mono_array_get (ta, gpointer, 2 * i + 1);
4352 RuntimeMethod *rtm = mono_array_get (ta, gpointer, 2 * i);
4355 sf->method = mono_method_get_object_checked (domain, rtm->method, NULL, &error);
4356 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4357 sf->native_offset = ip - rtm->code;
4361 sf->il_offset = mono_debug_il_offset_from_address (ji->method, sf->native_offset, domain);
4363 if (need_file_info) {
4366 filename = mono_debug_source_location_from_address (ji->method, sf->native_offset, &sf->line, domain);
4368 sf->filename = filename? mono_string_new (domain, filename): NULL;
4375 mono_array_set (res, gpointer, i, sf);
4382 ves_icall_System_Delegate_CreateDelegate_internal (MonoReflectionType *type, MonoObject *target, MonoReflectionMethod *info)
4384 MonoClass *delegate_class = mono_class_from_mono_type (type->type);
4385 MonoObject *delegate;
4388 g_assert (delegate_class->parent == mono_defaults.multicastdelegate_class);
4390 delegate = mono_object_new_checked (mono_object_domain (type), delegate_class, &error);
4391 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4393 interp_delegate_ctor (mono_object_domain (type), delegate, target, mono_interp_get_runtime_method (mono_get_root_domain (), info->method, &error));
4394 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4402 mono_native_tls_alloc (&thread_context_id, NULL);
4403 mono_native_tls_set_value (thread_context_id, NULL);
4404 mono_os_mutex_init_recursive (&runtime_method_lookup_section);
4405 mono_os_mutex_init_recursive (&create_method_pointer_mutex);
4407 mono_interp_transform_init ();
4410 typedef int (*TestMethod) (void);
4413 interp_regression_step (MonoImage *image, int verbose, int *total_run, int *total, GTimer *timer, MonoDomain *domain)
4415 int result, expected, failed, cfailed, run;
4416 double elapsed, transform_time;
4418 MonoObject *result_obj;
4419 static gboolean filter_method_init = FALSE;
4420 static const char *filter_method = NULL;
4422 g_print ("Test run: image=%s\n", mono_image_get_filename (image));
4423 cfailed = failed = run = 0;
4424 transform_time = elapsed = 0.0;
4427 /* fixme: ugly hack - delete all previously compiled methods */
4428 if (domain_jit_info (domain)) {
4429 g_hash_table_destroy (domain_jit_info (domain)->jit_trampoline_hash);
4430 domain_jit_info (domain)->jit_trampoline_hash = g_hash_table_new (mono_aligned_addr_hash, NULL);
4431 mono_internal_hash_table_destroy (&(domain->jit_code_hash));
4432 mono_jit_code_hash_init (&(domain->jit_code_hash));
4436 g_timer_start (timer);
4437 for (i = 0; i < mono_image_get_table_rows (image, MONO_TABLE_METHOD); ++i) {
4439 MonoMethod *method = mono_get_method_checked (image, MONO_TOKEN_METHOD_DEF | (i + 1), NULL, NULL, &error);
4441 mono_error_cleanup (&error); /* FIXME don't swallow the error */
4445 if (!filter_method_init) {
4446 filter_method = g_getenv ("INTERP_FILTER_METHOD");
4447 filter_method_init = TRUE;
4449 gboolean filter = FALSE;
4450 if (filter_method) {
4451 const char *name = filter_method;
4453 if ((strchr (name, '.') > name) || strchr (name, ':')) {
4454 MonoMethodDesc *desc = mono_method_desc_new (name, TRUE);
4455 filter = mono_method_desc_full_match (desc, method);
4456 mono_method_desc_free (desc);
4458 filter = strcmp (method->name, name) == 0;
4460 } else { // no filter
4463 if (strncmp (method->name, "test_", 5) == 0 && filter) {
4464 MonoError interp_error;
4465 MonoObject *exc = NULL;
4467 result_obj = interp_mono_runtime_invoke (method, NULL, NULL, &exc, &interp_error);
4468 if (!mono_error_ok (&interp_error)) {
4470 g_print ("Test '%s' execution failed.\n", method->name);
4471 } else if (exc != NULL) {
4472 g_print ("Exception in Test '%s' occured:\n", method->name);
4473 mono_object_describe (exc);
4477 result = *(gint32 *) mono_object_unbox (result_obj);
4478 expected = atoi (method->name + 5); // FIXME: oh no.
4481 if (result != expected) {
4483 g_print ("Test '%s' failed result (got %d, expected %d).\n", method->name, result, expected);
4488 g_timer_stop (timer);
4489 elapsed = g_timer_elapsed (timer, NULL);
4490 if (failed > 0 || cfailed > 0){
4491 g_print ("Results: total tests: %d, failed: %d, cfailed: %d (pass: %.2f%%)\n",
4492 run, failed, cfailed, 100.0*(run-failed-cfailed)/run);
4494 g_print ("Results: total tests: %d, all pass \n", run);
4497 g_print ("Elapsed time: %f secs (%f, %f)\n\n", elapsed,
4498 elapsed - transform_time, transform_time);
4499 *total += failed + cfailed;
4503 interp_regression (MonoImage *image, int verbose, int *total_run)
4506 GTimer *timer = g_timer_new ();
4507 MonoDomain *domain = mono_domain_get ();
4511 /* load the metadata */
4512 for (i = 0; i < mono_image_get_table_rows (image, MONO_TABLE_METHOD); ++i) {
4514 method = mono_get_method_checked (image, MONO_TOKEN_METHOD_DEF | (i + 1), NULL, NULL, &error);
4516 mono_error_cleanup (&error);
4519 mono_class_init (method->klass);
4524 interp_regression_step (image, verbose, total_run, &total, timer, domain);
4526 g_timer_destroy (timer);
4531 interp_regression_list (int verbose, int count, char *images [])
4533 int i, total, total_run, run;
4535 total_run = total = 0;
4536 for (i = 0; i < count; ++i) {
4537 MonoAssembly *ass = mono_assembly_open (images [i], NULL);
4539 g_warning ("failed to load assembly: %s", images [i]);
4542 total += interp_regression (mono_assembly_get_image (ass), verbose, &run);
4546 g_print ("Overall results: tests: %d, failed: %d (pass: %.2f%%)\n", total_run, total, 100.0*(total_run-total)/total_run);
4548 g_print ("Overall results: tests: %d, 100%% pass\n", total_run);