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 int mono_interp_traceopt = 0;
80 #define INIT_FRAME(frame,parent_frame,obj_this,method_args,method_retval,domain,mono_method,error) \
82 (frame)->parent = (parent_frame); \
83 (frame)->obj = (obj_this); \
84 (frame)->stack_args = (method_args); \
85 (frame)->retval = (method_retval); \
86 (frame)->runtime_method = mono_interp_get_runtime_method ((domain), (mono_method), (error)); \
89 (frame)->invoke_trap = 0; \
92 void ves_exec_method (MonoInvocation *frame);
94 static char* dump_stack (stackval *stack, stackval *sp);
95 static char* dump_frame (MonoInvocation *inv);
96 static MonoArray *get_trace_ips (MonoDomain *domain, MonoInvocation *top);
97 static void ves_exec_method_with_context (MonoInvocation *frame, ThreadContext *context);
99 typedef void (*ICallMethod) (MonoInvocation *frame);
101 static guint32 die_on_exception = 0;
102 static MonoNativeTlsKey thread_context_id;
104 static char* dump_args (MonoInvocation *inv);
106 #define DEBUG_INTERP 0
109 /* If true, then we output the opcodes as we interpret them */
110 static int global_tracing = 1;
112 static int debug_indent_level = 0;
114 static int break_on_method = 0;
115 static int nested_trace = 0;
116 static GList *db_methods = NULL;
123 for (h = 0; h < debug_indent_level; h++)
128 db_match_method (gpointer data, gpointer user_data)
130 MonoMethod *m = (MonoMethod*)user_data;
131 MonoMethodDesc *desc = data;
133 if (mono_method_desc_full_match (desc, m))
137 static void debug_enter (MonoInvocation *frame, int *tracing)
140 g_list_foreach (db_methods, db_match_method, (gpointer)frame->runtime_method->method);
142 *tracing = nested_trace ? (global_tracing = 2, 3) : 2;
146 MonoMethod *method = frame->runtime_method->method;
147 char *mn, *args = dump_args (frame);
148 debug_indent_level++;
150 mn = mono_method_full_name (method, FALSE);
151 g_printerr ("(0x%08x) Entering %s (", mono_thread_internal_current (), mn);
153 g_printerr ("%s)\n", args);
156 if (mono_profiler_events & MONO_PROFILE_ENTER_LEAVE)
157 mono_profiler_method_enter (frame->runtime_method->method);
161 #define DEBUG_LEAVE() \
164 args = dump_retval (frame); \
166 mn = mono_method_full_name (frame->runtime_method->method, FALSE); \
167 g_printerr ("(0x%08x) Leaving %s", mono_thread_internal_current (), mn); \
169 g_printerr (" => %s\n", args); \
171 debug_indent_level--; \
172 if (tracing == 3) global_tracing = 0; \
174 if (mono_profiler_events & MONO_PROFILE_ENTER_LEAVE) \
175 mono_profiler_method_leave (frame->runtime_method->method);
179 static void debug_enter (MonoInvocation *frame, int *tracing)
182 #define DEBUG_LEAVE()
187 interp_ex_handler (MonoException *ex) {
189 ThreadContext *context = mono_native_tls_get_value (thread_context_id);
193 stack_trace = dump_frame (context->current_frame);
194 ex->stack_trace = mono_string_new (mono_domain_get(), stack_trace);
195 g_free (stack_trace);
196 if (context->current_env == NULL || strcmp(ex->object.vtable->klass->name, "ExecutionEngineException") == 0) {
197 char *strace = mono_string_to_utf8_checked (ex->stack_trace, &error);
198 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
199 fprintf(stderr, "Nothing can catch this exception: ");
200 fprintf(stderr, "%s", ex->object.vtable->klass->name);
201 if (ex->message != NULL) {
202 char *m = mono_string_to_utf8_checked (ex->message, &error);
203 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
204 fprintf(stderr, ": %s", m);
207 fprintf(stderr, "\n%s\n", strace);
209 if (ex->inner_ex != NULL) {
210 ex = (MonoException *)ex->inner_ex;
211 fprintf(stderr, "Inner exception: %s", ex->object.vtable->klass->name);
212 if (ex->message != NULL) {
213 char *m = mono_string_to_utf8_checked (ex->message, &error);
214 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
215 fprintf(stderr, ": %s", m);
218 strace = mono_string_to_utf8_checked (ex->stack_trace, &error);
219 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
220 fprintf(stderr, "\n");
221 fprintf(stderr, "%s\n", strace);
224 /* wait for other threads to also collapse */
225 // Sleep(1000); // TODO: proper sleep
228 context->env_frame->ex = ex;
229 context->search_for_handler = 1;
230 longjmp (*context->current_env, 1);
234 ves_real_abort (int line, MonoMethod *mh,
235 const unsigned short *ip, stackval *stack, stackval *sp)
238 fprintf (stderr, "Execution aborted in method: %s::%s\n", mh->klass->name, mh->name);
239 fprintf (stderr, "Line=%d IP=0x%04lx, Aborted execution\n", line,
240 ip-(const unsigned short *)mono_method_get_header_checked (mh, &error)->code);
241 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
242 g_print ("0x%04x %02x\n",
243 ip-(const unsigned short *)mono_method_get_header_checked (mh, &error)->code, *ip);
244 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
246 printf ("\t[%ld] 0x%08x %0.5f\n", sp-stack, sp[-1].data.i, sp[-1].data.f);
249 #define ves_abort() \
251 ves_real_abort(__LINE__, frame->runtime_method->method, ip, frame->stack, sp); \
252 THROW_EX (mono_get_exception_execution_engine (NULL), ip); \
255 static mono_mutex_t runtime_method_lookup_section;
258 mono_interp_get_runtime_method (MonoDomain *domain, MonoMethod *method, MonoError *error)
261 mono_error_init (error);
263 mono_os_mutex_lock (&runtime_method_lookup_section);
264 if ((rtm = mono_internal_hash_table_lookup (&domain->jit_code_hash, method))) {
265 mono_os_mutex_unlock (&runtime_method_lookup_section);
268 rtm = mono_mempool_alloc (domain->mp, sizeof (RuntimeMethod));
269 memset (rtm, 0, sizeof (*rtm));
270 rtm->method = method;
271 rtm->param_count = mono_method_signature (method)->param_count;
272 rtm->hasthis = mono_method_signature (method)->hasthis;
273 rtm->valuetype = method->klass->valuetype;
274 mono_internal_hash_table_insert (&domain->jit_code_hash, method, rtm);
275 mono_os_mutex_unlock (&runtime_method_lookup_section);
281 interp_create_trampoline (MonoDomain *domain, MonoMethod *method, MonoError *error)
283 if (method->iflags & METHOD_IMPL_ATTRIBUTE_SYNCHRONIZED)
284 method = mono_marshal_get_synchronized_wrapper (method);
285 return mono_interp_get_runtime_method (domain, method, error);
288 static inline RuntimeMethod*
289 get_virtual_method (MonoDomain *domain, RuntimeMethod *runtime_method, MonoObject *obj)
291 MonoMethod *m = runtime_method->method;
294 if ((m->flags & METHOD_ATTRIBUTE_FINAL) || !(m->flags & METHOD_ATTRIBUTE_VIRTUAL)) {
295 RuntimeMethod *ret = NULL;
296 if (mono_object_is_transparent_proxy (obj)) {
297 ret = mono_interp_get_runtime_method (domain, mono_marshal_get_remoting_invoke (m), &error);
298 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
299 } else if (m->iflags & METHOD_IMPL_ATTRIBUTE_SYNCHRONIZED) {
300 ret = mono_interp_get_runtime_method (domain, mono_marshal_get_synchronized_wrapper (m), &error);
301 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
303 ret = runtime_method;
308 int slot = mono_method_get_vtable_slot (m);
309 if (mono_class_is_interface (m->klass)) {
310 g_assert (obj->vtable->klass != m->klass);
311 /* TODO: interface offset lookup is slow, go through IMT instead */
312 slot += mono_class_interface_offset (obj->vtable->klass, m->klass);
314 MonoMethod *virtual_method = obj->vtable->klass->vtable [slot];
315 RuntimeMethod *virtual_runtime_method = mono_interp_get_runtime_method (domain, virtual_method, &error);
316 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
317 return virtual_runtime_method;
321 stackval_from_data (MonoType *type, stackval *result, char *data, gboolean pinvoke)
324 switch (type->type) {
325 case MONO_TYPE_OBJECT:
326 case MONO_TYPE_CLASS:
327 case MONO_TYPE_STRING:
328 case MONO_TYPE_ARRAY:
329 case MONO_TYPE_SZARRAY:
334 result->data.p = *(gpointer*)data;
337 switch (type->type) {
341 result->data.i = *(gint8*)data;
344 case MONO_TYPE_BOOLEAN:
345 result->data.i = *(guint8*)data;
348 result->data.i = *(gint16*)data;
352 result->data.i = *(guint16*)data;
355 result->data.i = *(gint32*)data;
359 result->data.nati = *(mono_i*)data;
362 result->data.p = *(gpointer*)data;
365 result->data.i = *(guint32*)data;
368 result->data.f = *(float*)data;
372 result->data.l = *(gint64*)data;
375 result->data.f = *(double*)data;
377 case MONO_TYPE_STRING:
378 case MONO_TYPE_SZARRAY:
379 case MONO_TYPE_CLASS:
380 case MONO_TYPE_OBJECT:
381 case MONO_TYPE_ARRAY:
382 result->data.p = *(gpointer*)data;
384 case MONO_TYPE_VALUETYPE:
385 if (type->data.klass->enumtype) {
386 stackval_from_data (mono_class_enum_basetype (type->data.klass), result, data, pinvoke);
392 size = mono_class_native_size (type->data.klass, NULL);
394 size = mono_class_value_size (type->data.klass, NULL);
395 memcpy (result->data.vt, data, size);
399 g_warning ("got type 0x%02x", type->type);
400 g_assert_not_reached ();
405 stackval_to_data (MonoType *type, stackval *val, char *data, gboolean pinvoke)
408 gpointer *p = (gpointer*)data;
412 /* printf ("TODAT0 %p\n", data); */
413 switch (type->type) {
416 guint8 *p = (guint8*)data;
420 case MONO_TYPE_BOOLEAN: {
421 guint8 *p = (guint8*)data;
422 *p = (val->data.i != 0);
427 case MONO_TYPE_CHAR: {
428 guint16 *p = (guint16*)data;
433 mono_i *p = (mono_i*)data;
434 /* In theory the value used by stloc should match the local var type
435 but in practice it sometimes doesn't (a int32 gets dup'd and stloc'd into
436 a native int - both by csc and mcs). Not sure what to do about sign extension
437 as it is outside the spec... doing the obvious */
438 *p = (mono_i)val->data.nati;
442 mono_u *p = (mono_u*)data;
444 *p = (mono_u)val->data.nati;
449 gint32 *p = (gint32*)data;
455 gint64 *p = (gint64*)data;
460 float *p = (float*)data;
465 double *p = (double*)data;
469 case MONO_TYPE_STRING:
470 case MONO_TYPE_SZARRAY:
471 case MONO_TYPE_CLASS:
472 case MONO_TYPE_OBJECT:
473 case MONO_TYPE_ARRAY:
474 case MONO_TYPE_PTR: {
475 gpointer *p = (gpointer*)data;
479 case MONO_TYPE_VALUETYPE:
480 if (type->data.klass->enumtype) {
481 stackval_to_data (mono_class_enum_basetype (type->data.klass), val, data, pinvoke);
487 size = mono_class_native_size (type->data.klass, NULL);
489 size = mono_class_value_size (type->data.klass, NULL);
491 memcpy (data, val->data.p, size);
495 g_warning ("got type %x", type->type);
496 g_assert_not_reached ();
501 fill_in_trace (MonoException *exception, MonoInvocation *frame)
503 char *stack_trace = dump_frame (frame);
504 MonoDomain *domain = mono_domain_get();
505 (exception)->stack_trace = mono_string_new (domain, stack_trace);
506 (exception)->trace_ips = get_trace_ips (domain, frame);
507 g_free (stack_trace);
510 #define FILL_IN_TRACE(exception, frame) fill_in_trace(exception, frame)
512 #define THROW_EX(exception,ex_ip) \
514 frame->ip = (ex_ip); \
515 frame->ex = (MonoException*)(exception); \
516 FILL_IN_TRACE(frame->ex, frame); \
517 goto handle_exception; \
521 ves_array_create (MonoDomain *domain, MonoClass *klass, MonoMethodSignature *sig, stackval *values)
524 intptr_t *lower_bounds;
529 lengths = alloca (sizeof (uintptr_t) * klass->rank * 2);
530 for (i = 0; i < sig->param_count; ++i) {
531 lengths [i] = values->data.i;
534 if (klass->rank == sig->param_count) {
535 /* Only lengths provided. */
538 /* lower bounds are first. */
539 lower_bounds = (intptr_t *) lengths;
540 lengths += klass->rank;
542 obj = (MonoObject*) mono_array_new_full_checked (domain, klass, lengths, lower_bounds, &error);
543 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
548 ves_array_set (MonoInvocation *frame)
550 stackval *sp = frame->stack_args;
554 gint32 i, t, pos, esize;
560 ac = o->vtable->klass;
562 g_assert (ac->rank >= 1);
565 if (ao->bounds != NULL) {
566 pos -= ao->bounds [0].lower_bound;
567 for (i = 1; i < ac->rank; i++) {
568 if ((t = sp [i].data.i - ao->bounds [i].lower_bound) >=
569 ao->bounds [i].length) {
570 frame->ex = mono_get_exception_index_out_of_range ();
571 FILL_IN_TRACE(frame->ex, frame);
574 pos = pos*ao->bounds [i].length + sp [i].data.i -
575 ao->bounds [i].lower_bound;
577 } else if (pos >= ao->max_length) {
578 frame->ex = mono_get_exception_index_out_of_range ();
579 FILL_IN_TRACE(frame->ex, frame);
583 if (sp [ac->rank].data.p && !mono_object_class (o)->element_class->valuetype) {
585 MonoObject *isinst = mono_object_isinst_checked (sp [ac->rank].data.p, mono_object_class (o)->element_class, &error);
586 mono_error_cleanup (&error);
588 frame->ex = mono_get_exception_array_type_mismatch ();
589 FILL_IN_TRACE (frame->ex, frame);
594 esize = mono_array_element_size (ac);
595 ea = mono_array_addr_with_size (ao, esize, pos);
597 mt = mono_method_signature (frame->runtime_method->method)->params [ac->rank];
598 stackval_to_data (mt, &sp [ac->rank], ea, FALSE);
602 ves_array_get (MonoInvocation *frame)
604 stackval *sp = frame->stack_args;
608 gint32 i, t, pos, esize;
614 ac = o->vtable->klass;
616 g_assert (ac->rank >= 1);
619 if (ao->bounds != NULL) {
620 pos -= ao->bounds [0].lower_bound;
621 for (i = 1; i < ac->rank; i++) {
622 if ((t = sp [i].data.i - ao->bounds [i].lower_bound) >=
623 ao->bounds [i].length) {
624 frame->ex = mono_get_exception_index_out_of_range ();
625 FILL_IN_TRACE(frame->ex, frame);
629 pos = pos*ao->bounds [i].length + sp [i].data.i -
630 ao->bounds [i].lower_bound;
632 } else if (pos >= ao->max_length) {
633 frame->ex = mono_get_exception_index_out_of_range ();
634 FILL_IN_TRACE(frame->ex, frame);
638 esize = mono_array_element_size (ac);
639 ea = mono_array_addr_with_size (ao, esize, pos);
641 mt = mono_method_signature (frame->runtime_method->method)->ret;
642 stackval_from_data (mt, frame->retval, ea, FALSE);
646 ves_array_element_address (MonoInvocation *frame)
648 stackval *sp = frame->stack_args;
652 gint32 i, t, pos, esize;
657 ac = o->vtable->klass;
659 g_assert (ac->rank >= 1);
662 if (ao->bounds != NULL) {
663 pos -= ao->bounds [0].lower_bound;
664 for (i = 1; i < ac->rank; i++) {
665 if ((t = sp [i].data.i - ao->bounds [i].lower_bound) >=
666 ao->bounds [i].length) {
667 frame->ex = mono_get_exception_index_out_of_range ();
668 FILL_IN_TRACE(frame->ex, frame);
671 pos = pos*ao->bounds [i].length + sp [i].data.i -
672 ao->bounds [i].lower_bound;
674 } else if (pos >= ao->max_length) {
675 frame->ex = mono_get_exception_index_out_of_range ();
676 FILL_IN_TRACE(frame->ex, frame);
680 esize = mono_array_element_size (ac);
681 ea = mono_array_addr_with_size (ao, esize, pos);
683 frame->retval->data.p = ea;
687 interp_walk_stack (MonoStackWalk func, gboolean do_il_offset, gpointer user_data)
689 ThreadContext *context = mono_native_tls_get_value (thread_context_id);
690 MonoInvocation *frame;
692 MonoMethodHeader *hd;
695 if (!context) return;
697 frame = context->current_frame;
700 gboolean managed = FALSE;
701 MonoMethod *method = frame->runtime_method->method;
702 if (!method || (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) || (method->iflags & (METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL | METHOD_IMPL_ATTRIBUTE_RUNTIME)))
705 hd = mono_method_get_header_checked (method, &error);
706 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
707 il_offset = frame->ip - (const unsigned short *)hd->code;
708 if (!method->wrapper_type)
711 if (func (method, -1, il_offset, managed, user_data))
713 frame = frame->parent;
717 static MonoPIFunc mono_interp_enter_icall_trampoline = NULL;
719 struct _MethodArguments {
727 typedef struct _MethodArguments MethodArguments;
729 // TODO: this function is also arch dependent (register width).
730 static MethodArguments* build_args_from_sig (MonoMethodSignature *sig, MonoInvocation *frame)
732 // TODO: don't malloc this data structure.
733 MethodArguments *margs = g_malloc0 (sizeof (MethodArguments));
738 for (int i = 0; i < sig->param_count; i++) {
739 guint32 ptype = sig->params [i]->byref ? MONO_TYPE_PTR : sig->params [i]->type;
741 case MONO_TYPE_BOOLEAN:
752 case MONO_TYPE_SZARRAY:
753 case MONO_TYPE_CLASS:
754 case MONO_TYPE_OBJECT:
755 case MONO_TYPE_STRING:
760 g_error ("build_args_from_sig: not implemented yet (1): 0x%x\n", ptype);
765 margs->iargs = g_malloc0 (sizeof (gpointer) * margs->ilen);
768 g_error ("build_args_from_sig: TODO, more than two iregs: %d\n", margs->ilen);
771 g_error ("build_args_from_sig: TODO, allocate floats: %d\n", margs->flen);
777 margs->iargs [0] = frame->obj;
781 for (int i = 0; i < sig->param_count; i++) {
782 guint32 ptype = sig->params [i]->byref ? MONO_TYPE_PTR : sig->params [i]->type;
784 case MONO_TYPE_BOOLEAN:
795 case MONO_TYPE_SZARRAY:
796 case MONO_TYPE_CLASS:
797 case MONO_TYPE_OBJECT:
798 case MONO_TYPE_STRING:
800 margs->iargs [int_i] = frame->stack_args [i].data.p;
802 g_printerr ("build_args_from_sig: margs->iargs[%d]: %p (frame @ %d)\n", int_i, margs->iargs[int_i], i);
807 g_error ("build_args_from_sig: not implemented yet (2): 0x%x\n", ptype);
811 if (sig->ret->type != MONO_TYPE_VOID) {
812 margs->retval = &(frame->retval->data.p);
814 margs->retval = NULL;
821 ves_pinvoke_method (MonoInvocation *frame, MonoMethodSignature *sig, MonoFuncV addr, gboolean string_ctor, ThreadContext *context)
824 MonoInvocation *old_frame = context->current_frame;
825 MonoInvocation *old_env_frame = context->env_frame;
826 jmp_buf *old_env = context->current_env;
829 context->current_frame = old_frame;
830 context->env_frame = old_env_frame;
831 context->current_env = old_env;
832 context->managed_code = 1;
837 context->env_frame = frame;
838 context->current_env = &env;
840 g_assert (!frame->runtime_method);
841 if (!mono_interp_enter_icall_trampoline) {
843 mono_interp_enter_icall_trampoline = mono_arch_get_enter_icall_trampoline (&info);
845 // mono_tramp_info_register (info, NULL);
848 MethodArguments *margs = build_args_from_sig (sig, frame);
850 g_printerr ("ICALL: mono_interp_enter_icall_trampoline = %p, addr = %p\n", mono_interp_enter_icall_trampoline, addr);
851 g_printerr ("margs(out): ilen=%d, flen=%d\n", margs->ilen, margs->flen);
854 context->current_frame = frame;
855 context->managed_code = 0;
857 mono_interp_enter_icall_trampoline (addr, margs);
859 context->managed_code = 1;
860 /* domain can only be changed by native code */
861 context->domain = mono_domain_get ();
863 if (*mono_thread_interruption_request_flag ())
864 mono_thread_interruption_checkpoint ();
866 if (!MONO_TYPE_ISSTRUCT (sig->ret))
867 stackval_from_data (sig->ret, frame->retval, (char*)&frame->retval->data.p, sig->pinvoke);
869 context->current_frame = old_frame;
870 context->env_frame = old_env_frame;
871 context->current_env = old_env;
873 g_free (margs->iargs);
874 g_free (margs->fargs);
879 interp_delegate_ctor (MonoDomain *domain, MonoObject *this, MonoObject *target, RuntimeMethod *runtime_method)
881 MonoDelegate *delegate = (MonoDelegate *)this;
884 delegate->method_info = mono_method_get_object_checked (domain, runtime_method->method, NULL, &error);
885 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
886 delegate->target = target;
888 if (target && mono_object_is_transparent_proxy (target)) {
889 MonoMethod *method = mono_marshal_get_remoting_invoke (runtime_method->method);
890 delegate->method_ptr = mono_interp_get_runtime_method (domain, method, &error);
891 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
893 delegate->method_ptr = runtime_method;
898 mono_interp_ftnptr_to_delegate (MonoClass *klass, gpointer ftn)
902 MonoDomain *domain = mono_domain_get ();
905 d = (MonoDelegate*)mono_object_new_checked (domain, klass, &error);
906 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
908 ji = mono_jit_info_table_find (domain, ftn);
910 mono_raise_exception (mono_get_exception_argument ("", "Function pointer was not created by a Delegate."));
912 /* FIXME: discard the wrapper and call the original method */
913 interp_delegate_ctor (domain, (MonoObject*)d, NULL, mono_interp_get_runtime_method (domain, ji->d.method, &error));
914 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
921 * runtime specifies that the implementation of the method is automatically
922 * provided by the runtime and is primarily used for the methods of delegates.
925 ves_runtime_method (MonoInvocation *frame, ThreadContext *context)
927 MonoMethod *method = frame->runtime_method->method;
928 const char *name = method->name;
929 MonoObject *obj = (MonoObject*)frame->obj;
930 MonoObject *isinst_obj;
933 mono_class_init (method->klass);
935 isinst_obj = mono_object_isinst_checked (obj, mono_defaults.multicastdelegate_class, &error);
936 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
937 if (obj && isinst_obj) {
938 if (*name == '.' && (strcmp (name, ".ctor") == 0)) {
939 interp_delegate_ctor (context->domain, obj, frame->stack_args[0].data.p, frame->stack_args[1].data.p);
944 isinst_obj = mono_object_isinst_checked (obj, mono_defaults.array_class, &error);
945 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
946 if (obj && isinst_obj) {
947 if (*name == 'S' && (strcmp (name, "Set") == 0)) {
948 ves_array_set (frame);
951 if (*name == 'G' && (strcmp (name, "Get") == 0)) {
952 ves_array_get (frame);
955 if (*name == 'A' && (strcmp (name, "Address") == 0)) {
956 ves_array_element_address (frame);
961 g_error ("Don't know how to exec runtime method %s.%s::%s",
962 method->klass->name_space, method->klass->name,
967 dump_stack (stackval *stack, stackval *sp)
970 GString *str = g_string_new ("");
973 return g_string_free (str, FALSE);
976 g_string_append_printf (str, "[%lld/0x%0llx] ", s->data.l, s->data.l);
979 return g_string_free (str, FALSE);
983 dump_stackval (GString *str, stackval *s, MonoType *type)
985 switch (type->type) {
993 case MONO_TYPE_BOOLEAN:
994 g_string_append_printf (str, "[%d] ", s->data.i);
996 case MONO_TYPE_STRING:
997 case MONO_TYPE_SZARRAY:
998 case MONO_TYPE_CLASS:
999 case MONO_TYPE_OBJECT:
1000 case MONO_TYPE_ARRAY:
1004 g_string_append_printf (str, "[%p] ", s->data.p);
1006 case MONO_TYPE_VALUETYPE:
1007 if (type->data.klass->enumtype)
1008 g_string_append_printf (str, "[%d] ", s->data.i);
1010 g_string_append_printf (str, "[vt:%p] ", s->data.p);
1014 g_string_append_printf (str, "[%g] ", s->data.f);
1019 g_string_append_printf (str, "[%lld/0x%0llx] ", s->data.l, s->data.l);
1025 dump_args (MonoInvocation *inv)
1027 GString *str = g_string_new ("");
1029 MonoMethodSignature *signature = mono_method_signature (inv->runtime_method->method);
1031 if (signature->param_count == 0)
1032 return g_string_free (str, FALSE);
1034 if (signature->hasthis)
1035 g_string_append_printf (str, "%p ", inv->obj);
1037 for (i = 0; i < signature->param_count; ++i)
1038 dump_stackval (str, inv->stack_args + i, signature->params [i]);
1040 return g_string_free (str, FALSE);
1044 dump_retval (MonoInvocation *inv)
1046 GString *str = g_string_new ("");
1047 MonoType *ret = mono_method_signature (inv->runtime_method->method)->ret;
1049 if (ret->type != MONO_TYPE_VOID)
1050 dump_stackval (str, inv->retval, ret);
1052 return g_string_free (str, FALSE);
1056 dump_frame (MonoInvocation *inv)
1058 GString *str = g_string_new ("");
1063 for (i = 0; inv; inv = inv->parent) {
1064 if (inv->runtime_method != NULL) {
1065 MonoMethod *method = inv->runtime_method->method;
1069 const char * opname = "";
1071 gchar *source = NULL;
1075 if ((method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) == 0 &&
1076 (method->iflags & METHOD_IMPL_ATTRIBUTE_RUNTIME) == 0) {
1077 MonoMethodHeader *hd = mono_method_get_header_checked (method, &error);
1078 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
1082 opname = mono_interp_opname [*inv->ip];
1083 codep = inv->ip - inv->runtime_method->code;
1084 source = g_strdup_printf ("%s:%d // (TODO: proper stacktrace)", method->name, codep);
1089 MonoDebugSourceLocation *minfo = mono_debug_lookup_method (method);
1090 source = mono_debug_method_lookup_location (minfo, codep);
1094 args = dump_args (inv);
1095 name = mono_method_full_name (method, TRUE);
1097 g_string_append_printf (str, "#%d: 0x%05x %-10s in %s (%s) at %s\n", i, codep, opname, name, args, source);
1099 g_string_append_printf (str, "#%d: 0x%05x %-10s in %s (%s)\n", i, codep, opname, name, args);
1106 return g_string_free (str, FALSE);
1110 get_trace_ips (MonoDomain *domain, MonoInvocation *top)
1114 MonoInvocation *inv;
1117 for (i = 0, inv = top; inv; inv = inv->parent)
1118 if (inv->runtime_method != NULL)
1121 res = mono_array_new_checked (domain, mono_defaults.int_class, 2 * i, &error);
1122 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
1124 for (i = 0, inv = top; inv; inv = inv->parent)
1125 if (inv->runtime_method != NULL) {
1126 mono_array_set (res, gpointer, i, inv->runtime_method);
1128 mono_array_set (res, gpointer, i, (gpointer)inv->ip);
1136 #define MYGUINT64_MAX 18446744073709551615ULL
1137 #define MYGINT64_MAX 9223372036854775807LL
1138 #define MYGINT64_MIN (-MYGINT64_MAX -1LL)
1140 #define MYGUINT32_MAX 4294967295U
1141 #define MYGINT32_MAX 2147483647
1142 #define MYGINT32_MIN (-MYGINT32_MAX -1)
1144 #define CHECK_ADD_OVERFLOW(a,b) \
1145 (gint32)(b) >= 0 ? (gint32)(MYGINT32_MAX) - (gint32)(b) < (gint32)(a) ? -1 : 0 \
1146 : (gint32)(MYGINT32_MIN) - (gint32)(b) > (gint32)(a) ? +1 : 0
1148 #define CHECK_SUB_OVERFLOW(a,b) \
1149 (gint32)(b) < 0 ? (gint32)(MYGINT32_MAX) + (gint32)(b) < (gint32)(a) ? -1 : 0 \
1150 : (gint32)(MYGINT32_MIN) + (gint32)(b) > (gint32)(a) ? +1 : 0
1152 #define CHECK_ADD_OVERFLOW_UN(a,b) \
1153 (guint32)(MYGUINT32_MAX) - (guint32)(b) < (guint32)(a) ? -1 : 0
1155 #define CHECK_SUB_OVERFLOW_UN(a,b) \
1156 (guint32)(a) < (guint32)(b) ? -1 : 0
1158 #define CHECK_ADD_OVERFLOW64(a,b) \
1159 (gint64)(b) >= 0 ? (gint64)(MYGINT64_MAX) - (gint64)(b) < (gint64)(a) ? -1 : 0 \
1160 : (gint64)(MYGINT64_MIN) - (gint64)(b) > (gint64)(a) ? +1 : 0
1162 #define CHECK_SUB_OVERFLOW64(a,b) \
1163 (gint64)(b) < 0 ? (gint64)(MYGINT64_MAX) + (gint64)(b) < (gint64)(a) ? -1 : 0 \
1164 : (gint64)(MYGINT64_MIN) + (gint64)(b) > (gint64)(a) ? +1 : 0
1166 #define CHECK_ADD_OVERFLOW64_UN(a,b) \
1167 (guint64)(MYGUINT64_MAX) - (guint64)(b) < (guint64)(a) ? -1 : 0
1169 #define CHECK_SUB_OVERFLOW64_UN(a,b) \
1170 (guint64)(a) < (guint64)(b) ? -1 : 0
1172 #if SIZEOF_VOID_P == 4
1173 #define CHECK_ADD_OVERFLOW_NAT(a,b) CHECK_ADD_OVERFLOW(a,b)
1174 #define CHECK_ADD_OVERFLOW_NAT_UN(a,b) CHECK_ADD_OVERFLOW_UN(a,b)
1176 #define CHECK_ADD_OVERFLOW_NAT(a,b) CHECK_ADD_OVERFLOW64(a,b)
1177 #define CHECK_ADD_OVERFLOW_NAT_UN(a,b) CHECK_ADD_OVERFLOW64_UN(a,b)
1180 /* Resolves to TRUE if the operands would overflow */
1181 #define CHECK_MUL_OVERFLOW(a,b) \
1182 ((gint32)(a) == 0) || ((gint32)(b) == 0) ? 0 : \
1183 (((gint32)(a) > 0) && ((gint32)(b) == -1)) ? FALSE : \
1184 (((gint32)(a) < 0) && ((gint32)(b) == -1)) ? (a == - MYGINT32_MAX) : \
1185 (((gint32)(a) > 0) && ((gint32)(b) > 0)) ? (gint32)(a) > ((MYGINT32_MAX) / (gint32)(b)) : \
1186 (((gint32)(a) > 0) && ((gint32)(b) < 0)) ? (gint32)(a) > ((MYGINT32_MIN) / (gint32)(b)) : \
1187 (((gint32)(a) < 0) && ((gint32)(b) > 0)) ? (gint32)(a) < ((MYGINT32_MIN) / (gint32)(b)) : \
1188 (gint32)(a) < ((MYGINT32_MAX) / (gint32)(b))
1190 #define CHECK_MUL_OVERFLOW_UN(a,b) \
1191 ((guint32)(a) == 0) || ((guint32)(b) == 0) ? 0 : \
1192 (guint32)(b) > ((MYGUINT32_MAX) / (guint32)(a))
1194 #define CHECK_MUL_OVERFLOW64(a,b) \
1195 ((gint64)(a) == 0) || ((gint64)(b) == 0) ? 0 : \
1196 (((gint64)(a) > 0) && ((gint64)(b) == -1)) ? FALSE : \
1197 (((gint64)(a) < 0) && ((gint64)(b) == -1)) ? (a == - MYGINT64_MAX) : \
1198 (((gint64)(a) > 0) && ((gint64)(b) > 0)) ? (gint64)(a) > ((MYGINT64_MAX) / (gint64)(b)) : \
1199 (((gint64)(a) > 0) && ((gint64)(b) < 0)) ? (gint64)(a) > ((MYGINT64_MIN) / (gint64)(b)) : \
1200 (((gint64)(a) < 0) && ((gint64)(b) > 0)) ? (gint64)(a) < ((MYGINT64_MIN) / (gint64)(b)) : \
1201 (gint64)(a) < ((MYGINT64_MAX) / (gint64)(b))
1203 #define CHECK_MUL_OVERFLOW64_UN(a,b) \
1204 ((guint64)(a) == 0) || ((guint64)(b) == 0) ? 0 : \
1205 (guint64)(b) > ((MYGUINT64_MAX) / (guint64)(a))
1207 #if SIZEOF_VOID_P == 4
1208 #define CHECK_MUL_OVERFLOW_NAT(a,b) CHECK_MUL_OVERFLOW(a,b)
1209 #define CHECK_MUL_OVERFLOW_NAT_UN(a,b) CHECK_MUL_OVERFLOW_UN(a,b)
1211 #define CHECK_MUL_OVERFLOW_NAT(a,b) CHECK_MUL_OVERFLOW64(a,b)
1212 #define CHECK_MUL_OVERFLOW_NAT_UN(a,b) CHECK_MUL_OVERFLOW64_UN(a,b)
1216 interp_mono_runtime_invoke (MonoMethod *method, void *obj, void **params, MonoObject **exc, MonoError *error)
1218 MonoInvocation frame;
1219 ThreadContext * volatile context = mono_native_tls_get_value (thread_context_id);
1220 MonoObject *retval = NULL;
1221 MonoMethodSignature *sig = mono_method_signature (method);
1222 MonoClass *klass = mono_class_from_mono_type (sig->ret);
1223 int i, type, isobject = 0;
1226 stackval *args = alloca (sizeof (stackval) * sig->param_count);
1227 ThreadContext context_struct;
1228 MonoInvocation *old_frame = NULL;
1231 mono_error_init (error);
1236 if (context != &context_struct) {
1237 context->domain = mono_domain_get ();
1238 context->current_frame = old_frame;
1239 context->managed_code = 0;
1241 mono_native_tls_set_value (thread_context_id, NULL);
1243 *exc = (MonoObject *)frame.ex;
1247 if (context == NULL) {
1248 context = &context_struct;
1249 context_struct.base_frame = &frame;
1250 context_struct.current_frame = NULL;
1251 context_struct.env_frame = &frame;
1252 context_struct.current_env = &env;
1253 context_struct.search_for_handler = 0;
1254 context_struct.managed_code = 0;
1255 mono_native_tls_set_value (thread_context_id, context);
1258 old_frame = context->current_frame;
1260 context->domain = mono_domain_get ();
1262 switch (sig->ret->type) {
1263 case MONO_TYPE_VOID:
1265 case MONO_TYPE_STRING:
1266 case MONO_TYPE_OBJECT:
1267 case MONO_TYPE_CLASS:
1268 case MONO_TYPE_ARRAY:
1269 case MONO_TYPE_SZARRAY:
1272 case MONO_TYPE_VALUETYPE:
1273 retval = mono_object_new_checked (context->domain, klass, error);
1274 ret = ((char*)retval) + sizeof (MonoObject);
1275 if (!sig->ret->data.klass->enumtype)
1276 result.data.vt = ret;
1279 retval = mono_object_new_checked (context->domain, klass, error);
1280 ret = ((char*)retval) + sizeof (MonoObject);
1284 for (i = 0; i < sig->param_count; ++i) {
1285 if (sig->params [i]->byref) {
1286 args [i].data.p = params [i];
1289 type = sig->params [i]->type;
1294 case MONO_TYPE_BOOLEAN:
1295 args [i].data.i = *(MonoBoolean*)params [i];
1299 case MONO_TYPE_CHAR:
1300 args [i].data.i = *(gint16*)params [i];
1302 #if SIZEOF_VOID_P == 4
1303 case MONO_TYPE_U: /* use VAL_POINTER? */
1308 args [i].data.i = *(gint32*)params [i];
1310 #if SIZEOF_VOID_P == 8
1316 args [i].data.l = *(gint64*)params [i];
1318 case MONO_TYPE_VALUETYPE:
1319 if (sig->params [i]->data.klass->enumtype) {
1320 type = mono_class_enum_basetype (sig->params [i]->data.klass)->type;
1323 args [i].data.p = params [i];
1326 case MONO_TYPE_STRING:
1327 case MONO_TYPE_CLASS:
1328 case MONO_TYPE_ARRAY:
1329 case MONO_TYPE_SZARRAY:
1330 case MONO_TYPE_OBJECT:
1331 args [i].data.p = params [i];
1334 g_error ("type 0x%x not handled in runtime invoke", sig->params [i]->type);
1338 if (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL)
1339 method = mono_marshal_get_native_wrapper (method, FALSE, FALSE);
1340 INIT_FRAME(&frame,context->current_frame,obj,args,&result,mono_get_root_domain (),method,error);
1342 frame.invoke_trap = 1;
1343 context->managed_code = 1;
1344 ves_exec_method_with_context (&frame, context);
1345 context->managed_code = 0;
1346 if (context == &context_struct)
1347 mono_native_tls_set_value (thread_context_id, NULL);
1349 context->current_frame = old_frame;
1350 if (frame.ex != NULL) {
1352 *exc = (MonoObject*) frame.ex;
1355 if (context->current_env != NULL) {
1356 context->env_frame->ex = frame.ex;
1357 longjmp(*context->current_env, 1);
1360 printf("dropped exception...\n");
1362 if (sig->ret->type == MONO_TYPE_VOID && !method->string_ctor)
1364 if (isobject || method->string_ctor)
1365 return result.data.p;
1366 stackval_to_data (sig->ret, &result, ret, sig->pinvoke);
1371 do_icall (ThreadContext *context, int op, stackval *sp, gpointer ptr)
1373 MonoInvocation *old_frame = context->current_frame;
1374 MonoInvocation *old_env_frame = context->env_frame;
1375 jmp_buf *old_env = context->current_env;
1379 context->current_frame = old_frame;
1380 context->env_frame = old_env_frame;
1381 context->current_env = old_env;
1382 context->managed_code = 1;
1386 context->env_frame = context->current_frame;
1387 context->current_env = &env;
1388 context->managed_code = 0;
1391 case MINT_ICALL_V_V: {
1392 void (*func)() = ptr;
1396 case MINT_ICALL_V_P: {
1397 gpointer (*func)() = ptr;
1399 sp [-1].data.p = func ();
1402 case MINT_ICALL_P_V: {
1403 void (*func)(gpointer) = ptr;
1404 func (sp [-1].data.p);
1408 case MINT_ICALL_P_P: {
1409 gpointer (*func)(gpointer) = ptr;
1410 sp [-1].data.p = func (sp [-1].data.p);
1413 case MINT_ICALL_PP_V: {
1414 void (*func)(gpointer,gpointer) = ptr;
1416 func (sp [0].data.p, sp [1].data.p);
1419 case MINT_ICALL_PI_V: {
1420 void (*func)(gpointer,int) = ptr;
1422 func (sp [0].data.p, sp [1].data.i);
1425 case MINT_ICALL_PP_P: {
1426 gpointer (*func)(gpointer,gpointer) = ptr;
1428 sp [-1].data.p = func (sp [-1].data.p, sp [0].data.p);
1431 case MINT_ICALL_PI_P: {
1432 gpointer (*func)(gpointer,int) = ptr;
1434 sp [-1].data.p = func (sp [-1].data.p, sp [0].data.i);
1437 case MINT_ICALL_PPP_V: {
1438 void (*func)(gpointer,gpointer,gpointer) = ptr;
1440 func (sp [0].data.p, sp [1].data.p, sp [2].data.p);
1443 case MINT_ICALL_PPI_V: {
1444 void (*func)(gpointer,gpointer,int) = ptr;
1446 func (sp [0].data.p, sp [1].data.p, sp [2].data.i);
1450 g_assert_not_reached ();
1453 context->env_frame = old_env_frame;
1454 context->current_env = old_env;
1459 static mono_mutex_t create_method_pointer_mutex;
1461 static GHashTable *method_pointer_hash = NULL;
1464 interp_create_method_pointer (MonoMethod *method, MonoError *error)
1469 mono_os_mutex_lock (&create_method_pointer_mutex);
1470 if (!method_pointer_hash) {
1471 // FIXME: is registering method table as GC root really necessary?
1472 // MONO_GC_REGISTER_ROOT_FIXED (method_pointer_hash);
1473 method_pointer_hash = g_hash_table_new (NULL, NULL);
1475 addr = g_hash_table_lookup (method_pointer_hash, method);
1477 mono_os_mutex_unlock (&create_method_pointer_mutex);
1482 * If it is a static P/Invoke method, we can just return the pointer
1483 * to the method implementation.
1485 if (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL && ((MonoMethodPInvoke*) method)->addr) {
1486 ji = g_new0 (MonoJitInfo, 1);
1487 ji->d.method = method;
1489 ji->code_start = addr = ((MonoMethodPInvoke*) method)->addr;
1491 mono_jit_info_table_add (mono_get_root_domain (), ji);
1494 g_error ("FIXME: not available? figure out new API");
1496 addr = mono_arch_create_method_pointer (method);
1500 g_hash_table_insert (method_pointer_hash, method, addr);
1501 mono_os_mutex_unlock (&create_method_pointer_mutex);
1507 static int opcode_counts[512];
1509 #define COUNT_OP(op) opcode_counts[op]++
1511 #define COUNT_OP(op)
1515 #define DUMP_INSTR() \
1516 if (tracing > 1) { \
1518 if (sp > frame->stack) { \
1519 ins = dump_stack (frame->stack, sp); \
1521 ins = g_strdup (""); \
1525 g_print ("(%u) ", mono_thread_internal_current ()); \
1526 mono_interp_dis_mintop(rtm->code, ip); \
1527 g_print ("\t%d:%s\n", vt_sp - vtalloc, ins); \
1531 #define DUMP_INSTR()
1535 #define USE_COMPUTED_GOTO 1
1537 #if USE_COMPUTED_GOTO
1538 #define MINT_IN_SWITCH(op) COUNT_OP(op); goto *in_labels[op];
1539 #define MINT_IN_CASE(x) LAB_ ## x:
1541 #define MINT_IN_BREAK if (tracing > 1) goto main_loop; else { COUNT_OP(*ip); goto *in_labels[*ip]; }
1543 #define MINT_IN_BREAK { COUNT_OP(*ip); goto *in_labels[*ip]; }
1545 #define MINT_IN_DEFAULT mint_default: if (0) goto mint_default; /* make gcc shut up */
1547 #define MINT_IN_SWITCH(op) switch (op)
1548 #define MINT_IN_CASE(x) case x:
1549 #define MINT_IN_BREAK break
1550 #define MINT_IN_DEFAULT default:
1554 * Defining this causes register allocation errors in some versions of gcc:
1555 * error: unable to find a register to spill in class `SIREG'
1557 /* #define MINT_USE_DEDICATED_IP_REG */
1560 ves_exec_method_with_context (MonoInvocation *frame, ThreadContext *context)
1562 MonoInvocation child_frame;
1563 GSList *finally_ips = NULL;
1564 const unsigned short *endfinally_ip = NULL;
1565 #if defined(__GNUC__) && defined (i386) && defined (MINT_USE_DEDICATED_IP_REG)
1566 register const unsigned short *ip asm ("%esi");
1568 register const unsigned short *ip;
1570 register stackval *sp;
1573 gint tracing = global_tracing;
1574 unsigned char *vtalloc;
1577 unsigned char *vt_sp;
1578 unsigned char *locals;
1580 MonoObject *o = NULL;
1582 #if USE_COMPUTED_GOTO
1583 static void *in_labels[] = {
1584 #define OPDEF(a,b,c,d) \
1586 #include "mintops.def"
1591 frame->ex_handler = NULL;
1593 context->current_frame = frame;
1596 debug_enter (frame, &tracing);
1599 if (!frame->runtime_method->transformed) {
1600 context->managed_code = 0;
1602 char *mn = mono_method_full_name (frame->runtime_method->method, FALSE);
1603 g_printerr ("(0x%08x) Transforming %s\n", mono_thread_internal_current (), mn);
1606 frame->ex = mono_interp_transform_method (frame->runtime_method, context);
1607 context->managed_code = 1;
1615 rtm = frame->runtime_method;
1616 frame->args = alloca (rtm->alloca_size);
1617 sp = frame->stack = (stackval *)((char *)frame->args + rtm->args_size);
1620 memset(sp, 0, rtm->stack_size);
1622 vt_sp = (unsigned char *) sp + rtm->stack_size;
1626 locals = (unsigned char *) vt_sp + rtm->vt_stack_size;
1628 child_frame.parent = frame;
1634 * using while (ip < end) may result in a 15% performance drop,
1635 * but it may be useful for debug
1639 /* g_assert (sp >= frame->stack); */
1640 /* g_assert(vt_sp - vtalloc <= rtm->vt_stack_size); */
1642 MINT_IN_SWITCH (*ip) {
1643 MINT_IN_CASE(MINT_INITLOCALS)
1644 memset (locals, 0, rtm->locals_size);
1647 MINT_IN_CASE(MINT_NOP)
1650 MINT_IN_CASE(MINT_BREAK)
1652 G_BREAKPOINT (); /* this is not portable... */
1654 MINT_IN_CASE(MINT_LDNULL)
1659 MINT_IN_CASE(MINT_VTRESULT) {
1660 int ret_size = * (guint16 *)(ip + 1);
1661 unsigned char *ret_vt_sp = vt_sp;
1662 vt_sp -= READ32(ip + 2);
1664 memmove (vt_sp, ret_vt_sp, ret_size);
1665 vt_sp += (ret_size + 7) & ~7;
1670 #define LDC(n) do { sp->data.i = (n); ++ip; ++sp; } while (0)
1671 MINT_IN_CASE(MINT_LDC_I4_M1)
1674 MINT_IN_CASE(MINT_LDC_I4_0)
1677 MINT_IN_CASE(MINT_LDC_I4_1)
1680 MINT_IN_CASE(MINT_LDC_I4_2)
1683 MINT_IN_CASE(MINT_LDC_I4_3)
1686 MINT_IN_CASE(MINT_LDC_I4_4)
1689 MINT_IN_CASE(MINT_LDC_I4_5)
1692 MINT_IN_CASE(MINT_LDC_I4_6)
1695 MINT_IN_CASE(MINT_LDC_I4_7)
1698 MINT_IN_CASE(MINT_LDC_I4_8)
1701 MINT_IN_CASE(MINT_LDC_I4_S)
1702 sp->data.i = *(const short *)(ip + 1);
1706 MINT_IN_CASE(MINT_LDC_I4)
1708 sp->data.i = READ32 (ip);
1712 MINT_IN_CASE(MINT_LDC_I8)
1714 sp->data.l = READ64 (ip);
1718 MINT_IN_CASE(MINT_LDC_R4) {
1722 sp->data.f = * (float *)&val;
1727 MINT_IN_CASE(MINT_LDC_R8)
1728 sp->data.l = READ64 (ip + 1); /* note union usage */
1732 MINT_IN_CASE(MINT_DUP)
1737 MINT_IN_CASE(MINT_DUP_VT)
1738 i32 = READ32 (ip + 1);
1740 memcpy(sp->data.p, sp [-1].data.p, i32);
1741 vt_sp += (i32 + 7) & ~7;
1745 MINT_IN_CASE(MINT_POP)
1749 MINT_IN_CASE(MINT_JMP) {
1750 RuntimeMethod *new_method = rtm->data_items [* (guint16 *)(ip + 1)];
1751 if (!new_method->transformed) {
1753 frame->ex = mono_interp_transform_method (new_method, context);
1758 if (new_method->alloca_size > rtm->alloca_size)
1759 g_error ("MINT_JMP to method which needs more stack space (%d > %d)", new_method->alloca_size, rtm->alloca_size);
1760 rtm = frame->runtime_method = new_method;
1761 vt_sp = (unsigned char *) sp + rtm->stack_size;
1765 locals = vt_sp + rtm->vt_stack_size;
1766 ip = rtm->new_body_start; /* bypass storing input args from callers frame */
1769 MINT_IN_CASE(MINT_CALLI) {
1770 MonoMethodSignature *csignature;
1771 stackval *endsp = sp;
1775 csignature = rtm->data_items [* (guint16 *)(ip + 1)];
1779 child_frame.runtime_method = sp->data.p;
1782 child_frame.retval = sp;
1783 /* decrement by the actual number of args */
1784 sp -= csignature->param_count;
1785 child_frame.stack_args = sp;
1786 if (csignature->hasthis) {
1788 child_frame.obj = sp->data.p;
1790 child_frame.obj = NULL;
1792 if (csignature->hasthis && mono_object_is_transparent_proxy (child_frame.obj)) {
1793 child_frame.runtime_method = mono_interp_get_runtime_method (context->domain, mono_marshal_get_remoting_invoke (child_frame.runtime_method->method), &error);
1794 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
1795 } else if (child_frame.runtime_method->method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) {
1796 child_frame.runtime_method = mono_interp_get_runtime_method (context->domain, mono_marshal_get_native_wrapper (child_frame.runtime_method->method, FALSE, FALSE), &error);
1797 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
1800 ves_exec_method_with_context (&child_frame, context);
1802 context->current_frame = frame;
1804 if (child_frame.ex) {
1806 * An exception occurred, need to run finally, fault and catch handlers..
1808 frame->ex = child_frame.ex;
1809 goto handle_finally;
1812 /* need to handle typedbyref ... */
1813 if (csignature->ret->type != MONO_TYPE_VOID) {
1819 MINT_IN_CASE(MINT_CALLI_NAT) {
1820 MonoMethodSignature *csignature;
1821 stackval *endsp = sp;
1822 unsigned char *code = NULL;
1826 csignature = rtm->data_items [* (guint16 *)(ip + 1)];
1831 child_frame.runtime_method = NULL;
1834 child_frame.retval = sp;
1835 /* decrement by the actual number of args */
1836 sp -= csignature->param_count;
1837 child_frame.stack_args = sp;
1838 if (csignature->hasthis) {
1840 child_frame.obj = sp->data.p;
1842 child_frame.obj = NULL;
1844 ves_pinvoke_method (&child_frame, csignature, (MonoFuncV) code, FALSE, context);
1846 context->current_frame = frame;
1848 if (child_frame.ex) {
1850 * An exception occurred, need to run finally, fault and catch handlers..
1852 frame->ex = child_frame.ex;
1853 if (context->search_for_handler) {
1854 context->search_for_handler = 0;
1855 goto handle_exception;
1857 goto handle_finally;
1860 /* need to handle typedbyref ... */
1861 if (csignature->ret->type != MONO_TYPE_VOID) {
1867 MINT_IN_CASE(MINT_CALL) {
1868 stackval *endsp = sp;
1872 child_frame.runtime_method = rtm->data_items [* (guint16 *)(ip + 1)];
1875 child_frame.retval = sp;
1876 /* decrement by the actual number of args */
1877 sp -= child_frame.runtime_method->param_count;
1878 child_frame.stack_args = sp;
1879 if (child_frame.runtime_method->hasthis) {
1881 child_frame.obj = sp->data.p;
1883 child_frame.obj = NULL;
1885 if (child_frame.runtime_method->hasthis && !child_frame.runtime_method->valuetype && mono_object_is_transparent_proxy (child_frame.obj)) {
1886 child_frame.runtime_method = mono_interp_get_runtime_method (context->domain, mono_marshal_get_remoting_invoke (child_frame.runtime_method->method), &error);
1887 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
1889 ves_exec_method_with_context (&child_frame, context);
1891 context->current_frame = frame;
1893 if (child_frame.ex) {
1895 * An exception occurred, need to run finally, fault and catch handlers..
1897 frame->ex = child_frame.ex;
1898 goto handle_finally;
1901 /* need to handle typedbyref ... */
1906 MINT_IN_CASE(MINT_VCALL) {
1909 child_frame.runtime_method = rtm->data_items [* (guint16 *)(ip + 1)];
1913 child_frame.retval = sp;
1914 /* decrement by the actual number of args */
1915 sp -= child_frame.runtime_method->param_count;
1916 child_frame.stack_args = sp;
1917 if (child_frame.runtime_method->hasthis) {
1919 child_frame.obj = sp->data.p;
1921 child_frame.obj = NULL;
1924 if (child_frame.runtime_method->hasthis && !child_frame.runtime_method->valuetype && mono_object_is_transparent_proxy (child_frame.obj)) {
1925 child_frame.runtime_method = mono_interp_get_runtime_method (context->domain, mono_marshal_get_remoting_invoke (child_frame.runtime_method->method), &error);
1926 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
1929 ves_exec_method_with_context (&child_frame, context);
1931 context->current_frame = frame;
1933 if (child_frame.ex) {
1935 * An exception occurred, need to run finally, fault and catch handlers..
1937 frame->ex = child_frame.ex;
1938 goto handle_finally;
1942 MINT_IN_CASE(MINT_CALLVIRT) {
1943 stackval *endsp = sp;
1944 MonoObject *this_arg;
1949 token = * (unsigned short *)(ip + 1);
1951 child_frame.runtime_method = rtm->data_items [token];
1953 child_frame.retval = sp;
1955 /* decrement by the actual number of args */
1956 sp -= child_frame.runtime_method->param_count;
1957 child_frame.stack_args = sp;
1959 child_frame.obj = this_arg = sp->data.p;
1961 THROW_EX (mono_get_exception_null_reference(), ip - 2);
1962 child_frame.runtime_method = get_virtual_method (context->domain, child_frame.runtime_method, this_arg);
1964 if (this_arg->vtable->klass->valuetype && child_frame.runtime_method->valuetype) {
1965 child_frame.obj = (char *)this_arg + sizeof(MonoObject);
1968 ves_exec_method_with_context (&child_frame, context);
1970 context->current_frame = frame;
1972 if (child_frame.ex) {
1974 * An exception occurred, need to run finally, fault and catch handlers..
1976 frame->ex = child_frame.ex;
1977 if (context->search_for_handler) {
1978 context->search_for_handler = 0;
1979 goto handle_exception;
1981 goto handle_finally;
1984 /* need to handle typedbyref ... */
1989 MINT_IN_CASE(MINT_VCALLVIRT) {
1990 MonoObject *this_arg;
1995 token = * (unsigned short *)(ip + 1);
1997 child_frame.runtime_method = rtm->data_items [token];
1999 child_frame.retval = sp;
2001 /* decrement by the actual number of args */
2002 sp -= child_frame.runtime_method->param_count;
2003 child_frame.stack_args = sp;
2005 child_frame.obj = this_arg = sp->data.p;
2007 THROW_EX (mono_get_exception_null_reference(), ip - 2);
2008 child_frame.runtime_method = get_virtual_method (context->domain, child_frame.runtime_method, this_arg);
2010 if (this_arg->vtable->klass->valuetype && child_frame.runtime_method->valuetype) {
2011 child_frame.obj = (char *)this_arg + sizeof(MonoObject);
2014 ves_exec_method_with_context (&child_frame, context);
2016 context->current_frame = frame;
2018 if (child_frame.ex) {
2020 * An exception occurred, need to run finally, fault and catch handlers..
2022 frame->ex = child_frame.ex;
2023 if (context->search_for_handler) {
2024 context->search_for_handler = 0;
2025 goto handle_exception;
2027 goto handle_finally;
2031 MINT_IN_CASE(MINT_CALLRUN)
2032 ves_runtime_method (frame, context);
2035 goto handle_exception;
2038 MINT_IN_CASE(MINT_RET)
2040 *frame->retval = *sp;
2041 if (sp > frame->stack)
2042 g_warning ("ret: more values on stack: %d", sp-frame->stack);
2044 MINT_IN_CASE(MINT_RET_VOID)
2045 if (sp > frame->stack)
2046 g_warning ("ret.void: more values on stack: %d", sp-frame->stack);
2048 MINT_IN_CASE(MINT_RET_VT)
2049 i32 = READ32(ip + 1);
2051 memcpy(frame->retval->data.p, sp->data.p, i32);
2052 if (sp > frame->stack)
2053 g_warning ("ret.vt: more values on stack: %d", sp-frame->stack);
2055 MINT_IN_CASE(MINT_BR_S)
2056 ip += (short) *(ip + 1);
2058 MINT_IN_CASE(MINT_BR)
2059 ip += (gint32) READ32(ip + 1);
2061 #define ZEROP_S(datamem, op) \
2063 if (sp->data.datamem op 0) \
2064 ip += * (gint16 *)(ip + 1); \
2068 #define ZEROP(datamem, op) \
2070 if (sp->data.datamem op 0) \
2071 ip += READ32(ip + 1); \
2075 MINT_IN_CASE(MINT_BRFALSE_I4_S)
2078 MINT_IN_CASE(MINT_BRFALSE_I8_S)
2081 MINT_IN_CASE(MINT_BRFALSE_R8_S)
2084 MINT_IN_CASE(MINT_BRFALSE_I4)
2087 MINT_IN_CASE(MINT_BRFALSE_I8)
2090 MINT_IN_CASE(MINT_BRFALSE_R8)
2093 MINT_IN_CASE(MINT_BRTRUE_I4_S)
2096 MINT_IN_CASE(MINT_BRTRUE_I8_S)
2099 MINT_IN_CASE(MINT_BRTRUE_R8_S)
2102 MINT_IN_CASE(MINT_BRTRUE_I4)
2105 MINT_IN_CASE(MINT_BRTRUE_I8)
2108 MINT_IN_CASE(MINT_BRTRUE_R8)
2111 #define CONDBR_S(cond) \
2114 ip += * (gint16 *)(ip + 1); \
2117 #define BRELOP_S(datamem, op) \
2118 CONDBR_S(sp[0].data.datamem op sp[1].data.datamem)
2120 #define CONDBR(cond) \
2123 ip += READ32(ip + 1); \
2127 #define BRELOP(datamem, op) \
2128 CONDBR(sp[0].data.datamem op sp[1].data.datamem)
2130 MINT_IN_CASE(MINT_BEQ_I4_S)
2133 MINT_IN_CASE(MINT_BEQ_I8_S)
2136 MINT_IN_CASE(MINT_BEQ_R8_S)
2137 CONDBR_S(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f == sp[1].data.f)
2139 MINT_IN_CASE(MINT_BEQ_I4)
2142 MINT_IN_CASE(MINT_BEQ_I8)
2145 MINT_IN_CASE(MINT_BEQ_R8)
2146 CONDBR(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f == sp[1].data.f)
2148 MINT_IN_CASE(MINT_BGE_I4_S)
2151 MINT_IN_CASE(MINT_BGE_I8_S)
2154 MINT_IN_CASE(MINT_BGE_R8_S)
2155 CONDBR_S(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f >= sp[1].data.f)
2157 MINT_IN_CASE(MINT_BGE_I4)
2160 MINT_IN_CASE(MINT_BGE_I8)
2163 MINT_IN_CASE(MINT_BGE_R8)
2164 CONDBR(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f >= sp[1].data.f)
2166 MINT_IN_CASE(MINT_BGT_I4_S)
2169 MINT_IN_CASE(MINT_BGT_I8_S)
2172 MINT_IN_CASE(MINT_BGT_R8_S)
2173 CONDBR_S(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f > sp[1].data.f)
2175 MINT_IN_CASE(MINT_BGT_I4)
2178 MINT_IN_CASE(MINT_BGT_I8)
2181 MINT_IN_CASE(MINT_BGT_R8)
2182 CONDBR(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f > sp[1].data.f)
2184 MINT_IN_CASE(MINT_BLT_I4_S)
2187 MINT_IN_CASE(MINT_BLT_I8_S)
2190 MINT_IN_CASE(MINT_BLT_R8_S)
2191 CONDBR_S(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f < sp[1].data.f)
2193 MINT_IN_CASE(MINT_BLT_I4)
2196 MINT_IN_CASE(MINT_BLT_I8)
2199 MINT_IN_CASE(MINT_BLT_R8)
2200 CONDBR(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f < sp[1].data.f)
2202 MINT_IN_CASE(MINT_BLE_I4_S)
2205 MINT_IN_CASE(MINT_BLE_I8_S)
2208 MINT_IN_CASE(MINT_BLE_R8_S)
2209 CONDBR_S(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f <= sp[1].data.f)
2211 MINT_IN_CASE(MINT_BLE_I4)
2214 MINT_IN_CASE(MINT_BLE_I8)
2217 MINT_IN_CASE(MINT_BLE_R8)
2218 CONDBR(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f <= sp[1].data.f)
2220 MINT_IN_CASE(MINT_BNE_UN_I4_S)
2223 MINT_IN_CASE(MINT_BNE_UN_I8_S)
2226 MINT_IN_CASE(MINT_BNE_UN_R8_S)
2227 CONDBR_S(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f != sp[1].data.f)
2229 MINT_IN_CASE(MINT_BNE_UN_I4)
2232 MINT_IN_CASE(MINT_BNE_UN_I8)
2235 MINT_IN_CASE(MINT_BNE_UN_R8)
2236 CONDBR(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f != sp[1].data.f)
2239 #define BRELOP_S_CAST(datamem, op, type) \
2241 if ((type) sp[0].data.datamem op (type) sp[1].data.datamem) \
2242 ip += * (gint16 *)(ip + 1); \
2246 #define BRELOP_CAST(datamem, op, type) \
2248 if ((type) sp[0].data.datamem op (type) sp[1].data.datamem) \
2249 ip += READ32(ip + 1); \
2253 MINT_IN_CASE(MINT_BGE_UN_I4_S)
2254 BRELOP_S_CAST(i, >=, guint32);
2256 MINT_IN_CASE(MINT_BGE_UN_I8_S)
2257 BRELOP_S_CAST(l, >=, guint64);
2259 MINT_IN_CASE(MINT_BGE_UN_R8_S)
2260 CONDBR_S(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f >= sp[1].data.f)
2262 MINT_IN_CASE(MINT_BGE_UN_I4)
2263 BRELOP_CAST(i, >=, guint32);
2265 MINT_IN_CASE(MINT_BGE_UN_I8)
2266 BRELOP_CAST(l, >=, guint64);
2268 MINT_IN_CASE(MINT_BGE_UN_R8)
2269 CONDBR(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f >= sp[1].data.f)
2271 MINT_IN_CASE(MINT_BGT_UN_I4_S)
2272 BRELOP_S_CAST(i, >, guint32);
2274 MINT_IN_CASE(MINT_BGT_UN_I8_S)
2275 BRELOP_S_CAST(l, >, guint64);
2277 MINT_IN_CASE(MINT_BGT_UN_R8_S)
2278 CONDBR_S(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f > sp[1].data.f)
2280 MINT_IN_CASE(MINT_BGT_UN_I4)
2281 BRELOP_CAST(i, >, guint32);
2283 MINT_IN_CASE(MINT_BGT_UN_I8)
2284 BRELOP_CAST(l, >, guint64);
2286 MINT_IN_CASE(MINT_BGT_UN_R8)
2287 CONDBR(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f > sp[1].data.f)
2289 MINT_IN_CASE(MINT_BLE_UN_I4_S)
2290 BRELOP_S_CAST(i, <=, guint32);
2292 MINT_IN_CASE(MINT_BLE_UN_I8_S)
2293 BRELOP_S_CAST(l, <=, guint64);
2295 MINT_IN_CASE(MINT_BLE_UN_R8_S)
2296 CONDBR_S(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f <= sp[1].data.f)
2298 MINT_IN_CASE(MINT_BLE_UN_I4)
2299 BRELOP_CAST(i, <=, guint32);
2301 MINT_IN_CASE(MINT_BLE_UN_I8)
2302 BRELOP_CAST(l, <=, guint64);
2304 MINT_IN_CASE(MINT_BLE_UN_R8)
2305 CONDBR(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f <= sp[1].data.f)
2307 MINT_IN_CASE(MINT_BLT_UN_I4_S)
2308 BRELOP_S_CAST(i, <, guint32);
2310 MINT_IN_CASE(MINT_BLT_UN_I8_S)
2311 BRELOP_S_CAST(l, <, guint64);
2313 MINT_IN_CASE(MINT_BLT_UN_R8_S)
2314 CONDBR_S(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f < sp[1].data.f)
2316 MINT_IN_CASE(MINT_BLT_UN_I4)
2317 BRELOP_CAST(i, <, guint32);
2319 MINT_IN_CASE(MINT_BLT_UN_I8)
2320 BRELOP_CAST(l, <, guint64);
2322 MINT_IN_CASE(MINT_BLT_UN_R8)
2323 CONDBR(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f < sp[1].data.f)
2325 MINT_IN_CASE(MINT_SWITCH) {
2327 const unsigned short *st;
2333 if ((guint32)sp->data.i < n) {
2335 ip += 2 * (guint32)sp->data.i;
2336 offset = READ32 (ip);
2343 MINT_IN_CASE(MINT_LDIND_I1)
2345 sp[-1].data.i = *(gint8*)sp[-1].data.p;
2347 MINT_IN_CASE(MINT_LDIND_U1)
2349 sp[-1].data.i = *(guint8*)sp[-1].data.p;
2351 MINT_IN_CASE(MINT_LDIND_I2)
2353 sp[-1].data.i = *(gint16*)sp[-1].data.p;
2355 MINT_IN_CASE(MINT_LDIND_U2)
2357 sp[-1].data.i = *(guint16*)sp[-1].data.p;
2359 MINT_IN_CASE(MINT_LDIND_I4) /* Fall through */
2360 MINT_IN_CASE(MINT_LDIND_U4)
2362 sp[-1].data.i = *(gint32*)sp[-1].data.p;
2364 MINT_IN_CASE(MINT_LDIND_I8)
2366 sp[-1].data.l = *(gint64*)sp[-1].data.p;
2368 MINT_IN_CASE(MINT_LDIND_I)
2370 sp[-1].data.p = *(gpointer*)sp[-1].data.p;
2372 MINT_IN_CASE(MINT_LDIND_R4)
2374 sp[-1].data.f = *(gfloat*)sp[-1].data.p;
2376 MINT_IN_CASE(MINT_LDIND_R8)
2378 sp[-1].data.f = *(gdouble*)sp[-1].data.p;
2380 MINT_IN_CASE(MINT_LDIND_REF)
2382 sp[-1].data.p = *(gpointer*)sp[-1].data.p;
2384 MINT_IN_CASE(MINT_STIND_REF)
2387 * (gpointer *) sp->data.p = sp[1].data.p;
2389 MINT_IN_CASE(MINT_STIND_I1)
2392 * (gint8 *) sp->data.p = (gint8)sp[1].data.i;
2394 MINT_IN_CASE(MINT_STIND_I2)
2397 * (gint16 *) sp->data.p = (gint16)sp[1].data.i;
2399 MINT_IN_CASE(MINT_STIND_I4)
2402 * (gint32 *) sp->data.p = sp[1].data.i;
2404 MINT_IN_CASE(MINT_STIND_I)
2407 * (mono_i *) sp->data.p = (mono_i)sp[1].data.p;
2409 MINT_IN_CASE(MINT_STIND_I8)
2412 * (gint64 *) sp->data.p = sp[1].data.l;
2414 MINT_IN_CASE(MINT_STIND_R4)
2417 * (float *) sp->data.p = (gfloat)sp[1].data.f;
2419 MINT_IN_CASE(MINT_STIND_R8)
2422 * (double *) sp->data.p = sp[1].data.f;
2424 #define BINOP(datamem, op) \
2426 sp [-1].data.datamem = sp [-1].data.datamem op sp [0].data.datamem; \
2428 MINT_IN_CASE(MINT_ADD_I4)
2431 MINT_IN_CASE(MINT_ADD_I8)
2434 MINT_IN_CASE(MINT_ADD_R8)
2437 MINT_IN_CASE(MINT_ADD1_I4)
2441 MINT_IN_CASE(MINT_SUB_I4)
2444 MINT_IN_CASE(MINT_SUB_I8)
2447 MINT_IN_CASE(MINT_SUB_R8)
2450 MINT_IN_CASE(MINT_SUB1_I4)
2454 MINT_IN_CASE(MINT_MUL_I4)
2457 MINT_IN_CASE(MINT_MUL_I8)
2460 MINT_IN_CASE(MINT_MUL_R8)
2463 MINT_IN_CASE(MINT_DIV_I4)
2464 if (sp [-1].data.i == 0)
2465 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2466 if (sp [-1].data.i == (-1))
2467 THROW_EX (mono_get_exception_overflow (), ip);
2470 MINT_IN_CASE(MINT_DIV_I8)
2471 if (sp [-1].data.l == 0)
2472 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2473 if (sp [-1].data.l == (-1))
2474 THROW_EX (mono_get_exception_overflow (), ip);
2477 MINT_IN_CASE(MINT_DIV_R8)
2481 #define BINOP_CAST(datamem, op, type) \
2483 sp [-1].data.datamem = (type)sp [-1].data.datamem op (type)sp [0].data.datamem; \
2485 MINT_IN_CASE(MINT_DIV_UN_I4)
2486 if (sp [-1].data.i == 0)
2487 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2488 BINOP_CAST(i, /, guint32);
2490 MINT_IN_CASE(MINT_DIV_UN_I8)
2491 if (sp [-1].data.l == 0)
2492 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2493 BINOP_CAST(l, /, guint64);
2495 MINT_IN_CASE(MINT_REM_I4)
2496 if (sp [-1].data.i == 0)
2497 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2500 MINT_IN_CASE(MINT_REM_I8)
2501 if (sp [-1].data.l == 0)
2502 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2505 MINT_IN_CASE(MINT_REM_R8)
2506 /* FIXME: what do we actually do here? */
2508 sp [-1].data.f = fmod (sp [-1].data.f, sp [0].data.f);
2511 MINT_IN_CASE(MINT_REM_UN_I4)
2512 if (sp [-1].data.i == 0)
2513 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2514 BINOP_CAST(i, %, guint32);
2516 MINT_IN_CASE(MINT_REM_UN_I8)
2517 if (sp [-1].data.l == 0)
2518 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2519 BINOP_CAST(l, %, guint64);
2521 MINT_IN_CASE(MINT_AND_I4)
2524 MINT_IN_CASE(MINT_AND_I8)
2527 MINT_IN_CASE(MINT_OR_I4)
2530 MINT_IN_CASE(MINT_OR_I8)
2533 MINT_IN_CASE(MINT_XOR_I4)
2536 MINT_IN_CASE(MINT_XOR_I8)
2540 #define SHIFTOP(datamem, op) \
2542 sp [-1].data.datamem = sp [-1].data.datamem op sp [0].data.i; \
2545 MINT_IN_CASE(MINT_SHL_I4)
2548 MINT_IN_CASE(MINT_SHL_I8)
2551 MINT_IN_CASE(MINT_SHR_I4)
2554 MINT_IN_CASE(MINT_SHR_I8)
2557 MINT_IN_CASE(MINT_SHR_UN_I4)
2559 sp [-1].data.i = (guint32)sp [-1].data.i >> sp [0].data.i;
2562 MINT_IN_CASE(MINT_SHR_UN_I8)
2564 sp [-1].data.l = (guint64)sp [-1].data.l >> sp [0].data.i;
2567 MINT_IN_CASE(MINT_NEG_I4)
2568 sp [-1].data.i = - sp [-1].data.i;
2571 MINT_IN_CASE(MINT_NEG_I8)
2572 sp [-1].data.l = - sp [-1].data.l;
2575 MINT_IN_CASE(MINT_NEG_R8)
2576 sp [-1].data.f = - sp [-1].data.f;
2579 MINT_IN_CASE(MINT_NOT_I4)
2580 sp [-1].data.i = ~ sp [-1].data.i;
2583 MINT_IN_CASE(MINT_NOT_I8)
2584 sp [-1].data.l = ~ sp [-1].data.l;
2587 MINT_IN_CASE(MINT_CONV_I1_I4)
2588 sp [-1].data.i = (gint8)sp [-1].data.i;
2591 MINT_IN_CASE(MINT_CONV_I1_I8)
2592 sp [-1].data.i = (gint8)sp [-1].data.l;
2595 MINT_IN_CASE(MINT_CONV_I1_R8)
2596 sp [-1].data.i = (gint8)sp [-1].data.f;
2599 MINT_IN_CASE(MINT_CONV_U1_I4)
2600 sp [-1].data.i = (guint8)sp [-1].data.i;
2603 MINT_IN_CASE(MINT_CONV_U1_I8)
2604 sp [-1].data.i = (guint8)sp [-1].data.l;
2607 MINT_IN_CASE(MINT_CONV_U1_R8)
2608 sp [-1].data.i = (guint8)sp [-1].data.f;
2611 MINT_IN_CASE(MINT_CONV_I2_I4)
2612 sp [-1].data.i = (gint16)sp [-1].data.i;
2615 MINT_IN_CASE(MINT_CONV_I2_I8)
2616 sp [-1].data.i = (gint16)sp [-1].data.l;
2619 MINT_IN_CASE(MINT_CONV_I2_R8)
2620 sp [-1].data.i = (gint16)sp [-1].data.f;
2623 MINT_IN_CASE(MINT_CONV_U2_I4)
2624 sp [-1].data.i = (guint16)sp [-1].data.i;
2627 MINT_IN_CASE(MINT_CONV_U2_I8)
2628 sp [-1].data.i = (guint16)sp [-1].data.l;
2631 MINT_IN_CASE(MINT_CONV_U2_R8)
2632 sp [-1].data.i = (guint16)sp [-1].data.f;
2635 MINT_IN_CASE(MINT_CONV_I4_R8)
2636 sp [-1].data.i = (gint32)sp [-1].data.f;
2639 MINT_IN_CASE(MINT_CONV_U4_I8)
2640 MINT_IN_CASE(MINT_CONV_I4_I8)
2641 sp [-1].data.i = (gint32)sp [-1].data.l;
2644 MINT_IN_CASE(MINT_CONV_I4_I8_SP)
2645 sp [-2].data.i = (gint32)sp [-2].data.l;
2648 MINT_IN_CASE(MINT_CONV_U4_R8)
2649 sp [-1].data.i = (guint32)sp [-1].data.f;
2652 MINT_IN_CASE(MINT_CONV_I8_I4)
2653 sp [-1].data.l = sp [-1].data.i;
2656 MINT_IN_CASE(MINT_CONV_I8_I4_SP)
2657 sp [-2].data.l = sp [-2].data.i;
2660 MINT_IN_CASE(MINT_CONV_I8_U4)
2661 sp [-1].data.l = (guint32)sp [-1].data.i;
2664 MINT_IN_CASE(MINT_CONV_I8_R8)
2665 sp [-1].data.l = (gint64)sp [-1].data.f;
2668 MINT_IN_CASE(MINT_CONV_R4_I4)
2669 sp [-1].data.f = (float)sp [-1].data.i;
2672 MINT_IN_CASE(MINT_CONV_R4_I8)
2673 sp [-1].data.f = (float)sp [-1].data.l;
2676 MINT_IN_CASE(MINT_CONV_R4_R8)
2677 sp [-1].data.f = (float)sp [-1].data.f;
2680 MINT_IN_CASE(MINT_CONV_R8_I4)
2681 sp [-1].data.f = (double)sp [-1].data.i;
2684 MINT_IN_CASE(MINT_CONV_R8_I8)
2685 sp [-1].data.f = (double)sp [-1].data.l;
2688 MINT_IN_CASE(MINT_CONV_U8_I4)
2689 sp [-1].data.l = sp [-1].data.i & 0xffffffff;
2692 MINT_IN_CASE(MINT_CONV_U8_R8)
2693 sp [-1].data.l = (guint64)sp [-1].data.f;
2697 MINT_IN_CASE(MINT_CPOBJ) {
2700 vtklass = rtm->data_items[READ32 (ip)];
2703 memcpy (sp [0].data.p, sp [1].data.p, mono_class_value_size (vtklass, NULL));
2707 MINT_IN_CASE(MINT_LDOBJ) {
2710 c = rtm->data_items[* (guint16 *)(ip + 1)];
2712 if (c->byval_arg.type != MONO_TYPE_VALUETYPE || c->byval_arg.data.klass->enumtype) {
2714 stackval_from_data (&c->byval_arg, &sp [-1], p, FALSE);
2716 size = mono_class_value_size (c, NULL);
2718 sp [-1].data.p = vt_sp;
2719 memcpy(vt_sp, p, size);
2720 vt_sp += (size + 7) & ~7;
2724 MINT_IN_CASE(MINT_LDSTR)
2725 sp->data.p = rtm->data_items [* (guint16 *)(ip + 1)];
2729 MINT_IN_CASE(MINT_NEWOBJ) {
2730 MonoClass *newobj_class;
2731 MonoMethodSignature *csig;
2732 stackval valuetype_this;
2738 token = * (guint16 *)(ip + 1);
2741 child_frame.runtime_method = rtm->data_items [token];
2742 csig = mono_method_signature (child_frame.runtime_method->method);
2743 newobj_class = child_frame.runtime_method->method->klass;
2744 /*if (profiling_classes) {
2745 guint count = GPOINTER_TO_UINT (g_hash_table_lookup (profiling_classes, newobj_class));
2747 g_hash_table_insert (profiling_classes, newobj_class, GUINT_TO_POINTER (count));
2751 if (newobj_class->parent == mono_defaults.array_class) {
2752 sp -= csig->param_count;
2753 o = ves_array_create (context->domain, newobj_class, csig, sp);
2754 goto array_constructed;
2758 * First arg is the object.
2760 if (newobj_class->valuetype) {
2761 if (!newobj_class->enumtype && (newobj_class->byval_arg.type == MONO_TYPE_VALUETYPE)) {
2762 child_frame.obj = vt_sp;
2763 valuetype_this.data.p = vt_sp;
2765 memset (&valuetype_this, 0, sizeof (stackval));
2766 child_frame.obj = &valuetype_this;
2769 if (newobj_class != mono_defaults.string_class) {
2770 context->managed_code = 0;
2771 o = mono_object_new_checked (context->domain, newobj_class, &error);
2772 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2773 context->managed_code = 1;
2774 if (*mono_thread_interruption_request_flag ())
2775 mono_thread_interruption_checkpoint ();
2776 child_frame.obj = o;
2778 child_frame.retval = &retval;
2782 if (csig->param_count) {
2783 sp -= csig->param_count;
2784 child_frame.stack_args = sp;
2786 child_frame.stack_args = NULL;
2789 g_assert (csig->call_convention == MONO_CALL_DEFAULT);
2791 child_frame.ip = NULL;
2792 child_frame.ex = NULL;
2794 ves_exec_method_with_context (&child_frame, context);
2796 context->current_frame = frame;
2798 if (child_frame.ex) {
2800 * An exception occurred, need to run finally, fault and catch handlers..
2802 frame->ex = child_frame.ex;
2803 goto handle_finally;
2806 * a constructor returns void, but we need to return the object we created
2809 if (newobj_class->valuetype && !newobj_class->enumtype) {
2810 *sp = valuetype_this;
2811 } else if (newobj_class == mono_defaults.string_class) {
2819 MINT_IN_CASE(MINT_CASTCLASS)
2820 c = rtm->data_items [*(guint16 *)(ip + 1)];
2821 if ((o = sp [-1].data.p)) {
2822 MonoObject *isinst_obj = mono_object_isinst_checked (o, c, &error);
2823 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2825 THROW_EX (mono_get_exception_invalid_cast (), ip);
2829 MINT_IN_CASE(MINT_ISINST)
2830 c = rtm->data_items [*(guint16 *)(ip + 1)];
2831 if ((o = sp [-1].data.p)) {
2832 MonoObject *isinst_obj = mono_object_isinst_checked (o, c, &error);
2833 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2835 sp [-1].data.p = NULL;
2839 MINT_IN_CASE(MINT_CONV_R_UN_I4)
2840 sp [-1].data.f = (double)(guint32)sp [-1].data.i;
2843 MINT_IN_CASE(MINT_CONV_R_UN_I8)
2844 sp [-1].data.f = (double)(guint64)sp [-1].data.l;
2847 MINT_IN_CASE(MINT_UNBOX)
2848 c = rtm->data_items[*(guint16 *)(ip + 1)];
2852 THROW_EX (mono_get_exception_null_reference (), ip);
2854 MonoObject *isinst_obj = mono_object_isinst_checked (o, c, &error);
2855 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2856 if (!(isinst_obj || ((o->vtable->klass->rank == 0) && (o->vtable->klass->element_class == c->element_class))))
2857 THROW_EX (mono_get_exception_invalid_cast (), ip);
2859 if (c->byval_arg.type == MONO_TYPE_VALUETYPE && !c->enumtype) {
2860 g_error ("unbox: implement vt");
2862 stackval_from_data (&c->byval_arg, &sp [-1], mono_object_unbox (o), FALSE);
2866 MINT_IN_CASE(MINT_THROW)
2868 frame->ex_handler = NULL;
2870 sp->data.p = mono_get_exception_null_reference ();
2871 THROW_EX ((MonoException *)sp->data.p, ip);
2873 MINT_IN_CASE(MINT_LDFLDA)
2876 THROW_EX (mono_get_exception_null_reference (), ip);
2877 sp[-1].data.p = (char *)o + * (guint16 *)(ip + 1);
2880 MINT_IN_CASE(MINT_CKNULL)
2883 THROW_EX (mono_get_exception_null_reference (), ip);
2887 #define LDFLD(datamem, fieldtype) \
2888 o = sp [-1].data.p; \
2890 THROW_EX (mono_get_exception_null_reference (), ip); \
2891 sp[-1].data.datamem = * (fieldtype *)((char *)o + * (guint16 *)(ip + 1)) ; \
2894 MINT_IN_CASE(MINT_LDFLD_I1) LDFLD(i, gint8); MINT_IN_BREAK;
2895 MINT_IN_CASE(MINT_LDFLD_U1) LDFLD(i, guint8); MINT_IN_BREAK;
2896 MINT_IN_CASE(MINT_LDFLD_I2) LDFLD(i, gint16); MINT_IN_BREAK;
2897 MINT_IN_CASE(MINT_LDFLD_U2) LDFLD(i, guint16); MINT_IN_BREAK;
2898 MINT_IN_CASE(MINT_LDFLD_I4) LDFLD(i, gint32); MINT_IN_BREAK;
2899 MINT_IN_CASE(MINT_LDFLD_I8) LDFLD(l, gint64); MINT_IN_BREAK;
2900 MINT_IN_CASE(MINT_LDFLD_R4) LDFLD(f, float); MINT_IN_BREAK;
2901 MINT_IN_CASE(MINT_LDFLD_R8) LDFLD(f, double); MINT_IN_BREAK;
2902 MINT_IN_CASE(MINT_LDFLD_O) LDFLD(p, gpointer); MINT_IN_BREAK;
2903 MINT_IN_CASE(MINT_LDFLD_P) LDFLD(p, gpointer); MINT_IN_BREAK;
2905 MINT_IN_CASE(MINT_LDFLD_VT)
2908 THROW_EX (mono_get_exception_null_reference (), ip);
2909 i32 = READ32(ip + 2);
2910 sp [-1].data.p = vt_sp;
2911 memcpy(sp [-1].data.p, (char *)o + * (guint16 *)(ip + 1), i32);
2912 vt_sp += (i32 + 7) & ~7;
2916 MINT_IN_CASE(MINT_LDRMFLD) {
2918 MonoClassField *field;
2923 THROW_EX (mono_get_exception_null_reference (), ip);
2924 field = rtm->data_items[* (guint16 *)(ip + 1)];
2926 if (mono_object_is_transparent_proxy (o)) {
2927 MonoClass *klass = ((MonoTransparentProxy*)o)->remote_class->proxy_class;
2929 addr = mono_load_remote_field_checked (o, klass, field, &tmp, &error);
2930 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2932 addr = (char*)o + field->offset;
2935 stackval_from_data (field->type, &sp [-1], addr, FALSE);
2939 MINT_IN_CASE(MINT_LDRMFLD_VT) {
2940 MonoClassField *field;
2946 THROW_EX (mono_get_exception_null_reference (), ip);
2947 field = rtm->data_items[* (guint16 *)(ip + 1)];
2948 i32 = READ32(ip + 2);
2950 if (mono_object_is_transparent_proxy (o)) {
2951 MonoClass *klass = ((MonoTransparentProxy*)o)->remote_class->proxy_class;
2952 addr = mono_load_remote_field_checked (o, klass, field, &tmp, &error);
2953 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2955 addr = (char*)o + field->offset;
2958 sp [-1].data.p = vt_sp;
2959 memcpy(sp [-1].data.p, (char *)o + * (guint16 *)(ip + 1), i32);
2960 vt_sp += (i32 + 7) & ~7;
2961 memcpy(sp [-1].data.p, addr, i32);
2965 #define STFLD(datamem, fieldtype) \
2966 o = sp [-2].data.p; \
2968 THROW_EX (mono_get_exception_null_reference (), ip); \
2970 * (fieldtype *)((char *)o + * (guint16 *)(ip + 1)) = sp[1].data.datamem; \
2973 MINT_IN_CASE(MINT_STFLD_I1) STFLD(i, gint8); MINT_IN_BREAK;
2974 MINT_IN_CASE(MINT_STFLD_U1) STFLD(i, guint8); MINT_IN_BREAK;
2975 MINT_IN_CASE(MINT_STFLD_I2) STFLD(i, gint16); MINT_IN_BREAK;
2976 MINT_IN_CASE(MINT_STFLD_U2) STFLD(i, guint16); MINT_IN_BREAK;
2977 MINT_IN_CASE(MINT_STFLD_I4) STFLD(i, gint32); MINT_IN_BREAK;
2978 MINT_IN_CASE(MINT_STFLD_I8) STFLD(l, gint64); MINT_IN_BREAK;
2979 MINT_IN_CASE(MINT_STFLD_R4) STFLD(f, float); MINT_IN_BREAK;
2980 MINT_IN_CASE(MINT_STFLD_R8) STFLD(f, double); MINT_IN_BREAK;
2981 MINT_IN_CASE(MINT_STFLD_O) STFLD(p, gpointer); MINT_IN_BREAK;
2982 MINT_IN_CASE(MINT_STFLD_P) STFLD(p, gpointer); MINT_IN_BREAK;
2984 MINT_IN_CASE(MINT_STFLD_VT)
2987 THROW_EX (mono_get_exception_null_reference (), ip);
2988 i32 = READ32(ip + 2);
2990 memcpy((char *)o + * (guint16 *)(ip + 1), sp [1].data.p, i32);
2991 vt_sp -= (i32 + 7) & ~7;
2995 MINT_IN_CASE(MINT_STRMFLD) {
2996 MonoClassField *field;
3000 THROW_EX (mono_get_exception_null_reference (), ip);
3002 field = rtm->data_items[* (guint16 *)(ip + 1)];
3005 if (mono_object_is_transparent_proxy (o)) {
3006 MonoClass *klass = ((MonoTransparentProxy*)o)->remote_class->proxy_class;
3007 mono_store_remote_field_checked (o, klass, field, &sp [-1].data, &error);
3008 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3010 stackval_to_data (field->type, &sp [-1], (char*)o + field->offset, FALSE);
3015 MINT_IN_CASE(MINT_STRMFLD_VT) {
3016 MonoClassField *field;
3020 THROW_EX (mono_get_exception_null_reference (), ip);
3021 field = rtm->data_items[* (guint16 *)(ip + 1)];
3022 i32 = READ32(ip + 2);
3025 if (mono_object_is_transparent_proxy (o)) {
3026 MonoClass *klass = ((MonoTransparentProxy*)o)->remote_class->proxy_class;
3027 mono_store_remote_field_checked (o, klass, field, &sp [-1].data, &error);
3028 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3030 memcpy((char*)o + field->offset, sp [-1].data.p, i32);
3033 vt_sp -= (i32 + 7) & ~7;
3036 MINT_IN_CASE(MINT_LDSFLDA) {
3037 MonoClassField *field = rtm->data_items[*(guint16 *)(ip + 1)];
3038 MonoVTable *vt = mono_class_vtable (context->domain, field->parent);
3041 if (!vt->initialized) {
3043 mono_runtime_class_init_full (vt, &error);
3044 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3048 if (context->domain->special_static_fields && (addr = g_hash_table_lookup (context->domain->special_static_fields, field)))
3049 sp->data.p = mono_get_special_static_data (GPOINTER_TO_UINT (addr));
3051 sp->data.p = (char*)(vt->vtable) + field->offset;
3055 MINT_IN_CASE(MINT_LDSFLD) {
3057 MonoClassField *field;
3060 field = rtm->data_items[*(guint16 *)(ip + 1)];
3061 vt = rtm->data_items [*(guint16 *)(ip + 2)];
3062 if (!vt->initialized) {
3064 mono_runtime_class_init_full (vt, &error);
3065 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3068 if (context->domain->special_static_fields && (addr = g_hash_table_lookup (context->domain->special_static_fields, field)))
3069 addr = mono_get_special_static_data (GPOINTER_TO_UINT (addr));
3071 addr = (char*)(vt->vtable) + field->offset;
3073 stackval_from_data (field->type, sp, addr, FALSE);
3077 MINT_IN_CASE(MINT_LDSFLD_I4) {
3078 MonoClassField *field = rtm->data_items[*(guint16 *)(ip + 1)];
3079 MonoVTable *vt = rtm->data_items [*(guint16 *)(ip + 2)];
3080 if (!vt->initialized) {
3082 mono_runtime_class_init_full (vt, &error);
3083 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3086 sp->data.i = * (gint32 *)((char*)(vt->vtable) + field->offset);
3090 MINT_IN_CASE(MINT_LDSFLD_O) {
3091 MonoClassField *field = rtm->data_items[*(guint16 *)(ip + 1)];
3092 MonoVTable *vt = rtm->data_items [*(guint16 *)(ip + 2)];
3093 if (!vt->initialized) {
3095 mono_runtime_class_init_full (vt, &error);
3096 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3099 sp->data.p = * (gpointer *)((char*)(vt->vtable) + field->offset);
3103 MINT_IN_CASE(MINT_LDSFLD_VT) {
3105 MonoClassField *field;
3110 token = * (guint16 *)(ip + 1);
3111 size = READ32(ip + 2);
3112 field = rtm->data_items[token];
3115 vt = mono_class_vtable (context->domain, field->parent);
3116 if (!vt->initialized) {
3118 mono_runtime_class_init_full (vt, &error);
3119 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3122 if (context->domain->special_static_fields && (addr = g_hash_table_lookup (context->domain->special_static_fields, field)))
3123 addr = mono_get_special_static_data (GPOINTER_TO_UINT (addr));
3125 addr = (char*)(vt->vtable) + field->offset;
3128 vt_sp += (size + 7) & ~7;
3129 stackval_from_data (field->type, sp, addr, FALSE);
3133 MINT_IN_CASE(MINT_STSFLD) {
3135 MonoClassField *field;
3139 token = * (guint16 *)(ip + 1);
3140 field = rtm->data_items[token];
3144 vt = mono_class_vtable (context->domain, field->parent);
3145 if (!vt->initialized) {
3147 mono_runtime_class_init_full (vt, &error);
3148 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3151 if (context->domain->special_static_fields && (addr = g_hash_table_lookup (context->domain->special_static_fields, field)))
3152 addr = mono_get_special_static_data (GPOINTER_TO_UINT (addr));
3154 addr = (char*)(vt->vtable) + field->offset;
3156 stackval_to_data (field->type, sp, addr, FALSE);
3159 MINT_IN_CASE(MINT_STSFLD_VT) {
3161 MonoClassField *field;
3166 token = * (guint16 *)(ip + 1);
3167 size = READ32(ip + 2);
3168 field = rtm->data_items[token];
3171 vt = mono_class_vtable (context->domain, field->parent);
3172 if (!vt->initialized) {
3174 mono_runtime_class_init_full (vt, &error);
3175 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3178 if (context->domain->special_static_fields && (addr = g_hash_table_lookup (context->domain->special_static_fields, field)))
3179 addr = mono_get_special_static_data (GPOINTER_TO_UINT (addr));
3181 addr = (char*)(vt->vtable) + field->offset;
3183 stackval_to_data (field->type, sp, addr, FALSE);
3184 vt_sp -= (size + 7) & ~7;
3187 MINT_IN_CASE(MINT_STOBJ_VT) {
3189 c = rtm->data_items[* (guint16 *)(ip + 1)];
3191 size = mono_class_value_size (c, NULL);
3192 memcpy(sp [-2].data.p, sp [-1].data.p, size);
3193 vt_sp -= (size + 7) & ~7;
3197 MINT_IN_CASE(MINT_STOBJ) {
3199 c = rtm->data_items[* (guint16 *)(ip + 1)];
3201 size = mono_class_value_size (c, NULL);
3202 memcpy(sp [-2].data.p, &sp [-1].data, size);
3206 MINT_IN_CASE(MINT_CONV_OVF_I4_UN_R8)
3207 if (sp [-1].data.f < 0 || sp [-1].data.f > MYGUINT32_MAX)
3208 THROW_EX (mono_get_exception_overflow (), ip);
3209 sp [-1].data.i = (guint32)sp [-1].data.f;
3212 MINT_IN_CASE(MINT_CONV_OVF_U8_I4)
3213 if (sp [-1].data.i < 0)
3214 THROW_EX (mono_get_exception_overflow (), ip);
3215 sp [-1].data.l = sp [-1].data.i;
3218 MINT_IN_CASE(MINT_CONV_OVF_U8_R8)
3219 MINT_IN_CASE(MINT_CONV_OVF_I8_UN_R8)
3220 if (sp [-1].data.f < 0 || sp [-1].data.f > 9223372036854775807LL)
3221 THROW_EX (mono_get_exception_overflow (), ip);
3222 sp [-1].data.l = (guint64)sp [-1].data.f;
3225 MINT_IN_CASE(MINT_CONV_OVF_I8_R8)
3226 if (sp [-1].data.f < MYGINT64_MIN || sp [-1].data.f > MYGINT64_MAX)
3227 THROW_EX (mono_get_exception_overflow (), ip);
3228 sp [-1].data.l = (gint64)sp [-1].data.f;
3231 MINT_IN_CASE(MINT_CONV_OVF_I4_UN_I8)
3232 if ((mono_u)sp [-1].data.l > MYGUINT32_MAX)
3233 THROW_EX (mono_get_exception_overflow (), ip);
3234 sp [-1].data.i = (mono_u)sp [-1].data.l;
3237 MINT_IN_CASE(MINT_BOX)
3238 c = rtm->data_items [* (guint16 *)(ip + 1)];
3240 if (c->byval_arg.type == MONO_TYPE_VALUETYPE && !c->enumtype) {
3241 int size = mono_class_value_size (c, NULL);
3242 sp [-1].data.p = mono_value_box_checked (context->domain, c, sp [-1].data.p, &error);
3243 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3244 size = (size + 7) & ~7;
3248 stackval_to_data (&c->byval_arg, &sp [-1], (char*)&sp [-1], FALSE);
3249 sp [-1].data.p = mono_value_box_checked (context->domain, c, &sp [-1], &error);
3250 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3254 MINT_IN_CASE(MINT_NEWARR)
3255 sp [-1].data.p = (MonoObject*) mono_array_new_checked (context->domain, rtm->data_items[*(guint16 *)(ip + 1)], sp [-1].data.i, &error);
3256 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3258 /*if (profiling_classes) {
3259 guint count = GPOINTER_TO_UINT (g_hash_table_lookup (profiling_classes, o->vtable->klass));
3261 g_hash_table_insert (profiling_classes, o->vtable->klass, GUINT_TO_POINTER (count));
3265 MINT_IN_CASE(MINT_LDLEN)
3268 THROW_EX (mono_get_exception_null_reference (), ip);
3269 sp [-1].data.nati = mono_array_length ((MonoArray *)o);
3272 MINT_IN_CASE(MINT_GETCHR) {
3276 THROW_EX (mono_get_exception_null_reference (), ip);
3277 i32 = sp [-1].data.i;
3278 if (i32 < 0 || i32 >= mono_string_length (s))
3279 THROW_EX (mono_get_exception_index_out_of_range (), ip);
3281 sp [-1].data.i = mono_string_chars(s)[i32];
3285 MINT_IN_CASE(MINT_STRLEN)
3287 sp [-1].data.i = mono_string_length ((MonoString*)sp [-1].data.p);
3289 MINT_IN_CASE(MINT_ARRAY_RANK)
3292 THROW_EX (mono_get_exception_null_reference (), ip);
3293 sp [-1].data.i = mono_object_class (sp [-1].data.p)->rank;
3296 MINT_IN_CASE(MINT_LDELEMA) {
3300 /*token = READ32 (ip)*/;
3306 aindex = sp [1].data.i;
3307 if (aindex >= mono_array_length ((MonoArray *) o))
3308 THROW_EX (mono_get_exception_index_out_of_range (), ip - 2);
3310 /* check the array element corresponds to token */
3311 esize = mono_array_element_size (((MonoArray *) o)->obj.vtable->klass);
3313 sp->data.p = mono_array_addr_with_size ((MonoArray *) o, esize, aindex);
3317 MINT_IN_CASE(MINT_LDELEM_I1) /* fall through */
3318 MINT_IN_CASE(MINT_LDELEM_U1) /* fall through */
3319 MINT_IN_CASE(MINT_LDELEM_I2) /* fall through */
3320 MINT_IN_CASE(MINT_LDELEM_U2) /* fall through */
3321 MINT_IN_CASE(MINT_LDELEM_I4) /* fall through */
3322 MINT_IN_CASE(MINT_LDELEM_U4) /* fall through */
3323 MINT_IN_CASE(MINT_LDELEM_I8) /* fall through */
3324 MINT_IN_CASE(MINT_LDELEM_I) /* fall through */
3325 MINT_IN_CASE(MINT_LDELEM_R4) /* fall through */
3326 MINT_IN_CASE(MINT_LDELEM_R8) /* fall through */
3327 MINT_IN_CASE(MINT_LDELEM_REF) {
3335 THROW_EX (mono_get_exception_null_reference (), ip);
3337 aindex = sp [1].data.i;
3338 if (aindex >= mono_array_length (o))
3339 THROW_EX (mono_get_exception_index_out_of_range (), ip);
3342 * FIXME: throw mono_get_exception_array_type_mismatch () if needed
3345 case MINT_LDELEM_I1:
3346 sp [0].data.i = mono_array_get (o, gint8, aindex);
3348 case MINT_LDELEM_U1:
3349 sp [0].data.i = mono_array_get (o, guint8, aindex);
3351 case MINT_LDELEM_I2:
3352 sp [0].data.i = mono_array_get (o, gint16, aindex);
3354 case MINT_LDELEM_U2:
3355 sp [0].data.i = mono_array_get (o, guint16, aindex);
3358 sp [0].data.nati = mono_array_get (o, mono_i, aindex);
3360 case MINT_LDELEM_I4:
3361 sp [0].data.i = mono_array_get (o, gint32, aindex);
3363 case MINT_LDELEM_U4:
3364 sp [0].data.i = mono_array_get (o, guint32, aindex);
3366 case MINT_LDELEM_I8:
3367 sp [0].data.l = mono_array_get (o, guint64, aindex);
3369 case MINT_LDELEM_R4:
3370 sp [0].data.f = mono_array_get (o, float, aindex);
3372 case MINT_LDELEM_R8:
3373 sp [0].data.f = mono_array_get (o, double, aindex);
3375 case MINT_LDELEM_REF:
3376 sp [0].data.p = mono_array_get (o, gpointer, aindex);
3386 MINT_IN_CASE(MINT_STELEM_I) /* fall through */
3387 MINT_IN_CASE(MINT_STELEM_I1) /* fall through */
3388 MINT_IN_CASE(MINT_STELEM_I2) /* fall through */
3389 MINT_IN_CASE(MINT_STELEM_I4) /* fall through */
3390 MINT_IN_CASE(MINT_STELEM_I8) /* fall through */
3391 MINT_IN_CASE(MINT_STELEM_R4) /* fall through */
3392 MINT_IN_CASE(MINT_STELEM_R8) /* fall through */
3393 MINT_IN_CASE(MINT_STELEM_REF) {
3400 THROW_EX (mono_get_exception_null_reference (), ip);
3402 aindex = sp [1].data.i;
3403 if (aindex >= mono_array_length ((MonoArray *)o))
3404 THROW_EX (mono_get_exception_index_out_of_range (), ip);
3408 mono_array_set ((MonoArray *)o, mono_i, aindex, sp [2].data.nati);
3410 case MINT_STELEM_I1:
3411 mono_array_set ((MonoArray *)o, gint8, aindex, sp [2].data.i);
3413 case MINT_STELEM_I2:
3414 mono_array_set ((MonoArray *)o, gint16, aindex, sp [2].data.i);
3416 case MINT_STELEM_I4:
3417 mono_array_set ((MonoArray *)o, gint32, aindex, sp [2].data.i);
3419 case MINT_STELEM_I8:
3420 mono_array_set ((MonoArray *)o, gint64, aindex, sp [2].data.l);
3422 case MINT_STELEM_R4:
3423 mono_array_set ((MonoArray *)o, float, aindex, sp [2].data.f);
3425 case MINT_STELEM_R8:
3426 mono_array_set ((MonoArray *)o, double, aindex, sp [2].data.f);
3428 case MINT_STELEM_REF: {
3429 MonoObject *isinst_obj = mono_object_isinst_checked (sp [2].data.p, mono_object_class (o)->element_class, &error);
3430 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3431 if (sp [2].data.p && !isinst_obj)
3432 THROW_EX (mono_get_exception_array_type_mismatch (), ip);
3433 mono_array_set ((MonoArray *)o, gpointer, aindex, sp [2].data.p);
3442 MINT_IN_CASE(MINT_CONV_OVF_I4_U4)
3443 if (sp [-1].data.i < 0)
3444 THROW_EX (mono_get_exception_overflow (), ip);
3447 MINT_IN_CASE(MINT_CONV_OVF_I4_I8)
3448 if (sp [-1].data.l < MYGINT32_MIN || sp [-1].data.l > MYGINT32_MAX)
3449 THROW_EX (mono_get_exception_overflow (), ip);
3450 sp [-1].data.i = (gint32) sp [-1].data.l;
3453 MINT_IN_CASE(MINT_CONV_OVF_I4_R8)
3454 if (sp [-1].data.f < MYGINT32_MIN || sp [-1].data.f > MYGINT32_MAX)
3455 THROW_EX (mono_get_exception_overflow (), ip);
3456 sp [-1].data.i = (gint32) sp [-1].data.f;
3459 MINT_IN_CASE(MINT_CONV_OVF_U4_I4)
3460 if (sp [-1].data.i < 0)
3461 THROW_EX (mono_get_exception_overflow (), ip);
3464 MINT_IN_CASE(MINT_CONV_OVF_U4_I8)
3465 if (sp [-1].data.l < 0 || sp [-1].data.l > MYGUINT32_MAX)
3466 THROW_EX (mono_get_exception_overflow (), ip);
3467 sp [-1].data.i = (guint32) sp [-1].data.l;
3470 MINT_IN_CASE(MINT_CONV_OVF_U4_R8)
3471 if (sp [-1].data.f < 0 || sp [-1].data.f > MYGUINT32_MAX)
3472 THROW_EX (mono_get_exception_overflow (), ip);
3473 sp [-1].data.i = (guint32) sp [-1].data.f;
3476 MINT_IN_CASE(MINT_CONV_OVF_I2_I4)
3477 if (sp [-1].data.i < -32768 || sp [-1].data.i > 32767)
3478 THROW_EX (mono_get_exception_overflow (), ip);
3481 MINT_IN_CASE(MINT_CONV_OVF_I2_I8)
3482 if (sp [-1].data.l < -32768 || sp [-1].data.l > 32767)
3483 THROW_EX (mono_get_exception_overflow (), ip);
3484 sp [-1].data.i = (gint16) sp [-1].data.l;
3487 MINT_IN_CASE(MINT_CONV_OVF_I2_R8)
3488 if (sp [-1].data.f < -32768 || sp [-1].data.f > 32767)
3489 THROW_EX (mono_get_exception_overflow (), ip);
3490 sp [-1].data.i = (gint16) sp [-1].data.f;
3493 MINT_IN_CASE(MINT_CONV_OVF_U2_I4)
3494 if (sp [-1].data.i < 0 || sp [-1].data.i > 65535)
3495 THROW_EX (mono_get_exception_overflow (), ip);
3498 MINT_IN_CASE(MINT_CONV_OVF_U2_I8)
3499 if (sp [-1].data.l < 0 || sp [-1].data.l > 65535)
3500 THROW_EX (mono_get_exception_overflow (), ip);
3501 sp [-1].data.i = (guint16) sp [-1].data.l;
3504 MINT_IN_CASE(MINT_CONV_OVF_U2_R8)
3505 if (sp [-1].data.f < 0 || sp [-1].data.f > 65535)
3506 THROW_EX (mono_get_exception_overflow (), ip);
3507 sp [-1].data.i = (guint16) sp [-1].data.f;
3510 MINT_IN_CASE(MINT_CONV_OVF_I1_I4)
3511 if (sp [-1].data.i < -128 || sp [-1].data.i > 127)
3512 THROW_EX (mono_get_exception_overflow (), ip);
3515 MINT_IN_CASE(MINT_CONV_OVF_I1_I8)
3516 if (sp [-1].data.l < -128 || sp [-1].data.l > 127)
3517 THROW_EX (mono_get_exception_overflow (), ip);
3518 sp [-1].data.i = (gint8) sp [-1].data.l;
3521 MINT_IN_CASE(MINT_CONV_OVF_I1_R8)
3522 if (sp [-1].data.f < -128 || sp [-1].data.f > 127)
3523 THROW_EX (mono_get_exception_overflow (), ip);
3524 sp [-1].data.i = (gint8) sp [-1].data.f;
3527 MINT_IN_CASE(MINT_CONV_OVF_U1_I4)
3528 if (sp [-1].data.i < 0 || sp [-1].data.i > 255)
3529 THROW_EX (mono_get_exception_overflow (), ip);
3532 MINT_IN_CASE(MINT_CONV_OVF_U1_I8)
3533 if (sp [-1].data.l < 0 || sp [-1].data.l > 255)
3534 THROW_EX (mono_get_exception_overflow (), ip);
3535 sp [-1].data.i = (guint8) sp [-1].data.l;
3538 MINT_IN_CASE(MINT_CONV_OVF_U1_R8)
3539 if (sp [-1].data.f < 0 || sp [-1].data.f > 255)
3540 THROW_EX (mono_get_exception_overflow (), ip);
3541 sp [-1].data.i = (guint8) sp [-1].data.f;
3545 MINT_IN_CASE(MINT_LDELEM)
3546 MINT_IN_CASE(MINT_STELEM)
3547 MINT_IN_CASE(MINT_UNBOX_ANY)
3549 MINT_IN_CASE(MINT_REFANYVAL) ves_abort(); MINT_IN_BREAK;
3551 MINT_IN_CASE(MINT_CKFINITE)
3552 if (!isfinite(sp [-1].data.f))
3553 THROW_EX (mono_get_exception_arithmetic (), ip);
3557 MINT_IN_CASE(MINT_MKREFANY) ves_abort(); MINT_IN_BREAK;
3559 MINT_IN_CASE(MINT_LDTOKEN)
3562 * (gpointer *)sp->data.p = rtm->data_items[*(guint16 *)(ip + 1)];
3566 MINT_IN_CASE(MINT_ADD_OVF_I4)
3567 if (CHECK_ADD_OVERFLOW (sp [-2].data.i, sp [-1].data.i))
3568 THROW_EX (mono_get_exception_overflow (), ip);
3571 MINT_IN_CASE(MINT_ADD_OVF_I8)
3572 if (CHECK_ADD_OVERFLOW64 (sp [-2].data.l, sp [-1].data.l))
3573 THROW_EX (mono_get_exception_overflow (), ip);
3576 MINT_IN_CASE(MINT_ADD_OVF_UN_I4)
3577 if (CHECK_ADD_OVERFLOW_UN (sp [-2].data.i, sp [-1].data.i))
3578 THROW_EX (mono_get_exception_overflow (), ip);
3579 BINOP_CAST(i, +, guint32);
3581 MINT_IN_CASE(MINT_ADD_OVF_UN_I8)
3582 if (CHECK_ADD_OVERFLOW64_UN (sp [-2].data.l, sp [-1].data.l))
3583 THROW_EX (mono_get_exception_overflow (), ip);
3584 BINOP_CAST(l, +, guint64);
3586 MINT_IN_CASE(MINT_MUL_OVF_I4)
3587 if (CHECK_MUL_OVERFLOW (sp [-2].data.i, sp [-1].data.i))
3588 THROW_EX (mono_get_exception_overflow (), ip);
3591 MINT_IN_CASE(MINT_MUL_OVF_I8)
3592 if (CHECK_MUL_OVERFLOW64 (sp [-2].data.l, sp [-1].data.l))
3593 THROW_EX (mono_get_exception_overflow (), ip);
3596 MINT_IN_CASE(MINT_MUL_OVF_UN_I4)
3597 if (CHECK_MUL_OVERFLOW_UN (sp [-2].data.i, sp [-1].data.i))
3598 THROW_EX (mono_get_exception_overflow (), ip);
3599 BINOP_CAST(i, *, guint32);
3601 MINT_IN_CASE(MINT_MUL_OVF_UN_I8)
3602 if (CHECK_MUL_OVERFLOW64_UN (sp [-2].data.l, sp [-1].data.l))
3603 THROW_EX (mono_get_exception_overflow (), ip);
3604 BINOP_CAST(l, *, guint64);
3606 MINT_IN_CASE(MINT_SUB_OVF_I4)
3607 if (CHECK_SUB_OVERFLOW (sp [-2].data.i, sp [-1].data.i))
3608 THROW_EX (mono_get_exception_overflow (), ip);
3611 MINT_IN_CASE(MINT_SUB_OVF_I8)
3612 if (CHECK_SUB_OVERFLOW64 (sp [-2].data.l, sp [-1].data.l))
3613 THROW_EX (mono_get_exception_overflow (), ip);
3616 MINT_IN_CASE(MINT_SUB_OVF_UN_I4)
3617 if (CHECK_SUB_OVERFLOW_UN (sp [-2].data.i, sp [-1].data.i))
3618 THROW_EX (mono_get_exception_overflow (), ip);
3619 BINOP_CAST(i, -, guint32);
3621 MINT_IN_CASE(MINT_SUB_OVF_UN_I8)
3622 if (CHECK_SUB_OVERFLOW64_UN (sp [-2].data.l, sp [-1].data.l))
3623 THROW_EX (mono_get_exception_overflow (), ip);
3624 BINOP_CAST(l, -, guint64);
3626 MINT_IN_CASE(MINT_ENDFINALLY)
3628 ip = finally_ips->data;
3629 finally_ips = g_slist_remove (finally_ips, ip);
3636 MINT_IN_CASE(MINT_LEAVE) /* Fall through */
3637 MINT_IN_CASE(MINT_LEAVE_S)
3638 while (sp > frame->stack) {
3642 if (*ip == MINT_LEAVE_S) {
3643 ip += (short) *(ip + 1);
3645 ip += (gint32) READ32 (ip + 1);
3648 if (frame->ex_handler != NULL && MONO_OFFSET_IN_HANDLER(frame->ex_handler, frame->ip - rtm->code)) {
3649 frame->ex_handler = NULL;
3652 goto handle_finally;
3654 MINT_IN_CASE(MINT_ICALL_V_V)
3655 MINT_IN_CASE(MINT_ICALL_V_P)
3656 MINT_IN_CASE(MINT_ICALL_P_V)
3657 MINT_IN_CASE(MINT_ICALL_P_P)
3658 MINT_IN_CASE(MINT_ICALL_PP_V)
3659 MINT_IN_CASE(MINT_ICALL_PI_V)
3660 MINT_IN_CASE(MINT_ICALL_PP_P)
3661 MINT_IN_CASE(MINT_ICALL_PI_P)
3662 MINT_IN_CASE(MINT_ICALL_PPP_V)
3663 MINT_IN_CASE(MINT_ICALL_PPI_V)
3664 sp = do_icall (context, *ip, sp, rtm->data_items [*(guint16 *)(ip + 1)]);
3665 if (frame->ex != NULL)
3666 goto handle_exception;
3669 MINT_IN_CASE(MINT_MONO_LDPTR)
3670 sp->data.p = rtm->data_items [*(guint16 *)(ip + 1)];
3674 MINT_IN_CASE(MINT_MONO_NEWOBJ)
3675 sp->data.p = mono_object_new_checked (context->domain, rtm->data_items [*(guint16 *)(ip + 1)], &error);
3676 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3680 MINT_IN_CASE(MINT_MONO_FREE)
3683 g_error ("that doesn't seem right");
3684 g_free (sp->data.p);
3686 MINT_IN_CASE(MINT_MONO_RETOBJ)
3689 stackval_from_data (mono_method_signature (frame->runtime_method->method)->ret, frame->retval, sp->data.p,
3690 mono_method_signature (frame->runtime_method->method)->pinvoke);
3691 if (sp > frame->stack)
3692 g_warning ("retobj: more values on stack: %d", sp-frame->stack);
3695 #define RELOP(datamem, op) \
3697 sp [-1].data.i = sp [-1].data.datamem op sp [0].data.datamem; \
3699 MINT_IN_CASE(MINT_CEQ_I4)
3702 MINT_IN_CASE(MINT_CEQ0_I4)
3703 sp [-1].data.i = (sp [-1].data.i == 0);
3706 MINT_IN_CASE(MINT_CEQ_I8)
3709 MINT_IN_CASE(MINT_CEQ_R8)
3711 if (isunordered (sp [-1].data.f, sp [0].data.f))
3714 sp [-1].data.i = sp [-1].data.f == sp [0].data.f;
3717 MINT_IN_CASE(MINT_CGT_I4)
3720 MINT_IN_CASE(MINT_CGT_I8)
3723 MINT_IN_CASE(MINT_CGT_R8)
3725 if (isunordered (sp [-1].data.f, sp [0].data.f))
3728 sp [-1].data.i = sp [-1].data.f > sp [0].data.f;
3732 #define RELOP_CAST(datamem, op, type) \
3734 sp [-1].data.i = (type)sp [-1].data.datamem op (type)sp [0].data.datamem; \
3737 MINT_IN_CASE(MINT_CGT_UN_I4)
3738 RELOP_CAST(i, >, guint32);
3740 MINT_IN_CASE(MINT_CGT_UN_I8)
3741 RELOP_CAST(l, >, guint64);
3743 MINT_IN_CASE(MINT_CGT_UN_R8)
3745 if (isunordered (sp [-1].data.f, sp [0].data.f))
3748 sp [-1].data.i = sp [-1].data.f > sp [0].data.f;
3751 MINT_IN_CASE(MINT_CLT_I4)
3754 MINT_IN_CASE(MINT_CLT_I8)
3757 MINT_IN_CASE(MINT_CLT_R8)
3759 if (isunordered (sp [-1].data.f, sp [0].data.f))
3762 sp [-1].data.i = sp [-1].data.f < sp [0].data.f;
3765 MINT_IN_CASE(MINT_CLT_UN_I4)
3766 RELOP_CAST(i, <, guint32);
3768 MINT_IN_CASE(MINT_CLT_UN_I8)
3769 RELOP_CAST(l, <, guint64);
3771 MINT_IN_CASE(MINT_CLT_UN_R8)
3773 if (isunordered (sp [-1].data.f, sp [0].data.f))
3776 sp [-1].data.i = sp [-1].data.f < sp [0].data.f;
3779 MINT_IN_CASE(MINT_LDFTN) {
3780 sp->data.p = rtm->data_items [* (guint16 *)(ip + 1)];
3785 MINT_IN_CASE(MINT_LDVIRTFTN) {
3786 RuntimeMethod *m = rtm->data_items [* (guint16 *)(ip + 1)];
3790 THROW_EX (mono_get_exception_null_reference (), ip - 2);
3792 sp->data.p = get_virtual_method (context->domain, m, sp->data.p);
3797 MINT_IN_CASE(MINT_LDTHIS)
3798 sp->data.p = frame->obj;
3802 MINT_IN_CASE(MINT_STTHIS)
3804 frame->obj = sp->data.p;
3807 MINT_IN_CASE(MINT_LDTHISA)
3808 sp->data.p = &frame->obj;
3813 #define LDARG(datamem, argtype) \
3814 sp->data.datamem = * (argtype *)(frame->args + * (guint16 *)(ip + 1)); \
3818 MINT_IN_CASE(MINT_LDARG_I1) LDARG(i, gint8); MINT_IN_BREAK;
3819 MINT_IN_CASE(MINT_LDARG_U1) LDARG(i, guint8); MINT_IN_BREAK;
3820 MINT_IN_CASE(MINT_LDARG_I2) LDARG(i, gint16); MINT_IN_BREAK;
3821 MINT_IN_CASE(MINT_LDARG_U2) LDARG(i, guint16); MINT_IN_BREAK;
3822 MINT_IN_CASE(MINT_LDARG_I4) LDARG(i, gint32); MINT_IN_BREAK;
3823 MINT_IN_CASE(MINT_LDARG_I8) LDARG(l, gint64); MINT_IN_BREAK;
3824 MINT_IN_CASE(MINT_LDARG_R4) LDARG(f, float); MINT_IN_BREAK;
3825 MINT_IN_CASE(MINT_LDARG_R8) LDARG(f, double); MINT_IN_BREAK;
3826 MINT_IN_CASE(MINT_LDARG_O) LDARG(p, gpointer); MINT_IN_BREAK;
3827 MINT_IN_CASE(MINT_LDARG_P) LDARG(p, gpointer); MINT_IN_BREAK;
3829 MINT_IN_CASE(MINT_LDARG_VT)
3831 i32 = READ32(ip + 2);
3832 memcpy(sp->data.p, frame->args + * (guint16 *)(ip + 1), i32);
3833 vt_sp += (i32 + 7) & ~7;
3838 #define STARG(datamem, argtype) \
3840 * (argtype *)(frame->args + * (guint16 *)(ip + 1)) = sp->data.datamem; \
3843 MINT_IN_CASE(MINT_STARG_I1) STARG(i, gint8); MINT_IN_BREAK;
3844 MINT_IN_CASE(MINT_STARG_U1) STARG(i, guint8); MINT_IN_BREAK;
3845 MINT_IN_CASE(MINT_STARG_I2) STARG(i, gint16); MINT_IN_BREAK;
3846 MINT_IN_CASE(MINT_STARG_U2) STARG(i, guint16); MINT_IN_BREAK;
3847 MINT_IN_CASE(MINT_STARG_I4) STARG(i, gint32); MINT_IN_BREAK;
3848 MINT_IN_CASE(MINT_STARG_I8) STARG(l, gint64); MINT_IN_BREAK;
3849 MINT_IN_CASE(MINT_STARG_R4) STARG(f, float); MINT_IN_BREAK;
3850 MINT_IN_CASE(MINT_STARG_R8) STARG(f, double); MINT_IN_BREAK;
3851 MINT_IN_CASE(MINT_STARG_O) STARG(p, gpointer); MINT_IN_BREAK;
3852 MINT_IN_CASE(MINT_STARG_P) STARG(p, gpointer); MINT_IN_BREAK;
3854 MINT_IN_CASE(MINT_STARG_VT)
3855 i32 = READ32(ip + 2);
3857 memcpy(frame->args + * (guint16 *)(ip + 1), sp->data.p, i32);
3858 vt_sp -= (i32 + 7) & ~7;
3862 #define STINARG(datamem, argtype) \
3864 int n = * (guint16 *)(ip + 1); \
3865 * (argtype *)(frame->args + rtm->arg_offsets [n]) = frame->stack_args [n].data.datamem; \
3869 MINT_IN_CASE(MINT_STINARG_I1) STINARG(i, gint8); MINT_IN_BREAK;
3870 MINT_IN_CASE(MINT_STINARG_U1) STINARG(i, guint8); MINT_IN_BREAK;
3871 MINT_IN_CASE(MINT_STINARG_I2) STINARG(i, gint16); MINT_IN_BREAK;
3872 MINT_IN_CASE(MINT_STINARG_U2) STINARG(i, guint16); MINT_IN_BREAK;
3873 MINT_IN_CASE(MINT_STINARG_I4) STINARG(i, gint32); MINT_IN_BREAK;
3874 MINT_IN_CASE(MINT_STINARG_I8) STINARG(l, gint64); MINT_IN_BREAK;
3875 MINT_IN_CASE(MINT_STINARG_R4) STINARG(f, float); MINT_IN_BREAK;
3876 MINT_IN_CASE(MINT_STINARG_R8) STINARG(f, double); MINT_IN_BREAK;
3877 MINT_IN_CASE(MINT_STINARG_O) STINARG(p, gpointer); MINT_IN_BREAK;
3878 MINT_IN_CASE(MINT_STINARG_P) STINARG(p, gpointer); MINT_IN_BREAK;
3880 MINT_IN_CASE(MINT_STINARG_VT) {
3881 int n = * (guint16 *)(ip + 1);
3882 i32 = READ32(ip + 2);
3883 memcpy (frame->args + rtm->arg_offsets [n], frame->stack_args [n].data.p, i32);
3888 MINT_IN_CASE(MINT_LDARGA)
3889 sp->data.p = frame->args + * (guint16 *)(ip + 1);
3894 #define LDLOC(datamem, argtype) \
3895 sp->data.datamem = * (argtype *)(locals + * (guint16 *)(ip + 1)); \
3899 MINT_IN_CASE(MINT_LDLOC_I1) LDLOC(i, gint8); MINT_IN_BREAK;
3900 MINT_IN_CASE(MINT_LDLOC_U1) LDLOC(i, guint8); MINT_IN_BREAK;
3901 MINT_IN_CASE(MINT_LDLOC_I2) LDLOC(i, gint16); MINT_IN_BREAK;
3902 MINT_IN_CASE(MINT_LDLOC_U2) LDLOC(i, guint16); MINT_IN_BREAK;
3903 MINT_IN_CASE(MINT_LDLOC_I4) LDLOC(i, gint32); MINT_IN_BREAK;
3904 MINT_IN_CASE(MINT_LDLOC_I8) LDLOC(l, gint64); MINT_IN_BREAK;
3905 MINT_IN_CASE(MINT_LDLOC_R4) LDLOC(f, float); MINT_IN_BREAK;
3906 MINT_IN_CASE(MINT_LDLOC_R8) LDLOC(f, double); MINT_IN_BREAK;
3907 MINT_IN_CASE(MINT_LDLOC_O) LDLOC(p, gpointer); MINT_IN_BREAK;
3908 MINT_IN_CASE(MINT_LDLOC_P) LDLOC(p, gpointer); MINT_IN_BREAK;
3910 MINT_IN_CASE(MINT_LDLOC_VT)
3912 i32 = READ32(ip + 2);
3913 memcpy(sp->data.p, locals + * (guint16 *)(ip + 1), i32);
3914 vt_sp += (i32 + 7) & ~7;
3919 MINT_IN_CASE(MINT_LDLOCA_S)
3920 sp->data.p = locals + * (guint16 *)(ip + 1);
3925 #define STLOC(datamem, argtype) \
3927 * (argtype *)(locals + * (guint16 *)(ip + 1)) = sp->data.datamem; \
3930 MINT_IN_CASE(MINT_STLOC_I1) STLOC(i, gint8); MINT_IN_BREAK;
3931 MINT_IN_CASE(MINT_STLOC_U1) STLOC(i, guint8); MINT_IN_BREAK;
3932 MINT_IN_CASE(MINT_STLOC_I2) STLOC(i, gint16); MINT_IN_BREAK;
3933 MINT_IN_CASE(MINT_STLOC_U2) STLOC(i, guint16); MINT_IN_BREAK;
3934 MINT_IN_CASE(MINT_STLOC_I4) STLOC(i, gint32); MINT_IN_BREAK;
3935 MINT_IN_CASE(MINT_STLOC_I8) STLOC(l, gint64); MINT_IN_BREAK;
3936 MINT_IN_CASE(MINT_STLOC_R4) STLOC(f, float); MINT_IN_BREAK;
3937 MINT_IN_CASE(MINT_STLOC_R8) STLOC(f, double); MINT_IN_BREAK;
3938 MINT_IN_CASE(MINT_STLOC_O) STLOC(p, gpointer); MINT_IN_BREAK;
3939 MINT_IN_CASE(MINT_STLOC_P) STLOC(p, gpointer); MINT_IN_BREAK;
3941 #define STLOC_NP(datamem, argtype) \
3942 * (argtype *)(locals + * (guint16 *)(ip + 1)) = sp [-1].data.datamem; \
3945 MINT_IN_CASE(MINT_STLOC_NP_I4) STLOC_NP(i, gint32); MINT_IN_BREAK;
3946 MINT_IN_CASE(MINT_STLOC_NP_O) STLOC_NP(p, gpointer); MINT_IN_BREAK;
3948 MINT_IN_CASE(MINT_STLOC_VT)
3949 i32 = READ32(ip + 2);
3951 memcpy(locals + * (guint16 *)(ip + 1), sp->data.p, i32);
3952 vt_sp -= (i32 + 7) & ~7;
3956 MINT_IN_CASE(MINT_LOCALLOC)
3957 if (sp != frame->stack + 1) /*FIX?*/
3958 THROW_EX (mono_get_exception_execution_engine (NULL), ip);
3959 sp [-1].data.p = alloca (sp [-1].data.i);
3963 MINT_IN_CASE(MINT_ENDFILTER) ves_abort(); MINT_IN_BREAK;
3965 MINT_IN_CASE(MINT_INITOBJ)
3967 memset (sp->data.vt, 0, READ32(ip + 1));
3970 MINT_IN_CASE(MINT_CPBLK)
3972 if (!sp [0].data.p || !sp [1].data.p)
3973 THROW_EX (mono_get_exception_null_reference(), ip - 1);
3975 /* FIXME: value and size may be int64... */
3976 memcpy (sp [0].data.p, sp [1].data.p, sp [2].data.i);
3979 MINT_IN_CASE(MINT_CONSTRAINED_) {
3981 /* FIXME: implement */
3983 token = READ32 (ip);
3988 MINT_IN_CASE(MINT_INITBLK)
3991 THROW_EX (mono_get_exception_null_reference(), ip - 1);
3993 /* FIXME: value and size may be int64... */
3994 memset (sp [0].data.p, sp [1].data.i, sp [2].data.i);
3997 MINT_IN_CASE(MINT_NO_)
3998 /* FIXME: implement */
4002 MINT_IN_CASE(MINT_RETHROW)
4004 * need to clarify what this should actually do:
4005 * start the search from the last found handler in
4006 * this method or continue in the caller or what.
4007 * Also, do we need to run finally/fault handlers after a retrow?
4008 * Well, this implementation will follow the usual search
4009 * for an handler, considering the current ip as throw spot.
4010 * We need to NULL frame->ex_handler for the later code to
4011 * actually run the new found handler.
4013 frame->ex_handler = NULL;
4014 THROW_EX (frame->ex, ip - 1);
4017 g_print ("Unimplemented opcode: %04x %s at 0x%x\n", *ip, mono_interp_opname[*ip], ip-rtm->code);
4018 THROW_EX (mono_get_exception_execution_engine ("Unimplemented opcode"), ip);
4022 g_assert_not_reached ();
4024 * Exception handling code.
4025 * The exception object is stored in frame->ex.
4032 MonoInvocation *inv;
4033 MonoExceptionClause *clause;
4039 g_print ("* Handling exception '%s' at IL_%04x\n",
4040 frame->ex == NULL ? "** Unknown **" : mono_object_class (frame->ex)->name,
4041 rtm == NULL ? 0 : frame->ip - rtm->code);
4043 if (die_on_exception)
4046 for (inv = frame; inv; inv = inv->parent) {
4048 if (inv->runtime_method == NULL)
4050 method = inv->runtime_method->method;
4051 if (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL)
4053 if (method->iflags & (METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL | METHOD_IMPL_ATTRIBUTE_RUNTIME))
4055 if (inv->ip == NULL)
4057 ip_offset = inv->ip - inv->runtime_method->code;
4058 inv->ex_handler = NULL; /* clear this in case we are trhowing an exception while handling one - this one wins */
4059 for (i = 0; i < inv->runtime_method->num_clauses; ++i) {
4060 clause = &inv->runtime_method->clauses [i];
4061 if (clause->flags <= 1 && MONO_OFFSET_IN_CLAUSE (clause, ip_offset)) {
4062 if (!clause->flags) {
4063 MonoObject *isinst_obj = mono_object_isinst_checked ((MonoObject*)frame->ex, clause->data.catch_class, &error);
4064 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4067 * OK, we found an handler, now we need to execute the finally
4068 * and fault blocks before branching to the handler code.
4070 inv->ex_handler = clause;
4073 g_print ("* Found handler at '%s'\n", method->name);
4075 goto handle_finally;
4078 /* FIXME: handle filter clauses */
4085 * If we get here, no handler was found: print a stack trace.
4087 for (inv = frame; inv; inv = inv->parent) {
4088 if (inv->invoke_trap)
4089 goto handle_finally;
4092 ex_obj = (MonoObject*)frame->ex;
4093 mono_unhandled_exception (ex_obj);
4100 MonoExceptionClause *clause;
4101 GSList *old_list = finally_ips;
4102 MonoMethod *method = frame->runtime_method->method;
4103 MonoMethodHeader *header = mono_method_get_header_checked (method, &error);
4104 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4108 g_print ("* Handle finally IL_%04x\n", endfinally_ip == NULL ? 0 : endfinally_ip - rtm->code);
4110 if (rtm == NULL || (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL)
4111 || (method->iflags & (METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL | METHOD_IMPL_ATTRIBUTE_RUNTIME))) {
4114 ip_offset = frame->ip - rtm->code;
4116 if (endfinally_ip != NULL)
4117 finally_ips = g_slist_prepend(finally_ips, (void *)endfinally_ip);
4118 for (i = 0; i < header->num_clauses; ++i)
4119 if (frame->ex_handler == &rtm->clauses [i])
4123 clause = &rtm->clauses [i];
4124 if (MONO_OFFSET_IN_CLAUSE (clause, ip_offset) && (endfinally_ip == NULL || !(MONO_OFFSET_IN_CLAUSE (clause, endfinally_ip - rtm->code)))) {
4125 if (clause->flags == MONO_EXCEPTION_CLAUSE_FINALLY) {
4126 ip = rtm->code + clause->handler_offset;
4127 finally_ips = g_slist_prepend (finally_ips, (gpointer) ip);
4130 g_print ("* Found finally at IL_%04x with exception: %s\n", clause->handler_offset, frame->ex? "yes": "no");
4136 endfinally_ip = NULL;
4138 if (old_list != finally_ips && finally_ips) {
4139 ip = finally_ips->data;
4140 finally_ips = g_slist_remove (finally_ips, ip);
4141 sp = frame->stack; /* spec says stack should be empty at endfinally so it should be at the start too */
4146 * If an exception is set, we need to execute the fault handler, too,
4147 * otherwise, we continue normally.
4157 MonoExceptionClause *clause;
4158 MonoMethod *method = frame->runtime_method->method;
4159 MonoMethodHeader *header = mono_method_get_header_checked (method, &error);
4160 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4164 g_print ("* Handle fault\n");
4166 ip_offset = frame->ip - rtm->code;
4167 for (i = 0; i < header->num_clauses; ++i) {
4168 clause = &rtm->clauses [i];
4169 if (clause->flags == MONO_EXCEPTION_CLAUSE_FAULT && MONO_OFFSET_IN_CLAUSE (clause, ip_offset)) {
4170 ip = rtm->code + clause->handler_offset;
4173 g_print ("* Executing handler at IL_%04x\n", clause->handler_offset);
4179 * If the handler for the exception was found in this method, we jump
4180 * to it right away, otherwise we return and let the caller run
4181 * the finally, fault and catch blocks.
4182 * This same code should be present in the endfault opcode, but it
4183 * is corrently not assigned in the ECMA specs: LAMESPEC.
4185 if (frame->ex_handler) {
4188 g_print ("* Executing handler at IL_%04x\n", frame->ex_handler->handler_offset);
4190 ip = rtm->code + frame->ex_handler->handler_offset;
4192 vt_sp = (unsigned char *) sp + rtm->stack_size;
4193 sp->data.p = frame->ex;
4204 ves_exec_method (MonoInvocation *frame)
4206 ThreadContext *context = mono_native_tls_get_value (thread_context_id);
4207 ThreadContext context_struct;
4214 mono_unhandled_exception ((MonoObject*)frame->ex);
4217 if (context == NULL) {
4218 context = &context_struct;
4219 context_struct.domain = mono_domain_get ();
4220 context_struct.base_frame = frame;
4221 context_struct.current_frame = NULL;
4222 context_struct.env_frame = frame;
4223 context_struct.current_env = &env;
4224 context_struct.search_for_handler = 0;
4225 context_struct.managed_code = 0;
4226 mono_native_tls_set_value (thread_context_id, context);
4229 frame->parent = context->current_frame;
4230 frame->runtime_method = mono_interp_get_runtime_method (context->domain, frame->method, &error);
4231 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4232 context->managed_code = 1;
4233 ves_exec_method_with_context (frame, context);
4234 context->managed_code = 0;
4236 if (context != &context_struct && context->current_env) {
4237 context->env_frame->ex = frame->ex;
4238 longjmp (*context->current_env, 1);
4241 mono_unhandled_exception ((MonoObject*)frame->ex);
4243 if (context->base_frame == frame)
4244 mono_native_tls_set_value (thread_context_id, NULL);
4246 context->current_frame = frame->parent;
4250 ves_exec (MonoDomain *domain, MonoAssembly *assembly, int argc, char *argv[])
4252 MonoImage *image = mono_assembly_get_image (assembly);
4257 method = mono_get_method_checked (image, mono_image_get_entry_point (image), NULL, NULL, &error);
4258 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4261 g_error ("No entry point method found in %s", mono_image_get_filename (image));
4263 rval = mono_runtime_run_main_checked (method, argc, argv, &error);
4264 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4272 "mint %s, the Mono ECMA CLI interpreter, (C) 2001, 2002 Ximian, Inc.\n\n"
4273 "Usage is: mint [options] executable args...\n\n", VERSION);
4275 "Runtime Debugging:\n"
4280 " --noptr\t\t\tdon't print pointer addresses in trace output\n"
4283 " --traceclassinit\n"
4286 " --debug method_name\n"
4293 " --config filename load the specified config file instead of the default\n"
4294 " --workers n maximum number of worker threads\n"
4300 interp_ves_icall_get_frame_info (gint32 skip, MonoBoolean need_file_info,
4301 MonoReflectionMethod **method,
4302 gint32 *iloffset, gint32 *native_offset,
4303 MonoString **file, gint32 *line, gint32 *column)
4305 ThreadContext *context = mono_native_tls_get_value (thread_context_id);
4306 MonoInvocation *inv = context->current_frame;
4310 for (i = 0; inv && i < skip; inv = inv->parent)
4311 if (inv->runtime_method != NULL)
4322 *method = mono_method_get_object_checked (context->domain, inv->runtime_method->method, NULL, &error);
4323 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4328 if (need_file_info) {
4332 *file = mono_string_new (mono_domain_get (), "unknown");
4339 interp_ves_icall_get_trace (MonoException *exc, gint32 skip, MonoBoolean need_file_info)
4341 MonoDomain *domain = mono_domain_get ();
4343 MonoArray *ta = exc->trace_ips;
4348 /* Exception is not thrown yet */
4349 MonoArray *array = mono_array_new_checked (domain, mono_defaults.stack_frame_class, 0, &error);
4350 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4354 len = mono_array_length (ta);
4356 res = mono_array_new_checked (domain, mono_defaults.stack_frame_class, len > skip ? len - skip : 0, &error);
4357 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4359 for (i = skip; i < len / 2; i++) {
4360 MonoStackFrame *sf = (MonoStackFrame *)mono_object_new_checked (domain, mono_defaults.stack_frame_class, &error);
4361 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4362 gushort *ip = mono_array_get (ta, gpointer, 2 * i + 1);
4363 RuntimeMethod *rtm = mono_array_get (ta, gpointer, 2 * i);
4366 sf->method = mono_method_get_object_checked (domain, rtm->method, NULL, &error);
4367 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4368 sf->native_offset = ip - rtm->code;
4372 sf->il_offset = mono_debug_il_offset_from_address (ji->method, sf->native_offset, domain);
4374 if (need_file_info) {
4377 filename = mono_debug_source_location_from_address (ji->method, sf->native_offset, &sf->line, domain);
4379 sf->filename = filename? mono_string_new (domain, filename): NULL;
4386 mono_array_set (res, gpointer, i, sf);
4393 ves_icall_System_Delegate_CreateDelegate_internal (MonoReflectionType *type, MonoObject *target, MonoReflectionMethod *info)
4395 MonoClass *delegate_class = mono_class_from_mono_type (type->type);
4396 MonoObject *delegate;
4399 g_assert (delegate_class->parent == mono_defaults.multicastdelegate_class);
4401 delegate = mono_object_new_checked (mono_object_domain (type), delegate_class, &error);
4402 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4404 interp_delegate_ctor (mono_object_domain (type), delegate, target, mono_interp_get_runtime_method (mono_get_root_domain (), info->method, &error));
4405 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4413 mono_native_tls_alloc (&thread_context_id, NULL);
4414 mono_native_tls_set_value (thread_context_id, NULL);
4415 mono_os_mutex_init_recursive (&runtime_method_lookup_section);
4416 mono_os_mutex_init_recursive (&create_method_pointer_mutex);
4418 mono_interp_transform_init ();
4421 typedef int (*TestMethod) (void);
4424 interp_regression_step (MonoImage *image, int verbose, int *total_run, int *total, GTimer *timer, MonoDomain *domain)
4426 int result, expected, failed, cfailed, run;
4427 double elapsed, transform_time;
4429 MonoObject *result_obj;
4430 static gboolean filter_method_init = FALSE;
4431 static const char *filter_method = NULL;
4433 g_print ("Test run: image=%s\n", mono_image_get_filename (image));
4434 cfailed = failed = run = 0;
4435 transform_time = elapsed = 0.0;
4438 /* fixme: ugly hack - delete all previously compiled methods */
4439 if (domain_jit_info (domain)) {
4440 g_hash_table_destroy (domain_jit_info (domain)->jit_trampoline_hash);
4441 domain_jit_info (domain)->jit_trampoline_hash = g_hash_table_new (mono_aligned_addr_hash, NULL);
4442 mono_internal_hash_table_destroy (&(domain->jit_code_hash));
4443 mono_jit_code_hash_init (&(domain->jit_code_hash));
4447 g_timer_start (timer);
4448 for (i = 0; i < mono_image_get_table_rows (image, MONO_TABLE_METHOD); ++i) {
4450 MonoMethod *method = mono_get_method_checked (image, MONO_TOKEN_METHOD_DEF | (i + 1), NULL, NULL, &error);
4452 mono_error_cleanup (&error); /* FIXME don't swallow the error */
4456 if (!filter_method_init) {
4457 filter_method = g_getenv ("INTERP_FILTER_METHOD");
4458 filter_method_init = TRUE;
4460 gboolean filter = FALSE;
4461 if (filter_method) {
4462 const char *name = filter_method;
4464 if ((strchr (name, '.') > name) || strchr (name, ':')) {
4465 MonoMethodDesc *desc = mono_method_desc_new (name, TRUE);
4466 filter = mono_method_desc_full_match (desc, method);
4467 mono_method_desc_free (desc);
4469 filter = strcmp (method->name, name) == 0;
4471 } else { // no filter
4474 if (strncmp (method->name, "test_", 5) == 0 && filter) {
4475 MonoError interp_error;
4476 MonoObject *exc = NULL;
4478 result_obj = interp_mono_runtime_invoke (method, NULL, NULL, &exc, &interp_error);
4479 if (!mono_error_ok (&interp_error)) {
4481 g_print ("Test '%s' execution failed.\n", method->name);
4482 } else if (exc != NULL) {
4483 g_print ("Exception in Test '%s' occured:\n", method->name);
4484 mono_object_describe (exc);
4488 result = *(gint32 *) mono_object_unbox (result_obj);
4489 expected = atoi (method->name + 5); // FIXME: oh no.
4492 if (result != expected) {
4494 g_print ("Test '%s' failed result (got %d, expected %d).\n", method->name, result, expected);
4499 g_timer_stop (timer);
4500 elapsed = g_timer_elapsed (timer, NULL);
4501 if (failed > 0 || cfailed > 0){
4502 g_print ("Results: total tests: %d, failed: %d, cfailed: %d (pass: %.2f%%)\n",
4503 run, failed, cfailed, 100.0*(run-failed-cfailed)/run);
4505 g_print ("Results: total tests: %d, all pass \n", run);
4508 g_print ("Elapsed time: %f secs (%f, %f)\n\n", elapsed,
4509 elapsed - transform_time, transform_time);
4510 *total += failed + cfailed;
4514 interp_regression (MonoImage *image, int verbose, int *total_run)
4517 GTimer *timer = g_timer_new ();
4518 MonoDomain *domain = mono_domain_get ();
4522 /* load the metadata */
4523 for (i = 0; i < mono_image_get_table_rows (image, MONO_TABLE_METHOD); ++i) {
4525 method = mono_get_method_checked (image, MONO_TOKEN_METHOD_DEF | (i + 1), NULL, NULL, &error);
4527 mono_error_cleanup (&error);
4530 mono_class_init (method->klass);
4535 interp_regression_step (image, verbose, total_run, &total, timer, domain);
4537 g_timer_destroy (timer);
4542 interp_regression_list (int verbose, int count, char *images [])
4544 int i, total, total_run, run;
4546 total_run = total = 0;
4547 for (i = 0; i < count; ++i) {
4548 MonoAssembly *ass = mono_assembly_open (images [i], NULL);
4550 g_warning ("failed to load assembly: %s", images [i]);
4553 total += interp_regression (mono_assembly_get_image (ass), verbose, &run);
4557 g_print ("Overall results: tests: %d, failed: %d (pass: %.2f%%)\n", total_run, total, 100.0*(total_run-total)/total_run);
4559 g_print ("Overall results: tests: %d, 100%% pass\n", total_run);