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>
61 #include "interp-internals.h"
65 #include <mono/mini/mini.h>
66 #include <mono/mini/jit-icalls.h>
69 /* Mingw 2.1 doesnt need this any more, but leave it in for now for older versions */
72 #define finite _finite
76 #define finite isfinite
80 #define INIT_FRAME(frame,parent_frame,method_args,method_retval,domain,mono_method,error) \
82 (frame)->parent = (parent_frame); \
83 (frame)->stack_args = (method_args); \
84 (frame)->retval = (method_retval); \
85 (frame)->runtime_method = mono_interp_get_runtime_method ((domain), (mono_method), (error)); \
88 (frame)->invoke_trap = 0; \
91 void ves_exec_method (MonoInvocation *frame);
93 static char* dump_stack (stackval *stack, stackval *sp);
94 static char* dump_frame (MonoInvocation *inv);
95 static MonoArray *get_trace_ips (MonoDomain *domain, MonoInvocation *top);
96 static void ves_exec_method_with_context (MonoInvocation *frame, ThreadContext *context);
98 typedef void (*ICallMethod) (MonoInvocation *frame);
100 static guint32 die_on_exception = 0;
101 static MonoNativeTlsKey thread_context_id;
103 static char* dump_args (MonoInvocation *inv);
105 #define DEBUG_INTERP 0
108 int mono_interp_traceopt = 2;
109 /* If true, then we output the opcodes as we interpret them */
110 static int global_tracing = 2;
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_print ("(%p) Entering %s (", mono_thread_internal_current (), mn);
153 g_print ("%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_print ("(%p) Leaving %s", mono_thread_internal_current (), mn); \
169 g_print (" => %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 int mono_interp_traceopt = 0;
180 static void debug_enter (MonoInvocation *frame, int *tracing)
183 #define DEBUG_LEAVE()
188 interp_ex_handler (MonoException *ex) {
190 ThreadContext *context = mono_native_tls_get_value (thread_context_id);
194 stack_trace = dump_frame (context->current_frame);
195 ex->stack_trace = mono_string_new (mono_domain_get(), stack_trace);
196 g_free (stack_trace);
197 if (context->current_env == NULL || strcmp(ex->object.vtable->klass->name, "ExecutionEngineException") == 0) {
198 char *strace = mono_string_to_utf8_checked (ex->stack_trace, &error);
199 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
200 fprintf(stderr, "Nothing can catch this exception: ");
201 fprintf(stderr, "%s", ex->object.vtable->klass->name);
202 if (ex->message != NULL) {
203 char *m = mono_string_to_utf8_checked (ex->message, &error);
204 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
205 fprintf(stderr, ": %s", m);
208 fprintf(stderr, "\n%s\n", strace);
210 if (ex->inner_ex != NULL) {
211 ex = (MonoException *)ex->inner_ex;
212 fprintf(stderr, "Inner exception: %s", ex->object.vtable->klass->name);
213 if (ex->message != NULL) {
214 char *m = mono_string_to_utf8_checked (ex->message, &error);
215 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
216 fprintf(stderr, ": %s", m);
219 strace = mono_string_to_utf8_checked (ex->stack_trace, &error);
220 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
221 fprintf(stderr, "\n");
222 fprintf(stderr, "%s\n", strace);
225 /* wait for other threads to also collapse */
226 // Sleep(1000); // TODO: proper sleep
229 context->env_frame->ex = ex;
230 context->search_for_handler = 1;
231 longjmp (*context->current_env, 1);
235 ves_real_abort (int line, MonoMethod *mh,
236 const unsigned short *ip, stackval *stack, stackval *sp)
239 fprintf (stderr, "Execution aborted in method: %s::%s\n", mh->klass->name, mh->name);
240 fprintf (stderr, "Line=%d IP=0x%04lx, Aborted execution\n", line,
241 ip-(const unsigned short *)mono_method_get_header_checked (mh, &error)->code);
242 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
243 g_print ("0x%04x %02x\n",
244 ip-(const unsigned short *)mono_method_get_header_checked (mh, &error)->code, *ip);
245 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
247 printf ("\t[%ld] 0x%08x %0.5f\n", sp-stack, sp[-1].data.i, sp[-1].data.f);
250 #define ves_abort() \
252 ves_real_abort(__LINE__, frame->runtime_method->method, ip, frame->stack, sp); \
253 THROW_EX (mono_get_exception_execution_engine (NULL), ip); \
256 static mono_mutex_t runtime_method_lookup_section;
259 mono_interp_get_runtime_method (MonoDomain *domain, MonoMethod *method, MonoError *error)
264 mono_os_mutex_lock (&runtime_method_lookup_section);
265 if ((rtm = mono_internal_hash_table_lookup (&domain->jit_code_hash, method))) {
266 mono_os_mutex_unlock (&runtime_method_lookup_section);
269 rtm = mono_mempool_alloc (domain->mp, sizeof (RuntimeMethod));
270 memset (rtm, 0, sizeof (*rtm));
271 rtm->method = method;
272 rtm->param_count = mono_method_signature (method)->param_count;
273 rtm->hasthis = mono_method_signature (method)->hasthis;
274 rtm->valuetype = method->klass->valuetype;
275 mono_internal_hash_table_insert (&domain->jit_code_hash, method, rtm);
276 mono_os_mutex_unlock (&runtime_method_lookup_section);
282 interp_create_trampoline (MonoDomain *domain, MonoMethod *method, MonoError *error)
284 if (method->iflags & METHOD_IMPL_ATTRIBUTE_SYNCHRONIZED)
285 method = mono_marshal_get_synchronized_wrapper (method);
286 return mono_interp_get_runtime_method (domain, method, error);
289 static inline RuntimeMethod*
290 get_virtual_method (MonoDomain *domain, RuntimeMethod *runtime_method, MonoObject *obj)
292 MonoMethod *m = runtime_method->method;
295 if ((m->flags & METHOD_ATTRIBUTE_FINAL) || !(m->flags & METHOD_ATTRIBUTE_VIRTUAL)) {
296 RuntimeMethod *ret = NULL;
297 if (mono_object_is_transparent_proxy (obj)) {
298 ret = mono_interp_get_runtime_method (domain, mono_marshal_get_remoting_invoke (m), &error);
299 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
300 } else if (m->iflags & METHOD_IMPL_ATTRIBUTE_SYNCHRONIZED) {
301 ret = mono_interp_get_runtime_method (domain, mono_marshal_get_synchronized_wrapper (m), &error);
302 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
304 ret = runtime_method;
309 mono_class_setup_vtable (obj->vtable->klass);
311 int slot = mono_method_get_vtable_slot (m);
312 if (mono_class_is_interface (m->klass)) {
313 g_assert (obj->vtable->klass != m->klass);
314 /* TODO: interface offset lookup is slow, go through IMT instead */
315 slot += mono_class_interface_offset (obj->vtable->klass, m->klass);
317 MonoMethod *virtual_method = obj->vtable->klass->vtable [slot];
318 RuntimeMethod *virtual_runtime_method = mono_interp_get_runtime_method (domain, virtual_method, &error);
319 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
320 return virtual_runtime_method;
324 stackval_from_data (MonoType *type, stackval *result, char *data, gboolean pinvoke)
327 switch (type->type) {
328 case MONO_TYPE_OBJECT:
329 case MONO_TYPE_CLASS:
330 case MONO_TYPE_STRING:
331 case MONO_TYPE_ARRAY:
332 case MONO_TYPE_SZARRAY:
337 result->data.p = *(gpointer*)data;
340 switch (type->type) {
344 result->data.i = *(gint8*)data;
347 case MONO_TYPE_BOOLEAN:
348 result->data.i = *(guint8*)data;
351 result->data.i = *(gint16*)data;
355 result->data.i = *(guint16*)data;
358 result->data.i = *(gint32*)data;
362 result->data.nati = *(mono_i*)data;
365 result->data.p = *(gpointer*)data;
368 result->data.i = *(guint32*)data;
371 result->data.f = *(float*)data;
375 result->data.l = *(gint64*)data;
378 result->data.f = *(double*)data;
380 case MONO_TYPE_STRING:
381 case MONO_TYPE_SZARRAY:
382 case MONO_TYPE_CLASS:
383 case MONO_TYPE_OBJECT:
384 case MONO_TYPE_ARRAY:
385 result->data.p = *(gpointer*)data;
387 case MONO_TYPE_VALUETYPE:
388 if (type->data.klass->enumtype) {
389 stackval_from_data (mono_class_enum_basetype (type->data.klass), result, data, pinvoke);
392 mono_value_copy (result->data.vt, data, type->data.klass);
394 case MONO_TYPE_GENERICINST:
395 stackval_from_data (&type->data.generic_class->container_class->byval_arg, result, data, pinvoke);
398 g_warning ("got type 0x%02x", type->type);
399 g_assert_not_reached ();
404 stackval_to_data (MonoType *type, stackval *val, char *data, gboolean pinvoke)
407 gpointer *p = (gpointer*)data;
411 /* printf ("TODAT0 %p\n", data); */
412 switch (type->type) {
415 guint8 *p = (guint8*)data;
419 case MONO_TYPE_BOOLEAN: {
420 guint8 *p = (guint8*)data;
421 *p = (val->data.i != 0);
426 case MONO_TYPE_CHAR: {
427 guint16 *p = (guint16*)data;
432 mono_i *p = (mono_i*)data;
433 /* In theory the value used by stloc should match the local var type
434 but in practice it sometimes doesn't (a int32 gets dup'd and stloc'd into
435 a native int - both by csc and mcs). Not sure what to do about sign extension
436 as it is outside the spec... doing the obvious */
437 *p = (mono_i)val->data.nati;
441 mono_u *p = (mono_u*)data;
443 *p = (mono_u)val->data.nati;
448 gint32 *p = (gint32*)data;
454 gint64 *p = (gint64*)data;
459 float *p = (float*)data;
464 double *p = (double*)data;
468 case MONO_TYPE_STRING:
469 case MONO_TYPE_SZARRAY:
470 case MONO_TYPE_CLASS:
471 case MONO_TYPE_OBJECT:
472 case MONO_TYPE_ARRAY:
473 case MONO_TYPE_PTR: {
474 gpointer *p = (gpointer*)data;
478 case MONO_TYPE_VALUETYPE:
479 if (type->data.klass->enumtype) {
480 stackval_to_data (mono_class_enum_basetype (type->data.klass), val, data, pinvoke);
483 mono_value_copy (data, val->data.vt, type->data.klass);
485 case MONO_TYPE_GENERICINST:
486 stackval_to_data (&type->data.generic_class->container_class->byval_arg, val, data, pinvoke);
489 g_warning ("got type %x", type->type);
490 g_assert_not_reached ();
495 fill_in_trace (MonoException *exception, MonoInvocation *frame)
497 char *stack_trace = dump_frame (frame);
498 MonoDomain *domain = mono_domain_get();
499 (exception)->stack_trace = mono_string_new (domain, stack_trace);
500 (exception)->trace_ips = get_trace_ips (domain, frame);
501 g_free (stack_trace);
504 #define FILL_IN_TRACE(exception, frame) fill_in_trace(exception, frame)
506 #define THROW_EX(exception,ex_ip) \
508 frame->ip = (ex_ip); \
509 frame->ex = (MonoException*)(exception); \
510 FILL_IN_TRACE(frame->ex, frame); \
511 goto handle_exception; \
515 ves_array_create (MonoDomain *domain, MonoClass *klass, MonoMethodSignature *sig, stackval *values)
518 intptr_t *lower_bounds;
523 lengths = alloca (sizeof (uintptr_t) * klass->rank * 2);
524 for (i = 0; i < sig->param_count; ++i) {
525 lengths [i] = values->data.i;
528 if (klass->rank == sig->param_count) {
529 /* Only lengths provided. */
532 /* lower bounds are first. */
533 lower_bounds = (intptr_t *) lengths;
534 lengths += klass->rank;
536 obj = (MonoObject*) mono_array_new_full_checked (domain, klass, lengths, lower_bounds, &error);
537 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
542 ves_array_set (MonoInvocation *frame)
544 stackval *sp = frame->stack_args;
548 gint32 i, t, pos, esize;
552 o = frame->stack_args->data.p;
554 ac = o->vtable->klass;
556 g_assert (ac->rank >= 1);
559 if (ao->bounds != NULL) {
560 pos -= ao->bounds [0].lower_bound;
561 for (i = 1; i < ac->rank; i++) {
562 if ((t = sp [i].data.i - ao->bounds [i].lower_bound) >=
563 ao->bounds [i].length) {
564 frame->ex = mono_get_exception_index_out_of_range ();
565 FILL_IN_TRACE(frame->ex, frame);
568 pos = pos*ao->bounds [i].length + sp [i].data.i -
569 ao->bounds [i].lower_bound;
571 } else if (pos >= ao->max_length) {
572 frame->ex = mono_get_exception_index_out_of_range ();
573 FILL_IN_TRACE(frame->ex, frame);
577 if (sp [ac->rank].data.p && !mono_object_class (o)->element_class->valuetype) {
579 MonoObject *isinst = mono_object_isinst_checked (sp [ac->rank].data.p, mono_object_class (o)->element_class, &error);
580 mono_error_cleanup (&error);
582 frame->ex = mono_get_exception_array_type_mismatch ();
583 FILL_IN_TRACE (frame->ex, frame);
588 esize = mono_array_element_size (ac);
589 ea = mono_array_addr_with_size (ao, esize, pos);
591 mt = mono_method_signature (frame->runtime_method->method)->params [ac->rank];
592 stackval_to_data (mt, &sp [ac->rank], ea, FALSE);
596 ves_array_get (MonoInvocation *frame)
598 stackval *sp = frame->stack_args;
602 gint32 i, t, pos, esize;
606 o = frame->stack_args->data.p;
608 ac = o->vtable->klass;
610 g_assert (ac->rank >= 1);
613 if (ao->bounds != NULL) {
614 pos -= ao->bounds [0].lower_bound;
615 for (i = 1; i < ac->rank; i++) {
616 if ((t = sp [i].data.i - ao->bounds [i].lower_bound) >=
617 ao->bounds [i].length) {
618 frame->ex = mono_get_exception_index_out_of_range ();
619 FILL_IN_TRACE(frame->ex, frame);
623 pos = pos*ao->bounds [i].length + sp [i].data.i -
624 ao->bounds [i].lower_bound;
626 } else if (pos >= ao->max_length) {
627 frame->ex = mono_get_exception_index_out_of_range ();
628 FILL_IN_TRACE(frame->ex, frame);
632 esize = mono_array_element_size (ac);
633 ea = mono_array_addr_with_size (ao, esize, pos);
635 mt = mono_method_signature (frame->runtime_method->method)->ret;
636 stackval_from_data (mt, frame->retval, ea, FALSE);
640 ves_array_element_address (MonoInvocation *frame)
642 stackval *sp = frame->stack_args;
646 gint32 i, t, pos, esize;
649 o = frame->stack_args->data.p;
651 ac = o->vtable->klass;
653 g_assert (ac->rank >= 1);
656 if (ao->bounds != NULL) {
657 pos -= ao->bounds [0].lower_bound;
658 for (i = 1; i < ac->rank; i++) {
659 if ((t = sp [i].data.i - ao->bounds [i].lower_bound) >=
660 ao->bounds [i].length) {
661 frame->ex = mono_get_exception_index_out_of_range ();
662 FILL_IN_TRACE(frame->ex, frame);
665 pos = pos*ao->bounds [i].length + sp [i].data.i -
666 ao->bounds [i].lower_bound;
668 } else if (pos >= ao->max_length) {
669 frame->ex = mono_get_exception_index_out_of_range ();
670 FILL_IN_TRACE(frame->ex, frame);
674 esize = mono_array_element_size (ac);
675 ea = mono_array_addr_with_size (ao, esize, pos);
677 frame->retval->data.p = ea;
681 interp_walk_stack (MonoStackWalk func, gboolean do_il_offset, gpointer user_data)
683 ThreadContext *context = mono_native_tls_get_value (thread_context_id);
684 MonoInvocation *frame;
686 MonoMethodHeader *hd;
689 if (!context) return;
691 frame = context->current_frame;
694 gboolean managed = FALSE;
695 MonoMethod *method = frame->runtime_method->method;
696 if (!method || (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) || (method->iflags & (METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL | METHOD_IMPL_ATTRIBUTE_RUNTIME)))
699 hd = mono_method_get_header_checked (method, &error);
700 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
701 il_offset = frame->ip - (const unsigned short *)hd->code;
702 if (!method->wrapper_type)
705 if (func (method, -1, il_offset, managed, user_data))
707 frame = frame->parent;
711 static MonoPIFunc mono_interp_enter_icall_trampoline = NULL;
713 struct _MethodArguments {
721 typedef struct _MethodArguments MethodArguments;
723 // TODO: this function is also arch dependent (register width).
724 static MethodArguments* build_args_from_sig (MonoMethodSignature *sig, MonoInvocation *frame)
726 // TODO: don't malloc this data structure.
727 MethodArguments *margs = g_malloc0 (sizeof (MethodArguments));
732 for (int i = 0; i < sig->param_count; i++) {
733 guint32 ptype = sig->params [i]->byref ? MONO_TYPE_PTR : sig->params [i]->type;
735 case MONO_TYPE_BOOLEAN:
746 case MONO_TYPE_SZARRAY:
747 case MONO_TYPE_CLASS:
748 case MONO_TYPE_OBJECT:
749 case MONO_TYPE_STRING:
751 case MONO_TYPE_VALUETYPE:
755 g_error ("build_args_from_sig: not implemented yet (1): 0x%x\n", ptype);
760 margs->iargs = g_malloc0 (sizeof (gpointer) * margs->ilen);
763 g_error ("build_args_from_sig: TODO, more than 6 iregs: %d\n", margs->ilen);
766 g_error ("build_args_from_sig: TODO, allocate floats: %d\n", margs->flen);
772 margs->iargs [0] = frame->stack_args->data.p;
776 for (int i = 0; i < sig->param_count; i++) {
777 guint32 ptype = sig->params [i]->byref ? MONO_TYPE_PTR : sig->params [i]->type;
779 case MONO_TYPE_BOOLEAN:
790 case MONO_TYPE_SZARRAY:
791 case MONO_TYPE_CLASS:
792 case MONO_TYPE_OBJECT:
793 case MONO_TYPE_STRING:
795 case MONO_TYPE_VALUETYPE:
796 margs->iargs [int_i] = frame->stack_args [i].data.p;
798 g_print ("build_args_from_sig: margs->iargs[%d]: %p (frame @ %d)\n", int_i, margs->iargs[int_i], i);
803 g_error ("build_args_from_sig: not implemented yet (2): 0x%x\n", ptype);
807 if (sig->ret->type != MONO_TYPE_VOID) {
808 margs->retval = &(frame->retval->data.p);
810 margs->retval = NULL;
817 ves_pinvoke_method (MonoInvocation *frame, MonoMethodSignature *sig, MonoFuncV addr, gboolean string_ctor, ThreadContext *context)
820 MonoInvocation *old_frame = context->current_frame;
821 MonoInvocation *old_env_frame = context->env_frame;
822 jmp_buf *old_env = context->current_env;
825 context->current_frame = old_frame;
826 context->env_frame = old_env_frame;
827 context->current_env = old_env;
828 context->managed_code = 1;
833 context->env_frame = frame;
834 context->current_env = &env;
836 g_assert (!frame->runtime_method);
837 if (!mono_interp_enter_icall_trampoline) {
839 mono_interp_enter_icall_trampoline = mono_arch_get_enter_icall_trampoline (&info);
841 // mono_tramp_info_register (info, NULL);
844 MethodArguments *margs = build_args_from_sig (sig, frame);
846 g_print ("ICALL: mono_interp_enter_icall_trampoline = %p, addr = %p\n", mono_interp_enter_icall_trampoline, addr);
847 g_print ("margs(out): ilen=%d, flen=%d\n", margs->ilen, margs->flen);
850 context->current_frame = frame;
851 context->managed_code = 0;
853 mono_interp_enter_icall_trampoline (addr, margs);
855 context->managed_code = 1;
856 /* domain can only be changed by native code */
857 context->domain = mono_domain_get ();
859 if (*mono_thread_interruption_request_flag ())
860 mono_thread_interruption_checkpoint ();
862 if (!MONO_TYPE_ISSTRUCT (sig->ret))
863 stackval_from_data (sig->ret, frame->retval, (char*)&frame->retval->data.p, sig->pinvoke);
865 context->current_frame = old_frame;
866 context->env_frame = old_env_frame;
867 context->current_env = old_env;
869 g_free (margs->iargs);
870 g_free (margs->fargs);
875 interp_delegate_ctor (MonoDomain *domain, MonoObject *this, MonoObject *target, RuntimeMethod *runtime_method)
877 MonoDelegate *delegate = (MonoDelegate *)this;
880 delegate->method_info = mono_method_get_object_checked (domain, runtime_method->method, NULL, &error);
881 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
882 delegate->target = target;
884 if (target && mono_object_is_transparent_proxy (target)) {
885 MonoMethod *method = mono_marshal_get_remoting_invoke (runtime_method->method);
886 delegate->method_ptr = mono_interp_get_runtime_method (domain, method, &error);
887 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
889 delegate->method_ptr = runtime_method;
894 mono_interp_ftnptr_to_delegate (MonoClass *klass, gpointer ftn)
898 MonoDomain *domain = mono_domain_get ();
901 d = (MonoDelegate*)mono_object_new_checked (domain, klass, &error);
902 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
904 ji = mono_jit_info_table_find (domain, ftn);
906 mono_raise_exception (mono_get_exception_argument ("", "Function pointer was not created by a Delegate."));
908 /* FIXME: discard the wrapper and call the original method */
909 interp_delegate_ctor (domain, (MonoObject*)d, NULL, mono_interp_get_runtime_method (domain, ji->d.method, &error));
910 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
917 * runtime specifies that the implementation of the method is automatically
918 * provided by the runtime and is primarily used for the methods of delegates.
921 ves_runtime_method (MonoInvocation *frame, ThreadContext *context)
923 MonoMethod *method = frame->runtime_method->method;
924 const char *name = method->name;
925 MonoObject *obj = (MonoObject*) frame->stack_args->data.p;
926 MonoObject *isinst_obj;
929 mono_class_init (method->klass);
931 isinst_obj = mono_object_isinst_checked (obj, mono_defaults.multicastdelegate_class, &error);
932 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
933 if (obj && isinst_obj) {
934 if (*name == '.' && (strcmp (name, ".ctor") == 0)) {
935 interp_delegate_ctor (context->domain, obj, frame->stack_args [1].data.p, frame->stack_args[2].data.p);
940 isinst_obj = mono_object_isinst_checked (obj, mono_defaults.array_class, &error);
941 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
942 if (obj && isinst_obj) {
943 if (*name == 'S' && (strcmp (name, "Set") == 0)) {
944 ves_array_set (frame);
947 if (*name == 'G' && (strcmp (name, "Get") == 0)) {
948 ves_array_get (frame);
951 if (*name == 'A' && (strcmp (name, "Address") == 0)) {
952 ves_array_element_address (frame);
957 g_error ("Don't know how to exec runtime method %s.%s::%s",
958 method->klass->name_space, method->klass->name,
963 dump_stack (stackval *stack, stackval *sp)
966 GString *str = g_string_new ("");
969 return g_string_free (str, FALSE);
972 g_string_append_printf (str, "[%p (%lld)] ", s->data.l, s->data.l);
975 return g_string_free (str, FALSE);
979 dump_stackval (GString *str, stackval *s, MonoType *type)
981 switch (type->type) {
989 case MONO_TYPE_BOOLEAN:
990 g_string_append_printf (str, "[%d] ", s->data.i);
992 case MONO_TYPE_STRING:
993 case MONO_TYPE_SZARRAY:
994 case MONO_TYPE_CLASS:
995 case MONO_TYPE_OBJECT:
996 case MONO_TYPE_ARRAY:
1000 g_string_append_printf (str, "[%p] ", s->data.p);
1002 case MONO_TYPE_VALUETYPE:
1003 if (type->data.klass->enumtype)
1004 g_string_append_printf (str, "[%d] ", s->data.i);
1006 g_string_append_printf (str, "[vt:%p] ", s->data.p);
1010 g_string_append_printf (str, "[%g] ", s->data.f);
1015 GString *res = g_string_new ("");
1016 mono_type_get_desc (res, type, TRUE);
1017 g_string_append_printf (str, "[{%s} %lld/0x%0llx] ", res->str, s->data.l, s->data.l);
1018 g_string_free (res, TRUE);
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 && !signature->hasthis)
1032 return g_string_free (str, FALSE);
1034 if (signature->hasthis) {
1035 MonoMethod *method = inv->runtime_method->method;
1036 dump_stackval (str, inv->stack_args, &method->klass->byval_arg);
1039 for (i = 0; i < signature->param_count; ++i)
1040 dump_stackval (str, inv->stack_args + (!!signature->hasthis) + i, signature->params [i]);
1042 return g_string_free (str, FALSE);
1046 dump_retval (MonoInvocation *inv)
1048 GString *str = g_string_new ("");
1049 MonoType *ret = mono_method_signature (inv->runtime_method->method)->ret;
1051 if (ret->type != MONO_TYPE_VOID)
1052 dump_stackval (str, inv->retval, ret);
1054 return g_string_free (str, FALSE);
1058 dump_frame (MonoInvocation *inv)
1060 GString *str = g_string_new ("");
1065 for (i = 0; inv; inv = inv->parent) {
1066 if (inv->runtime_method != NULL) {
1067 MonoMethod *method = inv->runtime_method->method;
1071 const char * opname = "";
1073 gchar *source = NULL;
1077 if ((method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) == 0 &&
1078 (method->iflags & METHOD_IMPL_ATTRIBUTE_RUNTIME) == 0) {
1079 MonoMethodHeader *hd = mono_method_get_header_checked (method, &error);
1080 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
1084 opname = mono_interp_opname [*inv->ip];
1085 codep = inv->ip - inv->runtime_method->code;
1086 source = g_strdup_printf ("%s:%d // (TODO: proper stacktrace)", method->name, codep);
1091 MonoDebugSourceLocation *minfo = mono_debug_lookup_method (method);
1092 source = mono_debug_method_lookup_location (minfo, codep);
1096 args = dump_args (inv);
1097 name = mono_method_full_name (method, TRUE);
1099 g_string_append_printf (str, "#%d: 0x%05x %-10s in %s (%s) at %s\n", i, codep, opname, name, args, source);
1101 g_string_append_printf (str, "#%d: 0x%05x %-10s in %s (%s)\n", i, codep, opname, name, args);
1108 return g_string_free (str, FALSE);
1112 get_trace_ips (MonoDomain *domain, MonoInvocation *top)
1116 MonoInvocation *inv;
1119 for (i = 0, inv = top; inv; inv = inv->parent)
1120 if (inv->runtime_method != NULL)
1123 res = mono_array_new_checked (domain, mono_defaults.int_class, 2 * i, &error);
1124 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
1126 for (i = 0, inv = top; inv; inv = inv->parent)
1127 if (inv->runtime_method != NULL) {
1128 mono_array_set (res, gpointer, i, inv->runtime_method);
1130 mono_array_set (res, gpointer, i, (gpointer)inv->ip);
1138 #define MYGUINT64_MAX 18446744073709551615ULL
1139 #define MYGINT64_MAX 9223372036854775807LL
1140 #define MYGINT64_MIN (-MYGINT64_MAX -1LL)
1142 #define MYGUINT32_MAX 4294967295U
1143 #define MYGINT32_MAX 2147483647
1144 #define MYGINT32_MIN (-MYGINT32_MAX -1)
1146 #define CHECK_ADD_OVERFLOW(a,b) \
1147 (gint32)(b) >= 0 ? (gint32)(MYGINT32_MAX) - (gint32)(b) < (gint32)(a) ? -1 : 0 \
1148 : (gint32)(MYGINT32_MIN) - (gint32)(b) > (gint32)(a) ? +1 : 0
1150 #define CHECK_SUB_OVERFLOW(a,b) \
1151 (gint32)(b) < 0 ? (gint32)(MYGINT32_MAX) + (gint32)(b) < (gint32)(a) ? -1 : 0 \
1152 : (gint32)(MYGINT32_MIN) + (gint32)(b) > (gint32)(a) ? +1 : 0
1154 #define CHECK_ADD_OVERFLOW_UN(a,b) \
1155 (guint32)(MYGUINT32_MAX) - (guint32)(b) < (guint32)(a) ? -1 : 0
1157 #define CHECK_SUB_OVERFLOW_UN(a,b) \
1158 (guint32)(a) < (guint32)(b) ? -1 : 0
1160 #define CHECK_ADD_OVERFLOW64(a,b) \
1161 (gint64)(b) >= 0 ? (gint64)(MYGINT64_MAX) - (gint64)(b) < (gint64)(a) ? -1 : 0 \
1162 : (gint64)(MYGINT64_MIN) - (gint64)(b) > (gint64)(a) ? +1 : 0
1164 #define CHECK_SUB_OVERFLOW64(a,b) \
1165 (gint64)(b) < 0 ? (gint64)(MYGINT64_MAX) + (gint64)(b) < (gint64)(a) ? -1 : 0 \
1166 : (gint64)(MYGINT64_MIN) + (gint64)(b) > (gint64)(a) ? +1 : 0
1168 #define CHECK_ADD_OVERFLOW64_UN(a,b) \
1169 (guint64)(MYGUINT64_MAX) - (guint64)(b) < (guint64)(a) ? -1 : 0
1171 #define CHECK_SUB_OVERFLOW64_UN(a,b) \
1172 (guint64)(a) < (guint64)(b) ? -1 : 0
1174 #if SIZEOF_VOID_P == 4
1175 #define CHECK_ADD_OVERFLOW_NAT(a,b) CHECK_ADD_OVERFLOW(a,b)
1176 #define CHECK_ADD_OVERFLOW_NAT_UN(a,b) CHECK_ADD_OVERFLOW_UN(a,b)
1178 #define CHECK_ADD_OVERFLOW_NAT(a,b) CHECK_ADD_OVERFLOW64(a,b)
1179 #define CHECK_ADD_OVERFLOW_NAT_UN(a,b) CHECK_ADD_OVERFLOW64_UN(a,b)
1182 /* Resolves to TRUE if the operands would overflow */
1183 #define CHECK_MUL_OVERFLOW(a,b) \
1184 ((gint32)(a) == 0) || ((gint32)(b) == 0) ? 0 : \
1185 (((gint32)(a) > 0) && ((gint32)(b) == -1)) ? FALSE : \
1186 (((gint32)(a) < 0) && ((gint32)(b) == -1)) ? (a == - MYGINT32_MAX) : \
1187 (((gint32)(a) > 0) && ((gint32)(b) > 0)) ? (gint32)(a) > ((MYGINT32_MAX) / (gint32)(b)) : \
1188 (((gint32)(a) > 0) && ((gint32)(b) < 0)) ? (gint32)(a) > ((MYGINT32_MIN) / (gint32)(b)) : \
1189 (((gint32)(a) < 0) && ((gint32)(b) > 0)) ? (gint32)(a) < ((MYGINT32_MIN) / (gint32)(b)) : \
1190 (gint32)(a) < ((MYGINT32_MAX) / (gint32)(b))
1192 #define CHECK_MUL_OVERFLOW_UN(a,b) \
1193 ((guint32)(a) == 0) || ((guint32)(b) == 0) ? 0 : \
1194 (guint32)(b) > ((MYGUINT32_MAX) / (guint32)(a))
1196 #define CHECK_MUL_OVERFLOW64(a,b) \
1197 ((gint64)(a) == 0) || ((gint64)(b) == 0) ? 0 : \
1198 (((gint64)(a) > 0) && ((gint64)(b) == -1)) ? FALSE : \
1199 (((gint64)(a) < 0) && ((gint64)(b) == -1)) ? (a == - MYGINT64_MAX) : \
1200 (((gint64)(a) > 0) && ((gint64)(b) > 0)) ? (gint64)(a) > ((MYGINT64_MAX) / (gint64)(b)) : \
1201 (((gint64)(a) > 0) && ((gint64)(b) < 0)) ? (gint64)(a) > ((MYGINT64_MIN) / (gint64)(b)) : \
1202 (((gint64)(a) < 0) && ((gint64)(b) > 0)) ? (gint64)(a) < ((MYGINT64_MIN) / (gint64)(b)) : \
1203 (gint64)(a) < ((MYGINT64_MAX) / (gint64)(b))
1205 #define CHECK_MUL_OVERFLOW64_UN(a,b) \
1206 ((guint64)(a) == 0) || ((guint64)(b) == 0) ? 0 : \
1207 (guint64)(b) > ((MYGUINT64_MAX) / (guint64)(a))
1209 #if SIZEOF_VOID_P == 4
1210 #define CHECK_MUL_OVERFLOW_NAT(a,b) CHECK_MUL_OVERFLOW(a,b)
1211 #define CHECK_MUL_OVERFLOW_NAT_UN(a,b) CHECK_MUL_OVERFLOW_UN(a,b)
1213 #define CHECK_MUL_OVERFLOW_NAT(a,b) CHECK_MUL_OVERFLOW64(a,b)
1214 #define CHECK_MUL_OVERFLOW_NAT_UN(a,b) CHECK_MUL_OVERFLOW64_UN(a,b)
1218 mono_interp_runtime_invoke (MonoMethod *method, void *obj, void **params, MonoObject **exc, MonoError *error)
1220 MonoInvocation frame;
1221 ThreadContext * volatile context = mono_native_tls_get_value (thread_context_id);
1222 MonoObject *retval = NULL;
1223 MonoMethodSignature *sig = mono_method_signature (method);
1224 MonoClass *klass = mono_class_from_mono_type (sig->ret);
1225 int i, type, isobject = 0;
1228 stackval *args = alloca (sizeof (stackval) * (sig->param_count + !!sig->hasthis));
1229 ThreadContext context_struct;
1230 MonoInvocation *old_frame = NULL;
1238 if (context != &context_struct) {
1239 context->domain = mono_domain_get ();
1240 context->current_frame = old_frame;
1241 context->managed_code = 0;
1243 mono_native_tls_set_value (thread_context_id, NULL);
1245 *exc = (MonoObject *)frame.ex;
1249 if (context == NULL) {
1250 context = &context_struct;
1251 context_struct.base_frame = &frame;
1252 context_struct.current_frame = NULL;
1253 context_struct.env_frame = &frame;
1254 context_struct.current_env = &env;
1255 context_struct.search_for_handler = 0;
1256 context_struct.managed_code = 0;
1257 mono_native_tls_set_value (thread_context_id, context);
1260 old_frame = context->current_frame;
1262 context->domain = mono_domain_get ();
1264 switch (sig->ret->type) {
1265 case MONO_TYPE_VOID:
1267 case MONO_TYPE_STRING:
1268 case MONO_TYPE_OBJECT:
1269 case MONO_TYPE_CLASS:
1270 case MONO_TYPE_ARRAY:
1271 case MONO_TYPE_SZARRAY:
1274 case MONO_TYPE_VALUETYPE:
1275 retval = mono_object_new_checked (context->domain, klass, error);
1276 ret = ((char*)retval) + sizeof (MonoObject);
1277 if (!sig->ret->data.klass->enumtype)
1278 result.data.vt = ret;
1281 retval = mono_object_new_checked (context->domain, klass, error);
1282 ret = ((char*)retval) + sizeof (MonoObject);
1287 args [0].data.p = obj;
1289 for (i = 0; i < sig->param_count; ++i) {
1290 int a_index = i + !!sig->hasthis;
1291 if (sig->params [i]->byref) {
1292 args [a_index].data.p = params [i];
1295 type = sig->params [i]->type;
1300 case MONO_TYPE_BOOLEAN:
1301 args [a_index].data.i = *(MonoBoolean*)params [i];
1305 case MONO_TYPE_CHAR:
1306 args [a_index].data.i = *(gint16*)params [i];
1308 #if SIZEOF_VOID_P == 4
1309 case MONO_TYPE_U: /* use VAL_POINTER? */
1314 args [a_index].data.i = *(gint32*)params [i];
1316 #if SIZEOF_VOID_P == 8
1322 args [a_index].data.l = *(gint64*)params [i];
1324 case MONO_TYPE_VALUETYPE:
1325 if (sig->params [i]->data.klass->enumtype) {
1326 type = mono_class_enum_basetype (sig->params [i]->data.klass)->type;
1329 args [a_index].data.p = params [i];
1332 case MONO_TYPE_STRING:
1333 case MONO_TYPE_CLASS:
1334 case MONO_TYPE_ARRAY:
1335 case MONO_TYPE_SZARRAY:
1336 case MONO_TYPE_OBJECT:
1337 args [a_index].data.p = params [i];
1340 g_error ("type 0x%x not handled in runtime invoke", sig->params [i]->type);
1344 if (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL)
1345 method = mono_marshal_get_native_wrapper (method, FALSE, FALSE);
1346 INIT_FRAME (&frame,context->current_frame,args,&result,mono_get_root_domain (),method,error);
1348 frame.invoke_trap = 1;
1349 context->managed_code = 1;
1350 ves_exec_method_with_context (&frame, context);
1351 context->managed_code = 0;
1352 if (context == &context_struct)
1353 mono_native_tls_set_value (thread_context_id, NULL);
1355 context->current_frame = old_frame;
1356 if (frame.ex != NULL) {
1358 *exc = (MonoObject*) frame.ex;
1361 if (context->current_env != NULL) {
1362 context->env_frame->ex = frame.ex;
1363 longjmp(*context->current_env, 1);
1366 printf("dropped exception...\n");
1368 if (sig->ret->type == MONO_TYPE_VOID && !method->string_ctor)
1370 if (isobject || method->string_ctor)
1371 return result.data.p;
1372 stackval_to_data (sig->ret, &result, ret, sig->pinvoke);
1377 do_icall (ThreadContext *context, int op, stackval *sp, gpointer ptr)
1379 MonoInvocation *old_frame = context->current_frame;
1380 MonoInvocation *old_env_frame = context->env_frame;
1381 jmp_buf *old_env = context->current_env;
1385 context->current_frame = old_frame;
1386 context->env_frame = old_env_frame;
1387 context->current_env = old_env;
1388 context->managed_code = 1;
1392 context->env_frame = context->current_frame;
1393 context->current_env = &env;
1394 context->managed_code = 0;
1397 case MINT_ICALL_V_V: {
1398 void (*func)() = ptr;
1402 case MINT_ICALL_V_P: {
1403 gpointer (*func)() = ptr;
1405 sp [-1].data.p = func ();
1408 case MINT_ICALL_P_V: {
1409 void (*func)(gpointer) = ptr;
1410 func (sp [-1].data.p);
1414 case MINT_ICALL_P_P: {
1415 gpointer (*func)(gpointer) = ptr;
1416 sp [-1].data.p = func (sp [-1].data.p);
1419 case MINT_ICALL_PP_V: {
1420 void (*func)(gpointer,gpointer) = ptr;
1422 func (sp [0].data.p, sp [1].data.p);
1425 case MINT_ICALL_PI_V: {
1426 void (*func)(gpointer,int) = ptr;
1428 func (sp [0].data.p, sp [1].data.i);
1431 case MINT_ICALL_PP_P: {
1432 gpointer (*func)(gpointer,gpointer) = ptr;
1434 sp [-1].data.p = func (sp [-1].data.p, sp [0].data.p);
1437 case MINT_ICALL_PI_P: {
1438 gpointer (*func)(gpointer,int) = ptr;
1440 sp [-1].data.p = func (sp [-1].data.p, sp [0].data.i);
1443 case MINT_ICALL_PPP_V: {
1444 void (*func)(gpointer,gpointer,gpointer) = ptr;
1446 func (sp [0].data.p, sp [1].data.p, sp [2].data.p);
1449 case MINT_ICALL_PPI_V: {
1450 void (*func)(gpointer,gpointer,int) = ptr;
1452 func (sp [0].data.p, sp [1].data.p, sp [2].data.i);
1456 g_assert_not_reached ();
1459 context->env_frame = old_env_frame;
1460 context->current_env = old_env;
1465 static mono_mutex_t create_method_pointer_mutex;
1467 static GHashTable *method_pointer_hash = NULL;
1469 static MonoMethod *method_pointers [2] = {0};
1472 mp_tramp_0 (MonoObject *this_obj, void **params, MonoObject **exc, void *compiled_method) {
1474 void *params_real[] = {this_obj, ¶ms, &exc, &compiled_method};
1475 MonoObject *ret = mono_interp_runtime_invoke (method_pointers [0], NULL, params_real, NULL, &error);
1476 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
1481 mp_tramp_1 (MonoObject *this_obj, void **params, MonoObject **exc, void *compiled_method) {
1483 void *params_real[] = {this_obj, ¶ms, &exc, &compiled_method};
1484 MonoObject *ret = mono_interp_runtime_invoke (method_pointers [1], NULL, params_real, NULL, &error);
1485 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
1489 gpointer *mp_tramps[] = {(gpointer) mp_tramp_0, (gpointer) mp_tramp_1};
1491 static int tramps_used = 0;
1494 mono_interp_create_method_pointer (MonoMethod *method, MonoError *error)
1499 mono_os_mutex_lock (&create_method_pointer_mutex);
1500 if (!method_pointer_hash) {
1501 // FIXME: is registering method table as GC root really necessary?
1502 // MONO_GC_REGISTER_ROOT_FIXED (method_pointer_hash);
1503 method_pointer_hash = g_hash_table_new (NULL, NULL);
1505 addr = g_hash_table_lookup (method_pointer_hash, method);
1507 mono_os_mutex_unlock (&create_method_pointer_mutex);
1512 * If it is a static P/Invoke method, we can just return the pointer
1513 * to the method implementation.
1515 if (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL && ((MonoMethodPInvoke*) method)->addr) {
1516 ji = g_new0 (MonoJitInfo, 1);
1517 ji->d.method = method;
1519 ji->code_start = addr = ((MonoMethodPInvoke*) method)->addr;
1521 mono_jit_info_table_add (mono_get_root_domain (), ji);
1524 g_assert (method->wrapper_type == MONO_WRAPPER_RUNTIME_INVOKE);
1525 g_assert (tramps_used < 2);
1527 /* FIXME: needs locking */
1528 method_pointers [tramps_used] = method;
1529 addr = mp_tramps [tramps_used];
1533 g_hash_table_insert (method_pointer_hash, method, addr);
1534 mono_os_mutex_unlock (&create_method_pointer_mutex);
1540 static int opcode_counts[512];
1542 #define COUNT_OP(op) opcode_counts[op]++
1544 #define COUNT_OP(op)
1548 #define DUMP_INSTR() \
1549 if (tracing > 1) { \
1551 if (sp > frame->stack) { \
1552 ins = dump_stack (frame->stack, sp); \
1554 ins = g_strdup (""); \
1558 char *mn = mono_method_full_name (frame->runtime_method->method, FALSE); \
1559 g_print ("(%p) %s -> ", mono_thread_internal_current (), mn); \
1561 mono_interp_dis_mintop(rtm->code, ip); \
1562 g_print ("\t%d:%s\n", vt_sp - vtalloc, ins); \
1566 #define DUMP_INSTR()
1570 #define USE_COMPUTED_GOTO 1
1572 #if USE_COMPUTED_GOTO
1573 #define MINT_IN_SWITCH(op) COUNT_OP(op); goto *in_labels[op];
1574 #define MINT_IN_CASE(x) LAB_ ## x:
1576 #define MINT_IN_BREAK if (tracing > 1) goto main_loop; else { COUNT_OP(*ip); goto *in_labels[*ip]; }
1578 #define MINT_IN_BREAK { COUNT_OP(*ip); goto *in_labels[*ip]; }
1580 #define MINT_IN_DEFAULT mint_default: if (0) goto mint_default; /* make gcc shut up */
1582 #define MINT_IN_SWITCH(op) switch (op)
1583 #define MINT_IN_CASE(x) case x:
1584 #define MINT_IN_BREAK break
1585 #define MINT_IN_DEFAULT default:
1589 * Defining this causes register allocation errors in some versions of gcc:
1590 * error: unable to find a register to spill in class `SIREG'
1592 /* #define MINT_USE_DEDICATED_IP_REG */
1595 ves_exec_method_with_context (MonoInvocation *frame, ThreadContext *context)
1597 MonoInvocation child_frame;
1598 GSList *finally_ips = NULL;
1599 const unsigned short *endfinally_ip = NULL;
1600 #if defined(__GNUC__) && defined (i386) && defined (MINT_USE_DEDICATED_IP_REG)
1601 register const unsigned short *ip asm ("%esi");
1603 register const unsigned short *ip;
1605 register stackval *sp;
1608 gint tracing = global_tracing;
1609 unsigned char *vtalloc;
1612 unsigned char *vt_sp;
1613 unsigned char *locals;
1615 MonoObject *o = NULL;
1617 #if USE_COMPUTED_GOTO
1618 static void *in_labels[] = {
1619 #define OPDEF(a,b,c,d) \
1621 #include "mintops.def"
1626 frame->ex_handler = NULL;
1628 context->current_frame = frame;
1631 debug_enter (frame, &tracing);
1634 if (!frame->runtime_method->transformed) {
1635 context->managed_code = 0;
1637 char *mn = mono_method_full_name (frame->runtime_method->method, FALSE);
1638 g_print ("(%p) Transforming %s\n", mono_thread_internal_current (), mn);
1641 frame->ex = mono_interp_transform_method (frame->runtime_method, context);
1642 context->managed_code = 1;
1650 rtm = frame->runtime_method;
1651 frame->args = alloca (rtm->alloca_size);
1652 sp = frame->stack = (stackval *)((char *)frame->args + rtm->args_size);
1655 memset(sp, 0, rtm->stack_size);
1657 vt_sp = (unsigned char *) sp + rtm->stack_size;
1661 locals = (unsigned char *) vt_sp + rtm->vt_stack_size;
1663 child_frame.parent = frame;
1669 * using while (ip < end) may result in a 15% performance drop,
1670 * but it may be useful for debug
1674 /* g_assert (sp >= frame->stack); */
1675 /* g_assert(vt_sp - vtalloc <= rtm->vt_stack_size); */
1677 MINT_IN_SWITCH (*ip) {
1678 MINT_IN_CASE(MINT_INITLOCALS)
1679 memset (locals, 0, rtm->locals_size);
1682 MINT_IN_CASE(MINT_NOP)
1685 MINT_IN_CASE(MINT_BREAK)
1687 G_BREAKPOINT (); /* this is not portable... */
1689 MINT_IN_CASE(MINT_LDNULL)
1694 MINT_IN_CASE(MINT_VTRESULT) {
1695 int ret_size = * (guint16 *)(ip + 1);
1696 unsigned char *ret_vt_sp = vt_sp;
1697 vt_sp -= READ32(ip + 2);
1699 memmove (vt_sp, ret_vt_sp, ret_size);
1700 sp [-1].data.p = vt_sp;
1701 vt_sp += (ret_size + 7) & ~7;
1706 #define LDC(n) do { sp->data.i = (n); ++ip; ++sp; } while (0)
1707 MINT_IN_CASE(MINT_LDC_I4_M1)
1710 MINT_IN_CASE(MINT_LDC_I4_0)
1713 MINT_IN_CASE(MINT_LDC_I4_1)
1716 MINT_IN_CASE(MINT_LDC_I4_2)
1719 MINT_IN_CASE(MINT_LDC_I4_3)
1722 MINT_IN_CASE(MINT_LDC_I4_4)
1725 MINT_IN_CASE(MINT_LDC_I4_5)
1728 MINT_IN_CASE(MINT_LDC_I4_6)
1731 MINT_IN_CASE(MINT_LDC_I4_7)
1734 MINT_IN_CASE(MINT_LDC_I4_8)
1737 MINT_IN_CASE(MINT_LDC_I4_S)
1738 sp->data.i = *(const short *)(ip + 1);
1742 MINT_IN_CASE(MINT_LDC_I4)
1744 sp->data.i = READ32 (ip);
1748 MINT_IN_CASE(MINT_LDC_I8)
1750 sp->data.l = READ64 (ip);
1754 MINT_IN_CASE(MINT_LDC_R4) {
1758 sp->data.f = * (float *)&val;
1763 MINT_IN_CASE(MINT_LDC_R8)
1764 sp->data.l = READ64 (ip + 1); /* note union usage */
1768 MINT_IN_CASE(MINT_DUP)
1773 MINT_IN_CASE(MINT_DUP_VT)
1774 i32 = READ32 (ip + 1);
1776 memcpy(sp->data.p, sp [-1].data.p, i32);
1777 vt_sp += (i32 + 7) & ~7;
1781 MINT_IN_CASE(MINT_POP)
1785 MINT_IN_CASE(MINT_JMP) {
1786 RuntimeMethod *new_method = rtm->data_items [* (guint16 *)(ip + 1)];
1787 if (!new_method->transformed) {
1789 frame->ex = mono_interp_transform_method (new_method, context);
1794 if (new_method->alloca_size > rtm->alloca_size)
1795 g_error ("MINT_JMP to method which needs more stack space (%d > %d)", new_method->alloca_size, rtm->alloca_size);
1796 rtm = frame->runtime_method = new_method;
1797 vt_sp = (unsigned char *) sp + rtm->stack_size;
1801 locals = vt_sp + rtm->vt_stack_size;
1802 ip = rtm->new_body_start; /* bypass storing input args from callers frame */
1805 MINT_IN_CASE(MINT_CALLI) {
1806 MonoMethodSignature *csignature;
1807 stackval *endsp = sp;
1811 csignature = rtm->data_items [* (guint16 *)(ip + 1)];
1815 child_frame.runtime_method = sp->data.p;
1818 child_frame.retval = sp;
1819 /* decrement by the actual number of args */
1820 sp -= csignature->param_count;
1821 if (csignature->hasthis)
1823 child_frame.stack_args = sp;
1825 /* `this' can be NULL for string:.ctor */
1826 if (csignature->hasthis && sp->data.p && mono_object_is_transparent_proxy (sp->data.p)) {
1827 child_frame.runtime_method = mono_interp_get_runtime_method (context->domain, mono_marshal_get_remoting_invoke (child_frame.runtime_method->method), &error);
1828 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
1829 } else if (child_frame.runtime_method->method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) {
1830 child_frame.runtime_method = mono_interp_get_runtime_method (context->domain, mono_marshal_get_native_wrapper (child_frame.runtime_method->method, FALSE, FALSE), &error);
1831 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
1834 ves_exec_method_with_context (&child_frame, context);
1836 context->current_frame = frame;
1838 if (child_frame.ex) {
1840 * An exception occurred, need to run finally, fault and catch handlers..
1842 frame->ex = child_frame.ex;
1843 goto handle_finally;
1846 /* need to handle typedbyref ... */
1847 if (csignature->ret->type != MONO_TYPE_VOID) {
1853 MINT_IN_CASE(MINT_CALLI_NAT) {
1854 MonoMethodSignature *csignature;
1855 stackval *endsp = sp;
1856 unsigned char *code = NULL;
1860 csignature = rtm->data_items [* (guint16 *)(ip + 1)];
1865 child_frame.runtime_method = NULL;
1868 child_frame.retval = sp;
1869 /* decrement by the actual number of args */
1870 sp -= csignature->param_count;
1871 if (csignature->hasthis)
1873 child_frame.stack_args = sp;
1874 ves_pinvoke_method (&child_frame, csignature, (MonoFuncV) code, FALSE, context);
1876 context->current_frame = frame;
1878 if (child_frame.ex) {
1880 * An exception occurred, need to run finally, fault and catch handlers..
1882 frame->ex = child_frame.ex;
1883 if (context->search_for_handler) {
1884 context->search_for_handler = 0;
1885 goto handle_exception;
1887 goto handle_finally;
1890 /* need to handle typedbyref ... */
1891 if (csignature->ret->type != MONO_TYPE_VOID) {
1897 MINT_IN_CASE(MINT_CALL) {
1898 stackval *endsp = sp;
1902 child_frame.runtime_method = rtm->data_items [* (guint16 *)(ip + 1)];
1905 child_frame.retval = sp;
1906 /* decrement by the actual number of args */
1907 sp -= child_frame.runtime_method->param_count;
1908 if (child_frame.runtime_method->hasthis)
1910 child_frame.stack_args = sp;
1912 /* `this' can be NULL for string:.ctor */
1913 if (child_frame.runtime_method->hasthis && !child_frame.runtime_method->valuetype && sp->data.p && mono_object_is_transparent_proxy (sp->data.p)) {
1914 child_frame.runtime_method = mono_interp_get_runtime_method (context->domain, mono_marshal_get_remoting_invoke (child_frame.runtime_method->method), &error);
1915 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
1917 ves_exec_method_with_context (&child_frame, context);
1919 context->current_frame = frame;
1921 if (child_frame.ex) {
1923 * An exception occurred, need to run finally, fault and catch handlers..
1925 frame->ex = child_frame.ex;
1926 goto handle_finally;
1929 /* need to handle typedbyref ... */
1934 MINT_IN_CASE(MINT_VCALL) {
1937 child_frame.runtime_method = rtm->data_items [* (guint16 *)(ip + 1)];
1941 child_frame.retval = sp;
1942 /* decrement by the actual number of args */
1943 sp -= child_frame.runtime_method->param_count;
1944 if (child_frame.runtime_method->hasthis)
1946 child_frame.stack_args = sp;
1948 if (child_frame.runtime_method->hasthis && !child_frame.runtime_method->valuetype && mono_object_is_transparent_proxy (sp->data.p)) {
1949 child_frame.runtime_method = mono_interp_get_runtime_method (context->domain, mono_marshal_get_remoting_invoke (child_frame.runtime_method->method), &error);
1950 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
1953 ves_exec_method_with_context (&child_frame, context);
1955 context->current_frame = frame;
1957 if (child_frame.ex) {
1959 * An exception occurred, need to run finally, fault and catch handlers..
1961 frame->ex = child_frame.ex;
1962 goto handle_finally;
1966 MINT_IN_CASE(MINT_CALLVIRT) {
1967 stackval *endsp = sp;
1968 MonoObject *this_arg;
1973 token = * (unsigned short *)(ip + 1);
1975 child_frame.runtime_method = rtm->data_items [token];
1977 child_frame.retval = sp;
1979 /* decrement by the actual number of args */
1980 sp -= child_frame.runtime_method->param_count + 1;
1981 child_frame.stack_args = sp;
1982 this_arg = sp->data.p;
1984 THROW_EX (mono_get_exception_null_reference(), ip - 2);
1985 child_frame.runtime_method = get_virtual_method (context->domain, child_frame.runtime_method, this_arg);
1987 if (this_arg->vtable->klass->valuetype && child_frame.runtime_method->valuetype) {
1989 gpointer *unboxed = mono_object_unbox (this_arg);
1990 stackval_from_data (&this_arg->vtable->klass->byval_arg, sp, (char *) unboxed, FALSE);
1993 ves_exec_method_with_context (&child_frame, context);
1995 context->current_frame = frame;
1997 if (child_frame.ex) {
1999 * An exception occurred, need to run finally, fault and catch handlers..
2001 frame->ex = child_frame.ex;
2002 if (context->search_for_handler) {
2003 context->search_for_handler = 0;
2004 goto handle_exception;
2006 goto handle_finally;
2009 /* need to handle typedbyref ... */
2014 MINT_IN_CASE(MINT_VCALLVIRT) {
2015 MonoObject *this_arg;
2020 token = * (unsigned short *)(ip + 1);
2022 child_frame.runtime_method = rtm->data_items [token];
2024 child_frame.retval = sp;
2026 /* decrement by the actual number of args */
2027 sp -= child_frame.runtime_method->param_count + 1;
2028 child_frame.stack_args = sp;
2029 this_arg = sp->data.p;
2031 THROW_EX (mono_get_exception_null_reference(), ip - 2);
2032 child_frame.runtime_method = get_virtual_method (context->domain, child_frame.runtime_method, this_arg);
2034 if (this_arg->vtable->klass->valuetype && child_frame.runtime_method->valuetype) {
2035 gpointer *unboxed = mono_object_unbox (this_arg);
2036 stackval_from_data (&this_arg->vtable->klass->byval_arg, sp, (char *) unboxed, FALSE);
2039 ves_exec_method_with_context (&child_frame, context);
2041 context->current_frame = frame;
2043 if (child_frame.ex) {
2045 * An exception occurred, need to run finally, fault and catch handlers..
2047 frame->ex = child_frame.ex;
2048 if (context->search_for_handler) {
2049 context->search_for_handler = 0;
2050 goto handle_exception;
2052 goto handle_finally;
2056 MINT_IN_CASE(MINT_CALLRUN)
2057 ves_runtime_method (frame, context);
2060 goto handle_exception;
2063 MINT_IN_CASE(MINT_RET)
2065 *frame->retval = *sp;
2066 if (sp > frame->stack)
2067 g_warning ("ret: more values on stack: %d", sp-frame->stack);
2069 MINT_IN_CASE(MINT_RET_VOID)
2070 if (sp > frame->stack)
2071 g_warning ("ret.void: more values on stack: %d", sp-frame->stack);
2073 MINT_IN_CASE(MINT_RET_VT)
2074 i32 = READ32(ip + 1);
2076 memcpy(frame->retval->data.p, sp->data.p, i32);
2077 if (sp > frame->stack)
2078 g_warning ("ret.vt: more values on stack: %d", sp-frame->stack);
2080 MINT_IN_CASE(MINT_BR_S)
2081 ip += (short) *(ip + 1);
2083 MINT_IN_CASE(MINT_BR)
2084 ip += (gint32) READ32(ip + 1);
2086 #define ZEROP_S(datamem, op) \
2088 if (sp->data.datamem op 0) \
2089 ip += * (gint16 *)(ip + 1); \
2093 #define ZEROP(datamem, op) \
2095 if (sp->data.datamem op 0) \
2096 ip += READ32(ip + 1); \
2100 MINT_IN_CASE(MINT_BRFALSE_I4_S)
2103 MINT_IN_CASE(MINT_BRFALSE_I8_S)
2106 MINT_IN_CASE(MINT_BRFALSE_R8_S)
2109 MINT_IN_CASE(MINT_BRFALSE_I4)
2112 MINT_IN_CASE(MINT_BRFALSE_I8)
2115 MINT_IN_CASE(MINT_BRFALSE_R8)
2118 MINT_IN_CASE(MINT_BRTRUE_I4_S)
2121 MINT_IN_CASE(MINT_BRTRUE_I8_S)
2124 MINT_IN_CASE(MINT_BRTRUE_R8_S)
2127 MINT_IN_CASE(MINT_BRTRUE_I4)
2130 MINT_IN_CASE(MINT_BRTRUE_I8)
2133 MINT_IN_CASE(MINT_BRTRUE_R8)
2136 #define CONDBR_S(cond) \
2139 ip += * (gint16 *)(ip + 1); \
2142 #define BRELOP_S(datamem, op) \
2143 CONDBR_S(sp[0].data.datamem op sp[1].data.datamem)
2145 #define CONDBR(cond) \
2148 ip += READ32(ip + 1); \
2152 #define BRELOP(datamem, op) \
2153 CONDBR(sp[0].data.datamem op sp[1].data.datamem)
2155 MINT_IN_CASE(MINT_BEQ_I4_S)
2158 MINT_IN_CASE(MINT_BEQ_I8_S)
2161 MINT_IN_CASE(MINT_BEQ_R8_S)
2162 CONDBR_S(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f == sp[1].data.f)
2164 MINT_IN_CASE(MINT_BEQ_I4)
2167 MINT_IN_CASE(MINT_BEQ_I8)
2170 MINT_IN_CASE(MINT_BEQ_R8)
2171 CONDBR(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f == sp[1].data.f)
2173 MINT_IN_CASE(MINT_BGE_I4_S)
2176 MINT_IN_CASE(MINT_BGE_I8_S)
2179 MINT_IN_CASE(MINT_BGE_R8_S)
2180 CONDBR_S(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f >= sp[1].data.f)
2182 MINT_IN_CASE(MINT_BGE_I4)
2185 MINT_IN_CASE(MINT_BGE_I8)
2188 MINT_IN_CASE(MINT_BGE_R8)
2189 CONDBR(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f >= sp[1].data.f)
2191 MINT_IN_CASE(MINT_BGT_I4_S)
2194 MINT_IN_CASE(MINT_BGT_I8_S)
2197 MINT_IN_CASE(MINT_BGT_R8_S)
2198 CONDBR_S(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f > sp[1].data.f)
2200 MINT_IN_CASE(MINT_BGT_I4)
2203 MINT_IN_CASE(MINT_BGT_I8)
2206 MINT_IN_CASE(MINT_BGT_R8)
2207 CONDBR(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f > sp[1].data.f)
2209 MINT_IN_CASE(MINT_BLT_I4_S)
2212 MINT_IN_CASE(MINT_BLT_I8_S)
2215 MINT_IN_CASE(MINT_BLT_R8_S)
2216 CONDBR_S(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f < sp[1].data.f)
2218 MINT_IN_CASE(MINT_BLT_I4)
2221 MINT_IN_CASE(MINT_BLT_I8)
2224 MINT_IN_CASE(MINT_BLT_R8)
2225 CONDBR(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f < sp[1].data.f)
2227 MINT_IN_CASE(MINT_BLE_I4_S)
2230 MINT_IN_CASE(MINT_BLE_I8_S)
2233 MINT_IN_CASE(MINT_BLE_R8_S)
2234 CONDBR_S(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f <= sp[1].data.f)
2236 MINT_IN_CASE(MINT_BLE_I4)
2239 MINT_IN_CASE(MINT_BLE_I8)
2242 MINT_IN_CASE(MINT_BLE_R8)
2243 CONDBR(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f <= sp[1].data.f)
2245 MINT_IN_CASE(MINT_BNE_UN_I4_S)
2248 MINT_IN_CASE(MINT_BNE_UN_I8_S)
2251 MINT_IN_CASE(MINT_BNE_UN_R8_S)
2252 CONDBR_S(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f != sp[1].data.f)
2254 MINT_IN_CASE(MINT_BNE_UN_I4)
2257 MINT_IN_CASE(MINT_BNE_UN_I8)
2260 MINT_IN_CASE(MINT_BNE_UN_R8)
2261 CONDBR(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f != sp[1].data.f)
2264 #define BRELOP_S_CAST(datamem, op, type) \
2266 if ((type) sp[0].data.datamem op (type) sp[1].data.datamem) \
2267 ip += * (gint16 *)(ip + 1); \
2271 #define BRELOP_CAST(datamem, op, type) \
2273 if ((type) sp[0].data.datamem op (type) sp[1].data.datamem) \
2274 ip += READ32(ip + 1); \
2278 MINT_IN_CASE(MINT_BGE_UN_I4_S)
2279 BRELOP_S_CAST(i, >=, guint32);
2281 MINT_IN_CASE(MINT_BGE_UN_I8_S)
2282 BRELOP_S_CAST(l, >=, guint64);
2284 MINT_IN_CASE(MINT_BGE_UN_R8_S)
2285 CONDBR_S(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f >= sp[1].data.f)
2287 MINT_IN_CASE(MINT_BGE_UN_I4)
2288 BRELOP_CAST(i, >=, guint32);
2290 MINT_IN_CASE(MINT_BGE_UN_I8)
2291 BRELOP_CAST(l, >=, guint64);
2293 MINT_IN_CASE(MINT_BGE_UN_R8)
2294 CONDBR(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f >= sp[1].data.f)
2296 MINT_IN_CASE(MINT_BGT_UN_I4_S)
2297 BRELOP_S_CAST(i, >, guint32);
2299 MINT_IN_CASE(MINT_BGT_UN_I8_S)
2300 BRELOP_S_CAST(l, >, guint64);
2302 MINT_IN_CASE(MINT_BGT_UN_R8_S)
2303 CONDBR_S(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f > sp[1].data.f)
2305 MINT_IN_CASE(MINT_BGT_UN_I4)
2306 BRELOP_CAST(i, >, guint32);
2308 MINT_IN_CASE(MINT_BGT_UN_I8)
2309 BRELOP_CAST(l, >, guint64);
2311 MINT_IN_CASE(MINT_BGT_UN_R8)
2312 CONDBR(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f > sp[1].data.f)
2314 MINT_IN_CASE(MINT_BLE_UN_I4_S)
2315 BRELOP_S_CAST(i, <=, guint32);
2317 MINT_IN_CASE(MINT_BLE_UN_I8_S)
2318 BRELOP_S_CAST(l, <=, guint64);
2320 MINT_IN_CASE(MINT_BLE_UN_R8_S)
2321 CONDBR_S(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f <= sp[1].data.f)
2323 MINT_IN_CASE(MINT_BLE_UN_I4)
2324 BRELOP_CAST(i, <=, guint32);
2326 MINT_IN_CASE(MINT_BLE_UN_I8)
2327 BRELOP_CAST(l, <=, guint64);
2329 MINT_IN_CASE(MINT_BLE_UN_R8)
2330 CONDBR(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f <= sp[1].data.f)
2332 MINT_IN_CASE(MINT_BLT_UN_I4_S)
2333 BRELOP_S_CAST(i, <, guint32);
2335 MINT_IN_CASE(MINT_BLT_UN_I8_S)
2336 BRELOP_S_CAST(l, <, guint64);
2338 MINT_IN_CASE(MINT_BLT_UN_R8_S)
2339 CONDBR_S(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f < sp[1].data.f)
2341 MINT_IN_CASE(MINT_BLT_UN_I4)
2342 BRELOP_CAST(i, <, guint32);
2344 MINT_IN_CASE(MINT_BLT_UN_I8)
2345 BRELOP_CAST(l, <, guint64);
2347 MINT_IN_CASE(MINT_BLT_UN_R8)
2348 CONDBR(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f < sp[1].data.f)
2350 MINT_IN_CASE(MINT_SWITCH) {
2352 const unsigned short *st;
2358 if ((guint32)sp->data.i < n) {
2360 ip += 2 * (guint32)sp->data.i;
2361 offset = READ32 (ip);
2368 MINT_IN_CASE(MINT_LDIND_I1)
2370 sp[-1].data.i = *(gint8*)sp[-1].data.p;
2372 MINT_IN_CASE(MINT_LDIND_U1)
2374 sp[-1].data.i = *(guint8*)sp[-1].data.p;
2376 MINT_IN_CASE(MINT_LDIND_I2)
2378 sp[-1].data.i = *(gint16*)sp[-1].data.p;
2380 MINT_IN_CASE(MINT_LDIND_U2)
2382 sp[-1].data.i = *(guint16*)sp[-1].data.p;
2384 MINT_IN_CASE(MINT_LDIND_I4) /* Fall through */
2385 MINT_IN_CASE(MINT_LDIND_U4)
2387 sp[-1].data.i = *(gint32*)sp[-1].data.p;
2389 MINT_IN_CASE(MINT_LDIND_I8)
2391 sp[-1].data.l = *(gint64*)sp[-1].data.p;
2393 MINT_IN_CASE(MINT_LDIND_I) {
2394 guint16 offset = * (guint16 *)(ip + 1);
2395 sp[-1 - offset].data.p = *(gpointer*)sp[-1 - offset].data.p;
2399 MINT_IN_CASE(MINT_LDIND_R4)
2401 sp[-1].data.f = *(gfloat*)sp[-1].data.p;
2403 MINT_IN_CASE(MINT_LDIND_R8)
2405 sp[-1].data.f = *(gdouble*)sp[-1].data.p;
2407 MINT_IN_CASE(MINT_LDIND_REF)
2409 sp[-1].data.p = *(gpointer*)sp[-1].data.p;
2411 MINT_IN_CASE(MINT_STIND_REF)
2414 * (gpointer *) sp->data.p = sp[1].data.p;
2416 MINT_IN_CASE(MINT_STIND_I1)
2419 * (gint8 *) sp->data.p = (gint8)sp[1].data.i;
2421 MINT_IN_CASE(MINT_STIND_I2)
2424 * (gint16 *) sp->data.p = (gint16)sp[1].data.i;
2426 MINT_IN_CASE(MINT_STIND_I4)
2429 * (gint32 *) sp->data.p = sp[1].data.i;
2431 MINT_IN_CASE(MINT_STIND_I)
2434 * (mono_i *) sp->data.p = (mono_i)sp[1].data.p;
2436 MINT_IN_CASE(MINT_STIND_I8)
2439 * (gint64 *) sp->data.p = sp[1].data.l;
2441 MINT_IN_CASE(MINT_STIND_R4)
2444 * (float *) sp->data.p = (gfloat)sp[1].data.f;
2446 MINT_IN_CASE(MINT_STIND_R8)
2449 * (double *) sp->data.p = sp[1].data.f;
2451 #define BINOP(datamem, op) \
2453 sp [-1].data.datamem = sp [-1].data.datamem op sp [0].data.datamem; \
2455 MINT_IN_CASE(MINT_ADD_I4)
2458 MINT_IN_CASE(MINT_ADD_I8)
2461 MINT_IN_CASE(MINT_ADD_R8)
2464 MINT_IN_CASE(MINT_ADD1_I4)
2468 MINT_IN_CASE(MINT_SUB_I4)
2471 MINT_IN_CASE(MINT_SUB_I8)
2474 MINT_IN_CASE(MINT_SUB_R8)
2477 MINT_IN_CASE(MINT_SUB1_I4)
2481 MINT_IN_CASE(MINT_MUL_I4)
2484 MINT_IN_CASE(MINT_MUL_I8)
2487 MINT_IN_CASE(MINT_MUL_R8)
2490 MINT_IN_CASE(MINT_DIV_I4)
2491 if (sp [-1].data.i == 0)
2492 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2493 if (sp [-1].data.i == (-1))
2494 THROW_EX (mono_get_exception_overflow (), ip);
2497 MINT_IN_CASE(MINT_DIV_I8)
2498 if (sp [-1].data.l == 0)
2499 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2500 if (sp [-1].data.l == (-1))
2501 THROW_EX (mono_get_exception_overflow (), ip);
2504 MINT_IN_CASE(MINT_DIV_R8)
2508 #define BINOP_CAST(datamem, op, type) \
2510 sp [-1].data.datamem = (type)sp [-1].data.datamem op (type)sp [0].data.datamem; \
2512 MINT_IN_CASE(MINT_DIV_UN_I4)
2513 if (sp [-1].data.i == 0)
2514 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2515 BINOP_CAST(i, /, guint32);
2517 MINT_IN_CASE(MINT_DIV_UN_I8)
2518 if (sp [-1].data.l == 0)
2519 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2520 BINOP_CAST(l, /, guint64);
2522 MINT_IN_CASE(MINT_REM_I4)
2523 if (sp [-1].data.i == 0)
2524 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2527 MINT_IN_CASE(MINT_REM_I8)
2528 if (sp [-1].data.l == 0)
2529 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2532 MINT_IN_CASE(MINT_REM_R8)
2533 /* FIXME: what do we actually do here? */
2535 sp [-1].data.f = fmod (sp [-1].data.f, sp [0].data.f);
2538 MINT_IN_CASE(MINT_REM_UN_I4)
2539 if (sp [-1].data.i == 0)
2540 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2541 BINOP_CAST(i, %, guint32);
2543 MINT_IN_CASE(MINT_REM_UN_I8)
2544 if (sp [-1].data.l == 0)
2545 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2546 BINOP_CAST(l, %, guint64);
2548 MINT_IN_CASE(MINT_AND_I4)
2551 MINT_IN_CASE(MINT_AND_I8)
2554 MINT_IN_CASE(MINT_OR_I4)
2557 MINT_IN_CASE(MINT_OR_I8)
2560 MINT_IN_CASE(MINT_XOR_I4)
2563 MINT_IN_CASE(MINT_XOR_I8)
2567 #define SHIFTOP(datamem, op) \
2569 sp [-1].data.datamem = sp [-1].data.datamem op sp [0].data.i; \
2572 MINT_IN_CASE(MINT_SHL_I4)
2575 MINT_IN_CASE(MINT_SHL_I8)
2578 MINT_IN_CASE(MINT_SHR_I4)
2581 MINT_IN_CASE(MINT_SHR_I8)
2584 MINT_IN_CASE(MINT_SHR_UN_I4)
2586 sp [-1].data.i = (guint32)sp [-1].data.i >> sp [0].data.i;
2589 MINT_IN_CASE(MINT_SHR_UN_I8)
2591 sp [-1].data.l = (guint64)sp [-1].data.l >> sp [0].data.i;
2594 MINT_IN_CASE(MINT_NEG_I4)
2595 sp [-1].data.i = - sp [-1].data.i;
2598 MINT_IN_CASE(MINT_NEG_I8)
2599 sp [-1].data.l = - sp [-1].data.l;
2602 MINT_IN_CASE(MINT_NEG_R8)
2603 sp [-1].data.f = - sp [-1].data.f;
2606 MINT_IN_CASE(MINT_NOT_I4)
2607 sp [-1].data.i = ~ sp [-1].data.i;
2610 MINT_IN_CASE(MINT_NOT_I8)
2611 sp [-1].data.l = ~ sp [-1].data.l;
2614 MINT_IN_CASE(MINT_CONV_I1_I4)
2615 sp [-1].data.i = (gint8)sp [-1].data.i;
2618 MINT_IN_CASE(MINT_CONV_I1_I8)
2619 sp [-1].data.i = (gint8)sp [-1].data.l;
2622 MINT_IN_CASE(MINT_CONV_I1_R8)
2623 sp [-1].data.i = (gint8)sp [-1].data.f;
2626 MINT_IN_CASE(MINT_CONV_U1_I4)
2627 sp [-1].data.i = (guint8)sp [-1].data.i;
2630 MINT_IN_CASE(MINT_CONV_U1_I8)
2631 sp [-1].data.i = (guint8)sp [-1].data.l;
2634 MINT_IN_CASE(MINT_CONV_U1_R8)
2635 sp [-1].data.i = (guint8)sp [-1].data.f;
2638 MINT_IN_CASE(MINT_CONV_I2_I4)
2639 sp [-1].data.i = (gint16)sp [-1].data.i;
2642 MINT_IN_CASE(MINT_CONV_I2_I8)
2643 sp [-1].data.i = (gint16)sp [-1].data.l;
2646 MINT_IN_CASE(MINT_CONV_I2_R8)
2647 sp [-1].data.i = (gint16)sp [-1].data.f;
2650 MINT_IN_CASE(MINT_CONV_U2_I4)
2651 sp [-1].data.i = (guint16)sp [-1].data.i;
2654 MINT_IN_CASE(MINT_CONV_U2_I8)
2655 sp [-1].data.i = (guint16)sp [-1].data.l;
2658 MINT_IN_CASE(MINT_CONV_U2_R8)
2659 sp [-1].data.i = (guint16)sp [-1].data.f;
2662 MINT_IN_CASE(MINT_CONV_I4_R8)
2663 sp [-1].data.i = (gint32)sp [-1].data.f;
2666 MINT_IN_CASE(MINT_CONV_U4_I8)
2667 MINT_IN_CASE(MINT_CONV_I4_I8)
2668 sp [-1].data.i = (gint32)sp [-1].data.l;
2671 MINT_IN_CASE(MINT_CONV_I4_I8_SP)
2672 sp [-2].data.i = (gint32)sp [-2].data.l;
2675 MINT_IN_CASE(MINT_CONV_U4_R8)
2676 sp [-1].data.i = (guint32)sp [-1].data.f;
2679 MINT_IN_CASE(MINT_CONV_I8_I4)
2680 sp [-1].data.l = sp [-1].data.i;
2683 MINT_IN_CASE(MINT_CONV_I8_I4_SP)
2684 sp [-2].data.l = sp [-2].data.i;
2687 MINT_IN_CASE(MINT_CONV_I8_U4)
2688 sp [-1].data.l = (guint32)sp [-1].data.i;
2691 MINT_IN_CASE(MINT_CONV_I8_R8)
2692 sp [-1].data.l = (gint64)sp [-1].data.f;
2695 MINT_IN_CASE(MINT_CONV_R4_I4)
2696 sp [-1].data.f = (float)sp [-1].data.i;
2699 MINT_IN_CASE(MINT_CONV_R4_I8)
2700 sp [-1].data.f = (float)sp [-1].data.l;
2703 MINT_IN_CASE(MINT_CONV_R4_R8)
2704 sp [-1].data.f = (float)sp [-1].data.f;
2707 MINT_IN_CASE(MINT_CONV_R8_I4)
2708 sp [-1].data.f = (double)sp [-1].data.i;
2711 MINT_IN_CASE(MINT_CONV_R8_I8)
2712 sp [-1].data.f = (double)sp [-1].data.l;
2715 MINT_IN_CASE(MINT_CONV_U8_I4)
2716 sp [-1].data.l = sp [-1].data.i & 0xffffffff;
2719 MINT_IN_CASE(MINT_CONV_U8_R8)
2720 sp [-1].data.l = (guint64)sp [-1].data.f;
2724 MINT_IN_CASE(MINT_CPOBJ) {
2727 vtklass = rtm->data_items[READ32 (ip)];
2730 memcpy (sp [0].data.p, sp [1].data.p, mono_class_value_size (vtklass, NULL));
2734 MINT_IN_CASE(MINT_LDOBJ) {
2737 c = rtm->data_items[* (guint16 *)(ip + 1)];
2739 if (c->byval_arg.type != MONO_TYPE_VALUETYPE || c->byval_arg.data.klass->enumtype) {
2741 stackval_from_data (&c->byval_arg, &sp [-1], p, FALSE);
2743 size = mono_class_value_size (c, NULL);
2745 sp [-1].data.p = vt_sp;
2746 memcpy(vt_sp, p, size);
2747 vt_sp += (size + 7) & ~7;
2751 MINT_IN_CASE(MINT_LDSTR)
2752 sp->data.p = rtm->data_items [* (guint16 *)(ip + 1)];
2756 MINT_IN_CASE(MINT_NEWOBJ) {
2757 MonoClass *newobj_class;
2758 MonoMethodSignature *csig;
2759 stackval valuetype_this;
2765 token = * (guint16 *)(ip + 1);
2768 child_frame.runtime_method = rtm->data_items [token];
2769 csig = mono_method_signature (child_frame.runtime_method->method);
2770 newobj_class = child_frame.runtime_method->method->klass;
2771 /*if (profiling_classes) {
2772 guint count = GPOINTER_TO_UINT (g_hash_table_lookup (profiling_classes, newobj_class));
2774 g_hash_table_insert (profiling_classes, newobj_class, GUINT_TO_POINTER (count));
2777 if (newobj_class->parent == mono_defaults.array_class) {
2778 sp -= csig->param_count;
2779 o = ves_array_create (context->domain, newobj_class, csig, sp);
2780 goto array_constructed;
2783 g_assert (csig->hasthis);
2784 if (csig->param_count) {
2785 sp -= csig->param_count;
2786 memmove (sp + 1, sp, csig->param_count * sizeof (stackval));
2788 child_frame.stack_args = sp;
2791 * First arg is the object.
2793 if (newobj_class->valuetype) {
2794 MonoType *t = &newobj_class->byval_arg;
2795 if (!newobj_class->enumtype && (t->type == MONO_TYPE_VALUETYPE || (t->type == MONO_TYPE_GENERICINST && mono_type_generic_inst_is_valuetype (t)))) {
2797 valuetype_this.data.p = vt_sp;
2799 memset (&valuetype_this, 0, sizeof (stackval));
2800 sp->data.p = &valuetype_this;
2803 if (newobj_class != mono_defaults.string_class) {
2804 context->managed_code = 0;
2805 o = mono_object_new_checked (context->domain, newobj_class, &error);
2806 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2807 context->managed_code = 1;
2808 if (*mono_thread_interruption_request_flag ())
2809 mono_thread_interruption_checkpoint ();
2813 child_frame.retval = &retval;
2817 g_assert (csig->call_convention == MONO_CALL_DEFAULT);
2819 child_frame.ip = NULL;
2820 child_frame.ex = NULL;
2822 ves_exec_method_with_context (&child_frame, context);
2824 context->current_frame = frame;
2826 if (child_frame.ex) {
2828 * An exception occurred, need to run finally, fault and catch handlers..
2830 frame->ex = child_frame.ex;
2831 goto handle_finally;
2834 * a constructor returns void, but we need to return the object we created
2837 if (newobj_class->valuetype && !newobj_class->enumtype) {
2838 *sp = valuetype_this;
2839 } else if (newobj_class == mono_defaults.string_class) {
2847 MINT_IN_CASE(MINT_CASTCLASS)
2848 c = rtm->data_items [*(guint16 *)(ip + 1)];
2849 if ((o = sp [-1].data.p)) {
2850 MonoObject *isinst_obj = mono_object_isinst_checked (o, c, &error);
2851 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2853 THROW_EX (mono_get_exception_invalid_cast (), ip);
2857 MINT_IN_CASE(MINT_ISINST)
2858 c = rtm->data_items [*(guint16 *)(ip + 1)];
2859 if ((o = sp [-1].data.p)) {
2860 MonoObject *isinst_obj = mono_object_isinst_checked (o, c, &error);
2861 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2863 sp [-1].data.p = NULL;
2867 MINT_IN_CASE(MINT_CONV_R_UN_I4)
2868 sp [-1].data.f = (double)(guint32)sp [-1].data.i;
2871 MINT_IN_CASE(MINT_CONV_R_UN_I8)
2872 sp [-1].data.f = (double)(guint64)sp [-1].data.l;
2875 MINT_IN_CASE(MINT_UNBOX)
2876 c = rtm->data_items[*(guint16 *)(ip + 1)];
2880 THROW_EX (mono_get_exception_null_reference (), ip);
2882 MonoObject *isinst_obj = mono_object_isinst_checked (o, c, &error);
2883 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2884 if (!(isinst_obj || ((o->vtable->klass->rank == 0) && (o->vtable->klass->element_class == c->element_class))))
2885 THROW_EX (mono_get_exception_invalid_cast (), ip);
2887 if (c->byval_arg.type == MONO_TYPE_VALUETYPE && !c->enumtype) {
2888 int size = mono_class_native_size (c, NULL);
2889 sp [-1].data.p = vt_sp;
2890 vt_sp += (size + 7) & ~7;
2892 stackval_from_data (&c->byval_arg, &sp [-1], mono_object_unbox (o), FALSE);
2895 MINT_IN_CASE(MINT_THROW)
2897 frame->ex_handler = NULL;
2899 sp->data.p = mono_get_exception_null_reference ();
2900 THROW_EX ((MonoException *)sp->data.p, ip);
2902 MINT_IN_CASE(MINT_LDFLDA)
2905 THROW_EX (mono_get_exception_null_reference (), ip);
2906 sp[-1].data.p = (char *)o + * (guint16 *)(ip + 1);
2909 MINT_IN_CASE(MINT_CKNULL)
2912 THROW_EX (mono_get_exception_null_reference (), ip);
2916 #define LDFLD(datamem, fieldtype) \
2917 o = sp [-1].data.p; \
2919 THROW_EX (mono_get_exception_null_reference (), ip); \
2920 sp[-1].data.datamem = * (fieldtype *)((char *)o + * (guint16 *)(ip + 1)) ; \
2923 MINT_IN_CASE(MINT_LDFLD_I1) LDFLD(i, gint8); MINT_IN_BREAK;
2924 MINT_IN_CASE(MINT_LDFLD_U1) LDFLD(i, guint8); MINT_IN_BREAK;
2925 MINT_IN_CASE(MINT_LDFLD_I2) LDFLD(i, gint16); MINT_IN_BREAK;
2926 MINT_IN_CASE(MINT_LDFLD_U2) LDFLD(i, guint16); MINT_IN_BREAK;
2927 MINT_IN_CASE(MINT_LDFLD_I4) LDFLD(i, gint32); MINT_IN_BREAK;
2928 MINT_IN_CASE(MINT_LDFLD_I8) LDFLD(l, gint64); MINT_IN_BREAK;
2929 MINT_IN_CASE(MINT_LDFLD_R4) LDFLD(f, float); MINT_IN_BREAK;
2930 MINT_IN_CASE(MINT_LDFLD_R8) LDFLD(f, double); MINT_IN_BREAK;
2931 MINT_IN_CASE(MINT_LDFLD_O) LDFLD(p, gpointer); MINT_IN_BREAK;
2932 MINT_IN_CASE(MINT_LDFLD_P) LDFLD(p, gpointer); MINT_IN_BREAK;
2934 MINT_IN_CASE(MINT_LDFLD_VT)
2937 THROW_EX (mono_get_exception_null_reference (), ip);
2938 i32 = READ32(ip + 2);
2939 sp [-1].data.p = vt_sp;
2940 memcpy(sp [-1].data.p, (char *)o + * (guint16 *)(ip + 1), i32);
2941 vt_sp += (i32 + 7) & ~7;
2945 MINT_IN_CASE(MINT_LDRMFLD) {
2947 MonoClassField *field;
2952 THROW_EX (mono_get_exception_null_reference (), ip);
2953 field = rtm->data_items[* (guint16 *)(ip + 1)];
2955 if (mono_object_is_transparent_proxy (o)) {
2956 MonoClass *klass = ((MonoTransparentProxy*)o)->remote_class->proxy_class;
2958 addr = mono_load_remote_field_checked (o, klass, field, &tmp, &error);
2959 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2961 addr = (char*)o + field->offset;
2964 stackval_from_data (field->type, &sp [-1], addr, FALSE);
2968 MINT_IN_CASE(MINT_LDRMFLD_VT) {
2969 MonoClassField *field;
2975 THROW_EX (mono_get_exception_null_reference (), ip);
2976 field = rtm->data_items[* (guint16 *)(ip + 1)];
2977 i32 = READ32(ip + 2);
2979 if (mono_object_is_transparent_proxy (o)) {
2980 MonoClass *klass = ((MonoTransparentProxy*)o)->remote_class->proxy_class;
2981 addr = mono_load_remote_field_checked (o, klass, field, &tmp, &error);
2982 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2984 addr = (char*)o + field->offset;
2987 sp [-1].data.p = vt_sp;
2988 memcpy(sp [-1].data.p, (char *)o + * (guint16 *)(ip + 1), i32);
2989 vt_sp += (i32 + 7) & ~7;
2990 memcpy(sp [-1].data.p, addr, i32);
2994 #define STFLD(datamem, fieldtype) \
2995 o = sp [-2].data.p; \
2997 THROW_EX (mono_get_exception_null_reference (), ip); \
2999 * (fieldtype *)((char *)o + * (guint16 *)(ip + 1)) = sp[1].data.datamem; \
3002 MINT_IN_CASE(MINT_STFLD_I1) STFLD(i, gint8); MINT_IN_BREAK;
3003 MINT_IN_CASE(MINT_STFLD_U1) STFLD(i, guint8); MINT_IN_BREAK;
3004 MINT_IN_CASE(MINT_STFLD_I2) STFLD(i, gint16); MINT_IN_BREAK;
3005 MINT_IN_CASE(MINT_STFLD_U2) STFLD(i, guint16); MINT_IN_BREAK;
3006 MINT_IN_CASE(MINT_STFLD_I4) STFLD(i, gint32); MINT_IN_BREAK;
3007 MINT_IN_CASE(MINT_STFLD_I8) STFLD(l, gint64); MINT_IN_BREAK;
3008 MINT_IN_CASE(MINT_STFLD_R4) STFLD(f, float); MINT_IN_BREAK;
3009 MINT_IN_CASE(MINT_STFLD_R8) STFLD(f, double); MINT_IN_BREAK;
3010 MINT_IN_CASE(MINT_STFLD_O) STFLD(p, gpointer); MINT_IN_BREAK;
3011 MINT_IN_CASE(MINT_STFLD_P) STFLD(p, gpointer); MINT_IN_BREAK;
3013 MINT_IN_CASE(MINT_STFLD_VT)
3016 THROW_EX (mono_get_exception_null_reference (), ip);
3017 i32 = READ32(ip + 2);
3019 memcpy((char *)o + * (guint16 *)(ip + 1), sp [1].data.p, i32);
3020 vt_sp -= (i32 + 7) & ~7;
3024 MINT_IN_CASE(MINT_STRMFLD) {
3025 MonoClassField *field;
3029 THROW_EX (mono_get_exception_null_reference (), ip);
3031 field = rtm->data_items[* (guint16 *)(ip + 1)];
3034 if (mono_object_is_transparent_proxy (o)) {
3035 MonoClass *klass = ((MonoTransparentProxy*)o)->remote_class->proxy_class;
3036 mono_store_remote_field_checked (o, klass, field, &sp [-1].data, &error);
3037 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3039 stackval_to_data (field->type, &sp [-1], (char*)o + field->offset, FALSE);
3044 MINT_IN_CASE(MINT_STRMFLD_VT) {
3045 MonoClassField *field;
3049 THROW_EX (mono_get_exception_null_reference (), ip);
3050 field = rtm->data_items[* (guint16 *)(ip + 1)];
3051 i32 = READ32(ip + 2);
3054 if (mono_object_is_transparent_proxy (o)) {
3055 MonoClass *klass = ((MonoTransparentProxy*)o)->remote_class->proxy_class;
3056 mono_store_remote_field_checked (o, klass, field, &sp [-1].data, &error);
3057 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3059 memcpy((char*)o + field->offset, sp [-1].data.p, i32);
3062 vt_sp -= (i32 + 7) & ~7;
3065 MINT_IN_CASE(MINT_LDSFLDA) {
3066 MonoClassField *field = rtm->data_items[*(guint16 *)(ip + 1)];
3067 sp->data.p = mono_class_static_field_address (context->domain, field);
3072 MINT_IN_CASE(MINT_LDSFLD) {
3073 MonoClassField *field = rtm->data_items [* (guint16 *)(ip + 1)];
3074 gpointer addr = mono_class_static_field_address (context->domain, field);
3075 stackval_from_data (field->type, sp, addr, FALSE);
3080 MINT_IN_CASE(MINT_LDSFLD_VT) {
3081 MonoClassField *field = rtm->data_items [* (guint16 *)(ip + 1)];
3082 gpointer addr = mono_class_static_field_address (context->domain, field);
3083 int size = READ32 (ip + 2);
3087 vt_sp += (size + 7) & ~7;
3088 stackval_from_data (field->type, sp, addr, FALSE);
3092 MINT_IN_CASE(MINT_STSFLD) {
3093 MonoClassField *field = rtm->data_items [* (guint16 *)(ip + 1)];
3094 gpointer addr = mono_class_static_field_address (context->domain, field);
3097 stackval_to_data (field->type, sp, addr, FALSE);
3100 MINT_IN_CASE(MINT_STSFLD_VT) {
3101 MonoClassField *field = rtm->data_items [* (guint16 *)(ip + 1)];
3102 gpointer addr = mono_class_static_field_address (context->domain, field);
3103 int size = READ32 (ip + 2);
3107 stackval_to_data (field->type, sp, addr, FALSE);
3108 vt_sp -= (size + 7) & ~7;
3111 MINT_IN_CASE(MINT_STOBJ_VT) {
3113 c = rtm->data_items[* (guint16 *)(ip + 1)];
3115 size = mono_class_value_size (c, NULL);
3116 memcpy(sp [-2].data.p, sp [-1].data.p, size);
3117 vt_sp -= (size + 7) & ~7;
3121 MINT_IN_CASE(MINT_STOBJ) {
3123 c = rtm->data_items[* (guint16 *)(ip + 1)];
3125 size = mono_class_value_size (c, NULL);
3126 memcpy(sp [-2].data.p, &sp [-1].data, size);
3130 MINT_IN_CASE(MINT_CONV_OVF_I4_UN_R8)
3131 if (sp [-1].data.f < 0 || sp [-1].data.f > MYGUINT32_MAX)
3132 THROW_EX (mono_get_exception_overflow (), ip);
3133 sp [-1].data.i = (guint32)sp [-1].data.f;
3136 MINT_IN_CASE(MINT_CONV_OVF_U8_I4)
3137 if (sp [-1].data.i < 0)
3138 THROW_EX (mono_get_exception_overflow (), ip);
3139 sp [-1].data.l = sp [-1].data.i;
3142 MINT_IN_CASE(MINT_CONV_OVF_U8_R8)
3143 MINT_IN_CASE(MINT_CONV_OVF_I8_UN_R8)
3144 if (sp [-1].data.f < 0 || sp [-1].data.f > 9223372036854775807LL)
3145 THROW_EX (mono_get_exception_overflow (), ip);
3146 sp [-1].data.l = (guint64)sp [-1].data.f;
3149 MINT_IN_CASE(MINT_CONV_OVF_I8_R8)
3150 if (sp [-1].data.f < MYGINT64_MIN || sp [-1].data.f > MYGINT64_MAX)
3151 THROW_EX (mono_get_exception_overflow (), ip);
3152 sp [-1].data.l = (gint64)sp [-1].data.f;
3155 MINT_IN_CASE(MINT_CONV_OVF_I4_UN_I8)
3156 if ((mono_u)sp [-1].data.l > MYGUINT32_MAX)
3157 THROW_EX (mono_get_exception_overflow (), ip);
3158 sp [-1].data.i = (mono_u)sp [-1].data.l;
3161 MINT_IN_CASE(MINT_BOX) {
3162 c = rtm->data_items [* (guint16 *)(ip + 1)];
3163 guint16 offset = * (guint16 *)(ip + 2);
3165 if (c->byval_arg.type == MONO_TYPE_VALUETYPE && !c->enumtype) {
3166 int size = mono_class_value_size (c, NULL);
3167 sp [-1 - offset].data.p = mono_value_box_checked (context->domain, c, sp [-1 - offset].data.p, &error);
3168 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3169 size = (size + 7) & ~7;
3172 stackval_to_data (&c->byval_arg, &sp [-1 - offset], (char *) &sp [-1 - offset], FALSE);
3173 sp [-1 - offset].data.p = mono_value_box_checked (context->domain, c, &sp [-1 - offset], &error);
3174 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3179 MINT_IN_CASE(MINT_NEWARR)
3180 sp [-1].data.p = (MonoObject*) mono_array_new_checked (context->domain, rtm->data_items[*(guint16 *)(ip + 1)], sp [-1].data.i, &error);
3181 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3183 /*if (profiling_classes) {
3184 guint count = GPOINTER_TO_UINT (g_hash_table_lookup (profiling_classes, o->vtable->klass));
3186 g_hash_table_insert (profiling_classes, o->vtable->klass, GUINT_TO_POINTER (count));
3190 MINT_IN_CASE(MINT_LDLEN)
3193 THROW_EX (mono_get_exception_null_reference (), ip);
3194 sp [-1].data.nati = mono_array_length ((MonoArray *)o);
3197 MINT_IN_CASE(MINT_GETCHR) {
3201 THROW_EX (mono_get_exception_null_reference (), ip);
3202 i32 = sp [-1].data.i;
3203 if (i32 < 0 || i32 >= mono_string_length (s))
3204 THROW_EX (mono_get_exception_index_out_of_range (), ip);
3206 sp [-1].data.i = mono_string_chars(s)[i32];
3210 MINT_IN_CASE(MINT_STRLEN)
3212 sp [-1].data.i = mono_string_length ((MonoString*)sp [-1].data.p);
3214 MINT_IN_CASE(MINT_ARRAY_RANK)
3217 THROW_EX (mono_get_exception_null_reference (), ip);
3218 sp [-1].data.i = mono_object_class (sp [-1].data.p)->rank;
3221 MINT_IN_CASE(MINT_LDELEMA) {
3225 /*token = READ32 (ip)*/;
3231 aindex = sp [1].data.i;
3232 if (aindex >= mono_array_length ((MonoArray *) o))
3233 THROW_EX (mono_get_exception_index_out_of_range (), ip - 2);
3235 /* check the array element corresponds to token */
3236 esize = mono_array_element_size (((MonoArray *) o)->obj.vtable->klass);
3238 sp->data.p = mono_array_addr_with_size ((MonoArray *) o, esize, aindex);
3242 MINT_IN_CASE(MINT_LDELEM_I1) /* fall through */
3243 MINT_IN_CASE(MINT_LDELEM_U1) /* fall through */
3244 MINT_IN_CASE(MINT_LDELEM_I2) /* fall through */
3245 MINT_IN_CASE(MINT_LDELEM_U2) /* fall through */
3246 MINT_IN_CASE(MINT_LDELEM_I4) /* fall through */
3247 MINT_IN_CASE(MINT_LDELEM_U4) /* fall through */
3248 MINT_IN_CASE(MINT_LDELEM_I8) /* fall through */
3249 MINT_IN_CASE(MINT_LDELEM_I) /* fall through */
3250 MINT_IN_CASE(MINT_LDELEM_R4) /* fall through */
3251 MINT_IN_CASE(MINT_LDELEM_R8) /* fall through */
3252 MINT_IN_CASE(MINT_LDELEM_REF) /* fall through */
3253 MINT_IN_CASE(MINT_LDELEM_VT) {
3261 THROW_EX (mono_get_exception_null_reference (), ip);
3263 aindex = sp [1].data.i;
3264 if (aindex >= mono_array_length (o))
3265 THROW_EX (mono_get_exception_index_out_of_range (), ip);
3268 * FIXME: throw mono_get_exception_array_type_mismatch () if needed
3271 case MINT_LDELEM_I1:
3272 sp [0].data.i = mono_array_get (o, gint8, aindex);
3274 case MINT_LDELEM_U1:
3275 sp [0].data.i = mono_array_get (o, guint8, aindex);
3277 case MINT_LDELEM_I2:
3278 sp [0].data.i = mono_array_get (o, gint16, aindex);
3280 case MINT_LDELEM_U2:
3281 sp [0].data.i = mono_array_get (o, guint16, aindex);
3284 sp [0].data.nati = mono_array_get (o, mono_i, aindex);
3286 case MINT_LDELEM_I4:
3287 sp [0].data.i = mono_array_get (o, gint32, aindex);
3289 case MINT_LDELEM_U4:
3290 sp [0].data.i = mono_array_get (o, guint32, aindex);
3292 case MINT_LDELEM_I8:
3293 sp [0].data.l = mono_array_get (o, guint64, aindex);
3295 case MINT_LDELEM_R4:
3296 sp [0].data.f = mono_array_get (o, float, aindex);
3298 case MINT_LDELEM_R8:
3299 sp [0].data.f = mono_array_get (o, double, aindex);
3301 case MINT_LDELEM_REF:
3302 sp [0].data.p = mono_array_get (o, gpointer, aindex);
3304 case MINT_LDELEM_VT: {
3305 MonoClass *klass_vt = rtm->data_items [*(guint16 *) (ip + 1)];
3306 i32 = READ32 (ip + 2);
3307 char *src_addr = mono_array_addr_with_size ((MonoArray *) o, i32, aindex);
3308 sp [0].data.vt = vt_sp;
3309 stackval_from_data (&klass_vt->byval_arg, sp, src_addr, FALSE);
3310 vt_sp += (i32 + 7) & ~7;
3322 MINT_IN_CASE(MINT_STELEM_I) /* fall through */
3323 MINT_IN_CASE(MINT_STELEM_I1) /* fall through */
3324 MINT_IN_CASE(MINT_STELEM_I2) /* fall through */
3325 MINT_IN_CASE(MINT_STELEM_I4) /* fall through */
3326 MINT_IN_CASE(MINT_STELEM_I8) /* fall through */
3327 MINT_IN_CASE(MINT_STELEM_R4) /* fall through */
3328 MINT_IN_CASE(MINT_STELEM_R8) /* fall through */
3329 MINT_IN_CASE(MINT_STELEM_REF) /* fall through */
3330 MINT_IN_CASE(MINT_STELEM_VT) {
3337 THROW_EX (mono_get_exception_null_reference (), ip);
3339 aindex = sp [1].data.i;
3340 if (aindex >= mono_array_length ((MonoArray *)o))
3341 THROW_EX (mono_get_exception_index_out_of_range (), ip);
3345 mono_array_set ((MonoArray *)o, mono_i, aindex, sp [2].data.nati);
3347 case MINT_STELEM_I1:
3348 mono_array_set ((MonoArray *)o, gint8, aindex, sp [2].data.i);
3350 case MINT_STELEM_I2:
3351 mono_array_set ((MonoArray *)o, gint16, aindex, sp [2].data.i);
3353 case MINT_STELEM_I4:
3354 mono_array_set ((MonoArray *)o, gint32, aindex, sp [2].data.i);
3356 case MINT_STELEM_I8:
3357 mono_array_set ((MonoArray *)o, gint64, aindex, sp [2].data.l);
3359 case MINT_STELEM_R4:
3360 mono_array_set ((MonoArray *)o, float, aindex, sp [2].data.f);
3362 case MINT_STELEM_R8:
3363 mono_array_set ((MonoArray *)o, double, aindex, sp [2].data.f);
3365 case MINT_STELEM_REF: {
3366 MonoObject *isinst_obj = mono_object_isinst_checked (sp [2].data.p, mono_object_class (o)->element_class, &error);
3367 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3368 if (sp [2].data.p && !isinst_obj)
3369 THROW_EX (mono_get_exception_array_type_mismatch (), ip);
3370 mono_array_set ((MonoArray *)o, gpointer, aindex, sp [2].data.p);
3373 case MINT_STELEM_VT: {
3374 MonoClass *klass_vt = rtm->data_items [*(guint16 *) (ip + 1)];
3375 i32 = READ32 (ip + 2);
3376 char *dst_addr = mono_array_addr_with_size ((MonoArray *) o, i32, aindex);
3378 stackval_to_data (&klass_vt->byval_arg, &sp [2], dst_addr, FALSE);
3379 vt_sp -= (i32 + 7) & ~7;
3390 MINT_IN_CASE(MINT_CONV_OVF_I4_U4)
3391 if (sp [-1].data.i < 0)
3392 THROW_EX (mono_get_exception_overflow (), ip);
3395 MINT_IN_CASE(MINT_CONV_OVF_I4_I8)
3396 if (sp [-1].data.l < MYGINT32_MIN || sp [-1].data.l > MYGINT32_MAX)
3397 THROW_EX (mono_get_exception_overflow (), ip);
3398 sp [-1].data.i = (gint32) sp [-1].data.l;
3401 MINT_IN_CASE(MINT_CONV_OVF_I4_R8)
3402 if (sp [-1].data.f < MYGINT32_MIN || sp [-1].data.f > MYGINT32_MAX)
3403 THROW_EX (mono_get_exception_overflow (), ip);
3404 sp [-1].data.i = (gint32) sp [-1].data.f;
3407 MINT_IN_CASE(MINT_CONV_OVF_U4_I4)
3408 if (sp [-1].data.i < 0)
3409 THROW_EX (mono_get_exception_overflow (), ip);
3412 MINT_IN_CASE(MINT_CONV_OVF_U4_I8)
3413 if (sp [-1].data.l < 0 || sp [-1].data.l > MYGUINT32_MAX)
3414 THROW_EX (mono_get_exception_overflow (), ip);
3415 sp [-1].data.i = (guint32) sp [-1].data.l;
3418 MINT_IN_CASE(MINT_CONV_OVF_U4_R8)
3419 if (sp [-1].data.f < 0 || sp [-1].data.f > MYGUINT32_MAX)
3420 THROW_EX (mono_get_exception_overflow (), ip);
3421 sp [-1].data.i = (guint32) sp [-1].data.f;
3424 MINT_IN_CASE(MINT_CONV_OVF_I2_I4)
3425 if (sp [-1].data.i < -32768 || sp [-1].data.i > 32767)
3426 THROW_EX (mono_get_exception_overflow (), ip);
3429 MINT_IN_CASE(MINT_CONV_OVF_I2_I8)
3430 if (sp [-1].data.l < -32768 || sp [-1].data.l > 32767)
3431 THROW_EX (mono_get_exception_overflow (), ip);
3432 sp [-1].data.i = (gint16) sp [-1].data.l;
3435 MINT_IN_CASE(MINT_CONV_OVF_I2_R8)
3436 if (sp [-1].data.f < -32768 || sp [-1].data.f > 32767)
3437 THROW_EX (mono_get_exception_overflow (), ip);
3438 sp [-1].data.i = (gint16) sp [-1].data.f;
3441 MINT_IN_CASE(MINT_CONV_OVF_U2_I4)
3442 if (sp [-1].data.i < 0 || sp [-1].data.i > 65535)
3443 THROW_EX (mono_get_exception_overflow (), ip);
3446 MINT_IN_CASE(MINT_CONV_OVF_U2_I8)
3447 if (sp [-1].data.l < 0 || sp [-1].data.l > 65535)
3448 THROW_EX (mono_get_exception_overflow (), ip);
3449 sp [-1].data.i = (guint16) sp [-1].data.l;
3452 MINT_IN_CASE(MINT_CONV_OVF_U2_R8)
3453 if (sp [-1].data.f < 0 || sp [-1].data.f > 65535)
3454 THROW_EX (mono_get_exception_overflow (), ip);
3455 sp [-1].data.i = (guint16) sp [-1].data.f;
3458 MINT_IN_CASE(MINT_CONV_OVF_I1_I4)
3459 if (sp [-1].data.i < -128 || sp [-1].data.i > 127)
3460 THROW_EX (mono_get_exception_overflow (), ip);
3463 MINT_IN_CASE(MINT_CONV_OVF_I1_I8)
3464 if (sp [-1].data.l < -128 || sp [-1].data.l > 127)
3465 THROW_EX (mono_get_exception_overflow (), ip);
3466 sp [-1].data.i = (gint8) sp [-1].data.l;
3469 MINT_IN_CASE(MINT_CONV_OVF_I1_R8)
3470 if (sp [-1].data.f < -128 || sp [-1].data.f > 127)
3471 THROW_EX (mono_get_exception_overflow (), ip);
3472 sp [-1].data.i = (gint8) sp [-1].data.f;
3475 MINT_IN_CASE(MINT_CONV_OVF_U1_I4)
3476 if (sp [-1].data.i < 0 || sp [-1].data.i > 255)
3477 THROW_EX (mono_get_exception_overflow (), ip);
3480 MINT_IN_CASE(MINT_CONV_OVF_U1_I8)
3481 if (sp [-1].data.l < 0 || sp [-1].data.l > 255)
3482 THROW_EX (mono_get_exception_overflow (), ip);
3483 sp [-1].data.i = (guint8) sp [-1].data.l;
3486 MINT_IN_CASE(MINT_CONV_OVF_U1_R8)
3487 if (sp [-1].data.f < 0 || sp [-1].data.f > 255)
3488 THROW_EX (mono_get_exception_overflow (), ip);
3489 sp [-1].data.i = (guint8) sp [-1].data.f;
3493 MINT_IN_CASE(MINT_LDELEM)
3494 MINT_IN_CASE(MINT_STELEM)
3495 MINT_IN_CASE(MINT_UNBOX_ANY)
3497 MINT_IN_CASE(MINT_REFANYVAL) ves_abort(); MINT_IN_BREAK;
3499 MINT_IN_CASE(MINT_CKFINITE)
3500 if (!isfinite(sp [-1].data.f))
3501 THROW_EX (mono_get_exception_arithmetic (), ip);
3505 MINT_IN_CASE(MINT_MKREFANY) ves_abort(); MINT_IN_BREAK;
3507 MINT_IN_CASE(MINT_LDTOKEN)
3510 * (gpointer *)sp->data.p = rtm->data_items[*(guint16 *)(ip + 1)];
3514 MINT_IN_CASE(MINT_ADD_OVF_I4)
3515 if (CHECK_ADD_OVERFLOW (sp [-2].data.i, sp [-1].data.i))
3516 THROW_EX (mono_get_exception_overflow (), ip);
3519 MINT_IN_CASE(MINT_ADD_OVF_I8)
3520 if (CHECK_ADD_OVERFLOW64 (sp [-2].data.l, sp [-1].data.l))
3521 THROW_EX (mono_get_exception_overflow (), ip);
3524 MINT_IN_CASE(MINT_ADD_OVF_UN_I4)
3525 if (CHECK_ADD_OVERFLOW_UN (sp [-2].data.i, sp [-1].data.i))
3526 THROW_EX (mono_get_exception_overflow (), ip);
3527 BINOP_CAST(i, +, guint32);
3529 MINT_IN_CASE(MINT_ADD_OVF_UN_I8)
3530 if (CHECK_ADD_OVERFLOW64_UN (sp [-2].data.l, sp [-1].data.l))
3531 THROW_EX (mono_get_exception_overflow (), ip);
3532 BINOP_CAST(l, +, guint64);
3534 MINT_IN_CASE(MINT_MUL_OVF_I4)
3535 if (CHECK_MUL_OVERFLOW (sp [-2].data.i, sp [-1].data.i))
3536 THROW_EX (mono_get_exception_overflow (), ip);
3539 MINT_IN_CASE(MINT_MUL_OVF_I8)
3540 if (CHECK_MUL_OVERFLOW64 (sp [-2].data.l, sp [-1].data.l))
3541 THROW_EX (mono_get_exception_overflow (), ip);
3544 MINT_IN_CASE(MINT_MUL_OVF_UN_I4)
3545 if (CHECK_MUL_OVERFLOW_UN (sp [-2].data.i, sp [-1].data.i))
3546 THROW_EX (mono_get_exception_overflow (), ip);
3547 BINOP_CAST(i, *, guint32);
3549 MINT_IN_CASE(MINT_MUL_OVF_UN_I8)
3550 if (CHECK_MUL_OVERFLOW64_UN (sp [-2].data.l, sp [-1].data.l))
3551 THROW_EX (mono_get_exception_overflow (), ip);
3552 BINOP_CAST(l, *, guint64);
3554 MINT_IN_CASE(MINT_SUB_OVF_I4)
3555 if (CHECK_SUB_OVERFLOW (sp [-2].data.i, sp [-1].data.i))
3556 THROW_EX (mono_get_exception_overflow (), ip);
3559 MINT_IN_CASE(MINT_SUB_OVF_I8)
3560 if (CHECK_SUB_OVERFLOW64 (sp [-2].data.l, sp [-1].data.l))
3561 THROW_EX (mono_get_exception_overflow (), ip);
3564 MINT_IN_CASE(MINT_SUB_OVF_UN_I4)
3565 if (CHECK_SUB_OVERFLOW_UN (sp [-2].data.i, sp [-1].data.i))
3566 THROW_EX (mono_get_exception_overflow (), ip);
3567 BINOP_CAST(i, -, guint32);
3569 MINT_IN_CASE(MINT_SUB_OVF_UN_I8)
3570 if (CHECK_SUB_OVERFLOW64_UN (sp [-2].data.l, sp [-1].data.l))
3571 THROW_EX (mono_get_exception_overflow (), ip);
3572 BINOP_CAST(l, -, guint64);
3574 MINT_IN_CASE(MINT_ENDFINALLY)
3576 ip = finally_ips->data;
3577 finally_ips = g_slist_remove (finally_ips, ip);
3584 MINT_IN_CASE(MINT_LEAVE) /* Fall through */
3585 MINT_IN_CASE(MINT_LEAVE_S)
3586 while (sp > frame->stack) {
3590 if (*ip == MINT_LEAVE_S) {
3591 ip += (short) *(ip + 1);
3593 ip += (gint32) READ32 (ip + 1);
3596 if (frame->ex_handler != NULL && MONO_OFFSET_IN_HANDLER(frame->ex_handler, frame->ip - rtm->code)) {
3597 frame->ex_handler = NULL;
3600 goto handle_finally;
3602 MINT_IN_CASE(MINT_ICALL_V_V)
3603 MINT_IN_CASE(MINT_ICALL_V_P)
3604 MINT_IN_CASE(MINT_ICALL_P_V)
3605 MINT_IN_CASE(MINT_ICALL_P_P)
3606 MINT_IN_CASE(MINT_ICALL_PP_V)
3607 MINT_IN_CASE(MINT_ICALL_PI_V)
3608 MINT_IN_CASE(MINT_ICALL_PP_P)
3609 MINT_IN_CASE(MINT_ICALL_PI_P)
3610 MINT_IN_CASE(MINT_ICALL_PPP_V)
3611 MINT_IN_CASE(MINT_ICALL_PPI_V)
3612 sp = do_icall (context, *ip, sp, rtm->data_items [*(guint16 *)(ip + 1)]);
3613 if (frame->ex != NULL)
3614 goto handle_exception;
3617 MINT_IN_CASE(MINT_MONO_LDPTR)
3618 sp->data.p = rtm->data_items [*(guint16 *)(ip + 1)];
3622 MINT_IN_CASE(MINT_MONO_NEWOBJ)
3623 sp->data.p = mono_object_new_checked (context->domain, rtm->data_items [*(guint16 *)(ip + 1)], &error);
3624 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3628 MINT_IN_CASE(MINT_MONO_FREE)
3631 g_error ("that doesn't seem right");
3632 g_free (sp->data.p);
3634 MINT_IN_CASE(MINT_MONO_RETOBJ)
3637 stackval_from_data (mono_method_signature (frame->runtime_method->method)->ret, frame->retval, sp->data.p,
3638 mono_method_signature (frame->runtime_method->method)->pinvoke);
3639 if (sp > frame->stack)
3640 g_warning ("retobj: more values on stack: %d", sp-frame->stack);
3643 #define RELOP(datamem, op) \
3645 sp [-1].data.i = sp [-1].data.datamem op sp [0].data.datamem; \
3647 MINT_IN_CASE(MINT_CEQ_I4)
3650 MINT_IN_CASE(MINT_CEQ0_I4)
3651 sp [-1].data.i = (sp [-1].data.i == 0);
3654 MINT_IN_CASE(MINT_CEQ_I8)
3657 MINT_IN_CASE(MINT_CEQ_R8)
3659 if (isunordered (sp [-1].data.f, sp [0].data.f))
3662 sp [-1].data.i = sp [-1].data.f == sp [0].data.f;
3665 MINT_IN_CASE(MINT_CGT_I4)
3668 MINT_IN_CASE(MINT_CGT_I8)
3671 MINT_IN_CASE(MINT_CGT_R8)
3673 if (isunordered (sp [-1].data.f, sp [0].data.f))
3676 sp [-1].data.i = sp [-1].data.f > sp [0].data.f;
3680 #define RELOP_CAST(datamem, op, type) \
3682 sp [-1].data.i = (type)sp [-1].data.datamem op (type)sp [0].data.datamem; \
3685 MINT_IN_CASE(MINT_CGT_UN_I4)
3686 RELOP_CAST(i, >, guint32);
3688 MINT_IN_CASE(MINT_CGT_UN_I8)
3689 RELOP_CAST(l, >, guint64);
3691 MINT_IN_CASE(MINT_CGT_UN_R8)
3693 if (isunordered (sp [-1].data.f, sp [0].data.f))
3696 sp [-1].data.i = sp [-1].data.f > sp [0].data.f;
3699 MINT_IN_CASE(MINT_CLT_I4)
3702 MINT_IN_CASE(MINT_CLT_I8)
3705 MINT_IN_CASE(MINT_CLT_R8)
3707 if (isunordered (sp [-1].data.f, sp [0].data.f))
3710 sp [-1].data.i = sp [-1].data.f < sp [0].data.f;
3713 MINT_IN_CASE(MINT_CLT_UN_I4)
3714 RELOP_CAST(i, <, guint32);
3716 MINT_IN_CASE(MINT_CLT_UN_I8)
3717 RELOP_CAST(l, <, guint64);
3719 MINT_IN_CASE(MINT_CLT_UN_R8)
3721 if (isunordered (sp [-1].data.f, sp [0].data.f))
3724 sp [-1].data.i = sp [-1].data.f < sp [0].data.f;
3727 MINT_IN_CASE(MINT_LDFTN) {
3728 sp->data.p = rtm->data_items [* (guint16 *)(ip + 1)];
3733 MINT_IN_CASE(MINT_LDVIRTFTN) {
3734 RuntimeMethod *m = rtm->data_items [* (guint16 *)(ip + 1)];
3738 THROW_EX (mono_get_exception_null_reference (), ip - 2);
3740 sp->data.p = get_virtual_method (context->domain, m, sp->data.p);
3745 MINT_IN_CASE(MINT_LDTHISA)
3746 g_error ("should not happen");
3747 // sp->data.p = &frame->obj;
3752 #define LDARG(datamem, argtype) \
3753 sp->data.datamem = * (argtype *)(frame->args + * (guint16 *)(ip + 1)); \
3757 MINT_IN_CASE(MINT_LDARG_I1) LDARG(i, gint8); MINT_IN_BREAK;
3758 MINT_IN_CASE(MINT_LDARG_U1) LDARG(i, guint8); MINT_IN_BREAK;
3759 MINT_IN_CASE(MINT_LDARG_I2) LDARG(i, gint16); MINT_IN_BREAK;
3760 MINT_IN_CASE(MINT_LDARG_U2) LDARG(i, guint16); MINT_IN_BREAK;
3761 MINT_IN_CASE(MINT_LDARG_I4) LDARG(i, gint32); MINT_IN_BREAK;
3762 MINT_IN_CASE(MINT_LDARG_I8) LDARG(l, gint64); MINT_IN_BREAK;
3763 MINT_IN_CASE(MINT_LDARG_R4) LDARG(f, float); MINT_IN_BREAK;
3764 MINT_IN_CASE(MINT_LDARG_R8) LDARG(f, double); MINT_IN_BREAK;
3765 MINT_IN_CASE(MINT_LDARG_O) LDARG(p, gpointer); MINT_IN_BREAK;
3766 MINT_IN_CASE(MINT_LDARG_P) LDARG(p, gpointer); MINT_IN_BREAK;
3768 MINT_IN_CASE(MINT_LDARG_VT)
3770 i32 = READ32(ip + 2);
3771 memcpy(sp->data.p, frame->args + * (guint16 *)(ip + 1), i32);
3772 vt_sp += (i32 + 7) & ~7;
3777 #define STARG(datamem, argtype) \
3779 * (argtype *)(frame->args + * (guint16 *)(ip + 1)) = sp->data.datamem; \
3782 MINT_IN_CASE(MINT_STARG_I1) STARG(i, gint8); MINT_IN_BREAK;
3783 MINT_IN_CASE(MINT_STARG_U1) STARG(i, guint8); MINT_IN_BREAK;
3784 MINT_IN_CASE(MINT_STARG_I2) STARG(i, gint16); MINT_IN_BREAK;
3785 MINT_IN_CASE(MINT_STARG_U2) STARG(i, guint16); MINT_IN_BREAK;
3786 MINT_IN_CASE(MINT_STARG_I4) STARG(i, gint32); MINT_IN_BREAK;
3787 MINT_IN_CASE(MINT_STARG_I8) STARG(l, gint64); MINT_IN_BREAK;
3788 MINT_IN_CASE(MINT_STARG_R4) STARG(f, float); MINT_IN_BREAK;
3789 MINT_IN_CASE(MINT_STARG_R8) STARG(f, double); MINT_IN_BREAK;
3790 MINT_IN_CASE(MINT_STARG_O) STARG(p, gpointer); MINT_IN_BREAK;
3791 MINT_IN_CASE(MINT_STARG_P) STARG(p, gpointer); MINT_IN_BREAK;
3793 MINT_IN_CASE(MINT_STARG_VT)
3794 i32 = READ32(ip + 2);
3796 memcpy(frame->args + * (guint16 *)(ip + 1), sp->data.p, i32);
3797 vt_sp -= (i32 + 7) & ~7;
3801 #define STINARG(datamem, argtype) \
3803 int n = * (guint16 *)(ip + 1); \
3804 * (argtype *)(frame->args + rtm->arg_offsets [n]) = frame->stack_args [n].data.datamem; \
3808 MINT_IN_CASE(MINT_STINARG_I1) STINARG(i, gint8); MINT_IN_BREAK;
3809 MINT_IN_CASE(MINT_STINARG_U1) STINARG(i, guint8); MINT_IN_BREAK;
3810 MINT_IN_CASE(MINT_STINARG_I2) STINARG(i, gint16); MINT_IN_BREAK;
3811 MINT_IN_CASE(MINT_STINARG_U2) STINARG(i, guint16); MINT_IN_BREAK;
3812 MINT_IN_CASE(MINT_STINARG_I4) STINARG(i, gint32); MINT_IN_BREAK;
3813 MINT_IN_CASE(MINT_STINARG_I8) STINARG(l, gint64); MINT_IN_BREAK;
3814 MINT_IN_CASE(MINT_STINARG_R4) STINARG(f, float); MINT_IN_BREAK;
3815 MINT_IN_CASE(MINT_STINARG_R8) STINARG(f, double); MINT_IN_BREAK;
3816 MINT_IN_CASE(MINT_STINARG_O) STINARG(p, gpointer); MINT_IN_BREAK;
3817 MINT_IN_CASE(MINT_STINARG_P) STINARG(p, gpointer); MINT_IN_BREAK;
3819 MINT_IN_CASE(MINT_STINARG_VT) {
3820 int n = * (guint16 *)(ip + 1);
3821 i32 = READ32(ip + 2);
3822 memcpy (frame->args + rtm->arg_offsets [n], frame->stack_args [n].data.p, i32);
3827 MINT_IN_CASE(MINT_LDARGA)
3828 sp->data.p = frame->args + * (guint16 *)(ip + 1);
3833 #define LDLOC(datamem, argtype) \
3834 sp->data.datamem = * (argtype *)(locals + * (guint16 *)(ip + 1)); \
3838 MINT_IN_CASE(MINT_LDLOC_I1) LDLOC(i, gint8); MINT_IN_BREAK;
3839 MINT_IN_CASE(MINT_LDLOC_U1) LDLOC(i, guint8); MINT_IN_BREAK;
3840 MINT_IN_CASE(MINT_LDLOC_I2) LDLOC(i, gint16); MINT_IN_BREAK;
3841 MINT_IN_CASE(MINT_LDLOC_U2) LDLOC(i, guint16); MINT_IN_BREAK;
3842 MINT_IN_CASE(MINT_LDLOC_I4) LDLOC(i, gint32); MINT_IN_BREAK;
3843 MINT_IN_CASE(MINT_LDLOC_I8) LDLOC(l, gint64); MINT_IN_BREAK;
3844 MINT_IN_CASE(MINT_LDLOC_R4) LDLOC(f, float); MINT_IN_BREAK;
3845 MINT_IN_CASE(MINT_LDLOC_R8) LDLOC(f, double); MINT_IN_BREAK;
3846 MINT_IN_CASE(MINT_LDLOC_O) LDLOC(p, gpointer); MINT_IN_BREAK;
3847 MINT_IN_CASE(MINT_LDLOC_P) LDLOC(p, gpointer); MINT_IN_BREAK;
3849 MINT_IN_CASE(MINT_LDLOC_VT)
3851 i32 = READ32(ip + 2);
3852 memcpy(sp->data.p, locals + * (guint16 *)(ip + 1), i32);
3853 vt_sp += (i32 + 7) & ~7;
3858 MINT_IN_CASE(MINT_LDLOCA_S)
3859 sp->data.p = locals + * (guint16 *)(ip + 1);
3864 #define STLOC(datamem, argtype) \
3866 * (argtype *)(locals + * (guint16 *)(ip + 1)) = sp->data.datamem; \
3869 MINT_IN_CASE(MINT_STLOC_I1) STLOC(i, gint8); MINT_IN_BREAK;
3870 MINT_IN_CASE(MINT_STLOC_U1) STLOC(i, guint8); MINT_IN_BREAK;
3871 MINT_IN_CASE(MINT_STLOC_I2) STLOC(i, gint16); MINT_IN_BREAK;
3872 MINT_IN_CASE(MINT_STLOC_U2) STLOC(i, guint16); MINT_IN_BREAK;
3873 MINT_IN_CASE(MINT_STLOC_I4) STLOC(i, gint32); MINT_IN_BREAK;
3874 MINT_IN_CASE(MINT_STLOC_I8) STLOC(l, gint64); MINT_IN_BREAK;
3875 MINT_IN_CASE(MINT_STLOC_R4) STLOC(f, float); MINT_IN_BREAK;
3876 MINT_IN_CASE(MINT_STLOC_R8) STLOC(f, double); MINT_IN_BREAK;
3877 MINT_IN_CASE(MINT_STLOC_O) STLOC(p, gpointer); MINT_IN_BREAK;
3878 MINT_IN_CASE(MINT_STLOC_P) STLOC(p, gpointer); MINT_IN_BREAK;
3880 #define STLOC_NP(datamem, argtype) \
3881 * (argtype *)(locals + * (guint16 *)(ip + 1)) = sp [-1].data.datamem; \
3884 MINT_IN_CASE(MINT_STLOC_NP_I4) STLOC_NP(i, gint32); MINT_IN_BREAK;
3885 MINT_IN_CASE(MINT_STLOC_NP_O) STLOC_NP(p, gpointer); MINT_IN_BREAK;
3887 MINT_IN_CASE(MINT_STLOC_VT)
3888 i32 = READ32(ip + 2);
3890 memcpy(locals + * (guint16 *)(ip + 1), sp->data.p, i32);
3891 vt_sp -= (i32 + 7) & ~7;
3895 MINT_IN_CASE(MINT_LOCALLOC)
3896 if (sp != frame->stack + 1) /*FIX?*/
3897 THROW_EX (mono_get_exception_execution_engine (NULL), ip);
3898 sp [-1].data.p = alloca (sp [-1].data.i);
3902 MINT_IN_CASE(MINT_ENDFILTER) ves_abort(); MINT_IN_BREAK;
3904 MINT_IN_CASE(MINT_INITOBJ)
3906 memset (sp->data.vt, 0, READ32(ip + 1));
3909 MINT_IN_CASE(MINT_CPBLK)
3911 if (!sp [0].data.p || !sp [1].data.p)
3912 THROW_EX (mono_get_exception_null_reference(), ip - 1);
3914 /* FIXME: value and size may be int64... */
3915 memcpy (sp [0].data.p, sp [1].data.p, sp [2].data.i);
3918 MINT_IN_CASE(MINT_CONSTRAINED_) {
3920 /* FIXME: implement */
3922 token = READ32 (ip);
3927 MINT_IN_CASE(MINT_INITBLK)
3930 THROW_EX (mono_get_exception_null_reference(), ip - 1);
3932 /* FIXME: value and size may be int64... */
3933 memset (sp [0].data.p, sp [1].data.i, sp [2].data.i);
3936 MINT_IN_CASE(MINT_NO_)
3937 /* FIXME: implement */
3941 MINT_IN_CASE(MINT_RETHROW)
3943 * need to clarify what this should actually do:
3944 * start the search from the last found handler in
3945 * this method or continue in the caller or what.
3946 * Also, do we need to run finally/fault handlers after a retrow?
3947 * Well, this implementation will follow the usual search
3948 * for an handler, considering the current ip as throw spot.
3949 * We need to NULL frame->ex_handler for the later code to
3950 * actually run the new found handler.
3952 frame->ex_handler = NULL;
3953 THROW_EX (frame->ex, ip - 1);
3956 g_print ("Unimplemented opcode: %04x %s at 0x%x\n", *ip, mono_interp_opname[*ip], ip-rtm->code);
3957 THROW_EX (mono_get_exception_execution_engine ("Unimplemented opcode"), ip);
3961 g_assert_not_reached ();
3963 * Exception handling code.
3964 * The exception object is stored in frame->ex.
3971 MonoInvocation *inv;
3972 MonoExceptionClause *clause;
3978 g_print ("* Handling exception '%s' at IL_%04x\n",
3979 frame->ex == NULL ? "** Unknown **" : mono_object_class (frame->ex)->name,
3980 rtm == NULL ? 0 : frame->ip - rtm->code);
3982 if (die_on_exception)
3985 for (inv = frame; inv; inv = inv->parent) {
3987 if (inv->runtime_method == NULL)
3989 method = inv->runtime_method->method;
3990 if (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL)
3992 if (method->iflags & (METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL | METHOD_IMPL_ATTRIBUTE_RUNTIME))
3994 if (inv->ip == NULL)
3996 ip_offset = inv->ip - inv->runtime_method->code;
3997 inv->ex_handler = NULL; /* clear this in case we are trhowing an exception while handling one - this one wins */
3998 for (i = 0; i < inv->runtime_method->num_clauses; ++i) {
3999 clause = &inv->runtime_method->clauses [i];
4000 if (clause->flags <= 1 && MONO_OFFSET_IN_CLAUSE (clause, ip_offset)) {
4001 if (!clause->flags) {
4002 MonoObject *isinst_obj = mono_object_isinst_checked ((MonoObject*)frame->ex, clause->data.catch_class, &error);
4003 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4006 * OK, we found an handler, now we need to execute the finally
4007 * and fault blocks before branching to the handler code.
4009 inv->ex_handler = clause;
4012 g_print ("* Found handler at '%s'\n", method->name);
4014 goto handle_finally;
4017 /* FIXME: handle filter clauses */
4024 * If we get here, no handler was found: print a stack trace.
4026 for (inv = frame; inv; inv = inv->parent) {
4027 if (inv->invoke_trap)
4028 goto handle_finally;
4031 ex_obj = (MonoObject*)frame->ex;
4032 mono_unhandled_exception (ex_obj);
4039 MonoExceptionClause *clause;
4040 GSList *old_list = finally_ips;
4041 MonoMethod *method = frame->runtime_method->method;
4042 MonoMethodHeader *header = mono_method_get_header_checked (method, &error);
4043 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4047 g_print ("* Handle finally IL_%04x\n", endfinally_ip == NULL ? 0 : endfinally_ip - rtm->code);
4049 if (rtm == NULL || (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL)
4050 || (method->iflags & (METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL | METHOD_IMPL_ATTRIBUTE_RUNTIME))) {
4053 ip_offset = frame->ip - rtm->code;
4055 if (endfinally_ip != NULL)
4056 finally_ips = g_slist_prepend(finally_ips, (void *)endfinally_ip);
4057 for (i = 0; i < header->num_clauses; ++i)
4058 if (frame->ex_handler == &rtm->clauses [i])
4062 clause = &rtm->clauses [i];
4063 if (MONO_OFFSET_IN_CLAUSE (clause, ip_offset) && (endfinally_ip == NULL || !(MONO_OFFSET_IN_CLAUSE (clause, endfinally_ip - rtm->code)))) {
4064 if (clause->flags == MONO_EXCEPTION_CLAUSE_FINALLY) {
4065 ip = rtm->code + clause->handler_offset;
4066 finally_ips = g_slist_prepend (finally_ips, (gpointer) ip);
4069 g_print ("* Found finally at IL_%04x with exception: %s\n", clause->handler_offset, frame->ex? "yes": "no");
4075 endfinally_ip = NULL;
4077 if (old_list != finally_ips && finally_ips) {
4078 ip = finally_ips->data;
4079 finally_ips = g_slist_remove (finally_ips, ip);
4080 sp = frame->stack; /* spec says stack should be empty at endfinally so it should be at the start too */
4085 * If an exception is set, we need to execute the fault handler, too,
4086 * otherwise, we continue normally.
4096 MonoExceptionClause *clause;
4097 MonoMethod *method = frame->runtime_method->method;
4098 MonoMethodHeader *header = mono_method_get_header_checked (method, &error);
4099 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4103 g_print ("* Handle fault\n");
4105 ip_offset = frame->ip - rtm->code;
4106 for (i = 0; i < header->num_clauses; ++i) {
4107 clause = &rtm->clauses [i];
4108 if (clause->flags == MONO_EXCEPTION_CLAUSE_FAULT && MONO_OFFSET_IN_CLAUSE (clause, ip_offset)) {
4109 ip = rtm->code + clause->handler_offset;
4112 g_print ("* Executing handler at IL_%04x\n", clause->handler_offset);
4118 * If the handler for the exception was found in this method, we jump
4119 * to it right away, otherwise we return and let the caller run
4120 * the finally, fault and catch blocks.
4121 * This same code should be present in the endfault opcode, but it
4122 * is corrently not assigned in the ECMA specs: LAMESPEC.
4124 if (frame->ex_handler) {
4127 g_print ("* Executing handler at IL_%04x\n", frame->ex_handler->handler_offset);
4129 ip = rtm->code + frame->ex_handler->handler_offset;
4131 vt_sp = (unsigned char *) sp + rtm->stack_size;
4132 sp->data.p = frame->ex;
4143 ves_exec_method (MonoInvocation *frame)
4145 ThreadContext *context = mono_native_tls_get_value (thread_context_id);
4146 ThreadContext context_struct;
4153 mono_unhandled_exception ((MonoObject*)frame->ex);
4156 if (context == NULL) {
4157 context = &context_struct;
4158 context_struct.domain = mono_domain_get ();
4159 context_struct.base_frame = frame;
4160 context_struct.current_frame = NULL;
4161 context_struct.env_frame = frame;
4162 context_struct.current_env = &env;
4163 context_struct.search_for_handler = 0;
4164 context_struct.managed_code = 0;
4165 mono_native_tls_set_value (thread_context_id, context);
4168 frame->parent = context->current_frame;
4169 frame->runtime_method = mono_interp_get_runtime_method (context->domain, frame->method, &error);
4170 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4171 context->managed_code = 1;
4172 ves_exec_method_with_context (frame, context);
4173 context->managed_code = 0;
4175 if (context != &context_struct && context->current_env) {
4176 context->env_frame->ex = frame->ex;
4177 longjmp (*context->current_env, 1);
4180 mono_unhandled_exception ((MonoObject*)frame->ex);
4182 if (context->base_frame == frame)
4183 mono_native_tls_set_value (thread_context_id, NULL);
4185 context->current_frame = frame->parent;
4189 ves_exec (MonoDomain *domain, MonoAssembly *assembly, int argc, char *argv[])
4191 MonoImage *image = mono_assembly_get_image (assembly);
4196 method = mono_get_method_checked (image, mono_image_get_entry_point (image), NULL, NULL, &error);
4197 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4200 g_error ("No entry point method found in %s", mono_image_get_filename (image));
4202 rval = mono_runtime_run_main_checked (method, argc, argv, &error);
4203 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4211 "mint %s, the Mono ECMA CLI interpreter, (C) 2001, 2002 Ximian, Inc.\n\n"
4212 "Usage is: mint [options] executable args...\n\n", VERSION);
4214 "Runtime Debugging:\n"
4219 " --noptr\t\t\tdon't print pointer addresses in trace output\n"
4222 " --traceclassinit\n"
4225 " --debug method_name\n"
4232 " --config filename load the specified config file instead of the default\n"
4233 " --workers n maximum number of worker threads\n"
4239 interp_ves_icall_get_frame_info (gint32 skip, MonoBoolean need_file_info,
4240 MonoReflectionMethod **method,
4241 gint32 *iloffset, gint32 *native_offset,
4242 MonoString **file, gint32 *line, gint32 *column)
4244 ThreadContext *context = mono_native_tls_get_value (thread_context_id);
4245 MonoInvocation *inv = context->current_frame;
4249 for (i = 0; inv && i < skip; inv = inv->parent)
4250 if (inv->runtime_method != NULL)
4261 *method = mono_method_get_object_checked (context->domain, inv->runtime_method->method, NULL, &error);
4262 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4267 if (need_file_info) {
4271 *file = mono_string_new (mono_domain_get (), "unknown");
4278 interp_ves_icall_get_trace (MonoException *exc, gint32 skip, MonoBoolean need_file_info)
4280 MonoDomain *domain = mono_domain_get ();
4282 MonoArray *ta = exc->trace_ips;
4287 /* Exception is not thrown yet */
4288 MonoArray *array = mono_array_new_checked (domain, mono_defaults.stack_frame_class, 0, &error);
4289 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4293 len = mono_array_length (ta);
4295 res = mono_array_new_checked (domain, mono_defaults.stack_frame_class, len > skip ? len - skip : 0, &error);
4296 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4298 for (i = skip; i < len / 2; i++) {
4299 MonoStackFrame *sf = (MonoStackFrame *)mono_object_new_checked (domain, mono_defaults.stack_frame_class, &error);
4300 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4301 gushort *ip = mono_array_get (ta, gpointer, 2 * i + 1);
4302 RuntimeMethod *rtm = mono_array_get (ta, gpointer, 2 * i);
4305 sf->method = mono_method_get_object_checked (domain, rtm->method, NULL, &error);
4306 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4307 sf->native_offset = ip - rtm->code;
4311 sf->il_offset = mono_debug_il_offset_from_address (ji->method, sf->native_offset, domain);
4313 if (need_file_info) {
4316 filename = mono_debug_source_location_from_address (ji->method, sf->native_offset, &sf->line, domain);
4318 sf->filename = filename? mono_string_new (domain, filename): NULL;
4325 mono_array_set (res, gpointer, i, sf);
4332 ves_icall_System_Delegate_CreateDelegate_internal (MonoReflectionType *type, MonoObject *target, MonoReflectionMethod *info)
4334 MonoClass *delegate_class = mono_class_from_mono_type (type->type);
4335 MonoObject *delegate;
4338 g_assert (delegate_class->parent == mono_defaults.multicastdelegate_class);
4340 delegate = mono_object_new_checked (mono_object_domain (type), delegate_class, &error);
4341 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4343 interp_delegate_ctor (mono_object_domain (type), delegate, target, mono_interp_get_runtime_method (mono_get_root_domain (), info->method, &error));
4344 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4352 mono_native_tls_alloc (&thread_context_id, NULL);
4353 mono_native_tls_set_value (thread_context_id, NULL);
4354 mono_os_mutex_init_recursive (&runtime_method_lookup_section);
4355 mono_os_mutex_init_recursive (&create_method_pointer_mutex);
4357 mono_interp_transform_init ();
4360 typedef int (*TestMethod) (void);
4363 interp_regression_step (MonoImage *image, int verbose, int *total_run, int *total, GTimer *timer, MonoDomain *domain)
4365 int result, expected, failed, cfailed, run;
4366 double elapsed, transform_time;
4368 MonoObject *result_obj;
4369 static gboolean filter_method_init = FALSE;
4370 static const char *filter_method = NULL;
4372 g_print ("Test run: image=%s\n", mono_image_get_filename (image));
4373 cfailed = failed = run = 0;
4374 transform_time = elapsed = 0.0;
4377 /* fixme: ugly hack - delete all previously compiled methods */
4378 if (domain_jit_info (domain)) {
4379 g_hash_table_destroy (domain_jit_info (domain)->jit_trampoline_hash);
4380 domain_jit_info (domain)->jit_trampoline_hash = g_hash_table_new (mono_aligned_addr_hash, NULL);
4381 mono_internal_hash_table_destroy (&(domain->jit_code_hash));
4382 mono_jit_code_hash_init (&(domain->jit_code_hash));
4386 g_timer_start (timer);
4387 for (i = 0; i < mono_image_get_table_rows (image, MONO_TABLE_METHOD); ++i) {
4388 MonoObject *exc = NULL;
4390 MonoMethod *method = mono_get_method_checked (image, MONO_TOKEN_METHOD_DEF | (i + 1), NULL, NULL, &error);
4392 mono_error_cleanup (&error); /* FIXME don't swallow the error */
4396 if (!filter_method_init) {
4397 filter_method = g_getenv ("INTERP_FILTER_METHOD");
4398 filter_method_init = TRUE;
4400 gboolean filter = FALSE;
4401 if (filter_method) {
4402 const char *name = filter_method;
4404 if ((strchr (name, '.') > name) || strchr (name, ':')) {
4405 MonoMethodDesc *desc = mono_method_desc_new (name, TRUE);
4406 filter = mono_method_desc_full_match (desc, method);
4407 mono_method_desc_free (desc);
4409 filter = strcmp (method->name, name) == 0;
4411 } else { /* no filter, check for `Category' attribute on method */
4413 MonoCustomAttrInfo* ainfo = mono_custom_attrs_from_method_checked (method, &error);
4414 mono_error_cleanup (&error);
4418 for (j = 0; j < ainfo->num_attrs && filter; ++j) {
4419 MonoCustomAttrEntry *centry = &ainfo->attrs [j];
4420 if (centry->ctor == NULL)
4423 MonoClass *klass = centry->ctor->klass;
4424 if (strcmp (klass->name, "CategoryAttribute"))
4427 MonoObject *obj = mono_custom_attrs_get_attr_checked (ainfo, klass, &error);
4428 /* FIXME: there is an ordering problem if there're multiple attributes, do this instead:
4429 * MonoObject *obj = create_custom_attr (ainfo->image, centry->ctor, centry->data, centry->data_size, &error); */
4430 mono_error_cleanup (&error);
4431 MonoMethod *getter = mono_class_get_method_from_name (klass, "get_Category", -1);
4432 MonoObject *str = mono_interp_runtime_invoke (getter, obj, NULL, &exc, &error);
4433 mono_error_cleanup (&error);
4434 char *utf8_str = mono_string_to_utf8_checked ((MonoString *) str, &error);
4435 mono_error_cleanup (&error);
4436 if (!strcmp (utf8_str, "!INTERPRETER")) {
4437 g_print ("skip %s...\n", method->name);
4443 if (strncmp (method->name, "test_", 5) == 0 && filter) {
4444 MonoError interp_error;
4445 MonoObject *exc = NULL;
4447 result_obj = mono_interp_runtime_invoke (method, NULL, NULL, &exc, &interp_error);
4448 if (!mono_error_ok (&interp_error)) {
4450 g_print ("Test '%s' execution failed.\n", method->name);
4451 } else if (exc != NULL) {
4452 g_print ("Exception in Test '%s' occured:\n", method->name);
4453 mono_object_describe (exc);
4457 result = *(gint32 *) mono_object_unbox (result_obj);
4458 expected = atoi (method->name + 5); // FIXME: oh no.
4461 if (result != expected) {
4463 g_print ("Test '%s' failed result (got %d, expected %d).\n", method->name, result, expected);
4468 g_timer_stop (timer);
4469 elapsed = g_timer_elapsed (timer, NULL);
4470 if (failed > 0 || cfailed > 0){
4471 g_print ("Results: total tests: %d, failed: %d, cfailed: %d (pass: %.2f%%)\n",
4472 run, failed, cfailed, 100.0*(run-failed-cfailed)/run);
4474 g_print ("Results: total tests: %d, all pass \n", run);
4477 g_print ("Elapsed time: %f secs (%f, %f)\n\n", elapsed,
4478 elapsed - transform_time, transform_time);
4479 *total += failed + cfailed;
4483 interp_regression (MonoImage *image, int verbose, int *total_run)
4486 GTimer *timer = g_timer_new ();
4487 MonoDomain *domain = mono_domain_get ();
4491 /* load the metadata */
4492 for (i = 0; i < mono_image_get_table_rows (image, MONO_TABLE_METHOD); ++i) {
4494 method = mono_get_method_checked (image, MONO_TOKEN_METHOD_DEF | (i + 1), NULL, NULL, &error);
4496 mono_error_cleanup (&error);
4499 mono_class_init (method->klass);
4504 interp_regression_step (image, verbose, total_run, &total, timer, domain);
4506 g_timer_destroy (timer);
4511 mono_interp_regression_list (int verbose, int count, char *images [])
4513 int i, total, total_run, run;
4515 total_run = total = 0;
4516 for (i = 0; i < count; ++i) {
4517 MonoAssembly *ass = mono_assembly_open (images [i], NULL);
4519 g_warning ("failed to load assembly: %s", images [i]);
4522 total += interp_regression (mono_assembly_get_image (ass), verbose, &run);
4526 g_print ("Overall results: tests: %d, failed: %d (pass: %.2f%%)\n", total_run, total, 100.0*(total_run-total)/total_run);
4528 g_print ("Overall results: tests: %d, 100%% pass\n", total_run);